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