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