FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairEventManagerEditor.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
9 
10 #include "FairEveAnimationControl.h" // for FairEveAnimationControl, Fai...
11 #include "FairEveTransparencyControl.h" // for FairEveTransparencyControl
12 #include "FairEventManager.h" // for FairEventManager
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 <TEveManager.h> // for TEveManager, gEve
20 #include <TFile.h> // for TFile
21 #include <TGButton.h> // for TGTextButton, TGCheckButton
22 #include <TGComboBox.h> // for TGComboBox
23 #include <TGLabel.h> // for TGLabel
24 #include <TGLayout.h> // for TGLayoutHints, kLHintsExpandX
25 #include <TGNumberEntry.h> // for TGNumberEntry, TGNumberFormat
26 #include <TGenericClassInfo.h> // for TGenericClassInfo
27 #include <TGeoManager.h> // for TGeoManager, gGeoManager
28 #include <TList.h> // for TObjLink, TList
29 #include <TString.h> // for TString, Form
30 #include <TSystem.h> // for TSystem, gSystem
31 #include <iostream>
32 #include <memory> // for unique_ptr
33 class TGWindow; // lines 36-36
34 class TObject; // lines 37-37
35 
36 #define MAXE 5000
37 
38 // FairEventManagerEditor
39 //
40 // Specialization of TGedEditor for proper update propagation to
41 // TEveManager.
42 
44 
45 FairEventManagerEditor::FairEventManagerEditor(const TGWindow* p,
46  Int_t width,
47  Int_t height,
48  UInt_t options,
49  Pixel_t back)
50  : TGedFrame(p, width, height, options | kVerticalFrame, back)
51  , fObject(0)
52  , fManager(FairEventManager::Instance())
53  , fCurrentEvent(0)
54  , fGlobalTransparency(nullptr)
55  , fEventTime(nullptr)
56  , fScreenshotOpt(nullptr)
57 {
58  Init();
59 }
60 
61 void FairEventManagerEditor::SwitchBackground(Bool_t light_background) { fManager->SwitchBackground(light_background); }
62 
64 {
66  TChain* chain = rootManager->GetInChain();
67  Int_t Entries = chain->GetEntriesFast();
68 
69  MakeTitle("FairEventManager Editor");
70  TGVerticalFrame* fInfoFrame = CreateEditorTabSubFrame("Info");
71  TGCompositeFrame* title1 =
72  new TGCompositeFrame(fInfoFrame, 250, 10, kVerticalFrame | kLHintsExpandX | kFixedWidth | kOwnBackground);
73 
74  TString Infile = "Input file : ";
75  // TFile* file =FairRunAna::Instance()->GetInputFile();
76  TFile* file = FairRootManager::Instance()->GetInChain()->GetFile();
77  Infile += file->GetName();
78  TGLabel* TFName = new TGLabel(title1, Infile.Data());
79  title1->AddFrame(TFName);
80 
81  UInt_t RunId = FairRunAna::Instance()->getRunId();
82  TString run = "Run Id : ";
83  run += RunId;
84  TGLabel* TRunId = new TGLabel(title1, run.Data());
85  title1->AddFrame(TRunId);
86 
87  TString nevent = "No of events : ";
88  nevent += Entries;
89  TGLabel* TEvent = new TGLabel(title1, nevent.Data());
90  title1->AddFrame(TEvent);
91 
92  Int_t nodes = gGeoManager->GetNNodes();
93  TString NNodes = "No. of Nodes : ";
94  NNodes += nodes;
95  TGLabel* NoNode = new TGLabel(title1, NNodes.Data());
96  title1->AddFrame(NoNode);
97 
98  TGHorizontalFrame* f = new TGHorizontalFrame(title1);
99  TGLabel* l = new TGLabel(f, "Current Event:");
100  f->AddFrame(l, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 2, 1, 1));
101  fCurrentEvent = new TGNumberEntry(f,
102  0.,
103  6,
104  -1,
105  TGNumberFormat::kNESInteger,
106  TGNumberFormat::kNEANonNegative,
107  TGNumberFormat::kNELLimitMinMax,
108  0,
109  Entries);
110  f->AddFrame(fCurrentEvent, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
111  fCurrentEvent->Connect("ValueSet(Long_t)", "FairEventManagerEditor", this, "SelectSingleEvent()");
112  title1->AddFrame(f);
113 
114  TGHorizontalFrame* f2 = new TGHorizontalFrame(title1);
115  TGLabel* EventTimeLabel = new TGLabel(f2, "Event Time: ");
116  fEventTime = new TGLabel(f2, "");
117  f2->AddFrame(EventTimeLabel);
118  f2->AddFrame(fEventTime);
119  title1->AddFrame(f2);
120 
121  TGTextButton* fUpdate = new TGTextButton(title1, "Update");
122  title1->AddFrame(fUpdate, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
123  fUpdate->Connect("Clicked()", "FairEventManagerEditor", this, "SelectSingleEvent()");
124 
125  fInfoFrame->AddFrame(title1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
126 
128 
129  //=============== graphics =============================
130  TGVerticalFrame* scene_conf = CreateEditorTabSubFrame("Graphics");
131  TGHorizontalFrame* transparency_frame = new TGHorizontalFrame(scene_conf);
132 
133  std::unique_ptr<FairEveTransparencyControl> transparency(
134  new FairEveTransparencyControl(scene_conf, "Global transparency"));
135  scene_conf->AddFrame(transparency.release(), new TGLayoutHints(kLHintsNormal, 5, 5, 1, 1));
136 
137  TGCheckButton* backgroundButton = new TGCheckButton(scene_conf, "Light background");
138  scene_conf->AddFrame(backgroundButton, new TGLayoutHints(kLHintsRight | kLHintsExpandX, 5, 5, 1, 1));
139  backgroundButton->Connect("Toggled(Bool_t)", this->ClassName(), this, "SwitchBackground(Bool_t)");
140 
141  TGGroupFrame* frame_screenshot = new TGGroupFrame(scene_conf, "Screenshot");
142  frame_screenshot->SetTitlePos(TGGroupFrame::kCenter);
143 
144  frame_screenshot->SetLayoutManager(new TGHorizontalLayout(frame_screenshot));
145 
146  TGTextButton* Screen = new TGTextButton(frame_screenshot, "Make");
147  frame_screenshot->AddFrame(Screen, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 20, 2, 2, 2));
148  Screen->Connect("Clicked()", this->ClassName(), this, "MakeScreenshot()");
149 
150  fScreenshotOpt = new TGComboBox(frame_screenshot);
151  fScreenshotOpt->AddEntry("3D", 0);
152  fScreenshotOpt->AddEntry("RPhi", 1);
153  fScreenshotOpt->AddEntry("RhoZ", 2);
154  fScreenshotOpt->AddEntry("All", 3);
155  fScreenshotOpt->Select(0);
156  fScreenshotOpt->Resize(40, 30);
157  frame_screenshot->AddFrame(fScreenshotOpt, new TGLayoutHints(kLHintsRight | kLHintsExpandX));
158  scene_conf->AddFrame(frame_screenshot, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 2, 1));
159 
160  fAnimation = new FairEveAnimationControl(this, scene_conf, "Animation", fWidth, 2);
161  fAnimation->SetMinMax(0, Entries);
162  fAnimation->SetFunctionName("StartAnimation()");
163  fAnimation->Init();
164 
165  // scene_conf->AddFrame(online_screenshot,new TGLayoutHints(kLHintsRight|kLHintsExpandX));
166 }
167 
169 {
170  fManager->SetUseTimeOfEvent(kTRUE);
171  fManager->SetClearHandler(kTRUE);
172  SelectEvent();
173 }
174 
176 {
177  fManager->GotoEvent(fCurrentEvent->GetIntNumber());
181 }
182 
184 {
185  TString stime;
186  stime.Form("%.2f", time);
187  stime += " ns";
188  fEventTime->SetText(stime.Data());
189  Update();
190 }
191 
192 void FairEventManagerEditor::SetModel(TObject* obj) { fObject = obj; }
193 
195 {
196  switch (fAnimation->GetAnimationType()) {
197  case FairEveAnimationControl::eAnimationType::kEventByEvent: { // event by event
200  gSystem->mkdir("event_animations");
201  FairEventManager::Instance()->SetTimeLimits(0, -1); // disable drawing by timeslice
202  Int_t start = (Int_t)fAnimation->GetMin();
203  Int_t end = (Int_t)fAnimation->GetMax();
205  gSystem->mkdir("event_animations");
206  for (int i = start; i < end; i++) {
207  fCurrentEvent->SetIntNumber(i);
208  SelectEvent();
209  gEve->FullRedraw3D();
210  fManager->MakeScreenshot(screen, Form("event_animations/event_%i.png", i));
211  }
212  } break;
213  case FairEveAnimationControl::eAnimationType::kTimeSlice: { // timeslice
214  gSystem->mkdir("timeslice_animations");
217  SelectEvent();
218  Double_t start = (Double_t)fAnimation->GetMin();
219  Double_t end = (Double_t)fAnimation->GetMax();
220  Double_t step = (Double_t)fAnimation->GetStep();
221  if (step == 0) {
222  step = 1;
223  }
224  Double_t tail = (Double_t)fAnimation->GetTail();
225 
226  Int_t no = 0;
229  FairTask* pMainTask = ana->GetMainTask();
230  TList* taskList = pMainTask->GetListOfTasks();
231 
232  Int_t ntask = ana->GetNTasks();
233  Bool_t runOnce = true;
234  for (Double_t i = start; i < end; i += step) {
235  if (runOnce == true) { // Clear the buffer at the beginning of an animation run
236  if (fAnimation->GetClearBuffer() == kTRUE || fAnimation->GetRunContinuous() == kFALSE)
238  runOnce = false;
239  } else {
240  if (fAnimation->GetRunContinuous() == kFALSE) {
242  } else {
244  }
245  }
246  Double_t lowerLimit = 0;
247  if (tail < 0) {
248  lowerLimit = start;
249  } else {
250  lowerLimit = i - tail;
251  }
253  // std::cout << "EventTime set to: " << i << std::endl;
254  FairEventManager::Instance()->SetTimeLimits(lowerLimit, i);
257 
258  TObjLink* lnk = taskList->FirstLink();
259  while (lnk) {
260  FairTask* pCurTask = (FairTask*)lnk->GetObject();
261  pCurTask->ExecuteTask("");
262  lnk = lnk->Next();
263  }
264  gEve->FullRedraw3D();
265  fManager->MakeScreenshot(screen, Form("timeslice_animations/event_%i.png", no++));
266  }
267  } break;
268  }
269 }
270 
272 {
273  fManager->MakeScreenshot(static_cast<FairEveAnimationControl::eScreenshotType>(fScreenshotOpt->GetSelected()));
274 }
#define MAXE
void SetUseTimeOfEvent(Bool_t val)
virtual void ExecuteTask(Option_t *option="0")
Definition: FairTask.cxx:118
virtual void SetEvtTime(Float_t time)
TChain * GetInChain()
virtual void SetEvtTimeText(Double_t time)
UInt_t getRunId()
Definition: FairRunAna.h:76
void MakeScreenshot(FairEveAnimationControl::eScreenshotType screen, TString def_path="")
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual void SetMaxEnergy(Float_t max)
void SetMinMax(Double_t min, Double_t max)
static FairRunAna * Instance()
Definition: FairRunAna.cxx:61
void SetClearHandler(Bool_t val)
Int_t GetNTasks()
Definition: FairRun.h:122
void SetTimeLimits(Double_t min, Double_t max)
FairEveAnimationControl * fAnimation
virtual void SwitchBackground(Bool_t light)
static FairEventManager * Instance()
virtual void GotoEvent(Int_t event)
void SetFunctionName(TString name)
void SetAnimatedTracks(Bool_t val)
void SetEventTimeLabel(Double_t time)
virtual void SetEvtNumberText(Int_t evtNumber)
FairTask * GetMainTask()
Definition: FairRun.h:118
void SwitchBackground(Bool_t light_background)