Belle II Software  release-06-02-00
Const.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <framework/core/FrameworkExceptions.h>
12 
13 #include <TObject.h>
14 
15 #include <cstddef>
16 #include <stdexcept>
17 #include <string>
18 
19 class TDatabasePDG;
20 class TParticlePDG;
21 
22 namespace Belle2 {
34  class Const {
35 
36  public:
37 
42  enum EDetector {
43  invalidDetector = 0x0,
44  PXD = 0x1,
45  SVD = 0x2,
46  CDC = 0x3,
47  TOP = 0x4,
48  ARICH = 0x5,
49  ECL = 0x6,
50  KLM = 0x7,
51  BKLM = 0x100 + KLM,
52  EKLM = 0x200 + KLM,
53  IR = 0x8,
54  TRG = 0x9,
55  DAQ = 0xA,
56  BEAST = 0xB,
57  TEST = 0xC,
58  };
59 
65  static std::string parseDetectors(EDetector det);
66 
71  class DetectorSet {
72  public:
73 
77  DetectorSet(const DetectorSet&) = default;
79  DetectorSet& operator=(const DetectorSet&) = default;
80 
85  // cppcheck-suppress noExplicitConstructor
87 
91  virtual ~DetectorSet() {};
92 
97  DetectorSet& operator += (const DetectorSet& set) {m_bits |= set.m_bits; return *this;}
98 
103  DetectorSet& operator -= (const DetectorSet& set) {m_bits &= ~set.m_bits; return *this;}
104 
109  bool operator == (const DetectorSet& set) const {return m_bits == set.m_bits;}
110 
115  bool operator != (const DetectorSet& set) const {return m_bits != set.m_bits;}
116 
121  bool contains(const DetectorSet& set) const {return (m_bits & set.m_bits) == set.m_bits;}
122 
128  int getIndex(EDetector det) const;
129 
135  EDetector operator [](int index) const;
136 
140  size_t size() const;
141 
145  std::string __repr__() const;
146 
147  private:
148 
153  explicit DetectorSet(unsigned short bits): m_bits(bits) {};
154 
160  static unsigned short getBit(EDetector det);
161 
167  static EDetector getDetector(unsigned short bit);
168 
169  unsigned short m_bits;
171  ClassDef(DetectorSet, 1)
172  };
173 
177  template <class ASetType> class RestrictedDetectorSet: public DetectorSet {
178  public:
179 
183  BELLE2_DEFINE_EXCEPTION(InvalidDetectorTypeError, "The given detector is not a valid element of the set!")
184 
185 
189 
194  // cppcheck-suppress noExplicitConstructor
196 
201  // cppcheck-suppress noExplicitConstructor
203 
209 
214  static DetectorSet set() {return ASetType::set();}
215 
216  private:
217 
221  void checkSet() const {if (!ASetType::set().contains(*this)) throw InvalidDetectorTypeError();}
222  };
223 
224 
229  class VXDDetectors {
230  public:
231  static DetectorSet set() {return c_set;}
232  static const DetectorSet c_set;
233  };
236 
242  public:
243  static DetectorSet set() {return c_set;}
244  static const DetectorSet c_set;
245  };
248 
253  class PIDDetectors {
254  public:
255  static DetectorSet set() {return c_set;}
256  static const DetectorSet c_set;
257  static const size_t c_size = 6;
258  };
261 
267  public:
268  static DetectorSet set() {return c_set;}
269  static const DetectorSet c_set;
270  static const size_t c_size = 2;
271  };
274 
275 
279  static const DetectorSet allDetectors;
280 
281  class ParticleSet;
282 
289  class ParticleType {
290  public:
291 
298  explicit ParticleType(int pdgCode, const ParticleSet* set = nullptr, int index = -1):
299  m_pdgCode(pdgCode), m_set(set), m_index(index) {}
300 
302  ParticleType(const ParticleType&) = default;
304  ParticleType& operator=(const ParticleType&) = default;
305 
310  bool operator < (const ParticleType& other) const;
311 
313  bool operator==(const ParticleType& o) const { return m_pdgCode == o.m_pdgCode; }
314 
316  bool operator!=(const ParticleType& o) const { return !((*this) == o); }
317 
319  ParticleType& operator*() { return *this; }
320 
326 
332 
336  operator ParticleSet() const { ParticleSet s; s.add(*this); return s; }
337 
342  int getIndex() const { return m_index; }
343 
348  const TParticlePDG* getParticlePDG() const;
349 
354  int getPDGCode() const {return m_pdgCode;};
355 
360  double getMass() const;
361 
365  std::string __repr__() const;
366 
367  private:
368  int m_pdgCode;
370  int m_index;
371  };
372 
398  class ParticleSet {
399  public:
401  ParticleSet() = default;
402 
404  ParticleSet(const ParticleSet& other)
405  {
406  for (const ParticleType& pdgIter : other) add(pdgIter);
407  }
408 
411  {
412  m_particles.clear();
413  for (const ParticleType& pdgIter : other) add(pdgIter);
414  return *this;
415  }
416 
421  void add(const ParticleType& p);
422 
424  bool contains(const ParticleType& p) const;
425 
427  unsigned int size() const { return m_particles.size(); }
428 
430  const ParticleType& at(unsigned int index) const
431  {
432  if (index < m_particles.size())
433  return m_particles[index];
434  return invalidParticle;
435  }
436 
439  {
440  if (m_particles.empty())
441  return end();
442  return m_particles[0];
443  }
444 
447  {
448  return invalidParticle;
449  }
450 
452  const ParticleType& find(int pdg) const
453  {
454  for (ParticleType pdgIter : *this) {
455  if (pdgIter.getPDGCode() == pdg)
456  return m_particles[pdgIter.getIndex()];
457  }
458 
459  return invalidParticle;
460  }
461  private:
462  std::vector<ParticleType> m_particles;
463  };
464 
470  class ChargedStable : public ParticleType {
471  public:
476  // cppcheck-suppress noExplicitConstructor
479  {
480  if ((*this) == invalidParticle) {
481  throw std::runtime_error("Given ParticleType is not a charged stable particle!");
482  }
483  }
484 
489  explicit ChargedStable(int pdg)
490  : ParticleType(chargedStableSet.find(pdg))
491  {
492  if ((*this) == invalidParticle) {
493  throw std::runtime_error("Given PDG code is not a charged stable particle!");
494  }
495  }
496  static const unsigned int c_SetSize = 6;
497  };
498 
507  class Cluster : public ParticleType {
508  public:
513  // cppcheck-suppress noExplicitConstructor
515  : ParticleType(clusterSet.find(p.getPDGCode()))
516  {
517  if ((*this) == invalidParticle) {
518  throw std::runtime_error("Given ParticleType is not a cluster particle!");
519  }
520  }
521 
526  explicit Cluster(int pdg)
527  : ParticleType(clusterSet.find(pdg))
528  {
529  if ((*this) == invalidParticle) {
530  throw std::runtime_error("Given PDG code is not a cluster particle!");
531  }
532  }
533  static const unsigned int c_SetSize = 6;
534  };
535 
536  static const ParticleSet clusterSet;
540  static const ChargedStable electron;
541  static const ChargedStable muon;
542  static const ChargedStable pion;
543  static const ChargedStable kaon;
544  static const ChargedStable proton;
545  static const ChargedStable deuteron;
547  static const Cluster clusterphoton;
548  static const Cluster clusterKlong;
549  static const Cluster clusterelectron;
550  static const Cluster clusterpion;
551  static const Cluster clustermuon;
552  static const Cluster clusterjunk;
554  static const ParticleType photon;
555  static const ParticleType pi0;
556  static const ParticleType neutron;
557  static const ParticleType Kshort;
558  static const ParticleType Klong;
559  static const ParticleType Lambda;
560  static const ParticleType antiLambda;
564 
565  static const double electronMass;
566  static const double muonMass;
567  static const double pionMass;
568  static const double kaonMass;
569  static const double protonMass;
570  static const double deuteronMass;
571  static const double pi0Mass;
572  static const double neutronMass;
573  static const double K0Mass;
575  static const double speedOfLight;
576  static const double kBoltzmann;
577  static const double ehEnergy;
578  static const double fineStrConst;
579  static const double permSi;
580  static const double uTherm;
581  static const double eMobilitySi;
583  private:
588  Const() = delete;
589  Const(const Const&) = delete;
590  Const& operator=(const Const&) = delete;
591  ~Const() = delete;
594  };
596 }
597 
602 
607 
612 
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:470
ChargedStable(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:477
ChargedStable(int pdg)
Constructor from PDG code.
Definition: Const.h:489
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:496
A class that defines the valid set of Cluster detectors.
Definition: Const.h:266
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:268
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:270
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:269
Provides a type-safe way to pass members of the clusterSet set.
Definition: Const.h:507
Cluster(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:514
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:533
Cluster(int pdg)
Constructor from PDG code.
Definition: Const.h:526
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:71
bool operator==(const DetectorSet &set) const
Equality operator.
Definition: Const.h:109
size_t size() const
Getter for number of detector IDs in this set.
Definition: UnitConst.cc:256
static EDetector getDetector(unsigned short bit)
Conversion of bit pattern to detector ID.
Definition: UnitConst.cc:216
int getIndex(EDetector det) const
Getter for the index of a given detector in this set.
Definition: UnitConst.cc:235
virtual ~DetectorSet()
Destructor.
Definition: Const.h:91
bool operator!=(const DetectorSet &set) const
Inequality operator.
Definition: Const.h:115
static unsigned short getBit(EDetector det)
Conversion of detector ID to bit pattern.
Definition: UnitConst.cc:203
std::string __repr__() const
String for printing in python.
Definition: UnitConst.cc:265
DetectorSet(const DetectorSet &)=default
Copy constructor.
DetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:97
DetectorSet & operator-=(const DetectorSet &set)
Subtraction of another set from this one.
Definition: Const.h:103
unsigned short m_bits
The internal representation of the set as bit pattern.
Definition: Const.h:169
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:121
EDetector operator[](int index) const
Accessor for a detector ID in this set.
Definition: UnitConst.cc:246
DetectorSet(EDetector det)
Constructor for a set containig one detector ID.
Definition: Const.h:86
DetectorSet(unsigned short bits)
Constructor.
Definition: Const.h:153
DetectorSet & operator=(const DetectorSet &)=default
Assignment operator.
DetectorSet()
Default constructor.
Definition: Const.h:75
A class that defines the valid set of PID detectors.
Definition: Const.h:253
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:255
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:257
static const DetectorSet c_set
The set of valid PID detectors.
Definition: Const.h:256
A set of ParticleType objects, with defined order.
Definition: Const.h:398
ParticleType begin() const
Returns first particle.
Definition: Const.h:438
bool contains(const ParticleType &p) const
Returns true if and only if the set contains 'p'.
Definition: UnitConst.cc:390
ParticleSet & operator=(const ParticleSet &other)
Assignment operator.
Definition: Const.h:410
unsigned int size() const
Returns number of particles in this set.
Definition: Const.h:427
std::vector< ParticleType > m_particles
Actual particles.
Definition: Const.h:462
ParticleType end() const
Returns an invalid particle to check if iteration should be stopped.
Definition: Const.h:446
void add(const ParticleType &p)
Add a copy of the given ParticleType to this set.
Definition: UnitConst.cc:383
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
Definition: Const.h:430
ParticleSet(const ParticleSet &other)
Copy constructor to make sure particles belong to correct set.
Definition: Const.h:404
ParticleSet()=default
Emtpy constructor.
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
Definition: Const.h:452
The ParticleType class for identifying different particle types.
Definition: Const.h:289
int getPDGCode() const
PDG code.
Definition: Const.h:354
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:342
bool operator!=(const ParticleType &o) const
Test inequality.
Definition: Const.h:316
ParticleType & operator=(const ParticleType &)=default
Assignment Operator.
std::string __repr__() const
String for printing in python.
Definition: UnitConst.cc:328
ParticleType(const ParticleType &)=default
Copy constructor
ParticleType(int pdgCode, const ParticleSet *set=nullptr, int index=-1)
Constructor.
Definition: Const.h:298
bool operator<(const ParticleType &other) const
Comparison operator to be usable in sets.
Definition: UnitConst.cc:295
bool operator==(const ParticleType &o) const
Test equality.
Definition: Const.h:313
int m_index
index in the associated set, -1 if there's no set.
Definition: Const.h:370
int m_pdgCode
PDG code of the particle.
Definition: Const.h:368
const TParticlePDG * getParticlePDG() const
Accessor for ROOT TParticlePDG object.
Definition: UnitConst.cc:318
ParticleType & operator*()
dummy dereferencing for range-based for.
Definition: Const.h:319
ParticleType & operator++()
Prefix increment.
Definition: UnitConst.cc:300
double getMass() const
Particle mass.
Definition: UnitConst.cc:323
const ParticleSet * m_set
set this particle belongs to, or NULL if stand-alone.
Definition: Const.h:369
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
Definition: Const.h:177
RestrictedDetectorSet(const DetectorSet &set)
(Copy) constructor.
Definition: Const.h:195
static DetectorSet set()
Accessor for the set of valid detector IDs.
Definition: Const.h:214
void checkSet() const
Check of set validity.
Definition: Const.h:221
RestrictedDetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:208
RestrictedDetectorSet(EDetector det)
Constructor for a set containg one detector ID.
Definition: Const.h:202
A class that defines the valid set of tracking detectors.
Definition: Const.h:241
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:243
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:244
A class that defines the valid set of VXD detectors.
Definition: Const.h:229
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:231
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:232
This class provides a set of constants for the framework.
Definition: Const.h:34
static const ParticleType neutron
neutron particle
Definition: Const.h:556
static const ParticleType unspecifiedParticle
Unspecified particle, used when no other particle type fits.
Definition: Const.h:563
static const ParticleType pi0
neutral pion particle
Definition: Const.h:555
static const Cluster clustermuon
muon cluster
Definition: Const.h:551
static const ParticleType Lambda
Lambda particle.
Definition: Const.h:559
static const DetectorSet allDetectors
The set of all detectors.
Definition: Const.h:279
static const double eMobilitySi
Electron mobility in intrinsic Silicon at room temperature.
Definition: Const.h:581
static const ParticleSet clusterSet
set of cluster particles
Definition: Const.h:536
static const ChargedStable muon
muon particle
Definition: Const.h:541
RestrictedDetectorSet< PIDDetectors > PIDDetectorSet
Typedef for set of PID detectors.
Definition: Const.h:260
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:499
static const double kBoltzmann
Boltzmann constant in GeV/K.
Definition: Const.h:576
static const Cluster clusterelectron
electron cluster
Definition: Const.h:549
static const double kaonMass
charged kaon mass
Definition: Const.h:568
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
static const double K0Mass
neutral kaon mass
Definition: Const.h:573
static const Cluster clusterpion
charged hadron cluster
Definition: Const.h:550
RestrictedDetectorSet< VXDDetectors > VXDDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:235
static const ChargedStable pion
charged pion particle
Definition: Const.h:542
static std::string parseDetectors(EDetector det)
Converts Const::EDetector object to string.
Definition: UnitConst.cc:162
static const double pionMass
charged pion mass
Definition: Const.h:567
static const ParticleType Klong
K^0_L particle.
Definition: Const.h:558
static const ParticleSet finalStateParticlesSet
set of final set particles that can be created by the ParticleLoader
Definition: Const.h:538
RestrictedDetectorSet< ClusterDetectors > ClusterDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:273
static const double permSi
Permittivity of Silicon.
Definition: Const.h:579
static const double speedOfLight
[cm/ns]
Definition: Const.h:575
static const double electronMass
electron mass
Definition: Const.h:565
static const double neutronMass
neutron mass
Definition: Const.h:572
static const Cluster clusterKlong
K^0_L cluster.
Definition: Const.h:548
static const ParticleType antiLambda
Anti-Lambda particle.
Definition: Const.h:560
static const double deuteronMass
deuteron mass
Definition: Const.h:570
static const ChargedStable proton
proton particle
Definition: Const.h:544
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:561
static const double ehEnergy
Energy needed to create an electron-hole pair in Si at std.
Definition: Const.h:577
Const()=delete
no Const instances allowed.
RestrictedDetectorSet< TrackingDetectors > TrackingDetectorSet
Typedef for set of tracking detectors.
Definition: Const.h:247
static const ParticleType Kshort
K^0_S particle.
Definition: Const.h:557
static const double protonMass
proton mass
Definition: Const.h:569
static const double fineStrConst
The fine structure constant.
Definition: Const.h:578
static const Cluster clusterjunk
junk cluster
Definition: Const.h:552
static const double uTherm
Thermal Voltage at room temperature.
Definition: Const.h:580
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:543
static const ParticleType photon
photon particle
Definition: Const.h:554
static const double pi0Mass
neutral pion mass
Definition: Const.h:571
static const Cluster clusterphoton
photon cluster
Definition: Const.h:547
static const double muonMass
muon mass
Definition: Const.h:566
static const ChargedStable electron
electron particle
Definition: Const.h:540
static const ChargedStable deuteron
deuteron particle
Definition: Const.h:545
FourVector operator-(const FourVector &lhs, const FourVector &rhs)
Difference of two four vectors.
Definition: FourVector.h:197
FourVector operator+(const FourVector &lhs, const FourVector &rhs)
Sum of two four vectors.
Definition: FourVector.h:188
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Abstract base class for different kinds of events.