Belle II Software  release-06-01-15
SVDClusterCharge.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 <framework/logging/Logger.h>
10 #include <svd/reconstruction/SVDClusterCharge.h>
11 #include <svd/reconstruction/SVDMaxSumAlgorithm.h>
12 #include <svd/dataobjects/SVDEventInfo.h>
13 #include <TMath.h>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  namespace SVD {
24 
25  void SVDClusterCharge::applyMaxSampleCharge(const Belle2::SVD::RawCluster& rawCluster, double& charge, double& SNR,
26  double& seedCharge)
27  {
28 
29  //get seed charge
30  int seedCellID = rawCluster.getStripsInRawCluster().at(rawCluster.getSeedInternalIndex()).cellID;
31 
32  seedCharge = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), seedCellID,
33  rawCluster.getSeedMaxSample());
34 
35  std::vector<Belle2::SVD::StripInRawCluster> strips = rawCluster.getStripsInRawCluster();
36 
37  //initialize noise and charge
38  double noise = 0;
39  charge = 0;
40 
41 
42  for (int i = 0; i < (int)strips.size(); i++) {
43 
44  Belle2::SVD::StripInRawCluster strip = strips.at(i);
45 
46  double rawCharge = *std::max_element(begin(strip.samples), end(strip.samples));
47 
48  // calibrate (ADC -> electrons)
49  double stripCharge = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), strip.cellID, rawCharge);
50 
51  double tmp_noise = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), strip.cellID, strip.noise);
52  noise += tmp_noise * tmp_noise;
53 
54  charge += stripCharge;
55  }
56 
57  SNR = charge / sqrt(noise);
58  }
59 
60  void SVDClusterCharge::applySumSamplesCharge(const Belle2::SVD::RawCluster& rawCluster, double& charge, double& SNR,
61  double& seedCharge)
62  {
63 
64  std::vector<Belle2::SVD::StripInRawCluster> strips = rawCluster.getStripsInRawCluster();
65 
66  //initialize noise and charge
67  double noise = 0;
68  charge = 0;
69  seedCharge = 0;
70 
71  for (int i = 0; i < (int)strips.size(); i++) {
72 
73  Belle2::SVD::StripInRawCluster strip = strips.at(i);
74 
75  double rawCharge = 0;
76  for (auto sample : strip.samples)
77  rawCharge += sample;
78 
79  // calibrate (ADC -> electrons)
80  double stripCharge = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), strip.cellID, rawCharge);
81 
82  if (stripCharge > seedCharge)
83  seedCharge = stripCharge;
84 
85  double tmp_noise = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), strip.cellID, strip.noise);
86  noise += tmp_noise * tmp_noise;
87 
88  charge += stripCharge;
89  }
90 
91  SNR = charge / sqrt(noise);
92 
93  }
94 
95 
96  void SVDClusterCharge::applyELS3Charge(const Belle2::SVD::RawCluster& rawCluster, double& charge, double& SNR, double& seedCharge)
97  {
98 
99  // ISSUES:
100  // 1. samples always in electrons for charge
101  // 2. hardcoded ELS3 tau
102  // 3. seed charge is maxSample
103 
104  float m_ELS3tau = 55;
105 
106  //get seed charge
107  int seedCellID = rawCluster.getStripsInRawCluster().at(rawCluster.getSeedInternalIndex()).cellID;
108 
109  seedCharge = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), seedCellID,
110  rawCluster.getSeedMaxSample());
111 
112  //initialize noise and charge
113  double noise = 0;
114  charge = 0;
115 
116  //take the MaxSum 3 samples
117  SVDMaxSumAlgorithm maxSum = SVDMaxSumAlgorithm(rawCluster.getClsSamples(false));
118  std::vector<float> selectedSamples = maxSum.getSelectedSamples();
119 
120  auto begin = selectedSamples.begin();
121 
122  const double E = std::exp(- m_apvClockPeriod / m_ELS3tau);
123  const double E2 = E * E;
124  const double E3 = E * E * E;
125  const double E4 = E * E * E * E;
126  double a0 = (*begin);
127  double a1 = (*(begin + 1));
128  double a2 = (*(begin + 2));
129 
130  //compute raw time
131  const double w = (a0 - E2 * a2) / (2 * a0 + E * a1);
132  auto rawtime_num = 2 * E4 + w * E2;
133  auto rawtime_den = 1 - E4 - w * (2 + E2);
134  float rawtime = - m_apvClockPeriod * rawtime_num / rawtime_den;
135 
136  a0 = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), rawCluster.getStripsInRawCluster()[0].cellID,
137  a0);
138  a1 = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), rawCluster.getStripsInRawCluster()[0].cellID,
139  a1);
140  a2 = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), rawCluster.getStripsInRawCluster()[0].cellID,
141  a2);
142 
143 
144  double num = (1. / E - E3) * a1 + (2 + E2) * a2 - (1 + 2 * E2) * a0;
145  double den = m_apvClockPeriod / m_ELS3tau * std::exp(1 + rawtime / m_ELS3tau) * (1 + 4 * E2 + E4);
146 
147  charge = num / den;
148 
149  //compute Noise
150  std::vector<Belle2::SVD::StripInRawCluster> strips = rawCluster.getStripsInRawCluster();
151 
152  for (int i = 0; i < (int)strips.size(); i++) {
153 
154  Belle2::SVD::StripInRawCluster strip = strips.at(i);
155 
156  double tmp_noise = m_PulseShapeCal.getChargeFromADC(rawCluster.getSensorID(), rawCluster.isUSide(), strip.cellID, strip.noise);
157  noise += tmp_noise * tmp_noise;
158  }
159 
160  SNR = charge / sqrt(noise);
161 
162  }
163 
164 
165  } //SVD namespace
167 } //Belle2 namespace
Class representing a raw cluster candidate during clustering of the SVD.
Definition: RawCluster.h:33
int getSeedInternalIndex() const
Definition: RawCluster.h:120
int getSeedMaxSample() const
Definition: RawCluster.h:115
Belle2::SVDShaperDigit::APVFloatSamples getClsSamples(bool inElectrons) const
Definition: RawCluster.cc:104
bool isUSide() const
Definition: RawCluster.h:85
VxdID getSensorID() const
Definition: RawCluster.h:80
const std::vector< StripInRawCluster > getStripsInRawCluster() const
Definition: RawCluster.h:110
Class implementing the MaxSum algorithm.
std::vector< float > getSelectedSamples()
Abstract base class for different kinds of events.
structure containing the relevant informations of each strip of the raw cluster
Definition: RawCluster.h:20
Belle2::SVDShaperDigit::APVFloatSamples samples
ADC of the acquired samples.
Definition: RawCluster.h:25