9#include <top/calibration/TOPCommonT0BFAlgorithm.h>
10#include <top/dbobjects/TOPCalCommonT0.h>
31 "with a fit of bunch finder residuals (method BF)");
43 B2ERROR(
"TOPCommonT0BFAlgorithm: no histogram to fit");
47 int numEntries = h->GetSumOfWeights();
49 B2ERROR(
"TOPCommonT0BFAlgorithm: too few entries to fit the histogram");
53 m_bunchTimeSep = h->GetXaxis()->GetXmax() - h->GetXaxis()->GetXmin();
58 string expNo = to_string(expRun[0].first);
59 while (expNo.length() < 4) expNo.insert(0,
"0");
60 string runNo = to_string(expRun[0].second);
61 while (runNo.length() < 5) runNo.insert(0,
"0");
62 string outputFileName =
"commonT0-e" + expNo +
"-r" + runNo +
".root";
63 auto* file = TFile::Open(outputFileName.c_str(),
"recreate");
65 auto* tree =
new TTree(
"tree",
"common T0 calibration results");
66 tree->Branch<
int>(
"expNum", &
m_expNo);
67 tree->Branch<
int>(
"runNum", &
m_runNo);
70 tree->Branch<
float>(
"offset", &
m_offset);
75 tree->Branch<
float>(
"chi2", &
m_chi2);
114 auto h1a = getObjectPtr<TH1F>(
"offset_a");
115 auto h1b = getObjectPtr<TH1F>(
"offset_b");
117 B2ERROR(
"TOPCommonT0BFAlgorithm: histogram 'offset_a' not found");
121 B2ERROR(
"TOPCommonT0BFAlgorithm: histogram 'offset_b' not found");
125 int halfbins = h1a->GetNbinsX() / 2;
126 if (abs(h1a->GetMaximumBin() - halfbins) < abs(h1b->GetMaximumBin() - halfbins)) {
135 double sum = h->GetSumOfWeights();
136 if (sum < 5)
return 5;
137 double maxPosition = h->GetBinCenter(h->GetMaximumBin());
138 double binWidth = h->GetBinWidth(1);
139 double xmin = h->GetXaxis()->GetXmin();
140 double xmax = h->GetXaxis()->GetXmax();
142 auto* func =
new TF1(
"func1g",
143 "[0] + [1]/sqrt(2*pi)/[3]*exp(-0.5*((x-[2])/[3])**2)",
145 func->SetParameter(0, 0);
146 func->SetParameter(1, sum * binWidth);
147 func->SetParameter(2, maxPosition);
150 int status = h->Fit(func,
"LRSQ");
158 m_chi2 = func->GetChisquare() / func->GetNDF();
159 m_integral = func->GetParameter(1) / binWidth;
169 double sum = h->GetSumOfWeights();
170 if (sum < 7)
return 7;
171 double maxPosition = h->GetBinCenter(h->GetMaximumBin());
172 double binWidth = h->GetBinWidth(1);
173 double xmin = h->GetXaxis()->GetXmin();
174 double xmax = h->GetXaxis()->GetXmax();
176 auto* func =
new TF1(
"func2g",
177 "[0] + [1]*((1-[4])/sqrt(2*pi)/[3]*exp(-0.5*((x-[2])/[3])**2)"
178 "+ [4]/sqrt(2*pi)/[5]*exp(-0.5*((x-[2])/[5])**2))",
180 func->SetParameter(0, 0);
181 func->SetParameter(1, sum * binWidth);
182 func->SetParameter(2, maxPosition);
187 int status = h->Fit(func,
"LRSQ");
195 m_chi2 = func->GetChisquare() / func->GetNDF();
196 m_integral = func->GetParameter(1) / binWidth;
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.
Common T0 calibration constant.
int fitDoubleGaus(std::shared_ptr< TH1F > h)
Fit double gaus w/ same mean + constant.
float m_chi2
normalized chi^2
float m_offsetError
error on fitted offset
int m_minEntries
minimal number of histogram entries to perform fit
float m_offset
wrap-around of fitted offset (= common T0)
int m_runLast
last run number
float m_sigmaCore
core gaussian sigma
int m_expNo
experiment number
virtual EResult calibrate() final
algorithm implementation
int m_runNo
first run number
float m_tailFract
tail fraction (set to 0 for single gauss fit)
int m_numEvents
number of all events in the histogram
int m_cutoffEntries
cutoff entries for single/double gaussian fit
double m_sigmaTailInit
tail gaussian sigma [ns]
int m_fitStatus
fit status
double m_minError
minimal commonT0 uncertainty [ns] to declare c_OK
double m_tailFractInit
fraction of tail gaussian
float m_fittedOffset
fitted offset
double m_sigmaCoreInit
core gaussian sigma [ns]
float m_integral
number of fitted signal events
float m_sigmaTail
tail gaussian sigma (set to 0 for single gauss fit)
double m_bunchTimeSep
bunch separation in time [ns]
int fitSingleGaus(std::shared_ptr< TH1F > h)
Fit single gaus + constant.
TOPCommonT0BFAlgorithm()
Constructor.
std::shared_ptr< TH1F > getHistogram()
Returns histogram to be fitted.
Abstract base class for different kinds of events.