Belle II Software light-2607-kasei
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 {
27
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) const;
143
147 bool operator!=(const Iterator& iterator) const;
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
327 // cppcheck-suppress duplInheritedMember ; intentionally hides the base class member
329
334 static DetectorSet set() {return ASetType::set();}
335
336 private:
337
341 void checkSet() const {if (!ASetType::set().contains(*this)) throw InvalidDetectorTypeError();}
342 };
343
344
350 public:
351 static DetectorSet set() {return c_set;}
352 static const DetectorSet c_set;
353 };
356
362 public:
363 static DetectorSet set() {return c_set;}
364 static const DetectorSet c_set;
365 };
368
374 public:
375 static DetectorSet set() {return c_set;}
376 static const DetectorSet c_set;
377 static const size_t c_size = 6;
378 };
381
387 public:
388 static DetectorSet set() {return c_set;}
389 static const DetectorSet c_set;
390 static const size_t c_size = 2;
391 };
394
395
400
401 class ParticleSet;
402
410 public:
411
418 explicit ParticleType(int pdgCode, const ParticleSet* set = nullptr, int index = -1):
419 m_pdgCode(pdgCode), m_set(set), m_index(index) {}
420
422 ParticleType(const ParticleType&) = default;
425
430 bool operator < (const ParticleType& other) const;
431
433 bool operator==(const ParticleType& o) const { return m_pdgCode == o.m_pdgCode; }
434
436 bool operator!=(const ParticleType& o) const { return !((*this) == o); }
437
439 ParticleType& operator*() { return *this; }
440
446
452
456 operator ParticleSet() const { ParticleSet s; s.add(*this); return s; }
457
462 int getIndex() const { return m_index; }
463
468 const TParticlePDG* getParticlePDG() const;
469
474 int getPDGCode() const {return m_pdgCode;};
475
480 double getMass() const;
481
485 std::string __repr__() const;
486
487 private:
491 };
492
519 public:
521 ParticleSet() = default;
522
525 {
526 for (const ParticleType& pdgIter : other) add(pdgIter);
527 }
528
531 {
532 m_particles.clear();
533 for (const ParticleType& pdgIter : other) add(pdgIter);
534 return *this;
535 }
536
541 void add(const ParticleType& p);
542
544 bool contains(const ParticleType& p) const;
545
547 unsigned int size() const { return m_particles.size(); }
548
550 const ParticleType& at(unsigned int index) const
551 {
552 if (index < m_particles.size())
553 return m_particles[index];
554 return invalidParticle;
555 }
556
559 {
560 if (m_particles.empty())
561 return end();
562 return m_particles[0];
563 }
564
567 {
568 return invalidParticle;
569 }
570
572 const ParticleType& find(int pdg) const
573 {
574 for (const ParticleType& pdgIter : *this) {
575 if (pdgIter.getPDGCode() == pdg)
576 return m_particles[pdgIter.getIndex()];
577 }
578
579 return invalidParticle;
580 }
581 private:
582 std::vector<ParticleType> m_particles;
583 };
584
591 public:
596 // cppcheck-suppress noExplicitConstructor
599 {
600 if ((*this) == invalidParticle) {
601 throw std::runtime_error("Given ParticleType is not a charged stable particle!");
602 }
603 }
604
609 explicit ChargedStable(int pdg)
610 : ParticleType(chargedStableSet.find(pdg))
611 {
612 if ((*this) == invalidParticle) {
613 throw std::runtime_error("Given PDG code is not a charged stable particle!");
614 }
615 }
616 static const unsigned int c_SetSize = 6;
617 };
618
620
621
627 class Cluster : public ParticleType {
628 public:
633 // cppcheck-suppress noExplicitConstructor
636 {
637 if ((*this) == invalidParticle) {
638 throw std::runtime_error("Given ParticleType is not a cluster particle!");
639 }
640 }
641
646 explicit Cluster(int pdg)
647 : ParticleType(clusterSet.find(pdg))
648 {
649 if ((*this) == invalidParticle) {
650 throw std::runtime_error("Given PDG code is not a cluster particle!");
651 }
652 }
653 static const unsigned int c_SetSize = 6;
654 };
655
656 static const ParticleSet clusterSet;
657
659
660 static const ChargedStable electron;
661 static const ChargedStable muon;
662 static const ChargedStable pion;
663 static const ChargedStable kaon;
664 static const ChargedStable proton;
665 static const ChargedStable deuteron;
666
667 static const Cluster clusterphoton;
668 static const Cluster clusterKlong;
670 static const Cluster clusterpion;
671 static const Cluster clustermuon;
672 static const Cluster clusterjunk;
673
674 static const ParticleType photon;
675 static const ParticleType pi0;
676 static const ParticleType neutron;
678 static const ParticleType Kshort;
679 static const ParticleType Klong;
680 static const ParticleType Lambda;
685
686 static const double electronMass;
687 static const double muonMass;
688 static const double pionMass;
689 static const double kaonMass;
690 static const double protonMass;
691 static const double deuteronMass;
692 static const double pi0Mass;
693 static const double neutronMass;
694 static const double K0Mass;
695
696 static const double speedOfLight;
697 static const double kBoltzmann;
698 static const double ehEnergy;
699 static const double fineStrConst;
700 static const double permSi;
701 static const double uTherm;
702 static const double eMobilitySi;
703
704 static const double doubleNaN;
705 static const float floatNaN;
706
707 private:
712 Const() = delete;
713 Const(const Const&) = delete;
714 Const& operator=(const Const&) = delete;
715 ~Const() = delete;
717
718 };
720}
721
725Belle2::Const::DetectorSet operator + (const Belle2::Const::DetectorSet& firstSet, const Belle2::Const::DetectorSet& secondSet);
726
730Belle2::Const::DetectorSet operator - (const Belle2::Const::DetectorSet& firstSet, const Belle2::Const::DetectorSet& secondSet);
731
736
740Belle2::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:590
ChargedStable(const ParticleType &p)
Constructor from the more general ParticleType.
Definition Const.h:597
ChargedStable(int pdg)
Constructor from PDG code.
Definition Const.h:609
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition Const.h:616
A class that defines the valid set of Cluster detectors.
Definition Const.h:386
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition Const.h:388
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition Const.h:390
static const DetectorSet c_set
The set of valid tracking detectors.
Definition Const.h:389
Provides a type-safe way to pass members of the clusterSet set.
Definition Const.h:627
Cluster(const ParticleType &p)
Constructor from the more general ParticleType.
Definition Const.h:634
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition Const.h:653
Cluster(int pdg)
Constructor from PDG code.
Definition Const.h:646
uint16_t getSetBit() const
Get set bit.
Definition Const.h:160
uint16_t m_DetectorSetBits
Bits in DetectorSet.
Definition Const.h:171
int getIndex() const
Get index.
Definition Const.h:152
bool operator!=(const Iterator &iterator) const
Operator !=.
Definition UnitConst.cc:201
Iterator(int index, uint16_t detectorSetBits, uint16_t setBit)
Constructor.
Definition Const.h:96
bool operator==(const Iterator &iterator) const
Operator ==.
Definition UnitConst.cc:196
Iterator & operator++()
Operator ++.
Definition UnitConst.cc:181
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:295
size_t size() const
Getter for number of detector IDs in this set.
Definition UnitConst.cc:286
int getIndex(EDetector det) const
Getter for the index of a given detector in this set.
Definition UnitConst.cc:275
Iterator end() const
Ending iterator.
Definition UnitConst.cc:217
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:243
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 containing 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:256
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:206
A class that defines the valid set of PID detectors.
Definition Const.h:373
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition Const.h:375
static const size_t c_size
Number of PID detectors, temporary workaround.
Definition Const.h:377
static const DetectorSet c_set
The set of valid PID detectors.
Definition Const.h:376
A set of ParticleType objects, with defined order.
Definition Const.h:518
ParticleType begin() const
Returns first particle.
Definition Const.h:558
static ParticleType end()
Returns an invalid particle to check if iteration should be stopped.
Definition Const.h:566
bool contains(const ParticleType &p) const
Returns true if and only if the set contains 'p'.
Definition UnitConst.cc:421
unsigned int size() const
Returns number of particles in this set.
Definition Const.h:547
std::vector< ParticleType > m_particles
Actual particles.
Definition Const.h:582
ParticleSet & operator=(const ParticleSet &other)
Assignment operator.
Definition Const.h:530
void add(const ParticleType &p)
Add a copy of the given ParticleType to this set.
Definition UnitConst.cc:414
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
Definition Const.h:550
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
Definition Const.h:572
ParticleSet(const ParticleSet &other)
Copy constructor to make sure particles belong to correct set.
Definition Const.h:524
ParticleSet()=default
Empty constructor.
The ParticleType class for identifying different particle types.
Definition Const.h:409
int getPDGCode() const
PDG code.
Definition Const.h:474
int getIndex() const
This particle's index in the associated set.
Definition Const.h:462
bool operator!=(const ParticleType &o) const
Test inequality.
Definition Const.h:436
ParticleType & operator=(const ParticleType &)=default
Assignment Operator.
std::string __repr__() const
String for printing in python.
Definition UnitConst.cc:358
ParticleType(const ParticleType &)=default
Copy constructor.
ParticleType & operator*()
dummy dereferencing for range-based for.
Definition Const.h:439
ParticleType(int pdgCode, const ParticleSet *set=nullptr, int index=-1)
Constructor.
Definition Const.h:418
bool operator<(const ParticleType &other) const
Comparison operator to be usable in sets.
Definition UnitConst.cc:325
bool operator==(const ParticleType &o) const
Test equality.
Definition Const.h:433
int m_index
index in the associated set, -1 if there's no set.
Definition Const.h:490
int m_pdgCode
PDG code of the particle.
Definition Const.h:488
const TParticlePDG * getParticlePDG() const
Accessor for ROOT TParticlePDG object.
Definition UnitConst.cc:348
ParticleType & operator++()
Prefix increment.
Definition UnitConst.cc:330
double getMass() const
Particle mass.
Definition UnitConst.cc:353
const ParticleSet * m_set
set this particle belongs to, or NULL if stand-alone.
Definition Const.h:489
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
RestrictedDetectorSet()
Exception that is thrown if there is the attempt to add an invalid detector ID to a restricted set.
Definition Const.h:307
RestrictedDetectorSet & operator+=(const DetectorSet &set)
Addition of another set to this one.
Definition Const.h:328
void checkSet() const
Check of set validity.
Definition Const.h:341
RestrictedDetectorSet(EDetector det)
Constructor for a set containing one detector ID.
Definition Const.h:321
A class that defines the valid set of tracking detectors.
Definition Const.h:361
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition Const.h:363
static const DetectorSet c_set
The set of valid tracking detectors.
Definition Const.h:364
A class that defines the valid set of VXD detectors.
Definition Const.h:349
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition Const.h:351
static const DetectorSet c_set
The set of valid tracking detectors.
Definition Const.h:352
static const ParticleType neutron
neutron particle
Definition Const.h:676
static const ParticleType unspecifiedParticle
Unspecified particle, used when no other particle type fits.
Definition Const.h:684
static const ParticleType pi0
neutral pion particle
Definition Const.h:675
static const Cluster clustermuon
muon cluster
Definition Const.h:671
static const ParticleType Lambda
Lambda particle.
Definition Const.h:680
static const DetectorSet allDetectors
The set of all detectors.
Definition Const.h:399
static const double eMobilitySi
Electron mobility in intrinsic Silicon at room temperature.
Definition Const.h:702
static const ParticleSet clusterSet
set of cluster particles
Definition Const.h:656
static const ChargedStable muon
muon particle
Definition Const.h:661
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:380
static const ParticleSet chargedStableSet
set of charged stable particles
Definition Const.h:619
static const float floatNaN
quiet_NaN
Definition Const.h:705
static const double kBoltzmann
Boltzmann constant in GeV/K.
Definition Const.h:697
static const Cluster clusterelectron
electron cluster
Definition Const.h:669
static const double kaonMass
charged kaon mass
Definition Const.h:689
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition Const.h:42
static const double K0Mass
neutral kaon mass
Definition Const.h:694
static const Cluster clusterpion
charged hadron cluster
Definition Const.h:670
RestrictedDetectorSet< VXDDetectors > VXDDetectorSet
Typedef for set of VXD detectors.
Definition Const.h:355
static const ChargedStable pion
charged pion particle
Definition Const.h:662
static std::string parseDetectors(EDetector det)
Converts Const::EDetector object to string.
Definition UnitConst.cc:161
static const double pionMass
charged pion mass
Definition Const.h:688
static const ParticleType Klong
K^0_L particle.
Definition Const.h:679
static const ParticleSet finalStateParticlesSet
set of final set particles that can be created by the ParticleLoader
Definition Const.h:658
RestrictedDetectorSet< ClusterDetectors > ClusterDetectorSet
Typedef for set of VXD detectors.
Definition Const.h:393
static const double permSi
Permittivity of Silicon.
Definition Const.h:700
static const double speedOfLight
[cm/ns]
Definition Const.h:696
static const double electronMass
electron mass
Definition Const.h:686
static const double neutronMass
neutron mass
Definition Const.h:693
static const Cluster clusterKlong
K^0_L cluster.
Definition Const.h:668
static const ParticleType antiLambda
Anti-Lambda particle.
Definition Const.h:681
static const double deuteronMass
deuteron mass
Definition Const.h:691
static const ChargedStable proton
proton particle
Definition Const.h:664
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition Const.h:682
static const double ehEnergy
Energy needed to create an electron-hole pair in Si at std.
Definition Const.h:698
Const()=delete
no Const instances allowed.
RestrictedDetectorSet< TrackingDetectors > TrackingDetectorSet
Typedef for set of tracking detectors.
Definition Const.h:367
static const ParticleType Kshort
K^0_S particle.
Definition Const.h:678
static const double protonMass
proton mass
Definition Const.h:690
static const double doubleNaN
quiet_NaN
Definition Const.h:704
static const ParticleType antiNeutron
Anti-neutron particle.
Definition Const.h:677
static const double fineStrConst
The fine structure constant.
Definition Const.h:699
static const Cluster clusterjunk
junk cluster
Definition Const.h:672
static const double uTherm
Thermal Voltage at room temperature.
Definition Const.h:701
static const ChargedStable kaon
charged kaon particle
Definition Const.h:663
static const ParticleType photon
photon particle
Definition Const.h:674
static const double pi0Mass
neutral pion mass
Definition Const.h:692
static const Cluster clusterphoton
photon cluster
Definition Const.h:667
static const double muonMass
muon mass
Definition Const.h:687
static const ChargedStable electron
electron particle
Definition Const.h:660
static const ChargedStable deuteron
deuteron particle
Definition Const.h:665
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Abstract base class for different kinds of events.