12 #include <top/calibration/TOPPulseHeightAlgorithm.h>
14 #include <TDirectory.h>
29 TOPPulseHeightAlgorithm::TOPPulseHeightAlgorithm():
32 setDescription(
"Calibration algorithm for pulse-height and threshold efficiency calibration");
42 string expNo = to_string(expRun[0].first);
43 while (expNo.length() < 4) expNo.insert(0,
"0");
44 string runNo = to_string(expRun[0].second);
45 while (runNo.length() < 5) runNo.insert(0,
"0");
46 string outputFileName =
"pulseHeight-e" + expNo +
"-r" + runNo +
".root";
47 m_file = TFile::Open(outputFileName.c_str(),
"recreate");
49 m_tree =
new TTree(
"tree",
"pulse-height calibration results");
69 auto h1a = getObjectPtr<TH1F>(
"time");
70 if (h1a) h1a->Write();
71 auto h1b = getObjectPtr<TH1F>(
"time_sel");
72 if (h1b) h1b->Write();
73 auto h2a = getObjectPtr<TH2F>(
"ph_vs_width");
74 if (h2a) h2a->Write();
75 auto h2b = getObjectPtr<TH2F>(
"ph_vs_width_sel");
76 if (h2b) h2b->Write();
85 TDirectory* oldDir = gDirectory;
87 for (
int slot = 1; slot <= 16; slot++) {
89 string name =
"ph_slot_" + to_string(slot);
90 auto h = getObjectPtr<TH2F>(name);
93 name =
"slot_" + to_string(slot);
94 oldDir->mkdir(name.c_str())->cd();
98 B2INFO(
"slot " << slot <<
": " << n <<
"/512 channels successfully fitted");
128 for (
int ch = 0; ch < h2d->GetNbinsX(); ch++) {
130 string chan = to_string(ch);
131 while (chan.length() < 3) chan.insert(0,
"0");
132 string name =
"chan_" + chan;
133 auto* h = h2d->ProjectionY(name.c_str(), ch + 1, ch + 1);
134 string title =
"slot " + to_string(
m_slot) +
" channel " + to_string(ch);
135 h->SetTitle(title.c_str());
139 if (status == 0 and
m_good) {
155 double xmin = h->GetXaxis()->GetXmin();
156 double xmax = h->GetXaxis()->GetXmax();
158 auto* func =
new TF1(
"func",
"[0]*x/[1]*exp(-pow(x/[1],[2]))", xmin, xmax);
164 func->SetParameter(1, x0);
165 func->SetParameter(2, p2);
167 int status = h->Fit(func,
"LRSQ",
"",
m_xmin, xmax);
169 m_x0 = func->GetParameter(1);
171 m_p2 = func->GetParameter(2);
172 m_x0err = func->GetParError(1);
174 m_p2err = func->GetParError(2);
175 m_chi2 = func->GetChisquare();
191 m_ndf = -func->GetNumberFreeParameters();
192 for (
int i = 0; i < h->GetNbinsX(); i++) {
193 double x = h->GetBinCenter(i + 1);
195 fabove += func->Eval(x);
196 count += h->GetBinContent(i);
197 if (h->GetBinContent(i) > 0)
m_ndf++;
199 fbelow += func->Eval(x);
202 double integral = (fbelow + fabove) * count / fabove;
203 return h->GetSumOfWeights() / integral;