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 38 of file PulseFitWithFunction.cc.

39 {
40 }

Member Function Documentation

double PulseFitWithFunction::doFit ( double *  adc)
virtual

Definition at line 69 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.

70 {
71  double parout[4]; // amp_max ;
72  //double amp_parab , tim_parab ;
73  double chi2;
74  //int imax ;
75 //
76 // first one has to get starting point first with parabolic fun// //
77  Fit_parab(&adc[0],3,fNsamples,parout) ;
78  amp_parab = parout[0] ;
79  tim_parab = parout[1] ;
80  imax = (int)parout[2] ;
81  amp_max = parout[3] ;
82  //printf("amp_parab= %f tim_parab=%f amp_max=%f imax=%d\n",amp_parab,tim_parab,amp_max,imax);
84 //
85 
86  if(amp_parab < 1.) {
87  tim_parab = (double)imax ;
88  amp_parab = amp_max ;
89  }
90 //
94 
95 // here to fit maximum amplitude and time of arrival ...
96 
97  chi2 = Fit_electronic(0,&adc[0],8.) ;
98  // adc is an array to be filled with samples
99  // 0 is for Laser (1 for electron)
100  // 8 is for sigma of pedestals
101  // which (can be computed)
102 
103 
104  // double amplitude = fAmp_fitted_max ; // amplitude fitted
105  // double time = fTim_fitted_max ; // time fitted
106 
107 
108 
109  return chi2 ; // return amplitude fitted
110 
111 }
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 227 of file PulseFitWithFunction.cc.

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

Referenced by Fit_electronic().

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

Definition at line 117 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, and i.

Referenced by doFit().

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

References dt, imax, gen::k, and hitfit::return.

Referenced by doFit().

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

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

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().