12 #include <top/calibration/TOPCommonT0LLAlgorithm.h>
13 #include <top/dbobjects/TOPCalCommonT0.h>
14 #include <top/utilities/Chi2MinimumFinder1D.h>
35 TOPCommonT0LLAlgorithm::TOPCommonT0LLAlgorithm():
39 "with neg. log likelihood minimization (method LL)");
47 auto h1 = getObjectPtr<TH1F>(
"tracks_per_set");
49 B2ERROR(
"TOPCommonT0LLAlgorithm: histogram 'tracks_per_set' not found");
52 unsigned numSets = h1->GetNbinsX();
54 vector<Chi2MinimumFinder1D> finders;
55 for (
unsigned set = 0; set < numSets; set++) {
56 string name =
"chi2_set" + to_string(set);
57 auto h = getObjectPtr<TH1D>(name);
61 if (finders.size() != numSets) {
62 B2ERROR(
"TOPCommonT0LLAlgorithm: got number of chi2 scans not as expected"
63 <<
LogVar(
"expected", numSets)
64 <<
LogVar(
"found", finders.size()));
70 auto h4 = getObjectPtr<TH1F>(
"offset");
72 B2ERROR(
"TOPCommonT0LLAlgorithm: histogram 'offset' not found");
75 double bunchTimeSep = h4->GetXaxis()->GetXmax() - h4->GetXaxis()->GetXmin();
80 string expNo = to_string(expRun[0].first);
81 while (expNo.length() < 4) expNo.insert(0,
"0");
82 string runNo = to_string(expRun[0].second);
83 while (runNo.length() < 5) runNo.insert(0,
"0");
84 string outputFileName =
"commonT0-e" + expNo +
"-r" + runNo +
".root";
85 auto* file = TFile::Open(outputFileName.c_str(),
"recreate");
87 auto* tree =
new TTree(
"tree",
"common T0 calibration results");
88 tree->Branch<
int>(
"expNum", &
m_expNo);
89 tree->Branch<
int>(
"runNum", &
m_runNo);
92 tree->Branch<
float>(
"offset", &
m_offset);
105 auto h_pulls =
new TH1F(
"pulls",
"Pulls of statistically independent results",
107 h_pulls->SetXTitle(
"pulls");
108 std::vector<double> pos, err;
109 for (
auto& finder : finders) {
110 const auto& minimum = finder.getMinimum();
111 if (not minimum.valid)
continue;
112 pos.push_back(minimum.position);
113 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]);
121 double scaleError = 1;
122 if (h_pulls->GetEntries() > 1) scaleError = h_pulls->GetRMS();
126 auto finder = finders[0];
127 for (
unsigned i = 1; i < numSets; i++) {
128 finder.add(finders[i]);
131 auto h_commonT0 =
new TH1F(
"commonT0",
"Common T0", 1, 0, 1);
132 h_commonT0->SetYTitle(
"common T0 [ns]");
134 const auto& minimum = finder.getMinimum();
140 h_commonT0->SetBinContent(1,
m_offset);
156 auto h = finder.getHistogram(
"chi2",
"chi2 scan; t0 [ns]; -2 logL");
159 auto h2 = getObjectPtr<TH1F>(
"numHits");
161 auto h3 = getObjectPtr<TH2F>(
"timeHits");