Belle II Software  release-05-01-25
TOPSignalShape.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <top/dbobjects/TOPSignalShape.h>
12 #include <framework/logging/Logger.h>
13 #include <math.h>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  TOPSignalShape::TOPSignalShape(std::vector<double> shape, double timeBin, double tau,
24  double pole1, double pole2):
25  m_shape(shape), m_tau(tau), m_pole1(pole1), m_pole2(pole2)
26  {
27  m_tmax = m_tmin + (shape.size() - 1) * timeBin;
28 
29  // find peaking value (positive pulse maximum!)
30 
31  int samplePeak = 0;
32  for (unsigned i = 0; i < shape.size(); i++) {
33  if (shape[i] > shape[samplePeak]) samplePeak = i;
34  }
35 
36  TSpline5 spline("spline", m_tmin, m_tmax, shape.data(), shape.size());
37  double t1 = m_tmin + (samplePeak - 1) * timeBin;
38  double t2 = m_tmin + (samplePeak + 1) * timeBin;
39  for (int i = 0; i < 20; i++) {
40  double t = (t1 + t2) / 2;
41  if (spline.Derivative(t) > 0) {
42  t1 = t;
43  } else {
44  t2 = t;
45  }
46  }
47  double vPeak = spline.Eval((t1 + t2) / 2);
48 
49  // normalize waveform
50 
51  for (auto& value : m_shape) value /= vPeak;
52 
53  // find 50% CF crossing time (positive pulse!)
54 
55  auto sampleRise = samplePeak;
56  while (sampleRise >= 0 and m_shape[sampleRise] > 0.5) sampleRise--;
57  t1 = m_tmin + sampleRise * timeBin;
58  t2 = m_tmin + (sampleRise + 1) * timeBin;
59  for (int i = 0; i < 20; i++) {
60  double t = (t1 + t2) / 2;
61  if (spline.Eval(t) < vPeak / 2) {
62  t1 = t;
63  } else {
64  t2 = t;
65  }
66  }
67  double crossingTime = (t1 + t2) / 2;
68 
69  // set 50% CF crossing to happen at t = 0
70 
71  m_tmin -= crossingTime;
72  m_tmax -= crossingTime;
73 
74  }
75 
76 
77  double TOPSignalShape::getValue(double t) const
78  {
79  if (m_shape.empty()) {
80  B2ERROR("TOPSignalShape::getValue: object not initialized");
81  return 0;
82  }
83  if (t < m_tmin) return 0;
84  if (t > m_tmax) return m_shape.back() * exp(-(t - m_tmax) / m_tau);
85  if (!m_interpolator) {
86  std::vector<double> shape(m_shape); // since argument in TSpline5 is not const!
87  m_interpolator = new TSpline5("signalShape", m_tmin, m_tmax,
88  shape.data(), shape.size());
89  }
90  return m_interpolator->Eval(t);
91  }
92 
94 } // end Belle2 namespace
Belle2::TOPSignalShape::m_tmax
double m_tmax
time of the last waveform sample [ns]
Definition: TOPSignalShape.h:143
Belle2::TOPSignalShape::m_interpolator
TSpline5 * m_interpolator
cache for the interpolator
Definition: TOPSignalShape.h:149
Belle2::TOPSignalShape::getValue
double getValue(double t) const
Returns value at time t of the normalized waveform using interpolator.
Definition: TOPSignalShape.cc:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOPSignalShape::m_shape
std::vector< double > m_shape
waveform values
Definition: TOPSignalShape.h:141
Belle2::TOPSignalShape::m_tau
double m_tau
time constant of the exponential tail [ns]
Definition: TOPSignalShape.h:144
Belle2::TOPSignalShape::m_tmin
double m_tmin
time of the first waveform sample [ns]
Definition: TOPSignalShape.h:142