R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandCountRateCanvas.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
16#include <algorithm>
17#include <range/v3/numeric.hpp>
18#include <range/v3/view.hpp>
19
20namespace rng = ranges;
21
22constexpr auto BEGIN_VIEW_RATIO = 0.1;
23constexpr auto END_VIEW_RATIO = 0.9;
24
25namespace R3B::Neuland
26{
27
29 {
30 mapped_data_.init();
31 hit_data_.init();
32 cal_data_.init();
33 }
34
36 {
37 auto& canvas = CreateNewCanvas(histograms);
38
39 canvas.divide(2, 2);
40 constexpr auto start_graph_data_size = 100;
41
42 los_count_rate_ = canvas.add<1, TGraph>("los_count_rate", start_graph_data_size);
43 los_count_rate_->SetTitle("Count rates for LOS");
44 los_count_rate_->GetXaxis()->SetTitle("time (min)");
45 los_count_rate_->GetYaxis()->SetTitle("counts per min");
46
47 map_count_rate_ = canvas.add<2, TGraph>("map_count_rate", start_graph_data_size);
48 map_count_rate_->SetTitle("Count rates for map level");
49 map_count_rate_->GetXaxis()->SetTitle("time (min)");
50 map_count_rate_->GetYaxis()->SetTitle("counts per min");
51
52 cal_count_rate_ = canvas.add<3, TGraph>("cal_count_rate", start_graph_data_size);
53 cal_count_rate_->SetTitle("Count rates for cal level");
54 cal_count_rate_->GetXaxis()->SetTitle("time (min)");
55 cal_count_rate_->GetYaxis()->SetTitle("counts per min");
56
57 hit_count_rate_ = canvas.add<4, TGraph>("hit_count_rate", start_graph_data_size);
58 hit_count_rate_->SetTitle("Count rates for onspill hit level");
59 hit_count_rate_->GetXaxis()->SetTitle("time (min)");
60 hit_count_rate_->GetYaxis()->SetTitle("counts per min");
61 }
62
64 {
65 los_count();
66 map_count();
67 cal_count();
68 hit_count();
69
70 // auto* x_axis = los_count_rate_->GetXaxis();
71 // auto range_begin = x_axis->GetBinCenter(x_axis->GetFirst());
72 // const auto range_end = x_axis->GetBinCenter(x_axis->GetLast());
73 // fmt::print("****min: {}, max: {}, padmax: {}\n", range_begin, range_end, los_count_rate_.pad()->GetUxmax());
74 calculate_count_rate();
75 }
76
77 void CountRateCanvas::los_count()
78 {
79
80 auto* event_header = GetOnlineSpectra()->GetEventHeader();
81 const auto time_start = event_header->GetTStart();
82 if (not std::isnan(time_start))
83 {
84 ++los_counter_;
85 }
86 }
87
88 void CountRateCanvas::map_count()
89 {
90 map_counter_ += rng::accumulate(
91 mapped_data_.get(),
92 int{ 0 },
93 [](auto init, const auto& plane_signals) -> int
94 {
95 return init + rng::accumulate(plane_signals | rng::views::values,
96 int{ 0 },
97 [](auto init_bar, const auto bar_signals) -> int {
98 return init_bar +
99 static_cast<int>(std::min(bar_signals.left.size(),
100 bar_signals.right.size()));
101 });
102 },
104 }
105
106 void CountRateCanvas::cal_count()
107 {
108 cal_counter_ += rng::accumulate(
109 cal_data_.get(),
110 int{ 0 },
111 [](auto init, const auto& bar_signals)
112 { return init + static_cast<int>(std::min(bar_signals.left.size(), bar_signals.right.size())); });
113 }
114
115 void CountRateCanvas::hit_count()
116 {
117 auto* online_spectra = GetOnlineSpectra();
118 auto is_on_spill = CheckTriggerWithTpat(CalTrigger::onspill,
119 online_spectra->GetEventHeader()->GetTpat(),
120 online_spectra->GetBasePar()->GetOffSpillTpatPos());
121 const auto time_start = online_spectra->GetEventHeader()->GetTStart();
122 if (is_on_spill and not std::isnan(time_start))
123 {
124 hit_counter_ += static_cast<int>(hit_data_.size());
125 }
126 }
127
128 void CountRateCanvas::calculate_count_rate()
129 {
130 auto time_now = std::chrono::steady_clock::now();
131 auto time_duration = std::chrono::duration_cast<std::chrono::seconds>(time_now - timer_);
132 if ((time_duration) > counting_duration_)
133 {
134 constexpr auto minute_to_seconds = 60.;
135 auto time_passed_seconds = std::chrono::duration_cast<std::chrono::seconds>(time_now - start_time_);
136 auto time_passed_minutes = static_cast<double>(time_passed_seconds.count()) / minute_to_seconds;
137 auto duration_minutes = static_cast<double>(time_duration.count()) / minute_to_seconds;
138 los_count_rate_->SetPoint(los_count_rate_->GetN(), time_passed_minutes, los_counter_ / duration_minutes);
139 map_count_rate_->SetPoint(map_count_rate_->GetN(), time_passed_minutes, map_counter_ / duration_minutes);
140 cal_count_rate_->SetPoint(cal_count_rate_->GetN(), time_passed_minutes, cal_counter_ / duration_minutes);
141 hit_count_rate_->SetPoint(hit_count_rate_->GetN(), time_passed_minutes, hit_counter_ / duration_minutes);
142 adjust_graph_view();
143 ResetCount();
144 }
145 }
146
147 inline void CountRateCanvas::set_view(double width)
148 {
149 do_each_graph(
150 [this, width](CanvasElement<TGraph>& graph)
151 {
152 const auto last_x = graph->GetPointX(graph->GetN() - 1);
153 auto* x_axis = graph->GetXaxis();
154 const auto range_min = x_axis->GetBinCenter(x_axis->GetFirst());
155 const auto range_max = x_axis->GetBinCenter(x_axis->GetLast());
156 auto range_begin = range_min;
157 if (last_view_mode_ != RangeViewMode::two_hours)
158 {
159 if (last_x > width / 2.)
160 {
161 range_begin = last_x - width / 2.;
162 }
163 }
164 else
165 {
166 if (last_x > range_min + width * END_VIEW_RATIO)
167 {
168 range_begin = last_x - width * BEGIN_VIEW_RATIO;
169 }
170 }
171 if (range_max < range_begin + width)
172 {
173 x_axis->SetLimits(0., range_begin + width);
174 }
175 x_axis->SetRangeUser(range_begin, range_begin + width);
176 // graph.pad()->Modified();
177 // graph.pad()->RangeChanged();
178 graph.pad()->RedrawAxis();
179 graph.pad()->Update();
180 });
181 }
182
183 inline void CountRateCanvas::set_two_hour_view()
184 {
185 constexpr auto range_width_minutes = 120.;
186 set_view(range_width_minutes);
187 // auto* x_axis = los_count_rate_->GetXaxis();
188 // auto range_begin = x_axis->GetBinCenter(x_axis->GetFirst());
189 // const auto range_end = x_axis->GetBinCenter(x_axis->GetLast());
190 // fmt::print("****min: {}, max: {}, padmax: {}\n", range_begin, range_end, los_count_rate_.pad()->GetUxmax());
191 }
192
193 inline void CountRateCanvas::set_four_hour_view()
194 {
195 constexpr auto range_width_minutes = 240.;
196 set_view(range_width_minutes);
197 }
198
199 inline void CountRateCanvas::set_full_view()
200 {
201 do_each_graph(
202 [](CanvasElement<TGraph>& graph)
203 {
204 auto* axis = graph->GetXaxis();
205 axis->UnZoom();
206 axis->SetCanExtend(true);
207 graph.pad()->RedrawAxis();
208 });
209 }
210
211 void CountRateCanvas::adjust_graph_view()
212 {
213 const auto view_mode = GetOnlineSpectra()->GetGraphViewMode();
214 if (view_mode == last_view_mode_ and last_view_mode_ == RangeViewMode::full)
215 {
216 return;
217 }
218 switch (view_mode)
219 {
220 case RangeViewMode::full:
221 set_full_view();
222 break;
223 case RangeViewMode::two_hours:
224 set_two_hour_view();
225 break;
226 case RangeViewMode::four_hours:
227 set_four_hour_view();
228 break;
229 }
230 last_view_mode_ = view_mode;
231 // auto* x_axis = los_count_rate_->GetXaxis();
232 // auto range_begin = x_axis->GetBinCenter(x_axis->GetFirst());
233 // const auto range_end = x_axis->GetBinCenter(x_axis->GetLast());
234 // fmt::print("min: {}, max: {}\n", range_begin, range_end);
235 }
236
238 {
239 timer_ = std::chrono::steady_clock::now();
240 los_counter_ = 0;
241 map_counter_ = 0;
242 cal_counter_ = 0;
243 hit_counter_ = 0;
244 }
245
247} // namespace R3B::Neuland
constexpr auto BEGIN_VIEW_RATIO
constexpr auto END_VIEW_RATIO
void CanvasFill(DataMonitor &histograms) override
void CanvasInit(DataMonitor &histograms) override
auto CreateNewCanvas(DataMonitor &histograms) -> DataMonitorCanvas &
auto GetOnlineSpectra() const -> OnlineSpectra *
Simulation of NeuLAND Bar/Paddle.
auto CheckTriggerWithTpat(CalTrigger trigger, int tpat, int off_spill_bit) -> bool
std::unordered_map< unsigned int, R3B::MapBarSignal > bars