Belle II Software  release-06-01-15
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 /* Belle 2 headers. */
13 #include <framework/gearbox/GearDir.h>
14 #include <framework/logging/Logger.h>
15 
16 /* C++ headers. */
17 #include <cmath>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 BKLMSimulationPar::BKLMSimulationPar(const GearDir& content)
23 {
24  read(content);
25 }
26 
27 BKLMSimulationPar::~BKLMSimulationPar()
28 {
29 }
30 
31 void BKLMSimulationPar::read(const GearDir& content)
32 {
33  if (!content) {
34  B2FATAL("The GearDir to look for BKLM simulation parameters is not valid.");
35  return;
36  }
37  char name[40];
38  double weight[c_MAX_NHIT];
39 
40  for (int div = 0; div <= c_NDIV; ++div) {
41  for (int j = 0; j < c_MAX_NHIT; ++j) {
42  m_PhiMultiplicityCDF[div][j] = 1.0;
43  m_ZMultiplicityCDF[div][j] = 1.0;
44  }
45  }
46 
47  m_HitTimeMax = content.getWithUnit("/HitTimeMax");
48 
49  GearDir phiContent(content);
50  phiContent.append("/RPCStripMultiplicity/Phi");
51  m_NPhiDiv = phiContent.getNumberNodes("/Division");
52  int nDiv = min(phiContent.getNumberNodes("/Division"), c_NDIV + 1);
53  for (int div = 0; div < nDiv; ++div) {
54  sprintf(name, "/Division[@id=\"%d\"]", div);
55  GearDir divContent(phiContent);
56  divContent.append(name);
57  m_NPhiMultiplicity[div] = divContent.getNumberNodes("/Weight");
58  int nWeight = min(divContent.getNumberNodes("/Weight"), c_MAX_NHIT - 1);
59  weight[0] = 0.0;
60  for (int j = 1; j <= nWeight; ++j) {
61  sprintf(name, "/Weight[@multiplicity=\"%d\"]", j);
62  m_PhiWeight[div][j] = divContent.getDouble(name);
63  weight[j] = divContent.getDouble(name) + weight[j - 1];
64  weight[0] = weight[j];
65  }
66  for (int j = 1; j < c_MAX_NHIT; ++j) {
67  m_PhiMultiplicityCDF[div][j] = (j <= nWeight ? weight[j] / weight[0] : 1.0);
68  }
69  }
70 
71  GearDir zContent(content);
72  zContent.append("/RPCStripMultiplicity/Z");
73  nDiv = min(zContent.getNumberNodes("/Division"), c_NDIV + 1);
74  m_NZDiv = zContent.getNumberNodes("/Division");
75  for (int div = 0; div < nDiv; ++div) {
76  sprintf(name, "/Division[@id=\"%d\"]", div);
77  GearDir divContent(zContent);
78  divContent.append(name);
79  int nWeight = min(divContent.getNumberNodes("/Weight"), c_MAX_NHIT - 1);
80  m_NZMultiplicity[div] = divContent.getNumberNodes("/Weight");
81  weight[0] = 0.0;
82  for (int j = 1; j <= nWeight; ++j) {
83  sprintf(name, "/Weight[@multiplicity=\"%d\"]", j);
84  m_ZWeight[div][j] = divContent.getDouble(name);
85  weight[j] = divContent.getDouble(name) + weight[j - 1];
86  weight[0] = weight[j];
87  }
88  for (int j = 1; j < c_MAX_NHIT; ++j) {
89  m_ZMultiplicityCDF[div][j] = (j <= nWeight ? weight[j] / weight[0] : 1.0);
90  }
91  }
92 }
93 
94 double BKLMSimulationPar::getPhiMultiplicityCDF(double stripDiv, int mult) const
95 {
96  if (mult < 0)
97  return 0.0;
98  if (mult >= c_MAX_NHIT)
99  return 1.0;
100  int stripIndex = (int) fabs(stripDiv * c_NDIV / 0.5);
101  if (stripIndex > c_NDIV)
102  return 0.0;
103  return m_PhiMultiplicityCDF[stripIndex][mult];
104 }
105 
106 double BKLMSimulationPar::getZMultiplicityCDF(double stripDiv, int mult) const
107 {
108  if (mult < 0)
109  return 0.0;
110  if (mult >= c_MAX_NHIT)
111  return 1.0;
112  int stripIndex = (int) fabs(stripDiv * c_NDIV / 0.5);
113  if (stripIndex > c_NDIV)
114  return 0.0;
115  return m_ZMultiplicityCDF[stripIndex][mult];
116 }
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.