10 #include <svd/calibration/SVD3SampleCoGTimeCalibrationAlgorithm.h>
12 #include <svd/dbobjects/SVDCoGCalibrationFunction.h>
13 #include <svd/calibration/SVD3SampleCoGTimeCalibrations.h>
18 #include <framework/logging/Logger.h>
21 #include <TFitResult.h>
26 SVD3SampleCoGTimeCalibrationAlgorithm::SVD3SampleCoGTimeCalibrationAlgorithm(
const std::string& str) :
29 setDescription(
"SVD3SampleCoGTimeCalibration calibration algorithm");
36 gROOT->SetBatch(
true);
38 int ladderOfLayer[4] = {7, 10, 12, 16};
39 int sensorOnLayer[4] = {2, 3, 4, 5};
44 std::unique_ptr<TF1> pol3(
new TF1(
"pol3",
"[0] + [1]*x + [2]*x*x + [3]*x*x*x", -10,
49 while (gSystem->GetPathInfo(Form(
"algorithm_3SampleCoG_output_rev_%d.root", cal_rev), info) == 0)
51 std::unique_ptr<TFile> f(
new TFile(Form(
"algorithm_3SampleCoG_output_rev_%d.root", cal_rev),
"RECREATE"));
53 auto m_tree =
new TTree(Form(
"rev_%d", cal_rev),
"RECREATE");
54 int layer_num, ladder_num, sensor_num, view, ndf;
55 float a, b, c, d, a_err, b_err, c_err, d_err, chi2, p;
56 m_tree->Branch(
"layer", &layer_num,
"layer/I");
57 m_tree->Branch(
"ladder", &ladder_num,
"ladder/I");
58 m_tree->Branch(
"sensor", &sensor_num,
"sensor/I");
59 m_tree->Branch(
"isU", &view,
"isU/I");
60 m_tree->Branch(
"a", &a,
"a/F");
61 m_tree->Branch(
"b", &b,
"b/F");
62 m_tree->Branch(
"c", &c,
"c/F");
63 m_tree->Branch(
"d", &d,
"d/F");
64 m_tree->Branch(
"a_err", &a_err,
"a_err/F");
65 m_tree->Branch(
"b_err", &b_err,
"b_err/F");
66 m_tree->Branch(
"c_err", &c_err,
"c_err/F");
67 m_tree->Branch(
"d_err", &d_err,
"d_err/F");
68 m_tree->Branch(
"chi2", &chi2,
"chi2/F");
69 m_tree->Branch(
"ndf", &ndf,
"ndf/I");
70 m_tree->Branch(
"p", &p,
"p/F");
72 for (
int layer = 0; layer < 4; layer++) {
73 layer_num = layer + 3;
74 for (
int ladder = 0; ladder < (int)ladderOfLayer[layer]; ladder++) {
75 ladder_num = ladder + 1;
76 for (
int sensor = 0; sensor < (int)sensorOnLayer[layer]; sensor++) {
77 sensor_num = sensor + 1;
78 for (view = 1; view > -1; view--) {
82 auto hEventT0vsCoG = getObjectPtr<TH2F>(Form(
"eventT0vsCoG__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
83 auto hEventT0 = getObjectPtr<TH1F>(Form(
"eventT0__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
84 auto hEventT0nosync = getObjectPtr<TH1F>(Form(
"eventT0nosync__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
85 B2INFO(
"Histogram: " << hEventT0vsCoG->GetName() <<
86 " Entries (n. clusters): " << hEventT0vsCoG->GetEntries());
87 if (layer_num == 3 && hEventT0vsCoG->GetEntries() <
m_minEntries) {
88 B2INFO(
"Histogram: " << hEventT0vsCoG->GetName() <<
89 " Entries (n. clusters): " << hEventT0vsCoG->GetEntries() <<
91 B2WARNING(
"Not enough data, adding one run to the collector");
93 gSystem->Unlink(Form(
"algorithm_3SampleCoG_output_rev_%d.root", cal_rev));
96 for (
int i = 1; i <= hEventT0vsCoG->GetNbinsX(); i++) {
97 for (
int j = 1; j <= hEventT0vsCoG->GetNbinsY(); j++) {
98 if (hEventT0vsCoG->GetBinContent(i, j) < max(2,
int(hEventT0vsCoG->GetEntries() * 0.001))) {
99 hEventT0vsCoG->SetBinContent(i, j, 0);
103 TProfile* pfx = hEventT0vsCoG->ProfileX();
104 std::string name =
"pfx_" + std::string(hEventT0vsCoG->GetName());
105 pfx->SetName(name.c_str());
106 TFitResultPtr tfr = pfx->Fit(
"pol3",
"QMRS");
108 pol3->GetParameters(par);
111 timeCal->set_current(1);
113 timeCal->set_pol3parameters(par[0], par[1], par[2], par[3]);
114 payload->set(layer_num, ladder_num, sensor_num,
bool(view), 1, *timeCal);
117 hEventT0vsCoG->Write();
118 hEventT0nosync->Write();
121 a = par[0]; b = par[1]; c = par[2]; d = par[3];
122 a_err = tfr->ParError(0); b_err = tfr->ParError(1); c_err = tfr->ParError(2); d_err = tfr->ParError(3);
145 float meanRawTimeL3V = 0;
147 auto rawTimeL3V = getObjectPtr<TH1F>(
"hRawTimeL3V");
154 meanRawTimeL3V = rawTimeL3V->GetMean();
161 B2INFO(
"Setting start payload boundary to be the first run ("
162 << currentRun.first <<
"," << currentRun.second <<
")");
168 <<
" to " << meanRawTimeL3V <<
". We are requesting a new payload boundary for ("
169 << currentRun.first <<
"," << currentRun.second <<
")");