1 #ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecChi2Algo_HH
2 #define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitRecChi2Algo_HH
13 #include "Math/SVector.h"
14 #include "Math/SMatrix.h"
33 const double amplitudeOutOfTime,
35 const double* pedestals,
36 const double* pedestalsRMS,
37 const double* gainRatios,
39 const std::vector<double>& chi2Parameters);
53 const double amplitudeOutOfTime,
55 const double* pedestals,
56 const double* pedestalsRMS,
57 const double* gainRatios,
59 const std::vector<double>& chi2Parameters) {
60 double noise_A = chi2Parameters[0];
61 double const_A = chi2Parameters[1];
62 double noise_B = chi2Parameters[2];
63 double const_B = chi2Parameters[3];
73 for (
int iSample = 0; iSample < C::MAXSAMPLES;
76 int gainId = dataFrame.sample(iSample).gainId();
84 if (
gainId == 1 && iSample == 0)
85 S_0 = dataFrame.sample(iSample).adc();
86 if (
gainId == 1 && iSample < 3)
87 ped_ave += (1 / 3.0) * dataFrame.sample(iSample).adc();
91 double ADC_clock = 25;
92 double risingTime = testbeamPulseShape.
timeToRise();
93 double tzero = risingTime - 5 * ADC_clock;
95 double shiftTime = +timeIC;
96 double shiftTimeOutOfTime = -jitter * ADC_clock;
98 bool readoutError =
false;
100 for (
int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
101 int gainId = dataFrame.sample(iSample).gainId();
102 if (dataFrame.sample(iSample).adc() == 0)
108 !iGainSwitch ? ped_ave : pedestals[
gainId - 1];
110 double S_i = double(dataFrame.sample(iSample).adc());
114 double f_i = (testbeamPulseShape)(
tzero + shiftTime + iSample * ADC_clock);
116 double R_iErrorSquare = noise_A * noise_A + const_A * const_A *
amplitude *
amplitude;
118 chi2_ += R_i * R_i / R_iErrorSquare;
122 double g_i = (testbeamPulseShape)(
tzero + shiftTimeOutOfTime + iSample * ADC_clock);
124 double R_iOutOfTime = (S_i - S_0) * gainRatios[
gainId - 1] - g_i * amplitudeOutOfTime;
125 double R_iOutOfTimeErrorSquare = noise_B * noise_B + const_B * const_B * amplitudeOutOfTime * amplitudeOutOfTime;
127 chi2OutOfTime_ += R_iOutOfTime * R_iOutOfTime / R_iOutOfTimeErrorSquare;
130 if (!
isSaturated && !iGainSwitch && chi2_ > 0 && chi2OutOfTime_ > 0) {
131 chi2_ = 7 * (3 +
log(chi2_));
132 chi2_ = chi2_ < 0 ? 0 : chi2_;
133 chi2OutOfTime_ = 7 * (3 +
log(chi2OutOfTime_));
134 chi2OutOfTime_ = chi2OutOfTime_ < 0 ? 0 : chi2OutOfTime_;
143 chi2OutOfTime_ = 99.0;