1 #ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitFixedAlphaBetaAlgo_HH
2 #define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitFixedAlphaBetaAlgo_HH
14 #include "CLHEP/Matrix/Vector.h"
15 #include "CLHEP/Matrix/SymMatrix.h"
77 for (
int i = 0;
i < 36;
i++) {
78 for (
int j = 0;
j < 1701;
j++) {
94 for (
int i = 0;
i < 36;
i++) {
95 for (
int j = 0;
j < 1701;
j++) {
107 const double* pedestals,
108 const double* gainRatios,
120 const double* pedestals,
121 const double* gainRatios,
127 double frame[C::MAXSAMPLES];
133 double maxsample(-1);
135 bool external_pede =
false;
140 external_pede =
true;
142 pedestal = (double(dataFrame.sample(0).adc()) +
double(dataFrame.sample(1).adc())) / 2.;
146 for (
int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
148 GainId = dataFrame.sample(iSample).gainId();
158 if (GainId != gainId0)
161 if (GainId == gainId0) {
162 frame[iSample] = double(dataFrame.sample(iSample).adc()) -
pedestal;
164 frame[iSample] = (double(dataFrame.sample(iSample).adc()) - pedestals[GainId - 1]) * gainRatios[GainId - 1];
167 if (
frame[iSample] > maxsample) {
168 maxsample =
frame[iSample];
173 external_pede =
false;
174 pedestal = (double(dataFrame.sample(0).adc()) +
double(dataFrame.sample(1).adc())) / 2.;
176 for (
int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
178 GainId = dataFrame.sample(iSample).gainId();
185 frame[iSample] = double(dataFrame.sample(iSample).adc()) -
pedestal;
187 if (GainId > gainId0)
189 if (
frame[iSample] > maxsample) {
190 maxsample =
frame[iSample];
196 if ((iGainSwitch == 1 && external_pede ==
false) ||
201 InitFitParameters(
frame, imax);
202 chi2_ = PerformAnalyticFit(
frame, imax);
218 double dt =
t - fTim_max_;
219 if (
dt > -alfabeta_) {
220 dtsbeta =
dt / fBeta_;
223 return fAmp_max_ * puiss *
exp(-dtsbeta) + fPed_max_;
231 fAmp_max_ =
samples[max_sample];
232 fTim_max_ = max_sample;
237 if (fAmp_max_ < MinAmpl_) {
248 else if (max_sample < 1 || max_sample > 7) {
260 fTim_max_ = max_sample -
b / (2 *
a);
261 fAmp_max_ =
samples[max_sample] -
b *
b / (4 *
a);
278 int num_fit_min = (
int)(max_sample - fNum_samp_bef_max_);
279 int num_fit_max = (
int)(max_sample + fNum_samp_after_max_);
284 if (num_fit_max >= C::MAXSAMPLES) {
285 num_fit_max = C::MAXSAMPLES - 1;
289 LogDebug(
"EcalUncalibRecHitFixedAlphaBetaAlgo") <<
"No fit performed. The amplitude of sample 5 will be used";
294 double variation_func_max = 0.;
295 double variation_tim_max = 0.;
296 double variation_ped_max = 0.;
298 for (
int iter = 0; iter < fNb_iter_; iter++) {
302 for (
int i1 = 0;
i1 < 3;
i1++) {
304 for (
int j1 =
i1; j1 < 3; j1++) {
305 DM1_.fast(j1 + 1,
i1 + 1) = 0;
309 fAmp_max_ += variation_func_max;
310 fTim_max_ += variation_tim_max;
311 fPed_max_ += variation_ped_max;
314 for (
int i = num_fit_min;
i <= num_fit_max;
i++) {
317 func = pulseShapeFunction((
double)
i);
319 double dt = (double)
i - fTim_max_;
320 if (
dt > -alfabeta_) {
321 double dt_sur_beta =
dt / fBeta_;
322 double variable = (double)1. +
dt / alfabeta_;
323 double expo =
exp(-dt_sur_beta);
326 db[0] = un_sur_sigma * puissance * expo;
327 db[1] = fAmp_max_ *
db[0] * dt_sur_beta / (alfabeta_ *
variable);
332 db[2] = un_sur_sigma;
334 for (
int i1 = 0;
i1 < 3;
i1++) {
335 for (
int j1 =
i1; j1 < 3; j1++) {
337 DM1_.fast(j1 + 1,
i1 + 1) +=
db[
i1] *
db[j1];
343 for (
int ii = 0;
ii < 3;
ii++) {
354 InitFitParameters(
samples, max_sample);
364 CLHEP::HepVector
PROD = DM1_ * temp_;
371 InitFitParameters(
samples, max_sample);
375 variation_func_max =
PROD[0];
376 variation_tim_max =
PROD[1];
377 variation_ped_max =
PROD[2];
382 if (variation_func_max > 2000. || variation_func_max < -1000.) {
383 InitFitParameters(
samples, max_sample);
388 fAmp_max_ += variation_func_max;
389 fTim_max_ += variation_tim_max;
390 fPed_max_ += variation_ped_max;
394 if (fAmp_max_ > 2 *
samples[max_sample] || fAmp_max_ < -100 || fTim_max_ < 0 || 9 < fTim_max_) {
395 InitFitParameters(
samples, max_sample);
407 alfabeta_ = fAlpha_ * fBeta_;