Belle II Software  release-05-01-25
BKLMSimulationPar.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Yinghui GUAN *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* Own header. */
12 #include <klm/dbobjects/bklm/BKLMSimulationPar.h>
13 
14 /* Belle 2 headers. */
15 #include <framework/gearbox/GearDir.h>
16 #include <framework/logging/Logger.h>
17 
18 /* C++ headers. */
19 #include <cmath>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 BKLMSimulationPar::BKLMSimulationPar(const GearDir& content)
25 {
26  read(content);
27 }
28 
29 BKLMSimulationPar::~BKLMSimulationPar()
30 {
31 }
32 
33 void BKLMSimulationPar::read(const GearDir& content)
34 {
35  if (!content) {
36  B2FATAL("The GearDir to look for BKLM simulation parameters is not valid.");
37  return;
38  }
39  char name[40];
40  double weight[c_MAX_NHIT];
41 
42  for (int div = 0; div <= c_NDIV; ++div) {
43  for (int j = 0; j < c_MAX_NHIT; ++j) {
44  m_PhiMultiplicityCDF[div][j] = 1.0;
45  m_ZMultiplicityCDF[div][j] = 1.0;
46  }
47  }
48 
49  m_HitTimeMax = content.getWithUnit("/HitTimeMax");
50 
51  GearDir phiContent(content);
52  phiContent.append("/RPCStripMultiplicity/Phi");
53  m_NPhiDiv = phiContent.getNumberNodes("/Division");
54  int nDiv = min(phiContent.getNumberNodes("/Division"), c_NDIV + 1);
55  for (int div = 0; div < nDiv; ++div) {
56  sprintf(name, "/Division[@id=\"%d\"]", div);
57  GearDir divContent(phiContent);
58  divContent.append(name);
59  m_NPhiMultiplicity[div] = divContent.getNumberNodes("/Weight");
60  int nWeight = min(divContent.getNumberNodes("/Weight"), c_MAX_NHIT - 1);
61  weight[0] = 0.0;
62  for (int j = 1; j <= nWeight; ++j) {
63  sprintf(name, "/Weight[@multiplicity=\"%d\"]", j);
64  m_PhiWeight[div][j] = divContent.getDouble(name);
65  weight[j] = divContent.getDouble(name) + weight[j - 1];
66  weight[0] = weight[j];
67  }
68  for (int j = 1; j < c_MAX_NHIT; ++j) {
69  m_PhiMultiplicityCDF[div][j] = (j <= nWeight ? weight[j] / weight[0] : 1.0);
70  }
71  }
72 
73  GearDir zContent(content);
74  zContent.append("/RPCStripMultiplicity/Z");
75  nDiv = min(zContent.getNumberNodes("/Division"), c_NDIV + 1);
76  m_NZDiv = zContent.getNumberNodes("/Division");
77  for (int div = 0; div < nDiv; ++div) {
78  sprintf(name, "/Division[@id=\"%d\"]", div);
79  GearDir divContent(zContent);
80  divContent.append(name);
81  int nWeight = min(divContent.getNumberNodes("/Weight"), c_MAX_NHIT - 1);
82  m_NZMultiplicity[div] = divContent.getNumberNodes("/Weight");
83  weight[0] = 0.0;
84  for (int j = 1; j <= nWeight; ++j) {
85  sprintf(name, "/Weight[@multiplicity=\"%d\"]", j);
86  m_ZWeight[div][j] = divContent.getDouble(name);
87  weight[j] = divContent.getDouble(name) + weight[j - 1];
88  weight[0] = weight[j];
89  }
90  for (int j = 1; j < c_MAX_NHIT; ++j) {
91  m_ZMultiplicityCDF[div][j] = (j <= nWeight ? weight[j] / weight[0] : 1.0);
92  }
93  }
94 }
95 
96 double BKLMSimulationPar::getPhiMultiplicityCDF(double stripDiv, int mult) const
97 {
98  if (mult < 0)
99  return 0.0;
100  if (mult >= c_MAX_NHIT)
101  return 1.0;
102  int stripIndex = (int) fabs(stripDiv * c_NDIV / 0.5);
103  if (stripIndex > c_NDIV)
104  return 0.0;
105  return m_PhiMultiplicityCDF[stripIndex][mult];
106 }
107 
108 double BKLMSimulationPar::getZMultiplicityCDF(double stripDiv, int mult) const
109 {
110  if (mult < 0)
111  return 0.0;
112  if (mult >= c_MAX_NHIT)
113  return 1.0;
114  int stripIndex = (int) fabs(stripDiv * c_NDIV / 0.5);
115  if (stripIndex > c_NDIV)
116  return 0.0;
117  return m_ZMultiplicityCDF[stripIndex][mult];
118 }
Belle2::gearbox::Interface::getDouble
double getDouble(const std::string &path="") const noexcept(false)
Get the parameter path as a double.
Definition: Interface.cc:51
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::GearDir::append
void append(const std::string &path)
Append something to the current path, modifying the GearDir in place.
Definition: GearDir.h:62
Belle2::GearDir::getNumberNodes
virtual int getNumberNodes(const std::string &path="") const override
Return the number of nodes a given path will expand to.
Definition: GearDir.h:68