R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandMillepede.h
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#pragma once
14
15#include "MilleEntry.h"
16#include "R3BDataMonitor.h"
17#include "R3BIOConnector.h"
18#include "R3BLogger.h"
19#include "R3BNeulandCalData2.h"
23#include <Mille.h>
24#include <ParResultReader.h>
25#include <PedeLauncher.h>
26#include <R3BNeulandCommon.h>
27#include <TH1.h>
28#include <cstdint>
29#include <fmt/core.h>
30#include <fmt/format.h>
31#include <memory>
32#include <optional>
33#include <string>
34#include <string_view>
35#include <unordered_map>
36#include <utility>
37#include <vector>
38// #include <RankChecker.h>
39
40class TGraphErrors;
41
42class TH2D;
43
45{
46 enum class GlobalLabel : int8_t
47 {
48 tsync, // tsync
49 offset_effective_c, // offset times effective_C
50 effective_c // effective speed of light
51 };
52
58
74
76 {
77 public:
78 MillepedeEngine() = default;
79 void enable_rank_check(bool rank_check = true) { has_rank_check_ = rank_check; }
80 void set_t_diff_residual_cut(double val) { config_.t_diff_residual_cut = val; }
81 void set_p_value_cut(double val) { config_.p_value_cut = val; }
82 void set_options(const MillepedeOptions& options);
83
84 private:
85 bool has_rank_check_ = false;
86 int minimum_hit_ = 1;
87
89 // float minimum_pos_z_ = 0;
90 // float smallest_time_sum_ = 0.;
91 std::optional<float> average_t_sum_;
92 constexpr static std::string_view DEFAULT_SUB_DIR = "millepede";
93
98 // R3B::OutputVectorConnector<MilleDataPoint> output_mille_data_point_{ "MilleDataPoint" };
99 std::string pede_steer_filename_ = "neuland_steer.txt";
100 std::string input_parameter_filename_ = "neuland_pars.txt";
101 std::string working_dir_;
102
103 std::vector<int> plane_counter_;
104 std::unique_ptr<Mille> binary_data_writer_;
107
108 // histograms:
109 TGraphErrors* graph_time_offset_ = nullptr;
110 TGraphErrors* graph_time_sync_ = nullptr;
111 TGraphErrors* graph_effective_c_ = nullptr;
112 TH1D* hist_t_offset_residual_ = nullptr;
113 TH1D* hist_p_value_xz_ = nullptr;
114 TH1D* hist_p_value_yz_ = nullptr;
115 TH1D* hist_a_xz_ = nullptr;
116 TH1D* hist_b_xz_ = nullptr;
117 TH1D* hist_a_yz_ = nullptr;
118 TH1D* hist_b_yz_ = nullptr;
119 TH1D* hist_plane_hit_num_ = nullptr;
120 TH1L* barplot_filter_counts_ = nullptr;
121
122 // parameter:
124
125 std::unique_ptr<MilleDataProcessor> data_preprocessor_;
126
127 void Init() override;
128 void AddSignals(const std::vector<BarCalData>& signals) override;
129 void Calibrate(Cal2HitPar& hit_par) override;
130 void EndOfEvent(unsigned int event_num = 0) override;
131 void EventReset() override;
132 auto SignalFilter(const std::vector<BarCalData>& signals) -> bool override;
133 void BeginOfEvent() override
134 {
135 if (config_.enable_data_write)
136 {
137 output_mille_data_.clear();
140 }
141 // output_mille_data_point_.clear();
142 };
143 void EndOfTask() override;
144 void HistInit(DataMonitor& histograms) override;
145 void SetMinStat(int min) override
146 {
147 minimum_hit_ = min;
148 R3BLOG(info, fmt::format("Minimum number of hits is set to {}", minimum_hit_));
149 }
150 void SetErrorScale(float scale) override { config_.scale_factor = scale; }
151
152 void buffer_clear();
153 void write_to_buffer();
154 auto add_signal_t_sum(const MilleCalData& signal, const TrackFitResult& fit_coeff) -> float;
155 void add_signal_t_diff(const MilleCalData& signal);
156 void add_spacial_local_constraint(int plane_id, const std::vector<MilleCalData>& plane_signals);
157 auto set_minimum_values(const std::vector<R3B::Neuland::BarCalData>& signals) -> bool;
158 inline auto get_global_label_id(int module_num, GlobalLabel label) -> int;
159 inline auto to_module_num_label(int par_num) -> std::pair<int, GlobalLabel>;
160 void fill_module_parameters(const Millepede::ResultReader& result, Neuland::Cal2HitPar& cal_to_hit_par);
161 void fill_data_to_figure(Cal2HitPar& hit_par);
162
163 void init_parameter();
164 void init_steer_writer();
165 void set_working_dir();
167
168 using DataBufferType = std::unordered_map<int, std::vector<MilleCalData>>;
169 template <MillepedeCalibrationMode mode>
170 void add_signals(const DataBufferType& processed_data, const TrackFitResult& fit_coeff)
171 {
172 }
173
174 template <>
176 const TrackFitResult& fit_coeff);
177 template <>
179 const TrackFitResult& fit_coeff);
180
181 auto select_t_sync_signal(const std::vector<MilleCalData>& plane_data);
182 };
183
184} // namespace R3B::Neuland::Calibration
#define R3BLOG(severity, x)
Definition R3BLogger.h:33
auto to_module_num_label(int par_num) -> std::pair< int, GlobalLabel >
R3B::OutputVectorConnector< MilleCalData > output_tsync_mille_data_
R3B::OutputConnector< NeulandTrackInfo > output_mille_track_info_
void add_fit_result_hist(const MilleDataProcessor::FitResult &fit_result)
auto select_t_sync_signal(const std::vector< MilleCalData > &plane_data)
void Calibrate(Cal2HitPar &hit_par) override
void add_spacial_local_constraint(int plane_id, const std::vector< MilleCalData > &plane_signals)
auto set_minimum_values(const std::vector< R3B::Neuland::BarCalData > &signals) -> bool
void EndOfEvent(unsigned int event_num=0) override
std::unordered_map< int, std::vector< MilleCalData > > DataBufferType
static constexpr std::string_view DEFAULT_SUB_DIR
void fill_module_parameters(const Millepede::ResultReader &result, Neuland::Cal2HitPar &cal_to_hit_par)
void set_options(const MillepedeOptions &options)
std::unique_ptr< MilleDataProcessor > data_preprocessor_
auto add_signal_t_sum(const MilleCalData &signal, const TrackFitResult &fit_coeff) -> float
void add_signal_t_diff(const MilleCalData &signal)
auto SignalFilter(const std::vector< BarCalData > &signals) -> bool override
void add_signals(const DataBufferType &processed_data, const TrackFitResult &fit_coeff)
void AddSignals(const std::vector< BarCalData > &signals) override
auto get_global_label_id(int module_num, GlobalLabel label) -> int
void HistInit(DataMonitor &histograms) override
R3B::OutputVectorConnector< MilleCalData > output_mille_data_
constexpr auto DEFAULT_MINIMUM_PLANE_NUM
constexpr auto DEFAULT_CALIBRATION_P_VALUE_CUT
void MillepedeEngine::add_signals< MillepedeCalibrationMode::offset_effective_c >(const DataBufferType &processed_data, const TrackFitResult &fit_coeff)
constexpr auto DEFAULT_MAX_SLOPE_VALUE
void MillepedeEngine::add_signals< MillepedeCalibrationMode::tsync >(const DataBufferType &processed_data, const TrackFitResult &fit_coeff)
constexpr auto DEFAULT_T_DIFF_RESIDUAL_CUT
OutputConnector< std::vector< ElementType > > OutputVectorConnector
Data structure to store the cal level data for the data preprocessing.