Belle II Software light-2405-quaxo
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
65 static std::string parseDetectors(EDetector det);
66
72 public:
73
77 class Iterator {
78
79 public:
80
87 Iterator(int index, uint16_t detectorSetBits, uint16_t setBit) :
88 m_Index(index),
89 m_DetectorSetBits(detectorSetBits),
90 m_SetBit(setBit)
91 {
92 }
93
98 {
99 }
100
105
110 {
111 ++(*this);
112 }
113
118 {
120 }
121
126 {
127 return *(*this);
128 }
129
133 bool operator==(const Iterator& iterator);
134
138 bool operator!=(const Iterator& iterator);
139
143 int getIndex() const
144 {
145 return m_Index;
146 }
147
151 uint16_t getSetBit() const
152 {
153 return m_SetBit;
154 }
155
156 private:
157
160
163
165 uint16_t m_SetBit;
166
167 };
168
172 DetectorSet(const DetectorSet&) = default;
175
180 // cppcheck-suppress noExplicitConstructor
182
186 virtual ~DetectorSet() {};
187
191 Iterator begin() const;
192
196 Iterator end() const;
197
202 DetectorSet& operator += (const DetectorSet& set) {m_bits |= set.m_bits; return *this;}
203
208 DetectorSet& operator -= (const DetectorSet& set) {m_bits &= ~set.m_bits; return *this;}
209
214 bool operator == (const DetectorSet& set) const {return m_bits == set.m_bits;}
215
220 bool operator != (const DetectorSet& set) const {return m_bits != set.m_bits;}
221
226 bool contains(const DetectorSet& set) const {return (m_bits & set.m_bits) == set.m_bits;}
227
232 bool contains(const Iterator& it) const
233 {
234 return (m_bits & it.getSetBit()) != 0;
235 }
236
242 int getIndex(EDetector det) const;
243
247 size_t size() const;
248
252 std::string __str__() const;
253
254 private:
255
260 explicit DetectorSet(uint16_t bits): m_bits(bits) {};
261
267 static uint16_t getBit(EDetector det);
268
274 static EDetector getDetector(uint16_t bit);
275
277 uint16_t m_bits;
278
281
282 };
283
287 template <class ASetType> class RestrictedDetectorSet: public DetectorSet {
288 public:
289
293 BELLE2_DEFINE_EXCEPTION(InvalidDetectorTypeError, "The given detector is not a valid element of the set!")
294
295
299
304 // cppcheck-suppress noExplicitConstructor
306
311 // cppcheck-suppress noExplicitConstructor
313
319
324 static DetectorSet set() {return ASetType::set();}
325
326 private:
327
331 void checkSet() const {if (!ASetType::set().contains(*this)) throw InvalidDetectorTypeError();}
332 };
333
334
340 public:
341 static DetectorSet set() {return c_set;}
342 static const DetectorSet c_set;
343 };
346
352 public:
353 static DetectorSet set() {return c_set;}
354 static const DetectorSet c_set;
355 };
358
364 public:
365 static DetectorSet set() {return c_set;}
366 static const DetectorSet c_set;
367 static const size_t c_size = 6;
368 };
371
377 public:
378 static DetectorSet set() {return c_set;}
379 static const DetectorSet c_set;
380 static const size_t c_size = 2;
381 };
384
385
390
391 class ParticleSet;
392
400 public:
401
408 explicit ParticleType(int pdgCode, const ParticleSet* set = nullptr, int index = -1):
409 m_pdgCode(pdgCode), m_set(set), m_index(index) {}
410
412 ParticleType(const ParticleType&) = default;
415
420 bool operator < (const ParticleType& other) const;
421
423 bool operator==(const ParticleType& o) const { return m_pdgCode == o.m_pdgCode; }
424
426 bool operator!=(const ParticleType& o) const { return !((*this) == o); }
427
429 ParticleType& operator*() { return *this; }
430
436
442
446 operator ParticleSet() const { ParticleSet s; s.add(*this); return s; }
447
452 int getIndex() const { return m_index; }
453
458 const TParticlePDG* getParticlePDG() const;
459
464 int getPDGCode() const {return m_pdgCode;};
465
470 double getMass() const;
471
475 std::string __repr__() const;
476
477 private:
481 };
482
509 public:
511 ParticleSet() = default;
512
515 {
516 for (const ParticleType& pdgIter : other) add(pdgIter);
517 }
518
521 {
522 m_particles.clear();
523 for (const ParticleType& pdgIter : other) add(pdgIter);
524 return *this;
525 }
526
531 void add(const ParticleType& p);
532
534 bool contains(const ParticleType& p) const;
535
537 unsigned int size() const { return m_particles.size(); }
538
540 const ParticleType& at(unsigned int index) const
541 {
542 if (index < m_particles.size())
543 return m_particles[index];
544 return invalidParticle;
545 }
546
549 {
550 if (m_particles.empty())
551 return end();
552 return m_particles[0];
553 }
554
557 {
558 return invalidParticle;
559 }
560
562 const ParticleType& find(int pdg) const
563 {
564 for (ParticleType pdgIter : *this) {
565 if (pdgIter.getPDGCode() == pdg)
566 return m_particles[pdgIter.getIndex()];
567 }
568
569 return invalidParticle;
570 }
571 private:
572 std::vector<ParticleType> m_particles;
573 };
574
581 public:
586 // cppcheck-suppress noExplicitConstructor
589 {
590 if ((*this) == invalidParticle) {
591 throw std::runtime_error("Given ParticleType is not a charged stable particle!");
592 }
593 }
594
599 explicit ChargedStable(int pdg)
600 : ParticleType(chargedStableSet.find(pdg))
601 {
602 if ((*this) == invalidParticle) {
603 throw std::runtime_error("Given PDG code is not a charged stable particle!");
604 }
605 }
606 static const unsigned int c_SetSize = 6;
607 };
608
617 class Cluster : public ParticleType {
618 public:
623 // cppcheck-suppress noExplicitConstructor
626 {
627 if ((*this) == invalidParticle) {
628 throw std::runtime_error("Given ParticleType is not a cluster particle!");
629 }
630 }
631
636 explicit Cluster(int pdg)
637 : ParticleType(clusterSet.find(pdg))
638 {
639 if ((*this) == invalidParticle) {
640 throw std::runtime_error("Given PDG code is not a cluster particle!");
641 }
642 }
643 static const unsigned int c_SetSize = 6;
644 };
645
646 static const ParticleSet clusterSet;
650 static const ChargedStable electron;
651 static const ChargedStable muon;
652 static const ChargedStable pion;
653 static const ChargedStable kaon;
654 static const ChargedStable proton;
655 static const ChargedStable deuteron;
657 static const Cluster clusterphoton;
658 static const Cluster clusterKlong;
660 static const Cluster clusterpion;
661 static const Cluster clustermuon;
662 static const Cluster clusterjunk;
664 static const ParticleType photon;
665 static const ParticleType pi0;
666 static const ParticleType neutron;
668 static const ParticleType Kshort;
669 static const ParticleType Klong;
670 static const ParticleType Lambda;
675
676 static const double electronMass;
677 static const double muonMass;
678 static const double pionMass;
679 static const double kaonMass;
680 static const double protonMass;
681 static const double deuteronMass;
682 static const double pi0Mass;
683 static const double neutronMass;
684 static const double K0Mass;
686 static const double speedOfLight;
687 static const double kBoltzmann;
688 static const double ehEnergy;
689 static const double fineStrConst;
690 static const double permSi;
691 static const double uTherm;
692 static const double eMobilitySi;
694 static const double doubleNaN;
695 static const float floatNaN;
697 private:
702 Const() = delete;
703 Const(const Const&) = delete;
704 Const& operator=(const Const&) = delete;
705 ~Const() = delete;
708 };
710}
711
715Belle2::Const::DetectorSet operator + (const Belle2::Const::DetectorSet& firstSet, const Belle2::Const::DetectorSet& secondSet);
716
720Belle2::Const::DetectorSet operator - (const Belle2::Const::DetectorSet& firstSet, const Belle2::Const::DetectorSet& secondSet);
721
726
730Belle2::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:580
ChargedStable(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:587
ChargedStable(int pdg)
Constructor from PDG code.
Definition: Const.h:599
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:606
A class that defines the valid set of Cluster detectors.
Definition: Const.h:376
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:378
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:380
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:379
Provides a type-safe way to pass members of the clusterSet set.
Definition: Const.h:617
Cluster(const ParticleType &p)
Constructor from the more general ParticleType.
Definition: Const.h:624
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:643
Cluster(int pdg)
Constructor from PDG code.
Definition: Const.h:636
uint16_t getSetBit() const
Get set bit.
Definition: Const.h:151
uint16_t m_DetectorSetBits
Bits in DetectorSet.
Definition: Const.h:162
bool operator==(const Iterator &iterator)
Operator ==.
Definition: UnitConst.cc:197
int getIndex() const
Get index.
Definition: Const.h:143
bool operator!=(const Iterator &iterator)
Operator !=.
Definition: UnitConst.cc:203
Iterator(int index, uint16_t detectorSetBits, uint16_t setBit)
Constructor.
Definition: Const.h:87
Iterator & operator++()
Operator ++.
Definition: UnitConst.cc:182
EDetector operator*() const
Operator *.
Definition: Const.h:117
EDetector getDetector() const
Get detector.
Definition: Const.h:125
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:214
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:186
uint16_t m_bits
The internal representation of the set as bit pattern.
Definition: Const.h:277
DetectorSet & operator=(const DetectorSet &)=default
Assignment operator.
bool operator!=(const DetectorSet &set) const
Inequality operator.
Definition: Const.h:220
DetectorSet & operator-=(const DetectorSet &set)
Subtraction of another set from this one.
Definition: Const.h:208
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:260
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition: Const.h:226
DetectorSet(EDetector det)
Constructor for a set containig one detector ID.
Definition: Const.h:181
bool contains(const Iterator &it) const
Check whether this set contains detector specified by iterator.
Definition: Const.h:232
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:202
DetectorSet()
Default constructor.
Definition: Const.h:170
Iterator begin() const
Beginning iterator.
Definition: UnitConst.cc:209
A class that defines the valid set of PID detectors.
Definition: Const.h:363
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:365
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition: Const.h:367
static const DetectorSet c_set
The set of valid PID detectors.
Definition: Const.h:366
A set of ParticleType objects, with defined order.
Definition: Const.h:508
ParticleType begin() const
Returns first particle.
Definition: Const.h:548
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:537
std::vector< ParticleType > m_particles
Actual particles.
Definition: Const.h:572
ParticleType end() const
Returns an invalid particle to check if iteration should be stopped.
Definition: Const.h:556
ParticleSet & operator=(const ParticleSet &other)
Assignment operator.
Definition: Const.h:520
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:540
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
Definition: Const.h:562
ParticleSet(const ParticleSet &other)
Copy constructor to make sure particles belong to correct set.
Definition: Const.h:514
ParticleSet()=default
Emtpy constructor.
The ParticleType class for identifying different particle types.
Definition: Const.h:399
int getPDGCode() const
PDG code.
Definition: Const.h:464
int getIndex() const
This particle's index in the associated set.
Definition: Const.h:452
bool operator!=(const ParticleType &o) const
Test inequality.
Definition: Const.h:426
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:429
ParticleType(int pdgCode, const ParticleSet *set=nullptr, int index=-1)
Constructor.
Definition: Const.h:408
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:423
int m_index
index in the associated set, -1 if there's no set.
Definition: Const.h:480
int m_pdgCode
PDG code of the particle.
Definition: Const.h:478
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:479
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
Definition: Const.h:287
RestrictedDetectorSet(const DetectorSet &set)
(Copy) constructor.
Definition: Const.h:305
static DetectorSet set()
Accessor for the set of valid detector IDs.
Definition: Const.h:324
RestrictedDetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition: Const.h:318
void checkSet() const
Check of set validity.
Definition: Const.h:331
RestrictedDetectorSet(EDetector det)
Constructor for a set containg one detector ID.
Definition: Const.h:312
A class that defines the valid set of tracking detectors.
Definition: Const.h:351
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:353
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:354
A class that defines the valid set of VXD detectors.
Definition: Const.h:339
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:341
static const DetectorSet c_set
The set of valid tracking detectors.
Definition: Const.h:342
This class provides a set of constants for the framework.
Definition: Const.h:34
static const ParticleType neutron
neutron particle
Definition: Const.h:666
static const ParticleType unspecifiedParticle
Unspecified particle, used when no other particle type fits.
Definition: Const.h:674
static const ParticleType pi0
neutral pion particle
Definition: Const.h:665
static const Cluster clustermuon
muon cluster
Definition: Const.h:661
static const ParticleType Lambda
Lambda particle.
Definition: Const.h:670
static const DetectorSet allDetectors
The set of all detectors.
Definition: Const.h:389
static const double eMobilitySi
Electron mobility in intrinsic Silicon at room temperature.
Definition: Const.h:692
static const ParticleSet clusterSet
set of cluster particles
Definition: Const.h:646
static const ChargedStable muon
muon particle
Definition: Const.h:651
RestrictedDetectorSet< PIDDetectors > PIDDetectorSet
Typedef for set of PID detectors.
Definition: Const.h:370
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:609
static const float floatNaN
quiet_NaN
Definition: Const.h:695
static const double kBoltzmann
Boltzmann constant in GeV/K.
Definition: Const.h:687
static const Cluster clusterelectron
electron cluster
Definition: Const.h:659
static const double kaonMass
charged kaon mass
Definition: Const.h:679
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
static const double K0Mass
neutral kaon mass
Definition: Const.h:684
static const Cluster clusterpion
charged hadron cluster
Definition: Const.h:660
RestrictedDetectorSet< VXDDetectors > VXDDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:345
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
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:678
static const ParticleType Klong
K^0_L particle.
Definition: Const.h:669
static const ParticleSet finalStateParticlesSet
set of final set particles that can be created by the ParticleLoader
Definition: Const.h:648
RestrictedDetectorSet< ClusterDetectors > ClusterDetectorSet
Typedef for set of VXD detectors.
Definition: Const.h:383
static const double permSi
Permittivity of Silicon.
Definition: Const.h:690
static const double speedOfLight
[cm/ns]
Definition: Const.h:686
static const double electronMass
electron mass
Definition: Const.h:676
static const double neutronMass
neutron mass
Definition: Const.h:683
static const Cluster clusterKlong
K^0_L cluster.
Definition: Const.h:658
static const ParticleType antiLambda
Anti-Lambda particle.
Definition: Const.h:671
static const double deuteronMass
deuteron mass
Definition: Const.h:681
static const ChargedStable proton
proton particle
Definition: Const.h:654
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:672
static const double ehEnergy
Energy needed to create an electron-hole pair in Si at std.
Definition: Const.h:688
Const()=delete
no Const instances allowed.
RestrictedDetectorSet< TrackingDetectors > TrackingDetectorSet
Typedef for set of tracking detectors.
Definition: Const.h:357
static const ParticleType Kshort
K^0_S particle.
Definition: Const.h:668
static const double protonMass
proton mass
Definition: Const.h:680
static const double doubleNaN
quiet_NaN
Definition: Const.h:694
static const ParticleType antiNeutron
Anti-neutron particle.
Definition: Const.h:667
static const double fineStrConst
The fine structure constant.
Definition: Const.h:689
static const Cluster clusterjunk
junk cluster
Definition: Const.h:662
static const double uTherm
Thermal Voltage at room temperature.
Definition: Const.h:691
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:653
static const ParticleType photon
photon particle
Definition: Const.h:664
static const double pi0Mass
neutral pion mass
Definition: Const.h:682
static const Cluster clusterphoton
photon cluster
Definition: Const.h:657
static const double muonMass
muon mass
Definition: Const.h:677
static const ChargedStable electron
electron particle
Definition: Const.h:650
static const ChargedStable deuteron
deuteron particle
Definition: Const.h:655
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24