Belle II Software  release-08-01-10
MuidElementNumbers.cc
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 /* Own header. */
10 #include <klm/muid/MuidElementNumbers.h>
11 
12 /* Basf2 headers. */
13 #include <framework/gearbox/Const.h>
14 
15 using namespace Belle2;
16 
18 {
19 }
20 
22 {
23 }
24 
25 bool MuidElementNumbers::checkExtrapolationOutcome(unsigned int outcome, int lastLayer)
26 {
27  /* KLM volume not reached during the extrapolation. */
28  if (outcome == MuidElementNumbers::c_NotReached)
29  return false;
30  /* Barrel stop: never in layer 14. */
31  if ((outcome == MuidElementNumbers::c_StopInBarrel)
32  && (lastLayer > MuidElementNumbers::getMaximalBarrelLayer() - 1))
33  return false;
34  /* Forward endcap stop: never in layer 13. */
35  if ((outcome == MuidElementNumbers::c_StopInForwardEndcap)
37  return false;
38  /* Barrel exit: no layers greater than 15. */
39  if ((outcome == MuidElementNumbers::c_ExitBarrel)
41  return false;
42  /* Forward endcap exit: no layers greater than 14. */
43  if ((outcome == MuidElementNumbers::c_ExitForwardEndcap)
45  return false;
46  /* Backward endcap stop: never in layer 11. */
47  if ((outcome == MuidElementNumbers::c_StopInBackwardEndcap)
49  return false;
50  /* Backward endcap exit: no layers greater than 12. */
51  if ((outcome == MuidElementNumbers::c_ExitBackwardEndcap)
53  return false;
54  /* Like outcome == c_StopInForwardEndcap. */
55  if ((outcome >= MuidElementNumbers::c_CrossBarrelStopInForwardMin)
56  && (outcome <= MuidElementNumbers::c_CrossBarrelStopInForwardMax)
58  return false;
59  /* Like outcome == c_StopInBackwardEndcap. */
60  if ((outcome >= MuidElementNumbers::c_CrossBarrelStopInBackwardMin)
61  && (outcome <= MuidElementNumbers::c_CrossBarrelStopInBackwardMax)
63  return false;
64  /* Like outcome == c_ExitForwardEndcap. */
65  if ((outcome >= MuidElementNumbers::c_CrossBarrelExitForwardMin)
66  && (outcome <= MuidElementNumbers::c_CrossBarrelExitForwardMax)
68  return false;
69  /* Like outcome == c_ExitBackwardEndcap. */
70  if ((outcome >= MuidElementNumbers::c_CrossBarrelExitBackwardMin)
71  && (outcome <= MuidElementNumbers::c_CrossBarrelExitBackwardMax)
73  return false;
74  return true;
75 }
76 
77 unsigned int MuidElementNumbers::calculateExtrapolationOutcome(bool isForward, bool escaped, int lastBarrelLayer,
78  int lastEndcapLayer)
79 {
80  unsigned int outcome = MuidElementNumbers::c_NotReached;
81  if ((lastBarrelLayer >= 0) || (lastEndcapLayer >= 0)) {
82  /* Stop or exit in barrel. */
83  if (lastEndcapLayer < 0) {
84  if (escaped)
85  outcome = MuidElementNumbers::c_ExitBarrel;
86  else
87  outcome = MuidElementNumbers::c_StopInBarrel;
88  }
89  /* Stop or exit in endcap. */
90  else {
91  if (escaped) {
92  if (lastBarrelLayer < 0) { /* Exit in endcap with no barrel hits. */
93  if (isForward)
94  outcome = MuidElementNumbers::c_ExitForwardEndcap;
95  else
96  outcome = MuidElementNumbers::c_ExitBackwardEndcap;
97  } else { /* Exit in endcap with barrel hits. */
98  if (isForward)
99  outcome = MuidElementNumbers::c_CrossBarrelExitForwardMin + lastBarrelLayer;
100  else
101  outcome = MuidElementNumbers::c_CrossBarrelExitBackwardMin + lastBarrelLayer;
102  }
103  } else {
104  if (lastBarrelLayer < 0) { /* Stop in endcap with no barrel hits. */
105  if (isForward)
106  outcome = MuidElementNumbers::c_StopInForwardEndcap;
107  else
108  outcome = MuidElementNumbers::c_StopInBackwardEndcap;
109  } else { /* Stop in endcap with barrel hits. */
110  if (isForward)
111  outcome = MuidElementNumbers::c_CrossBarrelStopInForwardMin + lastBarrelLayer;
112  else
113  outcome = MuidElementNumbers::c_CrossBarrelStopInBackwardMin + lastBarrelLayer;
114  }
115  }
116  }
117  }
118  return outcome;
119 }
120 
122 {
123  /* For leptons, the sign of the PDG code is opposite to the charge. */
124  if (pdg == Const::electron.getPDGCode())
125  return MuidElementNumbers::c_Electron;
126  if (pdg == -Const::electron.getPDGCode())
127  return MuidElementNumbers::c_Positron;
128  if (pdg == Const::muon.getPDGCode())
129  return MuidElementNumbers::c_MuonMinus;
130  if (pdg == -Const::muon.getPDGCode())
131  return MuidElementNumbers::c_MuonPlus;
132  /* For hadrons, the sign of the PDG code is equal to the charge. */
133  if (pdg == Const::deuteron.getPDGCode())
134  return MuidElementNumbers::c_Deuteron;
135  if (pdg == -Const::deuteron.getPDGCode())
136  return MuidElementNumbers::c_AntiDeuteron;
137  if (pdg == Const::proton.getPDGCode())
138  return MuidElementNumbers::c_Proton;
139  if (pdg == -Const::proton.getPDGCode())
140  return MuidElementNumbers::c_AntiProton;
141  if (pdg == Const::pion.getPDGCode())
142  return MuidElementNumbers::c_PionPlus;
143  if (pdg == -Const::pion.getPDGCode())
144  return MuidElementNumbers::c_PionMinus;
145  if (pdg == Const::kaon.getPDGCode())
146  return MuidElementNumbers::c_KaonPlus;
147  if (pdg == -Const::kaon.getPDGCode())
148  return MuidElementNumbers::c_KaonMinus;
149  /* Only charged final state particles are supported. */
150  return MuidElementNumbers::c_NotValid;
151 }
152 
153 std::vector<int> MuidElementNumbers::getPDGVector(int charge)
154 {
155  std::vector<int> pdgVector;
156  for (const Const::ChargedStable particle : Const::chargedStableSet) {
157  if ((particle == Const::electron) || (particle == Const::muon))
158  pdgVector.push_back(-charge * particle.getPDGCode());
159  else
160  pdgVector.push_back(charge * particle.getPDGCode());
161  }
162  return pdgVector;
163 }
164 
166 {
167  std::vector<int> pdgVector = getPDGVector(1);
168  std::vector<int> temp = getPDGVector(-1);
169  pdgVector.insert(pdgVector.end(), temp.begin(), temp.end());
170  std::sort(pdgVector.begin(), pdgVector.end());
171  return pdgVector;
172 }
173 
174 int MuidElementNumbers::getLongitudinalID(int hypothesis, int outcome, int lastLayer)
175 {
176  int id = lastLayer;
177  id += (outcome << MuidElementNumbers::c_LastLayerBit);
179  return id;
180 }
181 
182 int MuidElementNumbers::getTransverseID(int hypothesis, int detector, int degreesOfFreedom)
183 {
184  int id = degreesOfFreedom;
185  id += (detector << MuidElementNumbers::c_DegreesOfFreedomBit);
187  return id;
188 }
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
static const ChargedStable muon
muon particle
Definition: Const.h:651
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:609
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
static const ChargedStable proton
proton particle
Definition: Const.h:654
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:653
static const ChargedStable electron
electron particle
Definition: Const.h:650
static const ChargedStable deuteron
deuteron particle
Definition: Const.h:655
static int getLongitudinalID(int hypothesis, int outcome, int lastLayer)
Get the unique longitudinal identifier for given hypothesis, outcome and last layer crossed.
static constexpr int getMaximalEndcapForwardLayer()
Get maximal endcap-forward layer number (0-based).
static int getTransverseID(int hypothesis, int detector, int degreesOfFreedom)
Get the unique transverse identifier for given hypothesis, detector and degrees of freedom.
static unsigned int calculateExtrapolationOutcome(bool isForward, bool escaped, int lastBarrelLayer, int lastEndcapLayer)
Calculate the track extrapolation outcome.
static constexpr int getMaximalEndcapBackwardLayer()
Get maximal endcap-forward layer number (0-based).
static constexpr int getMaximalBarrelLayer()
Get maximal barrel layer number (0-based).
@ c_OutcomeBit
Number of bits occupied by outcome in getLongitudinalID().
@ c_DetectorBit
Number of bits occupied by detector in getTransverseID().
@ c_DegreesOfFreedomBit
Number of bits occupied by degreesOfFreedom in getTransverseID().
@ c_LastLayerBit
Number of bits occupied by lastLayer in getLongitudinalID().
static std::vector< int > getPDGVector()
Get a vector with all the hypothesis PDG codes used for Muid.
static bool checkExtrapolationOutcome(unsigned int outcome, int lastLayer)
Check the track extrapolation outcome.
static Hypothesis calculateHypothesisFromPDG(int pdg)
Calculate hypothesis number from PDG code.
Abstract base class for different kinds of events.