Belle II Software  release-05-01-25
EclConfigurationPure.cc
1 #include <ecl/digitization/EclConfigurationPure.h>
2 #include <ecl/digitization/ECLSampledShaper.h>
3 #include <algorithm>
4 #include <iostream>
5 #include <cassert>
6 
7 using namespace Belle2;
8 using namespace Belle2::ECL;
9 using namespace std;
10 
11 double EclConfigurationPure::m_tickPure = EclConfiguration::m_tick / EclConfiguration::m_ntrg * 8;
12 
13 void EclConfigurationPure::signalsamplepure_t::InitSample(const TH1F* sampledfun, const TH1F* sampledfunDerivative)
14 {
15  const int N = m_ns * m_nlPure;
16  double r1 = 32 / m_ns;
17  double r2 = EclConfiguration::m_tick / EclConfiguration::m_ntrg * 8 / EclConfigurationPure::m_tickPure ;
18 
19  ECLSampledShaper dsp(sampledfun, round(r1 / r2));
20  dsp.fillarray(N, m_ft);
21  double maxval = * max_element(m_ft, m_ft + N);
22 
23  for_each(m_ft1, m_ft1 + N, [maxval](double & a) { a /= maxval; });
24  double maxval2 = * max_element(m_ft, m_ft + N);
25  assert(maxval2 - 1.0 < 0.001);
26  double sum = 0;
27  for (int i = 0; i < N; i++) sum += m_ft[i];
28  m_sumscale = m_ns / sum;
29  // for (int i = 0; i < N; ++i) m_ft1[i] = sampledfunDerivative->GetBinContent(i + 1);
30  ECLSampledShaper dsp1(sampledfunDerivative, round(r1 / r2));
31  dsp1.fillarray(N, m_ft1);
32  for_each(m_ft1, m_ft1 + N, [r1, r2, maxval](double & a) { a *= (r1 / r2) / maxval; });
33 }
34 
35 void EclConfigurationPure::adccountspure_t::AddHit(const double a, const double t0,
37 {
38  total += s.Accumulate(a, t0, c);
39 }
40 
41 double EclConfigurationPure::signalsamplepure_t::Accumulate(const double a, const double t0, double* s) const
42 {
43  // input parameters
44  // a -- signal amplitude
45  // t -- signal offset
46  // output parameter
47  // s -- output array with added signal
48  const double itick = 1 / m_tickPure; // reciprocal to avoid division in usec^-1 (has to be evaluated at compile time)
49  const double tlen = m_nlPure - 1.0 / m_ns; // length of the sampled signal in ADC clocks units
50  const double tmax = m_tmin + m_nsmp - 1; // upper range of the fit region
51 
52  double t = t0 * itick; // rescale time in usec to ADC clocks
53  double x0 = t, x1 = t + tlen;
54 
55  if (x0 > tmax) return 0; // signal starts after the upper range of output array -- do nothing
56  if (x0 < m_tmin) {
57  if (x1 < m_tmin) return 0; // signal ends before lower range of output array -- do nothing
58  x0 = m_tmin; // adjust signal with range of output array
59  }
60 
61  int imax = m_nsmp; // length of sampled signal is long enough so
62  // the last touched element is the last element
63  // of the output array
64  if (x1 < tmax) { // if initial time is too early we need to adjust
65  // the last touched element of output array to avoid
66  // out-of-bound situation in m_ft
67  imax = x1 - m_tmin; // imax is always positive so floor can be
68  // replace by simple typecast
69  imax += 1; // like s.end()
70  }
71 
72  double epsilon = 1.0 / m_ns / 10.;
73  double imind = ceil(x0 - m_tmin + epsilon); // store result in double to avoid int->double conversion below
74  // the ceil function today at modern CPUs is surprisingly fast (before it was horribly slow)
75  int imin = imind; // starting point to fill output array
76  double w = ((m_tmin - t) + imind - 1) * double(m_ns);
77  int jmin = w ; // starting point in sampled signal array
78  w -= jmin;
79 
80  // use linear interpolation between samples. Since signal samples
81  // are aligned with output samples only two weights are need to
82  // calculate to fill output array
83  const double w1 = a * w, w0 = a - w1;
84  double sum = 0;
85  //cout <<"Filling energy: " << a << " time " << t << endl;
86  //cout <<"imin: " << imin << " imax: " << imax << endl;
87  for (int i = imin, j = jmin; i < imax; i++, j += m_ns) {
88  double amp = 0;
89  if (j >= 0) amp = w0 * m_ft[j] + w1 * m_ft[j + 1];
90  //double amp = a * m_ft[j];
91  // cout << i << ":" << j << " " << m_ft[j] << " " << w * m_ft[j] + (1-w) * m_ft[j+1] << endl;
92  s[i] += amp;
93  sum += amp;
94  }
95  //cout << endl;
96  return sum * m_sumscale;
97 }
Belle2::ECL::EclConfiguration::m_ntrg
static constexpr int m_ntrg
number of trigger counts per ADC clock tick
Definition: EclConfiguration.h:49
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ECL::EclConfiguration::m_tick
static constexpr double m_tick
== 72/127 digitization clock tick (in microseconds ???)
Definition: EclConfiguration.h:46
Belle2::ECL::ECLSampledShaper
digitisation shaper
Definition: ECLSampledShaper.h:34
Belle2::ECL::EclConfigurationPure::signalsamplepure_t
a struct for a signal sample for the pure CsI calorimeter
Definition: EclConfigurationPure.h:40