308 TDirectory* dir_channels =
m_outFile->mkdir(
"channels",
"Per-channel histograms",
true);
311 TDirectory* dir_bklm = dir_channels->mkdir(
"BKLM",
"",
true);
312 TString sectionName[2] = {
"Backward",
"Forward"};
313 TString planeName[2] = {
"Z",
"Phi"};
315 for (
int iF = 0; iF < 2; ++iF) {
316 TDirectory* dir_section = dir_bklm->mkdir(sectionName[iF].Data(),
"",
true);
317 for (
int iS = 0; iS < 8; ++iS) {
318 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
319 for (
int iL = 0; iL < 15; ++iL) {
320 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
321 for (
int iP = 0; iP < 2; ++iP) {
322 m_channelHistDir_BKLM[iF][iS][iL][iP] = dir_layer->mkdir(Form(
"Plane_%s", planeName[iP].Data()),
"",
true);
329 TDirectory* dir_eklm = dir_channels->mkdir(
"EKLM",
"",
true);
330 for (
int iF = 0; iF < 2; ++iF) {
331 TDirectory* dir_section = dir_eklm->mkdir(sectionName[iF].Data(),
"",
true);
332 for (
int iS = 0; iS < 4; ++iS) {
333 TDirectory* dir_sector = dir_section->mkdir(Form(
"Sector_%d", iS + 1),
"",
true);
334 int maxLayer = 12 + 2 * iF;
335 for (
int iL = 0; iL < maxLayer; ++iL) {
336 TDirectory* dir_layer = dir_sector->mkdir(Form(
"Layer_%d", iL + 1),
"",
true);
337 for (
int iP = 0; iP < 2; ++iP) {
345 B2INFO(
"Created directory structure for per-channel histograms.");
351 TString iFstring[2] = {
"Backward",
"Forward"};
352 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
355 h_diff =
new TH1F(
"h_diff",
"Position difference between bklmHit2d and extHit;position difference", 100, 0, 10);
356 h_calibrated =
new TH1I(
"h_calibrated_summary",
"h_calibrated_summary;calibrated or not", 3, 0, 3);
357 hc_calibrated =
new TH1I(
"hc_calibrated_summary",
"hc_calibrated_summary;calibrated or not", 3, 0, 3);
375 double maximalPhiStripLengthBKLM =
377 double maximalZStripLengthBKLM =
379 double maximalStripLengthEKLM =
383 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
386 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
389 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
390 50, 0.0, maximalPhiStripLengthBKLM);
392 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
393 50, 0.0, maximalZStripLengthBKLM);
395 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
396 50, 0.0, maximalStripLengthEKLM);
398 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
399 50, 0.0, maximalStripLengthEKLM);
402 "Time over propagation length for RPCs (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
405 "Time over propagation length for RPCs (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]", 50, 0.0,
408 "Time over propagation length for scintillators (Phi_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
409 50, 0.0, maximalPhiStripLengthBKLM);
411 "Time over propagation length for scintillators (Z_Readout); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
412 50, 0.0, maximalZStripLengthBKLM);
414 "Time over propagation length for scintillators (plane1, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
415 50, 0.0, maximalStripLengthEKLM);
417 "Time over propagation length for scintillators (plane2, Endcap); propagation distance[cm]; T_rec-T_0-T_fly-'T_calibration'[ns]",
418 50, 0.0, maximalStripLengthEKLM);
421 h_time_scint_tc =
new TH1F(
"h_time_scint_tc",
"time distribution for Scintillator", nBin_scint,
423 h_time_scint_tc_end =
new TH1F(
"h_time_scint_tc_end",
"time distribution for Scintillator (Endcap)", nBin_scint,
430 h_time_scint =
new TH1F(
"h_time_scint",
"time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation[ns]", nBin_scint,
432 h_time_scint_end =
new TH1F(
"h_time_scint_end",
"time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
435 hc_time_rpc =
new TH1F(
"hc_time_rpc",
"Calibrated time distribution for RPC; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
438 "Calibrated time distribution for Scintillator; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
442 "Calibrated time distribution for Scintillator (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", nBin_scint,
447 "RPC: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
449 "BKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
451 "EKLM scintillator: Event T0; T_{0}[ns]", nBin_t0, -100.0, 100.0);
455 "RPC: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
457 "BKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -40.0, 40.0);
459 "EKLM scintillator: corrected Event T0; T_{0}^{+} - T_{0}^{-} [ns]", nBin_t0, -20.0, 20.0);
465 "RPC: #mu^{+} hit multiplicity;N_{hits};Events", 100, 0, 100);
467 "RPC: #mu^{-} hit multiplicity;N_{hits};Events", 100, 0, 100);
469 "BKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
471 "BKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
473 "EKLM Scint: #mu^{+} hit multiplicity;N_{hits};Events", 30, 0, 30);
475 "EKLM Scint: #mu^{-} hit multiplicity;N_{hits};Events", 30, 0, 30);
479 "RPC: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
480 50, 0, 2.0, 100, -40, 40);
482 "BKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
483 50, 0, 1.0, 100, -40, 40);
485 "EKLM Scint: #DeltaT_{0} vs variance weight;v = 1/N^{+} + 1/N^{-};#DeltaT_{0} [ns]",
486 50, 0, 1.0, 100, -20, 20);
490 "RPC: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
493 "BKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
496 "EKLM Scint: RMS(#DeltaT_{0}) vs v;v = 1/N^{+} + 1/N^{-};RMS(#DeltaT_{0}) [ns]",
501 "RPC: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
502 50, 0, 200, 100, -40, 40);
504 "BKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
505 40, 0, 40, 100, -40, 40);
507 "EKLM Scint: #DeltaT_{0} vs total hits;N^{+} + N^{-};#DeltaT_{0} [ns]",
508 40, 0, 40, 100, -20, 20);
512 "RPC: #DeltaT_{0} (N^{+}+N^{-} < 10);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
514 "RPC: #DeltaT_{0} (10 #leq N^{+}+N^{-} < 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
516 "RPC: #DeltaT_{0} (N^{+}+N^{-} #geq 30);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
519 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
521 "BKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
523 "BKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -40.0, 40.0);
526 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} < 5);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
528 "EKLM Scint: #DeltaT_{0} (5 #leq N^{+}+N^{-} < 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
530 "EKLM Scint: #DeltaT_{0} (N^{+}+N^{-} #geq 15);#DeltaT_{0} [ns]", nBin_t0, -20.0, 20.0);
533 B2INFO(
"Skipping debug histogram allocation (m_saveAllPlots = false)");
537 for (
int iF = 0; iF < 2; ++iF) {
538 hn = Form(
"h_timeF%d_rpc", iF);
539 ht = Form(
"Time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
541 hn = Form(
"h_timeF%d_scint", iF);
542 ht = Form(
"Time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
545 hn = Form(
"h_timeF%d_scint_end", iF);
546 ht = Form(
"Time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
550 hn = Form(
"h2_timeF%d_rpc", iF);
551 ht = Form(
"Time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
553 hn = Form(
"h2_timeF%d_scint", iF);
554 ht = Form(
"Time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation[ns]", iFstring[iF].Data());
557 hn = Form(
"h2_timeF%d_scint_end", iF);
558 ht = Form(
"Time distribution for Scintillator of %s (Endcap); Sector Index; T_rec-T_0-T_fly-T_propagation[ns]",
559 iFstring[iF].Data());
563 hn = Form(
"hc_timeF%d_rpc", iF);
564 ht = Form(
"Calibrated time distribution for RPC of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iFstring[iF].Data());
566 hn = Form(
"hc_timeF%d_scint", iF);
567 ht = Form(
"Calibrated time distribution for Scintillator of %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
568 iFstring[iF].Data());
571 hn = Form(
"hc_timeF%d_scint_end", iF);
572 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap); T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
573 iFstring[iF].Data());
577 hn = Form(
"h2c_timeF%d_rpc", iF);
578 ht = Form(
"Calibrated time distribution for RPC of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
579 iFstring[iF].Data());
582 hn = Form(
"h2c_timeF%d_scint", iF);
583 ht = Form(
"Calibrated time distribution for Scintillator of %s; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
584 iFstring[iF].Data());
587 hn = Form(
"h2c_timeF%d_scint_end", iF);
588 ht = Form(
"Calibrated time distribution for Scintillator of %s (Endcap) ; Sector Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
589 iFstring[iF].Data());
593 for (
int iS = 0; iS < 8; ++iS) {
595 hn = Form(
"h_timeF%d_S%d_scint", iF, iS);
596 ht = Form(
"Time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
599 hn = Form(
"h_timeF%d_S%d_rpc", iF, iS);
600 ht = Form(
"Time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
602 hn = Form(
"h2_timeF%d_S%d", iF, iS);
603 ht = Form(
"Time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
607 hn = Form(
"hc_timeF%d_S%d_scint", iF, iS);
608 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
609 iFstring[iF].Data());
612 hn = Form(
"hc_timeF%d_S%d_rpc", iF, iS);
613 ht = Form(
"Calibrated time distribution for RPC of Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
614 iFstring[iF].Data());
617 hn = Form(
"h2c_timeF%d_S%d", iF, iS);
618 ht = Form(
"Calibrated time distribution of Sector%d, %s; Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]", iS,
619 iFstring[iF].Data());
624 for (
int iL = 0; iL < 2; ++iL) {
625 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
626 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
627 iFstring[iF].Data());
630 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
631 ht = Form(
"Calibrated time distribution for Scintillator of Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
632 iL, iS, iFstring[iF].Data());
636 for (
int iP = 0; iP < 2; ++iP) {
637 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
638 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; T_rec-T_0-T_fly-T_propagation[ns]",
639 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
642 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
643 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
644 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
648 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
649 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]",
650 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
653 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
654 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]",
655 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
661 for (
int iL = 2; iL < 15; ++iL) {
662 hn = Form(
"h_timeF%d_S%d_L%d", iF, iS, iL);
663 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());
666 hn = Form(
"hc_timeF%d_S%d_L%d", iF, iS, iL);
667 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,
668 iFstring[iF].Data());
671 for (
int iP = 0; iP < 2; ++iP) {
672 hn = Form(
"h_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
673 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,
674 iFstring[iF].Data());
677 hn = Form(
"h2_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
678 ht = Form(
"time distribution for RPC of %s, Layer%d, Sector%d, %s; Channel Index; T_rec-T_0-T_fly-T_propagation[ns]",
679 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
682 hn = Form(
"hc_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
683 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]",
684 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
688 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d", iF, iS, iL, iP);
689 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]",
690 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
697 int maxLay = 12 + 2 * iF;
698 for (
int iS = 0; iS < 4; ++iS) {
699 hn = Form(
"h_timeF%d_S%d_scint_end", iF, iS);
700 ht = Form(
"Time distribution for Scintillator of Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iS,
701 iFstring[iF].Data());
704 hn = Form(
"h2_timeF%d_S%d_end", iF, iS);
705 ht = Form(
"Time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation[ns]", iS, iFstring[iF].Data());
708 hn = Form(
"hc_timeF%d_S%d_scint_end", iF, iS);
709 ht = Form(
"Calibrated time distribution for Scintillator of Sector%d (Endcap), %s; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
710 iS, iFstring[iF].Data());
713 hn = Form(
"h2c_timeF%d_S%d_end", iF, iS);
714 ht = Form(
"Calibrated time distribution of Sector%d, %s (Endcap); Layer Index; T_rec-T_0-T_fly-T_propagation-T_calibration[ns]",
715 iS, iFstring[iF].Data());
716 h2c_timeFS_end[iF][iS] =
new TH2F(hn.Data(), ht.Data(), maxLay, 0, maxLay, nBin_scint,
720 for (
int iL = 0; iL < maxLay; ++iL) {
721 hn = Form(
"h_timeF%d_S%d_L%d_end", iF, iS, iL);
722 ht = Form(
"Time distribution for Scintillator of Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]", iL, iS,
723 iFstring[iF].Data());
726 hn = Form(
"hc_timeF%d_S%d_L%d_end", iF, iS, iL);
727 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]",
728 iL, iS, iFstring[iF].Data());
732 for (
int iP = 0; iP < 2; ++iP) {
733 hn = Form(
"h_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
734 ht = Form(
"Time distribution for Scintillator of %s, Layer%d, Sector%d, %s (Endcap); T_rec-T_0-T_fly-T_propagation[ns]",
735 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
739 hn = Form(
"h2_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
740 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]",
741 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
745 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
746 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]",
747 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
751 hn = Form(
"h2c_timeF%d_S%d_L%d_P%d_end", iF, iS, iL, iP);
752 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]",
753 iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
754 h2c_timeFSLP_end[iF][iS][iL][iP] =
new TH2F(hn.Data(), ht.Data(), 75, 0, 75, nBin_scint,
1121 gROOT->SetBatch(kTRUE);
1128 fcn_gaus =
new TF1(
"fcn_gaus",
"gaus");
1129 fcn_land =
new TF1(
"fcn_land",
"landau");
1130 fcn_pol1 =
new TF1(
"fcn_pol1",
"pol1");
1131 fcn_const =
new TF1(
"fcn_const",
"pol0");
1139 std::string name =
"time_calibration.root";
1143 if (stat(name.c_str(), &buffer) != 0)
1145 name =
"time_calibration_" + std::to_string(i) +
".root";
1150 m_outFile =
new TFile(name.c_str(),
"recreate");
1153 std::vector<struct Event> eventsChannel;
1154 eventsChannel.clear();
1158 B2INFO(
"Counting events per channel...");
1159 std::map<KLMChannelNumber, unsigned int> eventCounts;
1163 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsBKLM;
1164 std::vector< std::pair<KLMChannelNumber, unsigned int> > channelsEKLM;
1169 m_cFlag[channel] = ChannelCalibrationStatus::c_NotEnoughData;
1171 if (eventCounts.find(channel) == eventCounts.end())
1174 int nEvents = eventCounts[channel];
1176 B2WARNING(
"Not enough calibration data collected."
1177 <<
LogVar(
"channel", channel)
1178 <<
LogVar(
"number of digit", nEvents));
1182 m_cFlag[channel] = ChannelCalibrationStatus::c_FailedFit;
1186 channelsBKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1189 channelsEKLM.push_back(std::pair<KLMChannelNumber, unsigned int>(channel, nEvents));
1193 std::sort(channelsBKLM.begin(), channelsBKLM.end(), compareEventNumber);
1194 std::sort(channelsEKLM.begin(), channelsEKLM.end(), compareEventNumber);
1197 double delayBKLM, delayBKLMError;
1198 double delayEKLM, delayEKLMError;
1206 B2INFO(
"2D fits complete, data cleared.");
1243 std::vector<std::pair<std::string, std::function<bool(
const KLMChannelIndex&)>>> batches = {
1244 {
"RPC Backward", isRPCBackward},
1245 {
"RPC Forward", isRPCForward},
1246 {
"BKLM Scintillator Backward", isBKLMScintillatorBackward},
1247 {
"BKLM Scintillator Forward", isBKLMScintillatorForward},
1248 {
"EKLM Scintillator Backward", isEKLMScintillatorBackward},
1249 {
"EKLM Scintillator Forward", isEKLMScintillatorForward}
1256 B2INFO(
"First loop: Computing global statistics (batched processing)...");
1258 TString iFstring[2] = {
"Backward",
"Forward"};
1259 TString iPstring[2] = {
"ZReadout",
"PhiReadout"};
1261 int nBin_scint = 80;
1263 for (
const auto& batch : batches) {
1264 B2INFO(
"Processing batch for global stats: " << batch.first);
1268 channelId = klmChannel.getKLMChannelNumber();
1270 if (!batch.second(klmChannel))
1273 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1279 eventsChannel =
m_evts[channelId];
1280 int iSub = klmChannel.getSubdetector();
1284 for (
const Event& event : eventsChannel) {
1289 XYZVector diffD = XYZVector(event.diffDistX, event.diffDistY, event.diffDistZ);
1292 double timeHit =
event.time();
1294 timeHit = timeHit -
event.t0;
1296 if (timeHit <= -400e3)
1313 B2INFO(
"Batch processed and cleared: " << batch.first);
1322 B2INFO(
"Global Mean for Raw." <<
LogVar(
"RPC", tmpMean_rpc_global)
1323 <<
LogVar(
"Scint BKLM", tmpMean_scint_global)
1324 <<
LogVar(
"Scint EKLM", tmpMean_scint_global_end));
1330 B2INFO(
"Second pass: Computing per-channel time shifts (batched processing)...");
1332 for (
const auto& batch : batches) {
1333 B2INFO(
"Processing batch for time shifts: " << batch.first);
1337 channelId = klmChannel.getKLMChannelNumber();
1339 if (!batch.second(klmChannel))
1342 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1348 eventsChannel =
m_evts[channelId];
1349 int iSub = klmChannel.getSubdetector();
1350 int iF, iS, iL, iP, iC;
1353 iF = klmChannel.getSection();
1354 iS = klmChannel.getSector() - 1;
1355 iL = klmChannel.getLayer() - 1;
1356 iP = klmChannel.getPlane();
1357 iC = klmChannel.getStrip() - 1;
1359 iF = klmChannel.getSection() - 1;
1360 iS = klmChannel.getSector() - 1;
1361 iL = klmChannel.getLayer() - 1;
1362 iP = klmChannel.getPlane() - 1;
1363 iC = klmChannel.getStrip() - 1;
1368 TH1F* h_temp_tc =
nullptr;
1373 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1374 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1375 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1378 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc", iF, iS, iL, iP, iC);
1379 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1380 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1385 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_tc_end", iF, iS, iL, iP, iC);
1386 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1387 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1392 for (
const Event& event : eventsChannel) {
1397 double timeHit =
event.time();
1399 timeHit = timeHit -
event.t0;
1400 if (timeHit <= -400e3)
1402 h_temp_tc->Fill(timeHit);
1406 double tmpMean_channel =
fcn_gaus->GetParameter(1);
1411 m_timeShift[channelId] = tmpMean_channel - tmpMean_rpc_global;
1413 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global;
1416 m_timeShift[channelId] = tmpMean_channel - tmpMean_scint_global_end;
1423 B2INFO(
"Batch processed and cleared: " << batch.first);
1429 B2INFO(
"Effective Light m_timeShift obtained.");
1437 B2INFO(
"Effective light speed fitting.");
1441 double fittedDelayRPCPhi =
fcn_pol1->GetParameter(1);
1442 double e_slope_rpc_phi =
fcn_pol1->GetParError(1);
1445 double fittedDelayRPCZ =
fcn_pol1->GetParameter(1);
1446 double e_slope_rpc_z =
fcn_pol1->GetParError(1);
1449 double delayRPCPhi, delayRPCZ;
1453 B2INFO(
"Using fixed RPC propagation delay: " <<
m_fixedRPCDelay <<
" ns/cm (c_eff = 0.5c)"
1454 <<
LogVar(
"Fitted phi (not used)", fittedDelayRPCPhi)
1455 <<
LogVar(
"Fitted Z (not used)", fittedDelayRPCZ));
1457 delayRPCPhi = fittedDelayRPCPhi;
1458 delayRPCZ = fittedDelayRPCZ;
1462 double slope_scint_phi =
fcn_pol1->GetParameter(1);
1463 double e_slope_scint_phi =
fcn_pol1->GetParError(1);
1466 double slope_scint_z =
fcn_pol1->GetParameter(1);
1467 double e_slope_scint_z =
fcn_pol1->GetParError(1);
1470 double slope_scint_plane1_end =
fcn_pol1->GetParameter(1);
1471 double e_slope_scint_plane1_end =
fcn_pol1->GetParError(1);
1474 double slope_scint_plane2_end =
fcn_pol1->GetParameter(1);
1475 double e_slope_scint_plane2_end =
fcn_pol1->GetParError(1);
1477 TString logStr_phi, logStr_z;
1479 logStr_phi = Form(
"%.4f ns/cm (fixed)", delayRPCPhi);
1480 logStr_z = Form(
"%.4f ns/cm (fixed)", delayRPCZ);
1481 B2INFO(
"Delay in RPCs (using fixed value):"
1482 <<
LogVar(
"Used Value (phi readout)", logStr_phi.Data())
1483 <<
LogVar(
"Used Value (z readout)", logStr_z.Data()));
1485 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", delayRPCPhi, e_slope_rpc_phi);
1486 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayRPCZ, e_slope_rpc_z);
1487 B2INFO(
"Delay in RPCs:"
1488 <<
LogVar(
"Fitted Value (phi readout)", logStr_phi.Data())
1489 <<
LogVar(
"Fitted Value (z readout)", logStr_z.Data()));
1491 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_phi, e_slope_scint_phi);
1492 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_z, e_slope_scint_z);
1493 B2INFO(
"Delay in BKLM scintillators:"
1494 <<
LogVar(
"Fitted Value (phi readout) ", logStr_phi.Data())
1495 <<
LogVar(
"Fitted Value (z readout) ", logStr_z.Data()));
1496 logStr_phi = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane1_end,
1497 e_slope_scint_plane1_end);
1498 logStr_z = Form(
"%.4f +/- %.4f ns/cm", slope_scint_plane2_end,
1499 e_slope_scint_plane2_end);
1500 B2INFO(
"Delay in EKLM scintillators:"
1501 <<
LogVar(
"Fitted Value (plane1 readout) ", logStr_phi.Data())
1502 <<
LogVar(
"Fitted Value (plane2 readout) ", logStr_z.Data()));
1504 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayBKLM, delayBKLMError);
1505 B2INFO(
"Delay in BKLM scintillators:"
1506 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1507 logStr_z = Form(
"%.4f +/- %.4f ns/cm", delayEKLM, delayEKLMError);
1508 B2INFO(
"Delay in EKLM scintillators:"
1509 <<
LogVar(
"Fitted Value (2d fit) ", logStr_z.Data()));
1520 B2INFO(
"Third loop: Time distribution filling (batched processing)...");
1522 for (
const auto& batch : batches) {
1523 B2INFO(
"Processing batch: " << batch.first);
1527 channelId = klmChannel.getKLMChannelNumber();
1529 if (!batch.second(klmChannel))
1532 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData)
1538 eventsChannel =
m_evts[channelId];
1539 int iSub = klmChannel.getSubdetector();
1540 int iF, iS, iL, iP, iC;
1543 iF = klmChannel.getSection();
1544 iS = klmChannel.getSector() - 1;
1545 iL = klmChannel.getLayer() - 1;
1546 iP = klmChannel.getPlane();
1547 iC = klmChannel.getStrip() - 1;
1549 iF = klmChannel.getSection() - 1;
1550 iS = klmChannel.getSector() - 1;
1551 iL = klmChannel.getLayer() - 1;
1552 iP = klmChannel.getPlane() - 1;
1553 iC = klmChannel.getStrip() - 1;
1558 TH1F* h_temp =
nullptr;
1563 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1564 ht = Form(
"Time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1565 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1568 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1569 ht = Form(
"time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1570 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1575 hn = Form(
"h_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1576 ht = Form(
"Time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1577 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1583 for (
const Event& event : eventsChannel) {
1588 double timeHit =
event.time();
1590 timeHit = timeHit -
event.t0;
1591 if (timeHit <= -400e3)
1599 propgationT =
event.dist * delayRPCZ;
1601 propgationT =
event.dist * delayRPCPhi;
1602 double time = timeHit - propgationT;
1617 double propgationT =
event.dist * delayBKLM;
1618 double time = timeHit - propgationT;
1634 double propgationT =
event.dist * delayEKLM;
1635 double time = timeHit - propgationT;
1652 TFitResultPtr r = h_temp->Fit(
fcn_gaus,
"LESQ");
1654 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1667 B2INFO(
"Batch processed and cleared: " << batch.first);
1670 B2INFO(
"Original filling done.");
1673 int iChannel_rpc = 0;
1675 int iChannel_end = 0;
1677 channelId = klmChannel.getKLMChannelNumber();
1678 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1681 int iSub = klmChannel.getSubdetector();
1683 int iL = klmChannel.getLayer() - 1;
1713 B2INFO(
"Channel's time distribution fitting done.");
1718 B2INFO(
"Calibrated channel's time distribution filling begins.");
1722 channelId = klmChannel.getKLMChannelNumber();
1732 channelId = klmChannel.getKLMChannelNumber();
1737 B2DEBUG(20,
"Uncalibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeShift[channelId]));
1744 channelId = klmChannel.getKLMChannelNumber();
1746 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
1749 int iSub = klmChannel.getSubdetector();
1752 int iL = klmChannel.getLayer() - 1;
1776 B2INFO(
"Fourth loop: Calibrated time distribution filling (batched processing)...");
1778 for (
const auto& batch : batches) {
1779 B2INFO(
"Processing batch: " << batch.first);
1783 channelId = klmChannel.getKLMChannelNumber();
1785 if (!batch.second(klmChannel))
1791 eventsChannel =
m_evts[channelId];
1792 int iSub = klmChannel.getSubdetector();
1793 int iF, iS, iL, iP, iC;
1796 iF = klmChannel.getSection();
1797 iS = klmChannel.getSector() - 1;
1798 iL = klmChannel.getLayer() - 1;
1799 iP = klmChannel.getPlane();
1800 iC = klmChannel.getStrip() - 1;
1802 iF = klmChannel.getSection() - 1;
1803 iS = klmChannel.getSector() - 1;
1804 iL = klmChannel.getLayer() - 1;
1805 iP = klmChannel.getPlane() - 1;
1806 iC = klmChannel.getStrip() - 1;
1810 TH1F* hc_temp =
nullptr;
1815 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1816 ht = Form(
"Calibrated time distribution for RPC of Channel%d, %s, Layer%d, Sector%d, %s",
1817 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1821 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d", iF, iS, iL, iP, iC);
1822 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s",
1823 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1828 hn = Form(
"hc_timeF%d_S%d_L%d_P%d_C%d_end", iF, iS, iL, iP, iC);
1829 ht = Form(
"Calibrated time distribution for Scintillator of Channel%d, %s, Layer%d, Sector%d, %s (Endcap)",
1830 iC, iPstring[iP].Data(), iL, iS, iFstring[iF].Data());
1835 for (
const Event& event : eventsChannel) {
1840 double timeHit =
event.time();
1842 timeHit = timeHit -
event.t0;
1843 if (timeHit <= -400e3)
1851 propgationT =
event.dist * delayRPCZ;
1853 propgationT =
event.dist * delayRPCPhi;
1854 double time = timeHit - propgationT -
m_timeShift[channelId];
1857 hc_temp->Fill(time);
1869 double propgationT =
event.dist * delayBKLM;
1870 double time = timeHit - propgationT -
m_timeShift[channelId];
1873 hc_temp->Fill(time);
1886 double propgationT =
event.dist * delayEKLM;
1887 double time = timeHit - propgationT -
m_timeShift[channelId];
1890 hc_temp->Fill(time);
1904 if (
m_cFlag[channelId] == ChannelCalibrationStatus::c_NotEnoughData) {
1909 TFitResultPtr rc = hc_temp->Fit(
fcn_gaus,
"LESQ");
1911 m_cFlag[channelId] = ChannelCalibrationStatus::c_SuccessfulCalibration;
1924 B2INFO(
"Batch processed and cleared: " << batch.first);
1928 int icChannel_rpc = 0;
1930 int icChannel_end = 0;
1932 channelId = klmChannel.getKLMChannelNumber();
1933 if (
m_cFlag[channelId] != ChannelCalibrationStatus::c_SuccessfulCalibration)
1936 int iSub = klmChannel.getSubdetector();
1938 int iL = klmChannel.getLayer() - 1;
1968 B2INFO(
"Channel's time distribution fitting done.");
1973 B2INFO(
"Calibrated channel's time distribution filling begins.");
1977 channelId = klmChannel.getKLMChannelNumber();
1987 channelId = klmChannel.getKLMChannelNumber();
1992 B2DEBUG(20,
"Calibrated Estimation " <<
LogVar(
"Channel", channelId) <<
LogVar(
"Estimated value",
m_timeRes[channelId]));
1999 channelId = klmChannel.getKLMChannelNumber();
2001 B2ERROR(
"!!! Not All Channels Calibration Constant Set. Error Happened on " <<
LogVar(
"Channel", channelId));
2004 int iSub = klmChannel.getSubdetector();
2007 int iL = klmChannel.getLayer() - 1;
2024 B2INFO(
"Fifth pass: Computing di-muon ΔT0 for EventT0 hit resolution calibration...");
2027 struct TrackT0Info {
2029 int nHits_BKLM_Scint;
2030 int nHits_BKLM_RPC_Phi;
2031 int nHits_BKLM_RPC_Z;
2032 int nHits_EKLM_Scint;
2033 double sumT0_BKLM_Scint;
2034 double sumT0_BKLM_RPC_Phi;
2035 double sumT0_BKLM_RPC_Z;
2036 double sumT0_EKLM_Scint;
2038 TrackT0Info() : charge(0),
2039 nHits_BKLM_Scint(0),
2040 nHits_BKLM_RPC_Phi(0),
2041 nHits_BKLM_RPC_Z(0),
2042 nHits_EKLM_Scint(0),
2043 sumT0_BKLM_Scint(0.0),
2044 sumT0_BKLM_RPC_Phi(0.0),
2045 sumT0_BKLM_RPC_Z(0.0),
2046 sumT0_EKLM_Scint(0.0) {}
2050 std::map<std::pair<int, int>, std::map<int, TrackT0Info>> eventTrackMap;
2053 for (
const auto& batch : batches) {
2054 B2INFO(
"Processing batch for di-muon analysis: " << batch.first);
2057 for (
const auto& channelPair :
m_evts) {
2059 const std::vector<Event>& chEvents = channelPair.second;
2062 int subdetector, section, sector, layer, plane, strip;
2064 chId, &subdetector, §ion, §or, &layer, &plane, &strip);
2067 int iSub = subdetector;
2070 for (
const Event& event : chEvents) {
2076 std::pair<int, int> eventKey(event.Run, event.Events);
2077 int trackIdx =
event.nTrack;
2078 int charge =
event.Track_Charge;
2081 double timeHit =
event.time() -
m_timeShift[chId];
2083 if (timeHit <= -400e3)
2092 propT =
event.dist * delayRPCZ;
2094 propT =
event.dist * delayRPCPhi;
2097 propT =
event.dist * delayBKLM;
2101 propT =
event.dist * delayEKLM;
2104 double t0_estimate = timeHit - propT;
2107 TrackT0Info& trackInfo = eventTrackMap[eventKey][trackIdx];
2108 trackInfo.charge = charge;
2114 trackInfo.nHits_BKLM_RPC_Z++;
2115 trackInfo.sumT0_BKLM_RPC_Z += t0_estimate;
2117 trackInfo.nHits_BKLM_RPC_Phi++;
2118 trackInfo.sumT0_BKLM_RPC_Phi += t0_estimate;
2122 trackInfo.nHits_BKLM_Scint++;
2123 trackInfo.sumT0_BKLM_Scint += t0_estimate;
2126 trackInfo.nHits_EKLM_Scint++;
2127 trackInfo.sumT0_EKLM_Scint += t0_estimate;
2135 B2INFO(
"Event-track map built. Processing events for EventT0 histograms...");
2139 double sum_delta2_over_v_BKLM_Scint = 0.0;
2140 double sum_delta2_over_v_BKLM_RPC_Phi = 0.0;
2141 double sum_delta2_over_v_BKLM_RPC_Z = 0.0;
2142 double sum_delta2_over_v_EKLM_Scint = 0.0;
2144 int nDimuon_BKLM_Scint = 0;
2145 int nDimuon_BKLM_RPC_Phi = 0;
2146 int nDimuon_BKLM_RPC_Z = 0;
2147 int nDimuon_EKLM_Scint = 0;
2149 for (
const auto& eventPair : eventTrackMap) {
2150 const auto& trackMap = eventPair.second;
2153 if (trackMap.size() != 2)
2156 auto it1 = trackMap.begin();
2157 auto it2 = trackMap.begin();
2159 const TrackT0Info& track1 = it1->second;
2160 const TrackT0Info& track2 = it2->second;
2163 if (track1.charge * track2.charge >= 0)
2167 const TrackT0Info& muPlus = (track1.charge > 0) ? track1 : track2;
2168 const TrackT0Info& muMinus = (track1.charge > 0) ? track2 : track1;
2171 if (muPlus.nHits_BKLM_Scint > 0 && muMinus.nHits_BKLM_Scint > 0) {
2172 double t0_plus = muPlus.sumT0_BKLM_Scint / muPlus.nHits_BKLM_Scint;
2173 double t0_minus = muMinus.sumT0_BKLM_Scint / muMinus.nHits_BKLM_Scint;
2174 double deltaT0 = t0_plus - t0_minus;
2177 double v = 1.0 / muPlus.nHits_BKLM_Scint + 1.0 / muMinus.nHits_BKLM_Scint;
2178 int nTotal = muPlus.nHits_BKLM_Scint + muMinus.nHits_BKLM_Scint;
2184 sum_delta2_over_v_BKLM_Scint += (deltaT0 * deltaT0) / v;
2185 nDimuon_BKLM_Scint++;
2202 }
else if (nTotal < 15) {
2210 if (muPlus.nHits_BKLM_RPC_Phi > 0 && muMinus.nHits_BKLM_RPC_Phi > 0) {
2211 double t0_plus = muPlus.sumT0_BKLM_RPC_Phi / muPlus.nHits_BKLM_RPC_Phi;
2212 double t0_minus = muMinus.sumT0_BKLM_RPC_Phi / muMinus.nHits_BKLM_RPC_Phi;
2213 double deltaT0 = t0_plus - t0_minus;
2215 double v = 1.0 / muPlus.nHits_BKLM_RPC_Phi + 1.0 / muMinus.nHits_BKLM_RPC_Phi;
2216 int nTotal = muPlus.nHits_BKLM_RPC_Phi + muMinus.nHits_BKLM_RPC_Phi;
2221 sum_delta2_over_v_BKLM_RPC_Phi += (deltaT0 * deltaT0) / v;
2222 nDimuon_BKLM_RPC_Phi++;
2237 }
else if (nTotal < 30) {
2245 if (muPlus.nHits_BKLM_RPC_Z > 0 && muMinus.nHits_BKLM_RPC_Z > 0) {
2246 double t0_plus = muPlus.sumT0_BKLM_RPC_Z / muPlus.nHits_BKLM_RPC_Z;
2247 double t0_minus = muMinus.sumT0_BKLM_RPC_Z / muMinus.nHits_BKLM_RPC_Z;
2248 double deltaT0 = t0_plus - t0_minus;
2250 double v = 1.0 / muPlus.nHits_BKLM_RPC_Z + 1.0 / muMinus.nHits_BKLM_RPC_Z;
2251 int nTotal = muPlus.nHits_BKLM_RPC_Z + muMinus.nHits_BKLM_RPC_Z;
2256 sum_delta2_over_v_BKLM_RPC_Z += (deltaT0 * deltaT0) / v;
2257 nDimuon_BKLM_RPC_Z++;
2272 }
else if (nTotal < 30) {
2280 if (muPlus.nHits_EKLM_Scint > 0 && muMinus.nHits_EKLM_Scint > 0) {
2281 double t0_plus = muPlus.sumT0_EKLM_Scint / muPlus.nHits_EKLM_Scint;
2282 double t0_minus = muMinus.sumT0_EKLM_Scint / muMinus.nHits_EKLM_Scint;
2283 double deltaT0 = t0_plus - t0_minus;
2285 double v = 1.0 / muPlus.nHits_EKLM_Scint + 1.0 / muMinus.nHits_EKLM_Scint;
2286 int nTotal = muPlus.nHits_EKLM_Scint + muMinus.nHits_EKLM_Scint;
2291 sum_delta2_over_v_EKLM_Scint += (deltaT0 * deltaT0) / v;
2292 nDimuon_EKLM_Scint++;
2308 }
else if (nTotal < 15) {
2316 B2INFO(
"Di-muon ΔT0 data collected."
2317 <<
LogVar(
"BKLM Scint di-muon events", nDimuon_BKLM_Scint)
2318 <<
LogVar(
"BKLM RPC Phi di-muon events", nDimuon_BKLM_RPC_Phi)
2319 <<
LogVar(
"BKLM RPC Z di-muon events", nDimuon_BKLM_RPC_Z)
2320 <<
LogVar(
"EKLM Scint di-muon events", nDimuon_EKLM_Scint));
2325 float sigma_BKLM_Scint = 10.0f;
2326 float sigma_BKLM_Scint_err = 1.0f;
2327 if (nDimuon_BKLM_Scint > 0) {
2328 double sigma2 = sum_delta2_over_v_BKLM_Scint /
static_cast<double>(nDimuon_BKLM_Scint);
2329 sigma_BKLM_Scint =
static_cast<float>(std::sqrt(sigma2));
2331 sigma_BKLM_Scint_err = sigma_BKLM_Scint / std::sqrt(2.0 * nDimuon_BKLM_Scint);
2334 float sigma_RPC_Phi = 10.0f;
2335 float sigma_RPC_Phi_err = 1.0f;
2336 if (nDimuon_BKLM_RPC_Phi > 0) {
2337 double sigma2 = sum_delta2_over_v_BKLM_RPC_Phi /
static_cast<double>(nDimuon_BKLM_RPC_Phi);
2338 sigma_RPC_Phi =
static_cast<float>(std::sqrt(sigma2));
2339 sigma_RPC_Phi_err = sigma_RPC_Phi / std::sqrt(2.0 * nDimuon_BKLM_RPC_Phi);
2342 float sigma_RPC_Z = 10.0f;
2343 float sigma_RPC_Z_err = 1.0f;
2344 if (nDimuon_BKLM_RPC_Z > 0) {
2345 double sigma2 = sum_delta2_over_v_BKLM_RPC_Z /
static_cast<double>(nDimuon_BKLM_RPC_Z);
2346 sigma_RPC_Z =
static_cast<float>(std::sqrt(sigma2));
2347 sigma_RPC_Z_err = sigma_RPC_Z / std::sqrt(2.0 * nDimuon_BKLM_RPC_Z);
2351 float sigma_RPC = 10.0f;
2352 float sigma_RPC_err = 1.0f;
2353 int nDimuon_RPC_total = nDimuon_BKLM_RPC_Phi + nDimuon_BKLM_RPC_Z;
2354 if (nDimuon_RPC_total > 0) {
2356 double w_phi =
static_cast<double>(nDimuon_BKLM_RPC_Phi) / nDimuon_RPC_total;
2357 double w_z =
static_cast<double>(nDimuon_BKLM_RPC_Z) / nDimuon_RPC_total;
2358 sigma_RPC = w_phi * sigma_RPC_Phi + w_z * sigma_RPC_Z;
2360 sigma_RPC_err = std::sqrt(w_phi * w_phi * sigma_RPC_Phi_err * sigma_RPC_Phi_err +
2361 w_z * w_z * sigma_RPC_Z_err * sigma_RPC_Z_err);
2364 float sigma_EKLM_Scint = 10.0f;
2365 float sigma_EKLM_Scint_err = 1.0f;
2366 if (nDimuon_EKLM_Scint > 0) {
2367 double sigma2 = sum_delta2_over_v_EKLM_Scint /
static_cast<double>(nDimuon_EKLM_Scint);
2368 sigma_EKLM_Scint =
static_cast<float>(std::sqrt(sigma2));
2369 sigma_EKLM_Scint_err = sigma_EKLM_Scint / std::sqrt(2.0 * nDimuon_EKLM_Scint);
2372 B2INFO(
"Extracted per-hit resolutions using event-by-event weighting:"
2373 <<
LogVar(
"σ_BKLM_Scint [ns]", sigma_BKLM_Scint) <<
LogVar(
"±", sigma_BKLM_Scint_err)
2374 <<
LogVar(
"σ_RPC_Phi [ns]", sigma_RPC_Phi) <<
LogVar(
"±", sigma_RPC_Phi_err)
2375 <<
LogVar(
"σ_RPC_Z [ns]", sigma_RPC_Z) <<
LogVar(
"±", sigma_RPC_Z_err)
2376 <<
LogVar(
"σ_RPC_combined [ns]", sigma_RPC) <<
LogVar(
"±", sigma_RPC_err)
2377 <<
LogVar(
"σ_EKLM_Scint [ns]", sigma_EKLM_Scint) <<
LogVar(
"±", sigma_EKLM_Scint_err));
2386 B2INFO(
"EventT0 hit resolution calibration complete and stored in payload.");
2389 eventTrackMap.clear();
2410 B2INFO(
"Save Histograms into Files.");
2413 TDirectory* dir_monitor =
m_outFile->mkdir(
"monitor_Hists",
"",
true);
2417 h_diff->SetDirectory(dir_monitor);
2420 TDirectory* dir_eventT0 =
m_outFile->mkdir(
"EventT0",
"",
true);
2469 TDirectory* dir_effC =
m_outFile->mkdir(
"effC_Hists",
"",
true);
2485 TDirectory* dir_time =
m_outFile->mkdir(
"time",
"",
true);
2510 B2INFO(
"Top file setup Done.");
2514 B2INFO(
"Skipping debug histogram directory creation (m_saveAllPlots = false)");
2518 B2INFO(
"File Write and Close. Done.");
2522 TDirectory* dir_time_F[2];
2523 TDirectory* dir_time_FS[2][8];
2524 TDirectory* dir_time_FSL[2][8][15];
2525 TDirectory* dir_time_FSLP[2][8][15][2];
2526 TDirectory* dir_time_F_end[2];
2527 TDirectory* dir_time_FS_end[2][4];
2528 TDirectory* dir_time_FSL_end[2][4][14];
2529 TDirectory* dir_time_FSLP_end[2][4][14][2];
2531 B2INFO(
"Sub files declare Done.");
2532 for (
int iF = 0; iF < 2; ++iF) {
2551 sprintf(dirname,
"isForward_%d", iF);
2552 dir_time_F[iF] = dir_time->mkdir(dirname,
"",
true);
2553 dir_time_F[iF]->cd();
2555 for (
int iS = 0; iS < 8; ++iS) {
2562 h2_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2563 h2c_timeFS[iF][iS]->SetDirectory(dir_time_F[iF]);
2565 sprintf(dirname,
"Sector_%d", iS + 1);
2566 dir_time_FS[iF][iS] = dir_time_F[iF]->mkdir(dirname,
"",
true);
2567 dir_time_FS[iF][iS]->cd();
2569 for (
int iL = 0; iL < 15; ++iL) {
2570 h_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2571 hc_timeFSL[iF][iS][iL]->SetDirectory(dir_time_FS[iF][iS]);
2573 sprintf(dirname,
"Layer_%d", iL + 1);
2574 dir_time_FSL[iF][iS][iL] = dir_time_FS[iF][iS]->mkdir(dirname,
"",
true);
2575 dir_time_FSL[iF][iS][iL]->cd();
2576 for (
int iP = 0; iP < 2; ++iP) {
2577 h_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2578 hc_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2579 h2_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2580 h2c_timeFSLP[iF][iS][iL][iP]->SetDirectory(dir_time_FSL[iF][iS][iL]);
2582 sprintf(dirname,
"Plane_%d", iP);
2583 dir_time_FSLP[iF][iS][iL][iP] = dir_time_FSL[iF][iS][iL]->mkdir(dirname,
"",
true);
2584 dir_time_FSLP[iF][iS][iL][iP]->cd();
2590 sprintf(dirname,
"isForward_%d_end", iF + 1);
2591 dir_time_F_end[iF] = dir_time->mkdir(dirname,
"",
true);
2592 dir_time_F_end[iF]->cd();
2593 int maxLayer = 12 + 2 * iF;
2594 for (
int iS = 0; iS < 4; ++iS) {
2601 sprintf(dirname,
"Sector_%d_end", iS + 1);
2602 dir_time_FS_end[iF][iS] = dir_time_F_end[iF]->mkdir(dirname,
"",
true);
2603 dir_time_FS_end[iF][iS]->cd();
2604 for (
int iL = 0; iL < maxLayer; ++iL) {
2605 h_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2606 hc_timeFSL_end[iF][iS][iL]->SetDirectory(dir_time_FS_end[iF][iS]);
2608 sprintf(dirname,
"Layer_%d_end", iL + 1);
2609 dir_time_FSL_end[iF][iS][iL] = dir_time_FS_end[iF][iS]->mkdir(dirname,
"",
true);
2610 dir_time_FSL_end[iF][iS][iL]->cd();
2611 for (
int iP = 0; iP < 2; ++iP) {
2612 h_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2613 hc_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2614 h2_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2615 h2c_timeFSLP_end[iF][iS][iL][iP]->SetDirectory(dir_time_FSL_end[iF][iS][iL]);
2617 sprintf(dirname,
"plane_%d_end", iP);
2618 dir_time_FSLP_end[iF][iS][iL][iP] = dir_time_FSL_end[iF][iS][iL]->mkdir(dirname,
"",
true);
2619 dir_time_FSLP_end[iF][iS][iL][iP]->cd();
2628 B2INFO(
"File Write and Close. Done.");