CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
PulseFitWithFunction Class Reference

#include <PulseFitWithFunction.h>

Inheritance diagram for PulseFitWithFunction:

Public Member Functions

virtual double doFit (double *)
 
double getAmpl ()
 
double getAmpl_parab ()
 
double getMax_parab ()
 
int getSampMax_parab ()
 
double getTime ()
 
double getTime_parab ()
 
virtual void init (int, int, int, int, double, double)
 
 PulseFitWithFunction ()
 
virtual ~PulseFitWithFunction ()
 

Public Attributes

double fAmp_fitted_max
 
double fFunc_max
 
int fNumber_samp_max
 
double fSigma_ped
 
double fTim_fitted_max
 
double fTim_max
 
double fValue_tim_max
 

Private Member Functions

double Electronic_shape (double)
 
double Fit_electronic (int, double *, double)
 
void Fit_parab (double *, int, int, double *)
 

Private Attributes

double amp_max
 
double amp_parab
 
double fAlpha
 
double fAlpha_beam
 
double fAlpha_laser
 
double fBeta
 
double fBeta_beam
 
double fBeta_laser
 
int fNb_iter
 
int fNsamples
 
int fNum_samp_after_max
 
int fNum_samp_bef_max
 
int imax
 
double tim_parab
 

Detailed Description

Definition at line 26 of file PulseFitWithFunction.h.

Constructor & Destructor Documentation

PulseFitWithFunction::PulseFitWithFunction ( )
PulseFitWithFunction::~PulseFitWithFunction ( )
virtual

Definition at line 37 of file PulseFitWithFunction.cc.

38 {
39 }

Member Function Documentation

double PulseFitWithFunction::doFit ( double *  adc)
virtual

Definition at line 68 of file PulseFitWithFunction.cc.

References amp_max, amp_parab, fFunc_max, Fit_electronic(), Fit_parab(), fNsamples, fNumber_samp_max, fTim_max, fValue_tim_max, imax, and tim_parab.

69 {
70  double parout[4]; // amp_max ;
71  //double amp_parab , tim_parab ;
72  double chi2;
73  //int imax ;
74 //
75 // first one has to get starting point first with parabolic fun// //
76  Fit_parab(&adc[0],3,fNsamples,parout) ;
77  amp_parab = parout[0] ;
78  tim_parab = parout[1] ;
79  imax = (int)parout[2] ;
80  amp_max = parout[3] ;
81  //printf("amp_parab= %f tim_parab=%f amp_max=%f imax=%d\n",amp_parab,tim_parab,amp_max,imax);
83 //
84 
85  if(amp_parab < 1.) {
86  tim_parab = (double)imax ;
87  amp_parab = amp_max ;
88  }
89 //
93 
94 // here to fit maximum amplitude and time of arrival ...
95 
96  chi2 = Fit_electronic(0,&adc[0],8.) ;
97  // adc is an array to be filled with samples
98  // 0 is for Laser (1 for electron)
99  // 8 is for sigma of pedestals
100  // which (can be computed)
101 
102 
103  // double amplitude = fAmp_fitted_max ; // amplitude fitted
104  // double time = fTim_fitted_max ; // time fitted
105 
106 
107 
108  return chi2 ; // return amplitude fitted
109 
110 }
int adc(sample_type sample)
get the ADC sample (12 bits)
void Fit_parab(double *, int, int, double *)
double Fit_electronic(int, double *, double)
double PulseFitWithFunction::Electronic_shape ( double  tim)
private

Definition at line 226 of file PulseFitWithFunction.cc.

References dt, fAlpha, fBeta, fFunc_max, and fTim_max.

Referenced by Fit_electronic().

227 {
228  // electronic function (from simulation) to fit ECAL pulse shape
229  double func_electronic,dtsbeta,variable,puiss;
230  double albet = fAlpha*fBeta ;
231  if( albet <= 0 ) return( (Double_t)0. );
232  double dt = tim-fTim_max ;
233  if(dt > -albet) {
234  dtsbeta=dt/fBeta ;
235  variable=1.+dt/albet ;
236  puiss=TMath::Power(variable,fAlpha);
237  func_electronic=fFunc_max*puiss*TMath::Exp(-dtsbeta);
238  }
239  else func_electronic = 0. ;
240  //
241  return func_electronic ;
242 }
float dt
Definition: AMPTWrapper.h:126
double PulseFitWithFunction::Fit_electronic ( int  data,
double *  adc_to_fit,
double  sigmas_sample 
)
private

