19 #include <TDatabasePDG.h>
20 #include <TEveBrowser.h>
21 #include <TEveGeoNode.h>
22 #include <TEveManager.h>
23 #include <TEveProjectionManager.h>
24 #include <TEveProjections.h>
25 #include <TEveScene.h>
27 #include <TEveTrans.h>
28 #include <TEveViewer.h>
29 #include <TEveWindow.h>
30 #include <TGFileDialog.h>
31 #include <TGLCameraOverlay.h>
33 #include <TGLFontManager.h>
34 #include <TGLLightSet.h>
35 #include <TGLViewer.h>
37 #include <TGeoManager.h>
39 #include <TGeoVolume.h>
49 : TEveEventManager(
"FairEventManager",
"")
57 , fUseTimeOfEvent(kTRUE)
59 , fAnimatedTracks(kFALSE)
60 , fClearHandler(kTRUE)
63 , fRPhiPlane{0, 0, 10, 0}
64 , fRhoZPlane{-1, 0, 0, 0}
65 , fRphiCam(TGLViewer::kCameraOrthoXOY)
66 , fRhoCam(TGLViewer::kCameraOrthoZOY)
70 , fMultiRPhiView(
nullptr)
71 , fMultiRhoZView(
nullptr)
74 , fRPhiProjManager(
nullptr)
75 , fRhoZProjManager(
nullptr)
81 AddParticlesToPdgDataBase();
82 fPDGToColor[22] = 623;
83 fPDGToColor[-2112] = 2;
85 fPDGToColor[-3122] = 4;
87 fPDGToColor[-3222] = 6;
89 fPDGToColor[-3212] = 8;
91 fPDGToColor[-3112] = 10;
93 fPDGToColor[-3322] = 12;
94 fPDGToColor[111] = 13;
95 fPDGToColor[-3312] = 14;
96 fPDGToColor[211] = 15;
97 fPDGToColor[-3334] = 16;
98 fPDGToColor[-211] = 17;
99 fPDGToColor[-15] = 18;
100 fPDGToColor[130] = 19;
101 fPDGToColor[15] = 20;
102 fPDGToColor[321] = 21;
103 fPDGToColor[411] = 22;
104 fPDGToColor[-321] = 23;
105 fPDGToColor[-411] = 24;
106 fPDGToColor[2112] = 25;
107 fPDGToColor[421] = 26;
108 fPDGToColor[2212] = 27;
109 fPDGToColor[-421] = 28;
110 fPDGToColor[-2212] = 29;
111 fPDGToColor[431] = 30;
112 fPDGToColor[310] = 31;
113 fPDGToColor[-431] = 32;
114 fPDGToColor[221] = 33;
115 fPDGToColor[4122] = 34;
116 fPDGToColor[3122] = 35;
117 fPDGToColor[24] = 36;
118 fPDGToColor[3222] = 37;
119 fPDGToColor[-24] = 38;
120 fPDGToColor[3212] = 39;
121 fPDGToColor[23] = 40;
122 fPDGToColor[3112] = 41;
123 fPDGToColor[3322] = 42;
124 fPDGToColor[3312] = 43;
125 fPDGToColor[3334] = 44;
126 fPDGToColor[50000050] = 801;
127 fPDGToColor[1000010020] = 45;
128 fPDGToColor[1000010030] = 48;
129 fPDGToColor[1000020040] = 50;
130 fPDGToColor[1000020030] = 55;
135 TEveManager::Create();
137 if (gGeoManager ==
nullptr)
139 TGeoNode *N = gGeoManager->GetTopNode();
140 TEveGeoTopNode *TNod =
new TEveGeoTopNode(gGeoManager, N, visopt, vislvl, maxvisnds);
141 TGeoBBox *box =
dynamic_cast<TGeoBBox *
>(gGeoManager->GetTopNode()->GetVolume()->GetShape());
143 fWorldSizeX = box->GetDX();
144 fWorldSizeY = box->GetDY();
145 fWorldSizeZ = box->GetDZ();
147 if (!fXMLConfig.EqualTo(
""))
149 gEve->AddGlobalElement(TNod);
150 gEve->FullRedraw3D(kTRUE);
151 fEvent = gEve->AddEvent(
this);
153 fRPhiProjManager =
new TEveProjectionManager(TEveProjection::kPT_RPhi);
154 fRhoZProjManager =
new TEveProjectionManager(TEveProjection::kPT_RhoZ);
155 gEve->AddToListTree(fRPhiProjManager, kFALSE);
156 gEve->AddToListTree(fRhoZProjManager, kFALSE);
157 fAxesPhi =
new TEveProjectionAxes(fRPhiProjManager);
158 fAxesRho =
new TEveProjectionAxes(fRhoZProjManager);
160 TEveWindowSlot *RPhiSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
161 TEveWindowPack *RPhiPack = RPhiSlot->MakePack();
162 RPhiPack->SetElementName(
"RPhi View");
163 RPhiPack->SetShowTitleBar(kFALSE);
164 RPhiPack->NewSlot()->MakeCurrent();
165 fRPhiView = gEve->SpawnNewViewer(
"RPhi View",
"");
166 fRPhiScene = gEve->SpawnNewScene(
"RPhi",
"Scene holding axis.");
167 fRPhiScene->AddElement(fAxesPhi);
169 TEveWindowSlot *RhoZSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
170 TEveWindowPack *RhoZPack = RhoZSlot->MakePack();
171 RhoZPack->SetElementName(
"RhoZ View");
172 RhoZPack->SetShowTitleBar(kFALSE);
173 RhoZPack->NewSlot()->MakeCurrent();
174 fRhoZView = gEve->SpawnNewViewer(
"RhoZ View",
"");
175 fRhoZScene = gEve->SpawnNewScene(
"RhoZ",
"Scene holding axis.");
176 fRhoZScene->AddElement(fAxesRho);
178 SetViewers(fRPhiView, fRhoZView);
180 TEveWindowSlot *MultiSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
181 TEveWindowPack *MultiPack = MultiSlot->MakePack();
182 MultiPack->SetElementName(
"Multi View");
183 MultiPack->SetHorizontal();
184 MultiPack->SetShowTitleBar(kFALSE);
185 MultiPack->NewSlot()->MakeCurrent();
186 fMultiView = gEve->SpawnNewViewer(
"3D View (multi)",
"");
188 fMultiView->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft,
false);
189 fMultiView->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight,
false);
191 fMultiView->AddScene(gEve->GetGlobalScene());
192 fMultiView->AddScene(gEve->GetEventScene());
195 MultiPack = MultiPack->NewSlot()->MakePack();
196 MultiPack->SetShowTitleBar(kFALSE);
197 MultiPack->NewSlot()->MakeCurrent();
198 fMultiRPhiView = gEve->SpawnNewViewer(
"RPhi View (multi)",
"");
199 MultiPack->NewSlot()->MakeCurrent();
200 fMultiRhoZView = gEve->SpawnNewViewer(
"RhoZ View (multi)",
"");
202 SetViewers(fMultiRPhiView, fMultiRhoZView);
205 fRPhiView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
206 fRhoZView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
207 fMultiView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
208 fMultiRPhiView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
209 fMultiRhoZView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
210 fMultiView->GetEveFrame()->HideAllDecorations();
211 fMultiRPhiView->GetEveFrame()->HideAllDecorations();
212 fMultiRhoZView->GetEveFrame()->HideAllDecorations();
214 fEventTimeText =
new TEveText(
"Event Time: ");
215 fEventTimeText->PtrMainTrans()->SetPos(-100, 80, 0);
216 fEventTimeText->SetMainColor(kOrange - 2);
217 fEventTimeText->SetFontFile(
"ariali");
218 fEventTimeText->SetFontSize(20);
219 fEventTimeText->SetFontMode(TGLFont::kPixmap);
220 fEventTimeText->SetLighting(kTRUE);
221 fEventTimeText->SetRnrState(kFALSE);
222 gEve->AddElement(fEventTimeText);
224 fEventNumberText =
new TEveText(
"Event Number: ");
225 fEventNumberText->PtrMainTrans()->SetPos(-100, 100, 0);
226 fEventNumberText->SetMainColor(kOrange - 2);
227 fEventNumberText->SetFontFile(
"ariali");
228 fEventNumberText->SetFontSize(20);
229 fEventNumberText->SetFontMode(TGLFont::kPixmap);
230 fEventNumberText->SetLighting(kTRUE);
231 fEventNumberText->SetRnrState(kFALSE);
232 gEve->AddElement(fEventNumberText);
246 fRunAna->
Run(static_cast<Long64_t>(event));
254 fRunAna->
Run(static_cast<Long64_t>(fEntry));
262 fRunAna->
Run(static_cast<Long64_t>(fEntry));
271 if (fPDGToColor.find(pdg) != fPDGToColor.end()) {
272 return fPDGToColor[pdg];
281 TDatabasePDG *pdgDB = TDatabasePDG::Instance();
283 const Double_t kAu2Gev = 0.9314943228;
284 const Double_t khSlash = 1.0545726663e-27;
285 const Double_t kErg2Gev = 1 / 1.6021773349e-3;
286 const Double_t khShGev = khSlash * kErg2Gev;
287 const Double_t kYear2Sec = 3600 * 24 * 365.25;
291 if (!pdgDB->GetParticle(1000010020))
292 pdgDB->AddParticle(
"Deuteron",
"Deuteron", 2 * kAu2Gev + 8.071e-3, kTRUE, 0, 3,
"Ion", 1000010020);
294 if (!pdgDB->GetParticle(1000010030))
296 "Triton",
"Triton", 3 * kAu2Gev + 14.931e-3, kFALSE, khShGev / (12.33 * kYear2Sec), 3,
"Ion", 1000010030);
298 if (!pdgDB->GetParticle(1000020040))
300 "Alpha",
"Alpha", 4 * kAu2Gev + 2.424e-3, kTRUE, khShGev / (12.33 * kYear2Sec), 6,
"Ion", 1000020040);
302 if (!pdgDB->GetParticle(1000020030))
303 pdgDB->AddParticle(
"HE3",
"HE3", 3 * kAu2Gev + 14.931e-3, kFALSE, 0, 6,
"Ion", 1000020030);
307 if (!pdgDB->GetParticle(50000050))
308 pdgDB->AddParticle(
"Cherenkov",
"Cherenkov", 0, kFALSE, 0, 0,
"Special", 50000050);
310 if (!pdgDB->GetParticle(50000051))
311 pdgDB->AddParticle(
"FeedbackPhoton",
"FeedbackPhoton", 0, kFALSE, 0, 0,
"Special", 50000051);
316 void FairEventManager::SetViewers(TEveViewer *RPhi, TEveViewer *RhoZ)
318 RPhi->GetGLViewer()->SetCurrentCamera(fRphiCam);
322 RPhi->GetGLViewer()->GetCameraOverlay()->SetOrthographicMode(TGLCameraOverlay::kAxis);
323 RPhi->GetGLViewer()->GetCameraOverlay()->SetShowOrthographic(kTRUE);
325 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft,
false);
326 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight,
false);
327 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightTop,
false);
328 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightBottom,
false);
330 RhoZ->GetGLViewer()->SetCurrentCamera(fRhoCam);
334 RhoZ->GetGLViewer()->GetCameraOverlay()->SetOrthographicMode(TGLCameraOverlay::kAxis);
335 RhoZ->GetGLViewer()->GetCameraOverlay()->SetShowOrthographic(kTRUE);
337 RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft,
false);
338 RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight,
false);
339 RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightFront,
false);
341 RPhi->AddScene(fRPhiScene);
342 RPhi->AddScene(gEve->GetGlobalScene());
343 RPhi->AddScene(gEve->GetEventScene());
344 RhoZ->AddScene(fRhoZScene);
345 RhoZ->AddScene(gEve->GetGlobalScene());
346 RhoZ->AddScene(gEve->GetEventScene());
372 TString nodename = xml->
GetChild(i)->GetName();
373 if (nodename.EqualTo(
"Detectors")) {
374 TGeoNode *top = gGeoManager->GetTopNode();
376 if (top_xml !=
nullptr)
378 }
else if (nodename.EqualTo(
"MCTracksColors")) {
394 TString node_name = node->GetName();
395 Bool_t recursive = (xml->
GetAttrib(
"recursive")->
GetValue().Length() != 0 && !name.EqualTo(node_name));
396 if (recursive && depth == 0)
400 if (!color.EqualTo(
"")) {
404 if (!transparency.EqualTo(
"")) {
405 node->GetVolume()->SetTransparency((Char_t)(transparency.Atoi()));
409 Int_t xml_depth = val.Atoi();
411 xml_depth = depth - 1;
413 for (
int i = 0; i < node->GetNdaughters(); i++) {
414 TGeoNode *daughter_node = node->GetDaughter(i);
419 for (
int i = 0; i < node->GetNdaughters(); i++) {
420 TString subdetector_name = node->GetDaughter(i)->GetName();
424 if (subnode_name == subdetector_name) {
434 if (color.Contains(
"k")) {
435 Int_t plus_index = color.First(
'+');
436 Int_t minus_index = color.First(
'-');
437 Int_t cut = plus_index;
441 cut = color.Length();
442 TString col_name(color(0, cut));
444 if (col_name.EqualTo(
"kWhite")) {
446 }
else if (col_name.EqualTo(
"kBlack")) {
448 }
else if (col_name.EqualTo(
"kGray")) {
450 }
else if (col_name.EqualTo(
"kRed")) {
452 }
else if (col_name.EqualTo(
"kGreen")) {
454 }
else if (col_name.EqualTo(
"kBlue")) {
456 }
else if (col_name.EqualTo(
"kYellow")) {
458 }
else if (col_name.EqualTo(
"kMagenta")) {
460 }
else if (col_name.EqualTo(
"kCyan")) {
462 }
else if (col_name.EqualTo(
"kOrange")) {
464 }
else if (col_name.EqualTo(
"kSpring")) {
466 }
else if (col_name.EqualTo(
"kTeal")) {
468 }
else if (col_name.EqualTo(
"kAzure")) {
470 }
else if (col_name.EqualTo(
"kViolet")) {
472 }
else if (col_name.EqualTo(
"kPink")) {
475 TString col_num(color(cut + 1, color.Length()));
476 if (col_num.Length() > 0) {
477 if (color.Contains(
"+")) {
478 col_val += col_num.Atoi();
480 col_val -= col_num.Atoi();
491 if (use_xml == kFALSE) {
492 Int_t vis_level = gGeoManager->GetVisLevel();
493 TGeoNode *top = gGeoManager->GetTopNode();
494 SetTransparencyForLayer(top, vis_level, trans);
496 if (fXMLConfig !=
"") {
499 Int_t vis_level = gGeoManager->GetVisLevel();
500 TGeoNode *top = gGeoManager->GetTopNode();
501 SetTransparencyForLayer(top, vis_level, 0);
504 if (gEve->GetGlobalScene()->GetRnrState()) {
505 gEve->GetGlobalScene()->SetRnrState(kFALSE);
506 gEve->GetGlobalScene()->SetRnrState(kTRUE);
513 void FairEventManager::SetTransparencyForLayer(TGeoNode *node, Int_t depth, Char_t transparency)
515 node->GetVolume()->SetTransparency(transparency);
518 for (
int i = 0; i < node->GetNdaughters(); i++) {
519 TGeoNode *dau = node->GetDaughter(i);
520 SetTransparencyForLayer(dau, depth - 1, transparency);
528 const char *filetypes[] = {
"PNG",
"*.png",
"JPG",
"*.jpg", 0, 0};
530 fi.fFileTypes = filetypes;
531 fi.fIniDir = StrDup(
".");
532 new TGFileDialog(gClient->GetRoot(), gEve->GetMainWindow(), kFDSave, &fi);
533 if (fi.fFilename ==
nullptr)
535 filename = fi.fFilename;
540 case FairEveAnimationControl::eScreenshotType::k3D: {
541 gEve->GetDefaultGLViewer()->SavePicture(filename);
543 case FairEveAnimationControl::eScreenshotType::kXY: {
545 TGLViewer *gl = view->GetGLViewer();
546 gl->SavePicture(filename);
548 case FairEveAnimationControl::eScreenshotType::kZ: {
550 TGLViewer *gl = view->GetGLViewer();
551 gl->SavePicture(filename);
553 case FairEveAnimationControl::eScreenshotType::kAll: {
554 TString filename_path = filename(0, filename.Last(
'.'));
555 TString filename_ext = filename(filename.Last(
'.') + 1, 3);
556 TString filename3d = Form(
"%s_3d.%s", filename_path.Data(), filename_ext.Data());
557 TString filenameRphi = Form(
"%s_XY.%s", filename_path.Data(), filename_ext.Data());
558 TString filenameRhoz = Form(
"%s_Z.%s", filename_path.Data(), filename_ext.Data());
559 gEve->GetDefaultGLViewer()->SavePicture(filename3d);
561 TGLViewer *gl = view->GetGLViewer();
562 gl->SavePicture(filenameRphi);
564 gl = view->GetGLViewer();
565 gl->SavePicture(filenameRhoz);
572 if (fUseTimeOfEvent == kTRUE) {
581 stime.Form(
"%.2f", time);
583 fEventTimeText->SetText(stime);
588 TString text =
"Event: ";
590 fEventNumberText->SetText(text);
Int_t GetNChildren() const
FairXMLNode * GetRootNode() const
virtual void SetTransparency(Bool_t use_xml, Int_t trans)
void LoadXMLDetector(TGeoNode *node, FairXMLNode *xml, Int_t depth=0)
TEveViewer * GetRPhiView() const
virtual void SetEvtTimeText(Double_t time)
Float_t GetEvtTime()
current time in ns to display in the event display. Either set value or event time taken from FairRoo...
void MakeScreenshot(FairEveAnimationControl::eScreenshotType screen, TString def_path="")
FairXMLAttrib * GetAttrib(TString name) const
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
void Run(Int_t NStart=0, Int_t NStop=0)
virtual void SetRPhiPlane(Double_t a, Double_t b, Double_t c, Double_t d, TGLViewer::ECameraType camtype)
virtual void LoadXMLSettings()
virtual Int_t Color(Int_t pdg)
FairXMLNode * GetChild(TString name, Int_t count=0) const
virtual void Init(Int_t visopt=1, Int_t vislvl=3, Int_t maxvisnds=10000)
Int_t StringToColor(TString color) const
virtual void SwitchBackground(Bool_t light)
TVector3 GetWorldSize() const
virtual void DisplaySettings()
virtual void AddParticlesToPdgDataBase(Int_t pdg=0)
static FairEventManager * Instance()
virtual void GotoEvent(Int_t event)
virtual void SetEvtNumberText(Int_t evtNumber)
virtual void SetRhoZPlane(Double_t a, Double_t b, Double_t c, Double_t d, TGLViewer::ECameraType camtype)
TEveViewer * GetRhoZView() const
virtual ~FairEventManager()