R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandMilleCalDataProcessor.h
Go to the documentation of this file.
1#pragma once
2
4#include "R3BValueError.h"
5#include <Fit/Fitter.h>
7#include <R3BNeulandCommon.h>
8#include <Rtypes.h>
9#include <TF1.h>
10#include <cstdlib>
11#include <fmt/base.h>
12#include <fmt/core.h>
13#include <unordered_map>
14#include <vector>
15
16namespace R3B::Neuland
17{
18 class Cal2HitPar;
19
20}
21
23{
24
33 {
34 public:
35 MilleCalData() = default;
36 explicit MilleCalData(const BarCalData& bar_cal_data)
37 : module_num{ bar_cal_data.module_num }
38 , left{ bar_cal_data.left.front() }
39 , right{ bar_cal_data.right.front() }
40 {
41 }
42 bool is_outlier = false;
43 int module_num = 0;
44 float fit_diff = 0.F;
45 float residual = -1.;
46 float residual_bar_pos = -1.;
47 float tsync_meas = 0.F;
52
54 };
55
57 {
58 double offset = 0.;
59 double slope = 0.;
60 double p_value = 0.;
61
62 static constexpr auto diff_threshold = 0.1;
63
64 auto operator!=(const TrackFitPar& other) const
65 {
66 return (std::abs(other.offset - offset) / offset > diff_threshold) or
67 (std::abs(other.slope - slope) / slope > diff_threshold);
68 }
69 void clear()
70 {
71 offset = 0.;
72 slope = 0.;
73 p_value = 0.;
74 }
76 };
77
79 {
82 void clear()
83 {
84 x_z.clear();
85 y_z.clear();
86 }
88 };
89
101
103 {
104 std::vector<double> z_vals;
105 std::vector<double> z_errs;
106 std::vector<double> vals;
107 std::vector<double> errs;
108
109 void clear()
110 {
111 z_vals.clear();
112 z_errs.clear();
113 vals.clear();
114 errs.clear();
115 }
116 [[nodiscard]] auto size() const { return z_vals.size(); }
117 };
118
120 {
121 public:
125
141
142 explicit MilleDataProcessor(int num_of_modules);
143
159 auto process(const std::vector<BarCalData>& signals, const Cal2HitPar& hit_par) -> bool;
160
161 auto check_is_outlier(int module_num) const -> bool;
162
163 void reset();
164
165 void set_p_value_cut(double val) { p_value_cut_ = val; }
166
167 [[nodiscard]] auto get_data() const -> const auto& { return data_buffers_; }
168 [[nodiscard]] auto get_track_info() const -> const auto& { return track_info_; }
169 [[nodiscard]] auto get_track_fit_data() const -> const auto& { return track_fit_data_; }
170 // [[nodiscard]] auto calculate_residual(double val, int module_num) const -> float;
171
172 static auto linear_fit(const NeulandTrackDataSet& data,
173 FitPar& fit_par,
174 HuberRegressor& huber_regressor,
175 double p_value_cut) -> bool;
176
177 private:
179
183 using DataBufferType = std::unordered_map<int, std::vector<MilleCalData>>;
184 std::unordered_map<int, std::vector<MilleCalData>> data_buffers_;
188
189 void init_data_registers(int num_of_modules);
190
196 void fill_time_dataset();
197 void reset_fit_pars();
198 auto fit_planes(const Cal2HitPar& hit_par) -> bool;
199 void check_fit_result();
200 void set_data_buffers(DataBufferType& data_buffers,
201 const TrackInfo& track_info,
202 const Cal2HitPar& hit_par) const;
203 };
204} // namespace R3B::Neuland::Calibration
205
206#ifndef __CLING__
207template <>
209{
210 public:
211 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
212 template <typename FmtContent>
213 constexpr auto format(const R3B::Neuland::Calibration::MilleCalData& signal, FmtContent& ctn) const
214 {
215 return fmt::format_to(
216 ctn.out(), "ModuleNum: {}, left bar: {}, right bar: {}", signal.module_num, signal.left, signal.right);
217 }
218};
219
220template <>
222{
223 public:
224 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
225 template <typename FmtContent>
226 constexpr auto format(const R3B::Neuland::Calibration::MilleDataProcessor::FitPar& fit_par, FmtContent& ctn) const
227 {
228 return fmt::format_to(
229 ctn.out(), "slope: {}, offset: {}, p_value: {}", fit_par.slope, fit_par.offset, fit_par.p_value);
230 }
231};
232
233template <>
235{
236 public:
237 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
238 template <typename FmtContent>
240 FmtContent& ctn) const
241 {
242 return fmt::format_to(ctn.out(),
243 "\n"
244 "\tx_z plane: {{{}}}\n"
245 "\ty_z plane: {{{}}}",
246 fit_result.x_z,
247 fit_result.y_z);
248 }
249};
250
251template <>
253{
254 public:
255 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
256 template <typename FmtContent>
257 constexpr auto format(const R3B::Neuland::Calibration::NeulandTrackDataSet& fit_data, FmtContent& ctn) const
258 {
259 return fmt::format_to(ctn.out(),
260 "\tx = np.array({})\n"
261 "\tx_err = np.array({})\n"
262 "\ty = np.array({})\n"
263 "\ty_err = np.array({})",
264 fit_data.z_vals,
265 fit_data.z_errs,
266 fit_data.vals,
267 fit_data.errs);
268 }
269};
270#endif
void remove_isolated_bar_signal()
Remove signals that are isolated in the plane.
auto process(const std::vector< BarCalData > &signals, const Cal2HitPar &hit_par) -> bool
Process the cal level data.
static auto linear_fit(const NeulandTrackDataSet &data, FitPar &fit_par, HuberRegressor &huber_regressor, double p_value_cut) -> bool
void set_data_buffers(DataBufferType &data_buffers, const TrackInfo &track_info, const Cal2HitPar &hit_par) const
std::unordered_map< int, std::vector< MilleCalData > > data_buffers_
std::unordered_map< int, std::vector< MilleCalData > > DataBufferType
Data buffer for the event data.
constexpr auto format(const R3B::Neuland::Calibration::MilleCalData &signal, FmtContent &ctn) const
constexpr auto format(const R3B::Neuland::Calibration::MilleDataProcessor::FitPar &fit_par, FmtContent &ctn) const
constexpr auto format(const R3B::Neuland::Calibration::MilleDataProcessor::FitResult &fit_result, FmtContent &ctn) const
constexpr auto format(const R3B::Neuland::Calibration::NeulandTrackDataSet &fit_data, FmtContent &ctn) const
constexpr auto DEFAULT_CALIBRATION_P_VALUE_CUT
Simulation of NeuLAND Bar/Paddle.
ValueError< double > ValueErrorD
Data structure to store the cal level data for the data preprocessing.
ValueErrorD position
position of the hit along the bar direction
float residual_bar_pos
residual value against the fitted line of bar positions
float fit_diff
Difference value from the fitted line and position (time derived).
float residual
residual value against the fitted line
auto operator!=(const TrackFitPar &other) const
static constexpr auto diff_threshold
10% difference