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==
nullptr) 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;
176 std::vector<double> resi(fNsamples, 0.0);
178 while(std::fabs(chi2old-chi2) > 0.1 && iloop < nloop)
193 for(
int is=0; is<nsfit; is++)
198 double t1=(double)iis+xpar[2];
202 if(ibin1 < 0) ibin1=0;
204 double amp1,amp11,amp12,der1,der11,der12;
206 if(ibin1 <= fNsamplesShape-2){
209 double xfrac=xbin-ibin1;
212 amp1=(1.-xfrac)*amp11+xfrac*amp12;
215 der1=(1.-xfrac)*der11+xfrac*der12;
220 (xbin-double(fNsamplesShape-1))/25.;
221 der1=
dshape[fNsamplesShape-1];
225 for(
int js=0; js<nsfit; js++)
230 t1=(double)jjs+xpar[2];
233 if(ibin1 < 0) ibin1=0;
234 if(ibin1 > fNsamplesShape-2)ibin1=fNsamplesShape-2;
236 double xfrac=xbin-ibin1;
239 double amp2=(1.-xfrac)*amp11+xfrac*amp12;
242 double der2=(1.-xfrac)*der11+xfrac*der12;
243 c=c+cova[js*fNsamples+is];
244 y1=y1+adc[iis]*cova[js*fNsamples+is];
245 s1=s1+amp1*cova[js*fNsamples+is];
246 s2=s2+amp1*amp2*cova[js*fNsamples+is];
247 ys1=ys1+adc[iis]*amp2*cova[js*fNsamples+is];
248 sp1=sp1+der1*cova[is*fNsamples+js];
249 sp2=sp2+der1*der2*cova[js*fNsamples+is];
250 ssp=ssp+amp1*der2*cova[js*fNsamples+is];
251 ysp=ysp+adc[iis]*der2*cova[js*fNsamples+is];
258 ys1=ys1+amp1*adc[iis];
262 ysp=ysp+der1*adc[iis];
265 xpar[0]=(ysp*ssp-ys1*sp2)/(ssp*ssp-s2*sp2);
266 xpar[2]+=(ysp/xpar[0]/sp2-ssp/sp2);
268 for(
int is=0; is<nsfit; is++){
272 double t1=(double)iis+xpar[2];
275 if(ibin1 < 0) ibin1=0;
277 if(ibin1 < 0) ibin1=0;
278 if(ibin1 > fNsamplesShape-2)ibin1=fNsamplesShape-2;
280 double xfrac=xbin-ibin1;
281 double amp11=xpar[0]*
pshape[ibin1];
282 double amp12=xpar[0]*pshape[ibin2];
283 double amp1=xpar[1]+(1.-xfrac)*amp11+xfrac*amp12;
284 resi[iis]=adc[iis]-amp1;
288 for(
int is=0; is<nsfit; is++){
293 for(
int js=0; js<nsfit; js++){
296 chi2+=resi[iis]*resi[jjs]*cova[js*fNsamples+is];
299 }
else chi2+=resi[iis]*resi[iis];
std::vector< double > pshape
virtual double doFit(double *, double *cova=nullptr)
virtual void init(int, int, int, int, int, const std::vector< double > &, double)
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
std::vector< double > dshape
~PulseFitWithShape() override