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 "R3BLogger.h"
18#include "R3BNeulandCalData2.h"
22#include <Mille.h>
23#include <ParResultReader.h>
24#include <PedeLauncher.h>
25#include <R3BNeulandCommon.h>
26#include <TH1.h>
27#include <cstdint>
28#include <fmt/core.h>
29#include <memory>
30#include <optional>
31#include <string>
32#include <utility>
33#include <vector>
34// #include <RankChecker.h>
35
36class TGraphErrors;
37
39{
40 enum class GlobalLabel : int8_t
41 {
42 tsync, // tsync
43 offset_effective_c, // offset times effective_C
44 effective_c // effective speed of light
45 };
46
48 {
49 public:
50 MillepedeEngine() = default;
51 void enable_rank_check(bool rank_check = true) { has_rank_check_ = rank_check; }
52 void set_t_diff_residual_cut(double val) { t_diff_residual_cut_ = val; }
53 void set_p_value_cut(double val) { p_value_cut_ = val; }
54
55 private:
56 bool has_rank_check_ = false;
57 int minimum_hit_ = 1;
58 float error_scale_factor_ = 1000.F;
59 // float minimum_pos_z_ = 0;
60 // float smallest_time_sum_ = 0.;
61 std::optional<float> average_t_sum_;
62 float init_effective_c_ = DEFAULT_EFFECTIVE_C;
63 double t_diff_residual_cut_ = DEFAULT_T_DIFF_RESIDUAL_CUT;
64 double p_value_cut_ = DEFAULT_CALIBRATION_P_VALUE_CUT;
65
66 MilleDataPoint input_data_buffer_;
67 std::string input_data_filename_ = "neuland_cosmic_mille.bin";
68 std::string pede_steer_filename_ = "neuland_steer.txt";
69 std::string parameter_filename_ = "neuland_pars.txt";
70
71 Mille binary_data_writer_{ input_data_filename_ };
72 Millepede::ResultReader par_result_;
73 Millepede::Launcher pede_launcher_;
74
75 // histograms:
76 TGraphErrors* graph_time_offset_ = nullptr;
77 TGraphErrors* graph_time_sync_ = nullptr;
78 TGraphErrors* graph_effective_c_ = nullptr;
79 TH1D* hist_t_offset_residual_ = nullptr;
80
81 // parameter:
82 Cal2HitPar* cal_to_hit_par_ = nullptr;
83
84 std::unique_ptr<MilleDataProcessor> data_preprocessor_;
85
86 void Init() override;
87 void AddSignals(const std::vector<BarCalData>& signals) override;
88 void Calibrate(Cal2HitPar& hit_par) override;
89 void EndOfEvent(unsigned int event_num = 0) override;
90 void EventReset() override;
91 auto SignalFilter(const std::vector<BarCalData>& signals) -> bool override;
92 void EndOfTask() override;
93 void HistInit(DataMonitor& histograms) override;
94 void SetMinStat(int min) override
95 {
96 minimum_hit_ = min;
97 R3BLOG(info, fmt::format("Minimum number of hits is set to {}", minimum_hit_));
98 }
99 void SetErrorScale(float scale) override { error_scale_factor_ = scale; }
100
101 void buffer_clear();
102 void write_to_buffer();
103 void add_signal_t_sum(const MilleCalData& signal);
104 void add_signal_t_diff(const MilleCalData& signal);
105 void add_spacial_local_constraint(int plane_id, const std::vector<MilleCalData>& plane_signals);
106 auto set_minimum_values(const std::vector<R3B::Neuland::BarCalData>& signals) -> bool;
107 inline auto get_global_label_id(int module_num, GlobalLabel label) -> int;
108 inline auto to_module_num_label(int par_num) -> std::pair<int, GlobalLabel>;
109 void fill_module_parameters(const Millepede::ResultReader& result, Neuland::Cal2HitPar& cal_to_hit_par);
110 void fill_data_to_figure(Cal2HitPar& hit_par);
111
112 void init_parameter();
113 void init_steer_writer();
114
115 auto select_t_diff_signal(const std::vector<MilleCalData>& plane_data);
116 };
117
118} // namespace R3B::Neuland::Calibration
#define R3BLOG(severity, x)
Definition R3BLogger.h:35
void Calibrate(Cal2HitPar &hit_par) override
void EndOfEvent(unsigned int event_num=0) override
auto SignalFilter(const std::vector< BarCalData > &signals) -> bool override
void AddSignals(const std::vector< BarCalData > &signals) override
void HistInit(DataMonitor &histograms) override
constexpr auto DEFAULT_T_DIFF_RESIDUAL_CUT
constexpr auto DEFAULT_CALIBRATION_P_VALUE_CUT
constexpr auto DEFAULT_EFFECTIVE_C