R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandCalMonitorTask.cxx
Go to the documentation of this file.
2#include "R3BDataMonitor.h"
4#include "R3BNeulandCommon.h"
6#include <FairRootManager.h>
7#include <algorithm>
8#include <fmt/format.h>
9#include <functional>
10#include <ranges>
11#include <string_view>
12
13namespace R3B::Neuland
14{
15
16 constexpr auto MINIMAL_N_PLANE = 1;
17 CalMonitorTask::CalMonitorTask(std::string_view cal_data_name)
18 : CalibrationTask("R3BNeulandCalMonitorTask", 1)
19 , cal_data_{ cal_data_name }
20 {
21 }
22
23 void CalMonitorTask::ExtraInit([[maybe_unused]] FairRootManager* rootMan) { cal_data_.init(); }
24
26 {
27 const auto n_plane = GetBasePar()->get_num_of_planes();
28
29 hist_module_hit_num_ = histograms.add_hist<TH2D>("module_hit_num",
30 "Number of hits for each module",
31 n_plane,
32 -0.5,
33 -0.5 + n_plane,
35 -0.5,
36 -0.5 + BarsPerPlane);
37 hist_module_hit_num_->GetXaxis()->SetTitle("Plane ID");
38 hist_module_hit_num_->GetYaxis()->SetTitle("Bar ID");
39
40 for (auto planes_num : std::views::iota(MINIMAL_N_PLANE, n_plane + 1))
41 {
42 auto* hist =
44 .try_emplace(planes_num,
45 histograms.add_hist<TH2D>(
46 fmt::format("module_hit_{}_planes", planes_num),
47 fmt::format("Number of hits for each module if {} planes hit", planes_num),
48 n_plane,
49 -0.5,
50 -0.5 + n_plane,
52 -0.5,
53 -0.5 + BarsPerPlane)
54
55 )
56 .first->second;
57 hist->GetXaxis()->SetTitle("Plane ID");
58 hist->GetYaxis()->SetTitle("Bar ID");
59 }
60 static constexpr auto MAX_MODULE_NUM = 200;
61 hist_n_module_n_planes_ = histograms.add_hist<TH2D>("n_module_n_planes",
62 "Number of hit modules vs n hit planes",
63 n_plane + 1,
64 -0.5,
65 0.5 + n_plane,
66 MAX_MODULE_NUM,
67 0.5,
68 0.5 + MAX_MODULE_NUM);
69 hist_n_module_n_planes_->GetXaxis()->SetTitle("Plane ID");
70 hist_n_module_n_planes_->GetYaxis()->SetTitle("Number of modules");
71
73 histograms.add_hist<TH2D>("module_hit_n_half_planes",
74 "Number of hits for each module if first 13 planes hit",
75 n_plane,
76 -0.5,
77 -0.5 + n_plane,
79 -0.5,
80 -0.5 + BarsPerPlane);
82 histograms.add_hist<TH1D>("plane_hit_num", "Number of hit planes", n_plane + 1, -0.5, 0.5 + n_plane);
83 hist_plane_hit_num_->GetXaxis()->SetTitle("Number of planes hit");
84 hist_plane_hit_num_->GetYaxis()->SetTitle("Counts");
85
86 constexpr static auto MAX_HIT_SIZE = 10;
87 hist_bar_hit_sizes_ = histograms.add_hist<TH1D>(
88 "hit_sizes_of_bar", "Hit sizes of each bar", MAX_HIT_SIZE + 1, -0.5, 0.5 + MAX_HIT_SIZE);
89 hist_bar_hit_sizes_->GetXaxis()->SetTitle("Number of hits in the bar");
90 hist_bar_hit_sizes_->GetYaxis()->SetTitle("Counts");
91 }
92
94 {
95 const auto n_plane = GetBasePar()->get_num_of_planes();
96 plane_counter_.clear();
97 plane_counter_.resize(n_plane, 0);
98
99 for (const auto& bar_data : cal_data_)
100 {
101 if (bar_data.left.size() != bar_data.right.size())
102 {
103 continue;
104 }
105 hist_bar_hit_sizes_->Fill(static_cast<double>(bar_data.left.size()));
106 if (bar_data.left.size() != 1)
107 {
108 continue;
109 }
110 const auto module_num = bar_data.module_num;
111 const auto plane_id = Common::ModuleID2PlaneID(module_num - 1);
112 const auto bar_id = Common::ModuleNum2BarID(module_num);
113 hist_module_hit_num_->Fill(plane_id, bar_id);
114 ++plane_counter_.at(plane_id);
115 }
116
117 const auto n_hit_plane = std::ranges::count_if(plane_counter_, [](auto val) -> bool { return val != 0; });
118 const auto n_hit_plane_half = std::ranges::count_if(plane_counter_ | std::views::take(n_plane / 2),
119 [](auto val) -> bool { return val != 0; });
120 const auto n_hit_modules = std::ranges::fold_left(plane_counter_, 0, std::plus{});
121 hist_plane_hit_num_->Fill(static_cast<double>(n_hit_plane));
122 hist_n_module_n_planes_->Fill(static_cast<double>(n_hit_plane), n_hit_modules);
123
124 // auto has_bar = false;
125 // auto has_bar_1 = false;
126 for (const auto& bar_data : cal_data_)
127 {
128 if (bar_data.left.size() != bar_data.right.size())
129 {
130 continue;
131 }
132 hist_bar_hit_sizes_->Fill(static_cast<double>(bar_data.left.size()));
133 if (bar_data.left.size() != 1)
134 {
135 continue;
136 }
137 const auto module_num = bar_data.module_num;
138 const auto plane_id = Common::ModuleID2PlaneID(module_num - 1);
139 const auto bar_id = Common::ModuleNum2BarID(module_num);
140 if (n_hit_plane >= MINIMAL_N_PLANE)
141 {
142 hist_module_hit_n_planes_.at(static_cast<int>(n_hit_plane))->Fill(plane_id, bar_id);
143 }
144 if (n_hit_plane_half == n_plane / 2)
145 {
146 hist_module_hit_n_half_planes_->Fill(plane_id, bar_id);
147 }
148 // if(module_num == 501 or module_num == 550)
149 // {
150 // has_bar = true;
151 // }
152 // if(module_num == 701 or module_num == 750)
153 // {
154 // has_bar_1 = true;
155 // }
156 }
157 // if (n_hit_plane == 12 and has_bar)
158 // {
159 // fmt::println("------------left----------------");
160 // fmt::println("plane_id: {:>2}", fmt::join(std::views::iota(0, n_plane), ", "));
161 // fmt::println("vec : {:>2}", fmt::join(plane_counter_, ", "));
162 // fmt::println("module_n: {:>2}", fmt::join(cal_data_ | std::views::transform([](const auto&
163 // cal_data){return cal_data.module_num;}), ", "));
164 // }
165 // if (n_hit_plane == 12 and has_bar_1)
166 // {
167 // fmt::println("------------right----------------");
168 // fmt::println("plane_id: {:>2}", fmt::join(std::views::iota(0, n_plane), ", "));
169 // fmt::println("vec : {:>2}", fmt::join(plane_counter_, ", "));
170 // fmt::println("module_n: {:>2}", fmt::join(cal_data_ | std::views::transform([](const auto&
171 // cal_data){return cal_data.module_num;}), ", "));
172 // }
173 }
174} // namespace R3B::Neuland
auto add_hist(std::unique_ptr< TH1 > hist) -> TH1 *
std::map< int, TH2D * > hist_module_hit_n_planes_
InputVectorConnector< BarCalData > cal_data_
CalMonitorTask(std::string_view cal_data_name="NeulandCalData")
void ExtraInit(FairRootManager *rootMan) override
void HistogramInit(DataMonitor &histograms) override
static constexpr auto ModuleNum2BarID(int module_num) -> int
static constexpr auto ModuleID2PlaneID(int moduleID) -> int
Simulation of NeuLAND Bar/Paddle.
constexpr auto BarsPerPlane
constexpr auto MINIMAL_N_PLANE