Belle II Software  release-08-01-10
BKLMSimulationPar.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/dbobjects/bklm/BKLMSimulationPar.h>
11 
12 /* Basf2 headers. */
13 #include <framework/gearbox/GearDir.h>
14 #include <framework/logging/Logger.h>
15 
16 /* C++ headers. */
17 #include <cmath>
18 
19 using namespace Belle2;
20 
22 {
23  read(content);
24 }
25 
27 {
28 }
29 
30 void BKLMSimulationPar::read(const GearDir& content)
31 {
32  if (!content) {
33  B2FATAL("The GearDir to look for BKLM simulation parameters is not valid.");
34  return;
35  }
36  char name[40];
37  double weight[c_MAX_NHIT];
38 
39  for (int div = 0; div <= c_NDIV; ++div) {
40  for (int j = 0; j < c_MAX_NHIT; ++j) {
41  m_PhiMultiplicityCDF[div][j] = 1.0;
42  m_ZMultiplicityCDF[div][j] = 1.0;
43  }
44  }
45 
46  m_HitTimeMax = content.getWithUnit("/HitTimeMax");
47 
48  GearDir phiContent(content);
49  phiContent.append("/RPCStripMultiplicity/Phi");
50  m_NPhiDiv = phiContent.getNumberNodes("/Division");
51  int nDiv = std::min(phiContent.getNumberNodes("/Division"), c_NDIV + 1);
52  for (int div = 0; div < nDiv; ++div) {
53  sprintf(name, "/Division[@id=\"%d\"]", div);
54  GearDir divContent(phiContent);
55  divContent.append(name);
56  m_NPhiMultiplicity[div] = divContent.getNumberNodes("/Weight");
57  int nWeight = std::min(divContent.getNumberNodes("/Weight"), c_MAX_NHIT - 1);
58  weight[0] = 0.0;
59  for (int j = 1; j <= nWeight; ++j) {
60  sprintf(name, "/Weight[@multiplicity=\"%d\"]", j);
61  m_PhiWeight[div][j] = divContent.getDouble(name);
62  weight[j] = divContent.getDouble(name) + weight[j - 1];
63  weight[0] = weight[j];
64  }
65  for (int j = 1; j < c_MAX_NHIT; ++j) {
66  m_PhiMultiplicityCDF[div][j] = (j <= nWeight ? weight[j] / weight[0] : 1.0);
67  }
68  }
69 
70  GearDir zContent(content);
71  zContent.append("/RPCStripMultiplicity/Z");
72  nDiv = std::min(zContent.getNumberNodes("/Division"), c_NDIV + 1);
73  m_NZDiv = zContent.getNumberNodes("/Division");
74  for (int div = 0; div < nDiv; ++div) {
75  sprintf(name, "/Division[@id=\"%d\"]", div);
76  GearDir divContent(zContent);
77  divContent.append(name);
78  int nWeight = std::min(divContent.getNumberNodes("/Weight"), c_MAX_NHIT - 1);
79  m_NZMultiplicity[div] = divContent.getNumberNodes("/Weight");
80  weight[0] = 0.0;
81  for (int j = 1; j <= nWeight; ++j) {
82  sprintf(name, "/Weight[@multiplicity=\"%d\"]", j);
83  m_ZWeight[div][j] = divContent.getDouble(name);
84  weight[j] = divContent.getDouble(name) + weight[j - 1];
85  weight[0] = weight[j];
86  }
87  for (int j = 1; j < c_MAX_NHIT; ++j) {
88  m_ZMultiplicityCDF[div][j] = (j <= nWeight ? weight[j] / weight[0] : 1.0);
89  }
90  }
91 }
92 
93 double BKLMSimulationPar::getPhiMultiplicityCDF(double stripDiv, int mult) const
94 {
95  if (mult < 0)
96  return 0.0;
97  if (mult >= c_MAX_NHIT)
98  return 1.0;
99  int stripIndex = (int) fabs(stripDiv * c_NDIV / 0.5);
100  if (stripIndex > c_NDIV)
101  return 0.0;
102  return m_PhiMultiplicityCDF[stripIndex][mult];
103 }
104 
105 double BKLMSimulationPar::getZMultiplicityCDF(double stripDiv, int mult) const
106 {
107  if (mult < 0)
108  return 0.0;
109  if (mult >= c_MAX_NHIT)
110  return 1.0;
111  int stripIndex = (int) fabs(stripDiv * c_NDIV / 0.5);
112  if (stripIndex > c_NDIV)
113  return 0.0;
114  return m_ZMultiplicityCDF[stripIndex][mult];
115 }
double m_PhiMultiplicityCDF[c_NDIV+1][c_MAX_NHIT]
RPC phiStrip multiplicity cumulative probability distribution table.
~BKLMSimulationPar()
Default destructor.
static const int c_MAX_NHIT
Maximum number of hits.
static const int c_NDIV
Number of divisions.
double m_ZWeight[c_NDIV+1][c_MAX_NHIT]
RPC zStrip weight table.
double m_ZMultiplicityCDF[c_NDIV+1][c_MAX_NHIT]
RPC zStrip multiplicity cumulative probability distribution table.
int m_NZDiv
Number of division for zstrips.
double getZMultiplicityCDF(double stripDiv, int mult) const
Get the RPC z-strip cumulative prob density function.
double getPhiMultiplicityCDF(double stripDiv, int mult) const
Get the RPC phi-strip cumulative prob density function.
BKLMSimulationPar()
Default constructor.
double m_PhiWeight[c_NDIV+1][c_MAX_NHIT]
RPC phiStrip weight table.
double m_HitTimeMax
Maximum global time for a recorded sim hit.
int m_NPhiDiv
Number of division for phistrips.
int m_NPhiMultiplicity[c_NDIV+1]
Number of kind of mutiplicity of phistrips in each divison.
void read(const GearDir &)
Get simulation parameters from Gearbox.
int m_NZMultiplicity[c_NDIV+1]
Number of weigths of zstrips in each divison.
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
void append(const std::string &path)
Append something to the current path, modifying the GearDir in place.
Definition: GearDir.h:52
virtual int getNumberNodes(const std::string &path="") const override
Return the number of nodes a given path will expand to.
Definition: GearDir.h:58
double getDouble(const std::string &path="") const noexcept(false)
Get the parameter path as a double.
Definition: Interface.cc:41
Abstract base class for different kinds of events.