ATLAS Offline Software
VP1ParticleData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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  IPartPropSvc* partPropSvc;
60  StatusCode status = svcLocator->service( "PartPropSvc",partPropSvc,true/*createifnotthere*/ );
61  if(!status.isSuccess()||!partPropSvc) {
62  VP1Msg::message("VP1ParticleData ERROR: Could not get particle property service.");
63  Imp::m_badInit = true;
64  return 0;
65  }
66  const HepPDT::ParticleDataTable* tab = partPropSvc->PDT();
68  if (!tab) {
69  VP1Msg::message("VP1ParticleData ERROR: Could not get particle data table from particle property service.");
70  Imp::m_badInit = true;
71  return 0;
72  }
73  }
74 
75  const HepPDT::ParticleData* particle =
76  Imp::m_particleDataTable->particle(HepPDT::ParticleID(pdgcode));
77  if (!particle&&VP1Msg::verbose())
78  VP1Msg::messageVerbose("VP1ParticleData WARNING: Could not get particle data table for pdgcode="+QString::number(pdgcode));
79 
80  return particle;
81 }
82 
83 //____________________________________________________________________
84 double VP1ParticleData::particleMass( const int& pdgcode, bool& ok )
85 {
86  std::map<int,double>::const_iterator it = Imp::m_particleAbsPDGCodeToMass.find(abs(pdgcode));
88  ok = it->second != Imp::m_badValue;
89  return ok ? it->second : 0;
90  }
91  const HepPDT::ParticleData * data = particleData( abs(pdgcode) );
92  double m;
93  if (data)
94  m = data->mass().value();
95  else
97 
98  Imp::m_particleAbsPDGCodeToMass[abs(pdgcode)] = m;
99  ok = m != Imp::m_badValue;
100  return m;
101 }
102 
103 //____________________________________________________________________
104 double VP1ParticleData::particleCharge( const int& pdgcode, bool& ok )
105 {
106  if (pdgcode==22) {
107  ok = true;
108  return 0.0;
109  }
110  std::map<int,double>::const_iterator it = Imp::m_particlePDGCodeToCharge.find(pdgcode);
112  ok = it->second != Imp::m_badValue;
113  return ok ? it->second : 0;
114  }
115  const HepPDT::ParticleData * data = particleData( abs(pdgcode) );
116  double c;
117  if (data)
118  c = pdgcode >= 0 ? data->charge() : - data->charge();
119  else
120  c = Imp::m_badValue;
121 
123  ok = c != Imp::m_badValue;
124  return c;
125 }
126 
127 //____________________________________________________________________
128 QString VP1ParticleData::particleName( const int& pdgcode, bool& ok )
129 {
130  std::map<int,QString>::const_iterator it = Imp::m_particleAbsPDGCodeToName.find(pdgcode);
132  ok = (it->second != Imp::m_badName);
133  return ok ? it->second : "";
134  }
135 
136  QString name;
137  switch (pdgcode) {
138  case 21: name = "gluon"; break;
139  case 22: name = "photon"; break;
140  case -11: name = "e+"; break;
141  case 11: name = "e-"; break;
142  case -13: name = "mu+"; break;
143  case 13: name = "mu-"; break;
144  case -15: name = "tau+"; break;
145  case 15: name = "tau-"; break;
146  case -211: name = "M_PI-"; break;
147  case 211: name = "M_PI+"; break;
148  case 1: name = "d" ; break;
149  case 2: name = "u" ; break;
150  case 3: name = "s" ; break;
151  case 4: name = "c" ; break;
152  case 5: name = "b" ; break;
153  case 6: name = "t" ; break;
154  case -1: name = "dbar" ; break;
155  case -2: name = "ubar" ; break;
156  case -3: name = "sbar" ; break;
157  case -4: name = "cbar" ; break;
158  case -5: name = "bbar" ; break;
159  case -6: name = "tbar" ; break;
160  case 92: name = "frag string" ; break;
161  default:
162  break;
163  }
164 
165  if (name.isEmpty()) {
166  const HepPDT::ParticleData * data = particleData( abs(pdgcode) );
167  if (data)
168  name = (pdgcode<0?"anti-":"")+QString(data->name().c_str());//fixme: anything [[:alpha:]](+|-) we
169  // change + and -
170  else
172  }
173 
175  ok = (name != Imp::m_badName);
176  return name;
177 }
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:423
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
VP1ParticleData::particleCharge
static double particleCharge(const int &pdgcode, bool &ok)
Definition: VP1ParticleData.cxx:104
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:195
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:84
VP1Msg::verbose
static bool verbose()
Definition: VP1Msg.h:31
merge.status
status
Definition: merge.py:17
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:128