Belle II Software  release-08-01-10
VXDSimhit.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 #include <vxd/dataobjects/VXDElectronDeposit.h>
10 #include <vxd/dataobjects/VXDSimHit.h>
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 float VXDSimHit::getElectrons() const
16 {
17  VXDElectronDeposit total(m_electronProfile.back());
18  return total.getElectrons();
19 }
20 
21 std::vector<std::pair<float, float>> VXDSimHit::getElectronProfile() const
22 {
23  std::vector<std::pair<float, float>> result;
24  result.reserve(m_electronProfile.size());
25  for (unsigned int encoded : m_electronProfile) {
26  VXDElectronDeposit ed(encoded);
27  result.emplace_back(ed.getFraction(), ed.getElectrons());
28  }
29  return result;
30 }
31 
32 std::vector<std::pair<float, float>> VXDSimHit::getElectronsConstantDistance(double length) const
33 {
34  double totalLength = (getPosOut() - getPosIn()).R();
35  const int nSteps = (int)(totalLength / length) + 1;
36  std::vector<std::pair<float, float>> result;
37  result.reserve(nSteps);
38  //Account for the discrete number of steps and adjust the fraction per step
39  //we want to return
40  const double deltaFraction = 1. / nSteps;
41 
42  std::vector<unsigned int>::const_iterator currentPointIt = m_electronProfile.begin();
43  VXDElectronDeposit currentPoint(*currentPointIt);
44  VXDElectronDeposit lastPoint(0, 0);
45 
46  //Now we create all steps
47  for (int i = 0; i < nSteps; ++i) {
48  //By determining which fraction it should have, clipped to 1 for rounding errors
49  const double fraction = min((i + 1) * deltaFraction, 1.0);
50  //finding the correct segment
51  while (fraction > currentPoint.getFraction()) {
52  ++currentPointIt;
53  lastPoint = currentPoint;
54  currentPoint = VXDElectronDeposit(*currentPointIt);
55  }
56  //and calculating the weighted average of the current number of electrons
57  const double weight = (fraction - lastPoint.getFraction()) /
58  (currentPoint.getFraction() - lastPoint.getFraction());
59  const double electrons = (1 - weight) * lastPoint.getElectrons() + weight * currentPoint.getElectrons();
60  //which we then add to the result
61  result.emplace_back(fraction, electrons);
62  }
63  return result;
64 }
65 
66 std::vector<std::pair<float, float>> VXDSimHit::getElectronsConstantNumber(double electronsPerStep) const
67 {
68  VXDElectronDeposit total(m_electronProfile.back());
69  const int nSteps = (int)(total.getElectrons() / electronsPerStep) + 1;
70  std::vector<std::pair<float, float>> result;
71  result.reserve(nSteps);
72  //Account for the discrete number of steps and adjust number of electrons
73  double deltaElectrons = total.getElectrons() / nSteps;
74 
75  std::vector<unsigned int>::const_iterator currentPointIt = m_electronProfile.begin();
76  VXDElectronDeposit currentPoint(*currentPointIt);
77  VXDElectronDeposit lastPoint(0, 0);
78 
79  //Now we create all steps
80  for (int i = 0; i < nSteps; ++i) {
81  //By determining the number of electrons it should have, clipped to total for rounding errors
82  const double electrons = min((i + 1) * deltaElectrons, (double)total.getElectrons());
83  //finding the correct segment
84  while (electrons > currentPoint.getElectrons()) {
85  ++currentPointIt;
86  lastPoint = currentPoint;
87  currentPoint = VXDElectronDeposit(*currentPointIt);
88  }
89  //and calculating the weighted average of the current position
90  const double weight = (electrons - lastPoint.getElectrons()) /
91  (currentPoint.getElectrons() - lastPoint.getElectrons());
92  const double fraction = (1 - weight) * lastPoint.getFraction() + weight * currentPoint.getFraction();
93  //which we then add to the result
94  result.emplace_back(fraction, electrons);
95  }
96  return result;
97 }
double R
typedef autogenerated by FFTW
Packed class to represent energy deposit along a path in electrons.
unsigned int getElectrons() const
get the number of deposited electrons
float getFraction() const
get the fraction along the path
Abstract base class for different kinds of events.