Belle II Software  release-08-01-10
ECLWaveformFit.h
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 #pragma once
10 
11 /* ECL headers. */
12 #include <ecl/dataobjects/ECLDigit.h>
13 #include <ecl/dataobjects/ECLDsp.h>
14 #include <ecl/dbobjects/ECLAutoCovariance.h>
15 #include <ecl/dbobjects/ECLCrystalCalib.h>
16 #include <ecl/dbobjects/ECLDigitWaveformParameters.h>
17 #include <ecl/dbobjects/ECLDigitWaveformParametersForMC.h>
18 
19 /* Basf2 headers. */
20 #include <framework/core/Module.h>
21 #include <framework/database/DBObjPtr.h>
22 #include <framework/datastore/StoreArray.h>
23 
24 class TMinuit;
25 
26 namespace Belle2 {
39 
41  float m_covMatPacked[31 * (31 + 1) / 2] = {};
42 
44  float sigma{ -1};
45 
47  float& operator[](int i) { return m_covMatPacked[i];}
48 
50  const float& operator[](int i) const { return m_covMatPacked[i];}
51  };
52 
58 
63  constexpr static int c_nt = 12;
64 
66  constexpr static int c_ndt = 5;
67 
69  constexpr static int c_ntail = 20;
70 
72  constexpr static double c_dt = 0.5;
73 
75  constexpr static double c_idt = 1 / c_dt;
76 
78  constexpr static double c_dtn = c_dt / c_ndt;
79 
81  constexpr static double c_idtn = c_ndt / c_dt;
82 
85 
88 
97  double m_r0;
98 
100  double m_r1;
101 
106 
111  explicit SignalInterpolation2(const std::vector<double>&);
112 
120  void getShape(double t0, double* function, double* derivatives) const;
121 
122  };
123 
127  class ECLWaveformFitModule : public Module {
128 
129  public:
130 
134 
138 
140  virtual void initialize() override;
141 
143  virtual void beginRun() override;
144 
147  virtual void event() override;
148 
150  virtual void endRun() override;
151 
153  virtual void terminate() override;
154 
156  virtual const char* eclDigitArrayName() const
157  { return "ECLDigits" ; }
158 
160  virtual const char* eclDspArrayName() const
161  { return "ECLDsps" ; }
162 
163 
164  private:
165 
170 
174  void Fit2h(double& b, double& a0, double& t0, double& a1, double& chi2);
175 
180  void Fit2hExtraPhoton(double& b, double& a0, double& t0, double& a1,
181  double& A2, double& T2, double& chi2);
182 
184  double m_EnergyThreshold{0.03};
185 
187  double m_chi2Threshold25dof{57.1};
188 
190  double m_chi2Threshold27dof{60.0};
191 
193  bool m_TemplatesLoaded{false};
194 
196  std::vector<double> m_ADCtoEnergy;
197 
199  TMinuit* m_Minit2h{nullptr};
200 
202  TMinuit* m_Minit2h2{nullptr};
203 
206 
209 
211  bool m_CovarianceMatrix{true};
212 
214  bool m_IsMCFlag{false};
215 
218 
221 
224 
227 
230 
233 
236 
237  };
238 
240 }
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Module performs offline fit for saved ECL waveforms.
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.
virtual const char * eclDigitArrayName() const
ECLDigits Array Name.
virtual void initialize() override
Initialize variables.
DBObjPtr< ECLDigitWaveformParameters > m_WaveformParameters
Waveform parameters.
double m_chi2Threshold25dof
chi2 threshold (25 dof) to classify offline fit as good fit.
DBObjPtr< ECLAutoCovariance > m_AutoCovariance
Autocovariance.
virtual void event() override
event per event.
virtual void endRun() override
end run.
TMinuit * m_Minit2h
Minuit minimizer for optimized fit.
bool m_IsMCFlag
Flag to indicate if running over data or MC.
StoreArray< ECLDsp > m_eclDSPs
StoreArray ECLDsp.
virtual void terminate() override
terminate.
StoreArray< ECLDigit > m_eclDigits
StoreArray ECLDigit.
std::vector< double > m_ADCtoEnergy
Calibration vector from ADC to energy.
void loadTemplateParameterArray()
Loads waveform templates from database.
bool m_CovarianceMatrix
Option to use crystal dependent covariance matrices.
void Fit2h(double &b, double &a0, double &t0, double &a1, double &chi2)
Optimized fit using hadron component model.
DBObjPtr< ECLCrystalCalib > m_CrystalElectronics
Crystal electronics.
virtual void beginRun() override
begin run.
DBObjPtr< ECLCrystalCalib > m_CrystalEnergy
Crystal energy.
TMinuit * m_Minit2h2
Minuit minimizer for optimized fit with background photon.
virtual const char * eclDspArrayName() const
ECLDspsArray Name.
double m_EnergyThreshold
Energy threshold to fit pulse offline.
double m_chi2Threshold27dof
chi2 threshold (27 dof) to classify offline fit as good fit.
DBObjPtr< ECLDigitWaveformParametersForMC > m_WaveformParametersForMC
Waveform parameters for MC.
CovariancePacked m_c[ECLElementNumbers::c_NCrystals]
Packed covariance matrices.
bool m_TemplatesLoaded
Flag to indicate if waveform templates are loaded from database.
SignalInterpolation2 m_si[ECLElementNumbers::c_NCrystals][3]
ShaperDSP signal shapes.
Base class for Modules.
Definition: Module.h:72
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.
Struct to keep upper triangle of the covariance matrix.
const float & operator[](int i) const
Rvalue access by index.
float & operator[](int i)
Lvalue access by index.
float m_covMatPacked[31 *(31+1)/2]
Packed matrix.
float sigma
Sigma noise.
Interpolation of signal shape using function values and the first derivative.
double m_r0
Assuming exponential drop of the signal function far away from 0, extrapolate it to +inf.
double m_FunctionInterpolation[c_nt *c_ndt+c_ntail]
Function values.
constexpr static double c_idt
Inverted time step.
SignalInterpolation2()
Default constructor.
void getShape(double t0, double *function, double *derivatives) const
Returns signal shape and derivatives in 31 equidistant time points starting from t0.
constexpr static int c_ntail
Number of tail steps.
constexpr static double c_dtn
Time substep.
constexpr static double c_idtn
Inverted time substep.
double m_DerivativeInterpolation[c_nt *c_ndt+c_ntail]
Derivative values.
constexpr static int c_nt
Signal function is sampled in c_nt time steps with c_ndt substeps and c_ntail steps.
constexpr static double c_dt
Time step.
constexpr static int c_ndt
Number of substeps.