35 gROOT->SetBatch(
true);
40 std::unique_ptr<TF1> pol1(
new TF1(
"pol1",
"[0] + [1]*x", -10, 80));
41 pol1->SetParameters(-40, 0.9);
42 std::unique_ptr<TF1> pol3(
new TF1(
"pol3",
"[0] + [1]*x + [2]*x*x + [3]*x*x*x", -10, 80));
43 pol3->SetParLimits(0, -200, 0);
44 pol3->SetParLimits(1, 0, 10);
45 pol3->SetParLimits(2, -1, 0);
46 pol3->SetParLimits(3, 0, 1);
47 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));
48 pol5->SetParameters(-50, 1.5, 0.01, 0.0001, 0.00001, 0.000001);
52 while (gSystem->GetPathInfo(Form(
"algorithm_6SampleCoG_output_rev_%d.root", cal_rev), info) == 0)
54 std::unique_ptr<TFile> f(
new TFile(Form(
"algorithm_6SampleCoG_output_rev_%d.root", cal_rev),
"RECREATE"));
56 auto m_tree =
new TTree(Form(
"rev_%d", cal_rev),
"RECREATE");
57 int layer_num, ladder_num, sensor_num, view, ndf;
58 float a, b, c, d, a_err, b_err, c_err, d_err, chi2, p;
59 m_tree->Branch(
"layer", &layer_num,
"layer/I");
60 m_tree->Branch(
"ladder", &ladder_num,
"ladder/I");
61 m_tree->Branch(
"sensor", &sensor_num,
"sensor/I");
62 m_tree->Branch(
"isU", &view,
"isU/I");
63 m_tree->Branch(
"a", &a,
"a/F");
64 m_tree->Branch(
"b", &b,
"b/F");
65 m_tree->Branch(
"c", &c,
"c/F");
66 m_tree->Branch(
"d", &d,
"d/F");
67 m_tree->Branch(
"a_err", &a_err,
"a_err/F");
68 m_tree->Branch(
"b_err", &b_err,
"b_err/F");
69 m_tree->Branch(
"c_err", &c_err,
"c_err/F");
70 m_tree->Branch(
"d_err", &d_err,
"d_err/F");
71 m_tree->Branch(
"chi2", &chi2,
"chi2/F");
72 m_tree->Branch(
"ndf", &ndf,
"ndf/I");
73 m_tree->Branch(
"p", &p,
"p/F");
80 for (
int ij = 0; ij < (__hBinToSensorMap__->GetNbinsX()); ij++) {
85 auto binLabel = __hBinToSensorMap__->GetXaxis()->GetBinLabel(ij + 1);
87 std::sscanf(binLabel,
"L%dL%dS%d%c", &layer_num, &ladder_num, &sensor_num, &side);
92 B2INFO(
"Projecting for Sensor: " << binLabel <<
" with Bin Number: " << ij + 1);
94 __hEventT0vsCoG__->GetZaxis()->SetRange(ij + 1, ij + 1);
95 auto hEventT0vsCoG = (TH2D*)__hEventT0vsCoG__->Project3D(
"yxe");
96 auto hEventT0 = (TH1D*)__hEventT0__->ProjectionX(
"hEventT0_tmp", ij + 1, ij + 1);
97 auto hEventT0nosync = (TH1D*)__hEventT0NoSync__->ProjectionX(
"hEventT0NoSync_tmp", ij + 1, ij + 1);
99 hEventT0vsCoG->SetName(Form(
"eventT0vsCoG__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
100 hEventT0->SetName(Form(
"eventT0__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
101 hEventT0nosync->SetName(Form(
"eventT0nosync__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
103 char sidePN = (side ==
'U' ?
'P' :
'N');
104 hEventT0vsCoG->SetTitle(Form(
"EventT0Sync vs rawTime in %d.%d.%d %c/%c", layer_num, ladder_num, sensor_num, side, sidePN));
105 hEventT0->SetTitle(Form(
"EventT0Sync in %d.%d.%d %c/%c", layer_num, ladder_num, sensor_num, side, sidePN));
106 hEventT0nosync->SetTitle(Form(
"EventT0NoSync in %d.%d.%d %c/%c", layer_num, ladder_num, sensor_num, side, sidePN));
108 hEventT0vsCoG->SetDirectory(0);
109 hEventT0->SetDirectory(0);
110 hEventT0nosync->SetDirectory(0);
112 B2INFO(
"Histogram: " << hEventT0vsCoG->GetName() <<
113 " Entries (n. clusters): " << hEventT0vsCoG->GetEntries());
114 if (layer_num == 3 && hEventT0vsCoG->GetEntries() <
m_minEntries) {
115 B2INFO(
"Histogram: " << hEventT0vsCoG->GetName() <<
116 " Entries (n. clusters): " << hEventT0vsCoG->GetEntries() <<
118 B2WARNING(
"Not enough data, adding one run to the collector");
120 gSystem->Unlink(Form(
"algorithm_6SampleCoG_output_rev_%d.root", cal_rev));
123 if (layer_num != 3 && hEventT0vsCoG->GetEntries() <
m_minEntries / 10) {
124 B2INFO(
"Histogram: " << hEventT0vsCoG->GetName() <<
125 " Entries (n. clusters): " << hEventT0vsCoG->GetEntries() <<
127 B2WARNING(
"Not enough data, adding one run to the collector");
129 gSystem->Unlink(Form(
"algorithm_6SampleCoG_output_rev_%d.root", cal_rev));
132 for (
int i = 1; i <= hEventT0vsCoG->GetNbinsX(); i++) {
133 for (
int j = 1; j <= hEventT0vsCoG->GetNbinsY(); j++) {
134 if (hEventT0vsCoG->GetBinContent(i, j) < std::max(2,
int(hEventT0vsCoG->GetEntries() * 0.001))) {
135 hEventT0vsCoG->SetBinContent(i, j, 0);
139 TProfile* pfx = hEventT0vsCoG->ProfileX();
140 std::string name =
"pfx_" + std::string(hEventT0vsCoG->GetName());
141 pfx->SetName(name.c_str());
142 TFitResultPtr tfr = pfx->Fit(
"pol3",
"RQSM");
144 pol3->GetParameters(par);
155 timeCal->set_current(1);
157 timeCal->set_pol3parameters(par[0], par[1], par[2], par[3]);
158 payload->set(layer_num, ladder_num, sensor_num,
bool(view), 1, *timeCal);
161 hEventT0vsCoG->Write();
162 hEventT0nosync->Write();
166 delete hEventT0vsCoG;
168 delete hEventT0nosync;
170 if (tfr.Get() ==
nullptr || (tfr->Status() != 0 && tfr->Status() != 4 && tfr->Status() != 4000)) {
172 B2FATAL(
"Fit to the histogram failed in SVDCoGTimeCalibrationAlgorithm. "
173 <<
"Check the 2-D histogram to clarify the reason.");
175 a = par[0]; b = par[1]; c = par[2]; d = par[3];
176 a_err = tfr->ParError(0); b_err = tfr->ParError(1); c_err = tfr->ParError(2); d_err = tfr->ParError(3);