311 TDirectory* dir_channels =
m_outFile->mkdir(
"channels",
"Per-channel histograms",
true);
314 TDirectory* dir_bklm = dir_channels->mkdir(
"BKLM",
"",
true);
315 TString sectionName[2] = {
"Backward",
"Forward"};
316 TString planeName[2] = {
"Z",
"Phi"};
318 for (
int iF = 0; iF < 2; ++iF) {
319 TDirectory* dir_section = dir_bklm->mkdir(sectionName[iF].Data(),
"",
true);
320 for (
int iS = 0; iS < 8; ++iS) {
321 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
322 for (
int iL = 0; iL < 15; ++iL) {
323 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
324 for (
int iP = 0; iP < 2; ++iP) {
325 m_channelHistDir_BKLM[iF][iS][iL][iP] = dir_layer->mkdir(Form(
"Plane_%s", planeName[iP].Data()),
"",
true);
332 TDirectory* dir_eklm = dir_channels->mkdir(
"EKLM",
"",
true);
333 for (
int iF = 0; iF < 2; ++iF) {
334 TDirectory* dir_section = dir_eklm->mkdir(sectionName[iF].Data(),
"",
true);
335 for (
int iS = 0; iS < 4; ++iS) {
336 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
337 int maxLayer = 12 + 2 * iF;
338 for (
int iL = 0; iL < maxLayer; ++iL) {
339 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
340 for (
int iP = 0; iP < 2; ++iP) {
348 B2INFO(
"Created directory structure for per-channel histograms.");
354 TString iFstring[2] = {
"Backward",
"Forward"};
355 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
358 h_diff =
new TH1F(
"h_diff",
"Position difference between bklmHit2d and extHit;position difference", 100, 0, 10);
359 h_calibrated =
new TH1I(
"h_calibrated_summary",
"h_calibrated_summary;calibrated or not", 3, 0, 3);
360 hc_calibrated =
new TH1I(
"hc_calibrated_summary",
"hc_calibrated_summary;calibrated or not", 3, 0, 3);
378 double maximalPhiStripLengthBKLM =
380 double maximalZStripLengthBKLM =
382 double maximalStripLengthEKLM =
386 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
389 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
392 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
393 50, 0.0, maximalPhiStripLengthBKLM);
395 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
396 50, 0.0, maximalZStripLengthBKLM);
398 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
399 50, 0.0, maximalStripLengthEKLM);
401 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
402 50, 0.0, maximalStripLengthEKLM);
405 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
408 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
411 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
412 50, 0.0, maximalPhiStripLengthBKLM);
414 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
415 50, 0.0, maximalZStripLengthBKLM);
417 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
418 50, 0.0, maximalStripLengthEKLM);
420 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
421 50, 0.0, maximalStripLengthEKLM);
424 h_time_scint_tc =
new TH1F(
"h_time_scint_tc",
"time distribution for Scintillator", nBin_scint,
426 h_time_scint_tc_end =
new TH1F(
"h_time_scint_tc_end",
"time distribution for Scintillator (Endcap)", nBin_scint,
433 h_time_scint =
new TH1F(
"h_time_scint",
"time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation[ns]", nBin_scint,
435 h_time_scint_end =
new TH1F(
"h_time_scint_end",
"time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
438 hc_time_rpc =
new TH1F(
"hc_time_rpc",
"Calibrated time distribution for RPC; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
441 "Calibrated time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
445 "Calibrated time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
450 "RPC: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
452 "BKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
454 "EKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
458 "RPC: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
460 "BKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
462 "EKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -20.0, 20.0);
468 "RPC: #mu^{+} hit multiplicity;N_{hits};Events", 100, 0, 100);
470 "RPC: #mu^{-} hit multiplicity;N_{hits};Events", 100, 0, 100);
472 "BKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
474 "BKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
476 "EKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
478 "EKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
482 "RPC: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
483 50, 0, 2.0, 100, -40, 40);
485 "BKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
486 50, 0, 1.0, 100, -40, 40);
488 "EKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
489 50, 0, 1.0, 100, -20, 20);
493 "RPC: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
496 "BKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
499 "EKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
504 "RPC: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
505 50, 0, 200, 100, -40, 40);
507 "BKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
508 40, 0, 40, 100, -40, 40);
510 "EKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
511 40, 0, 40, 100, -20, 20);
515 "RPC: #DeltaT_{0} (N^{+}+N^{-} < 10);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
517 "RPC: #DeltaT_{0} (10 #leq N^{+}+N^{-} < 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
519 "RPC: #DeltaT_{0} (N^{+}+N^{-} #geq 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
522 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
524 "BKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
526 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
529 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
531 "EKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
533 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
536 B2INFO(
"Skipping debug histogram allocation (m_saveAllPlots = false)");
540 for (
int iF = 0; iF < 2; ++iF) {
541 hn = Form(
"h_timeF%d_rpc", iF);
542 ht = Form(
"Time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
544 hn = Form(
"h_timeF%d_scint", iF);
545 ht = Form(
"Time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
548 hn = Form(
"h_timeF%d_scint_end", iF);
549 ht = Form(
"Time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
553 hn = Form(
"h2_timeF%d_rpc", iF);
554 ht = Form(
"Time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
556 hn = Form(
"h2_timeF%d_scint", iF);
557 ht = Form(
"Time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
560 hn = Form(
"h2_timeF%d_scint_end", iF);
561 ht = Form(
"Time distribution for Scintillator of %s (Endcap); Sector Index; T_rec-T_0-T_fly-T_propagation[ns]",
562 iFstring[iF].Data());
566 hn = Form(
"hc_timeF%d_rpc", iF);
567 ht = Form(
"Calibrated time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iFstring[iF].Data());
569 hn = Form(
"hc_timeF%d_scint", iF);
570 ht = Form(
"Calibrated time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
571 iFstring[iF].Data());
574 hn = Form(
"hc_timeF%d_scint_end", iF);
575 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
576 iFstring[iF].Data());
580 hn = Form(
"h2c_timeF%d_rpc", iF);
581 ht = Form(
"Calibrated time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
582 iFstring[iF].Data());
585 hn = Form(
"h2c_timeF%d_scint", iF);
586 ht = Form(
"Calibrated time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
587 iFstring[iF].Data());
590 hn = Form(
"h2c_timeF%d_scint_end", iF);
591 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap) ; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
592 iFstring[iF].Data());
596 for (
int iS = 0; iS < 8; ++iS) {
598 hn = Form(
"h_timeF%d_S%d_scint", iF, iS);
599 ht = Form(
"Time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
602 hn = Form(
"h_timeF%d_S%d_rpc", iF, iS);
603 ht = Form(
"Time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
605 hn = Form(
"h2_timeF%d_S%d", iF, iS);
606 ht = Form(
"Time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
610 hn = Form(
"hc_timeF%d_S%d_scint", iF, iS);
611 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
612 iFstring[iF].Data());
615 hn = Form(
"hc_timeF%d_S%d_rpc", iF, iS);
616 ht = Form(
"Calibrated time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
617 iFstring[iF].Data());
620 hn = Form(
"h2c_timeF%d_S%d", iF, iS);
621 ht = Form(
"Calibrated time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
622 iFstring[iF].Data());
627 for (
int iL = 0; iL < 2; ++iL) {
628 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
629 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
630 iFstring[iF].Data());
633 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
634 ht = Form(
"Calibrated time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
635 iL, iS, iFstring[iF].Data());
639 for (
int iP = 0; iP < 2; ++iP) {
640 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
641 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]",
642 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
645 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
646 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
647 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
651 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
652 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]",
653 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
656 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
657 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]",
658 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
664 for (
int iL = 2; iL < 15; ++iL) {
665 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
666 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());
669 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
670 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,
671 iFstring[iF].Data());
674 for (
int iP = 0; iP < 2; ++iP) {
675 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
676 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,
677 iFstring[iF].Data());
680 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
681 ht = Form(
"time distribution for RPC of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
682 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
685 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
686 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]",
687 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
691 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
692 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]",
693 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
700 int maxLay = 12 + 2 * iF;
701 for (
int iS = 0; iS < 4; ++iS) {
702 hn = Form(
"h_timeF%d_S%d_scint_end", iF, iS);
703 ht = Form(
"Time distribution for Scintillator of Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iS,
704 iFstring[iF].Data());
707 hn = Form(
"h2_timeF%d_S%d_end", iF, iS);
708 ht = Form(
"Time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
711 hn = Form(
"hc_timeF%d_S%d_scint_end", iF, iS);
712 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d (Endcap), %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
713 iS, iFstring[iF].Data());
716 hn = Form(
"h2c_timeF%d_S%d_end", iF, iS);
717 ht = Form(
"Calibrated time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
718 iS, iFstring[iF].Data());
719 h2c_timeFS_end[iF][iS] =
new TH2F(hn.Data(), ht.Data(), maxLay, 0, maxLay, nBin_scint,
723 for (
int iL = 0; iL < maxLay; ++iL) {
724 hn = Form(
"h_timeF%d_S%d_L%d_end", iF, iS, iL);
725 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
726 iFstring[iF].Data());
729 hn = Form(
"hc_timeF%d_S%d_L%d_end", iF, iS, iL);
730 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]",
731 iL, iS, iFstring[iF].Data());
735 for (
int iP = 0; iP < 2; ++iP) {
736 hn = Form(
"h_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
737 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
738 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
742 hn = Form(
"h2_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
743 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]",
744 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
748 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
749 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]",
750 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
754 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
755 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]",
756 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
757 h2c_timeFSLP_end[iF][iS][iL][iP] =
new TH2F(hn.Data(), ht.Data(), 75, 0, 75, nBin_scint,
1123 gROOT->SetBatch(kTRUE);
1130 fcn_gaus =
new TF1(
"fcn_gaus",
"gaus");
1131 fcn_land =
new TF1(
"fcn_land",
"landau");
1132 fcn_pol1 =
new TF1(
"fcn_pol1",
"pol1");
1133 fcn_const =
new TF1(
"fcn_const",
"pol0");
1141 std::string name =
"time_calibration.root";
1145 if (stat(name.c_str(), &buffer) != 0)
1147 name =
"time_calibration_" + std::to_string(i) +
".root";
1152 m_outFile =
new TFile(name.c_str(),
"recreate");
1155 std::vector<struct Event> eventsChannel;
1156 eventsChannel.clear();
1160 B2INFO(
"Counting events per channel...");
1161 std::map<KLMChannelNumber, unsigned int> eventCounts;
1165 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsBKLM;
1166 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsEKLM;
1171 m_cFlag[channel] = ChannelCalibrationStatus::c_NotEnoughData;
1173 if (eventCounts.find(channel) == eventCounts.end())
1176 int nEvents = eventCounts[channel];
1178 B2WARNING(
"Not enough calibration data collected."
1179 <<
LogVar(
"channel", channel)
1180 <<
LogVar(
"number of digit", nEvents));
1184 m_cFlag[channel] = ChannelCalibrationStatus::c_FailedFit;
1188 channelsBKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1191 channelsEKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1195 std::sort(channelsBKLM.begin(), channelsBKLM.end(), compareEventNumber);
1196 std::sort(channelsEKLM.begin(), channelsEKLM.end(), compareEventNumber);
1199 double delayBKLM, delayBKLMError;
1200 double delayEKLM, delayEKLMError;
1208 B2INFO(
"2D fits complete, data cleared.");
1245 std::vector<std::pair<std::string, std::function<bool(
const KLMChannelIndex&)>>> batches = {
1246 {
"RPC Backward", isRPCBackward},
1247 {
"RPC Forward", isRPCForward},
1248 {
"BKLM Scintillator Backward", isBKLMScintillatorBackward},
1249 {
"BKLM Scintillator Forward", isBKLMScintillatorForward},
1250 {
"EKLM Scintillator Backward", isEKLMScintillatorBackward},
1251 {
"EKLM Scintillator Forward", isEKLMScintillatorForward}
1258 B2INFO(
"First loop: Computing global statistics (batched processing)...");
1260 TString iFstring[2] = {
"Backward",
"Forward"};
1261 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
1263 int nBin_scint = 80;
1265 for (
const auto& batch : batches) {
1266 B2INFO(
"Processing batch for global stats: " << batch.first);
1270 channelId = klmChannel.getKLMChannelNumber();
1272 if (!batch.second(klmChannel))
1275 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1281 eventsChannel =
m_evts[channelId];
1282 int iSub = klmChannel.getSubdetector();
1286 for (
const Event& event : eventsChannel) {
1291 XYZVector diffD = XYZVector(event.diffDistX, event.diffDistY, event.diffDistZ);
1294 double timeHit =
event.time();
1296 timeHit = timeHit -
event.t0;
1298 if (timeHit <= -400e3)
1315 B2INFO(
"Batch processed and cleared: " << batch.first);
1324 B2INFO(
"Global Mean for Raw." <<
LogVar(
"RPC", tmpMean_rpc_global)
1325 <<
LogVar(
"Scint BKLM", tmpMean_scint_global)
1326 <<
LogVar(
"Scint EKLM", tmpMean_scint_global_end));
1332 B2INFO(
"Second pass: Computing per-channel time shifts (batched processing)...");
1334 for (
const auto& batch : batches) {
1335 B2INFO(
"Processing batch for time shifts: " << batch.first);
1339 channelId = klmChannel.getKLMChannelNumber();
1341 if (!batch.second(klmChannel))
1344 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1350 eventsChannel =
m_evts[channelId];
1351 int iSub = klmChannel.getSubdetector();
1352 int iF, iS, iL, iP, iC;
1355 iF = klmChannel.getSection();
1356 iS = klmChannel.getSector() - 1;
1357 iL = klmChannel.getLayer() - 1;
1358 iP = klmChannel.getPlane();
1359 iC = klmChannel.getStrip() - 1;
1361 iF = klmChannel.getSection() - 1;
1362 iS = klmChannel.getSector() - 1;
1363 iL = klmChannel.getLayer() - 1;
1364 iP = klmChannel.getPlane() - 1;
1365 iC = klmChannel.getStrip() - 1;
1370 TH1F* h_temp_tc =
nullptr;
1375 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1376 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1377 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1380 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1381 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1382 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1387 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc_end", iF, iS, iL, iP, iC);
1388 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1389 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1394 for (
const Event& event : eventsChannel) {
1399 double timeHit =
event.time();
1401 timeHit = timeHit -
event.t0;
1402 if (timeHit <= -400e3)
1404 h_temp_tc->Fill(timeHit);
1408 double tmpMean_channel =
fcn_gaus->GetParameter(1);
1413 m_timeShift[channelId] = tmpMean_channel - tmpMean_rpc_global;
1415 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global;
1418 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global_end;
1425 B2INFO(
"Batch processed and cleared: " << batch.first);
1431 B2INFO(
"Effective Light m_timeShift obtained.");
1439 B2INFO(
"Effective light speed fitting.");
1443 double fittedDelayRPCPhi =
fcn_pol1->GetParameter(1);
1444 double e_slope_rpc_phi =
fcn_pol1->GetParError(1);
1447 double fittedDelayRPCZ =
fcn_pol1->GetParameter(1);
1448 double e_slope_rpc_z =
fcn_pol1->GetParError(1);
1451 double delayRPCPhi, delayRPCZ;
1455 B2INFO(
"Using fixed RPC propagation delay: " <<
m_fixedRPCDelay <<
" ns/cm (c_eff = 0.5c)"
1456 <<
LogVar(
"Fitted phi (not used)", fittedDelayRPCPhi)
1457 <<
LogVar(
"Fitted Z (not used)", fittedDelayRPCZ));
1459 delayRPCPhi = fittedDelayRPCPhi;
1460 delayRPCZ = fittedDelayRPCZ;
1464 double slope_scint_phi =
fcn_pol1->GetParameter(1);
1465 double e_slope_scint_phi =
fcn_pol1->GetParError(1);
1468 double slope_scint_z =
fcn_pol1->GetParameter(1);
1469 double e_slope_scint_z =
fcn_pol1->GetParError(1);
1472 double slope_scint_plane1_end =
fcn_pol1->GetParameter(1);
1473 double e_slope_scint_plane1_end =
fcn_pol1->GetParError(1);
1476 double slope_scint_plane2_end =
fcn_pol1->GetParameter(1);
1477 double e_slope_scint_plane2_end =
fcn_pol1->GetParError(1);
1479 TString logStr_phi, logStr_z;
1481 logStr_phi = Form(
"%.4f ns/cm (fixed)", delayRPCPhi);
1482 logStr_z = Form(
"%.4f ns/cm (fixed)", delayRPCZ);
1483 B2INFO(
"Delay in RPCs (using fixed value):"
1484 <<
LogVar(
"Used Value (phi readout)", logStr_phi.Data())
1485 <<
LogVar(
"Used Value (z readout)", logStr_z.Data()));
1487 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", delayRPCPhi, e_slope_rpc_phi);
1488 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayRPCZ, e_slope_rpc_z);
1489 B2INFO(
"Delay in RPCs:"
1490 <<
LogVar(
"Fitted Value (phi readout)", logStr_phi.Data())
1491 <<
LogVar(
"Fitted Value (z readout)", logStr_z.Data()));
1493 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_phi, e_slope_scint_phi);
1494 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_z, e_slope_scint_z);
1495 B2INFO(
"Delay in BKLM scintillators:"
1496 <<
LogVar(
"Fitted Value (phi readout) ", logStr_phi.Data())
1497 <<
LogVar(
"Fitted Value (z readout) ", logStr_z.Data()));
1498 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane1_end,
1499 e_slope_scint_plane1_end);
1500 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane2_end,
1501 e_slope_scint_plane2_end);
1502 B2INFO(
"Delay in EKLM scintillators:"
1503 <<
LogVar(
"Fitted Value (plane1 readout) ", logStr_phi.Data())
1504 <<
LogVar(
"Fitted Value (plane2 readout) ", logStr_z.Data()));
1506 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayBKLM, delayBKLMError);
1507 B2INFO(
"Delay in BKLM scintillators:"
1508 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1509 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayEKLM, delayEKLMError);
1510 B2INFO(
"Delay in EKLM scintillators:"
1511 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1522 B2INFO(
"Third loop: Time distribution filling (batched processing)...");
1524 for (
const auto& batch : batches) {
1525 B2INFO(
"Processing batch: " << batch.first);
1529 channelId = klmChannel.getKLMChannelNumber();
1531 if (!batch.second(klmChannel))
1534 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1540 eventsChannel =
m_evts[channelId];
1541 int iSub = klmChannel.getSubdetector();
1542 int iF, iS, iL, iP, iC;
1545 iF = klmChannel.getSection();
1546 iS = klmChannel.getSector() - 1;
1547 iL = klmChannel.getLayer() - 1;
1548 iP = klmChannel.getPlane();
1549 iC = klmChannel.getStrip() - 1;
1551 iF = klmChannel.getSection() - 1;
1552 iS = klmChannel.getSector() - 1;
1553 iL = klmChannel.getLayer() - 1;
1554 iP = klmChannel.getPlane() - 1;
1555 iC = klmChannel.getStrip() - 1;
1560 TH1F* h_temp =
nullptr;
1565 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1566 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1567 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1570 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1571 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1572 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1577 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1578 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1579 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1585 for (
const Event& event : eventsChannel) {
1590 double timeHit =
event.time();
1592 timeHit = timeHit -
event.t0;
1593 if (timeHit <= -400e3)
1601 propgationT =
event.dist * delayRPCZ;
1603 propgationT =
event.dist * delayRPCPhi;
1604 double time = timeHit - propgationT;
1619 double propgationT =
event.dist * delayBKLM;
1620 double time = timeHit - propgationT;
1636 double propgationT =
event.dist * delayEKLM;
1637 double time = timeHit - propgationT;
1654 TFitResultPtr r = h_temp->Fit(
fcn_gaus,
"LESQ");
1656 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1669 B2INFO(
"Batch processed and cleared: " << batch.first);
1672 B2INFO(
"Original filling done.");
1675 int iChannel_rpc = 0;
1677 int iChannel_end = 0;
1679 channelId = klmChannel.getKLMChannelNumber();
1680 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1683 int iSub = klmChannel.getSubdetector();
1685 int iL = klmChannel.getLayer() - 1;
1715 B2INFO(
"Channel's time distribution fitting done.");
1720 B2INFO(
"Calibrated channel's time distribution filling begins.");
1724 channelId = klmChannel.getKLMChannelNumber();
1734 channelId = klmChannel.getKLMChannelNumber();
1739 B2DEBUG(20,
"Uncalibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeShift[channelId]));
1746 channelId = klmChannel.getKLMChannelNumber();
1748 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
1751 int iSub = klmChannel.getSubdetector();
1754 int iL = klmChannel.getLayer() - 1;
1778 B2INFO(
"Fourth loop: Calibrated time distribution filling (batched processing)...");
1780 for (
const auto& batch : batches) {
1781 B2INFO(
"Processing batch: " << batch.first);
1785 channelId = klmChannel.getKLMChannelNumber();
1787 if (!batch.second(klmChannel))
1793 eventsChannel =
m_evts[channelId];
1794 int iSub = klmChannel.getSubdetector();
1795 int iF, iS, iL, iP, iC;
1798 iF = klmChannel.getSection();
1799 iS = klmChannel.getSector() - 1;
1800 iL = klmChannel.getLayer() - 1;
1801 iP = klmChannel.getPlane();
1802 iC = klmChannel.getStrip() - 1;
1804 iF = klmChannel.getSection() - 1;
1805 iS = klmChannel.getSector() - 1;
1806 iL = klmChannel.getLayer() - 1;
1807 iP = klmChannel.getPlane() - 1;
1808 iC = klmChannel.getStrip() - 1;
1812 TH1F* hc_temp =
nullptr;
1817 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1818 ht = Form(
"Calibrated time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1819 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1823 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1824 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1825 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1830 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1831 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1832 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1837 for (
const Event& event : eventsChannel) {
1842 double timeHit =
event.time();
1844 timeHit = timeHit -
event.t0;
1845 if (timeHit <= -400e3)
1853 propgationT =
event.dist * delayRPCZ;
1855 propgationT =
event.dist * delayRPCPhi;
1856 double time = timeHit - propgationT -
m_timeShift[channelId];
1859 hc_temp->Fill(time);
1871 double propgationT =
event.dist * delayBKLM;
1872 double time = timeHit - propgationT -
m_timeShift[channelId];
1875 hc_temp->Fill(time);
1888 double propgationT =
event.dist * delayEKLM;
1889 double time = timeHit - propgationT -
m_timeShift[channelId];
1892 hc_temp->Fill(time);
1906 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData) {
1911 TFitResultPtr rc = hc_temp->Fit(
fcn_gaus,
"LESQ");
1913 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1926 B2INFO(
"Batch processed and cleared: " << batch.first);
1930 int icChannel_rpc = 0;
1932 int icChannel_end = 0;
1934 channelId = klmChannel.getKLMChannelNumber();
1935 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1938 int iSub = klmChannel.getSubdetector();
1940 int iL = klmChannel.getLayer() - 1;
1970 B2INFO(
"Channel's time distribution fitting done.");
1975 B2INFO(
"Calibrated channel's time distribution filling begins.");
1979 channelId = klmChannel.getKLMChannelNumber();
1989 channelId = klmChannel.getKLMChannelNumber();
1994 B2DEBUG(20,
"Calibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeRes[channelId]));
2001 channelId = klmChannel.getKLMChannelNumber();
2003 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
2006 int iSub = klmChannel.getSubdetector();
2009 int iL = klmChannel.getLayer() - 1;
2026 B2INFO(
"Fifth pass: Computing di-muon ΔT0 for EventT0 hit resolution calibration...");
2029 struct TrackT0Info {
2031 int nHits_BKLM_Scint;
2032 int nHits_BKLM_RPC_Phi;
2033 int nHits_BKLM_RPC_Z;
2034 int nHits_EKLM_Scint;
2035 double sumT0_BKLM_Scint;
2036 double sumT0_BKLM_RPC_Phi;
2037 double sumT0_BKLM_RPC_Z;
2038 double sumT0_EKLM_Scint;
2040 TrackT0Info() : charge(0),
2041 nHits_BKLM_Scint(0),
2042 nHits_BKLM_RPC_Phi(0),
2043 nHits_BKLM_RPC_Z(0),
2044 nHits_EKLM_Scint(0),
2045 sumT0_BKLM_Scint(0.0),
2046 sumT0_BKLM_RPC_Phi(0.0),
2047 sumT0_BKLM_RPC_Z(0.0),
2048 sumT0_EKLM_Scint(0.0) {}
2052 std::map<std::pair<int, int>, std::map<int, TrackT0Info>> eventTrackMap;
2055 for (
const auto& batch : batches) {
2056 B2INFO(
"Processing batch for di-muon analysis: " << batch.first);
2059 for (
const auto& channelPair :
m_evts) {
2061 const std::vector<Event>& chEvents = channelPair.second;
2064 int subdetector, section, sector, layer, plane, strip;
2066 chId, &subdetector, §ion, §or, &layer, &plane, &strip);
2069 int iSub = subdetector;
2072 for (
const Event& event : chEvents) {
2078 std::pair<int, int> eventKey(event.Run, event.Events);
2079 int trackIdx =
event.nTrack;
2080 int charge =
event.Track_Charge;
2083 double timeHit =
event.time() -
m_timeShift[chId];
2085 if (timeHit <= -400e3)
2094 propT =
event.dist * delayRPCZ;
2096 propT =
event.dist * delayRPCPhi;
2099 propT =
event.dist * delayBKLM;
2103 propT =
event.dist * delayEKLM;
2106 double t0_estimate = timeHit - propT;
2109 TrackT0Info& trackInfo = eventTrackMap[eventKey][trackIdx];
2110 trackInfo.charge = charge;
2116 trackInfo.nHits_BKLM_RPC_Z++;
2117 trackInfo.sumT0_BKLM_RPC_Z += t0_estimate;
2119 trackInfo.nHits_BKLM_RPC_Phi++;
2120 trackInfo.sumT0_BKLM_RPC_Phi += t0_estimate;
2124 trackInfo.nHits_BKLM_Scint++;
2125 trackInfo.sumT0_BKLM_Scint += t0_estimate;
2128 trackInfo.nHits_EKLM_Scint++;
2129 trackInfo.sumT0_EKLM_Scint += t0_estimate;
2137 B2INFO(
"Event-track map built. Processing events for EventT0 histograms...");
2141 double sum_delta2_over_v_BKLM_Scint = 0.0;
2142 double sum_delta2_over_v_BKLM_RPC_Phi = 0.0;
2143 double sum_delta2_over_v_BKLM_RPC_Z = 0.0;
2144 double sum_delta2_over_v_EKLM_Scint = 0.0;
2146 int nDimuon_BKLM_Scint = 0;
2147 int nDimuon_BKLM_RPC_Phi = 0;
2148 int nDimuon_BKLM_RPC_Z = 0;
2149 int nDimuon_EKLM_Scint = 0;
2151 for (
const auto& eventPair : eventTrackMap) {
2152 const auto& trackMap = eventPair.second;
2155 if (trackMap.size() != 2)
2158 auto it1 = trackMap.begin();
2159 auto it2 = trackMap.begin();
2161 const TrackT0Info& track1 = it1->second;
2162 const TrackT0Info& track2 = it2->second;
2165 if (track1.charge * track2.charge >= 0)
2169 const TrackT0Info& muPlus = (track1.charge > 0) ? track1 : track2;
2170 const TrackT0Info& muMinus = (track1.charge > 0) ? track2 : track1;
2173 if (muPlus.nHits_BKLM_Scint > 0 && muMinus.nHits_BKLM_Scint > 0) {
2174 double t0_plus = muPlus.sumT0_BKLM_Scint / muPlus.nHits_BKLM_Scint;
2175 double t0_minus = muMinus.sumT0_BKLM_Scint / muMinus.nHits_BKLM_Scint;
2176 double deltaT0 = t0_plus - t0_minus;
2179 double v = 1.0 / muPlus.nHits_BKLM_Scint + 1.0 / muMinus.nHits_BKLM_Scint;
2180 int nTotal = muPlus.nHits_BKLM_Scint + muMinus.nHits_BKLM_Scint;
2186 sum_delta2_over_v_BKLM_Scint += (deltaT0 * deltaT0) / v;
2187 nDimuon_BKLM_Scint++;
2204 }
else if (nTotal < 15) {
2212 if (muPlus.nHits_BKLM_RPC_Phi > 0 && muMinus.nHits_BKLM_RPC_Phi > 0) {
2213 double t0_plus = muPlus.sumT0_BKLM_RPC_Phi / muPlus.nHits_BKLM_RPC_Phi;
2214 double t0_minus = muMinus.sumT0_BKLM_RPC_Phi / muMinus.nHits_BKLM_RPC_Phi;
2215 double deltaT0 = t0_plus - t0_minus;
2217 double v = 1.0 / muPlus.nHits_BKLM_RPC_Phi + 1.0 / muMinus.nHits_BKLM_RPC_Phi;
2218 int nTotal = muPlus.nHits_BKLM_RPC_Phi + muMinus.nHits_BKLM_RPC_Phi;
2223 sum_delta2_over_v_BKLM_RPC_Phi += (deltaT0 * deltaT0) / v;
2224 nDimuon_BKLM_RPC_Phi++;
2239 }
else if (nTotal < 30) {
2247 if (muPlus.nHits_BKLM_RPC_Z > 0 && muMinus.nHits_BKLM_RPC_Z > 0) {
2248 double t0_plus = muPlus.sumT0_BKLM_RPC_Z / muPlus.nHits_BKLM_RPC_Z;
2249 double t0_minus = muMinus.sumT0_BKLM_RPC_Z / muMinus.nHits_BKLM_RPC_Z;
2250 double deltaT0 = t0_plus - t0_minus;
2252 double v = 1.0 / muPlus.nHits_BKLM_RPC_Z + 1.0 / muMinus.nHits_BKLM_RPC_Z;
2253 int nTotal = muPlus.nHits_BKLM_RPC_Z + muMinus.nHits_BKLM_RPC_Z;
2258 sum_delta2_over_v_BKLM_RPC_Z += (deltaT0 * deltaT0) / v;
2259 nDimuon_BKLM_RPC_Z++;
2274 }
else if (nTotal < 30) {
2282 if (muPlus.nHits_EKLM_Scint > 0 && muMinus.nHits_EKLM_Scint > 0) {
2283 double t0_plus = muPlus.sumT0_EKLM_Scint / muPlus.nHits_EKLM_Scint;
2284 double t0_minus = muMinus.sumT0_EKLM_Scint / muMinus.nHits_EKLM_Scint;
2285 double deltaT0 = t0_plus - t0_minus;
2287 double v = 1.0 / muPlus.nHits_EKLM_Scint + 1.0 / muMinus.nHits_EKLM_Scint;
2288 int nTotal = muPlus.nHits_EKLM_Scint + muMinus.nHits_EKLM_Scint;
2293 sum_delta2_over_v_EKLM_Scint += (deltaT0 * deltaT0) / v;
2294 nDimuon_EKLM_Scint++;
2310 }
else if (nTotal < 15) {
2318 B2INFO(
"Di-muon ΔT0 data collected."
2319 <<
LogVar(
"BKLM Scint di-muon events", nDimuon_BKLM_Scint)
2320 <<
LogVar(
"BKLM RPC Phi di-muon events", nDimuon_BKLM_RPC_Phi)
2321 <<
LogVar(
"BKLM RPC Z di-muon events", nDimuon_BKLM_RPC_Z)
2322 <<
LogVar(
"EKLM Scint di-muon events", nDimuon_EKLM_Scint));
2327 float sigma_BKLM_Scint = 10.0f;
2328 float sigma_BKLM_Scint_err = 1.0f;
2329 if (nDimuon_BKLM_Scint > 0) {
2330 double sigma2 = sum_delta2_over_v_BKLM_Scint /
static_cast<double>(nDimuon_BKLM_Scint);
2331 sigma_BKLM_Scint =
static_cast<float>(std::sqrt(sigma2));
2333 sigma_BKLM_Scint_err = sigma_BKLM_Scint / std::sqrt(2.0 * nDimuon_BKLM_Scint);
2336 float sigma_RPC_Phi = 10.0f;
2337 float sigma_RPC_Phi_err = 1.0f;
2338 if (nDimuon_BKLM_RPC_Phi > 0) {
2339 double sigma2 = sum_delta2_over_v_BKLM_RPC_Phi /
static_cast<double>(nDimuon_BKLM_RPC_Phi);
2340 sigma_RPC_Phi =
static_cast<float>(std::sqrt(sigma2));
2341 sigma_RPC_Phi_err = sigma_RPC_Phi / std::sqrt(2.0 * nDimuon_BKLM_RPC_Phi);
2344 float sigma_RPC_Z = 10.0f;
2345 float sigma_RPC_Z_err = 1.0f;
2346 if (nDimuon_BKLM_RPC_Z > 0) {
2347 double sigma2 = sum_delta2_over_v_BKLM_RPC_Z /
static_cast<double>(nDimuon_BKLM_RPC_Z);
2348 sigma_RPC_Z =
static_cast<float>(std::sqrt(sigma2));
2349 sigma_RPC_Z_err = sigma_RPC_Z / std::sqrt(2.0 * nDimuon_BKLM_RPC_Z);
2353 float sigma_RPC = 10.0f;
2354 float sigma_RPC_err = 1.0f;
2355 int nDimuon_RPC_total = nDimuon_BKLM_RPC_Phi + nDimuon_BKLM_RPC_Z;
2356 if (nDimuon_RPC_total > 0) {
2358 double w_phi =
static_cast<double>(nDimuon_BKLM_RPC_Phi) / nDimuon_RPC_total;
2359 double w_z =
static_cast<double>(nDimuon_BKLM_RPC_Z) / nDimuon_RPC_total;
2360 sigma_RPC = w_phi * sigma_RPC_Phi + w_z * sigma_RPC_Z;
2362 sigma_RPC_err = std::sqrt(w_phi * w_phi * sigma_RPC_Phi_err * sigma_RPC_Phi_err +
2363 w_z * w_z * sigma_RPC_Z_err * sigma_RPC_Z_err);
2366 float sigma_EKLM_Scint = 10.0f;
2367 float sigma_EKLM_Scint_err = 1.0f;
2368 if (nDimuon_EKLM_Scint > 0) {
2369 double sigma2 = sum_delta2_over_v_EKLM_Scint /
static_cast<double>(nDimuon_EKLM_Scint);
2370 sigma_EKLM_Scint =
static_cast<float>(std::sqrt(sigma2));
2371 sigma_EKLM_Scint_err = sigma_EKLM_Scint / std::sqrt(2.0 * nDimuon_EKLM_Scint);
2374 B2INFO(
"Extracted per-hit resolutions using event-by-event weighting:"
2375 <<
LogVar(
"σ_BKLM_Scint [ns]", sigma_BKLM_Scint) <<
LogVar(
"±", sigma_BKLM_Scint_err)
2376 <<
LogVar(
"σ_RPC_Phi [ns]", sigma_RPC_Phi) <<
LogVar(
"±", sigma_RPC_Phi_err)
2377 <<
LogVar(
"σ_RPC_Z [ns]", sigma_RPC_Z) <<
LogVar(
"±", sigma_RPC_Z_err)
2378 <<
LogVar(
"σ_RPC_combined [ns]", sigma_RPC) <<
LogVar(
"±", sigma_RPC_err)
2379 <<
LogVar(
"σ_EKLM_Scint [ns]", sigma_EKLM_Scint) <<
LogVar(
"±", sigma_EKLM_Scint_err));
2388 B2INFO(
"EventT0 hit resolution calibration complete and stored in payload.");
2391 eventTrackMap.clear();
2412 B2INFO(
"Save Histograms into Files.");
2415 TDirectory* dir_monitor =
m_outFile->mkdir(
"monitor_Hists",
"",
true);
2419 h_diff->SetDirectory(dir_monitor);
2422 TDirectory* dir_eventT0 =
m_outFile->mkdir(
"EventT0",
"",
true);
2471 TDirectory* dir_effC =
m_outFile->mkdir(
"effC_Hists",
"",
true);
2487 TDirectory* dir_time =
m_outFile->mkdir(
"time",
"",
true);
2512 B2INFO(
"Top file setup Done.");
2516 B2INFO(
"Skipping debug histogram directory creation (m_saveAllPlots = false)");
2520 B2INFO(
"File Write and Close. Done.");
2524 TDirectory* dir_time_F[2];
2525 TDirectory* dir_time_FS[2][8];
2526 TDirectory* dir_time_FSL[2][8][15];
2527 TDirectory* dir_time_FSLP[2][8][15][2];
2528 TDirectory* dir_time_F_end[2];
2529 TDirectory* dir_time_FS_end[2][4];
2530 TDirectory* dir_time_FSL_end[2][4][14];
2531 TDirectory* dir_time_FSLP_end[2][4][14][2];
2533 B2INFO(
"Sub files declare Done.");
2534 for (
int iF = 0; iF < 2; ++iF) {
2553 sprintf(dirname,
"isForward_%d", iF);
2554 dir_time_F[iF] = dir_time->mkdir(dirname,
"",
true);
2555 dir_time_F[iF]->cd();
2557 for (
int iS = 0; iS < 8; ++iS) {
2564 h2_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2565 h2c_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2567 sprintf(dirname,
"Sector_%d", iS + 1);
2568 dir_time_FS[iF][iS] = dir_time_F[iF]->mkdir(dirname,
"",
true);
2569 dir_time_FS[iF][iS]->cd();
2571 for (
int iL = 0; iL < 15; ++iL) {
2572 h_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2573 hc_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2575 sprintf(dirname,
"Layer_%d", iL + 1);
2576 dir_time_FSL[iF][iS][iL] = dir_time_FS[iF][iS]->mkdir(dirname,
"",
true);
2577 dir_time_FSL[iF][iS][iL]->cd();
2578 for (
int iP = 0; iP < 2; ++iP) {
2579 h_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2580 hc_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2581 h2_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2582 h2c_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2584 sprintf(dirname,
"Plane_%d", iP);
2585 dir_time_FSLP[iF][iS][iL][iP] = dir_time_FSL[iF][iS][iL]->mkdir(dirname,
"",
true);
2586 dir_time_FSLP[iF][iS][iL][iP]->cd();
2592 sprintf(dirname,
"isForward_%d_end", iF + 1);
2593 dir_time_F_end[iF] = dir_time->mkdir(dirname,
"",
true);
2594 dir_time_F_end[iF]->cd();
2595 int maxLayer = 12 + 2 * iF;
2596 for (
int iS = 0; iS < 4; ++iS) {
2603 sprintf(dirname,
"Sector_%d_end", iS + 1);
2604 dir_time_FS_end[iF][iS] = dir_time_F_end[iF]->mkdir(dirname,
"",
true);
2605 dir_time_FS_end[iF][iS]->cd();
2606 for (
int iL = 0; iL < maxLayer; ++iL) {
2607 h_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2608 hc_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2610 sprintf(dirname,
"Layer_%d_end", iL + 1);
2611 dir_time_FSL_end[iF][iS][iL] = dir_time_FS_end[iF][iS]->mkdir(dirname,
"",
true);
2612 dir_time_FSL_end[iF][iS][iL]->cd();
2613 for (
int iP = 0; iP < 2; ++iP) {
2614 h_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2615 hc_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2616 h2_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2617 h2c_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2619 sprintf(dirname,
"plane_%d_end", iP);
2620 dir_time_FSLP_end[iF][iS][iL][iP] = dir_time_FSL_end[iF][iS][iL]->mkdir(dirname,
"",
true);
2621 dir_time_FSLP_end[iF][iS][iL][iP]->cd();
2630 B2INFO(
"File Write and Close. Done.");