312 TDirectory* dir_channels =
m_outFile->mkdir(
"channels",
"Per-channel histograms",
true);
315 TDirectory* dir_bklm = dir_channels->mkdir(
"BKLM",
"",
true);
316 TString sectionName[2] = {
"Backward",
"Forward"};
317 TString planeName[2] = {
"Z",
"Phi"};
319 for (
int iF = 0; iF < 2; ++iF) {
320 TDirectory* dir_section = dir_bklm->mkdir(sectionName[iF].Data(),
"",
true);
321 for (
int iS = 0; iS < 8; ++iS) {
322 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
323 for (
int iL = 0; iL < 15; ++iL) {
324 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
325 for (
int iP = 0; iP < 2; ++iP) {
326 m_channelHistDir_BKLM[iF][iS][iL][iP] = dir_layer->mkdir(Form(
"Plane_%s", planeName[iP].Data()),
"",
true);
333 TDirectory* dir_eklm = dir_channels->mkdir(
"EKLM",
"",
true);
334 for (
int iF = 0; iF < 2; ++iF) {
335 TDirectory* dir_section = dir_eklm->mkdir(sectionName[iF].Data(),
"",
true);
336 for (
int iS = 0; iS < 4; ++iS) {
337 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
338 int maxLayer = 12 + 2 * iF;
339 for (
int iL = 0; iL < maxLayer; ++iL) {
340 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
341 for (
int iP = 0; iP < 2; ++iP) {
349 B2INFO(
"Created directory structure for per-channel histograms.");
355 TString iFstring[2] = {
"Backward",
"Forward"};
356 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
359 h_diff =
new TH1F(
"h_diff",
"Position difference between bklmHit2d and extHit;position difference", 100, 0, 10);
360 h_calibrated =
new TH1I(
"h_calibrated_summary",
"h_calibrated_summary;calibrated or not", 3, 0, 3);
361 hc_calibrated =
new TH1I(
"hc_calibrated_summary",
"hc_calibrated_summary;calibrated or not", 3, 0, 3);
379 double maximalPhiStripLengthBKLM =
381 double maximalZStripLengthBKLM =
383 double maximalStripLengthEKLM =
387 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
390 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
393 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
394 50, 0.0, maximalPhiStripLengthBKLM);
396 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
397 50, 0.0, maximalZStripLengthBKLM);
399 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
400 50, 0.0, maximalStripLengthEKLM);
402 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
403 50, 0.0, maximalStripLengthEKLM);
406 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
409 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
412 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
413 50, 0.0, maximalPhiStripLengthBKLM);
415 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
416 50, 0.0, maximalZStripLengthBKLM);
418 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
419 50, 0.0, maximalStripLengthEKLM);
421 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
422 50, 0.0, maximalStripLengthEKLM);
425 h_time_scint_tc =
new TH1F(
"h_time_scint_tc",
"time distribution for Scintillator", nBin_scint,
427 h_time_scint_tc_end =
new TH1F(
"h_time_scint_tc_end",
"time distribution for Scintillator (Endcap)", nBin_scint,
434 h_time_scint =
new TH1F(
"h_time_scint",
"time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation[ns]", nBin_scint,
436 h_time_scint_end =
new TH1F(
"h_time_scint_end",
"time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
439 hc_time_rpc =
new TH1F(
"hc_time_rpc",
"Calibrated time distribution for RPC; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
442 "Calibrated time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
446 "Calibrated time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
451 "RPC: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
453 "BKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
455 "EKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
459 "RPC: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
461 "BKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
463 "EKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -20.0, 20.0);
468 "BKLM scintillator: #DeltaT_{0}/#sqrt{v}; z [ns]", 400, -100.0, 100.0);
470 "BKLM RPC #phi: #DeltaT_{0}/#sqrt{v}; z [ns]", 400, -200.0, 200.0);
472 "BKLM RPC z: #DeltaT_{0}/#sqrt{v}; z [ns]", 400, -200.0, 200.0);
474 "BKLM RPC #phi and z: #DeltaT_{0}/#sqrt{v}; z [ns]", 400, -200.0, 200.0);
476 "EKLM scintillator: #DeltaT_{0}/#sqrt{v}; z [ns]", 400, -100.0, 100.0);
482 "RPC: #mu^{+} hit multiplicity;N_{hits};Events", 100, 0, 100);
484 "RPC: #mu^{-} hit multiplicity;N_{hits};Events", 100, 0, 100);
486 "BKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
488 "BKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
490 "EKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
492 "EKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
496 "RPC: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
497 50, 0, 2.0, 100, -40, 40);
499 "BKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
500 50, 0, 1.0, 100, -40, 40);
502 "EKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
503 50, 0, 1.0, 100, -20, 20);
507 "RPC: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
510 "BKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
513 "EKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
518 "RPC: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
519 50, 0, 200, 100, -40, 40);
521 "BKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
522 40, 0, 40, 100, -40, 40);
524 "EKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
525 40, 0, 40, 100, -20, 20);
529 "RPC: #DeltaT_{0} (N^{+}+N^{-} < 10);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
531 "RPC: #DeltaT_{0} (10 #leq N^{+}+N^{-} < 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
533 "RPC: #DeltaT_{0} (N^{+}+N^{-} #geq 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
536 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
538 "BKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
540 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
543 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
545 "EKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
547 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
550 B2INFO(
"Skipping debug histogram allocation (m_saveAllPlots = false)");
554 for (
int iF = 0; iF < 2; ++iF) {
555 hn = Form(
"h_timeF%d_rpc", iF);
556 ht = Form(
"Time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
558 hn = Form(
"h_timeF%d_scint", iF);
559 ht = Form(
"Time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
562 hn = Form(
"h_timeF%d_scint_end", iF);
563 ht = Form(
"Time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
567 hn = Form(
"h2_timeF%d_rpc", iF);
568 ht = Form(
"Time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
570 hn = Form(
"h2_timeF%d_scint", iF);
571 ht = Form(
"Time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
574 hn = Form(
"h2_timeF%d_scint_end", iF);
575 ht = Form(
"Time distribution for Scintillator of %s (Endcap); Sector Index; T_rec-T_0-T_fly-T_propagation[ns]",
576 iFstring[iF].Data());
580 hn = Form(
"hc_timeF%d_rpc", iF);
581 ht = Form(
"Calibrated time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iFstring[iF].Data());
583 hn = Form(
"hc_timeF%d_scint", iF);
584 ht = Form(
"Calibrated time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
585 iFstring[iF].Data());
588 hn = Form(
"hc_timeF%d_scint_end", iF);
589 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
590 iFstring[iF].Data());
594 hn = Form(
"h2c_timeF%d_rpc", iF);
595 ht = Form(
"Calibrated time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
596 iFstring[iF].Data());
599 hn = Form(
"h2c_timeF%d_scint", iF);
600 ht = Form(
"Calibrated time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
601 iFstring[iF].Data());
604 hn = Form(
"h2c_timeF%d_scint_end", iF);
605 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap) ; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
606 iFstring[iF].Data());
610 for (
int iS = 0; iS < 8; ++iS) {
612 hn = Form(
"h_timeF%d_S%d_scint", iF, iS);
613 ht = Form(
"Time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
616 hn = Form(
"h_timeF%d_S%d_rpc", iF, iS);
617 ht = Form(
"Time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
619 hn = Form(
"h2_timeF%d_S%d", iF, iS);
620 ht = Form(
"Time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
624 hn = Form(
"hc_timeF%d_S%d_scint", iF, iS);
625 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
626 iFstring[iF].Data());
629 hn = Form(
"hc_timeF%d_S%d_rpc", iF, iS);
630 ht = Form(
"Calibrated time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
631 iFstring[iF].Data());
634 hn = Form(
"h2c_timeF%d_S%d", iF, iS);
635 ht = Form(
"Calibrated time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
636 iFstring[iF].Data());
641 for (
int iL = 0; iL < 2; ++iL) {
642 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
643 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
644 iFstring[iF].Data());
647 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
648 ht = Form(
"Calibrated time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
649 iL, iS, iFstring[iF].Data());
653 for (
int iP = 0; iP < 2; ++iP) {
654 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
655 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]",
656 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
659 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
660 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
661 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
665 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
666 ht = Form(
"Calibrated time distribution for Scintillator of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
667 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
670 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
671 ht = Form(
"Calibrated time distribution for Scintillator of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
672 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
678 for (
int iL = 2; iL < 15; ++iL) {
679 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
680 ht = Form(
"time distribution for RPC of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iL, iS, iFstring[iF].Data());
683 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
684 ht = Form(
"Calibrated time distribution for RPC of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iL, iS,
685 iFstring[iF].Data());
688 for (
int iP = 0; iP < 2; ++iP) {
689 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
690 ht = Form(
"time distribution for RPC of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iPstring[iP].Data(), iL, iS,
691 iFstring[iF].Data());
694 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
695 ht = Form(
"time distribution for RPC of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
696 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
699 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
700 ht = Form(
"Calibrated time distribution for RPC of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
701 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
705 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
706 ht = Form(
"Calibrated time distribution for RPC of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
707 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
714 int maxLay = 12 + 2 * iF;
715 for (
int iS = 0; iS < 4; ++iS) {
716 hn = Form(
"h_timeF%d_S%d_scint_end", iF, iS);
717 ht = Form(
"Time distribution for Scintillator of Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iS,
718 iFstring[iF].Data());
721 hn = Form(
"h2_timeF%d_S%d_end", iF, iS);
722 ht = Form(
"Time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
725 hn = Form(
"hc_timeF%d_S%d_scint_end", iF, iS);
726 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d (Endcap), %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
727 iS, iFstring[iF].Data());
730 hn = Form(
"h2c_timeF%d_S%d_end", iF, iS);
731 ht = Form(
"Calibrated time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
732 iS, iFstring[iF].Data());
733 h2c_timeFS_end[iF][iS] =
new TH2F(hn.Data(), ht.Data(), maxLay, 0, maxLay, nBin_scint,
737 for (
int iL = 0; iL < maxLay; ++iL) {
738 hn = Form(
"h_timeF%d_S%d_L%d_end", iF, iS, iL);
739 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
740 iFstring[iF].Data());
743 hn = Form(
"hc_timeF%d_S%d_L%d_end", iF, iS, iL);
744 ht = Form(
"Calibrated time distribution for Scintillator of Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
745 iL, iS, iFstring[iF].Data());
749 for (
int iP = 0; iP < 2; ++iP) {
750 hn = Form(
"h_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
751 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
752 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
756 hn = Form(
"h2_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
757 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
758 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
762 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
763 ht = Form(
"Calibrated time distribution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
764 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
768 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
769 ht = Form(
"Calibrated time distribution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); Channel Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
770 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
771 h2c_timeFSLP_end[iF][iS][iL][iP] =
new TH2F(hn.Data(), ht.Data(), 75, 0, 75, nBin_scint,
1137 gROOT->SetBatch(kTRUE);
1144 fcn_gaus =
new TF1(
"fcn_gaus",
"gaus");
1145 fcn_land =
new TF1(
"fcn_land",
"landau");
1146 fcn_pol1 =
new TF1(
"fcn_pol1",
"pol1");
1147 fcn_const =
new TF1(
"fcn_const",
"pol0");
1155 std::string name =
"time_calibration.root";
1159 if (stat(name.c_str(), &buffer) != 0)
1161 name =
"time_calibration_" + std::to_string(i) +
".root";
1166 m_outFile =
new TFile(name.c_str(),
"recreate");
1169 std::vector<struct Event> eventsChannel;
1170 eventsChannel.clear();
1174 B2INFO(
"Counting events per channel...");
1175 std::map<KLMChannelNumber, unsigned int> eventCounts;
1179 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsBKLM;
1180 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsEKLM;
1185 m_cFlag[channel] = ChannelCalibrationStatus::c_NotEnoughData;
1187 if (eventCounts.find(channel) == eventCounts.end())
1190 int nEvents = eventCounts[channel];
1192 B2WARNING(
"Not enough calibration data collected."
1193 <<
LogVar(
"channel", channel)
1194 <<
LogVar(
"number of digit", nEvents));
1198 m_cFlag[channel] = ChannelCalibrationStatus::c_FailedFit;
1202 channelsBKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1205 channelsEKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1209 std::sort(channelsBKLM.begin(), channelsBKLM.end(), compareEventNumber);
1210 std::sort(channelsEKLM.begin(), channelsEKLM.end(), compareEventNumber);
1213 double delayBKLM, delayBKLMError;
1214 double delayEKLM, delayEKLMError;
1222 B2INFO(
"2D fits complete, data cleared.");
1259 std::vector<std::pair<std::string, std::function<bool(
const KLMChannelIndex&)>>> batches = {
1260 {
"RPC Backward", isRPCBackward},
1261 {
"RPC Forward", isRPCForward},
1262 {
"BKLM Scintillator Backward", isBKLMScintillatorBackward},
1263 {
"BKLM Scintillator Forward", isBKLMScintillatorForward},
1264 {
"EKLM Scintillator Backward", isEKLMScintillatorBackward},
1265 {
"EKLM Scintillator Forward", isEKLMScintillatorForward}
1272 B2INFO(
"First loop: Computing global statistics (batched processing)...");
1274 TString iFstring[2] = {
"Backward",
"Forward"};
1275 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
1277 int nBin_scint = 80;
1279 for (
const auto& batch : batches) {
1280 B2INFO(
"Processing batch for global stats: " << batch.first);
1284 channelId = klmChannel.getKLMChannelNumber();
1286 if (!batch.second(klmChannel))
1289 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1295 eventsChannel =
m_evts[channelId];
1296 int iSub = klmChannel.getSubdetector();
1300 for (
const Event& event : eventsChannel) {
1305 XYZVector diffD = XYZVector(event.diffDistX, event.diffDistY, event.diffDistZ);
1308 double timeHit =
event.time();
1310 timeHit = timeHit -
event.t0;
1312 if (timeHit <= -400e3)
1329 B2INFO(
"Batch processed and cleared: " << batch.first);
1338 B2INFO(
"Global Mean for Raw." <<
LogVar(
"RPC", tmpMean_rpc_global)
1339 <<
LogVar(
"Scint BKLM", tmpMean_scint_global)
1340 <<
LogVar(
"Scint EKLM", tmpMean_scint_global_end));
1346 B2INFO(
"Second pass: Computing per-channel time shifts (batched processing)...");
1348 for (
const auto& batch : batches) {
1349 B2INFO(
"Processing batch for time shifts: " << batch.first);
1353 channelId = klmChannel.getKLMChannelNumber();
1355 if (!batch.second(klmChannel))
1358 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1364 eventsChannel =
m_evts[channelId];
1365 int iSub = klmChannel.getSubdetector();
1366 int iF, iS, iL, iP, iC;
1369 iF = klmChannel.getSection();
1370 iS = klmChannel.getSector() - 1;
1371 iL = klmChannel.getLayer() - 1;
1372 iP = klmChannel.getPlane();
1373 iC = klmChannel.getStrip() - 1;
1375 iF = klmChannel.getSection() - 1;
1376 iS = klmChannel.getSector() - 1;
1377 iL = klmChannel.getLayer() - 1;
1378 iP = klmChannel.getPlane() - 1;
1379 iC = klmChannel.getStrip() - 1;
1384 TH1F* h_temp_tc =
nullptr;
1389 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1390 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1391 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1394 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1395 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1396 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1401 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc_end", iF, iS, iL, iP, iC);
1402 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1403 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1408 for (
const Event& event : eventsChannel) {
1413 double timeHit =
event.time();
1415 timeHit = timeHit -
event.t0;
1416 if (timeHit <= -400e3)
1418 h_temp_tc->Fill(timeHit);
1422 double tmpMean_channel =
fcn_gaus->GetParameter(1);
1427 m_timeShift[channelId] = tmpMean_channel - tmpMean_rpc_global;
1429 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global;
1432 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global_end;
1439 B2INFO(
"Batch processed and cleared: " << batch.first);
1445 B2INFO(
"Effective Light m_timeShift obtained.");
1453 B2INFO(
"Effective light speed fitting.");
1457 double fittedDelayRPCPhi =
fcn_pol1->GetParameter(1);
1458 double e_slope_rpc_phi =
fcn_pol1->GetParError(1);
1461 double fittedDelayRPCZ =
fcn_pol1->GetParameter(1);
1462 double e_slope_rpc_z =
fcn_pol1->GetParError(1);
1465 double delayRPCPhi, delayRPCZ;
1469 B2INFO(
"Using fixed RPC propagation delay: " <<
m_fixedRPCDelay <<
" ns/cm (c_eff = 0.5c)"
1470 <<
LogVar(
"Fitted phi (not used)", fittedDelayRPCPhi)
1471 <<
LogVar(
"Fitted Z (not used)", fittedDelayRPCZ));
1473 delayRPCPhi = fittedDelayRPCPhi;
1474 delayRPCZ = fittedDelayRPCZ;
1478 double slope_scint_phi =
fcn_pol1->GetParameter(1);
1479 double e_slope_scint_phi =
fcn_pol1->GetParError(1);
1482 double slope_scint_z =
fcn_pol1->GetParameter(1);
1483 double e_slope_scint_z =
fcn_pol1->GetParError(1);
1486 double slope_scint_plane1_end =
fcn_pol1->GetParameter(1);
1487 double e_slope_scint_plane1_end =
fcn_pol1->GetParError(1);
1490 double slope_scint_plane2_end =
fcn_pol1->GetParameter(1);
1491 double e_slope_scint_plane2_end =
fcn_pol1->GetParError(1);
1493 TString logStr_phi, logStr_z;
1495 logStr_phi = Form(
"%.4f ns/cm (fixed)", delayRPCPhi);
1496 logStr_z = Form(
"%.4f ns/cm (fixed)", delayRPCZ);
1497 B2INFO(
"Delay in RPCs (using fixed value):"
1498 <<
LogVar(
"Used Value (phi readout)", logStr_phi.Data())
1499 <<
LogVar(
"Used Value (z readout)", logStr_z.Data()));
1501 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", delayRPCPhi, e_slope_rpc_phi);
1502 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayRPCZ, e_slope_rpc_z);
1503 B2INFO(
"Delay in RPCs:"
1504 <<
LogVar(
"Fitted Value (phi readout)", logStr_phi.Data())
1505 <<
LogVar(
"Fitted Value (z readout)", logStr_z.Data()));
1507 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_phi, e_slope_scint_phi);
1508 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_z, e_slope_scint_z);
1509 B2INFO(
"Delay in BKLM scintillators:"
1510 <<
LogVar(
"Fitted Value (phi readout) ", logStr_phi.Data())
1511 <<
LogVar(
"Fitted Value (z readout) ", logStr_z.Data()));
1512 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane1_end,
1513 e_slope_scint_plane1_end);
1514 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane2_end,
1515 e_slope_scint_plane2_end);
1516 B2INFO(
"Delay in EKLM scintillators:"
1517 <<
LogVar(
"Fitted Value (plane1 readout) ", logStr_phi.Data())
1518 <<
LogVar(
"Fitted Value (plane2 readout) ", logStr_z.Data()));
1520 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayBKLM, delayBKLMError);
1521 B2INFO(
"Delay in BKLM scintillators:"
1522 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1523 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayEKLM, delayEKLMError);
1524 B2INFO(
"Delay in EKLM scintillators:"
1525 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1536 B2INFO(
"Third loop: Time distribution filling (batched processing)...");
1538 for (
const auto& batch : batches) {
1539 B2INFO(
"Processing batch: " << batch.first);
1543 channelId = klmChannel.getKLMChannelNumber();
1545 if (!batch.second(klmChannel))
1548 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1554 eventsChannel =
m_evts[channelId];
1555 int iSub = klmChannel.getSubdetector();
1556 int iF, iS, iL, iP, iC;
1559 iF = klmChannel.getSection();
1560 iS = klmChannel.getSector() - 1;
1561 iL = klmChannel.getLayer() - 1;
1562 iP = klmChannel.getPlane();
1563 iC = klmChannel.getStrip() - 1;
1565 iF = klmChannel.getSection() - 1;
1566 iS = klmChannel.getSector() - 1;
1567 iL = klmChannel.getLayer() - 1;
1568 iP = klmChannel.getPlane() - 1;
1569 iC = klmChannel.getStrip() - 1;
1574 TH1F* h_temp =
nullptr;
1579 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1580 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1581 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1584 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1585 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1586 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1591 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1592 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1593 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1599 for (
const Event& event : eventsChannel) {
1604 double timeHit =
event.time();
1606 timeHit = timeHit -
event.t0;
1607 if (timeHit <= -400e3)
1615 propgationT =
event.dist * delayRPCZ;
1617 propgationT =
event.dist * delayRPCPhi;
1618 double time = timeHit - propgationT;
1633 double propgationT =
event.dist * delayBKLM;
1634 double time = timeHit - propgationT;
1650 double propgationT =
event.dist * delayEKLM;
1651 double time = timeHit - propgationT;
1668 TFitResultPtr r = h_temp->Fit(
fcn_gaus,
"LESQ");
1670 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1683 B2INFO(
"Batch processed and cleared: " << batch.first);
1686 B2INFO(
"Original filling done.");
1689 int iChannel_rpc = 0;
1691 int iChannel_end = 0;
1693 channelId = klmChannel.getKLMChannelNumber();
1694 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1697 int iSub = klmChannel.getSubdetector();
1699 int iL = klmChannel.getLayer() - 1;
1729 B2INFO(
"Channel's time distribution fitting done.");
1734 B2INFO(
"Calibrated channel's time distribution filling begins.");
1738 channelId = klmChannel.getKLMChannelNumber();
1748 channelId = klmChannel.getKLMChannelNumber();
1753 B2DEBUG(20,
"Uncalibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeShift[channelId]));
1760 channelId = klmChannel.getKLMChannelNumber();
1762 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
1765 int iSub = klmChannel.getSubdetector();
1768 int iL = klmChannel.getLayer() - 1;
1792 B2INFO(
"Fourth loop: Calibrated time distribution filling (batched processing)...");
1794 for (
const auto& batch : batches) {
1795 B2INFO(
"Processing batch: " << batch.first);
1799 channelId = klmChannel.getKLMChannelNumber();
1801 if (!batch.second(klmChannel))
1807 eventsChannel =
m_evts[channelId];
1808 int iSub = klmChannel.getSubdetector();
1809 int iF, iS, iL, iP, iC;
1812 iF = klmChannel.getSection();
1813 iS = klmChannel.getSector() - 1;
1814 iL = klmChannel.getLayer() - 1;
1815 iP = klmChannel.getPlane();
1816 iC = klmChannel.getStrip() - 1;
1818 iF = klmChannel.getSection() - 1;
1819 iS = klmChannel.getSector() - 1;
1820 iL = klmChannel.getLayer() - 1;
1821 iP = klmChannel.getPlane() - 1;
1822 iC = klmChannel.getStrip() - 1;
1826 TH1F* hc_temp =
nullptr;
1831 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1832 ht = Form(
"Calibrated time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1833 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1837 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1838 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1839 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1844 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1845 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1846 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1851 for (
const Event& event : eventsChannel) {
1856 double timeHit =
event.time();
1858 timeHit = timeHit -
event.t0;
1859 if (timeHit <= -400e3)
1867 propgationT =
event.dist * delayRPCZ;
1869 propgationT =
event.dist * delayRPCPhi;
1870 double time = timeHit - propgationT -
m_timeShift[channelId];
1873 hc_temp->Fill(time);
1885 double propgationT =
event.dist * delayBKLM;
1886 double time = timeHit - propgationT -
m_timeShift[channelId];
1889 hc_temp->Fill(time);
1902 double propgationT =
event.dist * delayEKLM;
1903 double time = timeHit - propgationT -
m_timeShift[channelId];
1906 hc_temp->Fill(time);
1920 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData) {
1925 TFitResultPtr rc = hc_temp->Fit(
fcn_gaus,
"LESQ");
1927 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1940 B2INFO(
"Batch processed and cleared: " << batch.first);
1944 int icChannel_rpc = 0;
1946 int icChannel_end = 0;
1948 channelId = klmChannel.getKLMChannelNumber();
1949 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1952 int iSub = klmChannel.getSubdetector();
1954 int iL = klmChannel.getLayer() - 1;
1984 B2INFO(
"Channel's time distribution fitting done.");
1989 B2INFO(
"Calibrated channel's time distribution filling begins.");
1993 channelId = klmChannel.getKLMChannelNumber();
2003 channelId = klmChannel.getKLMChannelNumber();
2008 B2DEBUG(20,
"Calibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeRes[channelId]));
2015 channelId = klmChannel.getKLMChannelNumber();
2017 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
2020 int iSub = klmChannel.getSubdetector();
2023 int iL = klmChannel.getLayer() - 1;
2040 B2INFO(
"Fifth pass: Computing di-muon ΔT0 for EventT0 hit resolution calibration...");
2043 struct TrackT0Info {
2045 int nHits_BKLM_Scint;
2046 int nHits_BKLM_RPC_Phi;
2047 int nHits_BKLM_RPC_Z;
2048 int nHits_EKLM_Scint;
2050 double sumT0_BKLM_Scint;
2051 double sumT0_BKLM_RPC_Phi;
2052 double sumT0_BKLM_RPC_Z;
2053 double sumT0_EKLM_Scint;
2054 double sumT0_BKLM_RPC;
2056 TrackT0Info() : charge(0),
2057 nHits_BKLM_Scint(0),
2058 nHits_BKLM_RPC_Phi(0),
2059 nHits_BKLM_RPC_Z(0),
2060 nHits_EKLM_Scint(0),
2062 sumT0_BKLM_Scint(0.0),
2063 sumT0_BKLM_RPC_Phi(0.0),
2064 sumT0_BKLM_RPC_Z(0.0),
2065 sumT0_EKLM_Scint(0.0),
2066 sumT0_BKLM_RPC(0.0) {}
2070 std::map<std::pair<int, int>, std::map<int, TrackT0Info>> eventTrackMap;
2073 for (
const auto& batch : batches) {
2074 B2INFO(
"Processing batch for di-muon analysis: " << batch.first);
2077 for (
const auto& channelPair :
m_evts) {
2079 const std::vector<Event>& chEvents = channelPair.second;
2082 int subdetector, section, sector, layer, plane, strip;
2084 chId, &subdetector, §ion, §or, &layer, &plane, &strip);
2087 int iSub = subdetector;
2090 for (
const Event& event : chEvents) {
2096 std::pair<int, int> eventKey(event.Run, event.Events);
2097 int trackIdx =
event.nTrack;
2098 int charge =
event.Track_Charge;
2101 double timeHit =
event.time() -
m_timeShift[chId];
2103 if (timeHit <= -400e3)
2112 propT =
event.dist * delayRPCZ;
2114 propT =
event.dist * delayRPCPhi;
2117 propT =
event.dist * delayBKLM;
2121 propT =
event.dist * delayEKLM;
2124 double t0_estimate = timeHit - propT;
2127 TrackT0Info& trackInfo = eventTrackMap[eventKey][trackIdx];
2128 trackInfo.charge = charge;
2133 trackInfo.nHits_BKLM_RPC++;
2134 trackInfo.sumT0_BKLM_RPC += t0_estimate;
2137 trackInfo.nHits_BKLM_RPC_Z++;
2138 trackInfo.sumT0_BKLM_RPC_Z += t0_estimate;
2140 trackInfo.nHits_BKLM_RPC_Phi++;
2141 trackInfo.sumT0_BKLM_RPC_Phi += t0_estimate;
2145 trackInfo.nHits_BKLM_Scint++;
2146 trackInfo.sumT0_BKLM_Scint += t0_estimate;
2149 trackInfo.nHits_EKLM_Scint++;
2150 trackInfo.sumT0_EKLM_Scint += t0_estimate;
2158 B2INFO(
"Event-track map built. Processing events for EventT0 histograms...");
2162 double sum_delta2_over_v_BKLM_Scint = 0.0;
2163 double sum_delta2_over_v_BKLM_RPC_Phi = 0.0;
2164 double sum_delta2_over_v_BKLM_RPC_Z = 0.0;
2165 double sum_delta2_over_v_EKLM_Scint = 0.0;
2166 double sum_delta2_over_v_BKLM_RPC = 0.0;
2168 int nDimuon_BKLM_Scint = 0;
2169 int nDimuon_BKLM_RPC_Phi = 0;
2170 int nDimuon_BKLM_RPC_Z = 0;
2171 int nDimuon_EKLM_Scint = 0;
2172 int nDimuon_BKLM_RPC = 0;
2174 for (
const auto& eventPair : eventTrackMap) {
2175 const auto& trackMap = eventPair.second;
2178 if (trackMap.size() != 2)
2181 auto it1 = trackMap.begin();
2182 auto it2 = trackMap.begin();
2184 const TrackT0Info& track1 = it1->second;
2185 const TrackT0Info& track2 = it2->second;
2188 if (track1.charge * track2.charge >= 0)
2192 const TrackT0Info& muPlus = (track1.charge > 0) ? track1 : track2;
2193 const TrackT0Info& muMinus = (track1.charge > 0) ? track2 : track1;
2196 if (muPlus.nHits_BKLM_Scint > 0 && muMinus.nHits_BKLM_Scint > 0) {
2197 double t0_plus = muPlus.sumT0_BKLM_Scint / muPlus.nHits_BKLM_Scint;
2198 double t0_minus = muMinus.sumT0_BKLM_Scint / muMinus.nHits_BKLM_Scint;
2199 double deltaT0 = t0_plus - t0_minus;
2202 double v = 1.0 / muPlus.nHits_BKLM_Scint + 1.0 / muMinus.nHits_BKLM_Scint;
2203 int nTotal = muPlus.nHits_BKLM_Scint + muMinus.nHits_BKLM_Scint;
2209 sum_delta2_over_v_BKLM_Scint += (deltaT0 * deltaT0) / v;
2211 nDimuon_BKLM_Scint++;
2228 }
else if (nTotal < 15) {
2236 if (muPlus.nHits_BKLM_RPC_Phi > 0 && muMinus.nHits_BKLM_RPC_Phi > 0) {
2237 double t0_plus = muPlus.sumT0_BKLM_RPC_Phi / muPlus.nHits_BKLM_RPC_Phi;
2238 double t0_minus = muMinus.sumT0_BKLM_RPC_Phi / muMinus.nHits_BKLM_RPC_Phi;
2239 double deltaT0 = t0_plus - t0_minus;
2241 double v = 1.0 / muPlus.nHits_BKLM_RPC_Phi + 1.0 / muMinus.nHits_BKLM_RPC_Phi;
2242 int nTotal = muPlus.nHits_BKLM_RPC_Phi + muMinus.nHits_BKLM_RPC_Phi;
2247 sum_delta2_over_v_BKLM_RPC_Phi += (deltaT0 * deltaT0) / v;
2249 nDimuon_BKLM_RPC_Phi++;
2264 }
else if (nTotal < 30) {
2272 if (muPlus.nHits_BKLM_RPC_Z > 0 && muMinus.nHits_BKLM_RPC_Z > 0) {
2273 double t0_plus = muPlus.sumT0_BKLM_RPC_Z / muPlus.nHits_BKLM_RPC_Z;
2274 double t0_minus = muMinus.sumT0_BKLM_RPC_Z / muMinus.nHits_BKLM_RPC_Z;
2275 double deltaT0 = t0_plus - t0_minus;
2277 double v = 1.0 / muPlus.nHits_BKLM_RPC_Z + 1.0 / muMinus.nHits_BKLM_RPC_Z;
2278 int nTotal = muPlus.nHits_BKLM_RPC_Z + muMinus.nHits_BKLM_RPC_Z;
2283 sum_delta2_over_v_BKLM_RPC_Z += (deltaT0 * deltaT0) / v;
2285 nDimuon_BKLM_RPC_Z++;
2300 }
else if (nTotal < 30) {
2308 if (muPlus.nHits_BKLM_RPC > 0 && muMinus.nHits_BKLM_RPC > 0) {
2309 double deltaT0 = muPlus.sumT0_BKLM_RPC / muPlus.nHits_BKLM_RPC
2310 - muMinus.sumT0_BKLM_RPC / muMinus.nHits_BKLM_RPC;
2311 double v = 1.0 / muPlus.nHits_BKLM_RPC + 1.0 / muMinus.nHits_BKLM_RPC;
2312 sum_delta2_over_v_BKLM_RPC += (deltaT0 * deltaT0) / v;
2318 if (muPlus.nHits_EKLM_Scint > 0 && muMinus.nHits_EKLM_Scint > 0) {
2319 double t0_plus = muPlus.sumT0_EKLM_Scint / muPlus.nHits_EKLM_Scint;
2320 double t0_minus = muMinus.sumT0_EKLM_Scint / muMinus.nHits_EKLM_Scint;
2321 double deltaT0 = t0_plus - t0_minus;
2323 double v = 1.0 / muPlus.nHits_EKLM_Scint + 1.0 / muMinus.nHits_EKLM_Scint;
2324 int nTotal = muPlus.nHits_EKLM_Scint + muMinus.nHits_EKLM_Scint;
2329 sum_delta2_over_v_EKLM_Scint += (deltaT0 * deltaT0) / v;
2331 nDimuon_EKLM_Scint++;
2347 }
else if (nTotal < 15) {
2355 B2INFO(
"Di-muon ΔT0 data collected."
2356 <<
LogVar(
"BKLM Scint di-muon events", nDimuon_BKLM_Scint)
2357 <<
LogVar(
"BKLM RPC Phi di-muon events", nDimuon_BKLM_RPC_Phi)
2358 <<
LogVar(
"BKLM RPC (phi and z) di-muon events", nDimuon_BKLM_RPC)
2359 <<
LogVar(
"BKLM RPC Z di-muon events", nDimuon_BKLM_RPC_Z)
2360 <<
LogVar(
"EKLM Scint di-muon events", nDimuon_EKLM_Scint));
2379 auto coreSigma = [](TH1F * h,
double fallback,
double & err,
int nEntries) ->
double {
2380 err = (nEntries > 0) ? fallback / std::sqrt(2.0 * nEntries) : 0.0;
2382 auto useMoment = [&](
const char* reason)
2384 B2WARNING(
"sigma_hit: " << reason <<
", using the second moment"
2385 <<
LogVar(
"histogram", std::string((h !=
nullptr) ? h->GetName() :
"none"))
2386 <<
LogVar(
"second moment [ns]", fallback));
2389 if (h ==
nullptr || h->GetEntries() < 100)
2390 return useMoment(
"fewer than 100 events");
2391 double prob[3] = {0.25, 0.50, 0.75};
2393 h->GetQuantiles(3, q, prob);
2394 const double median = q[1];
2395 const double sigma0 = (q[2] - q[0]) / 1.349;
2396 if (!(sigma0 > 0.0))
2397 return useMoment(
"zero interquartile range");
2398 TF1 f(
"fcore",
"gaus", median - 2.5 * sigma0, median + 2.5 * sigma0);
2399 f.SetParameters(h->GetMaximum(), median, sigma0);
2400 if (h->Fit(&f,
"RQN0") != 0)
2401 return useMoment(
"core fit did not converge");
2402 const double sg = std::fabs(f.GetParameter(2));
2404 if (sg > 5.0 * fallback || sg < 0.1 * fallback)
2405 return useMoment(
"core fit width far from the second moment");
2406 err = f.GetParError(2);
2410 float sigma_BKLM_Scint = 10.0f;
2411 float sigma_BKLM_Scint_err = 1.0f;
2412 if (nDimuon_BKLM_Scint > 0) {
2413 double sigma2 = sum_delta2_over_v_BKLM_Scint /
static_cast<double>(nDimuon_BKLM_Scint);
2414 double moment = std::sqrt(sigma2);
2415 double fitErr = 0.0;
2416 double core = coreSigma(
h_z_bklm_scint, moment, fitErr, nDimuon_BKLM_Scint);
2417 sigma_BKLM_Scint =
static_cast<float>(core);
2418 B2INFO(
"sigma_hit BKLM Scint" <<
LogVar(
"core fit [ns]", core)
2419 <<
LogVar(
"second moment [ns]", moment) <<
LogVar(
"ratio", moment / core));
2420 sigma_BKLM_Scint_err =
static_cast<float>(fitErr);
2423 float sigma_RPC_Phi = 10.0f;
2424 float sigma_RPC_Phi_err = 1.0f;
2425 if (nDimuon_BKLM_RPC_Phi > 0) {
2426 double sigma2 = sum_delta2_over_v_BKLM_RPC_Phi /
static_cast<double>(nDimuon_BKLM_RPC_Phi);
2427 double moment = std::sqrt(sigma2);
2428 double fitErr = 0.0;
2429 double core = coreSigma(
h_z_bklm_rpc_phi, moment, fitErr, nDimuon_BKLM_RPC_Phi);
2430 sigma_RPC_Phi =
static_cast<float>(core);
2431 B2INFO(
"sigma_hit RPC phi" <<
LogVar(
"core fit [ns]", core)
2432 <<
LogVar(
"second moment [ns]", moment) <<
LogVar(
"ratio", moment / core));
2433 sigma_RPC_Phi_err =
static_cast<float>(fitErr);
2436 float sigma_RPC_Z = 10.0f;
2437 float sigma_RPC_Z_err = 1.0f;
2438 if (nDimuon_BKLM_RPC_Z > 0) {
2439 double sigma2 = sum_delta2_over_v_BKLM_RPC_Z /
static_cast<double>(nDimuon_BKLM_RPC_Z);
2440 double moment = std::sqrt(sigma2);
2441 double fitErr = 0.0;
2442 double core = coreSigma(
h_z_bklm_rpc_z, moment, fitErr, nDimuon_BKLM_RPC_Z);
2443 sigma_RPC_Z =
static_cast<float>(core);
2444 B2INFO(
"sigma_hit RPC z" <<
LogVar(
"core fit [ns]", core)
2445 <<
LogVar(
"second moment [ns]", moment) <<
LogVar(
"ratio", moment / core));
2446 sigma_RPC_Z_err =
static_cast<float>(fitErr);
2451 float sigma_RPC = 10.0f;
2452 float sigma_RPC_err = 1.0f;
2453 if (nDimuon_BKLM_RPC > 0) {
2454 double sigma2 = sum_delta2_over_v_BKLM_RPC /
static_cast<double>(nDimuon_BKLM_RPC);
2455 double moment = std::sqrt(sigma2);
2456 double fitErr = 0.0;
2457 double core = coreSigma(
h_z_bklm_rpc, moment, fitErr, nDimuon_BKLM_RPC);
2458 sigma_RPC =
static_cast<float>(core);
2459 B2INFO(
"sigma_hit RPC (phi and z together)" <<
LogVar(
"core fit [ns]", core)
2460 <<
LogVar(
"second moment [ns]", moment) <<
LogVar(
"ratio", moment / core));
2461 sigma_RPC_err =
static_cast<float>(fitErr);
2464 float sigma_EKLM_Scint = 10.0f;
2465 float sigma_EKLM_Scint_err = 1.0f;
2466 if (nDimuon_EKLM_Scint > 0) {
2467 double sigma2 = sum_delta2_over_v_EKLM_Scint /
static_cast<double>(nDimuon_EKLM_Scint);
2468 double moment = std::sqrt(sigma2);
2469 double fitErr = 0.0;
2470 double core = coreSigma(
h_z_eklm_scint, moment, fitErr, nDimuon_EKLM_Scint);
2471 sigma_EKLM_Scint =
static_cast<float>(core);
2472 B2INFO(
"sigma_hit EKLM Scint" <<
LogVar(
"core fit [ns]", core)
2473 <<
LogVar(
"second moment [ns]", moment) <<
LogVar(
"ratio", moment / core));
2474 sigma_EKLM_Scint_err =
static_cast<float>(fitErr);
2477 B2INFO(
"Extracted per-hit resolutions using event-by-event weighting:"
2478 <<
LogVar(
"σ_BKLM_Scint [ns]", sigma_BKLM_Scint) <<
LogVar(
"±", sigma_BKLM_Scint_err)
2479 <<
LogVar(
"σ_RPC_Phi [ns]", sigma_RPC_Phi) <<
LogVar(
"±", sigma_RPC_Phi_err)
2480 <<
LogVar(
"σ_RPC_Z [ns]", sigma_RPC_Z) <<
LogVar(
"±", sigma_RPC_Z_err)
2481 <<
LogVar(
"σ_RPC_combined [ns]", sigma_RPC) <<
LogVar(
"±", sigma_RPC_err)
2482 <<
LogVar(
"σ_EKLM_Scint [ns]", sigma_EKLM_Scint) <<
LogVar(
"±", sigma_EKLM_Scint_err));
2491 B2INFO(
"EventT0 hit resolution calibration complete and stored in payload.");
2494 eventTrackMap.clear();
2515 B2INFO(
"Save Histograms into Files.");
2518 TDirectory* dir_monitor =
m_outFile->mkdir(
"monitor_Hists",
"",
true);
2522 h_diff->SetDirectory(dir_monitor);
2525 TDirectory* dir_eventT0 =
m_outFile->mkdir(
"EventT0",
"",
true);
2579 TDirectory* dir_effC =
m_outFile->mkdir(
"effC_Hists",
"",
true);
2595 TDirectory* dir_time =
m_outFile->mkdir(
"time",
"",
true);
2620 B2INFO(
"Top file setup Done.");
2624 B2INFO(
"Skipping debug histogram directory creation (m_saveAllPlots = false)");
2628 B2INFO(
"File Write and Close. Done.");
2632 TDirectory* dir_time_F[2];
2633 TDirectory* dir_time_FS[2][8];
2634 TDirectory* dir_time_FSL[2][8][15];
2635 TDirectory* dir_time_FSLP[2][8][15][2];
2636 TDirectory* dir_time_F_end[2];
2637 TDirectory* dir_time_FS_end[2][4];
2638 TDirectory* dir_time_FSL_end[2][4][14];
2639 TDirectory* dir_time_FSLP_end[2][4][14][2];
2641 B2INFO(
"Sub files declare Done.");
2642 for (
int iF = 0; iF < 2; ++iF) {
2661 sprintf(dirname,
"isForward_%d", iF);
2662 dir_time_F[iF] = dir_time->mkdir(dirname,
"",
true);
2663 dir_time_F[iF]->cd();
2665 for (
int iS = 0; iS < 8; ++iS) {
2672 h2_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2673 h2c_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2675 sprintf(dirname,
"Sector_%d", iS + 1);
2676 dir_time_FS[iF][iS] = dir_time_F[iF]->mkdir(dirname,
"",
true);
2677 dir_time_FS[iF][iS]->cd();
2679 for (
int iL = 0; iL < 15; ++iL) {
2680 h_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2681 hc_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2683 sprintf(dirname,
"Layer_%d", iL + 1);
2684 dir_time_FSL[iF][iS][iL] = dir_time_FS[iF][iS]->mkdir(dirname,
"",
true);
2685 dir_time_FSL[iF][iS][iL]->cd();
2686 for (
int iP = 0; iP < 2; ++iP) {
2687 h_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2688 hc_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2689 h2_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2690 h2c_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2692 sprintf(dirname,
"Plane_%d", iP);
2693 dir_time_FSLP[iF][iS][iL][iP] = dir_time_FSL[iF][iS][iL]->mkdir(dirname,
"",
true);
2694 dir_time_FSLP[iF][iS][iL][iP]->cd();
2700 sprintf(dirname,
"isForward_%d_end", iF + 1);
2701 dir_time_F_end[iF] = dir_time->mkdir(dirname,
"",
true);
2702 dir_time_F_end[iF]->cd();
2703 int maxLayer = 12 + 2 * iF;
2704 for (
int iS = 0; iS < 4; ++iS) {
2711 sprintf(dirname,
"Sector_%d_end", iS + 1);
2712 dir_time_FS_end[iF][iS] = dir_time_F_end[iF]->mkdir(dirname,
"",
true);
2713 dir_time_FS_end[iF][iS]->cd();
2714 for (
int iL = 0; iL < maxLayer; ++iL) {
2715 h_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2716 hc_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2718 sprintf(dirname,
"Layer_%d_end", iL + 1);
2719 dir_time_FSL_end[iF][iS][iL] = dir_time_FS_end[iF][iS]->mkdir(dirname,
"",
true);
2720 dir_time_FSL_end[iF][iS][iL]->cd();
2721 for (
int iP = 0; iP < 2; ++iP) {
2722 h_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2723 hc_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2724 h2_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2725 h2c_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2727 sprintf(dirname,
"plane_%d_end", iP);
2728 dir_time_FSLP_end[iF][iS][iL][iP] = dir_time_FSL_end[iF][iS][iL]->mkdir(dirname,
"",
true);
2729 dir_time_FSLP_end[iF][iS][iL][iP]->cd();
2738 B2INFO(
"File Write and Close. Done.");