1 #ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitFixedAlphaBetaAlgo_HH
2 #define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitFixedAlphaBetaAlgo_HH
14 #include "CLHEP/Matrix/Vector.h"
15 #include "CLHEP/Matrix/SymMatrix.h"
65 EcalUncalibRecHitFixedAlphaBetaAlgo<C>():
fAlpha_(0.),
fBeta_(0.),
fAmp_max_(-1.),
fTim_max_(-1),
fPed_max_(0),
alfabeta_(0),
fNb_iter_(4),
fNum_samp_bef_max_(1),
fNum_samp_after_max_(3),
fSigma_ped(1.1),
DM1_(3),
temp_(3){
67 for (
int i=0;
i<36;
i++){
68 for(
int j=0;
j<1701;
j++){
77 EcalUncalibRecHitFixedAlphaBetaAlgo<C>(
int n_iter,
int n_bef_max =1,
int n_aft_max =3,
float sigma_ped = 1.1):
fAlpha_(0.),
fBeta_(0.),
fAmp_max_(-1.),
fTim_max_(-1),
fPed_max_(0),
alfabeta_(0),
DM1_(3),
temp_(3){
84 for (
int i=0;
i<36;
i++){
85 for(
int j=0;
j<1701;
j++){
97 const double* gainRatios,
109 const double* gainRatios,
115 double frame[C::MAXSAMPLES];
121 double maxsample(-1);
123 bool external_pede =
false;
128 external_pede =
true;
129 if(dyn_pedestal) { pedestal = (double(dataFrame.sample(0).adc()) +
double(dataFrame.sample(1).adc()))/2.;}
130 else{ pedestal = pedestals[0];}
131 for(
int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
133 GainId = dataFrame.sample(iSample).gainId();
144 if (GainId != gainId0) iGainSwitch = 1;
146 if(GainId==gainId0){frame[iSample] = double(dataFrame.sample(iSample).adc())-pedestal ;}
147 else {frame[iSample] = (double(dataFrame.sample(iSample).adc())-pedestals[GainId-1])*gainRatios[GainId-1];}
149 if( frame[iSample]>maxsample ) {
150 maxsample = frame[iSample];
156 external_pede =
false;
157 pedestal = (double(dataFrame.sample(0).adc()) +
double(dataFrame.sample(1).adc()))/2.;
159 for(
int iSample = 0; iSample < C::MAXSAMPLES; iSample++) {
161 GainId = dataFrame.sample(iSample).gainId();
169 frame[iSample] = double(dataFrame.sample(iSample).adc())-pedestal ;
171 if (GainId > gainId0) iGainSwitch = 1;
172 if( frame[iSample]>maxsample ) {
173 maxsample = frame[iSample];
179 if( (iGainSwitch==1 && external_pede==
false) ||
184 InitFitParameters(frame, imax);
185 chi2_ = PerformAnalyticFit(frame,imax);
196 if( alfabeta_ <= 0 )
return((
double)0.);
197 double dtsbeta,variable,puiss;
198 double dt = t-fTim_max_ ;
199 if(dt > -alfabeta_) {
201 variable=1.+dt/alfabeta_ ;
202 puiss=
pow(variable,fAlpha_);
203 return fAmp_max_*puiss*
exp(-dtsbeta)+fPed_max_ ;
211 fAmp_max_ = samples[max_sample];
212 fTim_max_ = max_sample;
217 if(fAmp_max_ < MinAmpl_){
218 fAmp_max_ = samples[5];
219 double sumA = samples[5]+samples[4]+samples[6];
220 if(sumA != 0) { fTim_max_ = 5+(samples[6]-samples[4])/sumA; }
221 else{ fTim_max_ = -993; }
225 else if(max_sample <1 || max_sample > 7)
230 float a = float(samples[max_sample-1]+samples[max_sample+1]-2*samples[max_sample])/2.;
231 if(a==0){doFit_ =
false;
return;}
232 float b = float(samples[max_sample+1]-samples[max_sample-1])/2.;
234 fTim_max_ = max_sample - b/(2*
a);
235 fAmp_max_ = samples[max_sample] - b*b/(4*
a);
254 int num_fit_min =(int)(max_sample - fNum_samp_bef_max_ ) ;
255 int num_fit_max =(int)(max_sample + fNum_samp_after_max_) ;
257 if (num_fit_min<0) num_fit_min = 0 ;
259 if (num_fit_max>= C::MAXSAMPLES ) {num_fit_max = C::MAXSAMPLES-1 ;}
262 LogDebug(
"EcalUncalibRecHitFixedAlphaBetaAlgo")<<
"No fit performed. The amplitude of sample 5 will be used";
267 double variation_func_max = 0. ;
double variation_tim_max = 0. ;
double variation_ped_max = 0. ;
269 for (
int iter=0 ; iter < fNb_iter_ ; iter ++) {
273 for(
int i1=0 ; i1<3 ; i1++) {
275 for(
int j1=i1 ; j1<3 ; j1++) {
276 DM1_.fast(j1+1,i1+1) = 0; }
279 fAmp_max_ += variation_func_max ;
280 fTim_max_ += variation_tim_max ;
281 fPed_max_ += variation_ped_max ;
284 for(
int i = num_fit_min ;
i <= num_fit_max ;
i++) {
287 func = pulseShapeFunction( (
double)
i ) ;
289 double dt =(double)i - fTim_max_ ;
290 if(dt > -alfabeta_) {
291 double dt_sur_beta = dt/fBeta_ ;
292 double variable = (double)1. + dt/alfabeta_ ;
293 double expo =
exp(-dt_sur_beta) ;
294 double puissance =
pow(variable,fAlpha_) ;
296 db[0]=un_sur_sigma*puissance*expo ;
297 db[1]=fAmp_max_*
db[0]*dt_sur_beta/(alfabeta_*variable) ;
300 db[0]=0. ;
db[1]=0. ;
304 for(
int i1=0 ; i1<3 ; i1++) {
305 for(
int j1=i1 ; j1<3 ; j1++) {
307 DM1_.fast(j1+1,i1+1) +=
db[i1]*
db[j1]; }
310 delta = (samples[
i]-
func)*un_sur_sigma ;
312 for(
int ii=0 ;
ii<3 ;
ii++) {temp_[
ii] += delta*
db[
ii] ;}
313 chi2 += delta *
delta ;
321 InitFitParameters(samples,max_sample);
331 CLHEP::HepVector
PROD = DM1_*temp_ ;
338 InitFitParameters(samples,max_sample);
342 variation_func_max = PROD[0] ;
343 variation_tim_max = PROD[1] ;
344 variation_ped_max = PROD[2] ;
350 if( variation_func_max > 2000. || variation_func_max < -1000. ) {
351 InitFitParameters(samples,max_sample);
357 fAmp_max_ += variation_func_max ;
358 fTim_max_ += variation_tim_max ;
359 fPed_max_ += variation_ped_max ;
364 if( fAmp_max_>2*samples[max_sample] || fAmp_max_<-100 || fTim_max_<0 || 9<fTim_max_ ) {
365 InitFitParameters(samples,max_sample);
377 alfabeta_ = fAlpha_*fBeta_;
void InitFitParameters(double *samples, int max_sample)
float beta_table_[36][1701]
std::vector< Variable::Flags > flags
double pulseShapeFunction(double t)
virtual EcalUncalibratedRecHit makeRecHit(const C &dataFrame, const double *pedestals, const double *gainRatios, const EcalWeightSet::EcalWeightMatrix **weights, const EcalWeightSet::EcalChi2WeightMatrix **chi2Matrix)
Compute parameters.
float alpha_table_[36][1701]
void SetMinAmpl(double ampl)
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
void SetAlphaBeta(double alpha, double beta)
bool isSaturated(const Digi &digi, const int &maxADCvalue, int ifirst, int n)
math::Matrix< 3, 10 >::type EcalWeightMatrix
float PerformAnalyticFit(double *samples, int max_sample)
void SetDynamicPedestal(bool dyn_pede)
Power< A, B >::type pow(const A &a, const B &b)