Belle II Software development
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
12using namespace std;
13using namespace Belle2;
14
16{
18 return total.getElectrons();
19}
20
21std::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
32std::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
66std::vector<std::pair<float, float>> VXDSimHit::getElectronsConstantNumber(double electronsPerStep) const
67{
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
std::vector< unsigned int > m_electronProfile
Energy depsoition profile encoded using the ElectronDeposit class.
Definition: VXDSimHit.h:125
ROOT::Math::XYZVector getPosOut() const
Return the end point of the electron deposition in local coordinates.
Definition: VXDSimHit.h:72
std::vector< std::pair< float, float > > getElectronsConstantDistance(double length) const
Get the electron deposition along constant stepsize.
Definition: VXDSimhit.cc:32
float getElectrons() const
Return the number of created electrons.
Definition: VXDSimhit.cc:15
std::vector< std::pair< float, float > > getElectronProfile() const
Get the decoded electron profile.
Definition: VXDSimhit.cc:21
ROOT::Math::XYZVector getPosIn() const
Return the start point of the electron deposition in local coordinates.
Definition: VXDSimHit.h:70
std::vector< std::pair< float, float > > getElectronsConstantNumber(double electronsPerStep) const
Get the electron deposition with constant number of electrons between sampling points.
Definition: VXDSimhit.cc:66
Abstract base class for different kinds of events.
STL namespace.