5 #include <TGraphErrors.h>
95 hPed0 =
new TH1F(name, name, 16384, -0.5, 16383.5);
123 TString name =
"h2Template";
128 name =
"h2Residuals";
176 for (
int isamp = 0; isamp <
nsamples; isamp++)
178 hRawPulse->SetBinContent(isamp + 1, y[isamp]);
179 gRawPulse->SetPoint(isamp, Double_t(isamp), y[isamp]);
200 for (
int isamp = 0; isamp <
nsamples; isamp++)
202 hSubPulse->SetBinContent(isamp + 1, invert * (y[isamp] -
ped0));
204 gSubPulse->SetPoint(isamp, (Double_t) isamp, invert * (y[isamp] -
ped0));
210 void MbdSig::SetXY(
const Float_t*
x,
const Float_t* y,
const int invert)
227 for (
int isamp = 0; isamp <
nsamples; isamp++)
230 hRawPulse->SetBinContent(isamp + 1, y[isamp]);
231 gRawPulse->SetPoint(isamp, x[isamp], y[isamp]);
249 for (
int isamp = 0; isamp <
nsamples; isamp++)
254 hSubPulse->SetBinContent(isamp + 1, invert * (y[isamp] -
ped0));
256 gSubPulse->SetPoint(isamp, x[isamp], invert * (y[isamp] -
ped0));
266 cout <<
"gsub bad " << (uint64_t)
gSubPulse << endl;
274 double step_size = 0.01;
276 for (
double ix = 0; ix <
nsamples; ix += step_size)
278 Double_t val = s3.Eval(ix);
291 for (
int isamp = sampmin; isamp <= sampmax; isamp++)
313 for (
int isamp = 0; isamp <
n; isamp++)
316 if (x >= begin && x <= end)
355 for (
int isamp = minpedsamp; isamp <= maxpedsamp; isamp++)
384 for (
int isamp = 0; isamp <
n; isamp++)
388 if (x >= minpedx && x <= maxpedx)
417 Int_t minsamp = max - presample - nsamps + 1;
418 Int_t maxsamp = max - presample;
432 for (
int isamp = minsamp; isamp <= maxsamp; isamp++)
444 Double_t mean =
hPed0->GetMean();
445 Double_t rms =
hPed0->GetRMS();
447 static int counter = 0;
448 if (
verbose > 0 && counter < 10)
450 cout <<
"CalcEventPed0_PreSamp: ped0stats " << mean <<
"\t" << rms << endl;
465 for (
int isamp = 0; isamp <
n; isamp++)
467 if (y[isamp] > threshold)
469 if (isamp == (n - 1) || y[isamp + 1] > threshold)
482 Double_t dx = x[sample] - x[sample - 1];
483 Double_t
dy = y[sample] - y[sample - 1];
484 Double_t dt1 = y[sample] - threshold;
486 Double_t t0 = x[sample] - dt1 * (dx /
dy);
491 Double_t
MbdSig::dCFD(
const Double_t fraction_threshold)
501 Double_t
ymax = TMath::MaxElement(n, y);
507 Double_t threshold = fraction_threshold *
ymax;
511 for (
int isamp = 0; isamp <
n; isamp++)
513 if (y[isamp] > threshold)
515 if (isamp == (n - 1) || y[isamp + 1] > threshold)
528 Double_t dx = x[sample] - x[sample - 1];
529 Double_t
dy = y[sample] - y[sample - 1];
530 Double_t dt1 = y[sample] - threshold;
532 Double_t t0 = x[sample] - dt1 * (dx /
dy);
544 std::cout <<
"ERROR y == 0" << std::endl;
553 Double_t ymax = TMath::MaxElement(n, y);
569 for (
int ix = 0; ix <
n; ix++)
571 if (x[ix] >= xmin && x[ix] <= xmax)
574 Double_t dx = (x[ix + 1] - x[ix - 1]) / 2.0;
582 void MbdSig::LocMax(Double_t& x_at_max, Double_t& ymax, Double_t xminrange, Double_t xmaxrange)
590 if (xmaxrange <= xminrange)
592 xminrange = -DBL_MAX;
599 for (
int i = 0;
i <
n;
i++)
602 if (x[
i] < xminrange)
606 if (x[
i] > xmaxrange)
619 void MbdSig::LocMin(Double_t& x_at_max, Double_t&
ymin, Double_t xminrange, Double_t xmaxrange)
627 if (xmaxrange <= xminrange)
629 xminrange = -DBL_MAX;
635 for (
int i = 0;
i <
n;
i++)
638 if (x[
i] < xminrange)
642 if (x[
i] > xmaxrange)
661 cout <<
"CH " <<
ch << endl;
662 for (
int isamp = 0; isamp <
nsamples; isamp++)
664 gpulse->GetPoint(isamp, x, y);
665 cout << isamp <<
"\t" << x <<
"\t" << y << endl;
678 if (junk[0] ==
'w' || junk[0] ==
's')
692 Double_t xx = x[0] - par[1];
707 else if (xx > template_endtime)
725 int ilow = TMath::FloorNint(index);
726 int ihigh = TMath::CeilNint(index);
731 cout <<
"ERROR, ilow ihigh " << ilow <<
"\t" << ihigh << endl;
732 cout <<
" " << xx <<
" " << x[0] <<
" " << par[1] << endl;
755 f = par[0] * (y0 + ((y1 - y0) / (x1 - x0)) * (xx - x0));
766 int samp_point =
static_cast<int>(x[0]);
767 Double_t temp_x, temp_y;
768 gRawPulse->GetPoint(samp_point, temp_x, temp_y);
784 cout <<
"Fitting ch " << ch << endl;
797 Double_t x_at_max,
ymax;
801 gSubPulse->GetPoint(xsamp, x_at_max, ymax);
824 cout <<
"FitTemplate " << ch <<
"\t" <<
f_ampl <<
"\t" <<
f_time << endl;
842 std::cout <<
"SHAPE " << ch <<
"\t" <<
template_y.size() << std::endl;
847 std::cout <<
i <<
":\t" << std::endl;
851 std::cout << std::endl;
856 TString name =
"template_fcn";
866 std::cout <<
"SHAPE " << ch << std::endl;