ATLAS Offline Software
VP1ParticleData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1ParticleData //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: March 2008 //
12 // //
14 
16 #include "VP1Base/VP1Msg.h"
17 
18 #include "GaudiKernel/Bootstrap.h"
19 #include "GaudiKernel/ISvcLocator.h"
20 #include "GaudiKernel/IPartPropSvc.h"
21 
22 #include "HepPDT/ParticleDataTable.hh"
23 #include "HepPDT/ParticleData.hh"
24 
25 //____________________________________________________________________
27 public:
28  static bool m_badInit;
29  static const HepPDT::ParticleDataTable * m_particleDataTable;
30  static std::map<int,double> m_particleAbsPDGCodeToMass;
31  static std::map<int,double> m_particlePDGCodeToCharge;
32  static std::map<int,QString> m_particleAbsPDGCodeToName;
33  static const double m_badValue;
34  static const QString m_badName;
35 };
36 
38 const HepPDT::ParticleDataTable * VP1ParticleData::Imp::m_particleDataTable = 0;
42 const double VP1ParticleData::Imp::m_badValue = -1.0e99;
43 const QString VP1ParticleData::Imp::m_badName = "_Bad_Name_";
44 
45 //____________________________________________________________________
46 const HepPDT::ParticleData * VP1ParticleData::particleData( const int& pdgcode )
47 {
48  if (Imp::m_badInit)
49  return 0;
51  //init
52  ISvcLocator* svcLocator = Gaudi::svcLocator();
53  if (!svcLocator) {
54  VP1Msg::message("VP1ParticleData ERROR: Could not get svcLocator.");
55  Imp::m_badInit = true;
56  return 0;
57  }
58 
59  SmartIF<IPartPropSvc> partPropSvc{svcLocator->service( "PartPropSvc" )};
60  if(!partPropSvc) {
61  VP1Msg::message("VP1ParticleData ERROR: Could not get particle property service.");
62  Imp::m_badInit = true;
63  return 0;
64  }
65  const HepPDT::ParticleDataTable* tab = partPropSvc->PDT();
67  if (!tab) {
68  VP1Msg::message("VP1ParticleData ERROR: Could not get particle data table from particle property service.");
69  Imp::m_badInit = true;
70  return 0;
71  }
72  }
73 
74  const HepPDT::ParticleData* particle =
75  Imp::m_particleDataTable->particle(HepPDT::ParticleID(pdgcode));
76  if (!particle&&VP1Msg::verbose())
77  VP1Msg::messageVerbose("VP1ParticleData WARNING: Could not get particle data table for pdgcode="+QString::number(pdgcode));
78 
79  return particle;
80 }
81 
82 //____________________________________________________________________
83 double VP1ParticleData::particleMass( const int& pdgcode, bool& ok )
84 {
85  std::map<int,double>::const_iterator it = Imp::m_particleAbsPDGCodeToMass.find(abs(pdgcode));
87  ok = it->second != Imp::m_badValue;
88  return ok ? it->second : 0;
89  }
90  const HepPDT::ParticleData * data = particleData( abs(pdgcode) );
91  double m;
92  if (data)
93  m = data->mass().value();
94  else
96 
97  Imp::m_particleAbsPDGCodeToMass[abs(pdgcode)] = m;
98  ok = m != Imp::m_badValue;
99  return m;
100 }
101 
102 //____________________________________________________________________
103 double VP1ParticleData::particleCharge( const int& pdgcode, bool& ok )
104 {
105  if (pdgcode==22) {
106  ok = true;
107  return 0.0;
108  }
109  std::map<int,double>::const_iterator it = Imp::m_particlePDGCodeToCharge.find(pdgcode);
111  ok = it->second != Imp::m_badValue;
112  return ok ? it->second : 0;
113  }
114  const HepPDT::ParticleData * data = particleData( abs(pdgcode) );
115  double c;
116  if (data)
117  c = pdgcode >= 0 ? data->charge() : - data->charge();
118  else
119  c = Imp::m_badValue;
120 
122  ok = c != Imp::m_badValue;
123  return c;
124 }
125 
126 //____________________________________________________________________
127 QString VP1ParticleData::particleName( const int& pdgcode, bool& ok )
128 {
129  std::map<int,QString>::const_iterator it = Imp::m_particleAbsPDGCodeToName.find(pdgcode);
131  ok = (it->second != Imp::m_badName);
132  return ok ? it->second : "";
133  }
134 
135  QString name;
136  switch (pdgcode) {
137  case 21: name = "gluon"; break;
138  case 22: name = "photon"; break;
139  case -11: name = "e+"; break;
140  case 11: name = "e-"; break;
141  case -13: name = "mu+"; break;
142  case 13: name = "mu-"; break;
143  case -15: name = "tau+"; break;
144  case 15: name = "tau-"; break;
145  case -211: name = "M_PI-"; break;
146  case 211: name = "M_PI+"; break;
147  case 1: name = "d" ; break;
148  case 2: name = "u" ; break;
149  case 3: name = "s" ; break;
150  case 4: name = "c" ; break;
151  case 5: name = "b" ; break;
152  case 6: name = "t" ; break;
153  case -1: name = "dbar" ; break;
154  case -2: name = "ubar" ; break;
155  case -3: name = "sbar" ; break;
156  case -4: name = "cbar" ; break;
157  case -5: name = "bbar" ; break;
158  case -6: name = "tbar" ; break;
159  case 92: name = "frag string" ; break;
160  default:
161  break;
162  }
163 
164  if (name.isEmpty()) {
165  const HepPDT::ParticleData * data = particleData( abs(pdgcode) );
166  if (data)
167  name = (pdgcode<0?"anti-":"")+QString(data->name().c_str());//fixme: anything [[:alpha:]](+|-) we
168  // change + and -
169  else
171  }
172 
174  ok = (name != Imp::m_badName);
175  return name;
176 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
VP1ParticleData::Imp::m_badInit
static bool m_badInit
Definition: VP1ParticleData.cxx:28
VP1ParticleData::Imp::m_particleAbsPDGCodeToMass
static std::map< int, double > m_particleAbsPDGCodeToMass
Definition: VP1ParticleData.cxx:30
VP1Msg.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
VP1ParticleData.h
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
VP1ParticleData::Imp::m_badValue
static const double m_badValue
Definition: VP1ParticleData.cxx:33
VP1ParticleData::Imp::m_particleAbsPDGCodeToName
static std::map< int, QString > m_particleAbsPDGCodeToName
Definition: VP1ParticleData.cxx:32
VP1ParticleData::particleCharge
static double particleCharge(const int &pdgcode, bool &ok)
Definition: VP1ParticleData.cxx:103
jobOptions.ParticleID
ParticleID
Definition: jobOptions.decayer.py:85
VP1ParticleData::Imp::m_badName
static const QString m_badName
Definition: VP1ParticleData.cxx:34
VP1ParticleData::Imp
Definition: VP1ParticleData.cxx:26
python.selection.number
number
Definition: selection.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
VP1ParticleData::Imp::m_particlePDGCodeToCharge
static std::map< int, double > m_particlePDGCodeToCharge
Definition: VP1ParticleData.cxx:31
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
VP1ParticleData::Imp::m_particleDataTable
static const HepPDT::ParticleDataTable * m_particleDataTable
Definition: VP1ParticleData.cxx:29
VP1Msg::message
static void message(const QString &, IVP1System *sys=0)
Definition: VP1Msg.cxx:30
VP1ParticleData::particleMass
static double particleMass(const int &pdgcode, bool &ok)
Definition: VP1ParticleData.cxx:83
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
VP1ParticleData::particleData
static const HepPDT::ParticleData * particleData(const int &pdgcode)
Definition: VP1ParticleData.cxx:46
python.compressB64.c
def c
Definition: compressB64.py:93
VP1ParticleData::particleName
static QString particleName(const int &pdgcode, bool &ok)
Definition: VP1ParticleData.cxx:127