forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleEventDisplayGUI.cxx
More file actions
1251 lines (1087 loc) · 42.1 KB
/
SimpleEventDisplayGUI.cxx
File metadata and controls
1251 lines (1087 loc) · 42.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <fmt/format.h>
#include <iostream>
#include <fstream>
#include <memory>
#include <unistd.h>
#include <string_view>
#include <filesystem>
#include "TGFrame.h"
#include "TGTextEntry.h"
#include "TGLabel.h"
#include "TGButton.h"
#include "TGNumberEntry.h"
#include "TGButtonGroup.h"
#include "TQObject.h"
#include "TH2Poly.h"
#include "TPolyMarker.h"
#include "TLine.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TFile.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TObjArray.h"
#include "TROOT.h"
#include "TMath.h"
#include "TApplication.h"
#include <fairlogger/Logger.h>
#include "GPUTPCGeometry.h"
#include "TPCBase/Mapper.h"
#include "TPCBase/CalDet.h"
#include "TPCBase/CalArray.h"
#include "TPCBase/Painter.h"
#include "DataFormatsTPC/Constants.h"
#include "TPCMonitor/SimpleEventDisplayGUI.h"
using namespace o2::tpc;
namespace fs = std::filesystem;
//__________________________________________________________________________
void SimpleEventDisplayGUI::monitorGui()
{
float xsize = 160;
float ysize = 25;
float yoffset = 10;
float ysize_dist = 2;
float mainx = xsize + 2 * 10;
float mainy = 335;
int ycount = 0;
float currentY = yoffset + ycount * (ysize_dist + ysize);
auto nextY = [&ycount, ¤tY, yoffset, ysize, ysize_dist]() {
++ycount;
currentY = yoffset + ycount * (ysize_dist + ysize);
};
TGMainFrame* mFrameMain = new TGMainFrame(gClient->GetRoot(), mainx, mainy, kMainFrame | kVerticalFrame);
mFrameMain->SetLayoutBroken(kTRUE);
mFrameMain->SetCleanup(kDeepCleanup);
TGCompositeFrame* mContRight = new TGCompositeFrame(mFrameMain, xsize + 5, mainy, kVerticalFrame | kFixedWidth | kFitHeight);
mFrameMain->AddFrame(mContRight, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY | kLHintsExpandX, 3, 5, 3, 3));
//---------------------------
TGTextButton* mFrameNextEvent = new TGTextButton(mContRight, "&Next Event");
mContRight->AddFrame(mFrameNextEvent, new TGLayoutHints(kLHintsExpandX));
mFrameNextEvent->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "next(=-1)");
mFrameNextEvent->SetTextColor(200);
mFrameNextEvent->SetToolTipText("Go to next event");
mFrameNextEvent->MoveResize(10, currentY, xsize, (unsigned int)ysize);
nextY();
//---------------------------
TGTextButton* mFramePreviousEvent = new TGTextButton(mContRight, "&Previous Event");
mContRight->AddFrame(mFramePreviousEvent, new TGLayoutHints(kLHintsExpandX));
if (mRunMode == RunMode::Online) {
mFramePreviousEvent->SetState(kButtonDisabled);
}
mFramePreviousEvent->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "next(=-2)");
mFramePreviousEvent->SetTextColor(200);
mFramePreviousEvent->SetToolTipText("Go to previous event");
mFramePreviousEvent->MoveResize(10, currentY, xsize, (unsigned int)ysize);
nextY();
//---------------------------
TGTextButton* mGoToEvent = new TGTextButton(mContRight, "&Go to event");
mContRight->AddFrame(mGoToEvent, new TGLayoutHints(kLHintsNormal));
mGoToEvent->SetTextColor(200);
mGoToEvent->SetToolTipText("Go to event");
mGoToEvent->MoveResize(10, currentY, 0.65 * xsize, (unsigned int)ysize);
mGoToEvent->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "callEventNumber()");
//
auto* ftbuf = new TGTextBuffer(10);
ftbuf->AddText(0, "0");
mEventNumber = new TGTextEntry(mContRight, ftbuf);
mContRight->AddFrame(mEventNumber, new TGLayoutHints(kFitHeight));
mEventNumber->MoveResize(0.7 * xsize, currentY, 0.3 * xsize, (unsigned int)ysize);
mEventNumber->SetAlignment(kTextRight);
nextY();
//---------------------------
TGTextButton* mApplySignalThreshold = new TGTextButton(mContRight, "&Apply Threshold");
mContRight->AddFrame(mApplySignalThreshold, new TGLayoutHints(kLHintsNormal));
mApplySignalThreshold->SetTextColor(200);
mApplySignalThreshold->SetToolTipText("Apply Threshold");
mApplySignalThreshold->MoveResize(10, currentY, 0.65 * xsize, (unsigned int)ysize);
mApplySignalThreshold->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "applySignalThreshold()");
auto* signalThresholdBuf = new TGTextBuffer(10);
signalThresholdBuf->AddText(0, "0");
mSignalThresholdValue = new TGTextEntry(mContRight, signalThresholdBuf);
mSignalThresholdValue->MoveResize(0.7 * xsize, currentY, 0.3 * xsize, (unsigned int)ysize);
mSignalThresholdValue->SetAlignment(kTextRight);
mSignalThresholdValue->Connect("ReturnPressed()", "o2::tpc::SimpleEventDisplayGUI", this, "applySignalThreshold()");
nextY();
//---------------------------
mCheckSingleTB = new TGCheckButton(mContRight, "One TB");
mContRight->AddFrame(mCheckSingleTB, new TGLayoutHints(kLHintsExpandX));
mCheckSingleTB->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "toggleSingleTimeBin()");
mCheckSingleTB->SetTextColor(200);
mCheckSingleTB->SetToolTipText("Show single time bin");
mCheckSingleTB->MoveResize(10, currentY, 0.5 * xsize, (unsigned int)ysize);
mCheckSingleTB->SetDown(0);
mSelTimeBin = new TGNumberEntry(mContRight, mEvDisp.getFirstTimeBin(), 6, 999, TGNumberFormat::kNESInteger,
TGNumberFormat::kNEAPositive,
TGNumberFormat::kNELLimitMinMax,
mEvDisp.getFirstTimeBin(), mEvDisp.getLastTimeBin());
mSelTimeBin->MoveResize(0.55 * xsize, currentY, 0.45 * xsize, (unsigned int)ysize);
mSelTimeBin->Connect("ValueSet(Long_t)", "o2::tpc::SimpleEventDisplayGUI", this, "selectTimeBin()");
(mSelTimeBin->GetNumberEntry())->Connect("ReturnPressed()", "o2::tpc::SimpleEventDisplayGUI", this, "selectTimeBin()");
nextY();
//---------------------------
mCheckFFT = new TGCheckButton(mContRight, "Show FFT");
mContRight->AddFrame(mCheckFFT, new TGLayoutHints(kLHintsExpandX));
mCheckFFT->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "toggleFFT()");
mCheckFFT->SetTextColor(200);
mCheckFFT->SetToolTipText("Switch on FFT calculation");
mCheckFFT->MoveResize(10, currentY, xsize, (unsigned int)ysize);
mCheckFFT->SetDown(0);
toggleFFT();
nextY();
//---------------------------
mCheckOccupancy = new TGCheckButton(mContRight, "Show Occupancy");
mContRight->AddFrame(mCheckOccupancy, new TGLayoutHints(kLHintsExpandX));
mCheckOccupancy->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "toggleOccupancy()");
mCheckOccupancy->SetTextColor(200);
mCheckOccupancy->SetToolTipText("Switch on Occupancy calculation");
mCheckOccupancy->MoveResize(10, currentY, xsize, (unsigned int)ysize);
mCheckOccupancy->SetDown(0);
toggleOccupancy();
nextY();
//---------------------------
mCheckPadTime = new TGCheckButton(mContRight, "Show PadTime");
mContRight->AddFrame(mCheckPadTime, new TGLayoutHints(kLHintsExpandX));
mCheckPadTime->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "togglePadTime()");
mCheckPadTime->SetTextColor(200);
mCheckPadTime->SetToolTipText("Switch on PadTime calculation");
mCheckPadTime->MoveResize(10, currentY, xsize, (unsigned int)ysize);
mCheckPadTime->SetDown(0);
nextY();
//---------------------------
mCheckShowClusters = new TGCheckButton(mContRight, "Overlay clusters");
mContRight->AddFrame(mCheckShowClusters, new TGLayoutHints(kLHintsExpandX));
mCheckShowClusters->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "toggleClusters()");
mCheckShowClusters->SetTextColor(200);
mCheckShowClusters->SetToolTipText("Switch on ShowClusters calculation");
mCheckShowClusters->MoveResize(10, currentY, xsize, (unsigned int)ysize);
mCheckShowClusters->SetDown(0);
mCheckShowClusters->SetEnabled(kFALSE);
nextY();
//---------------------------
mFlagGroup = new TGVButtonGroup(mContRight, "Cl Flags");
auto hframe = new TGHorizontalFrame(mFlagGroup);
const std::string flagTips[NCheckClFlags] = {"Golden", "Split Pad", "Split Time", "Edge", "Single Pad and/or Time"};
for (int iCheck = 0; iCheck < NCheckClFlags; ++iCheck) {
mCheckClFlags[iCheck] = new TGCheckButton(hframe, "", 10000 + iCheck);
mCheckClFlags[iCheck]->SetToolTipText(flagTips[iCheck].data());
mCheckClFlags[iCheck]->SetDown(1);
mCheckClFlags[iCheck]->SetEnabled(kFALSE);
mCheckClFlags[iCheck]->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "showClusters(=-1,-1)");
hframe->AddFrame(mCheckClFlags[iCheck], new TGLayoutHints(kLHintsExpandX));
}
mFlagGroup->AddFrame(hframe, new TGLayoutHints(kLHintsExpandX));
mFlagGroup->Show();
mFlagGroup->MoveResize(10, currentY, xsize, (unsigned int)2 * ysize);
mContRight->AddFrame(mFlagGroup, new TGLayoutHints(kLHintsExpandX));
mFlagGroup->SetState(kFALSE);
nextY();
nextY();
//---------------------------
TGTextButton* mFrameExit = new TGTextButton(mContRight, "Exit ROOT");
mContRight->AddFrame(mFrameExit, new TGLayoutHints(kLHintsExpandX));
mFrameExit->Connect("Clicked()", "o2::tpc::SimpleEventDisplayGUI", this, "exitRoot()");
mFrameExit->SetTextColor(200);
mFrameExit->SetToolTipText("Exit the ROOT process");
mFrameExit->MoveResize(10, currentY, xsize, (unsigned int)ysize);
nextY();
//---------------------------
mFrameMain->MapSubwindows();
mFrameMain->MapWindow();
mFrameMain->SetWindowName("OM");
mFrameMain->MoveResize(50, 50, (unsigned int)mainx, (unsigned int)currentY + 20);
mFrameMain->Move(4 * 400 + 10, 10);
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::toggleFFT()
{
if (mCheckFFT->IsDown()) {
if (gROOT->GetListOfCanvases()->FindObject("SigIFFT")) {
return;
}
// FFT canvas
const int w = 400;
const int h = 400;
const int hOff = 60;
const int vOff = 2;
new TCanvas("SigIFFT", "SigIFFT", -3 * (w + vOff), 0 * h, w, h);
new TCanvas("SigOFFT", "SigOFFT", -3 * (w + vOff), 1 * h + hOff, w, h);
} else {
delete gROOT->GetListOfCanvases()->FindObject("SigIFFT");
delete gROOT->GetListOfCanvases()->FindObject("SigOFFT");
delete mHFFTI;
delete mHFFTO;
mHFFTI = mHFFTO = nullptr;
}
}
//______________________________________________________________________________
void SimpleEventDisplayGUI::initOccupancyHists()
{
const int w = 400;
const int h = 400;
const int hOff = 60;
const int vOff = 2;
TCanvas* c = nullptr;
if (mShowSides) {
// histograms and canvases for occupancy values A-Side
c = new TCanvas("OccupancyValsA", "OccupancyValsA", 0 * w - 1, 0 * h, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"selectSectorExec(int,int,int,TObject*)");
mHOccupancyA = new TH2F("hOccupancyValsA", "Occupancy Values Side A;x (cm);y (cm)", 330, -250, 250, 330, -250, 250);
mHOccupancyA->SetStats(kFALSE);
mHOccupancyA->SetUniqueID(0); // A-Side
mHOccupancyA->Draw("colz");
painter::drawSectorsXY(Side::A);
// histograms and canvases for occupancy values C-Side
c = new TCanvas("OccupancyValsC", "OccupancyValsC", 0 * w - 1, 1 * h + hOff, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"selectSectorExec(int,int,int,TObject*)");
mHOccupancyC = new TH2F("hOccupancyValsC", "Occupancy Values Side C;x (cm);y (cm)", 330, -250, 250, 330, -250, 250);
mHOccupancyC->SetStats(kFALSE);
mHOccupancyC->SetUniqueID(1); // C-Side
mHOccupancyC->Draw("colz");
painter::drawSectorsXY(Side::C);
}
// histograms and canvases for occupancy values IROC
c = new TCanvas("OccupancyValsI", "OccupancyValsI", -1 * (w + vOff), 0 * h, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"drawPadSignal(int,int,int,TObject*)");
mHOccupancyIROC = new TH2F("hOccupancyValsIROC", "Occupancy Values IROC;row;pad", 63, 0, 63, 108, -54, 54);
mHOccupancyIROC->SetDirectory(nullptr);
mHOccupancyIROC->SetStats(kFALSE);
mHOccupancyIROC->Draw("colz");
// histograms and canvases for occupancy values OROC
c = new TCanvas("OccupancyValsO", "OccupancyValsO", -1 * (w + vOff), 1 * h + hOff, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"drawPadSignal(int,int,int,TObject*)");
mHOccupancyOROC = new TH2F("hOccupancyValsOROC", "Occupancy Values OROC;row;pad", 89, 0, 89, 140, -70, 70);
mHOccupancyOROC->SetDirectory(nullptr);
mHOccupancyOROC->SetStats(kFALSE);
mHOccupancyOROC->Draw("colz");
fillHists(0, Occupancy);
}
void SimpleEventDisplayGUI::deleteOccupancyHists()
{
delete gROOT->GetListOfCanvases()->FindObject("OccupancyValsA");
delete mHOccupancyA;
mHOccupancyA = nullptr;
delete gROOT->GetListOfCanvases()->FindObject("OccupancyValsC");
delete mHOccupancyC;
mHOccupancyC = nullptr;
delete gROOT->GetListOfCanvases()->FindObject("OccupancyValsO");
delete mHOccupancyOROC;
mHOccupancyOROC = nullptr;
delete gROOT->GetListOfCanvases()->FindObject("OccupancyValsI");
delete mHOccupancyIROC;
mHOccupancyIROC = nullptr;
delete gROOT->GetListOfCanvases()->FindObject("hOccupancyValsA");
delete gROOT->GetListOfCanvases()->FindObject("hOccupancyValsC");
delete gROOT->GetListOfCanvases()->FindObject("hOccupancyValsIROC");
delete gROOT->GetListOfCanvases()->FindObject("hOccupancyValsOROC");
}
void SimpleEventDisplayGUI::initPadTimeHists()
{
// histograms and canvases for pad vs. time values IROC
const int w = 400;
const int h = 400;
const int hOff = 60;
const int vOff = 4;
TCanvas* c = nullptr;
const Int_t firstTimeBin = mEvDisp.getFirstTimeBin();
const Int_t lastTimeBin = mEvDisp.getLastTimeBin();
const Int_t nTimeBins = mEvDisp.getLastTimeBin() - mEvDisp.getFirstTimeBin();
c = new TCanvas("PadTimeValsI", "PadTimeValsI", -3 * (w + vOff), 0 * h, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"drawPadSignal(int,int,int,TObject*)");
mHPadTimeIROC = new TH2F("hPadTimeValsI", "PadTime Values IROC;time bin;pad", nTimeBins, firstTimeBin, lastTimeBin, 108, -54, 54);
// mHPadTimeIROC->SetDirectory(nullptr);
mHPadTimeIROC->SetStats(kFALSE);
mHPadTimeIROC->Draw("colz");
if (!mClustersIROC) {
mClustersIROC = new TPolyMarker;
mClustersIROC->SetMarkerSize(1);
mClustersIROC->SetMarkerStyle(29);
mClustersIROC->SetMarkerColor(kMagenta);
mClustersIROC->Draw();
}
// histograms and canvases for pad vs. time values OROC
c = new TCanvas("PadTimeValsO", "PadTimeValsO", -3 * (w + vOff), 1 * h + hOff, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"drawPadSignal(int,int,int,TObject*)");
mHPadTimeOROC = new TH2F("hPadTimeValsO", "PadTime Values OROC;time bin;pad", nTimeBins, firstTimeBin, lastTimeBin, 140, -70, 70);
// mHPadTimeOROC->SetDirectory(nullptr);
mHPadTimeOROC->SetStats(kFALSE);
mHPadTimeOROC->Draw("colz");
if (!mClustersOROC) {
mClustersOROC = new TPolyMarker;
mClustersOROC->SetMarkerSize(1);
mClustersOROC->SetMarkerStyle(29);
mClustersOROC->SetMarkerColor(kMagenta);
mClustersOROC->Draw();
}
}
void SimpleEventDisplayGUI::deletePadTimeHists()
{
delete gROOT->GetListOfCanvases()->FindObject("PadTimeValsO");
delete mHPadTimeOROC;
mHPadTimeOROC = nullptr;
delete gROOT->GetListOfCanvases()->FindObject("PadTimeValsI");
delete mHPadTimeIROC;
mHPadTimeIROC = nullptr;
delete gROOT->GetListOfCanvases()->FindObject("hPadTimeValsIROC");
delete gROOT->GetListOfCanvases()->FindObject("hPadTimeValsOROC");
}
void SimpleEventDisplayGUI::initSingleTBHists()
{
// histograms and canvases for pad vs. time values IROC
const int w = 400;
const int h = 400;
const int hOff = 60;
const int vOff = 4;
TCanvas* c = nullptr;
const Int_t firstTimeBin = mEvDisp.getFirstTimeBin();
const Int_t lastTimeBin = mEvDisp.getLastTimeBin();
const Int_t nTimeBins = mEvDisp.getLastTimeBin() - mEvDisp.getFirstTimeBin();
c = new TCanvas("SingleTB", "SingleTB", -3 * (w + vOff), 1 * h + hOff, 1.8 * w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"drawPadSignal(int,int,int,TObject*)");
mSectorPolyTimeBin = painter::makeSectorHist("hSingleTB");
// mHPadTimeIROC->SetDirectory(nullptr);
mSectorPolyTimeBin->SetStats(kFALSE);
mSectorPolyTimeBin->Draw("colz");
if (!mClustersRowPad) {
mClustersRowPad = new TPolyMarker;
mClustersRowPad->SetMarkerSize(1);
mClustersRowPad->SetMarkerStyle(29);
mClustersRowPad->SetMarkerColor(kMagenta);
}
mClustersRowPad->Draw();
}
void SimpleEventDisplayGUI::deleteSingleTBHists()
{
delete gROOT->GetListOfCanvases()->FindObject("SingleTB");
delete mSectorPolyTimeBin;
mSectorPolyTimeBin = nullptr;
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::togglePadTime()
{
if (mCheckPadTime->IsDown()) {
initPadTimeHists();
mCheckShowClusters->SetEnabled(kTRUE);
} else {
deletePadTimeHists();
mCheckShowClusters->SetEnabled(kFALSE);
}
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::toggleOccupancy()
{
if (mCheckOccupancy->IsDown()) {
initOccupancyHists();
} else {
deleteOccupancyHists();
}
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::toggleSingleTimeBin()
{
if (mCheckSingleTB->IsDown()) {
initSingleTBHists();
selectTimeBin();
} else {
deleteSingleTBHists();
if (mClustersRowPad) {
mClustersRowPad->SetPolyMarker(0);
}
}
}
//______________________________________________________________________________
void SimpleEventDisplayGUI::toggleClusters()
{
if (mCheckShowClusters->IsDown()) {
if (mTPCclusterReader.getTreeSize() > 0) {
return;
}
fs::path p{mInputFileInfo};
std::string clusterFile = fmt::format("{}/tpc-native-clusters.root", p.parent_path().c_str());
if (!fs::exists(clusterFile)) {
LOGP(warn, "Clusters file '{}' does not exist, trying local 'tpc-native-clusters.root'", clusterFile);
clusterFile = "tpc-native-clusters.root";
if (!fs::exists(clusterFile)) {
LOGP(error, "Clusters file '{}' does not exist, can't load clusters", clusterFile);
return;
}
}
LOGP(info, "loading clusters from file '{}'", clusterFile);
mTPCclusterReader.init(clusterFile.data());
gROOT->cd();
const auto presentEventNumber = mEvDisp.getPresentEventNumber();
fillClusters(presentEventNumber);
mFlagGroup->SetState(kTRUE);
for (int iCheck = 0; iCheck < NCheckClFlags; ++iCheck) {
mCheckClFlags[iCheck]->SetEnabled(kTRUE);
}
} else {
if (mClustersIROC) {
mClustersIROC->SetPolyMarker(0);
mClustersOROC->SetPolyMarker(0);
}
mFlagGroup->SetState(kFALSE);
for (int iCheck = 0; iCheck < NCheckClFlags; ++iCheck) {
mCheckClFlags[iCheck]->SetEnabled(kFALSE);
}
}
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::exitRoot()
{
mStop = true;
gApplication->Terminate();
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::update(TString clist)
{
std::unique_ptr<TObjArray> arr(clist.Tokenize(";"));
for (auto o : *arr) {
auto c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(o->GetName());
if (c) {
c->Modified();
c->Update();
}
}
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::resetHists(int type, HistogramType histogramType)
{
if (!type) {
switch (histogramType) {
case MaxValues:
if (mHMaxA) {
mHMaxA->Reset();
}
if (mHMaxC) {
mHMaxC->Reset();
}
break;
case Occupancy:
if (mHOccupancyA) {
mHOccupancyA->Reset();
}
if (mHOccupancyC) {
mHOccupancyC->Reset();
}
break;
default:
break;
}
}
switch (histogramType) {
case MaxValues:
if (mHMaxIROC) {
mHMaxIROC->Reset();
}
if (mHMaxOROC) {
mHMaxOROC->Reset();
}
break;
case Occupancy:
if (mHOccupancyIROC) {
mHOccupancyIROC->Reset();
}
if (mHOccupancyOROC) {
mHOccupancyOROC->Reset();
}
break;
default:
break;
}
}
//__________________________________________________________________________
TH1* SimpleEventDisplayGUI::getBinInfoXY(int& binx, int& biny, float& bincx, float& bincy)
{
auto pad = (TPad*)gTQSender;
TObject* select = pad->GetSelected();
if (!select) {
return nullptr;
}
if (!select->InheritsFrom("TH2")) {
pad->SetUniqueID(0);
return nullptr;
}
TH1* h = (TH1*)select;
pad->GetCanvas()->FeedbackMode(kTRUE);
const int px = pad->GetEventX();
const int py = pad->GetEventY();
const float xx = pad->AbsPixeltoX(px);
const float x = pad->PadtoX(xx);
const float yy = pad->AbsPixeltoY(py);
const float y = pad->PadtoX(yy);
if (h->InheritsFrom(TH2Poly::Class())) {
auto hPoly = (TH2Poly*)h;
binx = hPoly->GetXaxis()->FindBin(x);
biny = hPoly->GetYaxis()->FindBin(y);
bincx = hPoly->GetXaxis()->GetBinCenter(binx);
bincy = hPoly->GetYaxis()->GetBinCenter(biny);
binx = biny = hPoly->FindBin(x, y);
} else {
binx = h->GetXaxis()->FindBin(x);
biny = h->GetYaxis()->FindBin(y);
bincx = h->GetXaxis()->GetBinCenter(binx);
bincy = h->GetYaxis()->GetBinCenter(biny);
}
return h;
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::drawPadSignal(int event, int x, int y, TObject* o)
{
//
// type: name of canvas
//
// fmt::print("o: {}, type: {}, name: {}\n", (void*)o, o ? o->IsA()->GetName() : "", o ? o->GetName() : "");
if (!o) {
return;
}
// check if an event was alreay loaded
if (!mEvDisp.getNumberOfProcessedEvents()) {
return;
}
// return if mouse is pressed to allow looking at one pad
if (event != 51) {
return;
}
int binx, biny;
float bincx, bincy;
TH1* h = getBinInfoXY(binx, biny, bincx, bincy);
if (!h) {
return;
}
// fmt::print("binx {}, biny {}, cx {}, cy {}\n", binx, biny, bincx, bincy);
const auto& mapper = Mapper::instance();
// int roc = h->GetUniqueID();
int roc = mSelectedSector;
TString type;
const std::string_view objectName(o->GetName());
// for standard row vs cpad histo, is overwritte in case of TH2Poly sector histo below
int row = int(TMath::Floor(bincx));
// find pad and channel
int pad = -1;
if (objectName == "hMaxValsIROC" || objectName == "hOccupancyValsIROC") {
type = "SigI";
} else if (objectName == "hMaxValsOROC" || objectName == "hOccupancyValsOROC") {
type = "SigO";
roc += 36;
} else if (objectName == "hPadTimeValsI") {
type = "SigI";
row = h->GetUniqueID();
} else if (objectName == "hPadTimeValsO") {
type = "SigO";
row = h->GetUniqueID();
roc += 36;
} else if (objectName == "hSingleTB") {
type = "SigI";
const auto padPosSec = mapper.padPos(binx - 1);
pad = padPosSec.getPad();
row = padPosSec.getRow();
if (bincx > 133) {
type = "SigO";
roc += 36;
row -= mapper.getNumberOfRowsROC(0);
}
// fmt::print("roc {}, row {}, pad {}\n", roc, row, pad);
} else {
return;
}
const int nPads = mapper.getNumberOfPadsInRowROC(roc, row);
if (pad == -1) {
const int cpad = int(TMath::Floor(bincy));
pad = cpad + nPads / 2;
}
if (pad < 0 || pad >= (int)nPads) {
return;
}
if (row < 0 || row >= (int)mapper.getNumberOfRowsROC(roc)) {
return;
}
if (roc < 0 || roc >= (int)ROC::MaxROC) {
return;
}
const TString rocType = (roc < 36) ? "I" : "O";
// draw requested pad signal
TH1*& hFFT = (roc < 36) ? mHFFTI : mHFFTO;
TCanvas* c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(type);
TCanvas* cFFT = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(Form("%sFFT", type.Data()));
if (c) {
c->Clear();
c->cd();
TH1D* h2 = mEvDisp.makePadSignals(roc, row, pad);
if (h2) {
h2->Draw();
h2->SetStats(0);
if (cFFT) {
const bool init = (hFFT == nullptr);
const double maxTime = h2->GetNbinsX() * 200.e-6;
hFFT = h2->FFT(hFFT, "MAG M");
if (hFFT) {
hFFT->SetStats(0);
const auto nbinsx = hFFT->GetNbinsX();
auto xax = hFFT->GetXaxis();
xax->SetRange(2, nbinsx / 2);
if (init) {
xax->Set(nbinsx, xax->GetXmin() / maxTime, xax->GetXmax() / maxTime);
hFFT->SetNameTitle(Form("hFFT_%sROC", rocType.Data()), "FFT magnitude;frequency (kHz);amplitude");
}
hFFT->Scale(2. / (nbinsx - 1));
cFFT->cd();
hFFT->Draw();
}
}
}
if (mCheckSingleTB) {
TLine l;
l.SetLineColor(kRed);
const auto timeBin = mSelTimeBin->GetNumberEntry()->GetIntNumber();
h = (TH1D*)gROOT->FindObject(fmt::format("PadSignals_{}ROC", rocType.Data()).data());
if (h) {
l.DrawLine(timeBin + 0.5, h->GetMinimum(), timeBin + 0.5, h->GetMaximum());
}
}
if (mCheckPadTime && objectName.find("hPadTimeVals") == 0) {
TLine l;
l.SetLineColor(kMagenta);
const auto timeBin = bincx;
h = (TH1D*)gROOT->FindObject(fmt::format("PadSignals_{}ROC", rocType.Data()).data());
if (h) {
l.DrawLine(timeBin + 0.5, h->GetMinimum(), timeBin, h->GetMaximum());
}
}
if (mCheckShowClusters->IsDown()) {
showClusters(roc, row);
}
const auto padTimeValsName = fmt::format("PadTimeVals{}", type[type.Length() - 1]);
TCanvas* cPadTimeVals = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(padTimeValsName.data());
if (cPadTimeVals) {
h = (TH1D*)gROOT->FindObject(("h" + padTimeValsName).data());
if (h) {
cPadTimeVals->cd();
delete cPadTimeVals->GetListOfPrimitives()->FindObject("TLine");
TLine l;
l.SetLineColor(kRed);
const auto timeBin = mSelTimeBin->GetNumberEntry()->GetIntNumber();
l.DrawLine(timeBin + 0.5, h->GetYaxis()->GetXmin(), timeBin + 0.5, h->GetYaxis()->GetXmax());
}
}
update(Form("%s;%sFFT;PadTimeVals%s;SingleTB", type.Data(), type.Data(), rocType.Data()));
}
// printf("bin=%03d.%03d(%03d)[%05d], name=%s, ROC=%02d content=%.1f, ev: %d\n",row,pad,cpad,chn,h->GetName(), roc, h->GetBinContent(binx,biny), event);
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::fillHists(int type, HistogramType histogramType)
{
//
// type: 0 fill side and sector, 1: fill sector only
//
const auto& mapper = Mapper::instance();
float kEpsilon = 0.000000000001;
CalPad* pad = histogramType == MaxValues ? mEvDisp.getCalPadMax() : mEvDisp.getCalPadOccupancy();
TH2F* hSide = nullptr;
TH2F* hROC = nullptr;
resetHists(type, histogramType);
const int runNumber = TString(gSystem->Getenv("RUN_NUMBER")).Atoi();
// const int eventNumber = mEvDisp.getNumberOfProcessedEvents() - 1;
const int eventNumber = mEvDisp.getPresentEventNumber();
const bool eventComplete = mEvDisp.isPresentEventComplete();
for (int iROC = 0; iROC < 72; iROC++) {
hROC = histogramType == MaxValues ? mHMaxOROC : mHOccupancyOROC;
hSide = histogramType == MaxValues ? mHMaxC : mHOccupancyC;
if (iROC < 36) {
hROC = histogramType == MaxValues ? mHMaxIROC : mHOccupancyIROC;
}
if ((iROC % 36) < 18) {
hSide = histogramType == MaxValues ? mHMaxA : mHOccupancyA;
}
if ((iROC % 36) == (mSelectedSector % 36)) {
TString title = Form("%s Values %cROC %c%02d (%02d) TF %s%d%s", histogramType == MaxValues ? "Max" : "Occupancy", (iROC < 36) ? 'I' : 'O', (iROC % 36 < 18) ? 'A' : 'C', iROC % 18, iROC, eventComplete ? "" : "(", eventNumber, eventComplete ? "" : ")");
// TString title = Form("Max Values Run %d Event %d", runNumber, eventNumber);
if (hROC) {
hROC->SetTitle(title.Data());
}
}
auto& calRoc = pad->getCalArray(iROC);
const int nRows = mapper.getNumberOfRowsROC(iROC);
for (int irow = 0; irow < nRows; irow++) {
const int nPads = mapper.getNumberOfPadsInRowROC(iROC, irow);
for (int ipad = 0; ipad < nPads; ipad++) {
float value = calRoc.getValue(irow, ipad);
// printf("iROC: %02d, sel: %02d, row %02d, pad: %02d, value: %.5f\n", iROC, mSelectedSector, irow, ipad, value);
if (TMath::Abs(value) > kEpsilon) {
if (!type && hSide) {
const GlobalPosition2D global2D = mapper.getPadCentre(PadSecPos(Sector(iROC % 36), PadPos(irow + (iROC >= 36) * mapper.getNumberOfRowsROC(0), ipad)));
int binx = 1 + TMath::Nint((global2D.X() + 250.) * hSide->GetNbinsX() / 500.);
int biny = 1 + TMath::Nint((global2D.Y() + 250.) * hSide->GetNbinsY() / 500.);
hSide->SetBinContent(binx, biny, value);
}
const int nPads = mapper.getNumberOfPadsInRowROC(iROC, irow);
const int cpad = ipad - nPads / 2;
if ((iROC % 36 == mSelectedSector % 36) && hROC) {
// printf(" ->>> Fill: iROC: %02d, sel: %02d, row %02d, pad: %02d, value: %.5f\n", iROC, mSelectedSector, irow, ipad, value);
hROC->Fill(irow, cpad, value);
}
}
if ((iROC % 36 == mSelectedSector % 36) && hROC) {
hROC->SetUniqueID(iROC);
}
}
}
}
if (!type) {
update(histogramType == MaxValues ? "MaxValsA;MaxValsC" : "OccupancyValsA;OccupancyValsC");
}
update(histogramType == MaxValues ? "MaxValsI;MaxValsO" : "OccupancyValsI;OccupancyValsO");
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::selectSector(int sector)
{
mSelectedSector = sector % 36;
mEvDisp.setSelectedSector(mSelectedSector);
fillHists(1, MaxValues);
if (mCheckOccupancy->IsDown()) {
fillHists(1, Occupancy);
}
mEvDisp.updateSectorHists();
selectTimeBin();
}
//__________________________________________________________________________
int SimpleEventDisplayGUI::FindROCFromXY(const float x, const float y, const int side)
{
//
//
//
const auto& mapper = Mapper::instance();
float r = TMath::Sqrt(x * x + y * y);
static const float innerWall = mapper.getPadCentre(PadPos(0, 0)).X() - 5.;
static const float outerWall = mapper.getPadCentre(PadPos(151, 0)).X() + 5.;
static const float outerIROC = mapper.getPadCentre(PadPos(62, 0)).X();
static const float innerOROC = mapper.getPadCentre(PadPos(63, 0)).X();
static const float betweenROC = (outerIROC + innerOROC) / 2.;
// check radial boundary
if (r < innerWall || r > outerWall) {
return -1;
}
// check for IROC or OROC
int type = 0;
if (r > betweenROC) {
type = 1;
}
int alpha = TMath::Nint(TMath::ATan2(y, x) / TMath::Pi() * 180);
// printf("%6.3f %6.3f %03d\n",x, y, alpha);
if (alpha < 0) {
alpha += 360;
}
const int roc = alpha / 20 + side * 18 + type * 36;
return roc;
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::selectSectorExec(int event, int x, int y, TObject* o)
{
int binx, biny;
float bincx, bincy;
TH1* h = getBinInfoXY(binx, biny, bincx, bincy);
if (!h) {
return;
}
const int side = h->GetUniqueID();
const int roc = FindROCFromXY(bincx, bincy, side);
if (roc < 0) {
return;
}
const int sector = roc % 36;
std::string title("Max Values");
std::string_view name(h->GetTitle());
if (name.find("Occupancy") != std::string::npos) {
title = "Occupancy Values";
}
h->SetTitle(fmt::format("{} {}{:02d}", title, (sector < 18) ? 'A' : 'C', sector % 18).data());
if (sector != mOldHooverdSector) {
auto pad = (TPad*)gTQSender;
pad->Modified();
pad->Update();
mOldHooverdSector = sector;
}
if (event != 11) {
return;
}
// printf("selectSector: %d.%02d.%d = %02d\n", side, sector, roc < 36, roc);
selectSector(sector);
}
//__________________________________________________________________________
void SimpleEventDisplayGUI::initGUI()
{
const int w = 400;
const int h = 400;
const int hOff = 60;
const int vOff = 2;
TCanvas* c = nullptr;
if (mShowSides) {
// histograms and canvases for max values A-Side
c = new TCanvas("MaxValsA", "MaxValsA", 0 * w - 1, 0 * h, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"selectSectorExec(int,int,int,TObject*)");
mHMaxA = new TH2F("hMaxValsA", "Max Values Side A;x (cm);y (cm)", 330, -250, 250, 330, -250, 250);
mHMaxA->SetStats(kFALSE);
mHMaxA->SetUniqueID(0); // A-Side
mHMaxA->Draw("colz");
painter::drawSectorsXY(Side::A);
// histograms and canvases for max values C-Side
c = new TCanvas("MaxValsC", "MaxValsC", 0 * w - 1, 1 * h + hOff, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"selectSectorExec(int,int,int,TObject*)");
mHMaxC = new TH2F("hMaxValsC", "Max Values Side C;x (cm);y (cm)", 330, -250, 250, 330, -250, 250);
mHMaxC->SetStats(kFALSE);
mHMaxC->SetUniqueID(1); // C-Side
mHMaxC->Draw("colz");
painter::drawSectorsXY(Side::C);
}
// histograms and canvases for max values IROC
c = new TCanvas("MaxValsI", "MaxValsI", -1 * (w + vOff), 0 * h, w, h);
c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"o2::tpc::SimpleEventDisplayGUI", this,
"drawPadSignal(int,int,int,TObject*)");
mHMaxIROC = new TH2F("hMaxValsIROC", "Max Values IROC;row;pad", 63, 0, 63, 108, -54, 54);
mHMaxIROC->SetDirectory(nullptr);
mHMaxIROC->SetStats(kFALSE);
mHMaxIROC->Draw("colz");