Belle II Software  release-05-01-25
ECLWaveformFit.h
1 /********************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Savino Longo (longos@uvic.ca) *
7  * Alexei Sibidanov (sibid@uvic.ca) *
8  * *
9  * This software is provided "as is" without any warranty. *
10  ********************************************************************/
11 
12 #pragma once
13 
14 // FRAMEWORK
15 #include <framework/core/Module.h>
16 #include <framework/datastore/StoreArray.h>
17 
18 // ECL
19 #include <ecl/dataobjects/ECLDigit.h>
20 #include <ecl/dataobjects/ECLDsp.h>
21 
22 class TMinuit;
23 
24 namespace Belle2 {
37  float m_covMatPacked[31 * (31 + 1) / 2] = {};
39  float sigma{ -1};
41  float& operator[](int i) { return m_covMatPacked[i];}
43  const float& operator[](int i) const { return m_covMatPacked[i];}
44  };
45 
51  struct val_der_t {
53  double f0;
55  double f1;
57  double f2;
58  };
59 
67  constexpr static int c_nt = 12;
69  constexpr static int c_ndt = 5;
71  constexpr static int c_ntail = 20;
73  constexpr static double c_dt = 0.5;
75  constexpr static double c_idt = 1 / c_dt;
77  constexpr static double c_dtn = c_dt / c_ndt;
79  constexpr static double c_idtn = c_ndt / c_dt;
83  std::pair<double, double> m_F[c_nt * c_ndt + c_ntail];
90  double m_r0;
92  double m_r1;
93 
97  explicit SignalInterpolation2(const std::vector<double>&);
102  void getshape(double, val_der_t*) const;
103  };
104 
107  class ECLWaveformFitModule : public Module {
108 
109  public:
110 
114 
118 
120  virtual void initialize() override;
121 
123  virtual void beginRun() override;
124 
127  virtual void event() override;
128 
130  virtual void endRun() override;
131 
133  virtual void terminate() override;
134 
136  virtual const char* eclDigitArrayName() const
137  { return "ECLDigits" ; }
138 
140  virtual const char* eclDspArrayName() const
141  { return "ECLDsps" ; }
142 
143 
144  private:
148  double m_EnergyThreshold{0.03};
149  double m_chi2Threshold25dof{57.1};
150  double m_chi2Threshold27dof{60.0};
151  bool m_TemplatesLoaded{false};
153  std::vector<double> m_ADCtoEnergy;
155  TMinuit* m_Minit2h{nullptr};
156  TMinuit* m_Minit2h2{nullptr};
157  void Fit2h(double& b, double& a0, double& t0, double& a1, double& chi2);
158  void Fit2hExtraPhoton(double& b, double& a0, double& t0, double& a1, double& A2, double& T2,
159  double& chi2);
162  CovariancePacked m_c[8736] = {};
163  bool m_CovarianceMatrix{true};
164  bool m_IsMCFlag{false};
165  };
167 } // end Belle2 namespace
Belle2::ECLWaveformFitModule::beginRun
virtual void beginRun() override
begin run.
Definition: ECLWaveformFit.cc:243
Belle2::ECLWaveformFitModule::m_ADCtoEnergy
std::vector< double > m_ADCtoEnergy
calibration vector form adc to energy
Definition: ECLWaveformFit.h:153
Belle2::ECLWaveformFitModule
Module performs offline fit for saved ecl waveforms.
Definition: ECLWaveformFit.h:107
Belle2::ECLWaveformFitModule::m_eclDSPs
StoreArray< ECLDsp > m_eclDSPs
StoreArray ECLDsp.
Definition: ECLWaveformFit.h:145
Belle2::ECLWaveformFitModule::m_Minit2h2
TMinuit * m_Minit2h2
minuit minimizer for optimized fit with background photon
Definition: ECLWaveformFit.h:156
Belle2::ECLWaveformFitModule::loadTemplateParameterArray
void loadTemplateParameterArray()
loads waveform templates from database.
Definition: ECLWaveformFit.cc:209
Belle2::val_der_t
Struct to return signal function information f0 is the function value f1 is the first derivative f2 i...
Definition: ECLWaveformFit.h:51
Belle2::SignalInterpolation2::m_F
std::pair< double, double > m_F[c_nt *c_ndt+c_ntail]
storage for function value + first derivative
Definition: ECLWaveformFit.h:83
Belle2::SignalInterpolation2::c_idtn
constexpr static double c_idtn
inverted time substep
Definition: ECLWaveformFit.h:79
Belle2::ECLWaveformFitModule::m_TemplatesLoaded
bool m_TemplatesLoaded
Flag to indicate if waveform templates are loaded from database.
Definition: ECLWaveformFit.h:151
Belle2::CovariancePacked::m_covMatPacked
float m_covMatPacked[31 *(31+1)/2]
packed matrix
Definition: ECLWaveformFit.h:37
Belle2::SignalInterpolation2::c_nt
constexpr static int c_nt
Signal function is sampled in c_nt time steps with c_ndt substeps + c_ntail steps c_dt is the time st...
Definition: ECLWaveformFit.h:67
Belle2::SignalInterpolation2::c_ndt
constexpr static int c_ndt
substeps
Definition: ECLWaveformFit.h:69
Belle2::ECLWaveformFitModule::m_chi2Threshold25dof
double m_chi2Threshold25dof
chi2 threshold (25 dof) to classify offline fit as good fit.
Definition: ECLWaveformFit.h:149
Belle2::val_der_t::f1
double f1
see struct description
Definition: ECLWaveformFit.h:55
Belle2::ECLWaveformFitModule::m_CovarianceMatrix
bool m_CovarianceMatrix
Option to use crystal dependent covariance matrices.
Definition: ECLWaveformFit.h:163
Belle2::ECLWaveformFitModule::ECLWaveformFitModule
ECLWaveformFitModule()
Constructor.
Definition: ECLWaveformFit.cc:191
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::CovariancePacked
Struct to keep upper triangle of the covariance matrix.
Definition: ECLWaveformFit.h:35
Belle2::ECLWaveformFitModule::m_eclDigits
StoreArray< ECLDigit > m_eclDigits
StoreArray ECLDigit.
Definition: ECLWaveformFit.h:146
Belle2::ECLWaveformFitModule::initialize
virtual void initialize() override
Initialize variables.
Definition: ECLWaveformFit.cc:282
Belle2::val_der_t::f0
double f0
see struct description
Definition: ECLWaveformFit.h:53
Belle2::SignalInterpolation2::c_dtn
constexpr static double c_dtn
time substep
Definition: ECLWaveformFit.h:77
Belle2::ECLWaveformFitModule::Fit2hExtraPhoton
void Fit2hExtraPhoton(double &b, double &a0, double &t0, double &a1, double &A2, double &T2, double &chi2)
Optimized fit using hadron component model plus out of time background photon.
Definition: ECLWaveformFit.cc:481
Belle2::SignalInterpolation2::getshape
void getshape(double, val_der_t *) const
returns signal shape(+derivatives) in 31 equidistant time points starting from T0
Definition: ECLWaveformFit.cc:557
Belle2::ECLWaveformFitModule::~ECLWaveformFitModule
~ECLWaveformFitModule()
Destructor.
Definition: ECLWaveformFit.cc:204
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::val_der_t::f2
double f2
see struct description
Definition: ECLWaveformFit.h:57
Belle2::SignalInterpolation2::m_r1
double m_r1
see above
Definition: ECLWaveformFit.h:92
Belle2::ECLWaveformFitModule::m_IsMCFlag
bool m_IsMCFlag
Flag to indicate if running over data or MC.
Definition: ECLWaveformFit.h:164
Belle2::ECLWaveformFitModule::Fit2h
void Fit2h(double &b, double &a0, double &t0, double &a1, double &chi2)
Optimized fit using hadron component model.
Definition: ECLWaveformFit.cc:438
Belle2::SignalInterpolation2
Interpolate signal shape using function values and the first derivative.
Definition: ECLWaveformFit.h:62
Belle2::ECLWaveformFitModule::event
virtual void event() override
event per event.
Definition: ECLWaveformFit.cc:324
Belle2::CovariancePacked::operator[]
float & operator[](int i)
lvalue access by index
Definition: ECLWaveformFit.h:41
Belle2::CovariancePacked::sigma
float sigma
sigma noise
Definition: ECLWaveformFit.h:39
Belle2::ECLWaveformFitModule::m_chi2Threshold27dof
double m_chi2Threshold27dof
chi2 threshold (27 dof) to classify offline fit as good fit.
Definition: ECLWaveformFit.h:150
Belle2::ECLWaveformFitModule::terminate
virtual void terminate() override
terminate.
Definition: ECLWaveformFit.cc:433
Belle2::SignalInterpolation2::c_ntail
constexpr static int c_ntail
tail steps
Definition: ECLWaveformFit.h:71
Belle2::ECLWaveformFitModule::eclDigitArrayName
virtual const char * eclDigitArrayName() const
ECLDigits Array Name.
Definition: ECLWaveformFit.h:136
Belle2::SignalInterpolation2::c_idt
constexpr static double c_idt
inverted time step
Definition: ECLWaveformFit.h:75
Belle2::ECLWaveformFitModule::m_Minit2h
TMinuit * m_Minit2h
minuit minimizer for optimized fit
Definition: ECLWaveformFit.h:155
Belle2::SignalInterpolation2::SignalInterpolation2
SignalInterpolation2()
Default constructor.
Definition: ECLWaveformFit.h:95
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::ECLWaveformFitModule::m_si
SignalInterpolation2 m_si[8736][3]
ShaperDSP signal shapes.
Definition: ECLWaveformFit.h:160
Belle2::ECLWaveformFitModule::eclDspArrayName
virtual const char * eclDspArrayName() const
ECLDspsArray Name.
Definition: ECLWaveformFit.h:140
Belle2::ECLWaveformFitModule::endRun
virtual void endRun() override
end run.
Definition: ECLWaveformFit.cc:428
Belle2::SignalInterpolation2::m_r0
double m_r0
assuming exponential drop of the signal function far away from 0, extrapolate it to +inf f(i_last + i...
Definition: ECLWaveformFit.h:90
Belle2::CovariancePacked::operator[]
const float & operator[](int i) const
rvalue access by index
Definition: ECLWaveformFit.h:43
Belle2::SignalInterpolation2::c_dt
constexpr static double c_dt
time step
Definition: ECLWaveformFit.h:73
Belle2::ECLWaveformFitModule::m_c
CovariancePacked m_c[8736]
Packed covariance matrices.
Definition: ECLWaveformFit.h:162
Belle2::ECLWaveformFitModule::m_EnergyThreshold
double m_EnergyThreshold
energy threshold to fit pulse offline
Definition: ECLWaveformFit.h:148