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