Definition at line 116 of file PulseFitWithFunction.cc.

References delta, dt, Electronic_shape(), fAlpha, fAlpha_beam, fAlpha_laser, fAmp_fitted_max, fBeta, fBeta_beam, fBeta_laser, fFunc_max, fNb_iter, fNum_samp_after_max, fNum_samp_bef_max, fNumber_samp_max, fSigma_ped, fTim_fitted_max, fTim_max, fValue_tim_max, i, and getDQMSummary::iter.

Referenced by doFit().

116  {
117  // fit electronic function from simulation
118  // parameters fAlpha and fBeta are fixed and fit is providing
119  // the maximum amplitude ( fAmp_fitted_max ) and the time of
120  // the maximum amplitude ( fTim_fitted_max)
121  // initialization of parameters
122  double chi2=0;
123  double d_alpha, d_beta ;
124  // first initialize parameters fAlpha and fBeta ( depending of beam or laser)
125  fAlpha = fAlpha_laser ;
126  fBeta = fBeta_laser ;
127  if(data == 1) {
128  fAlpha = fAlpha_beam ;
129  fBeta = fBeta_beam ;
130  }
131  //
132  fAmp_fitted_max = 0. ;
133  fTim_fitted_max = 0. ;
134  double un_sur_sigma = 1./fSigma_ped ;
135  double variation_func_max = 0. ;
136  double variation_tim_max = 0. ;
137  //
138  if(fValue_tim_max > 20. || fValue_tim_max < 3.) {
140  }
141  int num_fit_min =(int)(fValue_tim_max - fNum_samp_bef_max) ;
142  int num_fit_max =(int)(fValue_tim_max + fNum_samp_after_max) ;
143  //
144 
145  if( sigmas_sample > 0. ) un_sur_sigma = 1./sigmas_sample;
146  else un_sur_sigma = 1.;
147 
148  double func,delta ;
149  // Loop on iterations
150  for (int iter=0 ; iter < fNb_iter ; iter ++) {
151 
152  // initialization inside iteration loop !
153  chi2 = 0. ;
154  double d11 = 0. ;
155  double d12 = 0. ;
156  double d22 = 0. ;
157  double z1 = 0. ;
158  double z2 = 0. ;
159  fFunc_max += variation_func_max ;
160  fTim_max += variation_tim_max ;
161  int nsamp_used = 0 ;
162  //
163 
164  // Then we loop on samples to be fitted
165 
166 
167  for( int i = num_fit_min ; i < num_fit_max+1 ; i++) {
168  // calculate function to be fitted
169 
170  func = Electronic_shape( (double)i ) ;
171 
172  // then calculate derivatives of function to be fitted
173  double dt =(double)i - fTim_max ;
174  double alpha_beta = fAlpha*fBeta ;
175 
176  if(dt > -alpha_beta) {
177  double dt_sur_beta = dt/fBeta ;
178 
179  double variable = (double)1. + dt/alpha_beta ;
180  double expo = TMath::Exp(-dt_sur_beta) ;
181 
182  double puissance = TMath::Power(variable,fAlpha) ;
183  d_alpha=un_sur_sigma*puissance*expo ;
184  d_beta=fFunc_max*d_alpha*dt_sur_beta/(alpha_beta*variable) ;
185  }
186  else {
187  continue ;
188  }
189 
190  nsamp_used ++ ; // number of samples used inside the fit
191  // compute matrix elements D (symetric --> d12 = d21 )
192  d11 += d_alpha*d_alpha ;
193  d12 += d_alpha*d_beta ;
194  d22 += d_beta*d_beta ;
195  // compute delta
196  delta = (adc_to_fit[i]-func)*un_sur_sigma ;
197  // compute vector elements Z
198  z1 += delta*d_alpha ;
199  z2 += delta*d_beta ;
200  chi2 += delta * delta ;
201  } // end of loop on samples
202  double denom = d11*d22-d12*d12 ;
203  if(denom == 0.) {
204  //printf( "attention denom = 0 signal pas fitte \n") ;
205  return 101 ;
206  }
207  if(nsamp_used < 3) {
208  //printf( "Attention nsamp = %d ---> no function fit provided \n",nsamp_used) ;
209  return 102 ;
210  }
211  // compute variations of parameters fAmp_max and fTim_max
212  variation_func_max = (z1*d22-z2*d12)/denom ;
213  variation_tim_max = (-z1*d12+z2*d11)/denom ;
214  chi2 = chi2/((double)nsamp_used - 2.) ;
215  } // end of loop on iterations
216  // results of the fit are calculated
217  fAmp_fitted_max = fFunc_max + variation_func_max ;
218  fTim_fitted_max = fTim_max + variation_tim_max ;
219  //
220  return chi2 ;
221 }
dbl * delta
Definition: mlp_gen.cc:36
float dt
Definition: AMPTWrapper.h:126
int i
Definition: DBlmapReader.cc:9
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void PulseFitWithFunction::Fit_parab ( double *  ,
int  ,
int  ,
double *   
)
private

