8 #include <svd/calibration/SVDCoGTimeCalibrationAlgorithm.h>
10 #include <svd/dbobjects/SVDCoGCalibrationFunction.h>
11 #include <svd/calibration/SVDCoGTimeCalibrations.h>
16 #include <framework/logging/Logger.h>
19 #include <TFitResult.h>
24 SVDCoGTimeCalibrationAlgorithm::SVDCoGTimeCalibrationAlgorithm(
const std::string& str) :
34 gROOT->SetBatch(
true);
36 int ladderOfLayer[4] = {7, 10, 12, 16};
37 int sensorOnLayer[4] = {2, 3, 4, 5};
42 std::unique_ptr<TF1> pol1(
new TF1(
"pol1",
"[0] + [1]*x", -10, 80));
43 pol1->SetParameters(-40, 0.9);
44 std::unique_ptr<TF1> pol3(
new TF1(
"pol3",
"[0] + [1]*x + [2]*x*x + [3]*x*x*x", -10, 80));
45 pol3->SetParLimits(0, -200, 0);
46 pol3->SetParLimits(1, 0, 10);
47 pol3->SetParLimits(2, -1, 0);
48 pol3->SetParLimits(3, 0, 1);
49 std::unique_ptr<TF1> pol5(
new TF1(
"pol5",
"[0] + [1]*x + [2]*x*x + [3]*x*x*x + [4]*x*x*x*x + [5]*x*x*x*x*x", -100, 100));
50 pol5->SetParameters(-50, 1.5, 0.01, 0.0001, 0.00001, 0.000001);
54 while (gSystem->GetPathInfo(Form(
"algorithm_6SampleCoG_output_rev_%d.root", cal_rev), info) == 0)
56 std::unique_ptr<TFile> f(
new TFile(Form(
"algorithm_6SampleCoG_output_rev_%d.root", cal_rev),
"RECREATE"));
58 auto m_tree =
new TTree(Form(
"rev_%d", cal_rev),
"RECREATE");
59 int layer_num, ladder_num, sensor_num, view, ndf;
60 float a, b, c, d, a_err, b_err, c_err, d_err, chi2, p;
61 m_tree->Branch(
"layer", &layer_num,
"layer/I");
62 m_tree->Branch(
"ladder", &ladder_num,
"ladder/I");
63 m_tree->Branch(
"sensor", &sensor_num,
"sensor/I");
64 m_tree->Branch(
"isU", &view,
"isU/I");
65 m_tree->Branch(
"a", &a,
"a/F");
66 m_tree->Branch(
"b", &b,
"b/F");
67 m_tree->Branch(
"c", &c,
"c/F");
68 m_tree->Branch(
"d", &d,
"d/F");
69 m_tree->Branch(
"a_err", &a_err,
"a_err/F");
70 m_tree->Branch(
"b_err", &b_err,
"b_err/F");
71 m_tree->Branch(
"c_err", &c_err,
"c_err/F");
72 m_tree->Branch(
"d_err", &d_err,
"d_err/F");
73 m_tree->Branch(
"chi2", &chi2,
"chi2/F");
74 m_tree->Branch(
"ndf", &ndf,
"ndf/I");
75 m_tree->Branch(
"p", &p,
"p/F");
77 for (
int layer = 0; layer < 4; layer++) {
78 layer_num = layer + 3;
79 for (
int ladder = 0; ladder < (int)ladderOfLayer[layer]; ladder++) {
80 ladder_num = ladder + 1;
81 for (
int sensor = 0; sensor < (int)sensorOnLayer[layer]; sensor++) {
82 sensor_num = sensor + 1;
83 for (view = 1; view > -1; view--) {
87 auto hEventT0vsCoG = getObjectPtr<TH2F>(Form(
"eventT0vsCoG__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
88 auto hEventT0 = getObjectPtr<TH1F>(Form(
"eventT0__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
89 auto hEventT0nosync = getObjectPtr<TH1F>(Form(
"eventT0nosync__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
90 B2INFO(
"Histogram: " << hEventT0vsCoG->GetName() <<
91 " Entries (n. clusters): " << hEventT0vsCoG->GetEntries());
92 if (layer_num == 3 && hEventT0vsCoG->GetEntries() <
m_minEntries) {
93 B2INFO(
"Histogram: " << hEventT0vsCoG->GetName() <<
94 " Entries (n. clusters): " << hEventT0vsCoG->GetEntries() <<
96 B2WARNING(
"Not enough data, adding one run to the collector");
98 gSystem->Unlink(Form(
"algorithm_6SampleCoG_output_rev_%d.root", cal_rev));
101 for (
int i = 1; i <= hEventT0vsCoG->GetNbinsX(); i++) {
102 for (
int j = 1; j <= hEventT0vsCoG->GetNbinsY(); j++) {
103 if (hEventT0vsCoG->GetBinContent(i, j) < max(2,
int(hEventT0vsCoG->GetEntries() * 0.001))) {
104 hEventT0vsCoG->SetBinContent(i, j, 0);
108 TProfile* pfx = hEventT0vsCoG->ProfileX();
109 std::string name =
"pfx_" + std::string(hEventT0vsCoG->GetName());
110 pfx->SetName(name.c_str());
111 TFitResultPtr tfr = pfx->Fit(
"pol3",
"RQSM");
113 pol3->GetParameters(par);
124 timeCal->set_current(1);
126 timeCal->set_pol3parameters(par[0], par[1], par[2], par[3]);
127 payload->set(layer_num, ladder_num, sensor_num,
bool(view), 1, *timeCal);
130 hEventT0vsCoG->Write();
131 hEventT0nosync->Write();
136 B2FATAL(
"Fit to the histogram failed in SVDCoGTimeCalibrationAlgorithm. "
137 <<
"Check the 2-D histogram to clarify the reason.");
139 a = par[0]; b = par[1]; c = par[2]; d = par[3];
140 a_err = tfr->ParError(0); b_err = tfr->ParError(1); c_err = tfr->ParError(2); d_err = tfr->ParError(3);
164 float meanRawTimeL3V = 0;
166 auto rawTimeL3V = getObjectPtr<TH1F>(
"hRawTimeL3V");
173 meanRawTimeL3V = rawTimeL3V->GetMean();
180 B2INFO(
"Setting start payload boundary to be the first run ("
181 << currentRun.first <<
"," << currentRun.second <<
")");
187 <<
" to " << meanRawTimeL3V <<
". We are requesting a new payload boundary for ("
188 << currentRun.first <<
"," << currentRun.second <<
")");
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.
class to contain the CoG Time calibrations
std::string m_id
Parameter given to set the UniqueID of the payload.
std::optional< float > m_previousRawTimeMeanL3V
CoG time mean of the previous run for V side of layer 3.
float m_minEntries
Set the minimun number of entries required in the histograms of layer 3.
virtual EResult calibrate() override
Run algo on data.
virtual bool isBoundaryRequired(const Calibration::ExpRun ¤tRun) override
If the event T0 changes significantly return true.
float m_allowedTimeShift
Allowed EventT0 shift.
SVDCalibrationsBase< SVDCalibrationsScalar< SVDCoGCalibrationFunction > > t_payload
typedef for the SVDCoGCalibrationFunction payload of all SVD sensors
Abstract base class for different kinds of events.