Belle II Software  release-05-02-19
Const.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2012 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Kuhr *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/FrameworkExceptions.h>
14 
15 #include <TObject.h>
16 
17 #include <cstddef>
18 #include <stdexcept>
19 #include <string>
20 
21 class TDatabasePDG;
22 class TParticlePDG;
23 
24 namespace Belle2 {
36  class Const {
37 
38  public:
39 
44  enum EDetector {
45  invalidDetector = 0x0,
46  PXD = 0x1,
47  SVD = 0x2,
48  CDC = 0x3,
49  TOP = 0x4,
50  ARICH = 0x5,
51  ECL = 0x6,
52  KLM = 0x7,
53  BKLM = 0x100 + KLM,
54  EKLM = 0x200 + KLM,
55  IR = 0x8,
56  TRG = 0x9,
57  DAQ = 0xA,
58  BEAST = 0xB,
59  TEST = 0xC,
60  };
61 
66  class DetectorSet {
67  public:
68 
72  DetectorSet(const DetectorSet&) = default;
74  DetectorSet& operator=(const DetectorSet&) = default;
75 
80  // cppcheck-suppress noExplicitConstructor
82 
86  virtual ~DetectorSet() {};
87 
92  DetectorSet& operator += (const DetectorSet& set) {m_bits |= set.m_bits; return *this;}
93 
98  DetectorSet& operator -= (const DetectorSet& set) {m_bits &= ~set.m_bits; return *this;}
99 
104  bool operator == (const DetectorSet& set) const {return m_bits == set.m_bits;}
105 
110  bool operator != (const DetectorSet& set) const {return m_bits != set.m_bits;}
111 
116  bool contains(const DetectorSet& set) const {return (m_bits & set.m_bits) == set.m_bits;}
117 
123  int getIndex(EDetector det) const;
124 
130  EDetector operator [](int index) const;
131 
135  size_t size() const;
136 
140  std::string __repr__() const;
141 
142  private:
143 
148  explicit DetectorSet(unsigned short bits): m_bits(bits) {};
149 
155  static unsigned short getBit(EDetector det);
156 
162  static EDetector getDetector(unsigned short bit);
163 
164  unsigned short m_bits;
166  ClassDef(DetectorSet, 1)
167  };
168 
172  template <class ASetType> class RestrictedDetectorSet: public DetectorSet {
173  public:
174 
178  BELLE2_DEFINE_EXCEPTION(InvalidDetectorTypeError, "The given detector is not a valid element of the set!")
179 
180 
184 
189  // cppcheck-suppress noExplicitConstructor
191 
196  // cppcheck-suppress noExplicitConstructor
198 
204 
209  static DetectorSet set() {return ASetType::set();}
210 
211  private:
212 
216  void checkSet() const {if (!ASetType::set().contains(*this)) throw InvalidDetectorTypeError();}
217  };
218 
219 
224  class VXDDetectors {
225  public:
226  static DetectorSet set() {return c_set;}
227  static const DetectorSet c_set;
228  };
231 
237  public:
238  static DetectorSet set() {return c_set;}
239  static const DetectorSet c_set;
240  };
243 
248  class PIDDetectors {
249  public:
250  static DetectorSet set() {return c_set;}
251  static const DetectorSet c_set;
252  static const size_t c_size = 6;
253  };
256 
262  public:
263  static DetectorSet set() {return c_set;}
264  static const DetectorSet c_set;
265  static const size_t c_size = 2;
266  };
269 
270 
274  static const DetectorSet allDetectors;
275 
276  class ParticleSet;
277 
284  class ParticleType {
285  public:
286 
293  explicit ParticleType(int pdgCode, const ParticleSet* set = NULL, int index = -1):
294  m_pdgCode(pdgCode), m_set(set), m_index(index) {}
295 
297  ParticleType(const ParticleType&) = default;
299  ParticleType& operator=(const ParticleType&) = default;
300 
305  bool operator < (const ParticleType& other) const;
306 
308  bool operator==(const ParticleType& o) const { return m_pdgCode == o.m_pdgCode; }
309 
311  bool operator!=(const ParticleType& o) const { return !((*this) == o); }
312 
314  ParticleType& operator*() { return *this; }
315 
321 
327 
331  operator ParticleSet() const { ParticleSet s; s.add(*this); return s; }
332 
337  int getIndex() const { return m_index; }
338 
343  const TParticlePDG* getParticlePDG() const;
344 
349  int getPDGCode() const {return m_pdgCode;};
350 
355  double getMass() const;
356 
360  std::string __repr__() const;
361 
362  private:
363  int m_pdgCode;
365  int m_index;
366  };
367 
393  class ParticleSet {
394  public:
396  ParticleSet() = default;
397 
399  ParticleSet(const ParticleSet& other)
400  {
401  for (const ParticleType& pdgIter : other) add(pdgIter);
402  }
403 
406  {
407  m_particles.clear();
408  for (const ParticleType& pdgIter : other) add(pdgIter);
409  return *this;
410  }
411 
416  void add(const ParticleType& p);
417 
419  bool contains(const ParticleType& p) const;
420 
422  unsigned int size() const { return m_particles.size(); }
423 
425  const ParticleType& at(unsigned int index) const
426  {
427  if (index < m_particles.size())
428  return m_particles[index];
429  return invalidParticle;
430  }
431 
434  {
435  if (m_particles.empty())
436  return end();
437  return m_particles[0];
438  }
439 
442  {
443  return invalidParticle;
444  }
445 
447  const ParticleType& find(int pdg) const
448  {
449  for (ParticleType pdgIter : *this) {
450  if (pdgIter.getPDGCode() == pdg)
451  return m_particles[pdgIter.getIndex()];
452  }
453 
454  return invalidParticle;
455  }
456  private:
457  std::vector<ParticleType> m_particles;
458  };
459 
465  class ChargedStable : public ParticleType {
466  public:
471  // cppcheck-suppress noExplicitConstructor
474  {
475  if ((*this) == invalidParticle) {
476  throw std::runtime_error("Given ParticleType is not a charged stable particle!");
477  }
478  }
479 
484  explicit ChargedStable(int pdg)
485  : ParticleType(chargedStableSet.find(pdg))
486  {
487  if ((*this) == invalidParticle) {
488  throw std::runtime_error("Given PDG code is not a charged stable particle!");
489  }
490  }
491  static const unsigned int c_SetSize = 6;
492  };
493 
502  class Cluster : public ParticleType {
503  public:
508  // cppcheck-suppress noExplicitConstructor
510  : ParticleType(clusterSet.find(p.getPDGCode()))
511  {
512  if ((*this) == invalidParticle) {
513  throw std::runtime_error("Given ParticleType is not a cluster particle!");
514  }
515  }
516 
521  explicit Cluster(int pdg)
522  : ParticleType(clusterSet.find(pdg))
523  {
524  if ((*this) == invalidParticle) {
525  throw std::runtime_error("Given PDG code is not a cluster particle!");
526  }
527  }
528  static const unsigned int c_SetSize = 6;
529  };
530 
531  static const ParticleSet clusterSet;
533  static const ChargedStable electron;
534  static const ChargedStable muon;
535  static const ChargedStable pion;
536  static const ChargedStable kaon;
537  static const ChargedStable proton;
538  static const ChargedStable deuteron;
540  static const Cluster clusterphoton;
541  static const Cluster clusterKlong;
542  static const Cluster clusterelectron;
543  static const Cluster clusterpion;
544  static const Cluster clustermuon;
545  static const Cluster clusterjunk;
547  static const ParticleType photon;
548  static const ParticleType pi0;
549  static const ParticleType neutron;
550  static const ParticleType Kshort;
551  static const ParticleType Klong;
552  static const ParticleType Lambda;
553  static const ParticleType antiLambda;
557 
558  static const double electronMass;
559  static const double muonMass;
560  static const double pionMass;
561  static const double kaonMass;
562  static const double protonMass;
563  static const double deuteronMass;
564  static const double pi0Mass;
565  static const double neutronMass;
566  static const double K0Mass;
568  static const double speedOfLight;
569  static const double kBoltzmann;
570  static const double ehEnergy;
571  static const double fineStrConst;
572  static const double permSi;
573  static const double uTherm;
574  static const double eMobilitySi;
576  private:
581  Const() = delete;
582  Const(const Const&) = delete;
583  Const& operator=(const Const&) = delete;
584  ~Const() = delete;
587  };
589 }
590 
595 
600 
605 
Belle2::Const::RestrictedDetectorSet::checkSet
void checkSet() const
Check of set validity.
Definition: Const.h:216
Belle2::Const::TrackingDetectors::c_set
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:239
Belle2::Const::ClusterDetectorSet
RestrictedDetectorSet< ClusterDetectors > ClusterDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:268
Belle2::Const::DetectorSet::__repr__
std::string __repr__() const
String for printing in python.
Definition: UnitConst.cc:252
Belle2::Const::photon
static const ParticleType photon
photon particle
Definition: Const.h:547
Belle2::Const::ChargedStable::c_SetSize
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:491
Belle2::Const::RestrictedDetectorSet::set
static DetectorSet set()
Accessor for the set of valid detector IDs.
Definition: Const.h:209
Belle2::Const::ClusterDetectors::c_set
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:264
Belle2::Const::unspecifiedParticle
static const ParticleType unspecifiedParticle
Unspecified particle, used when no other particle type fits.
Definition: Const.h:556
Belle2::Const::uTherm
static const double uTherm
Thermal Voltage at room temperature.
Definition: Const.h:573
Belle2::Const::VXDDetectorSet
RestrictedDetectorSet< VXDDetectors > VXDDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:230
Belle2::Const::invalidParticle
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:554
Belle2::Const::Kshort
static const ParticleType Kshort
K^0_S particle.
Definition: Const.h:550
Belle2::Const::DetectorSet::~DetectorSet
virtual ~DetectorSet()
Destructor.
Definition: Const.h:86
Belle2::Const::ParticleType::operator++
ParticleType & operator++()
Prefix increment.
Definition: UnitConst.cc:287
Belle2::Const::electron
static const ChargedStable electron
electron particle
Definition: Const.h:533
Belle2::Const::Klong
static const ParticleType Klong
K^0_L particle.
Definition: Const.h:551
Belle2::Const::kBoltzmann
static const double kBoltzmann
Boltzmann constant in GeV/K.
Definition: Const.h:569
Belle2::Const::RestrictedDetectorSet::operator+=
RestrictedDetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:203
Belle2::Const::PIDDetectors
A class that defines the valid set of PID detectors.
Definition: Const.h:248
Belle2::OrcaKinFit::FourVector::operator-
FourVector operator-(const FourVector &lhs, const FourVector &rhs)
Difference of two four vectors.
Definition: FourVector.h:211
Belle2::Const::clusterjunk
static const Cluster clusterjunk
junk cluster
Definition: Const.h:545
Belle2::Const::chargedStableSet
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:494
Belle2::Const::ParticleType::getPDGCode
int getPDGCode() const
PDG code.
Definition: Const.h:349
Belle2::Const::ChargedStable::ChargedStable
ChargedStable(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:472
Belle2::Const::clusterelectron
static const Cluster clusterelectron
electron cluster
Definition: Const.h:542
Belle2::Const::DetectorSet
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:66
Belle2::OrcaKinFit::FourVector::operator+
FourVector operator+(const FourVector &lhs, const FourVector &rhs)
Sum of two four vectors.
Definition: FourVector.h:202
Belle2::Const::DetectorSet::getBit
static unsigned short getBit(EDetector det)
Conversion of detector ID to bit pattern.
Definition: UnitConst.cc:190
Belle2::Const::VXDDetectors::c_set
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:227
Belle2::Const::eMobilitySi
static const double eMobilitySi
Electron mobility in intrinsic Silicon at room temperature.
Definition: Const.h:574
Belle2::Const::ParticleSet
A set of ParticleType objects, with defined order.
Definition: Const.h:393
Belle2::Const::DetectorSet::DetectorSet
DetectorSet(EDetector det)
Constructor for a set containig one detector ID.
Definition: Const.h:81
Belle2::Const::deuteronMass
static const double deuteronMass
deuteron mass
Definition: Const.h:563
Belle2::Const::permSi
static const double permSi
Permittivity of Silicon.
Definition: Const.h:572
Belle2::Const::ParticleSet::ParticleSet
ParticleSet()=default
Emtpy constructor.
Belle2::Const::EDetector
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:44
Belle2::Const::ChargedStable::ChargedStable
ChargedStable(int pdg)
Constructor from PDG code.
Definition: Const.h:484
Belle2::Const::DetectorSet::DetectorSet
DetectorSet(unsigned short bits)
Constructor.
Definition: Const.h:148
Belle2::Const::PIDDetectorSet
RestrictedDetectorSet< PIDDetectors > PIDDetectorSet
Typedef for set of PID detectors.
Definition: Const.h:255
Belle2::Const::electronMass
static const double electronMass
electron mass
Definition: Const.h:558
Belle2::Const::ParticleType::ParticleType
ParticleType(int pdgCode, const ParticleSet *set=NULL, int index=-1)
Constructor.
Definition: Const.h:293
Belle2::Const::DetectorSet::operator+=
DetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:92
Belle2::Const::clustermuon
static const Cluster clustermuon
muon cluster
Definition: Const.h:544
Belle2::Const::Cluster::Cluster
Cluster(int pdg)
Constructor from PDG code.
Definition: Const.h:521
Belle2::Const::DetectorSet::operator=
DetectorSet & operator=(const DetectorSet &)=default
Assignment operator.
Belle2::Const::kaon
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:536
Belle2::Const::ParticleSet::operator=
ParticleSet & operator=(const ParticleSet &other)
Assignment operator.
Definition: Const.h:405
Belle2::Const::DetectorSet::operator==
bool operator==(const DetectorSet &set) const
Equality operator.
Definition: Const.h:104
Belle2::Const::Cluster::c_SetSize
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:528
Belle2::Const::neutronMass
static const double neutronMass
neutron mass
Definition: Const.h:565
Belle2::Const::clusterKlong
static const Cluster clusterKlong
K^0_L cluster.
Definition: Const.h:541
Belle2::Const::ParticleSet::contains
bool contains(const ParticleType &p) const
Returns true if and only if the set contains 'p'.
Definition: UnitConst.cc:372
Belle2::Const::RestrictedDetectorSet
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
Definition: Const.h:172
Belle2::Const::speedOfLight
static const double speedOfLight
[cm/ns]
Definition: Const.h:568
Belle2::Const::pion
static const ChargedStable pion
charged pion particle
Definition: Const.h:535
Belle2::Const::allDetectors
static const DetectorSet allDetectors
The set of all detectors.
Definition: Const.h:274
Belle2::Const::ParticleSet::add
void add(const ParticleType &p)
Add a copy of the given ParticleType to this set.
Definition: UnitConst.cc:365
Belle2::Const::TrackingDetectorSet
RestrictedDetectorSet< TrackingDetectors > TrackingDetectorSet
Typedef for set of tracking detectors.
Definition: Const.h:242
Belle2::Const::Cluster
Provides a type-safe way to pass members of the clusterSet set.
Definition: Const.h:502
Belle2::Const::ParticleSet::begin
ParticleType begin() const
Returns first particle.
Definition: Const.h:433
Belle2::Const::ParticleSet::find
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
Definition: Const.h:447
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Const::TrackingDetectors
A class that defines the valid set of tracking detectors.
Definition: Const.h:236
Belle2::Const::deuteron
static const ChargedStable deuteron
deuteron particle
Definition: Const.h:538
Belle2::Const::ParticleSet::at
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
Definition: Const.h:425
Belle2::Const::PIDDetectors::c_set
static const DetectorSet c_set
The set of valid PID detectors.
Definition: Const.h:251
Belle2::Const::VXDDetectors
A class that defines the valid set of VXD detectors.
Definition: Const.h:224
Belle2::Const::DetectorSet::operator[]
EDetector operator[](int index) const
Accessor for a detector ID in this set.
Definition: UnitConst.cc:233
Belle2::Const::pi0
static const ParticleType pi0
neutral pion particle
Definition: Const.h:548
Belle2::Const::ParticleType::operator!=
bool operator!=(const ParticleType &o) const
Test inequality.
Definition: Const.h:311
Belle2::Const::ClusterDetectors::c_size
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:265
Belle2::Const::DetectorSet::operator-=
DetectorSet & operator-=(const DetectorSet &set)
Subtraction of another set from this one.
Definition: Const.h:98
Belle2::Const::protonMass
static const double protonMass
proton mass
Definition: Const.h:562
Belle2::Const::antiLambda
static const ParticleType antiLambda
Anti-Lambda particle.
Definition: Const.h:553
Belle2::Const::neutron
static const ParticleType neutron
neutron particle
Definition: Const.h:549
Belle2::Const::DetectorSet::operator!=
bool operator!=(const DetectorSet &set) const
Inequality operator.
Definition: Const.h:110
Belle2::Const::Cluster::Cluster
Cluster(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:509
Belle2::Const::ParticleType::operator*
ParticleType & operator*()
dummy dereferencing for range-based for.
Definition: Const.h:314
Belle2::Const::ParticleType::m_pdgCode
int m_pdgCode
PDG code of the particle.
Definition: Const.h:363
Belle2::Const::pionMass
static const double pionMass
charged pion mass
Definition: Const.h:560
Belle2::Const::kaonMass
static const double kaonMass
charged kaon mass
Definition: Const.h:561
Belle2::Const::ParticleType::operator==
bool operator==(const ParticleType &o) const
Test equality.
Definition: Const.h:308
Belle2::Const::DetectorSet::getDetector
static EDetector getDetector(unsigned short bit)
Conversion of bit pattern to detector ID.
Definition: UnitConst.cc:203
Belle2::Const::ParticleSet::ParticleSet
ParticleSet(const ParticleSet &other)
Copy constructor to make sure particles belong to correct set.
Definition: Const.h:399
Belle2::Const::ParticleType::m_index
int m_index
index in the associated set, -1 if there's no set.
Definition: Const.h:365
Belle2::Const::ParticleSet::end
ParticleType end() const
Returns an invalid particle to check if iteration should be stopped.
Definition: Const.h:441
Belle2::Const::ParticleType::operator<
bool operator<(const ParticleType &other) const
Comparison operator to be usable in sets.
Definition: UnitConst.cc:282
Belle2::Const::K0Mass
static const double K0Mass
neutral kaon mass
Definition: Const.h:566
Belle2::Const::ParticleSet::size
unsigned int size() const
Returns number of particles in this set.
Definition: Const.h:422
Belle2::Const::clusterpion
static const Cluster clusterpion
charged hadron cluster
Definition: Const.h:543
Belle2::Const::ParticleType
The ParticleType class for identifying different particle types.
Definition: Const.h:284
Belle2::Const::proton
static const ChargedStable proton
proton particle
Definition: Const.h:537
Belle2::Const::Const
Const()=delete
no Const instances allowed.
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::Const::PIDDetectors::c_size
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:252
Belle2::Const::ParticleType::m_set
const ParticleSet * m_set
set this particle belongs to, or NULL if stand-alone.
Definition: Const.h:364
Belle2::Const::muonMass
static const double muonMass
muon mass
Definition: Const.h:559
Belle2::Const::DetectorSet::contains
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:116
Belle2::Const::muon
static const ChargedStable muon
muon particle
Definition: Const.h:534
Belle2::Const::clusterphoton
static const Cluster clusterphoton
photon cluster
Definition: Const.h:540
Belle2::Const::ParticleType::operator=
ParticleType & operator=(const ParticleType &)=default
Assignment Operator.
BELLE2_DEFINE_EXCEPTION
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Definition: FrameworkExceptions.h:46
Belle2::Const
This class provides a set of constants for the framework.
Definition: Const.h:36
Belle2::Const::DetectorSet::DetectorSet
DetectorSet()
Default constructor.
Definition: Const.h:70
Belle2::Const::DetectorSet::getIndex
int getIndex(EDetector det) const
Getter for the index of a given detector in this set.
Definition: UnitConst.cc:222
Belle2::Const::DetectorSet::m_bits
unsigned short m_bits
The internal representation of the set as bit pattern.
Definition: Const.h:164
Belle2::Const::DetectorSet::size
size_t size() const
Getter for number of detector IDs in this set.
Definition: UnitConst.cc:243
Belle2::Const::fineStrConst
static const double fineStrConst
The fine structure constant.
Definition: Const.h:571
Belle2::Const::ClusterDetectors
A class that defines the valid set of Cluster detectors.
Definition: Const.h:261
Belle2::Const::ParticleType::getIndex
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:337
Belle2::Const::RestrictedDetectorSet::RestrictedDetectorSet
RestrictedDetectorSet(EDetector det)
Constructor for a set containg one detector ID.
Definition: Const.h:197
Belle2::Const::ParticleType::__repr__
std::string __repr__() const
String for printing in python.
Definition: UnitConst.cc:315
Belle2::Const::ParticleSet::m_particles
std::vector< ParticleType > m_particles
Actual particles.
Definition: Const.h:457
Belle2::Const::Lambda
static const ParticleType Lambda
Lambda particle.
Definition: Const.h:552
Belle2::Const::ParticleType::getParticlePDG
const TParticlePDG * getParticlePDG() const
Accessor for ROOT TParticlePDG object.
Definition: UnitConst.cc:305
Belle2::Const::ehEnergy
static const double ehEnergy
Energy needed to create an electron-hole pair in Si at std.
Definition: Const.h:570
Belle2::Const::RestrictedDetectorSet::RestrictedDetectorSet
RestrictedDetectorSet(const DetectorSet &set)
(Copy) constructor.
Definition: Const.h:190
Belle2::Const::clusterSet
static const ParticleSet clusterSet
set of cluster particles
Definition: Const.h:531
Belle2::Const::ParticleType::getMass
double getMass() const
Particle mass.
Definition: UnitConst.cc:310
Belle2::Const::pi0Mass
static const double pi0Mass
neutral pion mass
Definition: Const.h:564