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