10 #include <klm/calibration/KLMTimeAlgorithm.h>
13 #include <klm/dataobjects/bklm/BKLMElementNumbers.h>
16 #include <framework/database/Database.h>
17 #include <framework/database/DBObjPtr.h>
18 #include <framework/database/DBStore.h>
19 #include <framework/dataobjects/EventMetaData.h>
20 #include <framework/gearbox/Const.h>
21 #include <framework/logging/Logger.h>
24 #include <Math/MinimizerOptions.h>
26 #include <TFitResult.h>
34 using namespace ROOT::Math;
37 const int c_NBinsTime = 100;
40 const int c_NBinsDistance = 100;
43 static double s_BinnedData[c_NBinsTime][c_NBinsDistance];
46 static double s_LowerTimeBoundary = 0;
49 static double s_UpperTimeBoundary = 0;
52 static double s_StripLength = 0;
54 static bool compareEventNumber(
const std::pair<KLMChannelNumber, unsigned int>& pair1,
55 const std::pair<KLMChannelNumber, unsigned int>& pair2)
57 return pair1.second < pair2.second;
60 static double timeDensity(
const double x[2],
const double* par)
62 double polynomial, t0, gauss;
64 t0 = par[2] + par[4] * x[1];
65 gauss = par[1] / (
sqrt(2.0 * M_PI) * par[3]) *
66 exp(-0.5 * pow((x[0] - t0) / par[3], 2));
67 return fabs(polynomial + gauss);
70 static void fcn(
int& npar,
double* grad,
double& fval,
double* par,
int iflag)
77 for (
int i = 0; i < c_NBinsTime; ++i) {
78 x[0] = s_LowerTimeBoundary +
79 (s_UpperTimeBoundary - s_LowerTimeBoundary) *
80 (
double(i) + 0.5) / c_NBinsTime;
81 for (
int j = 0; j < c_NBinsDistance; ++j) {
82 x[1] = s_StripLength * (double(j) + 0.5) / c_NBinsDistance;
83 double f = timeDensity(x, par);
84 if (s_BinnedData[i][j] == 0)
85 fval = fval + 2.0 * f;
87 fval = fval + 2.0 * (f - s_BinnedData[i][j] *
88 (1.0 - log(s_BinnedData[i][j] / f)));
106 const std::vector<Calibration::ExpRun>& runs =
getRunList();
107 int firstExperiment = runs[0].first;
108 int lastExperiment = runs[runs.size() - 1].first;
109 if (firstExperiment != lastExperiment) {
110 B2FATAL(
"Runs from different experiments are used "
111 "for KLM time calibration (single algorithm run).");
120 if (eventMetaData->getExperiment() != firstExperiment) {
121 B2FATAL(
"Runs from different experiments are used "
122 "for KLM time calibration (consecutive algorithm runs).");
124 eventMetaData->setExperiment(firstExperiment);
125 eventMetaData->setRun(runs[0].second);
127 eventMetaData.
construct(1, runs[0].second, firstExperiment);
143 B2INFO(
"Read tree entries and seprate events by module id.");
145 std::shared_ptr<TTree> timeCalibrationData;
146 timeCalibrationData = getObjectPtr<TTree>(
"time_calibration_data");
147 timeCalibrationData->SetBranchAddress(
"t0", &event.t0);
148 timeCalibrationData->SetBranchAddress(
"flyTime", &event.flyTime);
149 timeCalibrationData->SetBranchAddress(
"recTime", &event.recTime);
150 timeCalibrationData->SetBranchAddress(
"dist", &event.dist);
151 timeCalibrationData->SetBranchAddress(
"diffDistX", &event.diffDistX);
152 timeCalibrationData->SetBranchAddress(
"diffDistY", &event.diffDistY);
153 timeCalibrationData->SetBranchAddress(
"diffDistZ", &event.diffDistZ);
154 timeCalibrationData->SetBranchAddress(
"eDep", &event.eDep);
155 timeCalibrationData->SetBranchAddress(
"nPE", &event.nPE);
156 timeCalibrationData->SetBranchAddress(
"channelId", &event.channelId);
157 timeCalibrationData->SetBranchAddress(
"inRPC", &event.inRPC);
158 timeCalibrationData->SetBranchAddress(
"isFlipped", &event.isFlipped);
160 B2INFO(
LogVar(
"Total number of digits:", timeCalibrationData->GetEntries()));
163 int n = timeCalibrationData->GetEntries();
166 for (
int i = 0; i < n; ++i) {
167 timeCalibrationData->GetEntry(i);
168 m_evts[
event.channelId].push_back(event);
170 B2INFO(
"Events packing finish.");
193 int nBin_scint = 400;
195 TString iFstring[2] = {
"Backward",
"Forward"};
196 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
199 h_diff =
new TH1F(
"h_diff",
"Position difference between bklmHit2d and extHit;position difference", 100, 0, 10);
200 h_calibrated =
new TH1I(
"h_calibrated_summary",
"h_calibrated_summary;calibrated or not", 3, 0, 3);
201 hc_calibrated =
new TH1I(
"hc_calibrated_summary",
"hc_calibrated_summary;calibrated or not", 3, 0, 3);
219 double maximalPhiStripLengthBKLM =
221 double maximalZStripLengthBKLM =
223 double maximalStripLengthEKLM =
227 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 400, 0.0,
230 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 400, 0.0,
233 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
234 200, 0.0, maximalPhiStripLengthBKLM);
236 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
237 200, 0.0, maximalZStripLengthBKLM);
239 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
240 200, 0.0, maximalStripLengthEKLM);
242 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
243 200, 0.0, maximalStripLengthEKLM);
246 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 400, 0.0,
249 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 400, 0.0,
252 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
253 200, 0.0, maximalPhiStripLengthBKLM);
255 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
256 200, 0.0, maximalZStripLengthBKLM);
258 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
259 200, 0.0, maximalStripLengthEKLM);
261 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
262 200, 0.0, maximalStripLengthEKLM);
265 h_time_scint_tc =
new TH1F(
"h_time_scint_tc",
"time distribtution for Scintillator", nBin_scint,
267 h_time_scint_tc_end =
new TH1F(
"h_time_scint_tc_end",
"time distribtution for Scintillator (Endcap)", nBin_scint,
274 h_time_scint =
new TH1F(
"h_time_scint",
"time distribtution for Scintillator; T_rec-T_0-T_fly-T_propagation[ns]", nBin_scint,
276 h_time_scint_end =
new TH1F(
"h_time_scint_end",
"time distribtution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
279 hc_time_rpc =
new TH1F(
"hc_time_rpc",
"Calibrated time distribtution for RPC; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
282 "Calibrated time distribtution for Scintillator; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
286 "Calibrated time distribtution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
289 for (
int iF = 0; iF < 2; ++iF) {
290 hn = Form(
"h_timeF%d_rpc", iF);
291 ht = Form(
"Time distribtution for RPC of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
293 hn = Form(
"h_timeF%d_scint", iF);
294 ht = Form(
"Time distribtution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
297 hn = Form(
"h_timeF%d_scint_end", iF);
298 ht = Form(
"Time distribtution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
302 hn = Form(
"h2_timeF%d_rpc", iF);
303 ht = Form(
"Time distribtution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
305 hn = Form(
"h2_timeF%d_scint", iF);
306 ht = Form(
"Time distribtution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
309 hn = Form(
"h2_timeF%d_scint_end", iF);
310 ht = Form(
"Time distribtution for Scintillator of %s (Endcap); Sector Index; T_rec-T_0-T_fly-T_propagation[ns]",
311 iFstring[iF].Data());
315 hn = Form(
"hc_timeF%d_rpc", iF);
316 ht = Form(
"Calibrated time distribtution for RPC of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iFstring[iF].Data());
318 hn = Form(
"hc_timeF%d_scint", iF);
319 ht = Form(
"Calibrated time distribtution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
320 iFstring[iF].Data());
323 hn = Form(
"hc_timeF%d_scint_end", iF);
324 ht = Form(
"Calibrated time distribtution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
325 iFstring[iF].Data());
329 hn = Form(
"h2c_timeF%d_rpc", iF);
330 ht = Form(
"Calibrated time distribtution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
331 iFstring[iF].Data());
334 hn = Form(
"h2c_timeF%d_scint", iF);
335 ht = Form(
"Calibrated time distribtution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
336 iFstring[iF].Data());
339 hn = Form(
"h2c_timeF%d_scint_end", iF);
340 ht = Form(
"Calibrated time distribtution for Scintillator of %s (Endcap) ; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
341 iFstring[iF].Data());
345 for (
int iS = 0; iS < 8; ++iS) {
347 hn = Form(
"h_timeF%d_S%d_scint", iF, iS);
348 ht = Form(
"Time distribtution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
351 hn = Form(
"h_timeF%d_S%d_rpc", iF, iS);
352 ht = Form(
"Time distribtution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
354 hn = Form(
"h2_timeF%d_S%d", iF, iS);
355 ht = Form(
"Time distribtution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
359 hn = Form(
"hc_timeF%d_S%d_scint", iF, iS);
360 ht = Form(
"Calibrated time distribtution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
361 iFstring[iF].Data());
364 hn = Form(
"hc_timeF%d_S%d_rpc", iF, iS);
365 ht = Form(
"Calibrated time distribtution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
366 iFstring[iF].Data());
369 hn = Form(
"h2c_timeF%d_S%d", iF, iS);
370 ht = Form(
"Calibrated time distribtution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
371 iFstring[iF].Data());
376 for (
int iL = 0; iL < 2; ++iL) {
377 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
378 ht = Form(
"Time distribtution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
379 iFstring[iF].Data());
382 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
383 ht = Form(
"Calibrated time distribtution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
384 iL, iS, iFstring[iF].Data());
388 for (
int iP = 0; iP < 2; ++iP) {
389 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
390 ht = Form(
"Time distribtution for Scintillator of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]",
391 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
394 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
395 ht = Form(
"Time distribtution for Scintillator of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
396 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
400 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
401 ht = Form(
"Calibrated time distribtution for Scintillator of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
402 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
405 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
406 ht = Form(
"Calibrated time distribtution for Scintillator of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
407 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
412 for (
int iC = 0; iC < nchannel_max; ++iC) {
413 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
414 ht = Form(
"time distribtution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iC,
415 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
419 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
420 ht = Form(
"time distribtution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iC,
421 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
425 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
426 ht = Form(
"Calibrated time distribtution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
427 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
430 hn = Form(
"time_length_bklm_F%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
431 double stripLength = 200;
434 "Time versus propagation length; "
435 "propagation distance[cm]; "
436 "T_rec-T_0-T_fly-'T_calibration'[ns]",
437 200, 0.0, stripLength,
444 for (
int iL = 2; iL < 15; ++iL) {
445 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
446 ht = Form(
"time distribtution for RPC of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iL, iS, iFstring[iF].Data());
449 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
450 ht = Form(
"Calibrated time distribtution for RPC of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iL, iS,
451 iFstring[iF].Data());
454 for (
int iP = 0; iP < 2; ++iP) {
455 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
456 ht = Form(
"time distribtution for RPC of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iPstring[iP].Data(), iL, iS,
457 iFstring[iF].Data());
460 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
461 ht = Form(
"time distribtution for RPC of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
462 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
465 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
466 ht = Form(
"Calibrated time distribtution for RPC of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
467 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
471 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
472 ht = Form(
"Calibrated time distribtution for RPC of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
473 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
478 for (
int iC = 0; iC < nchannel_max; ++iC) {
479 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
480 ht = Form(
"Time distribtution for RPC of Channel%d, %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iC,
481 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
484 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
485 ht = Form(
"Time distribtution for RPC of Channel%d, %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iC,
486 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
489 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
490 ht = Form(
"Calibrated time distribtution for RPC of Channel%d, %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
491 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
499 int maxLay = 12 + 2 * iF;
500 for (
int iS = 0; iS < 4; ++iS) {
501 hn = Form(
"h_timeF%d_S%d_scint_end", iF, iS);
502 ht = Form(
"Time distribtution for Scintillator of Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iS,
503 iFstring[iF].Data());
506 hn = Form(
"h2_timeF%d_S%d_end", iF, iS);
507 ht = Form(
"Time distribtution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
510 hn = Form(
"hc_timeF%d_S%d_scint_end", iF, iS);
511 ht = Form(
"Calibrated time distribtution for Scintillator of Sector%d (Endcap), %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
512 iS, iFstring[iF].Data());
515 hn = Form(
"h2c_timeF%d_S%d_end", iF, iS);
516 ht = Form(
"Calibrated time distribtution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
517 iS, iFstring[iF].Data());
518 h2c_timeFS_end[iF][iS] =
new TH2F(hn.Data(), ht.Data(), maxLay, 0, maxLay, nBin_scint,
522 for (
int iL = 0; iL < maxLay; ++iL) {
523 hn = Form(
"h_timeF%d_S%d_L%d_end", iF, iS, iL);
524 ht = Form(
"Time distribtution for Scintillator of Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
525 iFstring[iF].Data());
528 hn = Form(
"hc_timeF%d_S%d_L%d_end", iF, iS, iL);
529 ht = Form(
"Calibrated time distribtution for Scintillator of Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
530 iL, iS, iFstring[iF].Data());
534 for (
int iP = 0; iP < 2; ++iP) {
535 hn = Form(
"h_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
536 ht = Form(
"Time distribtution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
537 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
541 hn = Form(
"h2_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
542 ht = Form(
"Time distribtution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
543 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
547 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
548 ht = Form(
"Calibrated time distribtution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
549 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
553 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
554 ht = Form(
"Calibrated time distribtution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); Channel Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
555 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
556 h2c_timeFSLP_end[iF][iS][iL][iP] =
new TH2F(hn.Data(), ht.Data(), 75, 0, 75, nBin_scint,
560 for (
int iC = 0; iC < 75; ++iC) {
561 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc_end", iF, iS, iL, iP, iC);
562 ht = Form(
"Time distribtution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
563 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
567 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
568 ht = Form(
"Time distribtution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
569 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
572 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
573 ht = Form(
"Calibrated time distribtution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
574 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
577 hn = Form(
"time_length_eklm_F%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
582 "Time versus propagation length; "
583 "propagation distance[cm]; "
584 "T_rec-T_0-T_fly-'T_calibration'[ns]",
585 200, 0.0, stripLength,
596 TProfile* profileRpcPhi, TProfile* profileRpcZ,
597 TProfile* profileBKLMScintillatorPhi, TProfile* profileBKLMScintillatorZ,
598 TProfile* profileEKLMScintillatorPlane1,
599 TProfile* profileEKLMScintillatorPlane2,
bool fill2dHistograms)
603 if (
m_cFlag[channel] == ChannelCalibrationStatus::c_NotEnoughData)
606 std::vector<struct Event>::iterator it;
607 std::vector<struct Event> eventsChannel;
608 eventsChannel =
m_evts[channel];
609 int iSub = klmChannel.getSubdetector();
611 for (it = eventsChannel.begin(); it != eventsChannel.end(); ++it) {
612 double timeHit = it->time() -
m_timeShift[channel];
614 timeHit = timeHit - it->t0;
615 double distHit = it->dist;
618 int iF = klmChannel.getSection();
619 int iS = klmChannel.getSector() - 1;
620 int iL = klmChannel.getLayer() - 1;
621 int iP = klmChannel.getPlane();
622 int iC = klmChannel.getStrip() - 1;
625 profileRpcPhi->Fill(distHit, timeHit);
627 profileRpcZ->Fill(distHit, timeHit);
630 if (fill2dHistograms)
633 profileBKLMScintillatorPhi->Fill(distHit, timeHit);
635 profileBKLMScintillatorZ->Fill(distHit, timeHit);
639 int iF = klmChannel.getSection() - 1;
640 int iS = klmChannel.getSector() - 1;
641 int iL = klmChannel.getLayer() - 1;
642 int iP = klmChannel.getPlane() - 1;
643 int iC = klmChannel.getStrip() - 1;
644 if (fill2dHistograms)
647 profileEKLMScintillatorPlane1->Fill(distHit, timeHit);
649 profileEKLMScintillatorPlane2->Fill(distHit, timeHit);
657 const std::vector< std::pair<KLMChannelNumber, unsigned int> >& channels,
658 double& delay,
double& delayError)
660 std::vector<struct Event>::iterator it;
661 std::vector<struct Event> eventsChannel;
663 int nConvergedFits = 0;
666 if (nFits > (
int)channels.size())
667 nFits = channels.size();
668 for (
int i = 0; i < nFits; ++i) {
669 int subdetector, section, sector, layer, plane, strip;
671 channels[i].first, &subdetector, §ion, §or, &layer, &plane,
678 s_StripLength = module->getStripLength(plane, strip);
685 for (
int j = 0; j < c_NBinsTime; ++j) {
686 for (
int k = 0; k < c_NBinsDistance; ++k)
687 s_BinnedData[j][k] = 0;
689 eventsChannel =
m_evts[channels[i].first];
690 double averageTime = 0;
691 for (it = eventsChannel.begin(); it != eventsChannel.end(); ++it) {
692 double timeHit = it->time();
694 timeHit = timeHit - it->t0;
695 averageTime = averageTime + timeHit;
696 int timeBin = std::floor((timeHit - s_LowerTimeBoundary) * c_NBinsTime /
697 (s_UpperTimeBoundary - s_LowerTimeBoundary));
698 if (timeBin < 0 || timeBin >= c_NBinsTime)
700 int distanceBin = std::floor(it->dist * c_NBinsDistance / s_StripLength);
701 if (distanceBin < 0 || distanceBin >= c_NBinsDistance) {
702 B2ERROR(
"The distance to SiPM is greater than the strip length.");
705 s_BinnedData[timeBin][distanceBin] += 1;
707 averageTime = averageTime / eventsChannel.size();
709 minuit.SetPrintLevel(-1);
711 minuit.mnparm(0,
"P0", 1, 0.001, 0, 0, minuitResult);
712 minuit.mnparm(1,
"N", 10, 0.001, 0, 0, minuitResult);
713 minuit.mnparm(2,
"T0", averageTime, 0.001, 0, 0, minuitResult);
714 minuit.mnparm(3,
"SIGMA", 10, 0.001, 0, 0, minuitResult);
715 minuit.mnparm(4,
"DELAY", 0.0, 0.001, 0, 0, minuitResult);
717 minuit.mncomd(
"FIX 2 3 4 5", minuitResult);
718 minuit.mncomd(
"MIGRAD 10000", minuitResult);
719 minuit.mncomd(
"RELEASE 2", minuitResult);
720 minuit.mncomd(
"MIGRAD 10000", minuitResult);
721 minuit.mncomd(
"RELEASE 3", minuitResult);
722 minuit.mncomd(
"MIGRAD 10000", minuitResult);
723 minuit.mncomd(
"RELEASE 4", minuitResult);
724 minuit.mncomd(
"MIGRAD 10000", minuitResult);
725 minuit.mncomd(
"RELEASE 5", minuitResult);
726 minuit.mncomd(
"MIGRAD 10000", minuitResult);
728 if (minuit.fISW[1] != 3)
731 double channelDelay, channelDelayError;
732 minuit.GetParameter(4, channelDelay, channelDelayError);
733 delay = delay + channelDelay;
734 delayError = delayError + channelDelayError * channelDelayError;
736 delay = delay / nConvergedFits;
737 delayError =
sqrt(delayError) / (nConvergedFits - 1);
743 gROOT->SetBatch(kTRUE);
749 fcn_gaus =
new TF1(
"fcn_gaus",
"gaus");
750 fcn_land =
new TF1(
"fcn_land",
"landau");
751 fcn_pol1 =
new TF1(
"fcn_pol1",
"pol1");
752 fcn_const =
new TF1(
"fcn_const",
"pol0");
759 std::string name =
"time_calibration.root";
763 if (stat(name.c_str(), &buffer) != 0)
765 name =
"time_calibration_" + std::to_string(i) +
".root";
771 m_outFile =
new TFile(name.c_str(),
"recreate");
774 std::vector<struct Event>::iterator it;
775 std::vector<struct Event> eventsChannel;
777 eventsChannel.clear();
782 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsBKLM;
783 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsEKLM;
787 m_cFlag[channel] = ChannelCalibrationStatus::c_NotEnoughData;
790 int nEvents =
m_evts[channel].size();
792 B2WARNING(
"Not enough calibration data collected."
793 <<
LogVar(
"channel", channel)
794 <<
LogVar(
"number of digit", nEvents));
797 m_cFlag[channel] = ChannelCalibrationStatus::c_FailedFit;
800 channelsBKLM.push_back(
801 std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
804 channelsEKLM.push_back(
805 std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
808 std::sort(channelsBKLM.begin(), channelsBKLM.end(), compareEventNumber);
809 std::sort(channelsEKLM.begin(), channelsEKLM.end(), compareEventNumber);
812 double delayBKLM, delayBKLMError;
813 double delayEKLM, delayEKLMError;
821 B2INFO(
"Effective light speed Estimation.");
823 channelId = klmChannel.getKLMChannelNumber();
824 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
827 eventsChannel =
m_evts[channelId];
828 int iSub = klmChannel.getSubdetector();
830 for (it = eventsChannel.begin(); it != eventsChannel.end(); ++it) {
831 TVector3 diffD = TVector3(it->diffDistX, it->diffDistY, it->diffDistZ);
832 h_diff->Fill(diffD.Mag());
833 double timeHit = it->time();
835 timeHit = timeHit - it->t0;
837 int iF = klmChannel.getSection();
838 int iS = klmChannel.getSector() - 1;
839 int iL = klmChannel.getLayer() - 1;
840 int iP = klmChannel.getPlane();
841 int iC = klmChannel.getStrip() - 1;
849 int iF = klmChannel.getSection() - 1;
850 int iS = klmChannel.getSector() - 1;
851 int iL = klmChannel.getLayer() - 1;
852 int iP = klmChannel.getPlane() - 1;
853 int iC = klmChannel.getStrip() - 1;
859 B2INFO(
"Effective light speed Estimation! Hists and Graph filling done.");
867 B2INFO(
"Global Mean for Raw." <<
LogVar(
"RPC", tmpMean_rpc_global) <<
LogVar(
"Scint BKLM",
868 tmpMean_scint_global) <<
LogVar(
"Scint EKLM", tmpMean_scint_global_end));
871 channelId = klmChannel.getKLMChannelNumber();
872 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
875 int iSub = klmChannel.getSubdetector();
877 int iF = klmChannel.getSection();
878 int iS = klmChannel.getSector() - 1;
879 int iL = klmChannel.getLayer() - 1;
880 int iP = klmChannel.getPlane();
881 int iC = klmChannel.getStrip() - 1;
883 double tmpMean_channel =
fcn_gaus->GetParameter(1);
885 m_timeShift[channelId] = tmpMean_channel - tmpMean_rpc_global;
887 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global;
890 int iF = klmChannel.getSection() - 1;
891 int iS = klmChannel.getSector() - 1;
892 int iL = klmChannel.getLayer() - 1;
893 int iP = klmChannel.getPlane() - 1;
894 int iC = klmChannel.getStrip() - 1;
896 double tmpMean_channel =
fcn_gaus->GetParameter(1);
897 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global_end;
904 B2INFO(
"Effective Light m_timeShift obtained. done.");
911 B2INFO(
"Effective light speed fitting.");
913 double delayRPCPhi =
fcn_pol1->GetParameter(1);
914 double e_slope_rpc_phi =
fcn_pol1->GetParError(1);
917 double delayRPCZ =
fcn_pol1->GetParameter(1);
918 double e_slope_rpc_z =
fcn_pol1->GetParError(1);
921 double slope_scint_phi =
fcn_pol1->GetParameter(1);
922 double e_slope_scint_phi =
fcn_pol1->GetParError(1);
925 double slope_scint_z =
fcn_pol1->GetParameter(1);
926 double e_slope_scint_z =
fcn_pol1->GetParError(1);
929 double slope_scint_plane1_end =
fcn_pol1->GetParameter(1);
930 double e_slope_scint_plane1_end =
fcn_pol1->GetParError(1);
933 double slope_scint_plane2_end =
fcn_pol1->GetParameter(1);
934 double e_slope_scint_plane2_end =
fcn_pol1->GetParError(1);
936 TString logStr_phi, logStr_z;
937 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", delayRPCPhi, e_slope_rpc_phi);
938 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayRPCZ, e_slope_rpc_z);
939 B2INFO(
"Delay in RPCs:"
940 <<
LogVar(
"Fitted Value (phi readout) ", logStr_phi.Data())
941 <<
LogVar(
"Fitted Value (z readout) ", logStr_z.Data()));
942 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_phi, e_slope_scint_phi);
943 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_z, e_slope_scint_z);
944 B2INFO(
"Delay in BKLM scintillators:"
945 <<
LogVar(
"Fitted Value (phi readout) ", logStr_phi.Data())
946 <<
LogVar(
"Fitted Value (z readout) ", logStr_z.Data()));
947 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane1_end,
948 e_slope_scint_plane1_end);
949 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane2_end,
950 e_slope_scint_plane2_end);
951 B2INFO(
"Delay in EKLM scintillators:"
952 <<
LogVar(
"Fitted Value (plane1 readout) ", logStr_phi.Data())
953 <<
LogVar(
"Fitted Value (plane2 readout) ", logStr_z.Data()));
955 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayBKLM, delayBKLMError);
956 B2INFO(
"Delay in BKLM scintillators:"
957 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
958 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayEKLM, delayEKLMError);
959 B2INFO(
"Delay in EKLM scintillators:"
960 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
972 B2INFO(
"Time distribution filling begins.");
974 channelId = klmChannel.getKLMChannelNumber();
975 int iSub = klmChannel.getSubdetector();
977 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
979 eventsChannel =
m_evts[channelId];
981 for (it = eventsChannel.begin(); it != eventsChannel.end(); ++it) {
982 double timeHit = it->time();
984 timeHit = timeHit - it->t0;
986 int iF = klmChannel.getSection();
987 int iS = klmChannel.getSector() - 1;
988 int iL = klmChannel.getLayer() - 1;
989 int iP = klmChannel.getPlane();
990 int iC = klmChannel.getStrip() - 1;
994 propgationT = it->dist * delayRPCZ;
996 propgationT = it->dist * delayRPCPhi;
997 double time = timeHit - propgationT;
1008 double propgationT = it->dist * delayBKLM;
1009 double time = timeHit - propgationT;
1021 int iF = klmChannel.getSection() - 1;
1022 int iS = klmChannel.getSector() - 1;
1023 int iL = klmChannel.getLayer() - 1;
1024 int iP = klmChannel.getPlane() - 1;
1025 int iC = klmChannel.getStrip() - 1;
1026 double propgationT = it->dist * delayEKLM;
1027 double time = timeHit - propgationT;
1041 B2INFO(
"Orignal filling done.");
1043 int iChannel_rpc = 0;
1045 int iChannel_end = 0;
1047 channelId = klmChannel.getKLMChannelNumber();
1048 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1050 int iSub = klmChannel.getSubdetector();
1053 int iF = klmChannel.getSection();
1054 int iS = klmChannel.getSector() - 1;
1055 int iL = klmChannel.getLayer() - 1;
1056 int iP = klmChannel.getPlane();
1057 int iC = klmChannel.getStrip() - 1;
1063 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1076 int iF = klmChannel.getSection() - 1;
1077 int iS = klmChannel.getSector() - 1;
1078 int iL = klmChannel.getLayer() - 1;
1079 int iP = klmChannel.getPlane() - 1;
1080 int iC = klmChannel.getStrip() - 1;
1086 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1107 B2INFO(
"Channel's time distribution fitting done.");
1112 B2INFO(
"Calibrated channel's time distribution filling begins.");
1116 channelId = klmChannel.getKLMChannelNumber();
1121 int iSub = klmChannel.getSubdetector();
1123 int iL = klmChannel.getLayer() - 1;
1135 channelId = klmChannel.getKLMChannelNumber();
1140 B2DEBUG(20,
"Uncalibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeShift[channelId]));
1147 channelId = klmChannel.getKLMChannelNumber();
1149 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happended on " <<
LogVar(
"Channel", channelId));
1152 int iSub = klmChannel.getSubdetector();
1154 int iL = klmChannel.getLayer();
1174 channelId = klmChannel.getKLMChannelNumber();
1175 int iSub = klmChannel.getSubdetector();
1176 eventsChannel =
m_evts[channelId];
1177 for (it = eventsChannel.begin(); it != eventsChannel.end(); ++it) {
1178 double timeHit = it->time();
1180 timeHit = timeHit - it->t0;
1182 int iF = klmChannel.getSection();
1183 int iS = klmChannel.getSector() - 1;
1184 int iL = klmChannel.getLayer() - 1;
1185 int iP = klmChannel.getPlane();
1186 int iC = klmChannel.getStrip() - 1;
1190 propgationT = it->dist * delayRPCZ;
1192 propgationT = it->dist * delayRPCPhi;
1193 double time = timeHit - propgationT -
m_timeShift[channelId];
1204 double propgationT = it->dist * delayBKLM;
1205 double time = timeHit - propgationT -
m_timeShift[channelId];
1217 int iF = klmChannel.getSection() - 1;
1218 int iS = klmChannel.getSector() - 1;
1219 int iL = klmChannel.getLayer() - 1;
1220 int iP = klmChannel.getPlane() - 1;
1221 int iC = klmChannel.getStrip() - 1;
1222 double propgationT = it->dist * delayEKLM;
1223 double time = timeHit - propgationT -
m_timeShift[channelId];
1237 int icChannel_rpc = 0;
1239 int icChannel_end = 0;
1241 channelId = klmChannel.getKLMChannelNumber();
1242 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1244 int iSub = klmChannel.getSubdetector();
1247 int iF = klmChannel.getSection();
1248 int iS = klmChannel.getSector() - 1;
1249 int iL = klmChannel.getLayer() - 1;
1250 int iP = klmChannel.getPlane();
1251 int iC = klmChannel.getStrip() - 1;
1257 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1270 int iF = klmChannel.getSection() - 1;
1271 int iS = klmChannel.getSector() - 1;
1272 int iL = klmChannel.getLayer() - 1;
1273 int iP = klmChannel.getPlane() - 1;
1274 int iC = klmChannel.getStrip() - 1;
1280 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1301 B2INFO(
"Channel's time distribution fitting done.");
1306 B2INFO(
"Calibrated channel's time distribution filling begins.");
1310 channelId = klmChannel.getKLMChannelNumber();
1315 int iSub = klmChannel.getSubdetector();
1317 int iL = klmChannel.getLayer() - 1;
1329 channelId = klmChannel.getKLMChannelNumber();
1334 B2DEBUG(20,
"Calibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeRes[channelId]));
1341 channelId = klmChannel.getKLMChannelNumber();
1343 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happended on " <<
LogVar(
"Channel", channelId));
1346 int iSub = klmChannel.getSubdetector();
1348 int iL = klmChannel.getLayer();
1379 B2INFO(
"Save Histograms into Files.");
1380 TDirectory* dir_monitor =
m_outFile->mkdir(
"monitor_Hists");
1384 h_diff->SetDirectory(dir_monitor);
1387 TDirectory* dir_effC =
m_outFile->mkdir(
"effC_Hists");
1403 TDirectory* dir_time =
m_outFile->mkdir(
"time");
1428 B2INFO(
"Top file setup Done.");
1430 TDirectory* dir_time_F[2];
1431 TDirectory* dir_time_FS[2][8];
1432 TDirectory* dir_time_FSL[2][8][15];
1433 TDirectory* dir_time_FSLP[2][8][15][2];
1434 TDirectory* dir_time_F_end[2];
1435 TDirectory* dir_time_FS_end[2][4];
1436 TDirectory* dir_time_FSL_end[2][4][14];
1437 TDirectory* dir_time_FSLP_end[2][4][14][2];
1439 B2INFO(
"Sub files declare Done.");
1440 for (
int iF = 0; iF < 2; ++iF) {
1459 sprintf(dirname,
"isForward_%d", iF);
1460 dir_time_F[iF] = dir_time->mkdir(dirname);
1461 dir_time_F[iF]->cd();
1463 for (
int iS = 0; iS < 8; ++iS) {
1470 h2_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
1471 h2c_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
1473 sprintf(dirname,
"Sector_%d", iS + 1);
1474 dir_time_FS[iF][iS] = dir_time_F[iF]->mkdir(dirname);
1475 dir_time_FS[iF][iS]->cd();
1477 for (
int iL = 0; iL < 15; ++iL) {
1478 h_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
1479 hc_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
1481 sprintf(dirname,
"Layer_%d", iL + 1);
1482 dir_time_FSL[iF][iS][iL] = dir_time_FS[iF][iS]->mkdir(dirname);
1483 dir_time_FSL[iF][iS][iL]->cd();
1484 for (
int iP = 0; iP < 2; ++iP) {
1485 h_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
1486 hc_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
1487 h2_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
1488 h2c_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
1490 sprintf(dirname,
"Plane_%d", iP);
1491 dir_time_FSLP[iF][iS][iL][iP] = dir_time_FSL[iF][iS][iL]->mkdir(dirname);
1492 dir_time_FSLP[iF][iS][iL][iP]->cd();
1495 for (
int iC = 0; iC < nchannel_max; ++iC) {
1498 h_timeFSLPC[iF][iS][iL][iP][iC]->SetDirectory(dir_time_FSLP[iF][iS][iL][iP]);
1499 hc_timeFSLPC[iF][iS][iL][iP][iC]->SetDirectory(dir_time_FSLP[iF][iS][iL][iP]);
1506 sprintf(dirname,
"isForward_%d_end", iF + 1);
1507 dir_time_F_end[iF] = dir_time->mkdir(dirname);
1508 dir_time_F_end[iF]->cd();
1509 int maxLayer = 12 + 2 * iF;
1510 for (
int iS = 0; iS < 4; ++iS) {
1517 sprintf(dirname,
"Sector_%d_end", iS + 1);
1518 dir_time_FS_end[iF][iS] = dir_time_F_end[iF]->mkdir(dirname);
1519 dir_time_FS_end[iF][iS]->cd();
1520 for (
int iL = 0; iL < maxLayer; ++iL) {
1521 h_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
1522 hc_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
1524 sprintf(dirname,
"Layer_%d_end", iL + 1);
1525 dir_time_FSL_end[iF][iS][iL] = dir_time_FS_end[iF][iS]->mkdir(dirname);
1526 dir_time_FSL_end[iF][iS][iL]->cd();
1527 for (
int iP = 0; iP < 2; ++iP) {
1528 h_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
1529 hc_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
1530 h2_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
1531 h2c_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
1533 sprintf(dirname,
"plane_%d_end", iP);
1534 dir_time_FSLP_end[iF][iS][iL][iP] = dir_time_FSL_end[iF][iS][iL]->mkdir(dirname);
1535 dir_time_FSLP_end[iF][iS][iL][iP]->cd();
1537 for (
int iC = 0; iC < 75; ++iC) {
1538 h_timeFSLPC_end[iF][iS][iL][iP][iC]->SetDirectory(dir_time_FSLP_end[iF][iS][iL][iP]);
1539 hc_timeFSLPC_end[iF][iS][iL][iP][iC]->SetDirectory(dir_time_FSLP_end[iF][iS][iL][iP]);
1550 B2INFO(
"File Write and Close. Done.");
1568 }
else if (iC == totNStrips) {
1574 std::pair<int, double> tS_upper =
tS_upperStrip(kCIndex_upper);
1575 std::pair<int, double> tS_lower =
tS_lowerStrip(kCIndex_lower);
1576 unsigned int td_upper = tS_upper.first - iC;
1577 unsigned int td_lower = iC - tS_lower.first;
1578 unsigned int td = tS_upper.first - tS_lower.first;
1579 tS = (double(td_upper) * tS_lower.second + double(td_lower) * tS_upper.second) /
double(td);
1586 std::pair<int, double> tS;
1600 }
else if (iC == totNStrips) {
1612 std::pair<int, double> tS;
1623 }
else if (iC == 1) {
1648 }
else if (iC == totNStrips) {
1654 std::pair<int, double> tR_upper =
tR_upperStrip(kCIndex_upper);
1655 std::pair<int, double> tR_lower =
tR_lowerStrip(kCIndex_lower);
1656 unsigned int tr_upper = tR_upper.first - iC;
1657 unsigned int tr_lower = iC - tR_lower.first;
1658 unsigned int tr = tR_upper.first - tR_lower.first;
1659 tR = (double(tr_upper) * tR_lower.second + double(tr_lower) * tR_upper.second) /
double(tr);
1666 std::pair<int, double> tR;
1680 }
else if (iC == totNStrips) {
1692 std::pair<int, double> tR;
1703 }
else if (iC == 1) {
@ c_FirstRPCLayer
First RPC layer.
static int getNStrips(int section, int sector, int layer, int plane)
Get number of strips.
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
Class for accessing objects in the database.
Singleton class to cache database objects.
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
static constexpr int getMaximalStripNumber()
Get maximal strip number.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
double getStripLength(int strip) const
Get strip length.
double getMaximalStripLength() const
Get maximal strip length.
int getSubdetector() const
Get subdetector.
int getLayer() const
Get layer.
KLMChannelIndex begin()
First channel.
KLMChannelIndex & end()
Last channel.
int getSection() const
Get section.
int getPlane() const
Get plane.
int getStrip() const
Get strip.
int getSector() const
Get sector.
KLMChannelNumber getKLMChannelNumber() const
Get KLM channel number.
static const KLMElementNumbers & Instance()
Instantiation.
void channelNumberToElementNumbers(KLMChannelNumber channel, int *subdetector, int *section, int *sector, int *layer, int *plane, int *strip) const
Get element numbers by channel number.
TProfile * m_Profile2EKLMScintillatorPlane2
For EKLM scintillator plane2.
double mc_etime_channelAvg_rpc
Calibrated central value error of the global time distribution (BKLM RPC part).
TH2F * m_HistTimeLengthEKLM[2][4][14][2][75]
Two-dimensional distributions of time versus propagation length.
TH1F * h_timeFSLPC_tc[2][8][15][2][54]
BKLM part, used for effective light speed estimation.
TH2F * h2c_timeF_scint_end[2]
EKLM part.
TH1F * h_timeFSLPC_tc_end[2][4][14][2][75]
EKLM part, used for effective light speed estimation.
KLMTimeResolution * m_timeResolution
DBObject of time resolution.
TH1F * h_time_scint_tc_end
EKLM part.
void createHistograms()
Create histograms.
TGraphErrors * gre_time_channel_scint
BKLM Scintillator.
double m_LowerTimeBoundaryCalibratedScintilltorsEKLM
Lower time boundary for EKLM scintillators (calibrated data).
double m_LowerTimeBoundaryScintilltorsEKLM
Lower time boundary for EKLM scintillators.
TH1F * h_timeFSL[2][8][15]
BKLM part.
TH1F * hc_timeFSLPC_end[2][4][14][2][75]
EKLM part.
TH1F * hc_timeFSL_end[2][4][14]
EKLM part.
TH1F * h_timeFSLP_end[2][4][14][2]
EKLM part.
TGraph * gr_timeRes_channel_rpc
BKLM RPC.
TH1F * hc_timeFSLP_end[2][4][14][2]
EKLM part.
TH1F * h_timeFSLP[2][8][15][2]
BKLM part.
TH1F * hc_timeF_scint_end[2]
EKLM part.
std::map< KLMChannelNumber, double > m_timeShift
Shift values of each channel.
TH1F * h_time_scint
BKLM scintillator part.
double m_time_channelAvg_scint
Central value of the global time distribution (BKLM scintillator part).
TH1F * hc_timeFS_scint_end[2][4]
EKLM part.
double esti_timeRes(const KLMChannelIndex &klmChannel)
Estimate value of calibration constant for calibrated channels.
double m_UpperTimeBoundaryCalibratedRPC
Upper time boundary for RPC (calibrated data).
double m_ctime_channelAvg_rpc
Calibrated central value of the global time distribution (BKLM RPC part).
KLMTimeConstants * m_timeConstants
DBObject of time cost on some parts of the detector.
void setupDatabase()
Setup the database.
double m_LowerTimeBoundaryCalibratedScintilltorsBKLM
Lower time boundary for BKLM scintillators (calibrated data).
double m_UpperTimeBoundaryCalibratedScintilltorsBKLM
Upper time boundary for BKLM scintillators (calibrated data).
TH1F * hc_timeFS_scint[2][8]
BKLM scintillator part.
std::map< KLMChannelNumber, double > m_time_channel
Time distribution central value of each channel.
double m_ctime_channelAvg_scint_end
Calibrated central value of the global time distribution (EKLM scintillator part).
CalibrationAlgorithm::EResult readCalibrationData()
Read calibration data.
TGraph * gr_timeShift_channel_scint_end
EKLM.
TGraph * gr_timeRes_channel_scint
BKLM scintillator.
TH1F * hc_timeF_scint[2]
BKLM scintillator part.
TH1F * h_timeFS_scint[2][8]
BKLM scintillator part.
const KLMElementNumbers * m_ElementNumbers
Element numbers.
std::pair< int, double > tR_upperStrip(const KLMChannelIndex &klmChannel)
Tracing avaiable channels with increasing strip number.
TH1F * hc_timeF_rpc[2]
BKLM RPC part.
TH2F * h2c_timeFS_end[2][4]
EKLM part.
TH1F * h_timeFSLPC_end[2][4][14][2][75]
EKLM part.
const EKLM::GeometryData * m_EKLMGeometry
EKLM geometry data.
TGraphErrors * gre_ctime_channel_scint_end
EKLM.
TProfile * m_Profile2BKLMScintillatorPhi
For BKLM scintillator phi plane.
TH1F * hc_time_scint_end
EKLM part.
TGraphErrors * gre_time_channel_scint_end
EKLM.
TH2F * h2_timeFSLP[2][8][15][2]
BKLM part.
TGraph * gr_timeShift_channel_scint
BKLM scintillator.
double m_time_channelAvg_scint_end
Central value of the global time distribution (EKLM scintillator part).
TProfile * m_Profile2EKLMScintillatorPlane1
For EKLM scintillator plane1.
TH1F * hc_timeFS_rpc[2][8]
BKLM RPC part.
void fillTimeDistanceProfiles(TProfile *profileRpcPhi, TProfile *profileRpcZ, TProfile *profileBKLMScintillatorPhi, TProfile *profileBKLMScintillatorZ, TProfile *profileEKLMScintillatorPlane1, TProfile *profileEKLMScintillatorPlane2, bool fill2dHistograms)
Fill profiles of time versus distance.
TFile * m_outFile
Output file.
double esti_timeShift(const KLMChannelIndex &klmChannel)
Estimate value of calibration constant for uncalibrated channels.
std::pair< int, double > tS_upperStrip(const KLMChannelIndex &klmChannel)
Tracing avaiable channels with increasing strip number.
TH1F * hc_timeFSLP[2][8][15][2]
BKLM part.
TGraphErrors * gre_ctime_channel_rpc
BKLM RPC.
void saveHist()
Save histograms to file.
const bklm::GeometryPar * m_BKLMGeometry
BKLM geometry data.
TH2F * h2c_timeFSLP[2][8][15][2]
BKLM part.
double m_ctime_channelAvg_scint
Calibrated central value of the global time distribution (BKLM scintillator part).
TF1 * fcn_const
Const function.
TProfile * m_Profile2RpcZ
For BKLM RPC z plane.
TH1F * h_timeFSLPC[2][8][15][2][54]
BKLM part.
~KLMTimeAlgorithm()
Destructor.
TH2F * m_HistTimeLengthBKLM[2][8][15][2][54]
Two-dimensional distributions of time versus propagation length.
TH2F * h2_timeFSLP_end[2][4][14][2]
EKLM part.
TH1I * hc_calibrated
Calibration statistics for each channel.
void timeDistance2dFit(const std::vector< std::pair< KLMChannelNumber, unsigned int > > &channels, double &delay, double &delayError)
Two-dimensional fit for individual channels.
TGraph * gr_timeRes_channel_scint_end
EKLM.
TH1I * h_calibrated
Calibration statistics for each channel.
TProfile * m_ProfileBKLMScintillatorZ
For BKLM scintillator z plane.
TH1F * h_time_rpc_tc
BKLM RPC part.
TH1F * h_time_scint_end
EKLM part.
TH2F * h2c_timeF_scint[2]
BKLM scintillator part.
TF1 * fcn_pol1
Pol1 function.
double m_etime_channelAvg_scint_end
Central value error of the global time distribution (EKLM scintillator part).
TH1F * hc_time_rpc
BKLM RPC part.
double mc_etime_channelAvg_scint
Calibrated central value error of the global time distribution (BKLM scintillator part).
TH2F * h2c_timeFSLP_end[2][4][14][2]
EKLM part.
double mc_etime_channelAvg_scint_end
Calibrated central value error of the global time distribution (EKLM scintillator part).
TH2F * h2_timeF_scint_end[2]
EKLM part.
double m_UpperTimeBoundaryScintilltorsBKLM
Upper time boundary for BKLM scintillators.
TF1 * fcn_gaus
Gaussian function.
TH1F * h_timeF_rpc[2]
BKLM RPC part.
TProfile * m_ProfileBKLMScintillatorPhi
For BKLM scintillator phi plane.
TH1F * hc_time_scint
BKLM scintillator part.
TH2F * h2_timeFS[2][8]
BKLM part.
double m_etime_channelAvg_scint
Central value error of the global time distribution (BKLM scintillator part).
double m_UpperTimeBoundaryCalibratedScintilltorsEKLM
Upper time boundary for BKLM scintillators (calibrated data).
TH1F * h_timeF_scint_end[2]
EKLM part.
TProfile * m_ProfileRpcPhi
For BKLM RPC phi plane.
TGraphErrors * gre_ctime_channel_scint
BKLM Scintillator.
TProfile * m_ProfileEKLMScintillatorPlane2
For EKLM scintillator plane2.
TH1F * h_time_rpc
BKLM RPC part.
TH1F * h_timeFSL_end[2][4][14]
EKLM part.
TProfile * m_Profile2RpcPhi
For BKLM RPC phi plane.
TH1F * h_timeF_scint[2]
BKLM scintillator part.
TH1F * hc_timeFSL[2][8][15]
BKLM part.
TProfile * m_Profile2BKLMScintillatorZ
For BKLM scintillator z plane.
TH1F * h_timeFS_rpc[2][8]
BKLM RPC part.
KLMChannelIndex m_klmChannels
KLM ChannelIndex object.
TGraph * gr_timeShift_channel_rpc
BKLM RPC.
std::map< KLMChannelNumber, double > m_timeRes
Resolution values of each channel.
TH1F * h_diff
Distance between global and local position.
TH2F * h2_timeF_scint[2]
BKLM scintillator part.
TH1F * h_time_scint_tc
BKLM scintillator part.
double m_LowerTimeBoundaryRPC
Lower time boundary for RPC.
virtual EResult calibrate() override
Run algorithm on data.
std::map< KLMChannelNumber, double > m_ctime_channel
Calibrated time distribution central value of each channel.
double m_LowerTimeBoundaryCalibratedRPC
Lower time boundary for RPC (calibrated data).
bool m_useEventT0
Whether to use event T0 from CDC.
int m_MinimalDigitNumber
Minimal digit number (total).
TProfile * m_ProfileEKLMScintillatorPlane1
For EKLM scintillator plane1.
double m_UpperTimeBoundaryRPC
Upper time boundary for RPC.
TH2F * h2c_timeF_rpc[2]
BKLM RPC part.
TF1 * fcn_land
Landau function.
KLMTimeCableDelay * m_timeCableDelay
DBObject of the calibration constant of each channel due to cable decay.
std::pair< int, double > tS_lowerStrip(const KLMChannelIndex &klmChannel)
Tracing avaiable channels with decreasing strip number.
TProfile * m_ProfileRpcZ
For BKLM RPC z plane.
std::map< KLMChannelNumber, double > mc_etime_channel
Calibrated time distribution central value Error of each channel.
std::pair< int, double > tR_lowerStrip(const KLMChannelIndex &klmChannel)
Tracing avaiable channels with decreasing strip number.
double m_LowerTimeBoundaryScintilltorsBKLM
Lower time boundary for BKLM scintillators.
TH1F * hc_timeFSLPC[2][8][15][2][54]
BKLM part.
ROOT::Math::MinimizerOptions m_minimizerOptions
Minimization options.
std::map< KLMChannelNumber, int > m_cFlag
Calibration flag if the channel has enough hits collected and fitted OK.
TGraphErrors * gre_time_channel_rpc
BKLM RPC.
TH2F * h2_timeFS_end[2][4]
EKLM part.
TH2F * h2_timeF_rpc[2]
BKLM RPC part.
std::map< KLMChannelNumber, std::vector< struct Event > > m_evts
Container of hit information.
TH1F * h_timeFS_scint_end[2][4]
EKLM part.
double m_time_channelAvg_rpc
Central value of the global time distribution (BKLM RPC part).
TH2F * h2c_timeFS[2][8]
BKLM part.
double m_etime_channelAvg_rpc
Central value error of the global time distribution (BKLM RPC part).
KLMTimeAlgorithm()
Constructor.
std::map< KLMChannelNumber, double > m_etime_channel
Time distribution central value Error of each channel.
double m_UpperTimeBoundaryScintilltorsEKLM
Upper time boundary for BKLM scintillators.
int m_lower_limit_counts
Lower limit of hits collected for on single channel.
Class to store BKLM delay time coused by cable in the database.
void setTimeDelay(KLMChannelNumber channel, float timeDelay)
Set the time calibration constant.
Class to store KLM constants related to time.
@ c_BKLM
BKLM scintillator.
@ c_EKLM
EKLM scintillator.
void setDelay(float delay, int cType)
Set effective light speed of scintillators.
Class to store KLM time resolution in the database.
void setTimeResolution(KLMChannelNumber channel, float resolution)
Set time resolution.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
bool construct(Args &&... params)
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
static const double cm
Standard units with the value = 1.
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
double getMaximalZStripLength() const
Get maximal Z strip length (for scintillators).
static GeometryPar * instance(void)
Static method to get a reference to the singleton GeometryPar instance.
double getMaximalPhiStripLength() const
Get maximal phi strip length (for scintillators).
Define the geometry of a BKLM module Each sector [octant] contains Modules.
Class to store variables with their name which were sent to the logging service.
static DBStore & Instance()
Instance of a singleton DBStore.
void updateEvent()
Updates all intra-run dependent objects.
void update()
Updates all objects that are outside their interval of validity.
double sqrt(double a)
sqrt for double
uint16_t KLMChannelNumber
Channel number.
Abstract base class for different kinds of events.