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
20
21#include <cstdlib>
22
23//____________________________________________________________________
25public:
27 static std::map<int,double> m_particleAbsPDGCodeToMass;
28 static std::map<int,double> m_particlePDGCodeToCharge;
29 static std::map<int,QString> m_particleAbsPDGCodeToName;
30 static const double m_badValue;
31 static const QString m_badName;
32};
33
38const double VP1ParticleData::Imp::m_badValue = -1.0e99;
39const QString VP1ParticleData::Imp::m_badName = "_Bad_Name_";
40
41//____________________________________________________________________
42double VP1ParticleData::particleMass( const int& pdgcode, bool& ok )
43{
44 const int absPdgCode = std::abs(pdgcode);
45 std::map<int,double>::const_iterator it = Imp::m_particleAbsPDGCodeToMass.find(absPdgCode);
46 if (it!=Imp::m_particleAbsPDGCodeToMass.end()) {
47 ok = it->second != Imp::m_badValue;
48 return ok ? it->second : 0;
49 }
50 const auto mOpt = Imp::m_genData.particleMass(absPdgCode);
51 const double m = mOpt.value_or(Imp::m_badValue);
52
53 Imp::m_particleAbsPDGCodeToMass[absPdgCode] = m;
54 ok = m != Imp::m_badValue;
55 return m;
56}
57
58//____________________________________________________________________
59double VP1ParticleData::particleCharge( const int& pdgcode, bool& ok )
60{
61 if (pdgcode==22) {
62 ok = true;
63 return 0.0;
64 }
65 std::map<int,double>::const_iterator it = Imp::m_particlePDGCodeToCharge.find(pdgcode);
66 if (it!=Imp::m_particlePDGCodeToCharge.end()) {
67 ok = it->second != Imp::m_badValue;
68 return ok ? it->second : 0;
69 }
70 const double c = MC::isValid(pdgcode) ? MC::charge(pdgcode) : Imp::m_badValue;
71 if (c == Imp::m_badValue && VP1Msg::verbose()) {
72 VP1Msg::messageVerbose("VP1ParticleData WARNING: Invalid PDG code for charge lookup pdgcode="+QString::number(pdgcode));
73 }
74
76 ok = c != Imp::m_badValue;
77 return c;
78}
79
80//____________________________________________________________________
81QString VP1ParticleData::particleName( const int& pdgcode, bool& ok )
82{
83 std::map<int,QString>::const_iterator it = Imp::m_particleAbsPDGCodeToName.find(pdgcode);
84 if (it!=Imp::m_particleAbsPDGCodeToName.end()) {
85 ok = (it->second != Imp::m_badName);
86 return ok ? it->second : "";
87 }
88
89 QString name;
90 switch (pdgcode) {
91 case 21: name = "gluon"; break;
92 case 22: name = "photon"; break;
93 case -11: name = "e+"; break;
94 case 11: name = "e-"; break;
95 case -13: name = "mu+"; break;
96 case 13: name = "mu-"; break;
97 case -15: name = "tau+"; break;
98 case 15: name = "tau-"; break;
99 case -211: name = "pi-"; break;
100 case 211: name = "pi+"; break;
101 case 1: name = "d" ; break;
102 case 2: name = "u" ; break;
103 case 3: name = "s" ; break;
104 case 4: name = "c" ; break;
105 case 5: name = "b" ; break;
106 case 6: name = "t" ; break;
107 case -1: name = "dbar" ; break;
108 case -2: name = "ubar" ; break;
109 case -3: name = "sbar" ; break;
110 case -4: name = "cbar" ; break;
111 case -5: name = "bbar" ; break;
112 case -6: name = "tbar" ; break;
113 case 92: name = "frag string" ; break;
114 default:
115 break;
116 }
117
118 if (name.isEmpty()) {
119 const auto nameOpt = Imp::m_genData.particleName(std::abs(pdgcode));
120 if (nameOpt)
121 name = (pdgcode<0?"anti-":"")+QString::fromStdString(*nameOpt);//fixme: anything [[:alpha:]](+|-) we
122 // change + and -
123 else
124 name = Imp::m_badName;
125 }
126
127 Imp::m_particleAbsPDGCodeToName[pdgcode] = name;
128 ok = (name != Imp::m_badName);
129 return name;
130}
ATLAS-specific HepMC functions.
GenData is a class for particle data access.
Definition GenData.h:18
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static bool verbose()
Definition VP1Msg.h:31
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)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
double charge(const T &p)