9#include <top/calibration/TOPModuleT0LLAlgorithm.h>
10#include <top/dbobjects/TOPCalModuleT0.h>
11#include <top/utilities/Chi2MinimumFinder1D.h>
41 auto h1 = getObjectPtr<TH2F>(
"tracks_per_slot");
43 B2ERROR(
"TOPModuleT0LLAlgorithm: histogram 'tracks_per_slot' not found");
46 unsigned numModules = h1->GetNbinsX();
47 unsigned numSets = h1->GetNbinsY();
52 string expNo = to_string(expRun[0].first);
53 while (expNo.length() < 4) expNo.insert(0,
"0");
54 string runNo = to_string(expRun[0].second);
55 while (runNo.length() < 5) runNo.insert(0,
"0");
56 string outputFileName =
"moduleT0_final-e" + expNo +
"-r" + runNo +
".root";
57 auto* file = TFile::Open(outputFileName.c_str(),
"recreate");
62 auto h2 = getObjectPtr<TH1F>(
"numHits");
64 auto h3 = getObjectPtr<TH2F>(
"timeHits");
66 auto h4 = getObjectPtr<TH1F>(
"offset");
71 auto h_pulls =
new TH1F(
"pulls",
"Pulls of statistically independent results",
73 h_pulls->SetXTitle(
"pulls");
77 std::vector<double> T0(numModules, 0);
78 std::vector<double> errT0(numModules, 0);
83 for (
unsigned slot = 1; slot <= numModules; slot++) {
86 std::vector<double> pos, err;
89 for (
unsigned set = 0; set < numSets; set++) {
91 if (h1->GetBinContent(slot, set + 1) == 0)
continue;
93 string name =
"chi2_set" + to_string(set) +
"_slot" + to_string(slot);
94 auto h = getObjectPtr<TH1D>(name);
96 B2ERROR(
"TOPModuleT0LLAlgorithm: histogram '" << name <<
"' not found");
101 slotFinder = setFinder;
103 slotFinder.
add(setFinder);
106 if (not minimum.valid)
continue;
107 pos.push_back(minimum.position);
108 err.push_back(minimum.error);
112 for (
unsigned i = 0; i < pos.size(); i++) {
113 for (
unsigned j = i + 1; j < pos.size(); j++) {
114 double pull = (pos[i] - pos[j]) /
sqrt(err[i] * err[i] + err[j] * err[j]);
120 const auto& minimum = slotFinder.
getMinimum();
123 errT0[slot - 1] = minimum.error;
125 B2ERROR(
"TOPModuleT0Algorithm: no minimum found for slot " << slot);
130 string name =
"chi2_slot_" + to_string(slot);
131 string title =
"chi2 scan, slot " + to_string(slot) +
"; t0 [ns]; -2 logL";
138 if (h_pulls->GetEntries() > 1) {
139 double scaleError = h_pulls->GetRMS();
140 for (
auto& err : errT0) err *= scaleError;
145 auto* h_moduleT0 =
new TH1F(
"moduleT0",
"Module T0", 16, 0.5, 16.5);
146 h_moduleT0->SetXTitle(
"slot number");
147 h_moduleT0->SetYTitle(
"module T0 [ns]");
148 for (
unsigned i = 0; i < T0.size(); i++) {
149 h_moduleT0->SetBinContent(i + 1, T0[i]);
150 h_moduleT0->SetBinError(i + 1, errT0[i]);
161 for (
auto err : errT0) {
168 for (
unsigned i = 0; i < T0.size(); i++) {
169 moduleT0->setT0(i + 1, T0[i], errT0[i]);
171 moduleT0->suppressAverage();
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
@ c_Failure
Failed =3 in Python.
Module T0 calibration constants for all 16 modules.
Minimum finder using tabulated chi^2 values in one dimension.
TH1F getHistogram(std::string name, std::string title) const
Returns chi^2 packed into 1D histogram.
void add(unsigned i, double chi2)
Add chi^2 value to bin i.
const Minimum & getMinimum()
Returns parabolic minimum.
int getNbins() const
Returns number of bins.
TOPModuleT0LLAlgorithm()
Constructor.
virtual EResult calibrate() final
algorithm implementation
double m_minError
minimal moduleT0 uncertainty [ns] to declare c_OK
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.
double position
position of the minimum