Belle II Software  release-06-02-00
SVDClusterTime.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/SVDClusterTime.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 SVDClusterTime::applyCoG6Time(const Belle2::SVD::RawCluster& rawCluster, double& time, double& timeError, int& firstFrame)
26  {
27 
28  // ISSUES:
29  // 1. time error not computed
30 
31  //the first frame is 0 by definition
32  firstFrame = 0;
33 
34  //take the strips in the rawCluster
35  std::vector<Belle2::SVD::StripInRawCluster> strips = rawCluster.getStripsInRawCluster();
36 
37  //initialize time, stripTime and sumAmplitudes
38  time = 0;
39  timeError = 0;
40  float sumAmplitudes = 0;
41 
42  for (int i = 0; i < (int)strips.size(); i++) {
43 
44  Belle2::SVD::StripInRawCluster strip = strips.at(i);
45 
46  double stripTime = 0;
47  float stripSumAmplitudes = 0;
48 
49  for (int k = 0; k < 6; k ++) {
50  stripTime += k * strip.samples[k];
51  stripSumAmplitudes += strip.samples[k];
52  }
53  if (stripSumAmplitudes != 0) {
54  stripTime /= (stripSumAmplitudes);
55  stripTime *= m_apvClockPeriod;
56  } else {
57  stripTime = -1;
58  B2WARNING("Trying to divide by 0 (ZERO)! Sum of amplitudes is nullptr! Skipping this SVDShaperDigit!");
59  }
60 
61  // correct strip by the CalPeak
62  stripTime -= m_PulseShapeCal.getPeakTime(rawCluster.getSensorID(), rawCluster.isUSide(), strip.cellID);
63 
64  if (isnan(m_triggerBin))
65  B2FATAL("OOPS, we can't continue, you have to set the trigger bin!");
66 
67  if (! m_returnRawClusterTime)
68  // calibrate strip time (cellID not used)
69  stripTime = m_CoG6TimeCal.getCorrectedTime(rawCluster.getSensorID(), rawCluster.isUSide(), strip.cellID, stripTime, m_triggerBin);
70 
71  //update cluster time
72  time += stripTime * strip.maxSample;
73  sumAmplitudes += strip.maxSample;
74  }
75 
76  //finally compute cluster time
77  time = time / sumAmplitudes;
78  }
79 
80  void SVDClusterTime::applyCoG3Time(const Belle2::SVD::RawCluster& rawCluster, double& time, double& timeError, int& firstFrame)
81  {
82 
83  // ISSUES:
84  // 1. time error not computer
85 
86  timeError = 0;
87 
88  //take the MaxSum 3 samples
89  SVDMaxSumAlgorithm maxSum = SVDMaxSumAlgorithm(rawCluster.getClsSamples(false));
90 
91  std::vector<float> selectedSamples = maxSum.getSelectedSamples();
92  firstFrame = maxSum.getFirstFrame();
93 
94 
95  auto begin = selectedSamples.begin();
96  const auto end = selectedSamples.end();
97 
98  auto retval = 0., norm = 0.;
99  for (auto step = 0.; begin != end; ++begin, step += m_apvClockPeriod) {
100  norm += static_cast<double>(*begin);
101  retval += static_cast<double>(*begin) * step;
102  }
103  float rawtime = retval / norm;
104 
105  if (isnan(m_triggerBin))
106  B2FATAL("OOPS, we can't continue, you have to set the trigger bin!");
107 
108  if (m_returnRawClusterTime)
109  time = rawtime;
110  else
111  //cellID not used for calibration
112  time = m_CoG3TimeCal.getCorrectedTime(rawCluster.getSensorID(), rawCluster.isUSide(), 10, rawtime, m_triggerBin);
113 
114  }
115 
116 
117  void SVDClusterTime::applyELS3Time(const Belle2::SVD::RawCluster& rawCluster, double& time, double& timeError, int& firstFrame)
118  {
119 
120  // ISSUES:
121  // 1. ELS3 tau hardcoded
122  // 2. time error not computer
123 
124  timeError = 0;
125  float m_ELS3tau = 55;
126 
127  //take the MaxSum 3 samples
128  SVDMaxSumAlgorithm maxSum = SVDMaxSumAlgorithm(rawCluster.getClsSamples(false));
129 
130  std::vector<float> selectedSamples = maxSum.getSelectedSamples();
131  firstFrame = maxSum.getFirstFrame();
132 
133  auto begin = selectedSamples.begin();
134  const double E = std::exp(- m_apvClockPeriod / m_ELS3tau);
135  const double E2 = E * E;
136  const double E4 = E2 * E2;
137  double a0 = (*begin);
138  double a1 = (*(begin + 1));
139  double a2 = (*(begin + 2));
140 
141  //compute raw time
142  const double w = (a0 - E2 * a2) / (2 * a0 + E * a1);
143  auto rawtime_num = 2 * E4 + w * E2;
144  auto rawtime_den = 1 - E4 - w * (2 + E2);
145  double rawtime = - m_apvClockPeriod * rawtime_num / rawtime_den;
146 
147  if (isnan(m_triggerBin))
148  B2FATAL("OOPS, we can't continue, you have to set the trigger bin!");
149 
150  if (m_returnRawClusterTime)
151  time = rawtime;
152  else
153  time = m_ELS3TimeCal.getCorrectedTime(rawCluster.getSensorID(), rawCluster.isUSide(), 10, rawtime, m_triggerBin);
154 
155  }
156 
157  } //SVD namespace
159 } //Belle2 namespace
Class representing a raw cluster candidate during clustering of the SVD.
Definition: RawCluster.h:33
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
int maxSample
ADC max of the acquired samples.
Definition: RawCluster.h:23