Jpp
 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 "JTools/JConstants.hh"
12 
13 #include "JLang/JPredicate.hh"
14 #include "JLang/JException.hh"
15 
16 #include "Jeep/JPrint.hh"
17 
18 
19 /**
20  * \author mdejong
21  */
22 
23 namespace JAANET {}
24 namespace JPP { using namespace JAANET; }
25 
26 namespace JAANET {
27 
28  using JLANG::JException;
29 
30  /**
31  * Auxiliary class to handle particle name, codes and mass.
32  */
33  struct JParticle {
34  /**
35  * Default constructor.
36  */
38  {
39  this->name = "";
40  this->pdg = 0;
41  this->geant = 0;
42  this->mass = 0.0;
43  }
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param name name of particle
50  * \param pdg PDG code of particle
51  * \param geant GEANT code of particle
52  * \param mass mass of particle
53  */
54  JParticle(const std::string& name,
55  const int pdg,
56  const int geant,
57  const double mass)
58  {
59  this->name = name;
60  this->pdg = pdg;
61  this->geant = geant;
62  this->mass = mass;
63  }
64 
65 
66  /**
67  * Print particle.
68  *
69  * \param out output stream
70  * \param particle particle
71  * \return output stream
72  */
73  friend inline std::ostream& operator<<(std::ostream& out, const JParticle& particle)
74  {
75  using namespace std;
76  using namespace JEEP;
77 
78  return out << setw(32) << left << particle.name << " "
79  << setw( 6) << right << particle.pdg << " "
80  << setw( 6) << right << particle.geant << " "
81  << FIXED(12,10) << particle.mass;
82  }
83 
84 
85  std::string name; //!< name of particle
86  int pdg; //!< PDG code of particle
87  int geant; //!< GEANT code of particle
88  double mass; //!< mass of particle [GeV]
89  };
90 
91 
92  /**
93  * Auxiliary macro for particle creation.
94  *
95  * \param PDG PDG code
96  * \param GEANT GEANT code
97  * \param MASS mass
98  */
99 #define MAKE_PARTICLE(PDG, GEANT, MASS) JParticle(#PDG, PDG, GEANT, MASS)
100 
101 
102  /**
103  * Collection of particles.
104  */
105  struct JPDB :
106  public std::vector<JParticle>
107  {
108  /**
109  * Default constructor.
110  */
112  {}
113 
114 
115  /**
116  * Get particle data book.
117  * This particle data book contains all known GEANT particle codes.
118  *
119  * \return particle data book
120  */
121  static const JPDB& getInstance()
122  {
123  using namespace JAANET;
124  using namespace JTOOLS;
125 
126  static JPDB pdb;
127 
128  if (pdb.empty()) {
129 
151 
158  // anti-photon does not exist
172  }
173 
174  return pdb;
175  }
176 
177 
178  /**
179  * Check if PDB has particle corresponding to given GEANT code.
180  *
181  * \param geant GEANT code
182  * \return true if available; else false
183  */
184  bool hasGEANT(const int geant) const
185  {
186  return (find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::geant, geant)) != this->end());
187  }
188 
189 
190  /**
191  * Get particle corresponding to given GEANT code.\n
192  * This method throws an error if the particle cannot be found.
193  *
194  * \param geant GEANT code
195  * \return particle
196  */
197  const JParticle& getGEANT(const int geant) const
198  {
199  const_iterator p = find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::geant, geant));
200 
201  if (p != this->end())
202  return *p;
203  else
204  THROW(JException, "Invalid GEANT particle code " << geant);
205  }
206 
207 
208  /**
209  * Check if PDB has particle corresponding to given PDG code.
210  *
211  * \param pdg PDG code
212  * \return true if available; else false
213  */
214  bool hasPDG(const int pdg) const
215  {
216  return (find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::pdg, pdg)) != this->end());
217  }
218 
219 
220  /**
221  * Get particle corresponding to given PDG code.\n
222  * This method throws an error if the particle cannot be found.
223  *
224  * \param pdg PDG code
225  * \return particle
226  */
227  const JParticle& getPDG(const int pdg) const
228  {
229  const_iterator p = find_if(this->begin(), this->end(), JLANG::make_predicate(&JParticle::pdg, pdg));
230 
231  if (p != this->end())
232  return *p;
233  else
234  THROW(JException, "Invalid PDG particle code " << pdg);
235  }
236 
237 
238  /**
239  * Print particle data book.
240  *
241  * \param out output stream
242  * \param pdb particle data book
243  * \return output stream
244  */
245  friend inline std::ostream& operator<<(std::ostream& out, const JPDB& pdb)
246  {
247  using namespace std;
248 
249  out << setw(32) << left << "particle" << " "
250  << setw( 6) << right << "PDG" << " "
251  << setw( 6) << right << "GEANT" << " "
252  << setw(12) << right << "Mass [GeV]" << endl;
253 
254  for (JPDB::const_iterator i = pdb.begin(); i != pdb.end(); ++i) {
255  out << *i << endl;
256  }
257 
258  return out;
259  }
260  };
261 }
262 
263 #endif
static const double MASS_PROTON
proton mass [GeV]
Definition: JConstants.hh:67
static const double MASS_TAU_NEUTRINO
tau neutrino mass [GeV]
Definition: JConstants.hh:56
General exception.
Definition: JException.hh:40
std::string name
name of particle
Definition: JPDB.hh:85
Exceptions.
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_MUON
muon mass [GeV]
Definition: JConstants.hh:59
static const double MASS_CHARGED_OMEGA
Omega^+/- mass [GeV].
Definition: JConstants.hh:74
static const double MASS_CHARGED_PION
pi^+/- mass [GeV]
Definition: JConstants.hh:63
static const double MASS_TAU
tau mass [GeV]
Definition: JConstants.hh:60
static const double MASS_NEUTRAL_KAON
K_0 mass [GeV].
Definition: JConstants.hh:64
const JParticle & getGEANT(const int geant) const
Get particle corresponding to given GEANT code.
Definition: JPDB.hh:197
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
static const double MASS_CHARGED_KAON
K^+/- mass [GeV].
Definition: JConstants.hh:65
const JParticle & getPDG(const int pdg) const
Get particle corresponding to given PDG code.
Definition: JPDB.hh:227
JParticle()
Default constructor.
Definition: JPDB.hh:37
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:461
Collection of particles.
Definition: JPDB.hh:105
JPDB()
Default constructor.
Definition: JPDB.hh:111
static const JPDB & getInstance()
Get particle data book.
Definition: JPDB.hh:121
static const double MASS_LAMBDA
Lambda mass [GeV].
Definition: JConstants.hh:69
static const double MASS_PHOTON
Particle masses.
Definition: JConstants.hh:52
Constants.
static const double MASS_NEUTRAL_XI
Xi_0 mass [GeV].
Definition: JConstants.hh:72
I/O formatting auxiliaries.
bool hasGEANT(const int geant) const
Check if PDB has particle corresponding to given GEANT code.
Definition: JPDB.hh:184
friend std::ostream & operator<<(std::ostream &out, const JPDB &pdb)
Print particle data book.
Definition: JPDB.hh:245
static const double MASS_MUON_NEUTRINO
muon neutrino mass [GeV]
Definition: JConstants.hh:55
static const double MASS_ELECTRON_NEUTRINO
electron neutrino mass [GeV]
Definition: JConstants.hh:54
static const double MASS_CHARGED_SIGMA
Sigma^+/- mass [GeV].
Definition: JConstants.hh:71
Auxiliary class to handle particle name, codes and mass.
Definition: JPDB.hh:33
bool hasPDG(const int pdg) const
Check if PDB has particle corresponding to given PDG code.
Definition: JPDB.hh:214
static const double MASS_NEUTRAL_PION
pi_0 mass [GeV]
Definition: JConstants.hh:62
static const double MASS_NEUTRAL_SIGMA
Sigma_0 mass [GeV].
Definition: JConstants.hh:70
double mass
mass of particle [GeV]
Definition: JPDB.hh:88
static const double MASS_CHARGED_XI
Xi^+/- mass [GeV].
Definition: JConstants.hh:73
friend std::ostream & operator<<(std::ostream &out, const JParticle &particle)
Print particle.
Definition: JPDB.hh:73
int geant
GEANT code of particle.
Definition: JPDB.hh:87
Definition of particle types.
int pdg
PDG code of particle.
Definition: JPDB.hh:86
#define MAKE_PARTICLE(PDG, GEANT, MASS)
Auxiliary macro for particle creation.
Definition: JPDB.hh:99
JParticle(const std::string &name, const int pdg, const int geant, const double mass)
Constructor.
Definition: JPDB.hh:54
static const double MASS_ELECTRON
electron mass [GeV]
Definition: JConstants.hh:58
static const double MASS_NEUTRON
neutron mass [GeV]
Definition: JConstants.hh:68