12 #include <top/calibration/TOPCommonT0BFAlgorithm.h>
13 #include <top/dbobjects/TOPCalCommonT0.h>
30 TOPCommonT0BFAlgorithm::TOPCommonT0BFAlgorithm():
34 "with a fit of bunch finder residuals (method BF)");
46 B2ERROR(
"TOPCommonT0BFAlgorithm: no histogram to fit");
50 int numEntries = h->GetSumOfWeights();
52 B2ERROR(
"TOPCommonT0BFAlgorithm: too few entries to fit the histogram");
56 m_bunchTimeSep = h->GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin();
61 string expNo = to_string(expRun[0].first);
62 while (expNo.length() < 4) expNo.insert(0,
"0");
63 string runNo = to_string(expRun[0].second);
64 while (runNo.length() < 5) runNo.insert(0,
"0");
65 string outputFileName =
"commonT0-e" + expNo +
"-r" + runNo +
".root";
66 auto* file = TFile::Open(outputFileName.c_str(),
"recreate");
68 auto* tree =
new TTree(
"tree",
"common T0 calibration results");
69 tree->Branch<
int>(
"expNum", &
m_expNo);
70 tree->Branch<
int>(
"runNum", &
m_runNo);
73 tree->Branch<
float>(
"offset", &
m_offset);
78 tree->Branch<
float>(
"chi2", &
m_chi2);
117 auto h1a = getObjectPtr<TH1F>(
"offset_a");
118 auto h1b = getObjectPtr<TH1F>(
"offset_b");
120 B2ERROR(
"TOPCommonT0BFAlgorithm: histogram 'offset_a' not found");
124 B2ERROR(
"TOPCommonT0BFAlgorithm: histogram 'offset_b' not found");
128 int halfbins = h1a->GetNbinsX() / 2;
129 if (abs(h1a->GetMaximumBin() - halfbins) < abs(h1b->GetMaximumBin() - halfbins)) {
138 double sum = h->GetSumOfWeights();
139 if (sum < 5)
return 5;
140 double maxPosition = h->GetBinCenter(h->GetMaximumBin());
141 double binWidth = h->GetBinWidth(1);
142 double xmin = h->GetXaxis()->GetXmin();
143 double xmax = h->GetXaxis()->GetXmax();
145 auto* func =
new TF1(
"func1g",
146 "[0] + [1]/sqrt(2*pi)/[3]*exp(-0.5*((x-[2])/[3])**2)",
148 func->SetParameter(0, 0);
149 func->SetParameter(1, sum * binWidth);
150 func->SetParameter(2, maxPosition);
153 int status = h->Fit(func,
"LRSQ");
161 m_chi2 = func->GetChisquare() / func->GetNDF();
162 m_integral = func->GetParameter(1) / binWidth;
172 double sum = h->GetSumOfWeights();
173 if (sum < 7)
return 7;
174 double maxPosition = h->GetBinCenter(h->GetMaximumBin());
175 double binWidth = h->GetBinWidth(1);
176 double xmin = h->GetXaxis()->GetXmin();
177 double xmax = h->GetXaxis()->GetXmax();
179 auto* func =
new TF1(
"func2g",
180 "[0] + [1]*((1-[4])/sqrt(2*pi)/[3]*exp(-0.5*((x-[2])/[3])**2)"
181 "+ [4]/sqrt(2*pi)/[5]*exp(-0.5*((x-[2])/[5])**2))",
183 func->SetParameter(0, 0);
184 func->SetParameter(1, sum * binWidth);
185 func->SetParameter(2, maxPosition);
190 int status = h->Fit(func,
"LRSQ");
198 m_chi2 = func->GetChisquare() / func->GetNDF();
199 m_integral = func->GetParameter(1) / binWidth;