ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TScalerMonitorProcessor.cc
Go to the documentation of this file.
1/**
2 * @file TScalerMonitorProcessor.cc
3 * @brief
4 * @author Kodai Okawa<okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2024-01-28 14:26:03
6 * @note
7 */
8
10
11#include <TAxis.h>
12#include <TLegend.h>
13#include <TStyle.h>
14#include <chrono>
15
17
19
21 : fShortCount(0), fLongCount(0) {
22 RegisterInputCollection("InputCollection",
23 "Scaler object inheriting from art::TScalerData",
24 fInputColName, TString("scatot"));
25
26 RegisterProcessorParameter("ShortInterval", "the interval time (seconds) for short time monitor",
28 RegisterProcessorParameter("ShortDuration", "the time range (seconds) for short time monitor",
30 RegisterProcessorParameter("LongInterval", "the interval time (seconds) for long time monitor",
31 fLongInterval, 0);
32 RegisterProcessorParameter("LongDuration", "the time range (seconds) for long time monitor",
33 fLongDuration, 0);
34 IntVec_t ivec;
35 RegisterProcessorParameter("Clock", "the channel number of 10Hz clock [ch, Hz]",
36 fClock, ivec);
37
38 StringVec_t init_v;
39 RegisterProcessorParameter("Channels", "the time range (seconds) for long time monitor",
40 fChannels, init_v);
41
42 for (Int_t i = 0; i < SCALER_CH; i++) {
43 fFactors[i] = 1.0;
44 fGr_s[i] = nullptr;
45 fGr_l[i] = nullptr;
46 }
47}
48
50 for (Int_t i = 0; i < SCALER_CH; i++) {
51 delete fGr_s[i];
52 delete fGr_l[i];
53 }
54
55 // delete main;
56 // delete pad_s;
57 // delete pad_l;
58}
59
60void TScalerMonitorProcessor::Init(TEventCollection *col) {
61 gStyle->SetTimeOffset(-788918400); // to UNIX time
62 gStyle->SetNdivisions(505);
63 gStyle->SetPadGridX(1);
64 gStyle->SetPadGridY(1);
65
66 Info("Init", "Scaler live time chart");
67 Info("Init", "NEED: analysis speed > trigger rate");
68 Info("Init", "\tshort time chart: interval %d s, time range %d s", fShortInterval, fShortDuration);
69 Info("Init", "\tlong time chart : interval %d s, time range %d s", fLongInterval, fLongDuration);
70 Info("Init", "Display: channel, name, scale factor");
71 for (Size_t i = 0; i < fChannels.size(); i++) {
72 Info("Init", "Display: %s", fChannels[i].Data());
73 }
74
75 fInData = reinterpret_cast<TScalerData **>(col->GetObjectRef(fInputColName.Data()));
76 if (!fInData) {
77 SetStateError(TString::Format("input not found: %s", fInputColName.Data()));
78 return;
79 }
80
81 for (Size_t i = 0; i < fChannels.size(); i++) {
82 Int_t first = fChannels[i].First(',');
83 Int_t last = fChannels[i].Last(',');
84 Int_t len = fChannels[i].Length();
85 if (first == last) {
86 SetStateError("Input steering yaml is wrong, need \"ch, name, factor\"");
87 return;
88 }
89 TString channel_str = fChannels[i](0, first);
90 Int_t channel = channel_str.Remove(TString::kBoth, ' ').Atoi();
91 fDisplayCh.emplace_back(channel);
92
93 TString name = fChannels[i](first + 1, last - first - 1);
94 fNames.emplace_back(name.Remove(TString::kBoth, ' '));
95
96 TString factor_str = fChannels[i](last + 1, len - last - 1);
97 Double_t factor = factor_str.Remove(TString::kBoth, ' ').Atof();
98
99 fFactors[channel] = factor;
100 }
101
102 for (Int_t i = 0; i < SCALER_CH; i++) {
103 fGr_s[i] = new TGraph();
104 fGr_s[i]->SetLineWidth(1);
105 fGr_s[i]->SetMarkerStyle(8);
106 fGr_s[i]->SetMarkerSize(0.8);
107 fGr_s[i]->SetMinimum(0.);
108 fGr_s[i]->SetMaximum(1000.);
109
110 fGr_l[i] = new TGraph();
111 fGr_l[i]->SetLineWidth(1);
112 fGr_l[i]->SetMarkerStyle(8);
113 fGr_l[i]->SetMarkerSize(0.8);
114 fGr_l[i]->SetMinimum(0.);
115 fGr_l[i]->SetMaximum(1000.);
116 }
117
118 for (Size_t i = 0; i < fChannels.size(); i++) {
119 fGr_s[fDisplayCh[i]]->SetTitle("count rate (short);;cps");
120 fGr_s[fDisplayCh[i]]->SetName(fNames[i]);
121 fGr_s[fDisplayCh[i]]->SetLineColor(fColor_list[i]);
122 fGr_s[fDisplayCh[i]]->SetMarkerColor(fColor_list[i]);
123 fGr_s[fDisplayCh[i]]->GetXaxis()->SetTimeDisplay(1);
124 fGr_s[fDisplayCh[i]]->GetXaxis()->SetTimeFormat("%m/%d %H:%M");
125
126 fGr_l[fDisplayCh[i]]->SetTitle("count rate (long);;cps");
127 fGr_l[fDisplayCh[i]]->SetName(fNames[i]);
128 fGr_l[fDisplayCh[i]]->SetLineColor(fColor_list[i]);
129 fGr_l[fDisplayCh[i]]->SetMarkerColor(fColor_list[i]);
130 fGr_l[fDisplayCh[i]]->GetXaxis()->SetTimeDisplay(1);
131 fGr_l[fDisplayCh[i]]->GetXaxis()->SetTimeFormat("%m/%d %H:%M");
132 }
133
134 main = new TCanvas("canvas", "monitor", 800, 800);
135 pad_s = new TPad("short", "short", 0.0, 0.5, 1.0, 1.0);
136 pad_l = new TPad("long", "long", 0.0, 0.0, 1.0, 0.5);
137 pad_s->Draw();
138 pad_l->Draw();
139
140 fIsFirst = true;
141}
142
144 Long_t now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
145
146 if (fIsFirst) {
147 fStartShort = now;
148 fStartLong = now;
149 fCurrentShort = now;
150 fCurrentLong = now;
151
152 fIsFirst = false;
153
154 const TScalerData *const scadata = static_cast<TScalerData *>(*fInData);
155 for (Int_t i = 0; i < SCALER_CH; i++) {
156 fShortScatot[i] = scadata->GetValue(i);
157 fShortScadiff[i] = scadata->GetValue(i);
158 fLongScatot[i] = scadata->GetValue(i);
159 fLongScadiff[i] = scadata->GetValue(i);
160 }
161 }
162
163 ProcessShort(now);
164 ProcessLong(now);
165}
166
168 if (now - fCurrentShort > fShortInterval) {
169 const TScalerData *const scadata = static_cast<TScalerData *>(*fInData);
170 if (scadata->GetValue(fClock[0]) - fShortScatot[fClock[0]] <= 0) {
171 for (Int_t i = 0; i < SCALER_CH; i++) {
172 fShortScatot[i] = scadata->GetValue(i);
173 fShortScadiff[i] = scadata->GetValue(i);
174 }
175 fCurrentShort = now;
176 return;
177 }
178
179 for (Int_t i = 0; i < SCALER_CH; i++) {
180 fShortScadiff[i] = scadata->GetValue(i) - fShortScatot[i];
181 fShortScatot[i] = scadata->GetValue(i);
182 }
183
184 for (Int_t i = 0; i < SCALER_CH; i++) {
185 fShortScadiff[i] = (UInt_t)(fClock[1] * fShortScadiff[i] / fShortScadiff[fClock[0]]);
186 fGr_s[i]->SetPoint(fShortCount, now, fShortScadiff[i] * fFactors[i]);
187
188 if (now - fStartShort > fShortDuration) { // slide
189 for (Int_t j = 0; j < fShortCount; j++) {
190 Double_t x, y;
191 fGr_s[i]->GetPoint(j + 1, x, y);
192 fGr_s[i]->SetPoint(j, x, y);
193 }
194 fGr_s[i]->RemovePoint(fShortCount);
195 }
196 }
197
198 // draw process
199 pad_s->cd();
200 Bool_t isfirst_obj = true;
201 TLegend *legend = new TLegend(0.78, 0.70, 0.95, 0.95);
202 for (Size_t i = 0; i < fDisplayCh.size(); i++) {
203 if (isfirst_obj) {
204 fGr_s[fDisplayCh[i]]->Draw("apl");
205 legend->AddEntry(fGr_s[fDisplayCh[i]], fNames[i], "pl");
206 isfirst_obj = false;
207 continue;
208 }
209 fGr_s[fDisplayCh[i]]->Draw("pl");
210 legend->AddEntry(fGr_s[fDisplayCh[i]], fNames[i], "pl");
211 }
212 legend->Draw();
213 main->Update();
214
215 if (now - fStartShort <= fShortDuration) {
216 fShortCount++;
217 }
218 fCurrentShort = now;
219 }
220}
221
223 if (now - fCurrentLong > fLongInterval) {
224 const TScalerData *const scadata = static_cast<TScalerData *>(*fInData);
225 if (scadata->GetValue(fClock[0]) - fLongScatot[fClock[0]] <= 0) {
226 for (Int_t i = 0; i < SCALER_CH; i++) {
227 fLongScatot[i] = scadata->GetValue(i);
228 fLongScadiff[i] = scadata->GetValue(i);
229 }
230 fCurrentLong = now;
231 return;
232 }
233 for (Int_t i = 0; i < SCALER_CH; i++) {
234 fLongScadiff[i] = scadata->GetValue(i) - fLongScatot[i];
235 fLongScatot[i] = scadata->GetValue(i);
236 }
237
238 for (Int_t i = 0; i < SCALER_CH; i++) {
239 fLongScadiff[i] = (UInt_t)(fClock[1] * fLongScadiff[i] / fLongScadiff[fClock[0]]);
240 fGr_l[i]->SetPoint(fLongCount, now, fLongScadiff[i] * fFactors[i]);
241
242 if (now - fStartLong > fLongDuration) { // slide
243 for (Int_t j = 0; j < fLongCount; j++) {
244 Double_t x, y;
245 fGr_l[i]->GetPoint(j + 1, x, y);
246 fGr_l[i]->SetPoint(j, x, y);
247 }
248 fGr_l[i]->RemovePoint(fLongCount);
249 }
250 }
251
252 // draw process
253 pad_l->cd();
254 Bool_t isfirst_obj = true;
255 for (Int_t &ch : fDisplayCh) {
256 if (isfirst_obj) {
257 fGr_l[ch]->Draw("apl");
258 isfirst_obj = false;
259 continue;
260 }
261 fGr_l[ch]->Draw("pl");
262 }
263 main->Update();
264
265 if (now - fStartLong <= fLongDuration) {
266 fLongCount++;
267 }
268 fCurrentLong = now;
269 }
270}
ClassImp(TScalerMonitorProcessor)
void Init(TEventCollection *col) override
return to the guide