Belle II Software development
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
19class TDatabasePDG;
20class TParticlePDG;
21
22namespace 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
64 enum ERunType {
65 c_Beam,
66 c_Cosmic
67 };
68
74 static std::string parseDetectors(EDetector det);
75
81 public:
82
86 class Iterator {
87
88 public:
89
96 Iterator(int index, uint16_t detectorSetBits, uint16_t setBit) :
97 m_Index(index),
98 m_DetectorSetBits(detectorSetBits),
99 m_SetBit(setBit)
100 {
101 }
102
107 {
108 }
109
114
119 {
120 ++(*this);
121 }
122
127 {
129 }
130
135 {
136 return *(*this);
137 }
138
142 bool operator==(const Iterator& iterator);
143
147 bool operator!=(const Iterator& iterator);
148
152 int getIndex() const
153 {
154 return m_Index;
155 }
156
160 uint16_t getSetBit() const
161 {
162 return m_SetBit;
163 }
164
165 private:
166
169
172
174 uint16_t m_SetBit;
175
176 };
177
181 DetectorSet(const DetectorSet&) = default;
184
189 // cppcheck-suppress noExplicitConstructor
191
195 virtual ~DetectorSet() {};
196
200 Iterator begin() const;
201
205 Iterator end() const;
206
211 DetectorSet& operator += (const DetectorSet& set) {m_bits |= set.m_bits; return *this;}
212
217 DetectorSet& operator -= (const DetectorSet& set) {m_bits &= ~set.m_bits; return *this;}
218
223 bool operator == (const DetectorSet& set) const {return m_bits == set.m_bits;}
224
229 bool operator != (const DetectorSet& set) const {return m_bits != set.m_bits;}
230
235 bool contains(const DetectorSet& set) const {return (m_bits & set.m_bits) == set.m_bits;}
236
241 bool contains(const Iterator& it) const
242 {
243 return (m_bits & it.getSetBit()) != 0;
244 }
245
251 int getIndex(EDetector det) const;
252
256 size_t size() const;
257
261 std::string __str__() const;
262
263 private:
264
269 explicit DetectorSet(uint16_t bits): m_bits(bits) {};
270
276 static uint16_t getBit(EDetector det);
277
283 static EDetector getDetector(uint16_t bit);
284
286 uint16_t m_bits;
287
290
291 };
292
296 template <class ASetType> class RestrictedDetectorSet: public DetectorSet {
297 public:
298
302 BELLE2_DEFINE_EXCEPTION(InvalidDetectorTypeError, "The given detector is not a valid element of the set!")
303
304
308
313 // cppcheck-suppress noExplicitConstructor
315
320 // cppcheck-suppress noExplicitConstructor
322
328
333 static DetectorSet set() {return ASetType::set();}
334
335 private:
336
340 void checkSet() const {if (!ASetType::set().contains(*this)) throw InvalidDetectorTypeError();}
341 };
342
343
349 public:
350 static DetectorSet set() {return c_set;}
351 static const DetectorSet c_set;
352 };
355
361 public:
362 static DetectorSet set() {return c_set;}
363 static const DetectorSet c_set;
364 };
367
373 public:
374 static DetectorSet set() {return c_set;}
375 static const DetectorSet c_set;
376 static const size_t c_size = 6;
377 };
380
386 public:
387 static DetectorSet set() {return c_set;}
388 static const DetectorSet c_set;
389 static const size_t c_size = 2;
390 };
393
394
399
400 class ParticleSet;
401
409 public:
410
417 explicit ParticleType(int pdgCode, const ParticleSet* set = nullptr, int index = -1):
418 m_pdgCode(pdgCode), m_set(set), m_index(index) {}
419
421 ParticleType(const ParticleType&) = default;
424
429 bool operator < (const ParticleType& other) const;
430
432 bool operator==(const ParticleType& o) const { return m_pdgCode == o.m_pdgCode; }
433
435 bool operator!=(const ParticleType& o) const { return !((*this) == o); }
436
438 ParticleType& operator*() { return *this; }
439
445
451
455 operator ParticleSet() const { ParticleSet s; s.add(*this); return s; }
456
461 int getIndex() const { return m_index; }
462
467 const TParticlePDG* getParticlePDG() const;
468
473 int getPDGCode() const {return m_pdgCode;};
474
479 double getMass() const;
480
484 std::string __repr__() const;
485
486 private:
490 };
491
518 public:
520 ParticleSet() = default;
521
524 {
525 for (const ParticleType& pdgIter : other) add(pdgIter);
526 }
527
530 {
531 m_particles.clear();
532 for (const ParticleType& pdgIter : other) add(pdgIter);
533 return *this;
534 }
535
540 void add(const ParticleType& p);
541
543 bool contains(const ParticleType& p) const;
544
546 unsigned int size() const { return m_particles.size(); }
547
549 const ParticleType& at(unsigned int index) const
550 {
551 if (index < m_particles.size())
552 return m_particles[index];
553 return invalidParticle;
554 }
555
558 {
559 if (m_particles.empty())
560 return end();
561 return m_particles[0];
562 }
563
566 {
567 return invalidParticle;
568 }
569
571 const ParticleType& find(int pdg) const
572 {
573 for (ParticleType pdgIter : *this) {
574 if (pdgIter.getPDGCode() == pdg)
575 return m_particles[pdgIter.getIndex()];
576 }
577
578 return invalidParticle;
579 }
580 private:
581 std::vector<ParticleType> m_particles;
582 };
583
590 public:
595 // cppcheck-suppress noExplicitConstructor
598 {
599 if ((*this) == invalidParticle) {
600 throw std::runtime_error("Given ParticleType is not a charged stable particle!");
601 }
602 }
603
608 explicit ChargedStable(int pdg)
609 : ParticleType(chargedStableSet.find(pdg))
610 {
611 if ((*this) == invalidParticle) {
612 throw std::runtime_error("Given PDG code is not a charged stable particle!");
613 }
614 }
615 static const unsigned int c_SetSize = 6;
616 };
617
626 class Cluster : public ParticleType {
627 public:
632 // cppcheck-suppress noExplicitConstructor
635 {
636 if ((*this) == invalidParticle) {
637 throw std::runtime_error("Given ParticleType is not a cluster particle!");
638 }
639 }
640
645 explicit Cluster(int pdg)
646 : ParticleType(clusterSet.find(pdg))
647 {
648 if ((*this) == invalidParticle) {
649 throw std::runtime_error("Given PDG code is not a cluster particle!");
650 }
651 }
652 static const unsigned int c_SetSize = 6;
653 };
654
655 static const ParticleSet clusterSet;
659 static const ChargedStable electron;
660 static const ChargedStable muon;
661 static const ChargedStable pion;
662 static const ChargedStable kaon;
663 static const ChargedStable proton;
664 static const ChargedStable deuteron;
666 static const Cluster clusterphoton;
667 static const Cluster clusterKlong;
669 static const Cluster clusterpion;
670 static const Cluster clustermuon;
671 static const Cluster clusterjunk;
673 static const ParticleType photon;
674 static const ParticleType pi0;
675 static const ParticleType neutron;
677 static const ParticleType Kshort;
678 static const ParticleType Klong;
679 static const ParticleType Lambda;
684
685 static const double electronMass;
686 static const double muonMass;
687 static const double pionMass;
688 static const double kaonMass;
689 static const double protonMass;
690 static const double deuteronMass;
691 static const double pi0Mass;
692 static const double neutronMass;
693 static const double K0Mass;
695 static const double speedOfLight;
696 static const double kBoltzmann;
697 static const double ehEnergy;
698 static const double fineStrConst;
699 static const double permSi;
700 static const double uTherm;
701 static const double eMobilitySi;
703 static const double doubleNaN;
704 static const float floatNaN;
706 private:
711 Const() = delete;
712 Const(const Const&) = delete;
713 Const& operator=(const Const&) = delete;
714 ~Const() = delete;
717 };
719}
720
724Belle2::Const::DetectorSet operator + (const Belle2::Const::DetectorSet& firstSet, const Belle2::Const::DetectorSet& secondSet);
725
729Belle2::Const::DetectorSet operator - (const Belle2::Const::DetectorSet& firstSet, const Belle2::Const::DetectorSet& secondSet);
730
735
739Belle2::Const::ParticleSet operator + (const Belle2::Const::ParticleSet& firstSet, const Belle2::Const::ParticleSet& secondSet);
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
ChargedStable(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:596
ChargedStable(int pdg)
Constructor from PDG code.
Definition: Const.h:608
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:615
A class that defines the valid set of Cluster detectors.
Definition: Const.h:385
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:387
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:389
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:388
Provides a type-safe way to pass members of the clusterSet set.
Definition: Const.h:626
Cluster(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:633
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:652
Cluster(int pdg)
Constructor from PDG code.
Definition: Const.h:645
uint16_t getSetBit() const
Get set bit.
Definition: Const.h:160
uint16_t m_DetectorSetBits
Bits in DetectorSet.
Definition: Const.h:171
bool operator==(const Iterator &iterator)
Operator ==.
Definition: UnitConst.cc:197
int getIndex() const
Get index.
Definition: Const.h:152
bool operator!=(const Iterator &iterator)
Operator !=.
Definition: UnitConst.cc:203
Iterator(int index, uint16_t detectorSetBits, uint16_t setBit)
Constructor.
Definition: Const.h:96
Iterator & operator++()
Operator ++.
Definition: UnitConst.cc:182
EDetector operator*() const
Operator *.
Definition: Const.h:126
EDetector getDetector() const
Get detector.
Definition: Const.h:134
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:80
bool operator==(const DetectorSet &set) const
Equality operator.
Definition: Const.h:223
std::string __str__() const
String for printing in python.
Definition: UnitConst.cc:298
size_t size() const
Getter for number of detector IDs in this set.
Definition: UnitConst.cc:289
int getIndex(EDetector det) const
Getter for the index of a given detector in this set.
Definition: UnitConst.cc:278
Iterator end() const
Ending iterator.
Definition: UnitConst.cc:220
virtual ~DetectorSet()
Destructor.
Definition: Const.h:195
uint16_t m_bits
The internal representation of the set as bit pattern.
Definition: Const.h:286
DetectorSet & operator=(const DetectorSet &)=default
Assignment operator.
bool operator!=(const DetectorSet &set) const
Inequality operator.
Definition: Const.h:229
DetectorSet & operator-=(const DetectorSet &set)
Subtraction of another set from this one.
Definition: Const.h:217
static uint16_t getBit(EDetector det)
Conversion of detector ID to bit pattern.
Definition: UnitConst.cc:246
DetectorSet(const DetectorSet &)=default
Copy constructor.
ClassDef(DetectorSet, 1)
Class version.
DetectorSet(uint16_t bits)
Constructor.
Definition: Const.h:269
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:235
DetectorSet(EDetector det)
Constructor for a set containig one detector ID.
Definition: Const.h:190
bool contains(const Iterator &it) const
Check whether this set contains detector specified by iterator.
Definition: Const.h:241
static EDetector getDetector(uint16_t bit)
Conversion of bit pattern to detector ID.
Definition: UnitConst.cc:259
DetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:211
DetectorSet()
Default constructor.
Definition: Const.h:179
Iterator begin() const
Beginning iterator.
Definition: UnitConst.cc:209
A class that defines the valid set of PID detectors.
Definition: Const.h:372
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:374
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:376
static const DetectorSet c_set
The set of valid PID detectors.
Definition: Const.h:375
A set of ParticleType objects, with defined order.
Definition: Const.h:517
ParticleType begin() const
Returns first particle.
Definition: Const.h:557
bool contains(const ParticleType &p) const
Returns true if and only if the set contains 'p'.
Definition: UnitConst.cc:424
unsigned int size() const
Returns number of particles in this set.
Definition: Const.h:546
std::vector< ParticleType > m_particles
Actual particles.
Definition: Const.h:581
ParticleType end() const
Returns an invalid particle to check if iteration should be stopped.
Definition: Const.h:565
ParticleSet & operator=(const ParticleSet &other)
Assignment operator.
Definition: Const.h:529
void add(const ParticleType &p)
Add a copy of the given ParticleType to this set.
Definition: UnitConst.cc:417
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
Definition: Const.h:549
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
Definition: Const.h:571
ParticleSet(const ParticleSet &other)
Copy constructor to make sure particles belong to correct set.
Definition: Const.h:523
ParticleSet()=default
Emtpy constructor.
The ParticleType class for identifying different particle types.
Definition: Const.h:408
int getPDGCode() const
PDG code.
Definition: Const.h:473
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:461
bool operator!=(const ParticleType &o) const
Test inequality.
Definition: Const.h:435
ParticleType & operator=(const ParticleType &)=default
Assignment Operator.
std::string __repr__() const
String for printing in python.
Definition: UnitConst.cc:361
ParticleType(const ParticleType &)=default
Copy constructor
ParticleType & operator*()
dummy dereferencing for range-based for.
Definition: Const.h:438
ParticleType(int pdgCode, const ParticleSet *set=nullptr, int index=-1)
Constructor.
Definition: Const.h:417
bool operator<(const ParticleType &other) const
Comparison operator to be usable in sets.
Definition: UnitConst.cc:328
bool operator==(const ParticleType &o) const
Test equality.
Definition: Const.h:432
int m_index
index in the associated set, -1 if there's no set.
Definition: Const.h:489
int m_pdgCode
PDG code of the particle.
Definition: Const.h:487
const TParticlePDG * getParticlePDG() const
Accessor for ROOT TParticlePDG object.
Definition: UnitConst.cc:351
ParticleType & operator++()
Prefix increment.
Definition: UnitConst.cc:333
double getMass() const
Particle mass.
Definition: UnitConst.cc:356
const ParticleSet * m_set
set this particle belongs to, or NULL if stand-alone.
Definition: Const.h:488
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
Definition: Const.h:296
RestrictedDetectorSet(const DetectorSet &set)
(Copy) constructor.
Definition: Const.h:314
static DetectorSet set()
Accessor for the set of valid detector IDs.
Definition: Const.h:333
RestrictedDetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:327
void checkSet() const
Check of set validity.
Definition: Const.h:340
RestrictedDetectorSet(EDetector det)
Constructor for a set containg one detector ID.
Definition: Const.h:321
A class that defines the valid set of tracking detectors.
Definition: Const.h:360
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:362
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:363
A class that defines the valid set of VXD detectors.
Definition: Const.h:348
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:350
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:351
This class provides a set of constants for the framework.
Definition: Const.h:34
static const ParticleType neutron
neutron particle
Definition: Const.h:675
static const ParticleType unspecifiedParticle
Unspecified particle, used when no other particle type fits.
Definition: Const.h:683
static const ParticleType pi0
neutral pion particle
Definition: Const.h:674
static const Cluster clustermuon
muon cluster
Definition: Const.h:670
static const ParticleType Lambda
Lambda particle.
Definition: Const.h:679
static const DetectorSet allDetectors
The set of all detectors.
Definition: Const.h:398
static const double eMobilitySi
Electron mobility in intrinsic Silicon at room temperature.
Definition: Const.h:701
static const ParticleSet clusterSet
set of cluster particles
Definition: Const.h:655
static const ChargedStable muon
muon particle
Definition: Const.h:660
ERunType
Enum for identifying run type (beam or cosmic)
Definition: Const.h:64
RestrictedDetectorSet< PIDDetectors > PIDDetectorSet
Typedef for set of PID detectors.
Definition: Const.h:379
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:618
static const float floatNaN
quiet_NaN
Definition: Const.h:704
static const double kBoltzmann
Boltzmann constant in GeV/K.
Definition: Const.h:696
static const Cluster clusterelectron
electron cluster
Definition: Const.h:668
static const double kaonMass
charged kaon mass
Definition: Const.h:688
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
static const double K0Mass
neutral kaon mass
Definition: Const.h:693
static const Cluster clusterpion
charged hadron cluster
Definition: Const.h:669
RestrictedDetectorSet< VXDDetectors > VXDDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:354
static const ChargedStable pion
charged pion particle
Definition: Const.h:661
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:687
static const ParticleType Klong
K^0_L particle.
Definition: Const.h:678
static const ParticleSet finalStateParticlesSet
set of final set particles that can be created by the ParticleLoader
Definition: Const.h:657
RestrictedDetectorSet< ClusterDetectors > ClusterDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:392
static const double permSi
Permittivity of Silicon.
Definition: Const.h:699
static const double speedOfLight
[cm/ns]
Definition: Const.h:695
static const double electronMass
electron mass
Definition: Const.h:685
static const double neutronMass
neutron mass
Definition: Const.h:692
static const Cluster clusterKlong
K^0_L cluster.
Definition: Const.h:667
static const ParticleType antiLambda
Anti-Lambda particle.
Definition: Const.h:680
static const double deuteronMass
deuteron mass
Definition: Const.h:690
static const ChargedStable proton
proton particle
Definition: Const.h:663
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:681
static const double ehEnergy
Energy needed to create an electron-hole pair in Si at std.
Definition: Const.h:697
Const()=delete
no Const instances allowed.
RestrictedDetectorSet< TrackingDetectors > TrackingDetectorSet
Typedef for set of tracking detectors.
Definition: Const.h:366
static const ParticleType Kshort
K^0_S particle.
Definition: Const.h:677
static const double protonMass
proton mass
Definition: Const.h:689
static const double doubleNaN
quiet_NaN
Definition: Const.h:703
static const ParticleType antiNeutron
Anti-neutron particle.
Definition: Const.h:676
static const double fineStrConst
The fine structure constant.
Definition: Const.h:698
static const Cluster clusterjunk
junk cluster
Definition: Const.h:671
static const double uTherm
Thermal Voltage at room temperature.
Definition: Const.h:700
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:662
static const ParticleType photon
photon particle
Definition: Const.h:673
static const double pi0Mass
neutral pion mass
Definition: Const.h:691
static const Cluster clusterphoton
photon cluster
Definition: Const.h:666
static const double muonMass
muon mass
Definition: Const.h:686
static const ChargedStable electron
electron particle
Definition: Const.h:659
static const ChargedStable deuteron
deuteron particle
Definition: Const.h:664
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
map< unsigned, size_t >::const_iterator Iterator
Iteratior for m_map.
Abstract base class for different kinds of events.