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