CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 ()
 
 ~PulseFitWithFunction () override
 

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

Definition at line 33 of file PulseFitWithFunction.cc.

33 {}

Member Function Documentation

double PulseFitWithFunction::doFit ( double *  adc)
virtual

Definition at line 60 of file PulseFitWithFunction.cc.

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

Referenced by EcalPerEvtLaserAnalyzer::endJob(), and EcalLaserAnalyzer::endJob().

60  {
61  double parout[4]; // amp_max ;
62  //double amp_parab , tim_parab ;
63  double chi2;
64  //int imax ;
65  //
66  // first one has to get starting point first with parabolic fun// //
67  Fit_parab(&adc[0], 3, fNsamples, parout);
68  amp_parab = parout[0];
69  tim_parab = parout[1];
70  imax = (int)parout[2];
71  amp_max = parout[3];
72  //printf("amp_parab= %f tim_parab=%f amp_max=%f imax=%d\n",amp_parab,tim_parab,amp_max,imax);
74  //
75 
76  if (amp_parab < 1.) {
77  tim_parab = (double)imax;
79  }
80  //
84 
85  // here to fit maximum amplitude and time of arrival ...
86 
87  chi2 = Fit_electronic(0, &adc[0], 8.);
88  // adc is an array to be filled with samples
89  // 0 is for Laser (1 for electron)
90  // 8 is for sigma of pedestals
91  // which (can be computed)
92 
93  // double amplitude = fAmp_fitted_max ; // amplitude fitted
94  // double time = fTim_fitted_max ; // time fitted
95 
96  return chi2; // return amplitude fitted
97 }
void Fit_parab(double *, int, int, double *)
double Fit_electronic(int, double *, double)
uint16_t *__restrict__ uint16_t const *__restrict__ adc
double PulseFitWithFunction::Electronic_shape ( double  tim)
private

Definition at line 212 of file PulseFitWithFunction.cc.

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

Referenced by Fit_electronic().

212  {
213  // electronic function (from simulation) to fit ECAL pulse shape
214  double func_electronic, dtsbeta, variable, puiss;
215  double albet = fAlpha * fBeta;
216  if (albet <= 0)
217  return ((Double_t)0.);
218  double dt = tim - fTim_max;
219  if (dt > -albet) {
220  dtsbeta = dt / fBeta;
221  variable = 1. + dt / albet;
222  puiss = TMath::Power(variable, fAlpha);
223  func_electronic = fFunc_max * puiss * TMath::Exp(-dtsbeta);
224  } else
225  func_electronic = 0.;
226  //
227  return func_electronic;
228 }
float dt
Definition: AMPTWrapper.h:136
double PulseFitWithFunction::Fit_electronic ( int  data,
double *  adc_to_fit,
double  sigmas_sample 
)
private

Definition at line 103 of file PulseFitWithFunction.cc.

References HLT_FULL_cff::chi2, CommonMethods::delta(), makePileupJSON::denom, 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, cms::cuda::func, fValue_tim_max, and mps_fire::i.

Referenced by doFit().

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

Definition at line 229 of file PulseFitWithFunction.cc.

References makePileupJSON::denom, dt, imax, and isotrackApplyRegressor::k.

Referenced by doFit().

229  {
230  /* Now we calculate the parabolic adjustement in order to get */
231  /* maximum and time max */
232 
233  double denom, dt, amp1, amp2, amp3;
234  double ampmax = 0.;
235  int imax = 0;
236  int k;
237  /*
238  */
239  for (k = nmin; k < nmax; k++) {
240  //printf("ampl[%d]=%f\n",k,ampl[k]);
241  if (ampl[k] > ampmax) {
242  ampmax = ampl[k];
243  imax = k;
244  }
245  }
246  amp1 = ampl[imax - 1];
247  amp2 = ampl[imax];
248  amp3 = ampl[imax + 1];
249  denom = 2. * amp2 - amp1 - amp3;
250  /* */
251  if (denom > 0.) {
252  dt = 0.5 * (amp3 - amp1) / denom;
253  } else {
254  //printf("denom =%f\n",denom) ;
255  dt = 0.5;
256  }
257  /* */
258  /* ampmax correspond au maximum d'amplitude parabolique et dt */
259  /* decalage en temps par rapport au sample maximum soit k + dt */
260 
261  parout[0] = amp2 + (amp3 - amp1) * dt * 0.25;
262  parout[1] = (double)imax + dt;
263  parout[2] = (double)imax;
264  parout[3] = ampmax;
265  return;
266 }
float dt
Definition: AMPTWrapper.h:136
Quality *__restrict__ uint16_t nmin
double PulseFitWithFunction::getAmpl ( )
inline

