12 #include <top/calibration/TOPModuleT0LLAlgorithm.h>
13 #include <top/dbobjects/TOPCalModuleT0.h>
14 #include <top/utilities/Chi2MinimumFinder1D.h>
34 TOPModuleT0LLAlgorithm::TOPModuleT0LLAlgorithm():
44 auto h1 = getObjectPtr<TH2F>(
"tracks_per_slot");
46 B2ERROR(
"TOPModuleT0LLAlgorithm: histogram 'tracks_per_slot' not found");
49 unsigned numModules = h1->GetNbinsX();
50 unsigned numSets = h1->GetNbinsY();
55 string expNo = to_string(expRun[0].first);
56 while (expNo.length() < 4) expNo.insert(0,
"0");
57 string runNo = to_string(expRun[0].second);
58 while (runNo.length() < 5) runNo.insert(0,
"0");
59 string outputFileName =
"moduleT0_final-e" + expNo +
"-r" + runNo +
".root";
60 auto* file = TFile::Open(outputFileName.c_str(),
"recreate");
65 auto h2 = getObjectPtr<TH1F>(
"numHits");
67 auto h3 = getObjectPtr<TH2F>(
"timeHits");
69 auto h4 = getObjectPtr<TH1F>(
"offset");
74 auto h_pulls =
new TH1F(
"pulls",
"Pulls of statistically independent results",
76 h_pulls->SetXTitle(
"pulls");
80 std::vector<double> T0(numModules, 0);
81 std::vector<double> errT0(numModules, 0);
86 for (
unsigned slot = 1; slot <= numModules; slot++) {
89 std::vector<double> pos, err;
92 for (
unsigned set = 0; set < numSets; set++) {
94 if (h1->GetBinContent(slot, set + 1) == 0)
continue;
96 string name =
"chi2_set" + to_string(set) +
"_slot" + to_string(slot);
97 auto h = getObjectPtr<TH1D>(name);
99 B2ERROR(
"TOPModuleT0LLAlgorithm: histogram '" << name <<
"' not found");
104 slotFinder = setFinder;
106 slotFinder.
add(setFinder);
109 if (not minimum.valid)
continue;
110 pos.push_back(minimum.position);
111 err.push_back(minimum.error);
115 for (
unsigned i = 0; i < pos.size(); i++) {
116 for (
unsigned j = i + 1; j < pos.size(); j++) {
117 double pull = (pos[i] - pos[j]) / sqrt(err[i] * err[i] + err[j] * err[j]);
123 const auto& minimum = slotFinder.
getMinimum();
125 T0[slot - 1] = minimum.position;
126 errT0[slot - 1] = minimum.error;
128 B2ERROR(
"TOPModuleT0Algorithm: no minimum found for slot " << slot);
133 string name =
"chi2_slot_" + to_string(slot);
134 string title =
"chi2 scan, slot " + to_string(slot) +
"; t0 [ns]; -2 logL";
141 if (h_pulls->GetEntries() > 1) {
142 double scaleError = h_pulls->GetRMS();
143 for (
auto& err : errT0) err *= scaleError;
148 auto* h_moduleT0 =
new TH1F(
"moduleT0",
"Module T0", 16, 0.5, 16.5);
149 h_moduleT0->SetXTitle(
"slot number");
150 h_moduleT0->SetYTitle(
"module T0 [ns]");
151 for (
unsigned i = 0; i < T0.size(); i++) {
152 h_moduleT0->SetBinContent(i + 1, T0[i]);
153 h_moduleT0->SetBinError(i + 1, errT0[i]);
164 for (
auto err : errT0) {
171 for (
unsigned i = 0; i < T0.size(); i++) {
172 moduleT0->setT0(i + 1, T0[i], errT0[i]);
174 moduleT0->suppressAverage();