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.;
144 pedestal = pedestals[0];
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);
210 return EcalUncalibratedRecHit(dataFrame.id(), fAmp_max_, pedestal + fPed_max_, fTim_max_ - 5, chi2_, flags);
217 double dtsbeta, variable, puiss;
218 double dt = t - fTim_max_;
219 if (dt > -alfabeta_) {
220 dtsbeta = dt / fBeta_;
221 variable = 1. + dt / alfabeta_;
222 puiss =
pow(variable, fAlpha_);
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_) {
238 fAmp_max_ = samples[5];
239 double sumA = samples[5] + samples[4] + samples[6];
241 fTim_max_ = 5 + (samples[6] - samples[4]) / sumA;
248 else if (max_sample < 1 || max_sample > 7) {
253 float a = float(samples[max_sample - 1] + samples[max_sample + 1] - 2 * samples[max_sample]) / 2.;
258 float b = float(samples[max_sample + 1] - samples[max_sample - 1]) / 2.;
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);
324 double puissance =
pow(variable, fAlpha_);
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];
341 delta = (samples[
i] -
func) * un_sur_sigma;
343 for (
int ii = 0;
ii < 3;
ii++) {
344 temp_[
ii] += delta *
db[
ii];
346 chi2 += delta *
delta;
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_;
void InitFitParameters(double *samples, int max_sample)
float beta_table_[36][1701]
constexpr bool isNotFinite(T x)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
math::Matrix< 3, 10 >::type EcalWeightMatrix
double pulseShapeFunction(double t)
EcalUncalibratedRecHit makeRecHit(const C &dataFrame, const double *pedestals, const double *gainRatios, const EcalWeightSet::EcalWeightMatrix **weights, const EcalWeightSet::EcalChi2WeightMatrix **chi2Matrix) override
Compute parameters.
Exp< T >::type exp(const T &t)
float alpha_table_[36][1701]
void SetMinAmpl(double ampl)
void SetAlphaBeta(double alpha, double beta)
bool isSaturated(const Digi &digi, const int &maxADCvalue, int ifirst, int n)
float PerformAnalyticFit(double *samples, int max_sample)
void SetDynamicPedestal(bool dyn_pede)
Power< A, B >::type pow(const A &a, const B &b)