38 void PulseFitWithShape::init(
int n_samples,
int samplb,
int sampla,
int niter,
int n_samplesShape,
const std::vector<double>& shape,
double nois)
49 std::cout<<
"PulseFitWithShape::init: Error! Configuration samples in fit greater than total number of samples!" << std::endl;
72 if(cova==0) useCova=
false;
119 if(is < fNsamplesShape-2)
131 double a2=(sq3+sq1)/2.0-sq2;
132 double a1=sq2-sq1+a2*(1-2*ims);
136 if(a2!=0) t_ims=-a1/(2.0*a2);
148 for(
int is=0; is<nsamplef; is++){
150 if(adc[is+nsampleo] > qm){
158 if(im >= nsamplef+nsampleo) im=nsampleo+nsamplef-1;
162 double y2=(q1+q3)/2.-q2;
163 double y1=q2-q1+y2*(1-2*im);
164 double y0=q2-y1*(double)im-y2*(
double)(im*im);
166 xpar[0]=y0+y1*tm+y2*tm*tm;
167 xpar[2]=(double)ims/25.-tm;
170 double chi2old=999999.;
175 if(qm <= 5*noise)nloop=1;
181 while(std::fabs(chi2old-chi2) > 0.1 && iloop < nloop)
196 for(
int is=0; is<nsfit; is++)
201 double t1=(double)iis+xpar[2];
205 if(ibin1 < 0) ibin1=0;
207 double amp1,amp11,amp12,der1,der11,der12;
209 if(ibin1 <= fNsamplesShape-2){
212 double xfrac=xbin-ibin1;
215 amp1=(1.-xfrac)*amp11+xfrac*amp12;
218 der1=(1.-xfrac)*der11+xfrac*der12;
223 (xbin-double(fNsamplesShape-1))/25.;
224 der1=
dshape[fNsamplesShape-1];
228 for(
int js=0; js<nsfit; js++)
233 t1=(double)jjs+xpar[2];
236 if(ibin1 < 0) ibin1=0;
237 if(ibin1 > fNsamplesShape-2)ibin1=fNsamplesShape-2;
239 double xfrac=xbin-ibin1;
242 double amp2=(1.-xfrac)*amp11+xfrac*amp12;
245 double der2=(1.-xfrac)*der11+xfrac*der12;
246 c=c+cova[js*fNsamples+is];
247 y1=y1+adc[iis]*cova[js*fNsamples+is];
248 s1=s1+amp1*cova[js*fNsamples+is];
249 s2=s2+amp1*amp2*cova[js*fNsamples+is];
250 ys1=ys1+adc[iis]*amp2*cova[js*fNsamples+is];
251 sp1=sp1+der1*cova[is*fNsamples+js];
252 sp2=sp2+der1*der2*cova[js*fNsamples+is];
253 ssp=ssp+amp1*der2*cova[js*fNsamples+is];
254 ysp=ysp+adc[iis]*der2*cova[js*fNsamples+is];
261 ys1=ys1+amp1*adc[iis];
265 ysp=ysp+der1*adc[iis];
268 xpar[0]=(ysp*ssp-ys1*sp2)/(ssp*ssp-s2*sp2);
269 xpar[2]+=(ysp/xpar[0]/sp2-ssp/sp2);
271 for(
int is=0; is<nsfit; is++){
275 double t1=(double)iis+xpar[2];
278 if(ibin1 < 0) ibin1=0;
280 if(ibin1 < 0) ibin1=0;
281 if(ibin1 > fNsamplesShape-2)ibin1=fNsamplesShape-2;
283 double xfrac=xbin-ibin1;
284 double amp11=xpar[0]*
pshape[ibin1];
285 double amp12=xpar[0]*pshape[ibin2];
286 double amp1=xpar[1]+(1.-xfrac)*amp11+xfrac*amp12;
287 resi[iis]=adc[iis]-amp1;
291 for(
int is=0; is<nsfit; is++){
296 for(
int js=0; js<nsfit; js++){
299 chi2+=resi[iis]*resi[jjs]*cova[js*fNsamples+is];
302 }
else chi2+=resi[iis]*resi[iis];
int adc(sample_type sample)
get the ADC sample (12 bits)
std::vector< double > pshape
virtual double doFit(double *, double *cova=0)
virtual ~PulseFitWithShape()
virtual void init(int, int, int, int, int, const std::vector< double > &, double)
std::vector< double > dshape