R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandMuonRecons.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2023 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
15
16#include <R3BException.h>
17#include <R3BLogger.h>
18#include <R3BNeulandCalData2.h>
20#include <R3BNeulandCommon.h>
22#include <R3BNeulandHitPar.h>
24#include <R3BShared.h>
25#include <algorithm>
26#include <cmath>
27#include <fmt/format.h>
28#include <vector>
29
31{
32 namespace
33 {
34 void fill_module_parameters(const std::vector<R3BNeulandHitModulePar>& old_module_pars,
35 R3B::Neuland::Cal2HitPar& new_module_pars)
36 {
37#ifdef HAS_CPP_STANDARD_23
38 auto t_sync_ref_par_iter = std::ranges::find(
40#else
41 auto t_sync_ref_par_iter = std::find_if(old_module_pars.begin(),
42 old_module_pars.end(),
43 [](const R3BNeulandHitModulePar& par)
44 { return par.GetModuleId() == DEFAULT_TSYNC_REFERENCE_BAR_NUM; });
45#endif
46 if (t_sync_ref_par_iter == old_module_pars.end())
47 {
48 throw R3B::logic_error(
49 fmt::format("Reference module for tsync parameter with the module number {} doesn't exist!",
51 }
52 const auto t_sync_ref_value = t_sync_ref_par_iter->GetTSync();
53
54 for (const auto& par : old_module_pars)
55 {
56 auto new_par = R3B::Neuland::HitModulePar{};
57 // GetModuleId return 1 based module Num
58 new_par.module_num = par.GetModuleId();
59 new_par.t_diff.value = par.GetTDiff();
60 new_par.t_sync.value = par.GetTSync() - t_sync_ref_value;
61 new_par.effective_speed.value = -2 * par.GetEffectiveSpeed();
62 new_par.light_attenuation_length.value = par.GetLightAttenuationLength();
63 new_par.light_attenuation_factor.value =
64 std::exp(R3B::Neuland::TotalBarLength / new_par.light_attenuation_length.value / 2);
65
66 // Getters accept 1 as the left side and 2 as the right side
67
68 const auto left_index = 1 + toIndex(R3B::Side::left);
69 const auto right_index = 1 + toIndex(R3B::Side::right);
70
71 new_par.pedestal.left().value = par.GetPedestal(left_index);
72 new_par.pedestal.right().value = par.GetPedestal(right_index);
73
74 new_par.energy_gain.left().value = par.GetEnergyGain(left_index);
75 new_par.energy_gain.right().value = par.GetEnergyGain(right_index);
76
77 new_par.pmt_saturation.left().value = par.GetPMTSaturation(left_index);
78 new_par.pmt_saturation.right().value = par.GetPMTSaturation(right_index);
79
80 new_par.pmt_threshold.left().value = par.GetPMTThreshold(left_index);
81 new_par.pmt_threshold.right().value = par.GetPMTThreshold(right_index);
82 new_module_pars.AddModulePar(new_par);
83 }
84 }
85 } // namespace
86
88 {
89 const auto module_size = GetModuleSize();
90 if (module_size == 0)
91 {
92 throw R3B::runtime_error("module size is 0 during the initialization!");
93 }
94
95 // To set the number of planes in legacy hitCalibrationEngine
96 auto hit_par_temp = R3BNeulandHitPar{};
97 hit_par_temp.SetNumberOfPlanes(static_cast<int>(module_size) / BarsPerPlane);
98 hit_cal_engine_.Init(&hit_par_temp);
99 }
100
101 void MuonReconstruction::AddSignals(const std::vector<BarCalData>& signals)
102 {
103 for (const auto& signal : signals)
104 {
105 add_bar_signal(signal, Side::left);
107 }
108 }
109
111 {
112 // change to 0 based indexing
113 const auto module_id = static_cast<int>(barSignal.module_num - 1);
114
115 const auto& calData = (side == Side::left) ? barSignal.left : barSignal.right;
116
117 for (const auto& calSignal : calData)
118 {
119 // 1 is the right side and 0 is the left side
120 hit_cal_engine_.Set(module_id,
121 static_cast<int>(toIndex(side)),
122 calSignal.leading_time.value - calSignal.trigger_time.value,
123 static_cast<int>(calSignal.time_over_threshold.value));
124 if (hit_cal_engine_.IsValid(module_id))
125 {
126 cosmic_tracker_.AddPoint(module_id, hit_cal_engine_.GetPosition(module_id));
127 }
128 }
129 }
130
131 void MuonReconstruction::EndOfEvent(unsigned int event_num)
132 {
133 const auto added_points_num = cosmic_tracker_.GetBarIDs().size();
134 const auto& track = cosmic_tracker_.GetTrack();
135 if (track.Interactions.empty() or added_points_num < 6)
136 {
137 R3BLOG(debug, "Failed to get the cosmic track!");
138 }
139 else
140 {
141 hit_cal_engine_.Add(track, event_num);
142 }
143 }
144
146 {
147 hit_par.Reset();
148 // auto* new_dir = ParDirCreator{}.mkdir(DEFAULT_HIST_MONITOR_DIR);
149 auto* new_dir = ParDirCreator{}.mkdir("Histograms");
150 fill_module_parameters(hit_cal_engine_.Calibrate(new_dir), hit_par);
151 }
152
153} // namespace R3B::Neuland::Calibration
#define R3BLOG(severity, x)
Definition R3BLogger.h:33
void AddModulePar(const HitModulePar &module_par)
void EndOfEvent(unsigned int event_num=0) override
void add_bar_signal(const BarCalData &barSignal, Side side)
void AddSignals(const std::vector< BarCalData > &signals) override
auto mkdir(std::string_view dir_name) -> auto *
Int_t GetModuleId() const
Accessor functions.
void SetNumberOfPlanes(const Int_t nPlanes)
constexpr auto DEFAULT_TSYNC_REFERENCE_BAR_NUM
constexpr auto BarsPerPlane
constexpr auto TotalBarLength
constexpr auto toIndex(Side side) -> size_t
Definition R3BShared.h:118
std::vector< CalDataSignal > left
std::vector< CalDataSignal > right