CbmRoot
Loading...
Searching...
No Matches
CbmTimesliceManagerEditor.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau[committer] */
5
7
8#include "CbmEvent.h" // For CbmEvent
9#include "CbmTimesliceManager.h" // for CbmTimesliceManager
10#include "CbmTsEveAnimationControl.h" // for CbmTsEveAnimationControl
11#include "CbmTsEveTransparencyControl.h" // for CbmTsEveTransparencyControl
12
13#include "FairRootManager.h" // for FairRootManager
14#include "FairRunAna.h" // for FairRunAna
15#include "FairTask.h" // for FairTask
16
17#include <RtypesCore.h> // for Double_t, Int_t, UInt_t, Bool_t
18#include <TChain.h> // for TChain
19#include <TClonesArray.h> // for TClonesArray
20#include <TEveManager.h> // for TEveManager, gEve
21#include <TFile.h> // for TFile
22#include <TGButton.h> // for TGTextButton, TGCheckButton
23#include <TGComboBox.h> // for TGComboBox
24#include <TGLabel.h> // for TGLabel
25#include <TGLayout.h> // for TGLayoutHints, kLHintsExpandX
26#include <TGNumberEntry.h> // for TGNumberEntry, TGNumberFormat
27#include <TGenericClassInfo.h> // for TGenericClassInfo
28#include <TGeoManager.h> // for TGeoManager, gGeoManager
29#include <TList.h> // for TObjLink, TList
30#include <TString.h> // for TString, Form
31#include <TSystem.h> // for TSystem, gSystem
32
33#include <chrono>
34#include <iostream>
35#include <memory> // for unique_ptr
36#include <thread>
37
38class TGWindow; // lines 36-36
39class TObject; // lines 37-37
40
41#define MAXE 5000
42
43// CbmTimesliceManagerEditor
44//
45// Specialization of TGedEditor for proper update propagation to TEveManager.
46
47CbmTimesliceManagerEditor::CbmTimesliceManagerEditor(const TGWindow* p, Int_t width, Int_t height, UInt_t options,
48 Pixel_t back)
49 : TGedFrame(p, width, height, options | kVerticalFrame, back)
50 , fObject(0)
51 , fManager(CbmTimesliceManager::Instance())
52 , fCurrentEvent(0)
53 , fGlobalTransparency(nullptr)
54 , fEventTime(nullptr)
55 , fScreenshotOpt(nullptr)
56{
57 Init();
58}
59
61{
62 fManager->SwitchBackground(light_background);
63}
64
66{
67 // Forward to manager class which forwards to track display class
68 fManager->SwitchPdgColorTrack(pdg_color);
69}
70
72{
73 FairRootManager* rootManager = FairRootManager::Instance();
74 TChain* chain = rootManager->GetInChain();
75 fNbTs = chain->GetEntriesFast();
76
77 MakeTitle("CbmTimesliceManager Editor");
78 TGVerticalFrame* fInfoFrame = CreateEditorTabSubFrame("Info TS");
79 TGCompositeFrame* title1 =
80 new TGCompositeFrame(fInfoFrame, fWidth, 10, kVerticalFrame | kLHintsExpandX | kFixedWidth | kOwnBackground);
81
82 TString Infile = "Input file : ";
83 TFile* file = FairRootManager::Instance()->GetInChain()->GetFile();
84 Infile += file->GetName();
85 TGLabel* TFName = new TGLabel(title1, Infile.Data());
86 title1->AddFrame(TFName);
87
88 Int_t nodes = gGeoManager->GetNNodes();
89 TString NNodes = "No. of Nodes : ";
90 NNodes += nodes;
91 TGLabel* NoNode = new TGLabel(title1, NNodes.Data());
92 title1->AddFrame(NoNode);
93
94 UInt_t RunId = FairRunAna::Instance()->getRunId();
95 TString run = "Run Id : ";
96 run += RunId;
97 TGLabel* TRunId = new TGLabel(title1, run.Data());
98 title1->AddFrame(TRunId);
99
100 TString ntimeslices = "No of timeslices : ";
101 ntimeslices += fNbTs;
102 TGLabel* TNbTimeslices = new TGLabel(title1, ntimeslices.Data());
103 title1->AddFrame(TNbTimeslices);
104
105 TGHorizontalFrame* fTsIdx = new TGHorizontalFrame(title1);
106 TGLabel* lTsIdx = new TGLabel(fTsIdx, "Current TS:");
107 fTsIdx->AddFrame(lTsIdx, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 2, 1, 1));
108 fCurrentTimeslice = new TGNumberEntry(fTsIdx, 0., 6, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
109 TGNumberFormat::kNELLimitMinMax, 0, fNbTs);
110 fTsIdx->AddFrame(fCurrentTimeslice, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
111 fCurrentTimeslice->Connect("ValueSet(Long_t)", "CbmTimesliceManagerEditor", this, "SelectSingleTimeslice()");
112 title1->AddFrame(fTsIdx);
113
114 TGHorizontalFrame* fTsTime = new TGHorizontalFrame(title1);
115 TGLabel* TsTimeLabel = new TGLabel(fTsTime, "TS Time: ");
116 fTimesliceTime = new TGLabel(fTsTime, "");
117 fTsTime->AddFrame(TsTimeLabel);
118 fTsTime->AddFrame(fTimesliceTime);
119 title1->AddFrame(fTsTime);
120
121 TString nevent = "No of events in TS : ";
122 nevent += (Int_t)(-1);
123 fEventNb = new TGLabel(title1, nevent.Data());
124 title1->AddFrame(fEventNb);
125
126 fSelTs = new TGTextButton(title1, "Select TS");
127 fSelTs->Connect("Clicked()", "CbmTimesliceManagerEditor", this, "SelectSingleTimeslice()");
128 title1->AddFrame(fSelTs, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
129
130 fPrevTs = new TGTextButton(title1, "Prev TS");
131 fPrevTs->Connect("Clicked()", "CbmTimesliceManagerEditor", this, "PrevTimeslice()");
132 title1->AddFrame(fPrevTs, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
133
134 fNextTs = new TGTextButton(title1, "Next TS");
135 fNextTs->Connect("Clicked()", "CbmTimesliceManagerEditor", this, "NextTimeslice()");
136 title1->AddFrame(fNextTs, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
137
138
139 TGHorizontalFrame* fEvtIdx = new TGHorizontalFrame(title1);
140 TGLabel* lEvtIdx = new TGLabel(fEvtIdx, "Current Event:");
141 fEvtIdx->AddFrame(lEvtIdx, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 2, 1, 1));
142 fCurrentEvent = new TGNumberEntry(fEvtIdx, 0., 6, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
143 TGNumberFormat::kNELLimitMinMax, 0, -1);
144 fEvtIdx->AddFrame(fCurrentEvent, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
145 fCurrentTimeslice->Connect("ValueSet(Long_t)", "CbmTimesliceManagerEditor", this, "SelectSingleTimeslice()");
146 title1->AddFrame(fEvtIdx);
147
148
149 TGHorizontalFrame* fEvtTime = new TGHorizontalFrame(title1);
150 TGLabel* EventTimeLabel = new TGLabel(fEvtTime, "Event Time: ");
151 fEventTime = new TGLabel(fEvtTime, "");
152 fEvtTime->AddFrame(EventTimeLabel);
153 fEvtTime->AddFrame(fEventTime);
154 title1->AddFrame(fEvtTime);
155
156 fUpdateEvent = new TGTextButton(title1, "Update Event");
157 fUpdateEvent->Connect("Clicked()", "CbmTimesliceManagerEditor", this, "SelectSingleEvent()");
158 title1->AddFrame(fUpdateEvent, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
159
160 fPrevEvent = new TGTextButton(title1, "Prev Event");
161 fPrevEvent->Connect("Clicked()", "CbmTimesliceManagerEditor", this, "PrevEvent()");
162 title1->AddFrame(fPrevEvent, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
163
164 fNextEvent = new TGTextButton(title1, "Next Event");
165 fNextEvent->Connect("Clicked()", "CbmTimesliceManagerEditor", this, "NextEvent()");
166 title1->AddFrame(fNextEvent, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
167
169 fPrevTs->SetEnabled(kFALSE);
170 fNextTs->SetEnabled(kFALSE);
171
173 fUpdateEvent->SetEnabled(kFALSE);
174 fPrevEvent->SetEnabled(kFALSE);
175 fNextEvent->SetEnabled(kFALSE);
176
177
178 fInfoFrame->AddFrame(title1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
179
180 //=============== graphics =============================
181 TGVerticalFrame* scene_conf = CreateEditorTabSubFrame("Graphics");
182 // TGHorizontalFrame* transparency_frame = new TGHorizontalFrame(scene_conf); /// PAL: Unused in FairRoot original?!?
183
184 std::unique_ptr<CbmTsEveTransparencyControl> transparency(
185 new CbmTsEveTransparencyControl(scene_conf, "Global transparency"));
186 scene_conf->AddFrame(transparency.release(), new TGLayoutHints(kLHintsNormal, 5, 5, 1, 1));
187
188 TGCheckButton* backgroundButton = new TGCheckButton(scene_conf, "Light background");
189 scene_conf->AddFrame(backgroundButton, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
190 backgroundButton->Connect("Toggled(Bool_t)", this->ClassName(), this, "SwitchBackground(Bool_t)");
191
192 TGCheckButton* pdgColorTrackButton = new TGCheckButton(scene_conf, "Track w/ PDG color");
193 scene_conf->AddFrame(pdgColorTrackButton, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
194 pdgColorTrackButton->Connect("Toggled(Bool_t)", this->ClassName(), this, "SwitchPdgColorTrack(Bool_t)");
195
196 TGGroupFrame* frame_screenshot = new TGGroupFrame(scene_conf, "Screenshot");
197 frame_screenshot->SetTitlePos(TGGroupFrame::kCenter);
198
199 frame_screenshot->SetLayoutManager(new TGHorizontalLayout(frame_screenshot));
200
201 TGTextButton* Screen = new TGTextButton(frame_screenshot, "Make");
202 frame_screenshot->AddFrame(Screen, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 20, 2, 2, 2));
203 Screen->Connect("Clicked()", this->ClassName(), this, "MakeScreenshot()");
204
205 fScreenshotOpt = new TGComboBox(frame_screenshot);
207 if (CbmTimesliceManager::Instance()->GetMcbmViewersMode()) {
210 }
211 else {
214 }
216 fScreenshotOpt->Select(0);
217 fScreenshotOpt->Resize(40, 30);
218 frame_screenshot->AddFrame(fScreenshotOpt, new TGLayoutHints(kLHintsRight | kLHintsExpandX));
219 scene_conf->AddFrame(frame_screenshot, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 2, 1));
220
221 fAnimation = new CbmTsEveAnimationControl(this, scene_conf, "StartAnimation()", "Animation", fWidth);
224 fAnimation->Init();
225
226 // TODO: fine-tune the position of the elements in the GUI tab
227 // scene_conf->AddFrame(online_screenshot,new TGLayoutHints(kLHintsRight|kLHintsExpandX));
228
229
230 fCbmEvents = dynamic_cast<TClonesArray*>(rootManager->GetObject("CbmEvent"));
231
232 if (nullptr == fCbmEvents) {
233 LOG(fatal) << "CbmTimesliceManager::Init() => CbmEvents branch not found! Task will be deactivated";
234 }
235}
236
242
244{
245 fManager->GotoTimeslice(fCurrentTimeslice->GetIntNumber());
249
251 fPrevTs->SetEnabled((0 < fCurrentTimeslice->GetIntNumber()) ? kTRUE : kFALSE);
252 fNextTs->SetEnabled((fCurrentTimeslice->GetIntNumber() < (fNbTs - 1)) ? kTRUE : kFALSE);
253
254 fNbEventsInTs = fCbmEvents->GetEntriesFast();
255
256 TString nevent = "No of events in TS : ";
257 nevent += fNbEventsInTs;
258 fEventNb->ChangeText(nevent.Data());
259 fCurrentEvent->SetLimitValues(0, fNbEventsInTs);
260 fCurrentEvent->SetIntNumber(0);
262
264 if (0 < fNbEventsInTs) {
265 fUpdateEvent->SetEnabled(kTRUE);
266 fPrevEvent->SetEnabled(kFALSE);
267 if (1 < fNbEventsInTs) { //
268 fNextEvent->SetEnabled(kTRUE);
269 }
270 }
271 else {
272 fUpdateEvent->SetEnabled(kFALSE);
273 fPrevEvent->SetEnabled(kFALSE);
274 fNextEvent->SetEnabled(kFALSE);
275 }
276
278 if (0 < fNbEventsInTs) { //
279 SelectEvent();
280 }
281}
282
284{
285 LOG(debug1) << "CbmTimesliceManager::PrevTimeslice() => At timeslice " << fCurrentTimeslice->GetIntNumber();
286 uint32_t uTsIdx = fCurrentTimeslice->GetIntNumber();
287 if (0 < uTsIdx) { // Should be protected by button enabling/disabling, but better safe than sorry
288 uTsIdx -= 1;
289 fCurrentTimeslice->SetIntNumber(uTsIdx);
290 LOG(debug1) << "CbmTimesliceManager::PrevTimeslice() => Setting timeslice to " << uTsIdx << " result "
291 << fCurrentTimeslice->GetIntNumber();
292
294 }
295}
296
298{
299 LOG(debug1) << "CbmTimesliceManager::NextTimeslice() => At timeslice " << fCurrentTimeslice->GetIntNumber();
300 uint32_t uTsIdx = fCurrentTimeslice->GetIntNumber();
301 if (uTsIdx < fNbTs - 1) { // Should be protected by button enabling/disabling, but better safe than sorry
302 uTsIdx += 1;
303 fCurrentTimeslice->SetIntNumber(uTsIdx);
304 LOG(debug1) << "CbmTimesliceManager::NextTimeslice() => Setting timeslice to " << uTsIdx << " result "
305 << fCurrentTimeslice->GetIntNumber();
306
308 }
309}
310
316
318{
319 LOG(debug1) << "CbmTimesliceManager::SelectEvent() => Going to event " << fCurrentEvent->GetIntNumber();
320 fManager->GotoEvent(fCurrentEvent->GetIntNumber());
324
325 // Enable/Disable buttons to avoid invalid accesses
326 fPrevEvent->SetEnabled((0 < fCurrentEvent->GetIntNumber()) ? kTRUE : kFALSE);
327 fNextEvent->SetEnabled((fCurrentEvent->GetIntNumber() < (fNbEventsInTs - 1)) ? kTRUE : kFALSE);
328}
329
331{
332 LOG(debug1) << "CbmTimesliceManager::PrevEvent() => At event " << fCurrentEvent->GetIntNumber();
333 uint32_t uEventIdx = fCurrentEvent->GetIntNumber();
334 if (0 < uEventIdx) { // Should be protected by button enabling/disabling, but better safe than sorry
335 uEventIdx -= 1;
336 fCurrentEvent->SetIntNumber(uEventIdx);
337 LOG(debug1) << "CbmTimesliceManager::PrevEvent() => Setting event to " << uEventIdx << " result "
338 << fCurrentEvent->GetIntNumber();
339
341 }
342}
343
345{
346 LOG(debug1) << "CbmTimesliceManager::NextEvent() => At event " << fCurrentEvent->GetIntNumber();
347 uint32_t uEventIdx = fCurrentEvent->GetIntNumber();
348 if (uEventIdx < fNbEventsInTs - 1) { // Should be protected by button enabling/disabling, but better safe than sorry
349 uEventIdx += 1;
350 fCurrentEvent->SetIntNumber(uEventIdx);
351 LOG(debug1) << "CbmTimesliceManager::NextEvent() => Setting event to " << uEventIdx << " result "
352 << fCurrentEvent->GetIntNumber();
353
355 }
356}
357
359{
360 TString stime;
361 stime.Form("%.2f", time);
362 stime += " ns";
363 fTimesliceTime->SetText(stime.Data());
364 Update();
365}
367{
368 TString stime;
369 stime.Form("%.2f", time);
370 stime += " ns";
371 fEventTime->SetText(stime.Data());
372 Update();
373}
374
375void CbmTimesliceManagerEditor::SetModel(TObject* obj) { fObject = obj; }
376
378{
380
381 std::chrono::duration<double> secSleepTime(fAnimation->GetAnimFrameSec());
382 bool bSleep = (0.0 < fAnimation->GetAnimFrameSec());
383
384 switch (fAnimation->GetAnimationType()) {
385 case CbmTsEveAnimationControl::eAnimationType::kEventsInTs: { // Events in selected timeslice
387 uint32_t iEvtMin = static_cast<uint32_t>(fAnimation->GetEventMin());
388 uint32_t iEvtMax = static_cast<uint32_t>(fAnimation->GetEventMax());
389 uint32_t iEvtStep = static_cast<uint32_t>(fAnimation->GetEventStep());
390
391 if (fAnimation->GetScreenshotEna()) { //
392 gSystem->mkdir("event_animations");
393 }
394 for (uint32_t iEvt = iEvtMin; iEvt < iEvtMax; iEvt += iEvtStep) {
395 fCurrentEvent->SetIntNumber(iEvt);
396
397 if ((iEvtMin == iEvt && kTRUE == fAnimation->GetClearBuffer()) || kFALSE == fAnimation->GetRunContinuous()) {
401 }
402 else {
404 fManager->SetClearHandler(kFALSE);
405 }
406
407 SelectEvent();
408 gEve->FullRedraw3D();
409 if (fAnimation->GetScreenshotEna()) { //
410 fManager->MakeScreenshot(screen, Form("event_animations/event_%05i.png", iEvt));
411 }
412 if (bSleep) {
413 // sleep between events to be able to see them
414 std::this_thread::sleep_for(secSleepTime);
415 }
416 }
417 break;
418 }
419 case CbmTsEveAnimationControl::eAnimationType::kTimeSlices: { // Events in timeslice range
421 uint32_t iTsMin = static_cast<uint32_t>(fAnimation->GetTsMin());
422 uint32_t iTsMax = static_cast<uint32_t>(fAnimation->GetTsMax());
423 uint32_t iTsStep = static_cast<uint32_t>(fAnimation->GetTsStep());
424
426 uint32_t iEvtStep = static_cast<int32_t>(fAnimation->GetEventStep());
427
428 if (fAnimation->GetScreenshotEna()) { //
429 gSystem->mkdir("timeslice_animations");
430 }
431 for (uint32_t iTs = iTsMin; iTs < iTsMax; iTs += iTsStep) {
432 fCurrentTimeslice->SetIntNumber(iTs);
433
434 if (iTsMin == iTs && kTRUE == fAnimation->GetClearBuffer()) {
437 }
438
440 for (uint32_t iEvt = 0; iEvt < fNbEventsInTs; iEvt += iEvtStep) {
441 fCurrentEvent->SetIntNumber(iEvt);
442
443 if (kFALSE == fAnimation->GetRunContinuous()) {
446 }
447 else {
449 fManager->SetClearHandler(kFALSE);
450 }
451
452 SelectEvent();
453 gEve->FullRedraw3D();
454 if (fAnimation->GetScreenshotEna()) { //
455 fManager->MakeScreenshot(screen, Form("timeslice_animations/ts_%05i_event_%05i.png", iTs, iEvt));
456 }
457 if (bSleep) {
458 // sleep between events to be able to see them
459 std::this_thread::sleep_for(secSleepTime);
460 }
461 } // Event loop
462 } // TS loop
463 break;
464 }
465 }
466 LOG(info) << "CbmTimesliceManager::StartAnimation() => Done with animation";
467}
468
473
ClassImp(CbmConverterManager)
GUI elements for CbmTimesliceManager. Automatically loaded by TBrowser. Cannot be used standalone!
virtual void SelectTimeslice()
Select timeslice depending on GUI elements values and load its first event. RESERVED FOR GUI CALLS!
virtual void PrevEvent()
Select previous event in timeslice. RESERVED FOR GUI CALLS!
virtual void NextTimeslice()
Select next timeslice and load its first event. RESERVED FOR GUI CALLS!
void MakeScreenshot()
Screenshot(s) generation: to be called by GUI element.
void SwitchPdgColorTrack(Bool_t pdg_color)
virtual void SelectEvent()
Select event in timeslice depending on GUI elements values. RESERVED FOR GUI CALLS!
virtual void SelectSingleEvent()
Select event in timeslice depending on GUI elements values, after clearing display....
virtual void NextEvent()
Select next event in timeslice. RESERVED FOR GUI CALLS!
virtual void PrevTimeslice()
Select previous timeslice and load its first event. RESERVED FOR GUI CALLS!
CbmTsEveAnimationControl * fAnimation
virtual void SelectSingleTimeslice()
Select timeslice depending on GUI elements values, after clearing display. RESERVED FOR GUI CALLS!
virtual void StartAnimation()
Start display: to be called by GUI element, see HowTo for description of options.
void SwitchBackground(Bool_t light_background)
CbmTimesliceManagerEditor(const TGWindow *p=0, Int_t width=250, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
TBrowser Event display for Timeslices as Tree entry with CbmEvents in container. Function as unique I...
virtual void GotoTimeslice(uint32_t timeslice)
virtual void SetEvtNumberText(Int_t evtNumber)
void SwitchPdgColorTrack(Bool_t pdg_color)
virtual void SwitchBackground(Bool_t)
virtual void SetTsNumberText(Int_t tsNumber)
virtual void GotoEvent(Int_t event)
virtual void SetEvtTimeText(Double_t time)
static CbmTimesliceManager * Instance()
void SetClearHandler(Bool_t val)
Used to indicate to subtask that they should reset.
void MakeScreenshot(CbmTsEveAnimationControl::eScreenshotType screenshotType, TString def_path="")
Screenshot(s) generation: to be called by GUI element.
virtual void SetTsTimeText(Double_t time)
GUI elements to add animation and screenshot controls to CbmTimesliceManagerEditor....
void SetDisplayMcbm(bool bEna)
Tune list of allowed screenshot types depending on available CBM/mCBM views.
eScreenshotType GetScreenshotType() const
eAnimationType GetAnimationType() const
GUI elements to add global transparency control to CbmTimesliceManagerEditor. Cannot be used alone!