go-hep.org/x/hep@v0.38.1/heppdt/pid_test.go (about)

     1  // Copyright ©2017 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package heppdt_test
     6  
     7  import (
     8  	"fmt"
     9  	"reflect"
    10  	"testing"
    11  
    12  	"go-hep.org/x/hep/heppdt"
    13  )
    14  
    15  func TestPID(t *testing.T) {
    16  	/*
    17  		ids := []int{ 5, 25, 15, 213, -3214, 10213, 9050225, -200543, 129050225,
    18  			2000025, 3101, 3301, -2212, 1000020040, -1000060120, 555,
    19  			5000040, 5100005, 24, 5100024, 5100025, 9221132,
    20  			4111370, -4120240, 4110050, 10013730,
    21  			1000993, 1000612, 1000622, 1000632, 1006213, 1000652,
    22  			1009113, 1009213, 1009323,
    23  			1093114, 1009333, 1006313, 1092214, 1006223,
    24  		}
    25  	*/
    26  
    27  	for _, table := range []struct {
    28  		id                            int
    29  		nx, nr, n1, nq1, nq2, nq3, nj int
    30  		extra                         int
    31  		jspin, lspin, spin            int
    32  		fid                           int
    33  		charge                        float64
    34  		valid                         bool
    35  
    36  		ishadron, ismeson, isrhadron, isbaryon bool
    37  		islepton, isdiquark, isnucleus         bool
    38  
    39  		issusy, isdyon, isqlb, isunknown bool
    40  
    41  		hasup, hasdown, hasstrange, hascharm, hasbottom, hastop bool
    42  	}{
    43  		{
    44  			id: 5,
    45  			nx: 0, nr: 0, n1: 0, nq1: 0, nq2: 0, nq3: 0, nj: 5,
    46  			extra: 0,
    47  			jspin: 2, lspin: 0, spin: 0,
    48  			fid:    0,
    49  			charge: -1. / 3.,
    50  			valid:  true,
    51  			isqlb:  true,
    52  		},
    53  		{
    54  			id: 25,
    55  			nx: 0, nr: 0, n1: 0, nq1: 0, nq2: 0, nq3: 2, nj: 5,
    56  			extra: 0,
    57  			jspin: 0, lspin: 0, spin: 0,
    58  			fid:    0,
    59  			charge: 0,
    60  			valid:  true,
    61  			isqlb:  true,
    62  		},
    63  		{
    64  			id: 15,
    65  			nx: 0, nr: 0, n1: 0, nq1: 0, nq2: 0, nq3: 1, nj: 5,
    66  			extra: 0,
    67  			jspin: 2, lspin: 0, spin: 0,
    68  			fid:      0,
    69  			charge:   -1,
    70  			valid:    true,
    71  			isqlb:    true,
    72  			islepton: true,
    73  		},
    74  		// {
    75  		// 	id: 213,
    76  		// 	nx: 0, nr:0, n1:0, nq1:0, nq2:2, nq3:1, nj:3,
    77  		// 	extra: 0,
    78  		// 	jspin: 3, lspin:0, spin:1,
    79  		// 	fid: 0,
    80  		// 	charge: 1,
    81  		// 	valid: true,
    82  		// 	ishadron: true,
    83  		// 	ismeson: true,
    84  		// 	hasup: true,
    85  		// 	hasdown: true,
    86  		// },
    87  	} {
    88  		id := table.id
    89  		pid := heppdt.PID(id)
    90  		nx := pid.Digit(heppdt.N)
    91  		if nx != table.nx {
    92  			t.Fatalf("pid=%d. expected nx=%d. got=%d", id, table.nx, nx)
    93  		}
    94  
    95  		nr := pid.Digit(heppdt.Nr)
    96  		if nr != table.nr {
    97  			t.Fatalf("pid=%d. expected nr=%d. got=%d", id, table.nr, nr)
    98  		}
    99  
   100  		nq1 := pid.Digit(heppdt.Nq1)
   101  		if nq1 != table.nq1 {
   102  			t.Fatalf("pid=%d. expected nq1=%d. got=%d", id, table.nq1, nq1)
   103  		}
   104  
   105  		nq2 := pid.Digit(heppdt.Nq2)
   106  		if nq2 != table.nq2 {
   107  			t.Fatalf("pid=%d. expected nq2=%d. got=%d", id, table.nq2, nq2)
   108  		}
   109  
   110  		nq3 := pid.Digit(heppdt.Nq3)
   111  		if nq3 != table.nq3 {
   112  			t.Fatalf("pid=%d. expected nq3=%d. got=%d", id, table.nq3, nq3)
   113  		}
   114  
   115  		extra := pid.ExtraBits()
   116  		if extra != table.extra {
   117  			t.Fatalf("pid=%d. expected extra=%d. got=%d", id, table.extra, extra)
   118  		}
   119  
   120  		jspin := pid.JSpin()
   121  		if jspin != table.jspin {
   122  			t.Fatalf("pid=%d. expected jspin=%d. got=%d", id, table.jspin, jspin)
   123  		}
   124  
   125  		lspin := pid.LSpin()
   126  		if lspin != table.lspin {
   127  			t.Fatalf("pid=%d. expected lspin=%d. got=%d", id, table.lspin, lspin)
   128  		}
   129  
   130  		spin := pid.SSpin()
   131  		if spin != table.spin {
   132  			t.Fatalf("pid=%d. expected sspin=%d. got=%d", id, table.spin, spin)
   133  		}
   134  
   135  		charge := pid.Charge()
   136  		if charge != table.charge {
   137  			t.Fatalf("pid=%d. expected charge=%v. got=%v", id, table.charge, charge)
   138  		}
   139  
   140  		if pid.IsValid() != table.valid {
   141  			t.Fatalf("expected pid=%d valid=%v. got=%v", int(pid), table.valid, pid.IsValid())
   142  		}
   143  
   144  		if table.ishadron != pid.IsHadron() {
   145  			t.Fatalf("expected pid=%d ishadron=%v. got=%v", int(pid), table.ishadron, pid.IsHadron())
   146  		}
   147  
   148  		if table.ismeson != pid.IsMeson() {
   149  			t.Fatalf("expected pid=%d ismeson=%v. got=%v", int(pid), table.ismeson, pid.IsMeson())
   150  		}
   151  
   152  		if table.isrhadron != pid.IsRhadron() {
   153  			t.Fatalf("expected pid=%d isrhadron=%v. got=%v", int(pid), table.isrhadron, pid.IsRhadron())
   154  		}
   155  
   156  		if table.isbaryon != pid.IsBaryon() {
   157  			t.Fatalf("expected pid=%d isbaryon=%v. got=%v", int(pid), table.isbaryon, pid.IsBaryon())
   158  		}
   159  
   160  		if table.islepton != pid.IsLepton() {
   161  			t.Fatalf("expected pid=%d islepton=%v. got=%v", int(pid), table.islepton, pid.IsLepton())
   162  		}
   163  
   164  		if table.isdiquark != pid.IsDiQuark() {
   165  			t.Fatalf("expected pid=%d isdiquark=%v. got=%v", int(pid), table.isdiquark, pid.IsDiQuark())
   166  		}
   167  
   168  		if table.isnucleus != pid.IsNucleus() {
   169  			t.Fatalf("expected pid=%d isnucleus=%v. got=%v", int(pid), table.isnucleus, pid.IsNucleus())
   170  		}
   171  
   172  		if table.issusy != pid.IsSUSY() {
   173  			t.Fatalf("expected pid=%d issusy=%v. got=%v", int(pid), table.issusy, pid.IsSUSY())
   174  		}
   175  
   176  		if table.isdyon != pid.IsDyon() {
   177  			t.Fatalf("expected pid=%d isdyon=%v. got=%v", int(pid), table.isdyon, pid.IsDyon())
   178  		}
   179  
   180  		if table.isqlb != (pid.AbsPID() < 100) {
   181  			t.Fatalf("expected pid=%d is-quark/lepton/boson=%v. got=%v", int(pid), table.isqlb, pid.AbsPID() < 100)
   182  		}
   183  
   184  		if table.isunknown != (!pid.IsSUSY() && !pid.IsDyon() && !pid.IsHadron() &&
   185  			!pid.IsLepton() && !pid.IsDiQuark() && !pid.IsNucleus() &&
   186  			!(pid.AbsPID() < 100)) {
   187  			t.Fatalf("expected pid=%d isunknown=%v. got=%v", int(pid), table.isunknown, !table.isunknown)
   188  		}
   189  
   190  		if table.hasup != pid.HasUp() {
   191  			t.Fatalf("expected pid=%d hasup=%v. got=%v", int(pid), table.hasup, pid.HasUp())
   192  		}
   193  
   194  		if table.hasdown != pid.HasDown() {
   195  			t.Fatalf("expected pid=%d hasdown=%v. got=%v", int(pid), table.hasdown, pid.HasDown())
   196  		}
   197  
   198  		if table.hasstrange != pid.HasStrange() {
   199  			t.Fatalf("expected pid=%d hasstrange=%v. got=%v", int(pid), table.hasstrange, pid.HasStrange())
   200  		}
   201  
   202  		if table.hascharm != pid.HasCharm() {
   203  			t.Fatalf("expected pid=%d hascharm=%v. got=%v", int(pid), table.hascharm, pid.HasCharm())
   204  		}
   205  
   206  		if table.hasbottom != pid.HasBottom() {
   207  			t.Fatalf("expected pid=%d hasbottom=%v. got=%v", int(pid), table.hasbottom, pid.HasBottom())
   208  		}
   209  
   210  		if table.hastop != pid.HasTop() {
   211  			t.Fatalf("expected pid=%d hastop=%v. got=%v", int(pid), table.hastop, pid.HasTop())
   212  		}
   213  	}
   214  }
   215  
   216  func TestQuarks(t *testing.T) {
   217  	for _, tc := range []struct {
   218  		pid  int
   219  		want heppdt.Quarks
   220  	}{
   221  		{
   222  			pid:  1,
   223  			want: heppdt.Quarks{Nq1: 0, Nq2: 0, Nq3: 0},
   224  		},
   225  		{
   226  			pid:  2,
   227  			want: heppdt.Quarks{Nq1: 0, Nq2: 0, Nq3: 0},
   228  		},
   229  		{
   230  			pid:  3,
   231  			want: heppdt.Quarks{Nq1: 0, Nq2: 0, Nq3: 0},
   232  		},
   233  		{
   234  			pid:  4,
   235  			want: heppdt.Quarks{Nq1: 0, Nq2: 0, Nq3: 0},
   236  		},
   237  		{
   238  			pid:  5,
   239  			want: heppdt.Quarks{Nq1: 0, Nq2: 0, Nq3: 0},
   240  		},
   241  		{
   242  			pid:  6,
   243  			want: heppdt.Quarks{Nq1: 0, Nq2: 0, Nq3: 0},
   244  		},
   245  		{
   246  			pid:  +2212,
   247  			want: heppdt.Quarks{Nq1: 2, Nq2: 2, Nq3: 1},
   248  		},
   249  		{
   250  			pid:  -2212,
   251  			want: heppdt.Quarks{Nq1: 2, Nq2: 2, Nq3: 1},
   252  		},
   253  		{
   254  			pid:  +111,
   255  			want: heppdt.Quarks{Nq1: 0, Nq2: 1, Nq3: 1},
   256  		},
   257  		{
   258  			pid:  +113,
   259  			want: heppdt.Quarks{Nq1: 0, Nq2: 1, Nq3: 1},
   260  		},
   261  		{
   262  			pid:  +115,
   263  			want: heppdt.Quarks{Nq1: 0, Nq2: 1, Nq3: 1},
   264  		},
   265  		{
   266  			pid:  +211,
   267  			want: heppdt.Quarks{Nq1: 0, Nq2: 2, Nq3: 1},
   268  		},
   269  		{
   270  			pid:  +311,
   271  			want: heppdt.Quarks{Nq1: 0, Nq2: 3, Nq3: 1},
   272  		},
   273  		{
   274  			pid:  +411,
   275  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 1},
   276  		},
   277  		{
   278  			pid:  +413,
   279  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 1},
   280  		},
   281  		{
   282  			pid:  +415,
   283  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 1},
   284  		},
   285  		{
   286  			pid:  +421,
   287  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 2},
   288  		},
   289  		{
   290  			pid:  +423,
   291  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 2},
   292  		},
   293  		{
   294  			pid:  +425,
   295  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 2},
   296  		},
   297  		{
   298  			pid:  +431,
   299  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 3},
   300  		},
   301  		{
   302  			pid:  +433,
   303  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 3},
   304  		},
   305  		{
   306  			pid:  +435,
   307  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 3},
   308  		},
   309  		{
   310  			pid:  +441,
   311  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 4},
   312  		},
   313  		{
   314  			pid:  +443,
   315  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 4},
   316  		},
   317  		{
   318  			pid:  +445,
   319  			want: heppdt.Quarks{Nq1: 0, Nq2: 4, Nq3: 4},
   320  		},
   321  		{
   322  			pid:  +511,
   323  			want: heppdt.Quarks{Nq1: 0, Nq2: 5, Nq3: 1},
   324  		},
   325  		{
   326  			pid:  -511,
   327  			want: heppdt.Quarks{Nq1: 0, Nq2: 5, Nq3: 1},
   328  		},
   329  		{
   330  			pid:  1000010020,
   331  			want: heppdt.Quarks{Nq1: 0, Nq2: 0, Nq3: 2},
   332  		},
   333  	} {
   334  		t.Run(fmt.Sprintf("pid=%d", tc.pid), func(t *testing.T) {
   335  			pid := heppdt.PID(tc.pid)
   336  			qrks := pid.Quarks()
   337  			if !reflect.DeepEqual(qrks, tc.want) {
   338  				t.Fatalf("got=%#v, want=%#v", qrks, tc.want)
   339  			}
   340  		})
   341  	}
   342  }