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 {
106 return init_bar +
107 static_cast<int>(std::min(bar_signals.left.size(),
108 bar_signals.right.size()));
109 });
110 },
112 }
113
115 {
116 cal_counter_ += rng::accumulate(
117 cal_data_.get(),
118 0,
119 [](auto init, const auto& bar_signals)
120 { return init + static_cast<int>(std::min(bar_signals.left.size(), bar_signals.right.size())); });
121 }
122
124 {
125 auto* online_spectra = GetOnlineSpectra();
126 auto is_on_spill = CheckTriggerWithTpat(CalTrigger::onspill,
127 online_spectra->GetEventHeader()->GetTpat(),
128 online_spectra->GetBasePar()->get_offspill_tpat_pos());
129 const auto time_start = online_spectra->GetEventHeader()->GetTStart();
130 if (is_on_spill and not std::isnan(time_start))
131 {
132 hit_counter_ += static_cast<int>(hit_data_.size());
133 }
134 }
135
137 {
138 auto time_now = std::chrono::steady_clock::now();
139 auto time_duration = std::chrono::duration_cast<std::chrono::seconds>(time_now - timer_);
140 if ((time_duration) > counting_duration_)
141 {
142 constexpr auto minute_to_seconds = 60.;
143 auto time_passed_seconds = std::chrono::duration_cast<std::chrono::seconds>(time_now - start_time_);
144 auto time_passed_minutes = static_cast<double>(time_passed_seconds.count()) / minute_to_seconds;
145 auto duration_minutes = static_cast<double>(time_duration.count()) / minute_to_seconds;
146 los_count_rate_->SetPoint(los_count_rate_->GetN(), time_passed_minutes, los_counter_ / duration_minutes);
147 map_count_rate_->SetPoint(map_count_rate_->GetN(), time_passed_minutes, map_counter_ / duration_minutes);
148 cal_count_rate_->SetPoint(cal_count_rate_->GetN(), time_passed_minutes, cal_counter_ / duration_minutes);
149 hit_count_rate_->SetPoint(hit_count_rate_->GetN(), time_passed_minutes, hit_counter_ / duration_minutes);
151 ResetCount();
152 }
153 }
154
155 inline void CountRateCanvas::set_view(double width)
156 {
158 [this, width](CanvasElement<TGraph>& graph)
159 {
160 const auto last_x = graph->GetPointX(graph->GetN() - 1);
161 auto* x_axis = graph->GetXaxis();
162 const auto range_min = x_axis->GetBinCenter(x_axis->GetFirst());
163 const auto range_max = x_axis->GetBinCenter(x_axis->GetLast());
164 auto range_begin = range_min;
166 {
167 if (last_x > width / 2.)
168 {
169 range_begin = last_x - width / 2.;
170 }
171 }
172 else
173 {
174 if (last_x > range_min + width * END_VIEW_RATIO)
175 {
176 range_begin = last_x - width * BEGIN_VIEW_RATIO;
177 }
178 }
179 if (range_max < range_begin + width)
180 {
181 x_axis->SetLimits(0., range_begin + width);
182 }
183 x_axis->SetRangeUser(range_begin, range_begin + width);
184 // graph.pad()->Modified();
185 // graph.pad()->RangeChanged();
186 graph.pad()->RedrawAxis();
187 graph.pad()->Update();
188 });
189 }
190
192 {
193 constexpr auto range_width_minutes = 120.;
194 set_view(range_width_minutes);
195 // auto* x_axis = los_count_rate_->GetXaxis();
196 // auto range_begin = x_axis->GetBinCenter(x_axis->GetFirst());
197 // const auto range_end = x_axis->GetBinCenter(x_axis->GetLast());
198 // fmt::print("****min: {}, max: {}, padmax: {}\n", range_begin, range_end, los_count_rate_.pad()->GetUxmax());
199 }
200
202 {
203 constexpr auto range_width_minutes = 240.;
204 set_view(range_width_minutes);
205 }
206
208 {
210 [](CanvasElement<TGraph>& graph)
211 {
212 auto* axis = graph->GetXaxis();
213 axis->UnZoom();
214 axis->SetCanExtend(true);
215 graph.pad()->RedrawAxis();
216 });
217 }
218
220 {
221 const auto view_mode = GetOnlineSpectra()->GetGraphViewMode();
223 {
224 return;
225 }
226 switch (view_mode)
227 {
230 break;
233 break;
236 break;
237 }
238 last_view_mode_ = view_mode;
239 // auto* x_axis = los_count_rate_->GetXaxis();
240 // auto range_begin = x_axis->GetBinCenter(x_axis->GetFirst());
241 // const auto range_end = x_axis->GetBinCenter(x_axis->GetLast());
242 // fmt::print("min: {}, max: {}\n", range_begin, range_end);
243 }
244
246 {
247 timer_ = std::chrono::steady_clock::now();
248 los_counter_ = 0;
249 map_counter_ = 0;
250 cal_counter_ = 0;
251 hit_counter_ = 0;
252 }
253
255} // 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
bar number in a plane 1..50