Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
JPDB.hh
Go to the documentation of this file.
1#ifndef __JAANET__JPDB__
2#define __JAANET__JPDB__
3
4#include <string>
5#include <ostream>
6#include <iomanip>
7#include <vector>
8#include <algorithm>
9
11
13#include "JPhysics/JCharges.hh"
14
15#include "JLang/JPredicate.hh"
16#include "JLang/JException.hh"
17#include "JLang/JManip.hh"
18
19#include "TDatabasePDG.h"
20#include "TParticlePDG.h"
21#include "TCollection.h"
22#include "THashList.h"
23
24
25/**
26 * \author mdejong
27 */
28
29namespace JAANET {}
30namespace JPP { using namespace JAANET; }
31
32namespace JAANET {
33
35
37
38
39 /**
40 * Auxiliary class to handle particle name, codes and mass.
41 */
42 struct JParticle {
43 /**
44 * Default constructor.
45 */
47 name(""), pdg(0), geant(0), mass(0.0), charge(0)
48 {}
49
50
51 /**
52 * Constructor.
53 *
54 * \param name name of particle
55 * \param pdg PDG code of particle
56 * \param geant GEANT code of particle
57 * \param mass mass of particle
58 * \param charge electric charge of particle
59 */
60 JParticle(const std::string& name,
61 const int pdg,
62 const int geant,
63 const double mass,
64 const JElectricCharge& charge) :
66 {}
67
68
69 /**
70 * Print particle.
71 *
72 * \param out output stream
73 * \param particle particle
74 * \return output stream
75 */
76 friend inline std::ostream& operator<<(std::ostream& out, const JParticle& particle)
77 {
78 using namespace std;
79 using namespace JPP;
80
81 return out << setw(32) << left << particle.name << " "
82 << setw( 8) << right << particle.pdg << " "
83 << setw( 6) << right << particle.geant << " "
84 << FIXED(16,10) << particle.mass << " "
85 << setw( 5) << right << static_cast<int>(particle.charge);
86 }
87
88
89 std::string name; //!< name of particle
90 int pdg; //!< PDG code of particle
91 int geant; //!< GEANT code of particle
92 double mass; //!< mass of particle [GeV]
93 JElectricCharge charge; //!< electric charge of particle [|e|/3]
94 };
95
96
97 /**
98 * Auxiliary macro for particle creation.
99 *
100 * \param PDG PDG code
101 * \param GEANT GEANT code
102 * \param MASS mass
103 */
104#define MAKE_PARTICLE(PDG, GEANT, MASS, CHARGE) JParticle(#PDG, PDG, GEANT, MASS, CHARGE)
105
106
107 /**
108 * Collection of particles.
109 */
110 struct JPDB :
111 public std::vector<JParticle>
112 {
113 /**
114 * Default constructor.
115 */
117 {}
118
119
120 /**
121 * Get particle data book.
122 * This particle data book contains all known GEANT particle codes.
123 *
124 * \return particle data book
125 */
126 static const JPDB& getInstance()
127 {
128 using namespace JPP;
129
130 static JPDB pdb;
131
132 if (pdb.empty()) {
133
134 TDatabasePDG::Instance()->ReadPDGTable();
135
136 TIter next(TDatabasePDG::Instance()->ParticleList());
137
138 while (TParticlePDG* p = (TParticlePDG*) next()) {
139
140 const JParticle particle(p->GetName(), p->PdgCode(), convertPDGtoGEANT(p->PdgCode()), p->Mass(), int(p->Charge()));
141
142 pdb.push_back(particle);
143 }
144 }
145
146 return pdb;
147 }
148
149
150 /**
151 * Check if PDB has particle corresponding to given GEANT code.
152 *
153 * \param geant GEANT code
154 * \return true if available; else false
155 */
156 inline bool hasGEANT(const int geant) const
157 {
158 return (find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::geant, geant)) != this->end());
159 }
160
161
162 /**
163 * Get particle corresponding to given GEANT code.\n
164 * This method throws an error if the particle cannot be found.
165 *
166 * \param geant GEANT code
167 * \return particle
168 */
169 inline const JParticle& getGEANT(const int geant) const
170 {
171 const_iterator p = find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::geant, geant));
172
173 if (p != this->end())
174 return *p;
175 else
176 THROW(JException, "Invalid GEANT particle code " << geant);
177 }
178
179
180 /**
181 * Retrieve GEANT code for a given PDG code.
182 *
183 * \param pdg PDG code
184 * \return GEANT code
185 */
186 static int convertPDGtoGEANT(const int pdg)
187 {
188 switch (pdg) {
189
190 case TRACK_TYPE_NUE:
191 case TRACK_TYPE_NUMU:
192 case TRACK_TYPE_NUTAU:
197
200
203
206
209
210 default:
211 return TDatabasePDG::Instance()->ConvertPdgToGeant3(pdg);
212 }
213 }
214
215
216 /**
217 * Check if PDB has particle corresponding to given PDG code.
218 *
219 * \param pdg PDG code
220 * \return true if available; else false
221 */
222 inline bool hasPDG(const int pdg) const
223 {
224 return (find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::pdg, pdg)) != this->end());
225 }
226
227
228 /**
229 * Get particle corresponding to given PDG code.\n
230 * This method throws an error if the particle cannot be found.
231 *
232 * \param pdg PDG code
233 * \return particle
234 */
235 inline const JParticle& getPDG(const int pdg) const
236 {
237 const_iterator p = find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::pdg, pdg));
238
239 if (p != this->end())
240 return *p;
241 else
242 THROW(JException, "Invalid PDG particle code " << pdg);
243 }
244
245
246 /**
247 * Print particle data book.
248 *
249 * \param out output stream
250 * \param pdb particle data book
251 * \return output stream
252 */
253 friend inline std::ostream& operator<<(std::ostream& out, const JPDB& pdb)
254 {
255 using namespace std;
256
257 out << setw(32) << left << "particle" << " "
258 << setw( 8) << right << "PDG" << " "
259 << setw( 6) << right << "GEANT" << " "
260 << setw(16) << right << "Mass [GeV]" << " "
261 << setw( 5) << right << "Charge [|e|/3]" << endl;
262
263 for (JPDB::const_iterator i = pdb.begin(); i != pdb.end(); ++i) {
264 out << *i << endl;
265 }
266
267 return out;
268 }
269 };
270
271
272 /**
273 * Selection of particle data book entries.
274 */
276 public JPDB
277 {
278 /**
279 * Constructor.
280 *
281 * \param pdgs pdg codes
282 */
284 {
285 using namespace JPP;
286
287 const JPDB& PDB = JPDB::getInstance();
288
289 for (std::vector<int>::const_iterator pdg = pdgs.begin(); pdg != pdgs.end(); ++pdg) {
290
291 const JParticle& particle = PDB.getPDG(*pdg);
292
293 this->push_back(particle);
294 }
295 }
296
297
298 /**
299 * Print selection.
300 *
301 * \param out output stream
302 * \param pdb particle data book selection
303 * \return output stream
304 */
305 friend inline std::ostream& operator<<(std::ostream& out, const JPDBSelection& pdb)
306 {
307 return out << static_cast<const JPDB&>(pdb);
308 }
309 };
310
311
312 /**
313 * Retrieve quark entries from particle data book.
314 *
315 * \return quark entries
316 */
317 inline const JPDBSelection& getQuarks()
318 {
319 const std::vector<int> pdgs = { QUARK_TYPE_UP,
331
332 static const JPDBSelection quarks(pdgs);
333
334 return quarks;
335 }
336
337
338 /**
339 * Retrieve charged lepton entries from particle data book.
340 *
341 * \return charged lepton entries
342 */
344 {
351
352 static const JPDBSelection charged_leptons(pdgs);
353
354 return charged_leptons;
355 }
356}
357
358#endif
Auxiliary methods and classes for handling Standard Model charges.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
I/O manipulators.
Definition of particle types.
Physics constants.
General exception.
Definition JException.hh:25
Extensions to Evt data format.
@ QUARK_TYPE_ANTICHARM
@ QUARK_TYPE_ANTIBOTTOM
@ QUARK_TYPE_ANTISTRANGE
@ QUARK_TYPE_ANTIDOWN
const JPDBSelection & getChargedLeptons()
Retrieve charged lepton entries from particle data book.
Definition JPDB.hh:343
const JPDBSelection & getQuarks()
Retrieve quark entries from particle data book.
Definition JPDB.hh:317
@ GEANT4_TYPE_NEUTRAL_ANTISIGMA
@ GEANT4_TYPE_ANTISIGMA_PLUS
@ GEANT4_TYPE_NEUTRINO
@ GEANT4_TYPE_ANTISIGMA_MINUS
@ GEANT4_TYPE_NEUTRAL_ANTIXI
@ TRACK_TYPE_ANTINUMU
@ TRACK_TYPE_NEUTRAL_ANTISIGMA
@ TRACK_TYPE_ANTINUTAU
@ TRACK_TYPE_ELECTRON
@ TRACK_TYPE_ANTIMUON
@ TRACK_TYPE_ANTIELECTRON
@ TRACK_TYPE_ANTISIGMA_MINUS
@ TRACK_TYPE_NEUTRAL_ANTIXI
@ TRACK_TYPE_ANTISIGMA_PLUS
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Selection of particle data book entries.
Definition JPDB.hh:277
friend std::ostream & operator<<(std::ostream &out, const JPDBSelection &pdb)
Print selection.
Definition JPDB.hh:305
JPDBSelection(const std::vector< int > &pdgs)
Constructor.
Definition JPDB.hh:283
Collection of particles.
Definition JPDB.hh:112
JPDB()
Default constructor.
Definition JPDB.hh:116
bool hasGEANT(const int geant) const
Check if PDB has particle corresponding to given GEANT code.
Definition JPDB.hh:156
static int convertPDGtoGEANT(const int pdg)
Retrieve GEANT code for a given PDG code.
Definition JPDB.hh:186
friend std::ostream & operator<<(std::ostream &out, const JPDB &pdb)
Print particle data book.
Definition JPDB.hh:253
static const JPDB & getInstance()
Get particle data book.
Definition JPDB.hh:126
const JParticle & getGEANT(const int geant) const
Get particle corresponding to given GEANT code.
Definition JPDB.hh:169
bool hasPDG(const int pdg) const
Check if PDB has particle corresponding to given PDG code.
Definition JPDB.hh:222
const JParticle & getPDG(const int pdg) const
Get particle corresponding to given PDG code.
Definition JPDB.hh:235
Auxiliary class to handle particle name, codes and mass.
Definition JPDB.hh:42
int geant
GEANT code of particle.
Definition JPDB.hh:91
JParticle()
Default constructor.
Definition JPDB.hh:46
JElectricCharge charge
electric charge of particle [|e|/3]
Definition JPDB.hh:93
std::string name
name of particle
Definition JPDB.hh:89
double mass
mass of particle [GeV]
Definition JPDB.hh:92
JParticle(const std::string &name, const int pdg, const int geant, const double mass, const JElectricCharge &charge)
Constructor.
Definition JPDB.hh:60
friend std::ostream & operator<<(std::ostream &out, const JParticle &particle)
Print particle.
Definition JPDB.hh:76
int pdg
PDG code of particle.
Definition JPDB.hh:90
Auxiliary class for electric charges of SM fields.
Definition JCharges.hh:28