37 void PulseFitWithShape::init(
int n_samples,
int samplb,
int sampla,
int niter,
int n_samplesShape,
const std::vector<double>& shape,
double nois)
48 std::cout<<
"PulseFitWithShape::init: Error! Configuration samples in fit greater than total number of samples!" << std::endl;
71 if(cova==0) useCova=
false;
118 if(is < fNsamplesShape-2)
130 double a2=(sq3+sq1)/2.0-sq2;
131 double a1=sq2-sq1+a2*(1-2*ims);
135 if(a2!=0) t_ims=-a1/(2.0*a2);
147 for(
int is=0; is<nsamplef; is++){
149 if(adc[is+nsampleo] > qm){
157 if(im >= nsamplef+nsampleo) im=nsampleo+nsamplef-1;
161 double y2=(q1+q3)/2.-q2;
162 double y1=q2-q1+y2*(1-2*im);
163 double y0=q2-y1*(double)im-y2*(
double)(im*im);
165 xpar[0]=y0+y1*tm+y2*tm*tm;
166 xpar[2]=(double)ims/25.-tm;
169 double chi2old=999999.;
174 if(qm <= 5*noise)nloop=1;
180 while(std::fabs(chi2old-chi2) > 0.1 && iloop < nloop)
195 for(
int is=0; is<nsfit; is++)
200 double t1=(double)iis+xpar[2];
204 if(ibin1 < 0) ibin1=0;
206 double amp1,amp11,amp12,der1,der11,der12;
208 if(ibin1 <= fNsamplesShape-2){
211 double xfrac=xbin-ibin1;
214 amp1=(1.-xfrac)*amp11+xfrac*amp12;
217 der1=(1.-xfrac)*der11+xfrac*der12;
222 (xbin-double(fNsamplesShape-1))/25.;
223 der1=
dshape[fNsamplesShape-1];
227 for(
int js=0; js<nsfit; js++)
232 t1=(double)jjs+xpar[2];
235 if(ibin1 < 0) ibin1=0;
236 if(ibin1 > fNsamplesShape-2)ibin1=fNsamplesShape-2;
238 double xfrac=xbin-ibin1;
241 double amp2=(1.-xfrac)*amp11+xfrac*amp12;
244 double der2=(1.-xfrac)*der11+xfrac*der12;
245 c=c+cova[js*fNsamples+is];
246 y1=y1+adc[iis]*cova[js*fNsamples+is];
247 s1=s1+amp1*cova[js*fNsamples+is];
248 s2=s2+amp1*amp2*cova[js*fNsamples+is];
249 ys1=ys1+adc[iis]*amp2*cova[js*fNsamples+is];
250 sp1=sp1+der1*cova[is*fNsamples+js];
251 sp2=sp2+der1*der2*cova[js*fNsamples+is];
252 ssp=ssp+amp1*der2*cova[js*fNsamples+is];
253 ysp=ysp+adc[iis]*der2*cova[js*fNsamples+is];
260 ys1=ys1+amp1*adc[iis];
264 ysp=ysp+der1*adc[iis];
267 xpar[0]=(ysp*ssp-ys1*sp2)/(ssp*ssp-s2*sp2);
268 xpar[2]+=(ysp/xpar[0]/sp2-ssp/sp2);
270 for(
int is=0; is<nsfit; is++){
274 double t1=(double)iis+xpar[2];
277 if(ibin1 < 0) ibin1=0;
279 if(ibin1 < 0) ibin1=0;
280 if(ibin1 > fNsamplesShape-2)ibin1=fNsamplesShape-2;
282 double xfrac=xbin-ibin1;
283 double amp11=xpar[0]*
pshape[ibin1];
284 double amp12=xpar[0]*pshape[ibin2];
285 double amp1=xpar[1]+(1.-xfrac)*amp11+xfrac*amp12;
286 resi[iis]=adc[iis]-amp1;
290 for(
int is=0; is<nsfit; is++){
295 for(
int js=0; js<nsfit; js++){
298 chi2+=resi[iis]*resi[jjs]*cova[js*fNsamples+is];
301 }
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
return(e1-e2)*(e1-e2)+dp *dp