9 #include <top/calibration/TOPCommonT0LLAlgorithm.h>
10 #include <top/dbobjects/TOPCalCommonT0.h>
11 #include <top/utilities/Chi2MinimumFinder1D.h>
32 TOPCommonT0LLAlgorithm::TOPCommonT0LLAlgorithm():
36 "with neg. log likelihood minimization (method LL)");
44 auto h1 = getObjectPtr<TH1F>(
"tracks_per_set");
46 B2ERROR(
"TOPCommonT0LLAlgorithm: histogram 'tracks_per_set' not found");
49 unsigned numSets = h1->GetNbinsX();
51 vector<Chi2MinimumFinder1D> finders;
52 for (
unsigned set = 0; set < numSets; set++) {
53 string name =
"chi2_set" + to_string(set);
54 auto h = getObjectPtr<TH1D>(name);
58 if (finders.size() != numSets) {
59 B2ERROR(
"TOPCommonT0LLAlgorithm: got number of chi2 scans not as expected"
60 <<
LogVar(
"expected", numSets)
61 <<
LogVar(
"found", finders.size()));
67 auto h4 = getObjectPtr<TH1F>(
"offset");
69 B2ERROR(
"TOPCommonT0LLAlgorithm: histogram 'offset' not found");
72 double bunchTimeSep = h4->GetXaxis()->GetXmax() - h4->GetXaxis()->GetXmin();
77 string expNo = to_string(expRun[0].first);
78 while (expNo.length() < 4) expNo.insert(0,
"0");
79 string runNo = to_string(expRun[0].second);
80 while (runNo.length() < 5) runNo.insert(0,
"0");
81 string outputFileName =
"commonT0-e" + expNo +
"-r" + runNo +
".root";
82 auto* file = TFile::Open(outputFileName.c_str(),
"recreate");
84 auto* tree =
new TTree(
"tree",
"common T0 calibration results");
85 tree->Branch<
int>(
"expNum", &
m_expNo);
86 tree->Branch<
int>(
"runNum", &
m_runNo);
89 tree->Branch<
float>(
"offset", &
m_offset);
102 auto h_pulls =
new TH1F(
"pulls",
"Pulls of statistically independent results",
104 h_pulls->SetXTitle(
"pulls");
105 std::vector<double> pos, err;
106 for (
auto& finder : finders) {
107 const auto& minimum = finder.getMinimum();
108 if (not minimum.valid)
continue;
109 pos.push_back(minimum.position);
110 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]);
118 double scaleError = 1;
119 if (h_pulls->GetEntries() > 1) scaleError = h_pulls->GetRMS();
123 auto finder = finders[0];
124 for (
unsigned i = 1; i < numSets; i++) {
125 finder.add(finders[i]);
128 auto h_commonT0 =
new TH1F(
"commonT0",
"Common T0", 1, 0, 1);
129 h_commonT0->SetYTitle(
"common T0 [ns]");
131 const auto& minimum = finder.getMinimum();
137 h_commonT0->SetBinContent(1,
m_offset);
153 auto h = finder.getHistogram(
"chi2",
"chi2 scan; t0 [ns]; -2 logL");
156 auto h2 = getObjectPtr<TH1F>(
"numHits");
158 auto h3 = getObjectPtr<TH2F>(
"timeHits");
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)
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
Common T0 calibration constant.
Minimum finder using tabulated chi^2 values in one dimension.
float m_offsetError
error on fitted offset
float m_offset
wrap-around of fitted offset (= common T0)
int m_runLast
last run number
int m_expNo
experiment number
virtual EResult calibrate() final
algorithm implementation
int m_runNo
first run number
float m_errorScaling
factor used for scaling the error
int m_numTracks
number of tracks used
int m_numEvents
number of events used
int m_fitStatus
fit status (0 = OK)
double m_minError
minimal commonT0 uncertainty [ns] to declare c_OK
float m_fittedOffset
fitted offset
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.