Belle II Software  release-06-00-14
EclConfiguration.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 #include <ecl/digitization/EclConfiguration.h>
9 #include <ecl/digitization/shaperdsp.h>
10 #include <vector>
11 #include <cmath>
12 
13 using namespace Belle2;
14 using namespace Belle2::ECL;
15 using namespace std;
16 
17 // define the constexpr here to make clang happy. Could be a bug or some strict
18 // adherence to the standard. I guess it's just a different interpretation of
19 // how to use these values by clang.
20 // http://stackoverflow.com/questions/28264279/undefined-reference-when-accessing-static-constexpr-float-member
21 constexpr double EclConfiguration::s_clock;
22 constexpr double EclConfiguration::m_rf;
23 constexpr double EclConfiguration::m_step;
24 
25 void EclConfiguration::signalsample_t::InitSample(const double* MPd, double u)
26 {
27  const int N = m_ns * m_nl;
28  vector<double> MP(MPd, MPd + 10);
29  ShaperDSP_t dsp(MP, u);
30  dsp.settimestride(m_step / m_ns);
31  dsp.fillarray(0.0, N, m_ft);
32 
33  double sum = 0;
34  for (int i = 0; i < N; i++) sum += m_ft[i];
35  m_sumscale = m_ns / sum;
36 }
37 
38 
39 void EclConfiguration::signalsample_t::InitSample(const float* MP, double u)
40 {
41  double MPd[10];
42  for (int i = 0; i < 10; i++) MPd[i] = MP[i];
43  InitSample(MPd, u);
44 }
45 
46 void EclConfiguration::adccounts_t::AddHit(const double a, const double t0, const EclConfiguration::signalsample_t& s)
47 {
48  total += s.Accumulate(a, t0, c);
49 }
50 
51 double EclConfiguration::signalsample_t::Accumulate(const double a, const double t0, double* s) const
52 {
53  // input parameters
54  // a -- signal amplitude
55  // t -- signal offset
56  // output parameter
57  // s -- output array with added signal
58  const double itick = m_rf / s_clock; // reciprocal to avoid division in usec^-1 (has to be evaluated at compile time)
59  const double tlen = m_nl - 1.0 / m_ns; // length of the sampled signal in ADC clocks units
60  const double tmax = m_tmin + m_nsmp - 1; // upper range of the fit region
61 
62  double t = t0 * itick; // rescale time in usec to ADC clocks
63  double x0 = t, x1 = t + tlen;
64 
65  if (x0 > tmax) return 0; // signal starts after the upper range of output array -- do nothing
66  if (x0 < m_tmin) {
67  if (x1 < m_tmin) return 0; // signal ends before lower range of output array -- do nothing
68  x0 = m_tmin; // adjust signal with range of output array
69  }
70 
71  int imax = m_nsmp; // length of sampled signal is long enough so
72  // the last touched element is the last element
73  // of the output array
74  if (x1 < tmax) { // if initial time is too early we need to adjust
75  // the last touched element of output array to avoid
76  // out-of-bound situation in m_ft
77  imax = x1 - m_tmin; // imax is always positive so floor can be
78  // replace by simple typecast
79  imax += 1; // like s.end()
80  }
81 
82  double imind = ceil(x0 - m_tmin); // store result in double to avoid int->double conversion below
83  // the ceil function today at modern CPUs is surprisingly fast (before it was horribly slow)
84  int imin = imind; // starting point to fill output array
85  double w = ((m_tmin - t) + imind) * double(m_ns);
86  int jmin = w; // starting point in sampled signal array
87  w -= jmin;
88 
89  // use linear interpolation between samples. Since signal samples
90  // are aligned with output samples only two weights are need to
91  // calculate to fill output array
92  const double w1 = a * w, w0 = a - w1;
93  double sum = 0;
94  for (int i = imin, j = jmin; i < imax; i++, j += m_ns) {
95  double amp = w0 * m_ft[j] + w1 * m_ft[j + 1];
96  s[i] += amp;
97  sum += amp;
98  }
99  return sum * m_sumscale;
100 }
static constexpr double m_step
time between points in internal units t_{asrto}*m_rf/2.
static constexpr double s_clock
digitization clock in RF units
static constexpr double m_rf
accelerating RF, http://ptep.oxfordjournals.org/content/2013/3/03A006.full.pdf
Class include function that calculate electronic response from energy deposit
Definition: shaperdsp.h:26
Abstract base class for different kinds of events.
void AddHit(const double a, const double t0, const signalsample_t &q)
add hit method