ATLAS Offline Software
Loading...
Searching...
No Matches
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//____________________________________________________________________
27public:
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
38const HepPDT::ParticleDataTable * VP1ParticleData::Imp::m_particleDataTable = 0;
42const double VP1ParticleData::Imp::m_badValue = -1.0e99;
43const QString VP1ParticleData::Imp::m_badName = "_Bad_Name_";
44
45//____________________________________________________________________
46const HepPDT::ParticleData * VP1ParticleData::particleData( const int& pdgcode )
47{
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//____________________________________________________________________
83double VP1ParticleData::particleMass( const int& pdgcode, bool& ok )
84{
85 std::map<int,double>::const_iterator it = Imp::m_particleAbsPDGCodeToMass.find(abs(pdgcode));
86 if (it!=Imp::m_particleAbsPDGCodeToMass.end()) {
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//____________________________________________________________________
103double 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);
110 if (it!=Imp::m_particlePDGCodeToCharge.end()) {
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//____________________________________________________________________
127QString VP1ParticleData::particleName( const int& pdgcode, bool& ok )
128{
129 std::map<int,QString>::const_iterator it = Imp::m_particleAbsPDGCodeToName.find(pdgcode);
130 if (it!=Imp::m_particleAbsPDGCodeToName.end()) {
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
170 name = Imp::m_badName;
171 }
172
173 Imp::m_particleAbsPDGCodeToName[pdgcode] = name;
174 ok = (name != Imp::m_badName);
175 return name;
176}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static bool verbose()
Definition VP1Msg.h:31
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
static const HepPDT::ParticleDataTable * m_particleDataTable
static const QString m_badName
static const double m_badValue
static std::map< int, QString > m_particleAbsPDGCodeToName
static std::map< int, double > m_particleAbsPDGCodeToMass
static std::map< int, double > m_particlePDGCodeToCharge
static double particleMass(const int &pdgcode, bool &ok)
static double particleCharge(const int &pdgcode, bool &ok)
static QString particleName(const int &pdgcode, bool &ok)
static const HepPDT::ParticleData * particleData(const int &pdgcode)