Definition at line 52 of file PulseFitWithFunction.h.

References fAmp_fitted_max.

Referenced by EcalPerEvtLaserAnalyzer::endJob(), and EcalLaserAnalyzer::endJob().

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

Definition at line 49 of file PulseFitWithFunction.h.

References amp_parab.

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

Definition at line 55 of file PulseFitWithFunction.h.

References amp_max.

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

Definition at line 56 of file PulseFitWithFunction.h.

References imax.

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

Definition at line 53 of file PulseFitWithFunction.h.

References fTim_fitted_max.

Referenced by EcalPerEvtLaserAnalyzer::endJob(), and EcalLaserAnalyzer::endJob().

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

Definition at line 50 of file PulseFitWithFunction.h.

References tim_parab.

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

Definition at line 37 of file PulseFitWithFunction.cc.

References HLT_FULL_cff::beta, fAlpha_beam, fAlpha_laser, fBeta_beam, fBeta_laser, fNb_iter, fNsamples, fNum_samp_after_max, and fNum_samp_bef_max.

Referenced by EcalPerEvtLaserAnalyzer::endJob(), and EcalLaserAnalyzer::endJob().

37  {
38  //printf("\n");
39  //printf(" =========================================================\n");
40  //printf(" == Initialising the function fit method ==\n");
41  //printf(" == PulseFitWithFunction::init ==\n");
42  //printf(" == ==\n");
43 
44  fNsamples = n_samples;
45  fAlpha_laser = alfa;
46  fBeta_laser = beta;
47  fAlpha_beam = 0.98;
48  fBeta_beam = 2.04;
49  fNb_iter = niter;
50  fNum_samp_bef_max = samplb;
51  fNum_samp_after_max = sampla;
52  //printf(" == # samples used = %3d ==\n",fNsamples);
53  //printf(" == #sample before max= %1d and #sample after maximum= %1d ==\n",fNum_samp_bef_max,fNum_samp_after_max);
54  //printf(" == alpha= %5.4f beta= %5.4f ==\n",fAlpha_laser,fBeta_laser);
55  //printf(" =========================================================\n\n");
56  return;
57 }

Member Data Documentation

double PulseFitWithFunction::amp_max
private

Definition at line 59 of file PulseFitWithFunction.h.

Referenced by doFit(), and getMax_parab().

double PulseFitWithFunction::amp_parab
private

Definition at line 59 of file PulseFitWithFunction.h.

Referenced by doFit(), and getAmpl_parab().

double PulseFitWithFunction::fAlpha
private

Definition at line 68 of file PulseFitWithFunction.h.

Referenced by Electronic_shape(), and Fit_electronic().

double PulseFitWithFunction::fAlpha_beam
private

Definition at line 66 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fAlpha_laser
private

Definition at line 64 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fAmp_fitted_max

Definition at line 43 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and getAmpl().

double PulseFitWithFunction::fBeta
private

Definition at line 69 of file PulseFitWithFunction.h.

Referenced by Electronic_shape(), and Fit_electronic().

double PulseFitWithFunction::fBeta_beam
private

Definition at line 67 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fBeta_laser
private

Definition at line 65 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

double PulseFitWithFunction::fFunc_max

Definition at line 41 of file PulseFitWithFunction.h.

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

int PulseFitWithFunction::fNb_iter
private

Definition at line 70 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

int PulseFitWithFunction::fNsamples
private

Definition at line 62 of file PulseFitWithFunction.h.

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

int PulseFitWithFunction::fNum_samp_after_max
private

Definition at line 72 of file PulseFitWithFunction.h.

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

int PulseFitWithFunction::fNum_samp_bef_max
private

Definition at line 71 of file PulseFitWithFunction.h.

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

int PulseFitWithFunction::fNumber_samp_max

Definition at line 46 of file PulseFitWithFunction.h.

Referenced by doFit(), and Fit_electronic().

double PulseFitWithFunction::fSigma_ped

Definition at line 47 of file PulseFitWithFunction.h.

Referenced by Fit_electronic().

double PulseFitWithFunction::fTim_fitted_max

Definition at line 44 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and getTime().

double PulseFitWithFunction::fTim_max

Definition at line 42 of file PulseFitWithFunction.h.

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

double PulseFitWithFunction::fValue_tim_max

Definition at line 45 of file PulseFitWithFunction.h.

Referenced by doFit(), and Fit_electronic().

int PulseFitWithFunction::imax
private

Definition at line 60 of file PulseFitWithFunction.h.

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

double PulseFitWithFunction::tim_parab
private

Definition at line 59 of file PulseFitWithFunction.h.

Referenced by doFit(), and getTime_parab().