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