Belle II Software development
TRGTOPWaveformPlotterModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8//---------------------------------------------------------------
9// $Id$
10//---------------------------------------------------------------
11// Filename : TRGTOPWaveformPlotterModule.cc
12// Section : TRG TOP
13// Owner :
14// Email :
15//---------------------------------------------------------------
16// Description : TOP-CDC matching studies module for TRGTOP
17//---------------------------------------------------------------
18// 1.00 : 2020/09/20 : First version
19//
20// Modeled after / heavily borrowing from GDL, GRL and ECL DQM modules
21//---------------------------------------------------------------
22#include <trg/top/modules/trgtopWaveformPlotter/TRGTOPWaveformPlotterModule.h>
23//#include <mdst/dataobjects/SoftwareTriggerResult.h>
24
25#include <framework/datastore/StoreObjPtr.h>
26#include <framework/datastore/StoreArray.h>
27
28#include "trg/top/dataobjects/TRGTOPTimeStampsSlot.h"
29#include "trg/top/dataobjects/TRGTOPTimeStamp.h"
30
31#include "trg/top/dataobjects/TRGTOPWaveFormTimeStampsSlot.h"
32#include "trg/top/dataobjects/TRGTOPWaveFormTimeStamp.h"
33
34#include "trg/top/dataobjects/TRGTOPSlotTiming.h"
35
36#include "trg/top/dataobjects/TRGTOPTimingISimSlot.h"
37
38#include <framework/datastore/RelationVector.h>
39
40#include <framework/logging/Logger.h>
41
42#include <iostream>
43
44//using namespace std;
45using namespace Belle2;
46
47REG_MODULE(TRGTOPWaveformPlotter);
48
50{
51
52 setDescription("TRGTOP Waveform Plotter");
53
55
56 // Parameter definitions
57
58 addParam("plottingMode", m_plottingMode,
59 "Plotting mode: 0 (forced ranges for x and y), 1 (slot-level zoom-in), 2 (global zoom-in; default), 3 (global zoom-in for y and xmax, forced left-side edge for x), 4 (global zoom-in for y, forced range for x), anything else (full ranges)",
60 2);
61
62 addParam("firstAssumedClockCycle", m_firstAssumedClockCycle,
63 "First assumed clock cycle for main readout hits",
64 108);
65
66 addParam("cutPlotMinNumberTriggerReadoutHits", m_cutPlotMinNumberTriggerReadoutHits,
67 "Minimum number of trigger timestamps cut for drawing the waveform",
68 5);
69
70 addParam("cutPlotMinNumberMainReadoutHits", m_cutPlotMinNumberMainReadoutHits,
71 "Minimum number of main readout hits cut for drawing the hits",
72 5);
73
74 addParam("markerSizeHits", m_markerSizeHits,
75 "Marker size (default: 0.85) used to plot main readout hits",
76 0.85);
77
78 addParam("markerSizeTimestamps", m_markerSizeTimestamps,
79 "Marker size (default: 0.65) used to plot trigger readout timestamps",
80 0.65);
81
82 addParam("markerTypeHits", m_markerTypeHits,
83 "Marker type (default: 21) used to plot main readout hits",
84 21);
85
86 addParam("markerTypeTimestamps", m_markerTypeTimestamps,
87 "Marker type (default: 20) used to plot trigger readout timestamps",
88 20);
89
90 addParam("xMin", m_xMin,
91 "xMin for plotting (default: 100)",
92 100);
93
94 addParam("xMax", m_xMax,
95 "xMax for plotting (default: 200)",
96 200);
97
98 addParam("yMin", m_yMin,
99 "yMin for plotting (default: 0)",
100 0);
101
102 addParam("yMax", m_yMax,
103 "yMax for plotting (default: 47000)",
104 47000);
105
106 addParam("showGridx", m_showGridx,
107 "Show grid x (default: 0 (no))",
108 0);
109
110 addParam("showGridy", m_showGridy,
111 "Show grid y (default: 1 (yes))",
112 1);
113
114 addParam("canvasXMin", m_canvasXMin,
115 "TCanvas x min (default: 0))",
116 0);
117
118 addParam("canvasYMin", m_canvasYMin,
119 "TCanvas y min (default: 0))",
120 0);
121
122 addParam("canvasXSize", m_canvasXSize,
123 "TCanvas x size (default: 900))",
124 900);
125
126 addParam("canvasYSize", m_canvasYSize,
127 "TCanvas y size (default: 600))",
128 600);
129
130 addParam("shiftCanvas", m_shiftCanvas,
131 "Shift canvases (default: 1 (yes)))",
132 1);
133
134 addParam("xShiftCanvas", m_xShiftCanvas,
135 "x shift canvases (default: 900))",
136 910);
137
138 addParam("yShiftCanvas", m_yShiftCanvas,
139 "y shift canvases (default: 600))",
140 610);
141
142}
143
145{
146
147 // myROOTDir->cd();
148
149 // oldROOTDir->cd();
150
151}
152
154{
155
156 // oldROOTDir = gDirectory;
157
158 // m_file = new TFile(m_outputTTreeFileName.c_str(), "RECREATE");
159
160 // myROOTDir = gDirectory;
161
162 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) {
163 m_timeStampsGraphMainReadout[slot - 1] = 0;
164 m_timeStampsGraphTriggerReadout[slot - 1] = 0;
165 m_myMultiGraph[slot - 1] = 0;
166 m_myPaveText[slot - 1] = 0;
167 m_myCanvas[slot - 1] = 0;
168 }
169
170 // if (!oldROOTDir) oldROOTDir->cd();
171
172}
173
175{
176
177}
178
180{
181
182 // oldROOTDir = gDirectory;
183 // myROOTDir->cd();
184
185 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) {
186
187 //
188 // The code below assumes that none of the higher-level object (such as TCanvas) own any of the embedded objects (such as TGraph's)
189 //
190
191 if (m_timeStampsGraphMainReadout[slot - 1]) {
192 delete m_timeStampsGraphMainReadout[slot - 1];
193 m_timeStampsGraphMainReadout[slot - 1] = NULL;
194 }
195
196 if (m_timeStampsGraphTriggerReadout[slot - 1]) {
197 delete m_timeStampsGraphTriggerReadout[slot - 1];
198 m_timeStampsGraphTriggerReadout[slot - 1] = NULL;
199 }
200
201 if (m_myMultiGraph[slot - 1]) {
202 delete m_myMultiGraph[slot - 1];
203 m_myMultiGraph[slot - 1] = NULL;
204 }
205
206 if (m_myPaveText[slot - 1]) {
207 delete m_myPaveText[slot - 1];
208 m_myPaveText[slot - 1] = NULL;
209 }
210
211 if (m_myCanvas[slot - 1]) {
212 delete m_myCanvas[slot - 1];
213 m_myCanvas[slot - 1] = NULL;
214 }
215
216 }
217
218 // TOP timestamps made from TOPRawDigits
219 StoreArray<TRGTOPTimeStamp> trgtopTimeStamps("TRGTOPTimeStamps");
220 StoreArray<TRGTOPTimeStampsSlot> trgtopTimeStampsSlots("TRGTOPTimeStampsSlots");
221
222 // TRG TOP waveform readout
223 StoreArray<TRGTOPWaveFormTimeStamp> trgtopWaveFormTimeStamps("TRGTOPWaveFormTimeStamps");
224 StoreArray<TRGTOPWaveFormTimeStampsSlot> trgtopWaveFormTimeStampsSlots("TRGTOPWaveFormTimeStampsSlots");
225
226 // TOP TRG slot-level t0 decisions
227 StoreArray<TRGTOPSlotTiming> trgtopSlotTimingAll("TRGTOPSlotTimings");
228
229 // ISim results for main readout (for all slots and all decisions for each slot)
230 StoreArray<TRGTOPTimingISim> trgtopTimingISimMainReadoutAll("TRGTOPTimingISimMainReadouts");
231
232 // ISim results for trigger readout (for all slots and all decisions for each slot)
233 StoreArray<TRGTOPTimingISim> trgtopTimingISimTriggerReadoutAll("TRGTOPTimingISimTriggerReadouts");
234
235
236 // if (!trgtopWaveFormTimeStamps) return;
237 // if (!trgtopWaveFormTimeStampsSlots) return;
238
239 // ISim results for main readout hits
240
241 bool topTRGISimMRODecisionPresent[NUMBER_OF_TOP_SLOTS] = {false};
242 int topTRGISimMRODecisionTiming[NUMBER_OF_TOP_SLOTS] = {0};
243 int topTRGISimMRODecisionNTS[NUMBER_OF_TOP_SLOTS] = {0};
244 int topTRGISimMRODecisionNumber[NUMBER_OF_TOP_SLOTS] = {0};
245
246 std::string topTRGIsimMRODecisionText[NUMBER_OF_TOP_SLOTS];
247 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) topTRGIsimMRODecisionText[slot - 1] = "All iSim TOP decisions: ";
248
249 for (const auto& slotDecision : trgtopTimingISimMainReadoutAll) {
250
251 int slot = slotDecision.getSlotId();
252
253 topTRGISimMRODecisionPresent[slot - 1] = true;
254 topTRGISimMRODecisionTiming[slot - 1] = slotDecision.getSlotTiming();
255 topTRGISimMRODecisionNTS[slot - 1] = topTRGISimMRODecisionNTS[slot - 1] + slotDecision.getSlotNHits();
256 topTRGISimMRODecisionNumber[slot - 1] = topTRGISimMRODecisionNumber[slot - 1] + 1;
257
258 std::stringstream ss1;
259 ss1 << slotDecision.getSlotNHits();
260 std::stringstream ss2;
261 ss2 << slotDecision.getSlotTiming();
262 std::stringstream ss3;
263 ss3 << slotDecision.getSlotDecisionClockCycle();
264 topTRGIsimMRODecisionText[slot - 1] = topTRGIsimMRODecisionText[slot - 1] + " " + ss2.str() + " ( " + ss1.str() + " [" + ss3.str() +
265 "]" + " ); ";
266
267 }
268
269 // ISim results for trigger readout hits
270
271 bool topTRGISimWFRODecisionPresent[NUMBER_OF_TOP_SLOTS] = {false};
272 int topTRGISimWFRODecisionTiming[NUMBER_OF_TOP_SLOTS] = {0};
273 int topTRGISimWFRODecisionNTS[NUMBER_OF_TOP_SLOTS] = {0};
274 int topTRGISimWFRODecisionNumber[NUMBER_OF_TOP_SLOTS] = {0};
275
276 std::string topTRGIsimWFRODecisionText[NUMBER_OF_TOP_SLOTS];
277 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) topTRGIsimWFRODecisionText[slot - 1] = "All iSim TRG decisions: ";
278
279 for (const auto& slotDecision : trgtopTimingISimTriggerReadoutAll) {
280
281 int slot = slotDecision.getSlotId();
282
283 topTRGISimWFRODecisionPresent[slot - 1] = true;
284 topTRGISimWFRODecisionTiming[slot - 1] = slotDecision.getSlotTiming();
285 topTRGISimWFRODecisionNTS[slot - 1] = topTRGISimWFRODecisionNTS[slot - 1] + slotDecision.getSlotNHits();
286 topTRGISimWFRODecisionNumber[slot - 1] = topTRGISimWFRODecisionNumber[slot - 1] + 1;
287
288 std::stringstream ss1;
289 ss1 << slotDecision.getSlotNHits();
290 std::stringstream ss2;
291 ss2 << slotDecision.getSlotTiming();
292 std::stringstream ss3;
293 ss3 << slotDecision.getSlotDecisionClockCycle();
294 topTRGIsimWFRODecisionText[slot - 1] = topTRGIsimWFRODecisionText[slot - 1] + " " + ss2.str() + " ( " + ss1.str() + " [" + ss3.str()
295 + "]" + " ); ";
296
297 }
298
299 // slot-level online trigger decisions
300
301 bool topTRGDecisionPresent[NUMBER_OF_TOP_SLOTS] = {false};
302 int topTRGDecisionTiming[NUMBER_OF_TOP_SLOTS] = {0};
303 int topTRGDecisionNTS[NUMBER_OF_TOP_SLOTS] = {0};
304 int topTRGDecisionNumber[NUMBER_OF_TOP_SLOTS] = {0};
305 // int topTRGDecisionClockCycle[NUMBER_OF_TOP_SLOTS] = {0};
306
307 std::string topTRGDecisionText[NUMBER_OF_TOP_SLOTS];
308 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) topTRGDecisionText[slot - 1] = "All online TRG decisions: ";
309
310 for (const auto& slotDecision : trgtopSlotTimingAll) {
311
312 // for purposes of visualization do not display information received from the OTHER board
313 if (slotDecision.isThisBoard()) {
314
315 int slot = slotDecision.getSlotId();
316
317 topTRGDecisionPresent[slot - 1] = true;
318 topTRGDecisionTiming[slot - 1] = slotDecision.getSlotTiming();
319 topTRGDecisionNTS[slot - 1] = topTRGDecisionNTS[slot - 1] + slotDecision.getSlotNHits();
320 // topTRGDecisionClockCycle[slot-1] = slotDecision.getSlotDecisionClockCycle();
321 topTRGDecisionNumber[slot - 1] = topTRGDecisionNumber[slot - 1] + 1;
322
323 std::stringstream ss1;
324 ss1 << slotDecision.getSlotNHits();
325 std::stringstream ss2;
326 ss2 << slotDecision.getSlotTiming() / 2;
327 std::stringstream ss3;
328 ss3 << slotDecision.getSlotDecisionClockCycle();
329 topTRGDecisionText[slot - 1] = topTRGDecisionText[slot - 1] + " " + ss2.str() + " ( " + ss1.str() + " [" + ss3.str() + "]" + " ); ";
330
331 }
332 }
333
334 // main readout
335
336 bool topTRGMROPresent[NUMBER_OF_TOP_SLOTS] = {false};
337 int topTRGMRONTS[NUMBER_OF_TOP_SLOTS] = {0};
338
339 int clockCycleMainReadout[NUMBER_OF_TOP_SLOTS] = {0};
340 int indexClockCycleMainReadout[NUMBER_OF_TOP_SLOTS] = {0};
341
342 int xMinMRO[NUMBER_OF_TOP_SLOTS] = {0};
343 int xMaxMRO[NUMBER_OF_TOP_SLOTS] = {0};
344
345 int yMinMRO[NUMBER_OF_TOP_SLOTS] = {0};
346 int yMaxMRO[NUMBER_OF_TOP_SLOTS] = {0};
347
348 for (const auto& slotTSS : trgtopTimeStampsSlots) {
349
350 int slot = slotTSS.getSlotId();
351
352 clockCycleMainReadout[slot - 1] = m_firstAssumedClockCycle;
353
354 xMinMRO[slot - 1] = -1;
355 xMaxMRO[slot - 1] = -1;
356
357 yMinMRO[slot - 1] = -1;
358 yMaxMRO[slot - 1] = -1;
359
360 int nHits = slotTSS.getNumberOfTimeStamps();
361
362 if (nHits != 0) {
363
364 topTRGMROPresent[slot - 1] = true;
365 topTRGMRONTS[slot - 1] = nHits;
366
367 if (topTRGMRONTS[slot - 1] > MAX_NUMBER_OF_CLOCK_CYCLES) topTRGMRONTS[slot - 1] = MAX_NUMBER_OF_CLOCK_CYCLES;
368
369 for (const auto& timeStamp : slotTSS.getRelationsTo<TRGTOPTimeStamp>()) {
370 int value = timeStamp.getTimeStamp();
371
372 m_clockCyclesMainReadout[slot - 1][indexClockCycleMainReadout[slot - 1]] = clockCycleMainReadout[slot - 1];
373 m_timeStampsMainReadout[slot - 1][indexClockCycleMainReadout[slot - 1]] = value;
374
375 if (xMinMRO[slot - 1] == -1
376 || clockCycleMainReadout[slot - 1] < xMinMRO[slot - 1]) xMinMRO[slot - 1] = clockCycleMainReadout[slot - 1];
377 if (xMaxMRO[slot - 1] == -1
378 || clockCycleMainReadout[slot - 1] > xMaxMRO[slot - 1]) xMaxMRO[slot - 1] = clockCycleMainReadout[slot - 1];
379
380 if (yMinMRO[slot - 1] == -1 || value < yMinMRO[slot - 1]) yMinMRO[slot - 1] = value;
381 if (yMaxMRO[slot - 1] == -1 || value > yMaxMRO[slot - 1]) yMaxMRO[slot - 1] = value;
382
383 if (indexClockCycleMainReadout[slot - 1] < MAX_NUMBER_OF_CLOCK_CYCLES) {
384 indexClockCycleMainReadout[slot - 1]++;
385 clockCycleMainReadout[slot - 1]++;
386 }
387 }
388 }
389 }
390
391 // waveform readout
392
393 bool topTRGWFROPresent[NUMBER_OF_TOP_SLOTS] = {false};
394 int topTRGWFRONTS[NUMBER_OF_TOP_SLOTS] = {0};
395
396 int clockCycleTriggerReadout[NUMBER_OF_TOP_SLOTS] = {0};
397 int indexClockCycleTriggerReadout[NUMBER_OF_TOP_SLOTS] = {0};
398
399 int xMinWFRO[NUMBER_OF_TOP_SLOTS] = {0};
400 int xMaxWFRO[NUMBER_OF_TOP_SLOTS] = {0};
401
402 int yMinWFRO[NUMBER_OF_TOP_SLOTS] = {0};
403 int yMaxWFRO[NUMBER_OF_TOP_SLOTS] = {0};
404
405 for (auto& slotWaveFormTSS : trgtopWaveFormTimeStampsSlots) {
406
407 int slot = slotWaveFormTSS.getSlotId();
408
409 xMinWFRO[slot - 1] = -1;
410 xMaxWFRO[slot - 1] = -1;
411
412 yMinWFRO[slot - 1] = -1;
413 yMaxWFRO[slot - 1] = -1;
414
415 int nHits = slotWaveFormTSS.getNumberOfActualTimeStamps();
416
417 if (nHits != 0) {
418
419 topTRGWFROPresent[slot - 1] = true;
420 topTRGWFRONTS[slot - 1] = nHits;
421
422 if (topTRGWFRONTS[slot - 1] > MAX_NUMBER_OF_CLOCK_CYCLES) topTRGWFRONTS[slot - 1] = MAX_NUMBER_OF_CLOCK_CYCLES;
423
424 for (auto& timeStamp : slotWaveFormTSS.getRelationsTo<TRGTOPWaveFormTimeStamp>()) {
425
426 if (!timeStamp.isEmptyClockCycle()) {
427
428 int value = timeStamp.getTimeStamp();
429
430 m_clockCyclesTriggerReadout[slot - 1][indexClockCycleTriggerReadout[slot - 1]] = clockCycleTriggerReadout[slot - 1];
431 m_timeStampsTriggerReadout[slot - 1][indexClockCycleTriggerReadout[slot - 1]] = value;
432
433 if (xMinWFRO[slot - 1] == -1
434 || clockCycleTriggerReadout[slot - 1] < xMinWFRO[slot - 1]) xMinWFRO[slot - 1] = clockCycleTriggerReadout[slot - 1];
435 if (xMaxWFRO[slot - 1] == -1
436 || clockCycleTriggerReadout[slot - 1] > xMaxWFRO[slot - 1]) xMaxWFRO[slot - 1] = clockCycleTriggerReadout[slot - 1];
437
438 if (yMinWFRO[slot - 1] == -1 || value < yMinWFRO[slot - 1]) yMinWFRO[slot - 1] = value;
439 if (yMaxWFRO[slot - 1] == -1 || value > yMaxWFRO[slot - 1]) yMaxWFRO[slot - 1] = value;
440
441 if (indexClockCycleTriggerReadout[slot - 1] < MAX_NUMBER_OF_CLOCK_CYCLES) {
442 indexClockCycleTriggerReadout[slot - 1]++;
443 }
444 }
445 clockCycleTriggerReadout[slot - 1]++;
446 }
447 }
448 }
449
450 // plotting
451
452 // for each slot
453 // decide if there is anything available (and requested) to plot for this slot
454 // then create a TMultiGraph
455 // then create at least one TGraph and add it to the list in TMultiGraph
456 // finally, decide how to plot this TMultiGraph and do that
457
458 bool plotMyCanvas[NUMBER_OF_TOP_SLOTS] = {false};
459
460 int xMin = -1;
461 int xMax = -1;
462 int yMin = -1;
463 int yMax = -1;
464
465 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) {
466 if (topTRGMRONTS[slot - 1] > 0 || topTRGWFRONTS[slot - 1] > 0) {
467 if (topTRGMRONTS[slot - 1] >= m_cutPlotMinNumberMainReadoutHits) {
468 if (topTRGWFRONTS[slot - 1] >= m_cutPlotMinNumberTriggerReadoutHits) {
469 plotMyCanvas[slot - 1] = true;
470 if (xMinMRO[slot - 1] != -1 && (xMin == -1 || xMinMRO[slot - 1] < xMin)) xMin = xMinMRO[slot - 1];
471 if (xMaxMRO[slot - 1] != -1 && (xMax == -1 || xMaxMRO[slot - 1] > xMax)) xMax = xMaxMRO[slot - 1];
472 if (yMinMRO[slot - 1] != -1 && (yMin == -1 || yMinMRO[slot - 1] < yMin)) yMin = yMinMRO[slot - 1];
473 if (yMaxMRO[slot - 1] != -1 && (yMax == -1 || yMaxMRO[slot - 1] > yMax)) yMax = yMaxMRO[slot - 1];
474
475 if (xMinWFRO[slot - 1] != -1 && (xMin == -1 || xMinWFRO[slot - 1] < xMin)) xMin = xMinWFRO[slot - 1];
476 if (xMaxWFRO[slot - 1] != -1 && (xMax == -1 || xMaxWFRO[slot - 1] > xMax)) xMax = xMaxWFRO[slot - 1];
477 if (yMinWFRO[slot - 1] != -1 && (yMin == -1 || yMinWFRO[slot - 1] < yMin)) yMin = yMinWFRO[slot - 1];
478 if (yMaxWFRO[slot - 1] != -1 && (yMax == -1 || yMaxWFRO[slot - 1] > yMax)) yMax = yMaxWFRO[slot - 1];
479 }
480 }
481 }
482 }
483
484 xMin = std::max(xMin - 10, 0);
485 xMax = xMax + 10;
486 yMin = std::max(yMin - 10, 0);
487 yMax = yMax + 10;
488
489 std::string myMultiGraphTitle[NUMBER_OF_TOP_SLOTS];
490
491 std::string myPaveTextInfo[NUMBER_OF_TOP_SLOTS][8];
492
493 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) {
494
495 if (plotMyCanvas[slot - 1]) {
496
497 m_myMultiGraph[slot - 1] = new TMultiGraph();
498 // In principle, we can allow TCanvas (where this TMultiGraph will be plotted) to assume the ownership over this graph.
499 // Then, when memory is freed, it should be sufficient to delete TCanvas only, as it would delete the graph also.
500 // m_myMultiGraph[slot-1]->SetBit(kCanDelete);
501 std::stringstream slotInfo;
502 slotInfo << slot;
503 myMultiGraphTitle[slot - 1] = "Slot " + slotInfo.str() + " : ";
504
505 m_myPaveText[slot - 1] = new TPaveText(0.40, 0.10, 0.90, 0.30, "bl NDC");
506 // m_myPaveText[slot-1]->SetHeader(myMultiGraphTitle[slot-1].c_str(),"C");;
507
508 if (topTRGMROPresent[slot - 1]) {
509
510 m_timeStampsGraphMainReadout[slot - 1] = new TGraph(topTRGMRONTS[slot - 1], &m_clockCyclesMainReadout[slot - 1][0],
511 &m_timeStampsMainReadout[slot - 1][0]);
512 // In principle, we can allow TCanvas (where this TGraph will be plotted) to assume the ownership over this graph.
513 // Then, when memory is freed, it should be sufficient to delete TCanvas only, as it would delete the graph also.
514 // m_timeStampsGraphMainReadout[slot-1]->SetBit(kCanDelete);
515
516 m_timeStampsGraphMainReadout[slot - 1]->SetMarkerStyle(m_markerTypeHits);
517 m_timeStampsGraphMainReadout[slot - 1]->SetMarkerSize(m_markerSizeHits);
518 m_timeStampsGraphMainReadout[slot - 1]->SetMarkerColor(kRed);
519
520 m_myMultiGraph[slot - 1]->Add(m_timeStampsGraphMainReadout[slot - 1], "AP");
521 }
522
523
524 if (topTRGWFROPresent[slot - 1]) {
525
526 m_timeStampsGraphTriggerReadout[slot - 1] = new TGraph(topTRGWFRONTS[slot - 1], &m_clockCyclesTriggerReadout[slot - 1][0],
527 &m_timeStampsTriggerReadout[slot - 1][0]);
528 // In principle, we can allow TCanvas (where this TGraph will be plotted) to assume the ownership over this graph.
529 // Then, when memory is freed, it should be sufficient to delete TCanvas only, as it would delete the graph also.
530 // m_timeStampsGraphTriggerReadout[slot-1]->SetBit(kCanDelete);
531
532 m_timeStampsGraphTriggerReadout[slot - 1]->SetMarkerStyle(m_markerTypeTimestamps);
533 m_timeStampsGraphTriggerReadout[slot - 1]->SetMarkerSize(m_markerSizeTimestamps);
534 m_timeStampsGraphTriggerReadout[slot - 1]->SetLineWidth(3);
535
536 int color = kBlue;
537 if (!topTRGDecisionPresent[slot - 1]) color = kBlack;
538
539 m_timeStampsGraphTriggerReadout[slot - 1]->SetMarkerColor(color);
540
541 m_myMultiGraph[slot - 1]->Add(m_timeStampsGraphTriggerReadout[slot - 1], "AP");
542 }
543 }
544 }
545
546 int canvasXMin = m_canvasXMin;
547 int canvasYMin = m_canvasYMin;
548 int canvasXSize = m_canvasXSize;
549 int canvasYSize = m_canvasYSize;
550
551 for (int slot = 1; slot <= NUMBER_OF_TOP_SLOTS; slot++) {
552
553 if (plotMyCanvas[slot - 1]) {
554
555 myMultiGraphTitle[slot - 1] = myMultiGraphTitle[slot - 1] + " TOP / TRG / L1 / iSim TOP / iSim TRG hits:";
556
557 std::stringstream nHitInfoMainReadout;
558 nHitInfoMainReadout << topTRGMRONTS[slot - 1];
559 myMultiGraphTitle[slot - 1] = myMultiGraphTitle[slot - 1] + " " + nHitInfoMainReadout.str();
560
561 myPaveTextInfo[slot - 1][0] = "N hits (TOP readout): " + nHitInfoMainReadout.str();
562
563 std::stringstream nHitInfoTriggerReadout;
564 nHitInfoTriggerReadout << topTRGWFRONTS[slot - 1];
565 myMultiGraphTitle[slot - 1] = myMultiGraphTitle[slot - 1] + " / " + nHitInfoTriggerReadout.str();
566
567 myPaveTextInfo[slot - 1][1] = "N timestamps (TRG readout): " + nHitInfoTriggerReadout.str();
568
569 std::stringstream nHitInfoTriggerDecision;
570 nHitInfoTriggerDecision << topTRGDecisionNTS[slot - 1];
571 myMultiGraphTitle[slot - 1] = myMultiGraphTitle[slot - 1] + " / " + nHitInfoTriggerDecision.str();
572
573 myPaveTextInfo[slot - 1][2] = "N timestamps TRG online: " + nHitInfoTriggerDecision.str();
574
575 std::stringstream nHitInfoISimTriggerDecisionMainReadout;
576 nHitInfoISimTriggerDecisionMainReadout << topTRGISimMRODecisionNTS[slot - 1];
577 myMultiGraphTitle[slot - 1] = myMultiGraphTitle[slot - 1] + " / " + nHitInfoISimTriggerDecisionMainReadout.str();
578
579 myPaveTextInfo[slot - 1][3] = "N timestamps TRG ISim (all, TOP readout): " + nHitInfoISimTriggerDecisionMainReadout.str();
580
581 std::stringstream nHitInfoISimTriggerDecisionTriggerReadout;
582 nHitInfoISimTriggerDecisionTriggerReadout << topTRGISimWFRODecisionNTS[slot - 1];
583 myMultiGraphTitle[slot - 1] = myMultiGraphTitle[slot - 1] + " / " + nHitInfoISimTriggerDecisionTriggerReadout.str();
584
585 myPaveTextInfo[slot - 1][4] = "N timestamps TRG ISim (all, TRG readout): " + nHitInfoISimTriggerDecisionTriggerReadout.str();
586
587 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + ", t0 online/ISim main/TRG: ";
588
589 if (topTRGDecisionPresent[slot - 1]) {
590 std::stringstream nTimingInfoTriggerDecision;
591 nTimingInfoTriggerDecision << topTRGDecisionTiming[slot - 1] / 2;
592 std::stringstream nNumberInfoTriggerDecision;
593 nNumberInfoTriggerDecision << topTRGDecisionNumber[slot - 1];
594 myPaveTextInfo[slot - 1][5] = "Number of online TRG decisions: " + nNumberInfoTriggerDecision.str() + ", most recent t0: " +
595 nTimingInfoTriggerDecision.str();
596 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + nNumberInfoTriggerDecision.str() + " ( ";
597 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + nTimingInfoTriggerDecision.str() + " ) / ";
598 } else {
599 myPaveTextInfo[slot - 1][5] = "No online TRG decisions";
600 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + "none / ";
601 }
602
603 if (topTRGISimMRODecisionPresent[slot - 1]) {
604 std::stringstream nTimingInfoTriggerDecision;
605 nTimingInfoTriggerDecision << topTRGISimMRODecisionTiming[slot - 1];
606 std::stringstream nNumberInfoTriggerDecision;
607 nNumberInfoTriggerDecision << topTRGISimMRODecisionNumber[slot - 1];
608 myPaveTextInfo[slot - 1][6] = "Number of ISim TOP readout TRG decisions: " + nNumberInfoTriggerDecision.str() + ", most recent t0: "
609 + nTimingInfoTriggerDecision.str();
610 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + nNumberInfoTriggerDecision.str() + " ( ";
611 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + nTimingInfoTriggerDecision.str() + " ) / ";
612 } else {
613 myPaveTextInfo[slot - 1][6] = "No iSim TOP readout TRG decisions";
614 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + " none / ";
615 }
616
617 if (topTRGISimWFRODecisionPresent[slot - 1]) {
618 std::stringstream nTimingInfoTriggerDecision;
619 nTimingInfoTriggerDecision << topTRGISimWFRODecisionTiming[slot - 1];
620 std::stringstream nNumberInfoTriggerDecision;
621 nNumberInfoTriggerDecision << topTRGISimWFRODecisionNumber[slot - 1];
622 myPaveTextInfo[slot - 1][7] = "Number of ISim TRG readout TRG decisions: " + nNumberInfoTriggerDecision.str() + ", most recent t0: "
623 + nTimingInfoTriggerDecision.str();
624 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + nNumberInfoTriggerDecision.str() + " ( ";
625 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + nTimingInfoTriggerDecision.str() + " )";
626 } else {
627 myPaveTextInfo[slot - 1][7] = "No iSim TRG readout TRG decisions";
628 // myMultiGraphTitle[slot-1] = myMultiGraphTitle[slot-1] + "none";
629 }
630
631 myMultiGraphTitle[slot - 1] = myMultiGraphTitle[slot - 1] + "; Clock cycle (8ns units); Hit time (2ns units)";
632 m_myMultiGraph[slot - 1]->SetTitle(myMultiGraphTitle[slot - 1].c_str());
633
634 std::stringstream slotInfo;
635 slotInfo << slot;
636 std::string name = "c_" + slotInfo.str();
637 std::string title = "Main readout hits (red) and trigger readout timestamps (blue/black) for slot " + slotInfo.str();
638 m_myCanvas[slot - 1] = new TCanvas(name.c_str(), title.c_str(), canvasXMin, canvasYMin, canvasXSize, canvasYSize);
639 if (m_shiftCanvas) {
640 canvasXMin = canvasXMin + m_xShiftCanvas;
641 if (canvasXMin >= 1000) {
642 canvasXMin = m_canvasXMin;
643 canvasYMin = canvasYMin + m_yShiftCanvas;
644 if (canvasYMin >= 700) {
645 canvasYMin = m_canvasYMin;
646 }
647 }
648 }
649
650 m_myMultiGraph[slot - 1]->Draw("AP");
651
652 TAxis* xAxis = m_myMultiGraph[slot - 1]->GetXaxis();
653
654 if (m_plottingMode == 0) {
655 m_myMultiGraph[slot - 1]->SetMinimum(m_yMin);
656 m_myMultiGraph[slot - 1]->SetMaximum(m_yMax);
657 xAxis->SetLimits(m_xMin, m_xMax);
658 } else if (m_plottingMode == 1) {
659 m_myMultiGraph[slot - 1]->SetMinimum(std::min(yMinMRO[slot - 1], yMinWFRO[slot - 1]));
660 m_myMultiGraph[slot - 1]->SetMaximum(std::max(yMaxMRO[slot - 1], yMaxWFRO[slot - 1]));
661 xAxis->SetLimits(std::min(xMinMRO[slot - 1], xMinWFRO[slot - 1]), std::max(xMaxMRO[slot - 1], xMaxWFRO[slot - 1]));
662 } else if (m_plottingMode == 2) {
663 m_myMultiGraph[slot - 1]->SetMinimum(yMin);
664 m_myMultiGraph[slot - 1]->SetMaximum(yMax);
665 xAxis->SetLimits(xMin, xMax);
666 } else if (m_plottingMode == 3) {
667 m_myMultiGraph[slot - 1]->SetMinimum(yMin);
668 m_myMultiGraph[slot - 1]->SetMaximum(yMax);
669 xAxis->SetLimits(m_xMin, xMax);
670 } else if (m_plottingMode == 4) {
671 m_myMultiGraph[slot - 1]->SetMinimum(yMin);
672 m_myMultiGraph[slot - 1]->SetMaximum(yMax);
673 xAxis->SetLimits(m_xMin, m_xMax);
674 } else {
675 m_myMultiGraph[slot - 1]->SetMinimum(0);
676 m_myMultiGraph[slot - 1]->SetMaximum(MAX_TIMESTAMP_RANGE);
677 xAxis->SetLimits(0, MAX_NUMBER_OF_CLOCK_CYCLES);
678 }
679
680 m_myMultiGraph[slot - 1]->Draw("AP");
681 m_myCanvas[slot - 1]->SetGridx(m_showGridx);
682 m_myCanvas[slot - 1]->SetGridy(m_showGridy);
683
684 // m_myPaveText[slot-1]->AddText(myPaveTextInfo[slot-1][0].c_str());
685 // m_myPaveText[slot-1]->AddText(myPaveTextInfo[slot-1][1].c_str());
686 // m_myPaveText[slot-1]->AddText(myPaveTextInfo[slot-1][2].c_str());
687 // m_myPaveText[slot-1]->AddText(myPaveTextInfo[slot-1][3].c_str());
688 // m_myPaveText[slot-1]->AddText(myPaveTextInfo[slot-1][4].c_str());
689 m_myPaveText[slot - 1]->AddText(myPaveTextInfo[slot - 1][5].c_str());
690 m_myPaveText[slot - 1]->AddText(myPaveTextInfo[slot - 1][6].c_str());
691 m_myPaveText[slot - 1]->AddText(myPaveTextInfo[slot - 1][7].c_str());
692
693 m_myPaveText[slot - 1]->AddText(topTRGDecisionText[slot - 1].c_str());
694 m_myPaveText[slot - 1]->AddText(topTRGIsimMRODecisionText[slot - 1].c_str());
695 m_myPaveText[slot - 1]->AddText(topTRGIsimWFRODecisionText[slot - 1].c_str());
696
697 m_myPaveText[slot - 1]->SetBorderSize(1);
698 // m_myPaveText[slot-1]->SetFillColor(19);
699 m_myPaveText[slot - 1]->SetFillStyle(0);
700 m_myPaveText[slot - 1]->SetTextFont(40);
701 m_myPaveText[slot - 1]->SetTextAlign(12);
702 m_myPaveText[slot - 1]->Draw();
703
704 m_myCanvas[slot - 1]->Update();
705
706 }
707 }
708
709 // if (!oldROOTDir) oldROOTDir->cd();
710}
711
713{
714 // oldROOTDir = gDirectory;
715 // myROOTDir->cd();
716
717 // if (!oldROOTDir) oldROOTDir->cd();
718}
719
720//TRGTOPWaveformPlotterModule::~TRGTOPWaveformPlotterModule()
721//{
722//}
723
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Example Detector.
TCanvas * m_myCanvas[NUMBER_OF_TOP_SLOTS]
TDirectory.
virtual void initialize() override
initialize
virtual void terminate() override
terminate
virtual void beginRun() override
begin Run
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.