36 const std::vector<double> &shape,
45 std::cout <<
"PulseFitWithShape::init: Error! Configuration samples in fit greater than total number of samples!"
114 if (is < fNsamplesShape - 2)
122 double sq1 =
pshape[ims - 1];
124 double sq3 =
pshape[ims + 1];
126 double a2 = (sq3 + sq1) / 2.0 - sq2;
127 double a1 = sq2 - sq1 + a2 * (1 - 2 * ims);
131 t_ims = -a1 / (2.0 *
a2);
142 for (
int is = 0; is < nsamplef; is++) {
143 if (adc[is + nsampleo] > qm) {
144 qm = adc[is + nsampleo];
150 if (qm > 5. * noise) {
151 if (im >= nsamplef + nsampleo)
152 im = nsampleo + nsamplef - 1;
153 double q1 = adc[im - 1];
155 double q3 = adc[im + 1];
156 double y2 = (q1 + q3) / 2. - q2;
157 double y1 = q2 - q1 + y2 * (1 - 2 * im);
158 double y0 = q2 - y1 * (double)im - y2 * (
double)(im * im);
160 xpar[0] = y0 + y1 * tm + y2 * tm * tm;
161 xpar[2] = (double)ims / 25. - tm;
164 double chi2old = 999999.;
166 int nsfit = nsamplef;
172 std::vector<double> resi(fNsamples, 0.0);
174 while (std::fabs(chi2old - chi2) > 0.1 && iloop < nloop) {
188 for (
int is = 0; is < nsfit; is++) {
192 double t1 = (double)iis + xpar[2];
193 double xbin = t1 * 25.;
194 int ibin1 = (int)xbin;
199 double amp1, amp11, amp12, der1, der11, der12;
201 if (ibin1 <= fNsamplesShape - 2) {
203 int ibin2 = ibin1 + 1;
204 double xfrac = xbin - ibin1;
207 amp1 = (1. - xfrac) * amp11 + xfrac * amp12;
210 der1 = (1. - xfrac) * der11 + xfrac * der12;
214 amp1 =
pshape[fNsamplesShape - 1] +
dshape[fNsamplesShape - 1] * (xbin - double(fNsamplesShape - 1)) / 25.;
215 der1 =
dshape[fNsamplesShape - 1];
219 for (
int js = 0; js < nsfit; js++) {
223 t1 = (double)jjs + xpar[2];
228 if (ibin1 > fNsamplesShape - 2)
229 ibin1 = fNsamplesShape - 2;
230 int ibin2 = ibin1 + 1;
231 double xfrac = xbin - ibin1;
234 double amp2 = (1. - xfrac) * amp11 + xfrac * amp12;
237 double der2 = (1. - xfrac) * der11 + xfrac * der12;
238 c = c + cova[js * fNsamples + is];
239 y1 = y1 + adc[iis] * cova[js * fNsamples + is];
240 s1 = s1 + amp1 * cova[js * fNsamples + is];
241 s2 = s2 + amp1 * amp2 * cova[js * fNsamples + is];
242 ys1 = ys1 + adc[iis] * amp2 * cova[js * fNsamples + is];
243 sp1 = sp1 + der1 * cova[is * fNsamples + js];
244 sp2 = sp2 + der1 * der2 * cova[js * fNsamples + is];
245 ssp = ssp + amp1 * der2 * cova[js * fNsamples + is];
246 ysp = ysp + adc[iis] * der2 * cova[js * fNsamples + is];
252 s2 = s2 + amp1 * amp1;
253 ys1 = ys1 + amp1 * adc[iis];
255 sp2 = sp2 + der1 * der1;
256 ssp = ssp + der1 * amp1;
257 ysp = ysp + der1 * adc[iis];
260 xpar[0] = (ysp * ssp - ys1 * sp2) / (ssp * ssp - s2 * sp2);
261 xpar[2] += (ysp / xpar[0] / sp2 - ssp / sp2);
263 for (
int is = 0; is < nsfit; is++) {
267 double t1 = (double)iis + xpar[2];
268 double xbin = t1 * 25.;
269 int ibin1 = (int)xbin;
275 if (ibin1 > fNsamplesShape - 2)
276 ibin1 = fNsamplesShape - 2;
277 int ibin2 = ibin1 + 1;
278 double xfrac = xbin - ibin1;
279 double amp11 = xpar[0] *
pshape[ibin1];
280 double amp12 = xpar[0] * pshape[ibin2];
281 double amp1 = xpar[1] + (1. - xfrac) * amp11 + xfrac * amp12;
282 resi[iis] = adc[iis] - amp1;
286 for (
int is = 0; is < nsfit; is++) {
291 for (
int js = 0; js < nsfit; js++) {
294 chi2 += resi[iis] * resi[jjs] * cova[js * fNsamples + is];
298 chi2 += resi[iis] * resi[iis];
const edm::EventSetup & c
virtual double doFit(double *, double *cova=nullptr)
virtual void init(int, int, int, int, int, const std::vector< double > &, double)
std::vector< double > dshape
std::vector< double > pshape
~PulseFitWithShape() override
uint16_t *__restrict__ uint16_t const *__restrict__ adc