R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandLSQREngineAdaptor.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 <FairRuntimeDb.h>
17#include <R3BException.h>
18#include <R3BLogger.h>
19#include <R3BNeulandCalData2.h>
21#include <R3BNeulandCommon.h>
23#include <R3BNeulandHitPar.h>
25#include <R3BShared.h>
26#include <cmath>
27#include <vector>
28
29namespace
30{
31 void fill_module_parameters(const std::vector<R3BNeulandHitModulePar>& old_module_pars,
32 R3B::Neuland::Cal2HitPar& new_module_pars)
33 {
34 for (const auto& par : old_module_pars)
35 {
36 auto new_par = R3B::Neuland::HitModulePar{};
37 // GetModuleId return 1 based module Num
38 new_par.module_num = par.GetModuleId();
39 new_par.t_diff.value = par.GetTDiff();
40 new_par.t_sync.value = par.GetTSync();
41 new_par.effective_speed.value = par.GetEffectiveSpeed();
42 new_par.light_attenuation_length.value = par.GetLightAttenuationLength();
43 new_par.light_attenuation_factor.value =
44 std::exp(R3B::Neuland::TotalBarLength / new_par.light_attenuation_length.value / 2);
45
46 // Getters accept 1 as the left side and 2 as the right side
47
48 const auto left_index = 1 + toIndex(R3B::Side::left);
49 const auto right_index = 1 + toIndex(R3B::Side::right);
50
51 new_par.pedestal.left().value = par.GetPedestal(left_index);
52 new_par.pedestal.right().value = par.GetPedestal(right_index);
53
54 new_par.energy_gain.left().value = par.GetEnergyGain(left_index);
55 new_par.energy_gain.right().value = par.GetEnergyGain(right_index);
56
57 new_par.pmt_saturation.left().value = par.GetPMTSaturation(left_index);
58 new_par.pmt_saturation.right().value = par.GetPMTSaturation(right_index);
59
60 new_par.pmt_threshold.left().value = par.GetPMTThreshold(left_index);
61 new_par.pmt_threshold.right().value = par.GetPMTThreshold(right_index);
62 new_module_pars.AddModulePar(new_par);
63 }
64 }
65} // namespace
66
68{
70 {
71 const auto module_size = GetModuleSize();
72 if (module_size == 0)
73 {
74 throw R3B::runtime_error("module size is 0 during the initialization!");
75 }
76
77 // To set the number of planes in legacy hitCalibrationEngine
78 auto hit_par_temp = R3BNeulandHitPar{};
79 hit_par_temp.SetNumberOfPlanes(static_cast<int>(module_size) / BarsPerPlane);
80 hit_cal_engine_.Init(&hit_par_temp);
81 }
82
83 void LSQREngineAdaptor::AddSignals(const std::vector<BarCalData>& signals)
84 {
85 for (const auto& signal : signals)
86 {
87 add_bar_signal(signal, Side::left);
88 add_bar_signal(signal, Side::right);
89 }
90 }
91
92 void LSQREngineAdaptor::add_bar_signal(const BarCalData& barSignal, Side side)
93 {
94 // change to 0 based indexing
95 const auto module_id = static_cast<int>(barSignal.module_num - 1);
96
97 const auto& calData = (side == Side::left) ? barSignal.left : barSignal.right;
98
99 for (const auto& calSignal : calData)
100 {
101 // 1 is the right side and 0 is the left side
102 hit_cal_engine_.Set(module_id,
103 static_cast<int>(toIndex(side)),
104 calSignal.leading_time.value - calSignal.trigger_time.value,
105 static_cast<int>(calSignal.time_over_threshold.value));
106 if (hit_cal_engine_.IsValid(module_id))
107 {
108 cosmic_tracker_.AddPoint(module_id, hit_cal_engine_.GetPosition(module_id));
109 }
110 }
111 }
112
113 void LSQREngineAdaptor::EndOfEvent(unsigned int event_num)
114 {
115 const auto added_points_num = cosmic_tracker_.GetBarIDs().size();
116 const auto& track = cosmic_tracker_.GetTrack();
117 if (track.Interactions.empty() or added_points_num < 6)
118 {
119 R3BLOG(debug, "Failed to get the cosmic track!");
120 }
121 else
122 {
123 hit_cal_engine_.Add(track, event_num);
124 }
125 }
126
128 {
129 hit_par.Reset();
130 // auto* new_dir = ParDirCreator{}.mkdir(DEFAULT_HIST_MONITOR_DIR);
131 auto* new_dir = ParDirCreator{}.mkdir("Histograms");
132 fill_module_parameters(hit_cal_engine_.Calibrate(new_dir), hit_par);
133 }
134
135} // namespace R3B::Neuland::Calibration
#define R3BLOG(severity, x)
Definition R3BLogger.h:35
void AddModulePar(const HitModulePar &module_par)
void AddPoint(const Int_t barID, const Double_t pos=NaN)
void Set(const Int_t id, const Int_t side, const Double_t time, const Int_t qdc)
void AddSignals(const std::vector< BarCalData > &signals) override
void EndOfEvent(unsigned int event_num=0) override
auto mkdir(std::string_view dir_name) -> auto *
void SetNumberOfPlanes(const Int_t nPlanes)
constexpr auto BarsPerPlane
constexpr auto TotalBarLength
constexpr auto toIndex(Side side) -> size_t
Definition R3BShared.h:111
std::vector< CalDataSignal > left