309 TDirectory* dir_channels =
m_outFile->mkdir(
"channels",
"Per-channel histograms",
true);
312 TDirectory* dir_bklm = dir_channels->mkdir(
"BKLM",
"",
true);
313 TString sectionName[2] = {
"Backward",
"Forward"};
314 TString planeName[2] = {
"Z",
"Phi"};
316 for (
int iF = 0; iF < 2; ++iF) {
317 TDirectory* dir_section = dir_bklm->mkdir(sectionName[iF].Data(),
"",
true);
318 for (
int iS = 0; iS < 8; ++iS) {
319 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
320 for (
int iL = 0; iL < 15; ++iL) {
321 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
322 for (
int iP = 0; iP < 2; ++iP) {
323 m_channelHistDir_BKLM[iF][iS][iL][iP] = dir_layer->mkdir(Form(
"Plane_%s", planeName[iP].Data()),
"",
true);
330 TDirectory* dir_eklm = dir_channels->mkdir(
"EKLM",
"",
true);
331 for (
int iF = 0; iF < 2; ++iF) {
332 TDirectory* dir_section = dir_eklm->mkdir(sectionName[iF].Data(),
"",
true);
333 for (
int iS = 0; iS < 4; ++iS) {
334 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
335 int maxLayer = 12 + 2 * iF;
336 for (
int iL = 0; iL < maxLayer; ++iL) {
337 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
338 for (
int iP = 0; iP < 2; ++iP) {
346 B2INFO(
"Created directory structure for per-channel histograms.");
352 TString iFstring[2] = {
"Backward",
"Forward"};
353 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
356 h_diff =
new TH1F(
"h_diff",
"Position difference between bklmHit2d and extHit;position difference", 100, 0, 10);
357 h_calibrated =
new TH1I(
"h_calibrated_summary",
"h_calibrated_summary;calibrated or not", 3, 0, 3);
358 hc_calibrated =
new TH1I(
"hc_calibrated_summary",
"hc_calibrated_summary;calibrated or not", 3, 0, 3);
376 double maximalPhiStripLengthBKLM =
378 double maximalZStripLengthBKLM =
380 double maximalStripLengthEKLM =
384 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
387 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
390 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
391 50, 0.0, maximalPhiStripLengthBKLM);
393 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
394 50, 0.0, maximalZStripLengthBKLM);
396 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
397 50, 0.0, maximalStripLengthEKLM);
399 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
400 50, 0.0, maximalStripLengthEKLM);
403 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
406 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
409 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
410 50, 0.0, maximalPhiStripLengthBKLM);
412 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
413 50, 0.0, maximalZStripLengthBKLM);
415 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
416 50, 0.0, maximalStripLengthEKLM);
418 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
419 50, 0.0, maximalStripLengthEKLM);
422 h_time_scint_tc =
new TH1F(
"h_time_scint_tc",
"time distribution for Scintillator", nBin_scint,
424 h_time_scint_tc_end =
new TH1F(
"h_time_scint_tc_end",
"time distribution for Scintillator (Endcap)", nBin_scint,
431 h_time_scint =
new TH1F(
"h_time_scint",
"time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation[ns]", nBin_scint,
433 h_time_scint_end =
new TH1F(
"h_time_scint_end",
"time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
436 hc_time_rpc =
new TH1F(
"hc_time_rpc",
"Calibrated time distribution for RPC; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
439 "Calibrated time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
443 "Calibrated time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
448 "RPC: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
450 "BKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
452 "EKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
456 "RPC: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
458 "BKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
460 "EKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -20.0, 20.0);
466 "RPC: #mu^{+} hit multiplicity;N_{hits};Events", 100, 0, 100);
468 "RPC: #mu^{-} hit multiplicity;N_{hits};Events", 100, 0, 100);
470 "BKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
472 "BKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
474 "EKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
476 "EKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
480 "RPC: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
481 50, 0, 2.0, 100, -40, 40);
483 "BKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
484 50, 0, 1.0, 100, -40, 40);
486 "EKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
487 50, 0, 1.0, 100, -20, 20);
491 "RPC: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
494 "BKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
497 "EKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
502 "RPC: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
503 50, 0, 200, 100, -40, 40);
505 "BKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
506 40, 0, 40, 100, -40, 40);
508 "EKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
509 40, 0, 40, 100, -20, 20);
513 "RPC: #DeltaT_{0} (N^{+}+N^{-} < 10);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
515 "RPC: #DeltaT_{0} (10 #leq N^{+}+N^{-} < 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
517 "RPC: #DeltaT_{0} (N^{+}+N^{-} #geq 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
520 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
522 "BKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
524 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
527 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
529 "EKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
531 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
534 B2INFO(
"Skipping debug histogram allocation (m_saveAllPlots = false)");
538 for (
int iF = 0; iF < 2; ++iF) {
539 hn = Form(
"h_timeF%d_rpc", iF);
540 ht = Form(
"Time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
542 hn = Form(
"h_timeF%d_scint", iF);
543 ht = Form(
"Time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
546 hn = Form(
"h_timeF%d_scint_end", iF);
547 ht = Form(
"Time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
551 hn = Form(
"h2_timeF%d_rpc", iF);
552 ht = Form(
"Time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
554 hn = Form(
"h2_timeF%d_scint", iF);
555 ht = Form(
"Time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
558 hn = Form(
"h2_timeF%d_scint_end", iF);
559 ht = Form(
"Time distribution for Scintillator of %s (Endcap); Sector Index; T_rec-T_0-T_fly-T_propagation[ns]",
560 iFstring[iF].Data());
564 hn = Form(
"hc_timeF%d_rpc", iF);
565 ht = Form(
"Calibrated time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iFstring[iF].Data());
567 hn = Form(
"hc_timeF%d_scint", iF);
568 ht = Form(
"Calibrated time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
569 iFstring[iF].Data());
572 hn = Form(
"hc_timeF%d_scint_end", iF);
573 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
574 iFstring[iF].Data());
578 hn = Form(
"h2c_timeF%d_rpc", iF);
579 ht = Form(
"Calibrated time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
580 iFstring[iF].Data());
583 hn = Form(
"h2c_timeF%d_scint", iF);
584 ht = Form(
"Calibrated time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
585 iFstring[iF].Data());
588 hn = Form(
"h2c_timeF%d_scint_end", iF);
589 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap) ; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
590 iFstring[iF].Data());
594 for (
int iS = 0; iS < 8; ++iS) {
596 hn = Form(
"h_timeF%d_S%d_scint", iF, iS);
597 ht = Form(
"Time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
600 hn = Form(
"h_timeF%d_S%d_rpc", iF, iS);
601 ht = Form(
"Time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
603 hn = Form(
"h2_timeF%d_S%d", iF, iS);
604 ht = Form(
"Time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
608 hn = Form(
"hc_timeF%d_S%d_scint", iF, iS);
609 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
610 iFstring[iF].Data());
613 hn = Form(
"hc_timeF%d_S%d_rpc", iF, iS);
614 ht = Form(
"Calibrated time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
615 iFstring[iF].Data());
618 hn = Form(
"h2c_timeF%d_S%d", iF, iS);
619 ht = Form(
"Calibrated time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
620 iFstring[iF].Data());
625 for (
int iL = 0; iL < 2; ++iL) {
626 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
627 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
628 iFstring[iF].Data());
631 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
632 ht = Form(
"Calibrated time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
633 iL, iS, iFstring[iF].Data());
637 for (
int iP = 0; iP < 2; ++iP) {
638 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
639 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]",
640 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
643 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
644 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
645 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
649 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
650 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]",
651 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
654 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
655 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]",
656 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
662 for (
int iL = 2; iL < 15; ++iL) {
663 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
664 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());
667 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
668 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,
669 iFstring[iF].Data());
672 for (
int iP = 0; iP < 2; ++iP) {
673 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
674 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,
675 iFstring[iF].Data());
678 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
679 ht = Form(
"time distribution for RPC of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
680 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
683 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
684 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]",
685 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
689 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
690 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]",
691 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
698 int maxLay = 12 + 2 * iF;
699 for (
int iS = 0; iS < 4; ++iS) {
700 hn = Form(
"h_timeF%d_S%d_scint_end", iF, iS);
701 ht = Form(
"Time distribution for Scintillator of Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iS,
702 iFstring[iF].Data());
705 hn = Form(
"h2_timeF%d_S%d_end", iF, iS);
706 ht = Form(
"Time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
709 hn = Form(
"hc_timeF%d_S%d_scint_end", iF, iS);
710 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d (Endcap), %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
711 iS, iFstring[iF].Data());
714 hn = Form(
"h2c_timeF%d_S%d_end", iF, iS);
715 ht = Form(
"Calibrated time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
716 iS, iFstring[iF].Data());
717 h2c_timeFS_end[iF][iS] =
new TH2F(hn.Data(), ht.Data(), maxLay, 0, maxLay, nBin_scint,
721 for (
int iL = 0; iL < maxLay; ++iL) {
722 hn = Form(
"h_timeF%d_S%d_L%d_end", iF, iS, iL);
723 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
724 iFstring[iF].Data());
727 hn = Form(
"hc_timeF%d_S%d_L%d_end", iF, iS, iL);
728 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]",
729 iL, iS, iFstring[iF].Data());
733 for (
int iP = 0; iP < 2; ++iP) {
734 hn = Form(
"h_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
735 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
736 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
740 hn = Form(
"h2_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
741 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]",
742 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
746 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
747 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]",
748 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
752 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
753 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]",
754 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
755 h2c_timeFSLP_end[iF][iS][iL][iP] =
new TH2F(hn.Data(), ht.Data(), 75, 0, 75, nBin_scint,
1122 gROOT->SetBatch(kTRUE);
1129 fcn_gaus =
new TF1(
"fcn_gaus",
"gaus");
1130 fcn_land =
new TF1(
"fcn_land",
"landau");
1131 fcn_pol1 =
new TF1(
"fcn_pol1",
"pol1");
1132 fcn_const =
new TF1(
"fcn_const",
"pol0");
1140 std::string name =
"time_calibration.root";
1144 if (stat(name.c_str(), &buffer) != 0)
1146 name =
"time_calibration_" + std::to_string(i) +
".root";
1151 m_outFile =
new TFile(name.c_str(),
"recreate");
1154 std::vector<struct Event> eventsChannel;
1155 eventsChannel.clear();
1159 B2INFO(
"Counting events per channel...");
1160 std::map<KLMChannelNumber, unsigned int> eventCounts;
1164 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsBKLM;
1165 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsEKLM;
1170 m_cFlag[channel] = ChannelCalibrationStatus::c_NotEnoughData;
1172 if (eventCounts.find(channel) == eventCounts.end())
1175 int nEvents = eventCounts[channel];
1177 B2WARNING(
"Not enough calibration data collected."
1178 <<
LogVar(
"channel", channel)
1179 <<
LogVar(
"number of digit", nEvents));
1183 m_cFlag[channel] = ChannelCalibrationStatus::c_FailedFit;
1187 channelsBKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1190 channelsEKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1194 std::sort(channelsBKLM.begin(), channelsBKLM.end(), compareEventNumber);
1195 std::sort(channelsEKLM.begin(), channelsEKLM.end(), compareEventNumber);
1198 double delayBKLM, delayBKLMError;
1199 double delayEKLM, delayEKLMError;
1207 B2INFO(
"2D fits complete, data cleared.");
1244 std::vector<std::pair<std::string, std::function<bool(
const KLMChannelIndex&)>>> batches = {
1245 {
"RPC Backward", isRPCBackward},
1246 {
"RPC Forward", isRPCForward},
1247 {
"BKLM Scintillator Backward", isBKLMScintillatorBackward},
1248 {
"BKLM Scintillator Forward", isBKLMScintillatorForward},
1249 {
"EKLM Scintillator Backward", isEKLMScintillatorBackward},
1250 {
"EKLM Scintillator Forward", isEKLMScintillatorForward}
1257 B2INFO(
"First loop: Computing global statistics (batched processing)...");
1259 TString iFstring[2] = {
"Backward",
"Forward"};
1260 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
1262 int nBin_scint = 80;
1264 for (
const auto& batch : batches) {
1265 B2INFO(
"Processing batch for global stats: " << batch.first);
1269 channelId = klmChannel.getKLMChannelNumber();
1271 if (!batch.second(klmChannel))
1274 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1280 eventsChannel =
m_evts[channelId];
1281 int iSub = klmChannel.getSubdetector();
1285 for (
const Event& event : eventsChannel) {
1290 XYZVector diffD = XYZVector(event.diffDistX, event.diffDistY, event.diffDistZ);
1293 double timeHit =
event.time();
1295 timeHit = timeHit -
event.t0;
1297 if (timeHit <= -400e3)
1314 B2INFO(
"Batch processed and cleared: " << batch.first);
1323 B2INFO(
"Global Mean for Raw." <<
LogVar(
"RPC", tmpMean_rpc_global)
1324 <<
LogVar(
"Scint BKLM", tmpMean_scint_global)
1325 <<
LogVar(
"Scint EKLM", tmpMean_scint_global_end));
1331 B2INFO(
"Second pass: Computing per-channel time shifts (batched processing)...");
1333 for (
const auto& batch : batches) {
1334 B2INFO(
"Processing batch for time shifts: " << batch.first);
1338 channelId = klmChannel.getKLMChannelNumber();
1340 if (!batch.second(klmChannel))
1343 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1349 eventsChannel =
m_evts[channelId];
1350 int iSub = klmChannel.getSubdetector();
1351 int iF, iS, iL, iP, iC;
1354 iF = klmChannel.getSection();
1355 iS = klmChannel.getSector() - 1;
1356 iL = klmChannel.getLayer() - 1;
1357 iP = klmChannel.getPlane();
1358 iC = klmChannel.getStrip() - 1;
1360 iF = klmChannel.getSection() - 1;
1361 iS = klmChannel.getSector() - 1;
1362 iL = klmChannel.getLayer() - 1;
1363 iP = klmChannel.getPlane() - 1;
1364 iC = klmChannel.getStrip() - 1;
1369 TH1F* h_temp_tc =
nullptr;
1374 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1375 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1376 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1379 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1380 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1381 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1386 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc_end", iF, iS, iL, iP, iC);
1387 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1388 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1393 for (
const Event& event : eventsChannel) {
1398 double timeHit =
event.time();
1400 timeHit = timeHit -
event.t0;
1401 if (timeHit <= -400e3)
1403 h_temp_tc->Fill(timeHit);
1407 double tmpMean_channel =
fcn_gaus->GetParameter(1);
1412 m_timeShift[channelId] = tmpMean_channel - tmpMean_rpc_global;
1414 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global;
1417 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global_end;
1424 B2INFO(
"Batch processed and cleared: " << batch.first);
1430 B2INFO(
"Effective Light m_timeShift obtained.");
1438 B2INFO(
"Effective light speed fitting.");
1442 double fittedDelayRPCPhi =
fcn_pol1->GetParameter(1);
1443 double e_slope_rpc_phi =
fcn_pol1->GetParError(1);
1446 double fittedDelayRPCZ =
fcn_pol1->GetParameter(1);
1447 double e_slope_rpc_z =
fcn_pol1->GetParError(1);
1450 double delayRPCPhi, delayRPCZ;
1454 B2INFO(
"Using fixed RPC propagation delay: " <<
m_fixedRPCDelay <<
" ns/cm (c_eff = 0.5c)"
1455 <<
LogVar(
"Fitted phi (not used)", fittedDelayRPCPhi)
1456 <<
LogVar(
"Fitted Z (not used)", fittedDelayRPCZ));
1458 delayRPCPhi = fittedDelayRPCPhi;
1459 delayRPCZ = fittedDelayRPCZ;
1463 double slope_scint_phi =
fcn_pol1->GetParameter(1);
1464 double e_slope_scint_phi =
fcn_pol1->GetParError(1);
1467 double slope_scint_z =
fcn_pol1->GetParameter(1);
1468 double e_slope_scint_z =
fcn_pol1->GetParError(1);
1471 double slope_scint_plane1_end =
fcn_pol1->GetParameter(1);
1472 double e_slope_scint_plane1_end =
fcn_pol1->GetParError(1);
1475 double slope_scint_plane2_end =
fcn_pol1->GetParameter(1);
1476 double e_slope_scint_plane2_end =
fcn_pol1->GetParError(1);
1478 TString logStr_phi, logStr_z;
1480 logStr_phi = Form(
"%.4f ns/cm (fixed)", delayRPCPhi);
1481 logStr_z = Form(
"%.4f ns/cm (fixed)", delayRPCZ);
1482 B2INFO(
"Delay in RPCs (using fixed value):"
1483 <<
LogVar(
"Used Value (phi readout)", logStr_phi.Data())
1484 <<
LogVar(
"Used Value (z readout)", logStr_z.Data()));
1486 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", delayRPCPhi, e_slope_rpc_phi);
1487 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayRPCZ, e_slope_rpc_z);
1488 B2INFO(
"Delay in RPCs:"
1489 <<
LogVar(
"Fitted Value (phi readout)", logStr_phi.Data())
1490 <<
LogVar(
"Fitted Value (z readout)", logStr_z.Data()));
1492 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_phi, e_slope_scint_phi);
1493 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_z, e_slope_scint_z);
1494 B2INFO(
"Delay in BKLM scintillators:"
1495 <<
LogVar(
"Fitted Value (phi readout) ", logStr_phi.Data())
1496 <<
LogVar(
"Fitted Value (z readout) ", logStr_z.Data()));
1497 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane1_end,
1498 e_slope_scint_plane1_end);
1499 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane2_end,
1500 e_slope_scint_plane2_end);
1501 B2INFO(
"Delay in EKLM scintillators:"
1502 <<
LogVar(
"Fitted Value (plane1 readout) ", logStr_phi.Data())
1503 <<
LogVar(
"Fitted Value (plane2 readout) ", logStr_z.Data()));
1505 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayBKLM, delayBKLMError);
1506 B2INFO(
"Delay in BKLM scintillators:"
1507 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1508 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayEKLM, delayEKLMError);
1509 B2INFO(
"Delay in EKLM scintillators:"
1510 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1521 B2INFO(
"Third loop: Time distribution filling (batched processing)...");
1523 for (
const auto& batch : batches) {
1524 B2INFO(
"Processing batch: " << batch.first);
1528 channelId = klmChannel.getKLMChannelNumber();
1530 if (!batch.second(klmChannel))
1533 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1539 eventsChannel =
m_evts[channelId];
1540 int iSub = klmChannel.getSubdetector();
1541 int iF, iS, iL, iP, iC;
1544 iF = klmChannel.getSection();
1545 iS = klmChannel.getSector() - 1;
1546 iL = klmChannel.getLayer() - 1;
1547 iP = klmChannel.getPlane();
1548 iC = klmChannel.getStrip() - 1;
1550 iF = klmChannel.getSection() - 1;
1551 iS = klmChannel.getSector() - 1;
1552 iL = klmChannel.getLayer() - 1;
1553 iP = klmChannel.getPlane() - 1;
1554 iC = klmChannel.getStrip() - 1;
1559 TH1F* h_temp =
nullptr;
1564 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1565 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1566 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1569 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1570 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1571 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1576 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1577 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1578 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1584 for (
const Event& event : eventsChannel) {
1589 double timeHit =
event.time();
1591 timeHit = timeHit -
event.t0;
1592 if (timeHit <= -400e3)
1600 propgationT =
event.dist * delayRPCZ;
1602 propgationT =
event.dist * delayRPCPhi;
1603 double time = timeHit - propgationT;
1618 double propgationT =
event.dist * delayBKLM;
1619 double time = timeHit - propgationT;
1635 double propgationT =
event.dist * delayEKLM;
1636 double time = timeHit - propgationT;
1653 TFitResultPtr r = h_temp->Fit(
fcn_gaus,
"LESQ");
1655 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1668 B2INFO(
"Batch processed and cleared: " << batch.first);
1671 B2INFO(
"Original filling done.");
1674 int iChannel_rpc = 0;
1676 int iChannel_end = 0;
1678 channelId = klmChannel.getKLMChannelNumber();
1679 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1682 int iSub = klmChannel.getSubdetector();
1684 int iL = klmChannel.getLayer() - 1;
1714 B2INFO(
"Channel's time distribution fitting done.");
1719 B2INFO(
"Calibrated channel's time distribution filling begins.");
1723 channelId = klmChannel.getKLMChannelNumber();
1733 channelId = klmChannel.getKLMChannelNumber();
1738 B2DEBUG(20,
"Uncalibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeShift[channelId]));
1745 channelId = klmChannel.getKLMChannelNumber();
1747 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
1750 int iSub = klmChannel.getSubdetector();
1753 int iL = klmChannel.getLayer() - 1;
1777 B2INFO(
"Fourth loop: Calibrated time distribution filling (batched processing)...");
1779 for (
const auto& batch : batches) {
1780 B2INFO(
"Processing batch: " << batch.first);
1784 channelId = klmChannel.getKLMChannelNumber();
1786 if (!batch.second(klmChannel))
1792 eventsChannel =
m_evts[channelId];
1793 int iSub = klmChannel.getSubdetector();
1794 int iF, iS, iL, iP, iC;
1797 iF = klmChannel.getSection();
1798 iS = klmChannel.getSector() - 1;
1799 iL = klmChannel.getLayer() - 1;
1800 iP = klmChannel.getPlane();
1801 iC = klmChannel.getStrip() - 1;
1803 iF = klmChannel.getSection() - 1;
1804 iS = klmChannel.getSector() - 1;
1805 iL = klmChannel.getLayer() - 1;
1806 iP = klmChannel.getPlane() - 1;
1807 iC = klmChannel.getStrip() - 1;
1811 TH1F* hc_temp =
nullptr;
1816 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1817 ht = Form(
"Calibrated time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1818 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1822 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1823 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1824 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1829 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1830 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1831 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1836 for (
const Event& event : eventsChannel) {
1841 double timeHit =
event.time();
1843 timeHit = timeHit -
event.t0;
1844 if (timeHit <= -400e3)
1852 propgationT =
event.dist * delayRPCZ;
1854 propgationT =
event.dist * delayRPCPhi;
1855 double time = timeHit - propgationT -
m_timeShift[channelId];
1858 hc_temp->Fill(time);
1870 double propgationT =
event.dist * delayBKLM;
1871 double time = timeHit - propgationT -
m_timeShift[channelId];
1874 hc_temp->Fill(time);
1887 double propgationT =
event.dist * delayEKLM;
1888 double time = timeHit - propgationT -
m_timeShift[channelId];
1891 hc_temp->Fill(time);
1905 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData) {
1910 TFitResultPtr rc = hc_temp->Fit(
fcn_gaus,
"LESQ");
1912 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1925 B2INFO(
"Batch processed and cleared: " << batch.first);
1929 int icChannel_rpc = 0;
1931 int icChannel_end = 0;
1933 channelId = klmChannel.getKLMChannelNumber();
1934 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1937 int iSub = klmChannel.getSubdetector();
1939 int iL = klmChannel.getLayer() - 1;
1969 B2INFO(
"Channel's time distribution fitting done.");
1974 B2INFO(
"Calibrated channel's time distribution filling begins.");
1978 channelId = klmChannel.getKLMChannelNumber();
1988 channelId = klmChannel.getKLMChannelNumber();
1993 B2DEBUG(20,
"Calibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeRes[channelId]));
2000 channelId = klmChannel.getKLMChannelNumber();
2002 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
2005 int iSub = klmChannel.getSubdetector();
2008 int iL = klmChannel.getLayer() - 1;
2025 B2INFO(
"Fifth pass: Computing di-muon ΔT0 for EventT0 hit resolution calibration...");
2028 struct TrackT0Info {
2030 int nHits_BKLM_Scint;
2031 int nHits_BKLM_RPC_Phi;
2032 int nHits_BKLM_RPC_Z;
2033 int nHits_EKLM_Scint;
2034 double sumT0_BKLM_Scint;
2035 double sumT0_BKLM_RPC_Phi;
2036 double sumT0_BKLM_RPC_Z;
2037 double sumT0_EKLM_Scint;
2039 TrackT0Info() : charge(0),
2040 nHits_BKLM_Scint(0),
2041 nHits_BKLM_RPC_Phi(0),
2042 nHits_BKLM_RPC_Z(0),
2043 nHits_EKLM_Scint(0),
2044 sumT0_BKLM_Scint(0.0),
2045 sumT0_BKLM_RPC_Phi(0.0),
2046 sumT0_BKLM_RPC_Z(0.0),
2047 sumT0_EKLM_Scint(0.0) {}
2051 std::map<std::pair<int, int>, std::map<int, TrackT0Info>> eventTrackMap;
2054 for (
const auto& batch : batches) {
2055 B2INFO(
"Processing batch for di-muon analysis: " << batch.first);
2058 for (
const auto& channelPair :
m_evts) {
2060 const std::vector<Event>& chEvents = channelPair.second;
2063 int subdetector, section, sector, layer, plane, strip;
2065 chId, &subdetector, §ion, §or, &layer, &plane, &strip);
2068 int iSub = subdetector;
2071 for (
const Event& event : chEvents) {
2077 std::pair<int, int> eventKey(event.Run, event.Events);
2078 int trackIdx =
event.nTrack;
2079 int charge =
event.Track_Charge;
2082 double timeHit =
event.time() -
m_timeShift[chId];
2084 if (timeHit <= -400e3)
2093 propT =
event.dist * delayRPCZ;
2095 propT =
event.dist * delayRPCPhi;
2098 propT =
event.dist * delayBKLM;
2102 propT =
event.dist * delayEKLM;
2105 double t0_estimate = timeHit - propT;
2108 TrackT0Info& trackInfo = eventTrackMap[eventKey][trackIdx];
2109 trackInfo.charge = charge;
2115 trackInfo.nHits_BKLM_RPC_Z++;
2116 trackInfo.sumT0_BKLM_RPC_Z += t0_estimate;
2118 trackInfo.nHits_BKLM_RPC_Phi++;
2119 trackInfo.sumT0_BKLM_RPC_Phi += t0_estimate;
2123 trackInfo.nHits_BKLM_Scint++;
2124 trackInfo.sumT0_BKLM_Scint += t0_estimate;
2127 trackInfo.nHits_EKLM_Scint++;
2128 trackInfo.sumT0_EKLM_Scint += t0_estimate;
2136 B2INFO(
"Event-track map built. Processing events for EventT0 histograms...");
2140 double sum_delta2_over_v_BKLM_Scint = 0.0;
2141 double sum_delta2_over_v_BKLM_RPC_Phi = 0.0;
2142 double sum_delta2_over_v_BKLM_RPC_Z = 0.0;
2143 double sum_delta2_over_v_EKLM_Scint = 0.0;
2145 int nDimuon_BKLM_Scint = 0;
2146 int nDimuon_BKLM_RPC_Phi = 0;
2147 int nDimuon_BKLM_RPC_Z = 0;
2148 int nDimuon_EKLM_Scint = 0;
2150 for (
const auto& eventPair : eventTrackMap) {
2151 const auto& trackMap = eventPair.second;
2154 if (trackMap.size() != 2)
2157 auto it1 = trackMap.begin();
2158 auto it2 = trackMap.begin();
2160 const TrackT0Info& track1 = it1->second;
2161 const TrackT0Info& track2 = it2->second;
2164 if (track1.charge * track2.charge >= 0)
2168 const TrackT0Info& muPlus = (track1.charge > 0) ? track1 : track2;
2169 const TrackT0Info& muMinus = (track1.charge > 0) ? track2 : track1;
2172 if (muPlus.nHits_BKLM_Scint > 0 && muMinus.nHits_BKLM_Scint > 0) {
2173 double t0_plus = muPlus.sumT0_BKLM_Scint / muPlus.nHits_BKLM_Scint;
2174 double t0_minus = muMinus.sumT0_BKLM_Scint / muMinus.nHits_BKLM_Scint;
2175 double deltaT0 = t0_plus - t0_minus;
2178 double v = 1.0 / muPlus.nHits_BKLM_Scint + 1.0 / muMinus.nHits_BKLM_Scint;
2179 int nTotal = muPlus.nHits_BKLM_Scint + muMinus.nHits_BKLM_Scint;
2185 sum_delta2_over_v_BKLM_Scint += (deltaT0 * deltaT0) / v;
2186 nDimuon_BKLM_Scint++;
2203 }
else if (nTotal < 15) {
2211 if (muPlus.nHits_BKLM_RPC_Phi > 0 && muMinus.nHits_BKLM_RPC_Phi > 0) {
2212 double t0_plus = muPlus.sumT0_BKLM_RPC_Phi / muPlus.nHits_BKLM_RPC_Phi;
2213 double t0_minus = muMinus.sumT0_BKLM_RPC_Phi / muMinus.nHits_BKLM_RPC_Phi;
2214 double deltaT0 = t0_plus - t0_minus;
2216 double v = 1.0 / muPlus.nHits_BKLM_RPC_Phi + 1.0 / muMinus.nHits_BKLM_RPC_Phi;
2217 int nTotal = muPlus.nHits_BKLM_RPC_Phi + muMinus.nHits_BKLM_RPC_Phi;
2222 sum_delta2_over_v_BKLM_RPC_Phi += (deltaT0 * deltaT0) / v;
2223 nDimuon_BKLM_RPC_Phi++;
2238 }
else if (nTotal < 30) {
2246 if (muPlus.nHits_BKLM_RPC_Z > 0 && muMinus.nHits_BKLM_RPC_Z > 0) {
2247 double t0_plus = muPlus.sumT0_BKLM_RPC_Z / muPlus.nHits_BKLM_RPC_Z;
2248 double t0_minus = muMinus.sumT0_BKLM_RPC_Z / muMinus.nHits_BKLM_RPC_Z;
2249 double deltaT0 = t0_plus - t0_minus;
2251 double v = 1.0 / muPlus.nHits_BKLM_RPC_Z + 1.0 / muMinus.nHits_BKLM_RPC_Z;
2252 int nTotal = muPlus.nHits_BKLM_RPC_Z + muMinus.nHits_BKLM_RPC_Z;
2257 sum_delta2_over_v_BKLM_RPC_Z += (deltaT0 * deltaT0) / v;
2258 nDimuon_BKLM_RPC_Z++;
2273 }
else if (nTotal < 30) {
2281 if (muPlus.nHits_EKLM_Scint > 0 && muMinus.nHits_EKLM_Scint > 0) {
2282 double t0_plus = muPlus.sumT0_EKLM_Scint / muPlus.nHits_EKLM_Scint;
2283 double t0_minus = muMinus.sumT0_EKLM_Scint / muMinus.nHits_EKLM_Scint;
2284 double deltaT0 = t0_plus - t0_minus;
2286 double v = 1.0 / muPlus.nHits_EKLM_Scint + 1.0 / muMinus.nHits_EKLM_Scint;
2287 int nTotal = muPlus.nHits_EKLM_Scint + muMinus.nHits_EKLM_Scint;
2292 sum_delta2_over_v_EKLM_Scint += (deltaT0 * deltaT0) / v;
2293 nDimuon_EKLM_Scint++;
2309 }
else if (nTotal < 15) {
2317 B2INFO(
"Di-muon ΔT0 data collected."
2318 <<
LogVar(
"BKLM Scint di-muon events", nDimuon_BKLM_Scint)
2319 <<
LogVar(
"BKLM RPC Phi di-muon events", nDimuon_BKLM_RPC_Phi)
2320 <<
LogVar(
"BKLM RPC Z di-muon events", nDimuon_BKLM_RPC_Z)
2321 <<
LogVar(
"EKLM Scint di-muon events", nDimuon_EKLM_Scint));
2326 float sigma_BKLM_Scint = 10.0f;
2327 float sigma_BKLM_Scint_err = 1.0f;
2328 if (nDimuon_BKLM_Scint > 0) {
2329 double sigma2 = sum_delta2_over_v_BKLM_Scint /
static_cast<double>(nDimuon_BKLM_Scint);
2330 sigma_BKLM_Scint =
static_cast<float>(std::sqrt(sigma2));
2332 sigma_BKLM_Scint_err = sigma_BKLM_Scint / std::sqrt(2.0 * nDimuon_BKLM_Scint);
2335 float sigma_RPC_Phi = 10.0f;
2336 float sigma_RPC_Phi_err = 1.0f;
2337 if (nDimuon_BKLM_RPC_Phi > 0) {
2338 double sigma2 = sum_delta2_over_v_BKLM_RPC_Phi /
static_cast<double>(nDimuon_BKLM_RPC_Phi);
2339 sigma_RPC_Phi =
static_cast<float>(std::sqrt(sigma2));
2340 sigma_RPC_Phi_err = sigma_RPC_Phi / std::sqrt(2.0 * nDimuon_BKLM_RPC_Phi);
2343 float sigma_RPC_Z = 10.0f;
2344 float sigma_RPC_Z_err = 1.0f;
2345 if (nDimuon_BKLM_RPC_Z > 0) {
2346 double sigma2 = sum_delta2_over_v_BKLM_RPC_Z /
static_cast<double>(nDimuon_BKLM_RPC_Z);
2347 sigma_RPC_Z =
static_cast<float>(std::sqrt(sigma2));
2348 sigma_RPC_Z_err = sigma_RPC_Z / std::sqrt(2.0 * nDimuon_BKLM_RPC_Z);
2352 float sigma_RPC = 10.0f;
2353 float sigma_RPC_err = 1.0f;
2354 int nDimuon_RPC_total = nDimuon_BKLM_RPC_Phi + nDimuon_BKLM_RPC_Z;
2355 if (nDimuon_RPC_total > 0) {
2357 double w_phi =
static_cast<double>(nDimuon_BKLM_RPC_Phi) / nDimuon_RPC_total;
2358 double w_z =
static_cast<double>(nDimuon_BKLM_RPC_Z) / nDimuon_RPC_total;
2359 sigma_RPC = w_phi * sigma_RPC_Phi + w_z * sigma_RPC_Z;
2361 sigma_RPC_err = std::sqrt(w_phi * w_phi * sigma_RPC_Phi_err * sigma_RPC_Phi_err +
2362 w_z * w_z * sigma_RPC_Z_err * sigma_RPC_Z_err);
2365 float sigma_EKLM_Scint = 10.0f;
2366 float sigma_EKLM_Scint_err = 1.0f;
2367 if (nDimuon_EKLM_Scint > 0) {
2368 double sigma2 = sum_delta2_over_v_EKLM_Scint /
static_cast<double>(nDimuon_EKLM_Scint);
2369 sigma_EKLM_Scint =
static_cast<float>(std::sqrt(sigma2));
2370 sigma_EKLM_Scint_err = sigma_EKLM_Scint / std::sqrt(2.0 * nDimuon_EKLM_Scint);
2373 B2INFO(
"Extracted per-hit resolutions using event-by-event weighting:"
2374 <<
LogVar(
"σ_BKLM_Scint [ns]", sigma_BKLM_Scint) <<
LogVar(
"±", sigma_BKLM_Scint_err)
2375 <<
LogVar(
"σ_RPC_Phi [ns]", sigma_RPC_Phi) <<
LogVar(
"±", sigma_RPC_Phi_err)
2376 <<
LogVar(
"σ_RPC_Z [ns]", sigma_RPC_Z) <<
LogVar(
"±", sigma_RPC_Z_err)
2377 <<
LogVar(
"σ_RPC_combined [ns]", sigma_RPC) <<
LogVar(
"±", sigma_RPC_err)
2378 <<
LogVar(
"σ_EKLM_Scint [ns]", sigma_EKLM_Scint) <<
LogVar(
"±", sigma_EKLM_Scint_err));
2387 B2INFO(
"EventT0 hit resolution calibration complete and stored in payload.");
2390 eventTrackMap.clear();
2411 B2INFO(
"Save Histograms into Files.");
2414 TDirectory* dir_monitor =
m_outFile->mkdir(
"monitor_Hists",
"",
true);
2418 h_diff->SetDirectory(dir_monitor);
2421 TDirectory* dir_eventT0 =
m_outFile->mkdir(
"EventT0",
"",
true);
2470 TDirectory* dir_effC =
m_outFile->mkdir(
"effC_Hists",
"",
true);
2486 TDirectory* dir_time =
m_outFile->mkdir(
"time",
"",
true);
2511 B2INFO(
"Top file setup Done.");
2515 B2INFO(
"Skipping debug histogram directory creation (m_saveAllPlots = false)");
2519 B2INFO(
"File Write and Close. Done.");
2523 TDirectory* dir_time_F[2];
2524 TDirectory* dir_time_FS[2][8];
2525 TDirectory* dir_time_FSL[2][8][15];
2526 TDirectory* dir_time_FSLP[2][8][15][2];
2527 TDirectory* dir_time_F_end[2];
2528 TDirectory* dir_time_FS_end[2][4];
2529 TDirectory* dir_time_FSL_end[2][4][14];
2530 TDirectory* dir_time_FSLP_end[2][4][14][2];
2532 B2INFO(
"Sub files declare Done.");
2533 for (
int iF = 0; iF < 2; ++iF) {
2552 sprintf(dirname,
"isForward_%d", iF);
2553 dir_time_F[iF] = dir_time->mkdir(dirname,
"",
true);
2554 dir_time_F[iF]->cd();
2556 for (
int iS = 0; iS < 8; ++iS) {
2563 h2_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2564 h2c_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2566 sprintf(dirname,
"Sector_%d", iS + 1);
2567 dir_time_FS[iF][iS] = dir_time_F[iF]->mkdir(dirname,
"",
true);
2568 dir_time_FS[iF][iS]->cd();
2570 for (
int iL = 0; iL < 15; ++iL) {
2571 h_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2572 hc_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2574 sprintf(dirname,
"Layer_%d", iL + 1);
2575 dir_time_FSL[iF][iS][iL] = dir_time_FS[iF][iS]->mkdir(dirname,
"",
true);
2576 dir_time_FSL[iF][iS][iL]->cd();
2577 for (
int iP = 0; iP < 2; ++iP) {
2578 h_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2579 hc_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2580 h2_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2581 h2c_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2583 sprintf(dirname,
"Plane_%d", iP);
2584 dir_time_FSLP[iF][iS][iL][iP] = dir_time_FSL[iF][iS][iL]->mkdir(dirname,
"",
true);
2585 dir_time_FSLP[iF][iS][iL][iP]->cd();
2591 sprintf(dirname,
"isForward_%d_end", iF + 1);
2592 dir_time_F_end[iF] = dir_time->mkdir(dirname,
"",
true);
2593 dir_time_F_end[iF]->cd();
2594 int maxLayer = 12 + 2 * iF;
2595 for (
int iS = 0; iS < 4; ++iS) {
2602 sprintf(dirname,
"Sector_%d_end", iS + 1);
2603 dir_time_FS_end[iF][iS] = dir_time_F_end[iF]->mkdir(dirname,
"",
true);
2604 dir_time_FS_end[iF][iS]->cd();
2605 for (
int iL = 0; iL < maxLayer; ++iL) {
2606 h_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2607 hc_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2609 sprintf(dirname,
"Layer_%d_end", iL + 1);
2610 dir_time_FSL_end[iF][iS][iL] = dir_time_FS_end[iF][iS]->mkdir(dirname,
"",
true);
2611 dir_time_FSL_end[iF][iS][iL]->cd();
2612 for (
int iP = 0; iP < 2; ++iP) {
2613 h_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2614 hc_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2615 h2_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2616 h2c_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2618 sprintf(dirname,
"plane_%d_end", iP);
2619 dir_time_FSLP_end[iF][iS][iL][iP] = dir_time_FSL_end[iF][iS][iL]->mkdir(dirname,
"",
true);
2620 dir_time_FSLP_end[iF][iS][iL][iP]->cd();
2629 B2INFO(
"File Write and Close. Done.");