Definition at line 243 of file PulseFitWithFunction.cc.

References dt, imax, roll_playback::k, and mathSSE::return().

Referenced by doFit().

244 {
245 /* Now we calculate the parabolic adjustement in order to get */
246 /* maximum and time max */
247 
248  double denom,dt,amp1,amp2,amp3 ;
249  double ampmax = 0. ;
250  int imax = 0 ;
251  int k ;
252 /*
253  */
254  for ( k = nmin ; k < nmax ; k++) {
255  //printf("ampl[%d]=%f\n",k,ampl[k]);
256  if (ampl[k] > ampmax ) {
257  ampmax = ampl[k] ;
258  imax = k ;
259  }
260  }
261  amp1 = ampl[imax-1] ;
262  amp2 = ampl[imax] ;
263  amp3 = ampl[imax+1] ;
264  denom=2.*amp2-amp1-amp3 ;
265 /* */
266  if(denom>0.){
267  dt =0.5*(amp3-amp1)/denom ;
268  }
269  else {
270  //printf("denom =%f\n",denom) ;
271  dt=0.5 ;
272  }
273 /* */
274 /* ampmax correspond au maximum d'amplitude parabolique et dt */
275 /* decalage en temps par rapport au sample maximum soit k + dt */
276 
277  parout[0] =amp2+(amp3-amp1)*dt*0.25 ;
278  parout[1] = (double)imax + dt ;
279  parout[2] = (double)imax ;
280  parout[3] = ampmax ;
281 return ;
282 }
float dt
Definition: AMPTWrapper.h:126
return((rh^lh)&mask)
double PulseFitWithFunction::getAmpl ( )
inline

Definition at line 53 of file PulseFitWithFunction.h.

References fAmp_fitted_max.

53 { return fAmp_fitted_max; }
double PulseFitWithFunction::getAmpl_parab ( )
inline

Definition at line 50 of file PulseFitWithFunction.h.

References amp_parab.

50 { return amp_parab; }
double PulseFitWithFunction::getMax_parab ( )
inline

Definition at line 56 of file PulseFitWithFunction.h.

References amp_max.

56 { return amp_max; }
int PulseFitWithFunction::getSampMax_parab ( )
inline

Definition at line 57 of file PulseFitWithFunction.h.

References imax.

57 { return imax; }
double PulseFitWithFunction::getTime ( )
inline

Definition at line 54 of file PulseFitWithFunction.h.

References fTim_fitted_max.

54 { return fTim_fitted_max; }
double PulseFitWithFunction::getTime_parab ( )
inline

Definition at line 51 of file PulseFitWithFunction.h.

References tim_parab.

51 { return tim_parab; }
void PulseFitWithFunction::init ( int  n_samples,
int  samplb,
int  sampla,
int  niter,
double  alfa,
double  beta 
)
virtual

