Jpp  15.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
10 #include "JAAnet/JParticleTypes.hh"
11 #include "JPhysics/JConstants.hh"
12 
13 #include "JLang/JPredicate.hh"
14 #include "JLang/JException.hh"
15 #include "JLang/JManip.hh"
16 
17 
18 /**
19  * \author mdejong
20  */
21 
22 namespace JAANET {}
23 namespace JPP { using namespace JAANET; }
24 
25 namespace JAANET {
26 
27  using JLANG::JException;
28 
29  /**
30  * Auxiliary class to handle particle name, codes and mass.
31  */
32  struct JParticle {
33  /**
34  * Default constructor.
35  */
37  {
38  this->name = "";
39  this->pdg = 0;
40  this->geant = 0;
41  this->mass = 0.0;
42  }
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param name name of particle
49  * \param pdg PDG code of particle
50  * \param geant GEANT code of particle
51  * \param mass mass of particle
52  */
53  JParticle(const std::string& name,
54  const int pdg,
55  const int geant,
56  const double mass)
57  {
58  this->name = name;
59  this->pdg = pdg;
60  this->geant = geant;
61  this->mass = mass;
62  }
63 
64 
65  /**
66  * Print particle.
67  *
68  * \param out output stream
69  * \param particle particle
70  * \return output stream
71  */
72  friend inline std::ostream& operator<<(std::ostream& out, const JParticle& particle)
73  {
74  using namespace std;
75  using namespace JPP;
76 
77  return out << setw(32) << left << particle.name << " "
78  << setw( 6) << right << particle.pdg << " "
79  << setw( 6) << right << particle.geant << " "
80  << FIXED(12,10) << particle.mass;
81  }
82 
83 
84  std::string name; //!< name of particle
85  int pdg; //!< PDG code of particle
86  int geant; //!< GEANT code of particle
87  double mass; //!< mass of particle [GeV]
88  };
89 
90 
91  /**
92  * Auxiliary macro for particle creation.
93  *
94  * \param PDG PDG code
95  * \param GEANT GEANT code
96  * \param MASS mass
97  */
98 #define MAKE_PARTICLE(PDG, GEANT, MASS) JParticle(#PDG, PDG, GEANT, MASS)
99 
100 
101  /**
102  * Collection of particles.
103  */
104  struct JPDB :
105  public std::vector<JParticle>
106  {
107  /**
108  * Default constructor.
109  */
111  {}
112 
113 
114  /**
115  * Get particle data book.
116  * This particle data book contains all known GEANT particle codes.
117  *
118  * \return particle data book
119  */
120  static const JPDB& getInstance()
121  {
122  using namespace JPP;
123 
124  static JPDB pdb;
125 
126  if (pdb.empty()) {
127 
164 
171  // anti-photon does not exist
199 
200  }
201 
202  return pdb;
203  }
204 
205 
206  /**
207  * Check if PDB has particle corresponding to given GEANT code.
208  *
209  * \param geant GEANT code
210  * \return true if available; else false
211  */
212  bool hasGEANT(const int geant) const
213  {
214  return (find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::geant, geant)) != this->end());
215  }
216 
217 
218  /**
219  * Get particle corresponding to given GEANT code.\n
220  * This method throws an error if the particle cannot be found.
221  *
222  * \param geant GEANT code
223  * \return particle
224  */
225  const JParticle& getGEANT(const int geant) const
226  {
227  const_iterator p = find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::geant, geant));
228 
229  if (p != this->end())
230  return *p;
231  else
232  THROW(JException, "Invalid GEANT particle code " << geant);
233  }
234 
235 
236  /**
237  * Check if PDB has particle corresponding to given PDG code.
238  *
239  * \param pdg PDG code
240  * \return true if available; else false
241  */
242  bool hasPDG(const int pdg) const
243  {
244  return (find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::pdg, pdg)) != this->end());
245  }
246 
247 
248  /**
249  * Get particle corresponding to given PDG code.\n
250  * This method throws an error if the particle cannot be found.
251  *
252  * \param pdg PDG code
253  * \return particle
254  */
255  const JParticle& getPDG(const int pdg) const
256  {
257  const_iterator p = find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::pdg, pdg));
258 
259  if (p != this->end())
260  return *p;
261  else
262  THROW(JException, "Invalid PDG particle code " << pdg);
263  }
264 
265 
266  /**
267  * Print particle data book.
268  *
269  * \param out output stream
270  * \param pdb particle data book
271  * \return output stream
272  */
273  friend inline std::ostream& operator<<(std::ostream& out, const JPDB& pdb)
274  {
275  using namespace std;
276 
277  out << setw(32) << left << "particle" << " "
278  << setw( 6) << right << "PDG" << " "
279  << setw( 6) << right << "GEANT" << " "
280  << setw(12) << right << "Mass [GeV]" << endl;
281 
282  for (JPDB::const_iterator i = pdb.begin(); i != pdb.end(); ++i) {
283  out << *i << endl;
284  }
285 
286  return out;
287  }
288  };
289 }
290 
291 #endif
static const double MASS_NEUTRAL_OMEGA_C
Omega_c_0 mass [GeV].
General exception.
Definition: JException.hh:23
static const double MASS_CHARGED_KAON
K^+/- mass [GeV].
std::string name
name of particle
Definition: JPDB.hh:84
static const double MASS_CHARGED_OMEGA_B
Omega_b^+/- mass [GeV].
Exceptions.
static const double MASS_NEUTRAL_LAMBDA_B
Lambda_b^0 mass [GeV].
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
static const double MASS_CHARGED_B
B^+/- mass [GeV].
static const double MASS_ELECTRON_NEUTRINO
electron neutrino mass [GeV]
static const double MASS_TAU_NEUTRINO
tau neutrino mass [GeV]
static const double MASS_NEUTRAL_KAON
K_0 mass [GeV].
static const double MASS_CHARGED_XI
Xi^+/- mass [GeV].
const JParticle & getGEANT(const int geant) const
Get particle corresponding to given GEANT code.
Definition: JPDB.hh:225
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
static const double MASS_MUON
muon mass [GeV]
const JParticle & getPDG(const int pdg) const
Get particle corresponding to given PDG code.
Definition: JPDB.hh:255
JParticle()
Default constructor.
Definition: JPDB.hh:36
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Collection of particles.
Definition: JPDB.hh:104
static const double MASS_NEUTRAL_XI_C
Xi_c_0 mass [GeV].
JPDB()
Default constructor.
Definition: JPDB.hh:110
static const JPDB & getInstance()
Get particle data book.
Definition: JPDB.hh:120
static const double MASS_NEUTRON
neutron mass [GeV]
static const double MASS_CHARGED_D_S
D_s^+/- mass [GeV].
static const double MASS_CHARGED_SIGMA
Sigma^+/- mass [GeV].
static const double MASS_CHARGED_LAMBDA_C
Lambda_c^+/- mass [GeV].
static const double MASS_NEUTRAL_B_S
B_s^0 mass [GeV].
bool hasGEANT(const int geant) const
Check if PDB has particle corresponding to given GEANT code.
Definition: JPDB.hh:212
friend std::ostream & operator<<(std::ostream &out, const JPDB &pdb)
Print particle data book.
Definition: JPDB.hh:273
static const double MASS_TAU
tau mass [GeV]
static const double MASS_LAMBDA
Lambda mass [GeV].
static const double MASS_CHARGED_PION
pi^+/- mass [GeV]
static const double MASS_CHARGED_B_C
B_c^+/- mass [GeV].
Physics constants.
static const double MASS_MUON_NEUTRINO
muon neutrino mass [GeV]
static const double MASS_ELECTRON
electron mass [GeV]
static const double MASS_NEUTRAL_D
D_0 mass [GeV].
I/O manipulators.
Auxiliary class to handle particle name, codes and mass.
Definition: JPDB.hh:32
static const double MASS_NEUTRAL_XI
Xi_0 mass [GeV].
bool hasPDG(const int pdg) const
Check if PDB has particle corresponding to given PDG code.
Definition: JPDB.hh:242
static const double MASS_NEUTRAL_SIGMA
Sigma_0 mass [GeV].
double mass
mass of particle [GeV]
Definition: JPDB.hh:87
static const double MASS_NEUTRAL_PION
pi_0 mass [GeV]
static const double MASS_CHARGED_XI_C
Xi_c^+/- mass [GeV].
static const double MASS_CHARGED_OMEGA
Omega^+/- mass [GeV].
friend std::ostream & operator<<(std::ostream &out, const JParticle &particle)
Print particle.
Definition: JPDB.hh:72
int geant
GEANT code of particle.
Definition: JPDB.hh:86
static const double MASS_NEUTRAL_XI_B
Xi_b^0 mass [GeV].
static const double MASS_CHARGED_XI_B
Xi_b^+/- mass [GeV].
static const double MASS_PROTON
proton mass [GeV]
Definition of particle types.
static const double MASS_PHOTON
Particle masses.
int pdg
PDG code of particle.
Definition: JPDB.hh:85
static const double MASS_NEUTRAL_B
B_0 mass [GeV].
#define MAKE_PARTICLE(PDG, GEANT, MASS)
Auxiliary macro for particle creation.
Definition: JPDB.hh:98
JParticle(const std::string &name, const int pdg, const int geant, const double mass)
Constructor.
Definition: JPDB.hh:53
static const double MASS_CHARGED_D
D^+/- mass [GeV].