8 #include <Fit/BinData.h>
9 #include <Fit/Chi2FCN.h>
11 #include <Fit/UnBinData.h>
12 #include <HFitInterface.h>
13 #include <Math/WrappedMultiTF1.h>
14 #include <Math/WrappedTF1.h>
15 #include <ROOT/TThreadExecutor.hxx>
16 #include <ROOT/TThreadedObject.hxx>
23 ROOT::TThreadExecutor *
t =
new ROOT::TThreadExecutor(1);
26 Double_t
v1 = par[0] *
h_template->Interpolate(x[0] - par[1]) + par[2];
32 TFile *fin = TFile::Open(templatefile.c_str());
35 h_template =
static_cast<TProfile *
>(fin->Get(
"waveform_template"));
36 m_peakTimeTemp = h_template->GetBinCenter(h_template->GetMaximumBin());
42 int size1 = waveformvector.size();
43 std::vector<std::vector<float>> fitresults;
44 for (
int i = 0;
i < size1;
i++)
46 waveformvector.at(
i).push_back(
i);
54 auto func = [&](std::vector<float> &
v)
56 int size1 =
v.size() - 1;
59 v.push_back(
v.at(1) -
v.at(0));
68 for (
int i = 0;
i < size1;
i++)
70 if (
v.at(
i) > maxheight)
79 pedestal = 0.5 * (
v.at(maxbin - 4) +
v.at(maxbin - 5));
83 pedestal = (
v.at(maxbin - 4));
87 pedestal = 0.5 * (
v.at(size1 - 3) +
v.at(size1 - 2));
93 v.push_back(
v.at(6) -
v.at(0));
100 auto h =
new TH1F(Form(
"h_%d", (
int)
round(
v.at(size1))),
"", size1, -0.5, size1 - 0.5);
101 for (
int i = 0;
i < size1;
i++)
103 h->SetBinContent(
i + 1,
v.at(
i));
104 h->SetBinError(
i + 1, 1);
107 ROOT::Math::WrappedMultiTF1 *fitFunction =
new ROOT::Math::WrappedMultiTF1(*
f, 3);
108 ROOT::Fit::BinData
data(
v.size() - 1, 1);
109 ROOT::Fit::FillData(
data,
h);
110 ROOT::Fit::Chi2Function *EPChi2 =
new ROOT::Fit::Chi2Function(
data, *fitFunction);
111 ROOT::Fit::Fitter *fitter =
new ROOT::Fit::Fitter();
112 fitter->Config().MinimizerOptions().SetMinimizerType(
"GSLMultiFit");
113 double params[] = {
static_cast<double>(maxheight -
pedestal), 0, static_cast<double>(pedestal)};
114 fitter->Config().SetParamsSettings(3, params);
116 fitter->FitFCN(*EPChi2,
nullptr,
data.Size(),
true);
118 double chi2min = fitres.MinFcnValue();
120 for (
int i = 0;
i < 3;
i++)
122 v.push_back(
f->GetParameter(
i));
125 v.push_back(chi2min);
135 t->Foreach(func, chnlvector);
136 int size3 = chnlvector.size();
137 std::vector<std::vector<float>> fit_params;
138 std::vector<float> fit_params_tmp;
139 for (
int i = 0;
i < size3;
i++)
141 std::vector<float> tv = chnlvector.at(
i);
142 int size2 = tv.size();
143 for (
int q = 4; q > 0; q--)
145 fit_params_tmp.push_back(tv.at(size2 - q));
147 fit_params.push_back(fit_params_tmp);
148 fit_params_tmp.clear();
157 double xp[3] = {
x0, x1, x2};
158 double yp[3] = {y0, y1, y2};
159 TSpline3 *sp =
new TSpline3(
"", xp, yp, n,
"b2e2", 0, 0);
160 double X,
Y, B,
C,
D;
173 for (
int i = 0;
i <= 1;
i++)
175 sp->GetCoeff(
i, X, Y, B, C, D);
182 float root = -B / (2 *
C) + X;
183 if (root >= xp[
i] && root <= xp[
i + 1])
185 float yvalue = sp->Eval(root);
197 float root = (-2 * C + sqrt(4 * C * C - 12 * B * D)) / (6 * D) +
X;
198 if (root >= xp[
i] && root <= xp[
i + 1])
200 float yvalue = sp->Eval(root);
207 root = (-2 * C - sqrt(4 * C * C - 12 * B * D)) / (6 * D) +
X;
208 if (root >= xp[
i] && root <= xp[
i + 1])
210 float yvalue = sp->Eval(root);
224 std::vector<std::vector<float>> fit_values;
225 int nchnls = chnlvector.size();
226 for (
int m = 0;
m < nchnls;
m++)
228 std::vector<float>
v = chnlvector.at(
m);
231 double maxy = v.at(0);
251 if (maxx == 0 || maxx == nsamples - 1)
258 FastMax(maxx - 1, maxx, maxx + 1, v.at(maxx - 1), v.at(maxx), v.at(maxx + 1),
time, amp);
262 std::vector<float> val = {amp,
time, ped, 0};
263 fit_values.push_back(val);