Definition at line 43 of file PulseFitWithFunction.cc.

References beta, fAlpha_beam, fAlpha_laser, fBeta_beam, fBeta_laser, fNb_iter, fNsamples, fNum_samp_after_max, fNum_samp_bef_max, and mathSSE::return().

44 {
45  //printf("\n");
46  //printf(" =========================================================\n");
47  //printf(" == Initialising the function fit method ==\n");
48  //printf(" == PulseFitWithFunction::init ==\n");
49  //printf(" == ==\n");
50 
51 
52  fNsamples = n_samples ;
53  fAlpha_laser = alfa;
54  fBeta_laser = beta ;
55  fAlpha_beam = 0.98 ;
56  fBeta_beam = 2.04 ;
57  fNb_iter = niter ;
58  fNum_samp_bef_max = samplb ;
59  fNum_samp_after_max = sampla ;
60  //printf(" == # samples used = %3d ==\n",fNsamples);
61  //printf(" == #sample before max= %1d and #sample after maximum= %1d ==\n",fNum_samp_bef_max,fNum_samp_after_max);
62  //printf(" == alpha= %5.4f beta= %5.4f ==\n",fAlpha_laser,fBeta_laser);
63  //printf(" =========================================================\n\n");
64  return ;
65  }
const double beta
return((rh^lh)&mask)

Member Data Documentation

double PulseFitWithFunction::amp_max
private

Definition at line 61 of file PulseFitWithFunction.h.

Referenced by doFit(), and getMax_parab().

double PulseFitWithFunction::amp_parab
private

Definition at line 61 of file PulseFitWithFunction.h.

Referenced by doFit(), and getAmpl_parab().

double PulseFitWithFunction::fAlpha
private

Definition at line 70 of file PulseFitWithFunction.h.

Referenced by Electronic_shape(), and Fit_electronic().

double PulseFitWithFunction::fAlpha_beam
private

Definition at line 68 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fAlpha_laser
private

Definition at line 66 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fAmp_fitted_max

Definition at line 44 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and getAmpl().

double PulseFitWithFunction::fBeta
private

Definition at line 71 of file PulseFitWithFunction.h.

Referenced by Electronic_shape(), and Fit_electronic().

double PulseFitWithFunction::fBeta_beam
private

Definition at line 69 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fBeta_laser
private

Definition at line 67 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fFunc_max

Definition at line 42 of file PulseFitWithFunction.h.

Referenced by doFit(), Electronic_shape(), and Fit_electronic().

int PulseFitWithFunction::fNb_iter
private

Definition at line 72 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

int PulseFitWithFunction::fNsamples
private

Definition at line 64 of file PulseFitWithFunction.h.

Referenced by doFit(), init(), and PulseFitWithFunction().

int PulseFitWithFunction::fNum_samp_after_max
private

Definition at line 74 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), init(), and PulseFitWithFunction().

int PulseFitWithFunction::fNum_samp_bef_max
private

Definition at line 73 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), init(), and PulseFitWithFunction().

int PulseFitWithFunction::fNumber_samp_max

Definition at line 47 of file PulseFitWithFunction.h.

Referenced by doFit(), and Fit_electronic().

double PulseFitWithFunction::fSigma_ped

Definition at line 48 of file PulseFitWithFunction.h.

Referenced by Fit_electronic().

double PulseFitWithFunction::fTim_fitted_max

Definition at line 45 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and getTime().

double PulseFitWithFunction::fTim_max

Definition at line 43 of file PulseFitWithFunction.h.

Referenced by doFit(), Electronic_shape(), and Fit_electronic().

double PulseFitWithFunction::fValue_tim_max

Definition at line 46 of file PulseFitWithFunction.h.

Referenced by doFit(), and Fit_electronic().

int PulseFitWithFunction::imax
private

Definition at line 62 of file PulseFitWithFunction.h.

Referenced by doFit(), Fit_parab(), and getSampMax_parab().

double PulseFitWithFunction::tim_parab
private

Definition at line 61 of file PulseFitWithFunction.h.

Referenced by doFit(), and getTime_parab().