CMS 3D CMS Logo

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

PulseFitWithFunction::~PulseFitWithFunction ( )
override

Definition at line 33 of file PulseFitWithFunction.cc.

33 {}

Member Function Documentation

◆ doFit()

double PulseFitWithFunction::doFit ( double *  adc)
virtual

Definition at line 60 of file PulseFitWithFunction.cc.

References gpuClustering::adc, amp_max, amp_parab, isoTrack_cff::chi2, fFunc_max, Fit_electronic(), Fit_parab(), fNsamples, fNumber_samp_max, fTim_max, fValue_tim_max, imax, createfilelist::int, 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

◆ Electronic_shape()

double PulseFitWithFunction::Electronic_shape ( double  tim)
private

Definition at line 210 of file PulseFitWithFunction.cc.

References dt, fAlpha, fBeta, fFunc_max, fTim_max, and HPSPFTaus_cff::variable.

Referenced by Fit_electronic().

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

◆ Fit_electronic()

double PulseFitWithFunction::Fit_electronic ( int  data,
double *  adc_to_fit,
double  sigmas_sample 
)
private

Definition at line 103 of file PulseFitWithFunction.cc.

References isoTrack_cff::chi2, data, dumpMFGeometry_cfg::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, fTim_fitted_max, fTim_max, EcalMonitorTask_cff::func, fValue_tim_max, mps_fire::i, createfilelist::int, HPSPFTaus_cff::variable, ppsModifySingularModes_cfi::z1, and ppsModifySingularModes_cfi::z2.

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.;
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 
135  double func, delta;
136  // Loop on iterations
137  for (int iter = 0; iter < fNb_iter; iter++) {
138  // initialization inside iteration loop !
139  chi2 = 0.;
140  double d11 = 0.;
141  double d12 = 0.;
142  double d22 = 0.;
143  double z1 = 0.;
144  double z2 = 0.;
145  fFunc_max += variation_func_max;
146  fTim_max += variation_tim_max;
147  int nsamp_used = 0;
148  //
149 
150  // Then we loop on samples to be fitted
151 
152  for (int i = num_fit_min; i < num_fit_max + 1; i++) {
153  // calculate function to be fitted
154 
155  func = Electronic_shape((double)i);
156 
157  // then calculate derivatives of function to be fitted
158  double dt = (double)i - fTim_max;
159  double alpha_beta = fAlpha * fBeta;
160 
161  if (dt > -alpha_beta) {
162  double dt_sur_beta = dt / fBeta;
163 
164  double variable = (double)1. + dt / alpha_beta;
165  double expo = TMath::Exp(-dt_sur_beta);
166 
167  double puissance = TMath::Power(variable, fAlpha);
168  d_alpha = un_sur_sigma * puissance * expo;
169  d_beta = fFunc_max * d_alpha * dt_sur_beta / (alpha_beta * variable);
170  } else {
171  continue;
172  }
173 
174  nsamp_used++; // number of samples used inside the fit
175  // compute matrix elements D (symetric --> d12 = d21 )
176  d11 += d_alpha * d_alpha;
177  d12 += d_alpha * d_beta;
178  d22 += d_beta * d_beta;
179  // compute delta
180  delta = (adc_to_fit[i] - func) * un_sur_sigma;
181  // compute vector elements Z
182  z1 += delta * d_alpha;
183  z2 += delta * d_beta;
184  chi2 += delta * delta;
185  } // end of loop on samples
186  double denom = d11 * d22 - d12 * d12;
187  if (denom == 0.) {
188  //printf( "attention denom = 0 signal pas fitte \n") ;
189  return 101;
190  }
191  if (nsamp_used < 3) {
192  //printf( "Attention nsamp = %d ---> no function fit provided \n",nsamp_used) ;
193  return 102;
194  }
195  // compute variations of parameters fAmp_max and fTim_max
196  variation_func_max = (z1 * d22 - z2 * d12) / denom;
197  variation_tim_max = (-z1 * d12 + z2 * d11) / denom;
198  chi2 = chi2 / ((double)nsamp_used - 2.);
199  } // end of loop on iterations
200  // results of the fit are calculated
201  fAmp_fitted_max = fFunc_max + variation_func_max;
202  fTim_fitted_max = fTim_max + variation_tim_max;
203  //
204  return chi2;
205 }
float dt
Definition: AMPTWrapper.h:136
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80

◆ Fit_parab()

