1 #ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecChi2Algo_HH
2 #define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecChi2Algo_HH
13 #include "Math/SVector.h"
14 #include "Math/SMatrix.h"
34 const double amplitude,
36 const double amplitudeOutOfTime,
38 const double* pedestals,
39 const double* pedestalsRMS,
40 const double* gainRatios,
42 const std::vector<double>& chi2Parameters
59 const double amplitude,
61 const double amplitudeOutOfTime,
63 const double* pedestals,
64 const double* pedestalsRMS,
65 const double* gainRatios,
67 const std::vector<double>& chi2Parameters
71 double noise_A = chi2Parameters[0];
72 double const_A = chi2Parameters[1];
73 double noise_B = chi2Parameters[2];
74 double const_B = chi2Parameters[3];
85 for(
int iSample = 0; iSample < C::MAXSAMPLES; iSample++)
87 int gainId = dataFrame.sample(iSample).gainId();
93 if(gainId != gainId0)iGainSwitch = 1;
95 if(gainId==1 && iSample==0)S_0 = dataFrame.sample(iSample).adc();
96 if(gainId==1 && iSample<3)ped_ave += (1/3.0)*dataFrame.sample(iSample).adc();
101 double ADC_clock = 25;
102 double risingTime = testbeamPulseShape.
timeToRise();
103 double tzero = risingTime - 5*ADC_clock;
105 double shiftTime = + timeIC;
106 double shiftTimeOutOfTime = -jitter*ADC_clock;
109 bool readoutError =
false;
111 for(
int iSample = 0; iSample < C::MAXSAMPLES; iSample++)
113 int gainId = dataFrame.sample(iSample).gainId();
114 if(dataFrame.sample(iSample).adc()==0)readoutError=
true;
115 if(gainId==0)
continue;
118 double ped = !iGainSwitch ? ped_ave:pedestals[gainId-1];
120 double S_i = double(dataFrame.sample(iSample).adc());
125 double f_i = (testbeamPulseShape)(tzero + shiftTime + iSample*ADC_clock);
126 double R_i = (S_i- ped)*gainRatios[gainId-1] - f_i*amplitude;
127 double R_iErrorSquare = noise_A*noise_A + const_A*const_A*amplitude*amplitude;
129 chi2_ += R_i*R_i/R_iErrorSquare;
133 double g_i = (testbeamPulseShape)(tzero + shiftTimeOutOfTime + iSample*ADC_clock);
135 double R_iOutOfTime = (S_i- S_0)*gainRatios[gainId-1] - g_i*amplitudeOutOfTime;
136 double R_iOutOfTimeErrorSquare = noise_B*noise_B + const_B*const_B*amplitudeOutOfTime*amplitudeOutOfTime;
139 chi2OutOfTime_ += R_iOutOfTime*R_iOutOfTime/R_iOutOfTimeErrorSquare;
143 if(!isSaturated && !iGainSwitch && chi2_>0 && chi2OutOfTime_>0)
145 chi2_ = 7*(3+
log(chi2_)); chi2_ = chi2_<0 ? 0:chi2_;
146 chi2OutOfTime_ = 7*(3+
log(chi2OutOfTime_)); chi2OutOfTime_ = chi2OutOfTime_<0 ? 0:chi2OutOfTime_;
static std::vector< std::string > checklist log
int gainId(sample_type sample)
get the gainId (2 bits)
virtual double chi2OutOfTime()
EcalUncalibRecHitRecChi2Algo()
bool isSaturated(const Digi &digi, const int &maxADCvalue, int ifirst, int n)
float EcalTimeCalibConstant
static const double tzero[3]
virtual double timeToRise() const