BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
Pdt.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: Pdt.cxx,v 1.5 2010/03/25 09:55:57 zhangy Exp $
4//
5// Description:
6// Searchable Particle Lists for BaBar
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author List:
12// John LoSecco Original Author
13// Zhang Yao([email protected])
14//
15// Copyright Information:
16// Copyright (C) 1998 The University of Notre Dame
17//
18// History:
19// Migration for BESIII MDC
20//
21//------------------------------------------------------------------------
22//
23// Based on Pdt.h by Luca Lista
24//
25// See Also
26// PdtEntry, DecayMode
27
28#include "MdcRecoUtil/AstStringMap.h"
29#include "MdcRecoUtil/Pdt.h"
30#include "MdcRecoUtil/PdtEntry.h"
31
32#include <string.h>
33#include <stdio.h>
34#include <assert.h>
35
36#include <string>
37using std::string;
38#include <vector>
39using std::vector;
40#include <map>
41using std::map;
42#include <iostream>
43#include <strstream>
44using std::cerr;
45using std::cout;
46using std::endl;
47using std::istrstream;
48using std::ostream;
49using std::strstream;
50
51#define HBARC (197.327*1.e-3*1.e-13) // GeV*cm
52
53PdtEntry* Pdt::_positiveEntries[5]={0,0,0,0,0};
54PdtEntry* Pdt::_negativeEntries[5]={0,0,0,0,0};
55PdtEntry* Pdt::_neutralEntries[5]={0,0,0,0,0};
56
57//By pdt number
58map<int, PdtEntry*>*
59Pdt::_entries = new map<int, PdtEntry*>;
60
61//By name
63Pdt::_entriesn = new AstStringMap< PdtEntry >;
64
65//By geant number
66map<int, PdtEntry*>*
67Pdt::_entriesg = new map<int, PdtEntry*>;
68
69//By lund number
70map<int, PdtEntry*>*
71Pdt::_entriesl = new map<int, PdtEntry*>;
72
74
75 int kf = (int) kf_id;
76
77 int i2 = (kf/10) % 10;
78 int i3 = (kf/100) % 10;
79 int i4 = (kf/1000) % 10;
80
81 if (i2 == i3 && i4 == 0 && kf > 100)
82 return lundId(kf);
83 else if (kf >= 21 && kf <= 23) return lundId(kf);
84
85 else if (kf == 310) return lundId(130);
86 else if (kf == 130) return lundId(310);
87
88 else return lundId(-kf);
89}
90
91void Pdt::addParticle(const char *pname, PdtLund::LundType id,
92 float spin, float charge, float mass,
93 float width, float cut){
94
95 PdtEntry* nentry = new PdtEntry(pname, id, spin, charge, mass, width, cut);
96 (*_entries)[pdgId(id)]=nentry;
97
98 if ( (*_entriesn)[pname] != 0 ) {
99 //cout << "Pdt::addParticle:adding existing particle:"<<pname<<endl;
100 }
101
102 _entriesn->insert( pname )=nentry;
103 if(PdtGeant::null!=nentry->geantId()){
104 (*_entriesg)[nentry->geantId()]=nentry;
105 }
106
107 (*_entriesl)[id]=nentry;
108
109 if(PdtPid::null!=nentry->pidId()) {
110 if(nentry->charge()>0) {
111 _positiveEntries[nentry->pidId()]=nentry;
112 }else{
113 _negativeEntries[nentry->pidId()]=nentry;
114 }
115 }
116
117 if(PdtPid::none!=nentry->pidNeutId()){
118 if(nentry->charge()==0){
119 _neutralEntries[nentry->pidNeutId()]=nentry;
120 }
121 }
122
123}
124
125void Pdt::addParticle(const char *pname, PdtGeant::GeantType id,
126 float spin, float charge, float mass,
127 float width, float cut){
128
129 PdtEntry* nentry = new PdtEntry(pname, id, spin, charge, mass, width, cut);
130
131 (*_entries)[pdgId(id)]=nentry;
132 if ( (*_entriesn)[pname] != 0 ) {
133 //cout << "Pdt::addParticle:adding existing particle:"<<pname<<endl;
134 }
135
136 _entriesn->insert( pname )=nentry;
137 if(PdtGeant::null!=nentry->geantId()){
138 (*_entriesg)[id]=nentry;
139 }
140
141 (*_entriesl)[lundId(id)]=nentry;
142
143 if(PdtPid::null!=nentry->pidId()) {
144 if(nentry->charge()>0) {
145 _positiveEntries[nentry->pidId()]=nentry;
146 }else{
147 _negativeEntries[nentry->pidId()]=nentry;
148 }
149
150 }
151
152 if(PdtPid::none!=nentry->pidNeutId()){
153 if(nentry->charge()==0) {
154 _neutralEntries[nentry->pidNeutId()]=nentry;
155 }
156 }
157
158}
159
160void Pdt::addDecay(const char* pname, float bf,
161 const char* child1, const char* child2, const char* child3,
162 const char* child4, const char* child5){
163
164 PdtEntry *primary = lookup(pname);
165 if (primary == 0) return;
166 const char *children[5] = {child1, child2, child3, child4, child5};
167
168 vector<PdtEntry*> *kids = new vector<PdtEntry*>;
169
170 int nkids;
171 for(nkids=0; nkids<5 && children[nkids]!=0; nkids++ )
172 {
173 PdtEntry* secondary = lookup(children[nkids]);
174 if( secondary ==0 ) break;
175 kids->push_back(secondary);
176 }
177
178 primary->addDecay(bf, kids );
179
180}
181
183 PdtLund::LundType child1,
184 PdtLund::LundType child2,
185 PdtLund::LundType child3,
186 PdtLund::LundType child4,
187 PdtLund::LundType child5){
188
189 PdtEntry *primary = lookup(id);
190 if (primary == 0) return;
191
192 PdtLund::LundType children[5] = {child1, child2, child3, child4, child5};
193 vector<PdtEntry*> *kids = new vector<PdtEntry*>;
194
195 int nkids;
196 for(nkids=0; nkids<5 && children[nkids]!=0; nkids++ )
197 {
198 PdtEntry* secondary = lookup(children[nkids]);
199 if( secondary ==0 ) break;
200 kids->push_back(secondary);
201 }
202
203 primary->addDecay(bf, kids );
204
205}
206
207PdtEntry* Pdt::lookup( const std::string& name ){
208 return (*_entriesn)[name];
209}
210
212 // look for the particle by Particle Data Group id
213 return (*_entriesl)[id];
214}
215
217 // look for the particle by GEANT id
218 return (*_entriesg)[id];
219}
220
222 // look for the particle by PDG id
223 return (*_entries)[id];
224}
225
227
228 // look for the particle by PID code id and charge
229 if(id==PdtPid::null) return lookup(PdtLund::null);
230 if(charge>0) return _positiveEntries[id];
231 return _negativeEntries[id];
232
233}
234
236
237 // look for the particle by PID code id and charge
238
239 if(id==PdtPid::none) return lookup(PdtLund::null);
240 return _neutralEntries[id];
241
242}
243
244void Pdt::printOn(ostream& cout){
245
246 //lange move printouts here
247 cout << "Number of particles in tables: "<<endl
248 << "By pdt number :" << _entries->size() <<endl
249 << "By name :" << _entriesn->size()<<endl
250 << "By geant number :" << _entriesg->size()<<endl
251 << "By lund number :" <<_entriesl->size()<<endl;
252
253 cout << '\n';
254 int i;
255 for (i=0;i<72;i++) cout << '-';
256 cout<<'\n';
257
258 cout << " Particle Data Table\n\n";
259 cout << " id name mass width spin charge lifetime\n";
260 cout << " (GeV) (GeV) (cm) \n";
261 for (i=0; i<72; i++) cout << '-';
262 cout << '\n';
263
264 PdtEntry *p;
265
266 map<int, PdtEntry*>::iterator iter=_entries->begin();
267
268 while ( iter != _entries->end()) {
269 p = iter->second;
270 assert(0!=p);
271 p->printOn(cout);
272 p->printBFOn(cout);
273 ++iter;
274 }
275 cout << '\n';
276 for (i=0; i<72; i++) cout << '-';
277 cout << '\n';
278
279 map<int, PdtEntry*>::iterator iter1=_entries->begin();
280
281 while ( iter1 != _entries->end()) {
282 p=iter1->second;
283 cout << "The conjuate of "<< p->name() << " is ";
284 cout << conjugate(p)->name() <<endl;
285 iter1++;
286 }
287}
288
289
290
291void Pdt::readMCppTable(string filenm){
292
293 string path = filenm;
294 char line[512];
295 FILE *ifl = fopen(path.c_str(),"r");
296
297 if(0 == ifl) cout<<" Pdt::readMCppTable: please copy " <<
298 filenm << " in to your run directory!"<<
299 std::endl;
300 assert(0!=ifl);
301
302 while ( fgets(line,512,ifl) )
303 {
304 if (strlen(line) >= 511)
305 {
306 cerr << "Pdt.read : input line is too long\n";
307 assert(0);
308 }
309 istrstream linestr(line);
310 string opcode;
311 char subcode;
312 linestr >> opcode >> subcode;
313
314 if( opcode == "end" )
315 break;
316
317 else if( opcode == "add" )
318 {
319 switch (subcode)
320 {
321 case 'p':
322 {
323 string classname;
324 linestr >> classname;
325 // if (classname == "Collision" || classname == "Parton")
326 if (classname == "Collision" )
327 continue;
328
329 string name;
330 int type;
331 float mass, width, cut, charge, spin, lifetime;
332
333 linestr >> name >> type;
334 linestr >> mass >> width >> cut >> charge;
335 linestr >> spin >> lifetime;
336
337 charge /= 3.0;
338 if (classname != "Meson")
339 spin /= 2.0;
340
341 // lifetime is c*tau (mm)
342 if (lifetime > 0.0 && width < 1e-10)
343 width = HBARC / (lifetime/10.0);
344
345 addParticle(name.c_str(), lundId(type), spin, charge, mass, width, cut);
346 break;
347 }
348
349 case 'c':
350 {
351 int ptype, nchild;
352 float bf;
353 string decayer;
354
355 linestr >> ptype >> bf >> decayer >> nchild;
356 PdtEntry *parent = lookup(lundId(ptype));
357 if (parent == 0) continue;
358
359 vector<PdtEntry*> *kids = new vector<PdtEntry*>;
360
361 int i;
362 for(i=0; i<nchild; i++ )
363 {
364 int ctype;
365 linestr >> ctype;
366 PdtEntry* secondary = lookup(lundId(ctype));
367 if( secondary ==0 ) break;
368 kids->push_back(secondary);
369 }
370
371 parent->addDecay(bf, kids );
372 break;
373 }
374
375 case 'd':
376 break;
377
378 default:
379 cerr << "Pdt.readMCppTable : unknown subcode '" << subcode
380 << "' for operation add\n";
381 break;
382 }
383 }
384 }
385 // adding geantino for GEANT studies
386 //why why why why - shouldn't you do this in the tables?
387 //addParticle("geantino", PdtGeant::geantino, 0., 0., 0., 0., 0. );
388
389 fclose(ifl);
390
391}
392
394
395 PdtEntry *p;
396
397 map<int, PdtEntry*>::iterator iter=_entries->begin();
398
399 while ( iter != _entries->end()) {
400 p = iter->second;
401 assert(0!=p);
402 delete p;
403 ++iter;
404 }
405
406 _entries->clear();
407 _entriesn->clear();
408 _entriesg->clear();
409 _entriesl->clear();
410}
411
412
414
415 if (gId == PdtGeant::deuteron ||
416 gId == PdtGeant::tritium ||
417 gId == PdtGeant::alpha ||
418 gId == PdtGeant::geantino ||
419 gId == PdtGeant::He3 ||
420 gId == PdtGeant::Cerenkov)
421 { return PdtLund::null; }
422 else
424
425}
426
428
429 //
430 // special case:
431 // GEANT has only one neutrino
432 //
433 if (lId == PdtLund::nu_e ||
434 lId == PdtLund::anti_nu_e ||
435 lId == PdtLund::nu_mu ||
436 lId == PdtLund::anti_nu_mu ||
437 lId == PdtLund::nu_tau ||
438 lId == PdtLund::anti_nu_tau )
439 { return PdtGeant::nu_e; }
440 else
441 {
442 int i;
443 for(i = 0; i< PdtGeant::_nGeantId; i++)
444 { if (PdtGeant::_lundId[i] == lId) return geantId(i); }
445 return PdtGeant::null;
446 }
447}
448
450
451 switch (lId)
452 {
453 case PdtLund::e_minus:
454 case PdtLund::e_plus:
455 return PdtPid::electron;
457 case PdtLund::mu_plus:
458 return PdtPid::muon;
460 case PdtLund::pi_plus:
461 return PdtPid::pion;
462 case PdtLund::K_minus:
463 case PdtLund::K_plus:
464 return PdtPid::kaon;
465 case PdtLund::p_plus:
467 return PdtPid::proton;
468 default:
469 return PdtPid::null;
470 }
471}
472
474
475 switch (lId)
476 {
477 case PdtLund::gamma:
478 return PdtPid::gamma;
479 case PdtLund::pi0:
480 return PdtPid::pi0;
481 case PdtLund::K_L0:
482 return PdtPid::K0L;
483 case PdtLund::anti_n0:
485 case PdtLund::n0:
486 return PdtPid::neutron;
487 default:
488 return PdtPid::none;
489 }
490}
491
493 return pidId(lundId(gId));
494}
495
497 return pidNeutId(lundId(gId));
498}
499
501 return geantId(lundId(pId, charge));
502}
503
505 return geantId(lundId(pId, charge));
506}
507
509
510 if(charge == -1)
511 {
512 switch(pId)
513 {
514 case PdtPid::electron:
515 return PdtLund::e_minus;
516 case PdtPid::muon:
517 return PdtLund::pi_minus;
518 case PdtPid::pion:
519 return PdtLund::pi_minus;
520 case PdtPid::kaon:
521 return PdtLund::K_minus;
522 case PdtPid::proton:
524 default:
525 return PdtLund::null;
526 }
527 }
528 else if (charge == 1)
529 {
530 switch(pId)
531 {
532 case PdtPid::electron:
533 return PdtLund::e_plus;
534 case PdtPid::muon:
535 return PdtLund::pi_plus;
536 case PdtPid::pion:
537 return PdtLund::pi_plus;
538 case PdtPid::kaon:
539 return PdtLund::K_plus;
540 case PdtPid::proton:
541 return PdtLund::p_plus;
542 default:
543 return PdtLund::null;
544 }
545 }
546 else
547 {
548 cerr << "error: wrong charge; must be +1 or -1" << endl;
549 return PdtLund::null;
550 }
551}
552
554
555 if (charge == 0)
556 {
557 switch(pId)
558 {
559 case PdtPid::gamma:
560 return PdtLund::gamma;
561 case PdtPid::pi0:
562 return PdtLund::pi0;
563 case PdtPid::K0L:
564 return PdtLund::K_L0;
565 case PdtPid::neutron:
566 return PdtLund::n0;
568 return PdtLund::anti_n0;
569 default:
570 return PdtLund::null;
571 }
572 }
573 else
574 {
575 cerr << "error: wrong charge; must be +1 or -1" << endl;
576 return PdtLund::null;
577 }
578}
579
581
582 int ret;
583 switch ( (int) pdg ) {
584 case 551: // chi_0b
585 ret = 10551 ;
586 case 10443: // chi_1c
587 ret = 20443 ;
588 case 20443: // psi(2S)
589 ret = 30443 ;
590 case 30443: // psi(3770)
591 ret = 40443 ;
592 case 20553: // Upsilon(2S)
593 ret = 30553 ;
594 case 4322: // Xi_c+
595 ret = 4232 ;
596 case -4322: // Anti Xi_c+
597 ret = -4232 ;
598 case 4232: // Xi'_c+
599 ret = 4322 ;
600 case -4232: // Anti Xi'_c+
601 ret = -4322 ;
602 default: // All the rest is the same (hopefully)
603 ret = (int) pdg;
604 }
605 return lundId(ret);
606}
607
609
610 int ret;
611 switch ( (int) lund ) {
612 case 551: // eta_b does not exist in PDG
613 ret = 0 ;
614 case 10551: // chi_0b
615 ret = 551 ;
616 case 10443: // h_1c does not exist in PDG
617 ret = 0 ;
618 case 20443: // chi_1c
619 ret = 10443 ;
620 case 30443: // psi(2S)
621 ret = 20443 ;
622 case 40443: // psi(3770)
623 ret = 30443 ;
624 case 30553: // Upsilon(2S)
625 ret = 20553 ;
626 case 4232: // Xi_c+
627 ret = 4322 ;
628 case -4232: // Anti Xi_c+
629 ret = -4322 ;
630 case 4322: // Xi'_c+
631 ret = 4232 ;
632 case -4322: // Anti Xi'_c+
633 ret = -4232 ;
634 default: // All the rest is the same (hopefully)
635 ret = (int) lund ;
636 }
637 return pdgId(ret);
638}
639
640
641
642unsigned Pdt::PdtNumHash(const int& num){
643
644 //Simple hash function from particle numbers
645
646 if (num>0) return num%PdtHashSize;
647 return (1-num)%PdtHashSize;
648}
649
650unsigned Pdt::PdtNameHash(const string& c){
651
652 int i;
653 int hash=0;
654
655 for(i=0;i<(int)c.length();i++){
656 hash=(153*hash+(int)c[i])%PdtHashSize;
657 }
658
659 return hash;
660
661}
662
664 return Pdt::sameOrConj(Pdt::lookup(id1),Pdt::lookup(id2));
665}
666
668 return Pdt::sameOrConj(Pdt::lookup(id1),Pdt::lookup(id2));
669}
670
671bool Pdt::sameOrConj( PdtEntry* pdt1, PdtEntry* pdt2) {
672 if ( (pdt1==0) || (pdt2==0) ) return false;
673 if ( pdt1->pdgId() == pdt2->pdgId() ) return true;
674 if ( pdt1->conjugate()->pdgId() == pdt2->pdgId() ) return true;
675 return false;
676}
677
678
679
680const PdtEntry*
682{
683 if( pdt==0 ) return 0;
684 PdtEntry* conjPdt = (PdtEntry*) pdt;
685
686 // get the key
687 int key = (int) pdt->pdgId();
688
689 // switch the key
690 key *= -1;
691
692 // look for an entry in the dictionary
693
694 map<int, PdtEntry*>::iterator iter=_entries->find(key);
695
696 if ( iter!=_entries->end() ) {
697 //found a match.
698 conjPdt=iter->second;
699 }
700 //otherwise its self conjugate - we should just return..
701
702 // return the conjugate
703 return conjPdt;
704}
705
706
707
708
double mass
string::const_iterator ptype
Definition: EvtMTree.hh:19
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared cut
Definition: KarFin.h:27
#define HBARC
Definition: Pdt.cxx:51
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
Definition: Taupair.h:42
virtual int size() const
virtual void clear()
virtual T *& insert(const std::string &key)
PdtPid::PidNeutralType pidNeutId() const
const PdtEntry * conjugate() const
Definition: PdtEntry.cxx:174
void addDecay(float bf, vector< PdtEntry * > *kids)
Definition: PdtEntry.cxx:105
void printOn(std::ostream &str) const
void printBFOn(std::ostream &str) const
static const PdtLund::LundType _lundId[52]
static float lifetime(PdtLund::LundType id)
static float width(PdtLund::LundType id)
static float charge(PdtLund::LundType id)
static void printOn(std::ostream &)
static PdtLund::LundType antiCode(PdtLund::LundType)
Definition: Pdt.cxx:73
static bool sameOrConj(PdtLund::LundType id1, PdtLund::LundType id2)
Definition: Pdt.cxx:663
static PdtPid::PidType pidId(const PdtLund::LundType)
Definition: Pdt.cxx:449
static void deleteAll()
Definition: Pdt.cxx:393
static void readMCppTable(std::string filenm)
static PdtGeant::GeantType geantId(const PdtLund::LundType)
Definition: Pdt.cxx:427
static PdtPdg::PdgType pdgId(const PdtLund::LundType)
Definition: Pdt.cxx:608
static PdtPid::PidNeutralType pidNeutId(const PdtLund::LundType)
Definition: Pdt.cxx:473
static PdtLund::LundType lundId(const PdtGeant::GeantType)
Definition: Pdt.cxx:413
static PdtEntry * lookup(const std::string &name)
Definition: Pdt.cxx:207
static const PdtEntry * conjugate(const PdtEntry *)
Definition: Pdt.cxx:681
static float spin(PdtLund::LundType id)
static void addParticle(const char *pname, PdtLund::LundType id, float spin, float charge, float mass, float width=0.0, float cut=0.0)
Definition: Pdt.cxx:91
static void addDecay(const char *pname, float bf, const char *child1, const char *child2=0, const char *child3=0, const char *child4=0, const char *child5=0)
Definition: Pdt.cxx:160