void PulseFitWithFunction::Fit_parab ( double *  ,
int  ,
int  ,
double *   
)
private

Definition at line 227 of file PulseFitWithFunction.cc.

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

Referenced by doFit().

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

◆ getAmpl()

double PulseFitWithFunction::getAmpl ( )
inline

◆ getAmpl_parab()

double PulseFitWithFunction::getAmpl_parab ( )
inline

Definition at line 49 of file PulseFitWithFunction.h.

References amp_parab.

49 { return amp_parab; }

◆ getMax_parab()

double PulseFitWithFunction::getMax_parab ( )
inline

Definition at line 55 of file PulseFitWithFunction.h.

References amp_max.

55 { return amp_max; }

◆ getSampMax_parab()

int PulseFitWithFunction::getSampMax_parab ( )
inline

Definition at line 56 of file PulseFitWithFunction.h.

References imax.

56 { return imax; }

◆ getTime()

double PulseFitWithFunction::getTime ( )
inline

◆ getTime_parab()

double PulseFitWithFunction::getTime_parab ( )
inline

Definition at line 50 of file PulseFitWithFunction.h.

References tim_parab.

50 { return tim_parab; }

◆ init()

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_2024v14_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

◆ amp_max

double PulseFitWithFunction::amp_max
private

Definition at line 59 of file PulseFitWithFunction.h.

Referenced by doFit(), and getMax_parab().

◆ amp_parab

double PulseFitWithFunction::amp_parab
private

Definition at line 59 of file PulseFitWithFunction.h.

Referenced by doFit(), and getAmpl_parab().

◆ fAlpha

double PulseFitWithFunction::fAlpha
private

Definition at line 68 of file PulseFitWithFunction.h.

Referenced by Electronic_shape(), and Fit_electronic().

◆ fAlpha_beam

double PulseFitWithFunction::fAlpha_beam
private

Definition at line 66 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

◆ fAlpha_laser

double PulseFitWithFunction::fAlpha_laser
private

Definition at line 64 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

◆ fAmp_fitted_max

double PulseFitWithFunction::fAmp_fitted_max

Definition at line 43 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and getAmpl().

◆ fBeta

double PulseFitWithFunction::fBeta
private

Definition at line 69 of file PulseFitWithFunction.h.

Referenced by Electronic_shape(), and Fit_electronic().

◆ fBeta_beam

double PulseFitWithFunction::fBeta_beam
private

Definition at line 67 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

◆ fBeta_laser

double PulseFitWithFunction::fBeta_laser
private

Definition at line 65 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

◆ fFunc_max

double PulseFitWithFunction::fFunc_max

Definition at line 41 of file PulseFitWithFunction.h.

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

◆ fNb_iter

int PulseFitWithFunction::fNb_iter
private

Definition at line 70 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and init().

◆ fNsamples

int PulseFitWithFunction::fNsamples
private

Definition at line 62 of file PulseFitWithFunction.h.

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

◆ fNum_samp_after_max

int PulseFitWithFunction::fNum_samp_after_max
private

Definition at line 72 of file PulseFitWithFunction.h.

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

◆ fNum_samp_bef_max

int PulseFitWithFunction::fNum_samp_bef_max
private

Definition at line 71 of file PulseFitWithFunction.h.

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

◆ fNumber_samp_max

int PulseFitWithFunction::fNumber_samp_max

Definition at line 46 of file PulseFitWithFunction.h.

Referenced by doFit(), and Fit_electronic().

◆ fSigma_ped

double PulseFitWithFunction::fSigma_ped

Definition at line 47 of file PulseFitWithFunction.h.

◆ fTim_fitted_max

double PulseFitWithFunction::fTim_fitted_max

Definition at line 44 of file PulseFitWithFunction.h.

Referenced by Fit_electronic(), and getTime().

◆ fTim_max

double PulseFitWithFunction::fTim_max

Definition at line 42 of file PulseFitWithFunction.h.

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

◆ fValue_tim_max

double PulseFitWithFunction::fValue_tim_max

Definition at line 45 of file PulseFitWithFunction.h.

Referenced by doFit(), and Fit_electronic().

◆ imax

int PulseFitWithFunction::imax
private

Definition at line 60 of file PulseFitWithFunction.h.

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

◆ tim_parab

double PulseFitWithFunction::tim_parab
private

Definition at line 59 of file PulseFitWithFunction.h.

Referenced by doFit(), and getTime_parab().