/
pid.go
709 lines (641 loc) · 15.3 KB
/
pid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
// Copyright 2017 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package heppdt
import (
"math"
)
type location int
// PID digits (base 10) are: n Nr Nl Nq1 Nq2 Nq3 Nj
// The location enum provides a convenient index into the PID.
const (
_ location = iota
Nj
Nq3
Nq2
Nq1
Nl
Nr
N
N8
N9
N10
)
// Quarks describes a given quark mixture
type Quarks struct {
Nq1 int16
Nq2 int16
Nq3 int16
}
// Particle Identification number
// In the standard numbering scheme, the PID digits (base 10) are:
// +/- n Nr Nl Nq1 Nq2 Nq3 Nj
// It is expected that any 7 digit number used as a PID will adhere to
// the Monte Carlo numbering scheme documented by the PDG.
// Note that particles not already explicitly defined
// can be expressed within this numbering scheme.
type PID int
// ExtraBits returns everything beyoind the 7th digit
// (e.g. outside the numbering scheme)
func (pid PID) ExtraBits() int {
return pid.AbsPID() / 10000000
}
// FundamentalID returns the first 2 digits if this is a "fundamental"
// particle.
// ID==100 is a special case (internal generator ID's are 81-100)
// Also, 101 and 102 are now used for geantinos
func (pid PID) FundamentalID() int {
if pid.Digit(N10) == 1 && pid.Digit(N9) == 0 {
return 0
}
if pid.Digit(Nq2) == 2 && pid.Digit(Nq1) == 0 {
return pid.AbsPID() % 10000
} else if pid.AbsPID() <= 102 {
return pid.AbsPID()
} else {
return 0
}
}
// Digit splits the PID into constituent integers
func (pid PID) Digit(loc location) int {
// PID digits (base 10) are: n Nr Nl Nq1 Nq2 Nq3 Nj
// the location enum provides a convenient index into the PID
num := int(math.Pow(10.0, float64(loc-1)))
return int(pid.AbsPID()/num) % 10
}
// findQ
func (pid PID) findQ(q int) bool {
if pid.IsDyon() {
return false
}
if pid.IsRhadron() {
iz := 7
for i := 6; i > 1; i-- {
if pid.Digit(location(i)) == 0 {
iz = i
} else if i == iz-1 {
// ignore squark or gluino
} else {
if pid.Digit(location(i)) == q {
return true
}
}
}
return false
}
if pid.Digit(Nq3) == q || pid.Digit(Nq2) == q || pid.Digit(Nq1) == q {
return true
}
if pid.IsPentaquark() {
if pid.Digit(Nl) == q || pid.Digit(Nr) == q {
return true
}
}
return false
}
// AbsPID returns the absolute value of the particle ID
func (pid PID) AbsPID() int {
id := int(pid)
if id >= 0 {
return id
}
return -int(id)
}
// IsValid returns whether PID is a valid particle ID
func (pid PID) IsValid() bool {
if pid.ExtraBits() > 0 {
switch {
case pid.IsNucleus():
return true
case pid.IsQBall():
return true
default:
return false
}
}
switch {
case pid.IsSUSY():
return true
case pid.IsRhadron():
return true
case pid.IsDyon():
return true
case pid.IsMeson():
return true
case pid.IsBaryon():
return true
case pid.IsDiQuark():
return true
case pid.FundamentalID() > 0:
return true
case pid.IsPentaquark():
return true
}
return false
}
// IsMeson returns whether this is a valid meson ID
func (pid PID) IsMeson() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.AbsPID() <= 100:
return false
case pid.FundamentalID() <= 100 && pid.FundamentalID() > 0:
return false
}
apid := pid.AbsPID()
id := int(pid)
switch {
case apid == 130 || apid == 310 || apid == 210:
return true
case apid == 150 || apid == 350 || apid == 510 || apid == 530:
// EvtGen odd number
return true
case id == 110 || id == 990 || id == 9990:
// pomeron, etc...
return true
case pid.Digit(Nj) > 0 && pid.Digit(Nq3) > 0 && pid.Digit(Nq2) > 0 && pid.Digit(Nq1) == 0:
// check for illegal antiparticles
switch {
case pid.Digit(Nq3) == pid.Digit(Nq2) && id < 0:
return false
default:
return true
}
}
return false
}
// IsBaryon returns whether this is a valid baryon id
func (pid PID) IsBaryon() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.AbsPID() <= 100:
return false
case pid.FundamentalID() <= 100 && pid.FundamentalID() > 0:
return false
case pid.AbsPID() == 2110 || pid.AbsPID() == 2210:
return true
case pid.Digit(Nj) > 0 && pid.Digit(Nq3) > 0 && pid.Digit(Nq2) > 0 && pid.Digit(Nq1) > 0:
return true
}
return false
}
// IsDiQuark returns whether this is a valid diquark id
func (pid PID) IsDiQuark() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.AbsPID() <= 100:
return false
case pid.FundamentalID() <= 100 && pid.FundamentalID() > 0:
return false
case pid.Digit(Nj) > 0 && pid.Digit(Nq3) == 0 && pid.Digit(Nq2) > 0 && pid.Digit(Nq1) > 0:
// EvtGen uses the diquarks for quark pairs, so for instance,
// 5501 is a valid "diquark" for EvtGen
// if pid.Digit(Nj) == 1 && pid.Digit(Nq2) == pid.Digit(Nq1) { // illegal
// return false
// } else {
return true
// }
}
return false
}
// IsHadron returns whether this is a valid hadron id
func (pid PID) IsHadron() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.IsMeson():
return true
case pid.IsBaryon():
return true
case pid.IsPentaquark():
return true
}
return false
}
// IsLepton returns whether this is a valid lepton id
func (pid PID) IsLepton() bool {
if pid.ExtraBits() > 0 {
return false
}
if fid := pid.FundamentalID(); fid >= 11 && fid <= 18 {
return true
}
return false
}
// IsNucleus returns whether this is a valid nucleus id.
// This implements the 2006 Monte Carlon nuclear code scheme.
// Ion numbers are +/- 10LZZZAAAI.
// AAA is A - total baryon number
// ZZZ is Z - total charge
// L is the total number of strange quarks.
// I is the isomer number, with I=0 corresponding to the ground state.
func (pid PID) IsNucleus() bool {
// a proton can also be a hydrogen nucleus
if pid.AbsPID() == 2212 {
return true
}
// new standard: +/- 10LZZZAAAI
if pid.Digit(N10) == 1 && pid.Digit(N9) == 0 {
// charge should always be less than or equal to baryon number
if pid.A() >= pid.Z() {
return true
}
}
return false
}
// IsPentaquark returns whether this is a valid pentaquark id
func (pid PID) IsPentaquark() bool {
// a pentaquark is of the form 9abcdej,
// where j is the spin and a, b, c, d, and e are quarks
switch {
case pid.ExtraBits() > 0:
return false
case pid.Digit(N) != 9:
return false
case pid.Digit(Nr) == 9 || pid.Digit(Nr) == 0:
return false
case pid.Digit(Nj) == 9 || pid.Digit(Nl) == 0:
return false
case pid.Digit(Nq1) == 0:
return false
case pid.Digit(Nq2) == 0:
return false
case pid.Digit(Nq3) == 0:
return false
case pid.Digit(Nj) == 0:
return false
case pid.Digit(Nq2) > pid.Digit(Nq1):
return false
case pid.Digit(Nq1) > pid.Digit(Nl):
return false
case pid.Digit(Nl) > pid.Digit(Nr):
return false
}
return true
}
// IsSUSY returns whether this is a valid SUSY particle id
func (pid PID) IsSUSY() bool {
// fundamental SUSY particles have n =1 or =2
switch {
case pid.ExtraBits() > 0:
return false
case pid.Digit(N) != 1 && pid.Digit(N) != 2:
return false
case pid.Digit(Nr) != 0:
return false
case pid.FundamentalID() == 0:
return false
}
return true
}
// IsRhadron returns whether this is a valid R-hadron particle id
func (pid PID) IsRhadron() bool {
// an R-hadron is of the form 10abcdj,
// where j is the spin and a, b, c, and d are quarks or gluons
switch {
case pid.ExtraBits() > 0:
return false
case pid.Digit(N) != 1:
return false
case pid.Digit(Nr) != 0:
return false
case pid.IsSUSY():
return false
case pid.Digit(Nq2) == 0:
return false // All R-hadrons have a least 3 core digits
case pid.Digit(Nq3) == 0:
return false // All R-hadrons have a least 3 core digits
case pid.Digit(Nj) == 0:
return false // All R-hadrons have a least 3 core digits
}
return true
}
// IsDyon returns whether this is a valid Dyon (magnetic monopole) id
func (pid PID) IsDyon() bool {
// Magnetic monopoles and Dyons are assumed to have one unit of
// Dirac monopole charge and a variable integer number xyz units
// of electric charge.
//
// Codes 411xyz0 are then used when the magnetic and electrical
// charge sign agree and 412xyz0 when they disagree,
// with the overall sign of the particle set by the magnetic charge.
// For now no spin information is provided.
switch {
case pid.ExtraBits() > 0:
return false
case pid.Digit(N) != 4:
return false
case pid.Digit(Nr) != 1:
return false
case pid.Digit(Nl) != 1 && pid.Digit(Nl) != 2:
return false
case pid.Digit(Nq3) == 0:
return false // all Dyons have at least 1 core digit
case pid.Digit(Nj) != 0:
return false // dyons have spin zero for now
}
return true
}
// IsQBall checks for QBall or any exotic particle with electric charge
// beyond the qqq scheme.
// Ad-hoc numbering for such particles is 100xxxx0, where xxxx is the
// charge in tenths.
func (pid PID) IsQBall() bool {
// Ad-hoc numbering for such particles is 100xxxx0,
// where xxxx is the charge in tenths.
switch {
case pid.ExtraBits() > 0:
return false
case pid.Digit(N) != 1 && pid.Digit(N) != 2:
return false
case pid.Digit(Nr) != 0:
return false
case pid.FundamentalID() == 0:
return false
}
return true
}
// HasUp returns whether this particle contains an up quark
func (pid PID) HasUp() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.FundamentalID() > 0:
return false
}
return pid.findQ(2)
}
// HasDown returns whether this particle contains a down quark
func (pid PID) HasDown() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.FundamentalID() > 0:
return false
}
return pid.findQ(1)
}
// HasStrange returns whether this particle contains a strange quark
func (pid PID) HasStrange() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.FundamentalID() > 0:
return false
}
return pid.findQ(3)
}
// HasCharm returns whether this particle contains a charm quark
func (pid PID) HasCharm() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.FundamentalID() > 0:
return false
}
return pid.findQ(4)
}
// HasBottom returns whether this particle contains a bottom quark
func (pid PID) HasBottom() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.FundamentalID() > 0:
return false
}
return pid.findQ(5)
}
// HasTop returns whether this particle contains a top quark
func (pid PID) HasTop() bool {
switch {
case pid.ExtraBits() > 0:
return false
case pid.FundamentalID() > 0:
return false
}
return pid.findQ(6)
}
// A returns A if this is a nucleus
func (pid PID) A() int {
// a proton can also be a hydrogen nucleus
switch {
case pid.AbsPID() == 2212:
return 1
case pid.Digit(N10) != 1 || pid.Digit(N9) != 0:
return 0
}
return (pid.AbsPID() / 10) % 1000
}
// Z returns Z if this is a nucleus
func (pid PID) Z() int {
// a proton can also be a hydrogen nucleus
switch {
case pid.AbsPID() == 2212:
return 1
case pid.Digit(N10) != 1 || pid.Digit(N9) != 0:
return 0
}
return (pid.AbsPID() / 10000) % 1000
}
// Lambda returns lambda if this is a nucleus
func (pid PID) Lambda() int {
// a proton can also be a hydrogen nucleus
if pid.AbsPID() == 2212 {
return 0
}
if !pid.IsNucleus() {
return 0
}
return pid.Digit(N8)
}
// JSpin returns 2J+1, where J is the total spin
func (pid PID) JSpin() int {
fid := pid.FundamentalID()
if fid > 0 && fid <= 100 {
switch {
case fid > 0 && fid < 7:
return 2
case fid == 9:
return 3
case fid > 10 && fid < 17:
return 2
case fid > 20 && fid < 25:
return 3
}
return 0
} else if pid.ExtraBits() > 0 {
return 0
}
return pid.AbsPID() % 10
}
// LSpin returns the orbital angular momentum.
// Valid for mesons only
func (pid PID) LSpin() int {
if !pid.IsMeson() {
return 0
}
tent := (pid.AbsPID() / 1000000) % 10
if tent == 9 {
return 0
}
Nl := (pid.AbsPID() / 10000) % 10
js := pid.AbsPID() % 10
if Nl == 0 && js == 3 {
return 0
} else if Nl == 0 && js == 5 {
return 1
} else if Nl == 0 && js == 7 {
return 2
} else if Nl == 0 && js == 9 {
return 3
} else if Nl == 0 && js == 1 {
return 0
} else if Nl == 1 && js == 3 {
return 1
} else if Nl == 1 && js == 5 {
return 2
} else if Nl == 1 && js == 7 {
return 3
} else if Nl == 1 && js == 9 {
return 4
} else if Nl == 2 && js == 3 {
return 1
} else if Nl == 2 && js == 5 {
return 2
} else if Nl == 2 && js == 7 {
return 3
} else if Nl == 2 && js == 9 {
return 4
} else if Nl == 1 && js == 1 {
return 1
} else if Nl == 3 && js == 3 {
return 2
} else if Nl == 3 && js == 5 {
return 3
} else if Nl == 3 && js == 7 {
return 4
} else if Nl == 3 && js == 9 {
return 5
}
// default to zero
return 0
}
// SSpin returns the spin. Valid for mesons only
func (pid PID) SSpin() int {
if !pid.IsMeson() {
return 0
}
tent := (pid.AbsPID() / 1000000) % 10
if tent == 9 {
return 0
}
Nl := (pid.AbsPID() / 10000) % 10
js := pid.AbsPID() % 10
if Nl == 0 && js >= 3 {
return 1
} else if Nl == 0 && js == 1 {
return 0
} else if Nl == 1 && js >= 3 {
return 0
} else if Nl == 2 && js >= 3 {
return 1
} else if Nl == 1 && js == 1 {
return 1
} else if Nl == 3 && js >= 3 {
return 1
}
// default to zero
return 0
}
var ch100 = [100]int{
-1, 2, -1, 2, -1, 2, -1, 2, 0, 0,
-3, 0, -3, 0, -3, 0, -3, 0, 0, 0,
0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 3, 0, 0, 3, 0, 0, 0,
0, -1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 6, 3, 6, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}
// threeCharge
func (pid PID) threeCharge() int {
var charge int
q1 := pid.Digit(Nq1)
q2 := pid.Digit(Nq2)
q3 := pid.Digit(Nq3)
ida := pid.AbsPID()
fid := pid.FundamentalID()
if ida == 0 { // illegal
return 0
} else if pid.ExtraBits() > 0 {
if pid.IsNucleus() { // ion
return 3 * pid.Z()
} else if pid.IsQBall() { // QBall
charge = 3 * ((ida / 10) % 10000)
} else { // not an ion
return 0
}
} else if pid.IsDyon() { // Dyon
charge = 3 * ((ida / 10) % 1000)
// this is half right
// the charge sign will be changed below if pid < 0
if pid.Digit(Nl) == 2 {
charge = -charge
}
} else if fid > 0 && fid <= 100 { // use table
charge = ch100[fid-1]
if ida == 1000017 || ida == 1000018 {
charge = 0
}
if ida == 1000034 || ida == 1000052 {
charge = 0
}
if ida == 1000053 || ida == 1000054 {
charge = 0
}
if ida == 5100061 || ida == 5100062 {
charge = 6
}
} else if pid.Digit(Nj) == 0 { // KL, Ks, or undefined
return 0
} else if (q1 == 0) || (pid.IsRhadron() && (q1 == 9)) { // meson // mesons
if q2 == 3 || q2 == 5 {
charge = ch100[q3-1] - ch100[q2-1]
} else {
charge = ch100[q2-1] - ch100[q3-1]
}
} else if q3 == 0 { // diquarks
charge = ch100[q2-1] + ch100[q1-1]
} else if pid.IsBaryon() || (pid.IsRhadron() && (pid.Digit(Nl) == 9)) { // baryon // baryons
charge = ch100[q3-1] + ch100[q2-1] + ch100[q1-1]
}
if charge == 0 {
return 0
} else if int(pid) < 0 {
charge = -charge
}
return charge
}
const onethird = 1. / 3.0
const onethirtith = 1. / 30.0
// Charge returns the actual charge which might be fractional
func (pid PID) Charge() float64 {
c := pid.threeCharge()
if pid.IsQBall() {
return float64(c) * onethirtith
}
return float64(c) * onethird
}
// Quarks returns a list of 3 constituent quarks
func (pid PID) Quarks() Quarks {
return Quarks{
Nq1: int16(pid.Digit(Nq1)),
Nq2: int16(pid.Digit(Nq2)),
Nq3: int16(pid.Digit(Nq3)),
}
}