8 #include <svd/calibration/SVD3SampleELSTimeCalibrationAlgorithm.h>
10 #include <svd/dbobjects/SVDCoGCalibrationFunction.h>
11 #include <svd/calibration/SVD3SampleELSTimeCalibrations.h>
18 #include <framework/logging/Logger.h>
21 #include <TFitResult.h>
26 SVD3SampleELSTimeCalibrationAlgorithm::SVD3SampleELSTimeCalibrationAlgorithm(
const std::string& str) :
29 setDescription(
"SVD3SampleELSTimeCalibration calibration algorithm");
36 gROOT->SetBatch(
true);
41 std::unique_ptr<TF1> pol1pole(
new TF1(
"pol1pole",
"[0] + [1]*x + [2]/(x - [3])", -60,
43 pol1pole->SetParameter(1, 0.6);
44 pol1pole->SetParameter(2, -150);
45 pol1pole->SetParLimits(1, 0, 1);
46 pol1pole->SetParLimits(2, -300, 0);
50 while (gSystem->GetPathInfo(Form(
"algorithm_3SampleELS_output_rev_%d.root", cal_rev), info) == 0)
52 std::unique_ptr<TFile> f(
new TFile(Form(
"algorithm_3SampleELS_output_rev_%d.root", cal_rev),
"RECREATE"));
54 auto m_tree =
new TTree(Form(
"rev_%d", cal_rev),
"RECREATE");
55 int layer_num, ladder_num, sensor_num, view, ndf;
56 float a, b, c, d, a_err, b_err, c_err, d_err, chi2, p;
57 m_tree->Branch(
"layer", &layer_num,
"layer/I");
58 m_tree->Branch(
"ladder", &ladder_num,
"ladder/I");
59 m_tree->Branch(
"sensor", &sensor_num,
"sensor/I");
60 m_tree->Branch(
"isU", &view,
"isU/I");
61 m_tree->Branch(
"a", &a,
"a/F");
62 m_tree->Branch(
"b", &b,
"b/F");
63 m_tree->Branch(
"c", &c,
"c/F");
64 m_tree->Branch(
"d", &d,
"d/F");
65 m_tree->Branch(
"a_err", &a_err,
"a_err/F");
66 m_tree->Branch(
"b_err", &b_err,
"b_err/F");
67 m_tree->Branch(
"c_err", &c_err,
"c_err/F");
68 m_tree->Branch(
"d_err", &d_err,
"d_err/F");
69 m_tree->Branch(
"chi2", &chi2,
"chi2/F");
70 m_tree->Branch(
"ndf", &ndf,
"ndf/I");
71 m_tree->Branch(
"p", &p,
"p/F");
73 auto __hEventT0vsCoG__ = getObjectPtr<TH3F>(
"__hEventT0vsCoG__");
74 auto __hEventT0__ = getObjectPtr<TH2F>(
"__hEventT0__");
75 auto __hEventT0NoSync__ = getObjectPtr<TH2F>(
"__hEventT0NoSync__");
76 auto __hBinToSensorMap__ = getObjectPtr<TH1F>(
"__hBinToSensorMap__");
78 for (
int ij = 0; ij < (__hBinToSensorMap__->GetNbinsX()); ij++) {
83 auto binLabel = __hBinToSensorMap__->GetXaxis()->GetBinLabel(ij + 1);
85 std::sscanf(binLabel,
"L%dL%dS%d%c", &layer_num, &ladder_num, &sensor_num, &side);
90 B2INFO(
"Projecting for Sensor: " << binLabel <<
" with Bin Number: " << ij + 1);
92 __hEventT0vsCoG__->GetZaxis()->SetRange(ij + 1, ij + 1);
93 auto hEventT0vsELS = (TH2D*)__hEventT0vsCoG__->Project3D(
"yxe");
94 auto hEventT0 = (TH1D*)__hEventT0__->ProjectionX(
"hEventT0_tmp", ij + 1, ij + 1);
95 auto hEventT0nosync = (TH1D*)__hEventT0NoSync__->ProjectionX(
"hEventT0NoSync_tmp", ij + 1, ij + 1);
97 hEventT0vsELS->SetName(Form(
"eventT0vsCoG__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
98 hEventT0->SetName(Form(
"eventT0__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
99 hEventT0nosync->SetName(Form(
"eventT0nosync__L%dL%dS%d%c", layer_num, ladder_num, sensor_num, side));
101 char sidePN = (side ==
'U' ?
'P' :
'N');
102 hEventT0vsELS->SetTitle(Form(
"EventT0Sync vs rawTime in %d.%d.%d %c/%c", layer_num, ladder_num, sensor_num, side, sidePN));
103 hEventT0->SetTitle(Form(
"EventT0Sync in %d.%d.%d %c/%c", layer_num, ladder_num, sensor_num, side, sidePN));
104 hEventT0nosync->SetTitle(Form(
"EventT0NoSync in %d.%d.%d %c/%c", layer_num, ladder_num, sensor_num, side, sidePN));
106 hEventT0vsELS->SetDirectory(0);
107 hEventT0->SetDirectory(0);
108 hEventT0nosync->SetDirectory(0);
110 B2INFO(
"Histogram: " << hEventT0vsELS->GetName() <<
111 " Entries (n. clusters): " << hEventT0vsELS->GetEntries());
112 if (layer_num == 3 && hEventT0vsELS->GetEntries() <
m_minEntries) {
113 B2INFO(
"Histogram: " << hEventT0vsELS->GetName() <<
114 " Entries (n. clusters): " << hEventT0vsELS->GetEntries() <<
116 B2WARNING(
"Not enough data, adding one run to the collector");
118 gSystem->Unlink(Form(
"algorithm_3SampleELS_output_rev_%d.root", cal_rev));
121 if (layer_num != 3 && hEventT0vsELS->GetEntries() <
m_minEntries / 10) {
122 B2INFO(
"Histogram: " << hEventT0vsELS->GetName() <<
123 " Entries (n. clusters): " << hEventT0vsELS->GetEntries() <<
125 B2WARNING(
"Not enough data, adding one run to the collector");
127 gSystem->Unlink(Form(
"algorithm_3SampleELS_output_rev_%d.root", cal_rev));
130 for (
int i = 1; i <= hEventT0vsELS->GetNbinsX(); i++) {
131 for (
int j = 1; j <= hEventT0vsELS->GetNbinsY(); j++) {
132 if (hEventT0vsELS->GetBinContent(i, j) < max(2,
int(hEventT0vsELS->GetEntries() * 0.001))) {
133 hEventT0vsELS->SetBinContent(i, j, 0);
137 TProfile* pfx = hEventT0vsELS->ProfileX();
138 std::string name =
"pfx_" + std::string(hEventT0vsELS->GetName());
139 pfx->SetName(name.c_str());
141 pol1pole->FixParameter(3, 7);
142 pfx->Fit(
"pol1pole",
"QMRS");
143 pol1pole->SetParLimits(3, 0, 15);
144 TFitResultPtr tfr = pfx->Fit(
"pol1pole",
"QMRS");
157 pol1pole->GetParameters(par);
160 timeCal->set_current(3);
161 timeCal->set_elsparameters(par[0], par[1], par[2], par[3]);
162 payload->set(layer_num, ladder_num, sensor_num,
bool(view), 1, *timeCal);
165 hEventT0vsELS->Write();
166 hEventT0nosync->Write();
170 delete hEventT0vsELS;
172 delete hEventT0nosync;
174 if (tfr.Get() ==
nullptr || (tfr->Status() != 0 && tfr->Status() != 4 && tfr->Status() != 4000)) {
176 B2FATAL(
"Fit to the histogram failed in SVD3SampleELSTimeCalibrationAlgorithm. "
177 <<
"Check the 2-D histogram to clarify the reason.");
179 a = par[0]; b = par[1]; c = par[2]; d = par[3];
180 a_err = tfr->ParError(0); b_err = tfr->ParError(1); c_err = tfr->ParError(2); d_err = tfr->ParError(3);
203 float meanRawTimeL3V = 0;
205 auto rawTimeL3V = getObjectPtr<TH1F>(
"hRawTimeL3V");
212 meanRawTimeL3V = rawTimeL3V->GetMean();
219 B2INFO(
"Setting start payload boundary to be the first run ("
220 << currentRun.first <<
"," << currentRun.second <<
")");
226 <<
" to " << meanRawTimeL3V <<
". We are requesting a new payload boundary for ("
227 << 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.
std::string m_id
Parameter given to set the UniqueID of the payload.
std::optional< float > m_previousRawTimeMeanL3V
Raw CoG of the previous run.
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 Raw CoGshift.
SVDCalibrationsBase< SVDCalibrationsScalar< SVDCoGCalibrationFunction > > t_payload
typedef for the SVDCoGCalibrationFunction payload of all SVD sensors
class to contain the CoG Time calibrations
Abstract base class for different kinds of events.