BOSS 8.0.0
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(zhangyao@ihep.ac.cn)
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/Pdt.h"
29#include "MdcRecoUtil/AstStringMap.h"
30#include "MdcRecoUtil/PdtEntry.h"
31
32#include <assert.h>
33#include <stdio.h>
34#include <string.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*>* Pdt::_entries = new map<int, PdtEntry*>;
59
60// By name
62
63// By geant number
64map<int, PdtEntry*>* Pdt::_entriesg = new map<int, PdtEntry*>;
65
66// By lund number
67map<int, PdtEntry*>* Pdt::_entriesl = new map<int, PdtEntry*>;
68
70
71 int kf = (int)kf_id;
72
73 int i2 = ( kf / 10 ) % 10;
74 int i3 = ( kf / 100 ) % 10;
75 int i4 = ( kf / 1000 ) % 10;
76
77 if ( i2 == i3 && i4 == 0 && kf > 100 ) return lundId( kf );
78 else if ( kf >= 21 && kf <= 23 ) return lundId( kf );
79
80 else if ( kf == 310 ) return lundId( 130 );
81 else if ( kf == 130 ) return lundId( 310 );
82
83 else return lundId( -kf );
84}
85
86void Pdt::addParticle( const char* pname, PdtLund::LundType id, float spin, float charge,
87 float mass, float width, float cut ) {
88
89 PdtEntry* nentry = new PdtEntry( pname, id, spin, charge, mass, width, cut );
90 ( *_entries )[pdgId( id )] = nentry;
91
92 if ( ( *_entriesn )[pname] != 0 )
93 {
94 // cout << "Pdt::addParticle:adding existing particle:"<<pname<<endl;
95 }
96
97 _entriesn->insert( pname ) = nentry;
98 if ( PdtGeant::null != nentry->geantId() ) { ( *_entriesg )[nentry->geantId()] = nentry; }
99
100 ( *_entriesl )[id] = nentry;
101
102 if ( PdtPid::null != nentry->pidId() )
103 {
104 if ( nentry->charge() > 0 ) { _positiveEntries[nentry->pidId()] = nentry; }
105 else { _negativeEntries[nentry->pidId()] = nentry; }
106 }
107
108 if ( PdtPid::none != nentry->pidNeutId() )
109 {
110 if ( nentry->charge() == 0 ) { _neutralEntries[nentry->pidNeutId()] = nentry; }
111 }
112}
113
114void Pdt::addParticle( const char* pname, PdtGeant::GeantType id, float spin, float charge,
115 float mass, float width, float cut ) {
116
117 PdtEntry* nentry = new PdtEntry( pname, id, spin, charge, mass, width, cut );
118
119 ( *_entries )[pdgId( id )] = nentry;
120 if ( ( *_entriesn )[pname] != 0 )
121 {
122 // cout << "Pdt::addParticle:adding existing particle:"<<pname<<endl;
123 }
124
125 _entriesn->insert( pname ) = nentry;
126 if ( PdtGeant::null != nentry->geantId() ) { ( *_entriesg )[id] = nentry; }
127
128 ( *_entriesl )[lundId( id )] = nentry;
129
130 if ( PdtPid::null != nentry->pidId() )
131 {
132 if ( nentry->charge() > 0 ) { _positiveEntries[nentry->pidId()] = nentry; }
133 else { _negativeEntries[nentry->pidId()] = nentry; }
134 }
135
136 if ( PdtPid::none != nentry->pidNeutId() )
137 {
138 if ( nentry->charge() == 0 ) { _neutralEntries[nentry->pidNeutId()] = nentry; }
139 }
140}
141
142void Pdt::addDecay( const char* pname, float bf, const char* child1, const char* child2,
143 const char* child3, const char* child4, const char* child5 ) {
144
145 PdtEntry* primary = lookup( pname );
146 if ( primary == 0 ) return;
147 const char* children[5] = { child1, child2, child3, child4, child5 };
148
149 vector<PdtEntry*>* kids = new vector<PdtEntry*>;
150
151 int nkids;
152 for ( nkids = 0; nkids < 5 && children[nkids] != 0; nkids++ )
153 {
154 PdtEntry* secondary = lookup( children[nkids] );
155 if ( secondary == 0 ) break;
156 kids->push_back( secondary );
157 }
158
159 primary->addDecay( bf, kids );
160}
161
164 PdtLund::LundType child4, PdtLund::LundType child5 ) {
165
166 PdtEntry* primary = lookup( id );
167 if ( primary == 0 ) return;
168
169 PdtLund::LundType children[5] = { child1, child2, child3, child4, child5 };
170 vector<PdtEntry*>* kids = new vector<PdtEntry*>;
171
172 int nkids;
173 for ( nkids = 0; nkids < 5 && children[nkids] != 0; nkids++ )
174 {
175 PdtEntry* secondary = lookup( children[nkids] );
176 if ( secondary == 0 ) break;
177 kids->push_back( secondary );
178 }
179
180 primary->addDecay( bf, kids );
181}
182
183PdtEntry* Pdt::lookup( const std::string& name ) { return ( *_entriesn )[name]; }
184
186 // look for the particle by Particle Data Group id
187 return ( *_entriesl )[id];
188}
189
191 // look for the particle by GEANT id
192 return ( *_entriesg )[id];
193}
194
196 // look for the particle by PDG id
197 return ( *_entries )[id];
198}
199
201
202 // look for the particle by PID code id and charge
203 if ( id == PdtPid::null ) return lookup( PdtLund::null );
204 if ( charge > 0 ) return _positiveEntries[id];
205 return _negativeEntries[id];
206}
207
209
210 // look for the particle by PID code id and charge
211
212 if ( id == PdtPid::none ) return lookup( PdtLund::null );
213 return _neutralEntries[id];
214}
215
216void Pdt::printOn( ostream& cout ) {
217
218 // lange move printouts here
219 cout << "Number of particles in tables: " << endl
220 << "By pdt number :" << _entries->size() << endl
221 << "By name :" << _entriesn->size() << endl
222 << "By geant number :" << _entriesg->size() << endl
223 << "By lund number :" << _entriesl->size() << endl;
224
225 cout << '\n';
226 int i;
227 for ( i = 0; i < 72; i++ ) cout << '-';
228 cout << '\n';
229
230 cout << " Particle Data Table\n\n";
231 cout << " id name mass width spin charge lifetime\n";
232 cout << " (GeV) (GeV) (cm) \n";
233 for ( i = 0; i < 72; i++ ) cout << '-';
234 cout << '\n';
235
236 PdtEntry* p;
237
238 map<int, PdtEntry*>::iterator iter = _entries->begin();
239
240 while ( iter != _entries->end() )
241 {
242 p = iter->second;
243 assert( 0 != p );
244 p->printOn( cout );
245 p->printBFOn( cout );
246 ++iter;
247 }
248 cout << '\n';
249 for ( i = 0; i < 72; i++ ) cout << '-';
250 cout << '\n';
251
252 map<int, PdtEntry*>::iterator iter1 = _entries->begin();
253
254 while ( iter1 != _entries->end() )
255 {
256 p = iter1->second;
257 cout << "The conjuate of " << p->name() << " is ";
258 cout << conjugate( p )->name() << endl;
259 iter1++;
260 }
261}
262
263void Pdt::readMCppTable( string filenm ) {
264
265 string path = filenm;
266 char line[512];
267 FILE* ifl = fopen( path.c_str(), "r" );
268
269 if ( 0 == ifl )
270 cout << " Pdt::readMCppTable: please copy " << filenm << " in to your run directory!"
271 << std::endl;
272 assert( 0 != ifl );
273
274 while ( fgets( line, 512, ifl ) )
275 {
276 if ( strlen( line ) >= 511 )
277 {
278 cerr << "Pdt.read : input line is too long\n";
279 assert( 0 );
280 }
281 istrstream linestr( line );
282 string opcode;
283 char subcode;
284 linestr >> opcode >> subcode;
285
286 if ( opcode == "end" ) break;
287
288 else if ( opcode == "add" )
289 {
290 switch ( subcode )
291 {
292 case 'p': {
293 string classname;
294 linestr >> classname;
295 // if (classname == "Collision" || classname == "Parton")
296 if ( classname == "Collision" ) continue;
297
298 string name;
299 int type;
300 float mass, width, cut, charge, spin, lifetime;
301
302 linestr >> name >> type;
303 linestr >> mass >> width >> cut >> charge;
304 linestr >> spin >> lifetime;
305
306 charge /= 3.0;
307 if ( classname != "Meson" ) spin /= 2.0;
308
309 // lifetime is c*tau (mm)
310 if ( lifetime > 0.0 && width < 1e-10 ) width = HBARC / ( lifetime / 10.0 );
311
312 addParticle( name.c_str(), lundId( type ), spin, charge, mass, width, cut );
313 break;
314 }
315
316 case 'c': {
317 int ptype, nchild;
318 float bf;
319 string decayer;
320
321 linestr >> ptype >> bf >> decayer >> nchild;
322 PdtEntry* parent = lookup( lundId( ptype ) );
323 if ( parent == 0 ) continue;
324
325 vector<PdtEntry*>* kids = new vector<PdtEntry*>;
326
327 int i;
328 for ( i = 0; i < nchild; i++ )
329 {
330 int ctype;
331 linestr >> ctype;
332 PdtEntry* secondary = lookup( lundId( ctype ) );
333 if ( secondary == 0 ) break;
334 kids->push_back( secondary );
335 }
336
337 parent->addDecay( bf, kids );
338 break;
339 }
340
341 case 'd': break;
342
343 default:
344 cerr << "Pdt.readMCppTable : unknown subcode '" << subcode << "' for operation add\n";
345 break;
346 }
347 }
348 }
349 // adding geantino for GEANT studies
350 // why why why why - shouldn't you do this in the tables?
351 // addParticle("geantino", PdtGeant::geantino, 0., 0., 0., 0., 0. );
352
353 fclose( ifl );
354}
355
357
358 PdtEntry* p;
359
360 map<int, PdtEntry*>::iterator iter = _entries->begin();
361
362 while ( iter != _entries->end() )
363 {
364 p = iter->second;
365 assert( 0 != p );
366 delete p;
367 ++iter;
368 }
369
370 _entries->clear();
371 _entriesn->clear();
372 _entriesg->clear();
373 _entriesl->clear();
374}
375
377
378 if ( gId == PdtGeant::deuteron || gId == PdtGeant::tritium || gId == PdtGeant::alpha ||
379 gId == PdtGeant::geantino || gId == PdtGeant::He3 || gId == PdtGeant::Cerenkov )
380 { return PdtLund::null; }
381 else { return PdtGeant::_lundId[gId - PdtGeant::_firstGeantId]; }
382}
383
385
386 //
387 // special case:
388 // GEANT has only one neutrino
389 //
390 if ( lId == PdtLund::nu_e || lId == PdtLund::anti_nu_e || lId == PdtLund::nu_mu ||
391 lId == PdtLund::anti_nu_mu || lId == PdtLund::nu_tau || lId == PdtLund::anti_nu_tau )
392 { return PdtGeant::nu_e; }
393 else
394 {
395 int i;
396 for ( i = 0; i < PdtGeant::_nGeantId; i++ )
397 {
398 if ( PdtGeant::_lundId[i] == lId ) return geantId( i );
399 }
400 return PdtGeant::null;
401 }
402}
403
405
406 switch ( lId )
407 {
408 case PdtLund::e_minus:
411 case PdtLund::mu_plus: return PdtPid::muon;
413 case PdtLund::pi_plus: return PdtPid::pion;
414 case PdtLund::K_minus:
415 case PdtLund::K_plus: return PdtPid::kaon;
416 case PdtLund::p_plus:
418 default: return PdtPid::null;
419 }
420}
421
423
424 switch ( lId )
425 {
426 case PdtLund::gamma: return PdtPid::gamma;
427 case PdtLund::pi0: return PdtPid::pi0;
428 case PdtLund::K_L0: return PdtPid::K0L;
430 case PdtLund::n0: return PdtPid::neutron;
431 default: return PdtPid::none;
432 }
433}
434
436
440
442 return geantId( lundId( pId, charge ) );
443}
444
446 return geantId( lundId( pId, charge ) );
447}
448
450
451 if ( charge == -1 )
452 {
453 switch ( pId )
454 {
456 case PdtPid::muon: return PdtLund::pi_minus;
457 case PdtPid::pion: return PdtLund::pi_minus;
458 case PdtPid::kaon: return PdtLund::K_minus;
460 default: return PdtLund::null;
461 }
462 }
463 else if ( charge == 1 )
464 {
465 switch ( pId )
466 {
468 case PdtPid::muon: return PdtLund::pi_plus;
469 case PdtPid::pion: return PdtLund::pi_plus;
470 case PdtPid::kaon: return PdtLund::K_plus;
471 case PdtPid::proton: return PdtLund::p_plus;
472 default: return PdtLund::null;
473 }
474 }
475 else
476 {
477 cerr << "error: wrong charge; must be +1 or -1" << endl;
478 return PdtLund::null;
479 }
480}
481
483
484 if ( charge == 0 )
485 {
486 switch ( pId )
487 {
488 case PdtPid::gamma: return PdtLund::gamma;
489 case PdtPid::pi0: return PdtLund::pi0;
490 case PdtPid::K0L: return PdtLund::K_L0;
491 case PdtPid::neutron: return PdtLund::n0;
493 default: return PdtLund::null;
494 }
495 }
496 else
497 {
498 cerr << "error: wrong charge; must be +1 or -1" << endl;
499 return PdtLund::null;
500 }
501}
502
504
505 int ret;
506 switch ( (int)pdg )
507 {
508 case 551: // chi_0b
509 ret = 10551;
510 case 10443: // chi_1c
511 ret = 20443;
512 case 20443: // psi(2S)
513 ret = 30443;
514 case 30443: // psi(3770)
515 ret = 40443;
516 case 20553: // Upsilon(2S)
517 ret = 30553;
518 case 4322: // Xi_c+
519 ret = 4232;
520 case -4322: // Anti Xi_c+
521 ret = -4232;
522 case 4232: // Xi'_c+
523 ret = 4322;
524 case -4232: // Anti Xi'_c+
525 ret = -4322;
526 default: // All the rest is the same (hopefully)
527 ret = (int)pdg;
528 }
529 return lundId( ret );
530}
531
533
534 int ret;
535 switch ( (int)lund )
536 {
537 case 551: // eta_b does not exist in PDG
538 ret = 0;
539 case 10551: // chi_0b
540 ret = 551;
541 case 10443: // h_1c does not exist in PDG
542 ret = 0;
543 case 20443: // chi_1c
544 ret = 10443;
545 case 30443: // psi(2S)
546 ret = 20443;
547 case 40443: // psi(3770)
548 ret = 30443;
549 case 30553: // Upsilon(2S)
550 ret = 20553;
551 case 4232: // Xi_c+
552 ret = 4322;
553 case -4232: // Anti Xi_c+
554 ret = -4322;
555 case 4322: // Xi'_c+
556 ret = 4232;
557 case -4322: // Anti Xi'_c+
558 ret = -4232;
559 default: // All the rest is the same (hopefully)
560 ret = (int)lund;
561 }
562 return pdgId( ret );
563}
564
565unsigned Pdt::PdtNumHash( const int& num ) {
566
567 // Simple hash function from particle numbers
568
569 if ( num > 0 ) return num % PdtHashSize;
570 return ( 1 - num ) % PdtHashSize;
571}
572
573unsigned Pdt::PdtNameHash( const string& c ) {
574
575 int i;
576 int hash = 0;
577
578 for ( i = 0; i < (int)c.length(); i++ ) { hash = ( 153 * hash + (int)c[i] ) % PdtHashSize; }
579
580 return hash;
581}
582
584 return Pdt::sameOrConj( Pdt::lookup( id1 ), Pdt::lookup( id2 ) );
585}
586
588 return Pdt::sameOrConj( Pdt::lookup( id1 ), Pdt::lookup( id2 ) );
589}
590
591bool Pdt::sameOrConj( PdtEntry* pdt1, PdtEntry* pdt2 ) {
592 if ( ( pdt1 == 0 ) || ( pdt2 == 0 ) ) return false;
593 if ( pdt1->pdgId() == pdt2->pdgId() ) return true;
594 if ( pdt1->conjugate()->pdgId() == pdt2->pdgId() ) return true;
595 return false;
596}
597
598const PdtEntry* Pdt::conjugate( const PdtEntry* pdt ) {
599 if ( pdt == 0 ) return 0;
600 PdtEntry* conjPdt = (PdtEntry*)pdt;
601
602 // get the key
603 int key = (int)pdt->pdgId();
604
605 // switch the key
606 key *= -1;
607
608 // look for an entry in the dictionary
609
610 map<int, PdtEntry*>::iterator iter = _entries->find( key );
611
612 if ( iter != _entries->end() )
613 {
614 // found a match.
615 conjPdt = iter->second;
616 }
617 // otherwise its self conjugate - we should just return..
618
619 // return the conjugate
620 return conjPdt;
621}
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
const PdtEntry * conjugate() const
Definition PdtEntry.cxx:171
void addDecay(float bf, vector< PdtEntry * > *kids)
Definition PdtEntry.cxx:107
void printOn(std::ostream &str) const
void printBFOn(std::ostream &str) const
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:69
static bool sameOrConj(PdtLund::LundType id1, PdtLund::LundType id2)
Definition Pdt.cxx:583
static PdtPid::PidType pidId(const PdtLund::LundType)
Definition Pdt.cxx:404
static float mass(PdtLund::LundType id)
static void deleteAll()
Definition Pdt.cxx:356
static void readMCppTable(std::string filenm)
static PdtGeant::GeantType geantId(const PdtLund::LundType)
Definition Pdt.cxx:384
static PdtPdg::PdgType pdgId(const PdtLund::LundType)
Definition Pdt.cxx:532
static PdtPid::PidNeutralType pidNeutId(const PdtLund::LundType)
Definition Pdt.cxx:422
static PdtLund::LundType lundId(const PdtGeant::GeantType)
Definition Pdt.cxx:376
static PdtEntry * lookup(const std::string &name)
Definition Pdt.cxx:183
static const PdtEntry * conjugate(const PdtEntry *)
Definition Pdt.cxx:598
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:86
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:142