BmnRoot
Loading...
Searching...
No Matches
MpdEventManager.cxx
Go to the documentation of this file.
1// MpdEventManager: class for event management and navigation.
2
3#include "MpdEventManager.h"
5#include "constants.h"
6
7#include "TDatabasePDG.h"
8#include "TEveGeoNode.h"
9#include "TEveManager.h"
10#include "TGeoManager.h"
11#include "TObjString.h"
12#include <TGLViewer.h>
13#include <TGLCameraOverlay.h>
14#include <TGLLightSet.h>
15#include <TEveBrowser.h>
16#include <TColor.h>
17
18#include "TDOMParser.h"
19#include "TXMLEngine.h"
20#include "TXMLAttr.h"
21#include "TXMLNode.h"
22
23#include "nlohmann/json.hpp"
24
25#include <unistd.h>
26#include <cerrno>
27#include <iostream>
28#include <sstream>
29#include <fstream>
30
31MpdEventManager* MpdEventManager::fgRinstance = 0;
33
35
36// convert string with hexadecimal presentation without "0x" to integer
37int hex_string_to_int(string hex_string)
38{
39 int x;
40 stringstream stream;
41 stream<<hex<<hex_string;
42 stream>>x;
43 return x;
44}
45
46//______________________________________________________________________________
48: TEveEventManager("EventManager", ""),
49 fRunAna(FairRunAna::Instance()),
50 EveMCPoints(NULL),
51 EveMCTracks(NULL),
52 EveRecoPoints(NULL),
53 EveRecoTracks(NULL),
54 background_color(1),
55 isDarkColor(true),
56 isOnline(false),
57 iDataSource(0),
58 isZDCModule(NULL),
59 fgShowShowMCPoints(false),
60 fgShowShowRecoPoints(false),
61 fgShowShowRecoTracks(false),
62 fgRedrawRecoPointsReqired(false),
63 fCurrentPDG(0),
64 fEventEditor(NULL),
65 fRPhiView(0),
66 fRhoZView(0),
67 fMulti3DView(0),
68 fMultiRPhiView(0),
69 fMultiRhoZView(0),
70 fRPhiMng(NULL),
71 fRhoZMng(NULL),
72 fRPhiGeomScene(0),
73 fRhoZGeomScene(0),
74 fAxesPhi(NULL),
75 fAxesRho(NULL),
76 fRPhiPlane{0, 0, 1, 0},
77 fRhoZPlane{-1, 0, 0, 0},
78 fEvent(0),
79 iCurrentEvent(0),
80 fPriOnly(kFALSE),
81 fMinEnergyLimit(0),
82 fMaxEnergyLimit(13),
83 fMinEnergyCut(0),
84 fMaxEnergyCut(13),
85 fLastUsedColor(2001),
86 fXMLConfig("")
87{
88 fgRinstance = this;
89
91
92 // set colors for particles
93 fPDGToColor[22] = 623; // photon
94 fPDGToColor[-2112] = 2; // anti-neutron
95 fPDGToColor[-11] = 3; // e+
96 fPDGToColor[-3122] = 4; // anti-lambda
97 fPDGToColor[11] = 5; // e-
98 fPDGToColor[-3222] = 6; // Sigma -
99 fPDGToColor[12] = 7; // e-neutrino
100 fPDGToColor[-3212] = 8; // Sigma0
101 fPDGToColor[-13] = 9; // mu+
102 fPDGToColor[-3112] = 10; // Sigma+ (PB
103 fPDGToColor[13] = 11; // mu-
104 fPDGToColor[-3322] = 12; // Xi0
105 fPDGToColor[111] = 13; // pi0
106 fPDGToColor[-3312] = 14; // Xi+
107 fPDGToColor[211] = 15; // pi+
108 fPDGToColor[-3334] = 16; // Omega+ (PB)
109 fPDGToColor[-211] = 17; // pi-
110 fPDGToColor[-15] = 18; // tau+
111 fPDGToColor[130] = 19; // K long
112 fPDGToColor[15] = 20; // tau -
113 fPDGToColor[321] = 21; // K+
114 fPDGToColor[411] = 22; // D+
115 fPDGToColor[-321] = 23; // K-
116 fPDGToColor[-411] = 24; // D-
117 fPDGToColor[2112] = 25; // n
118 fPDGToColor[421] = 26; // D0
119 fPDGToColor[2212] = 27; // p
120 fPDGToColor[-421] = 28; // D0
121 fPDGToColor[-2212] = 29; // anti-proton
122 fPDGToColor[431] = 30; // Ds+
123 fPDGToColor[310] = 31; // K short
124 fPDGToColor[-431] = 32; // anti Ds-
125 fPDGToColor[221] = 33; // eta
126 fPDGToColor[4122] = 34; // Lambda_C+
127 fPDGToColor[3122] = 35; // Lambda
128 fPDGToColor[24] = 36; // W+
129 fPDGToColor[3222] = 37; // Sigma+
130 fPDGToColor[-24] = 38; // W-
131 fPDGToColor[3212] = 39; //Sigma0
132 fPDGToColor[23] = 40; // Z
133 fPDGToColor[3112] = 41; // Sigma -
134 fPDGToColor[3322] = 42; // Xi0
135 fPDGToColor[3312] = 43; // Xi-
136 fPDGToColor[3334] = 44; // Omega- (PB)
137 fPDGToColor[50000050] = 801; //Cerenkov
138 fPDGToColor[1000010020] = 45;
139 fPDGToColor[1000010030] = 48;
140 fPDGToColor[1000020040] = 50;
141 fPDGToColor[1000020030] = 55;
142
143 InitColorStructure();
144}
145
146// return integer value of color by string storing color number, RGB triple or color name (e.g. kBlue, RGB(51,63,73), RGB(#0039E1))
147// support following MAIN COLOR NAMESET + some additional colors as examples:
148// kWhite, kBlack, kGgray,
149// kBlue, kAzure (темно-синий), kCyan (морской волны), kTeal (бирюзовый),
150// kGreen, kSpring (светло-зеленый), kGreen+2 (темно-зеленый), kSpring+2 (темно-зеленый), kKhaki
151// kYellow, kOrange (желтый с оттенком), kOrange+2 (оранжевый кор.), kOrange+1 (светло-оранжевый кор.), kOrange+7 (выделенно-оранжевый)
152// kRed, kViolet, kMagenta (бардовый), kMagenta-6 (светло-бардовый), kPink (темно-розовый)
153Int_t MpdEventManager::StringToColor(TString color)
154{
155 color = color.ReplaceAll(" ", "");
156 color.ToLower();
157
158 // check if color is a RGB triple
159 if (color.BeginsWith("rgb"))
160 {
161 // parse RGB triple
162 if (color.Length() < 6)
163 {
164 cout<<color<<" - RGB triple isn't correct. Color set to default blue"<<endl;
165 return 600;
166 }
167 TString triple = color(3, color.Length() - 3);
168 triple.Remove(TString::kLeading, '('); triple.Remove(TString::kTrailing, ')');
169
170 int red_rgb = -1, green_rgb = -1, blue_rgb = -1;
171 if (triple[0] == '#')
172 {
173 if (triple.Length() < 7)
174 {
175 cout<<triple<<" - hex triple size after '#' isn't correct (should have 6 symbols). Color set to default blue"<<endl;
176 return 600;
177 }
178
179 TString str_red = triple(1,2);
180 TString str_green = triple(3,2);
181 TString str_blue = triple(5,2);
182 if ((!str_red.IsHex()) || (!str_green.IsHex()) || (!str_blue.IsHex()))
183 {
184 cout<<triple<<" - hex triple after '#' has not hex format. Color set to default blue"<<endl;
185 return 600;
186 }
187
188 red_rgb = hex_string_to_int(str_red.Data());
189 green_rgb = hex_string_to_int(str_green.Data());
190 blue_rgb = hex_string_to_int(str_blue.Data());
191 }
192 else
193 {
194 TObjArray* pRGB = triple.Tokenize(",");
195 if (pRGB->GetEntriesFast() < 3)
196 {
197 cout<<triple<<" - RGB string doesn't include color triple. Color set to default blue"<<endl;
198 return 600;
199 }
200 red_rgb = ((TObjString*)pRGB->At(0))->GetString().Atoi();
201 green_rgb = ((TObjString*)pRGB->At(1))->GetString().Atoi();
202 blue_rgb = ((TObjString*)pRGB->At(2))->GetString().Atoi();
203 delete pRGB;
204 }
205
206 Int_t ci = fLastUsedColor++;
207 new TColor(ci, red_rgb/255.0F, green_rgb/255.0F, blue_rgb/255.0F);
208 return ci;
209 }
210
211 if (color.Contains("k"))
212 {
213 Ssiz_t sign_index = color.First('+');
214 if (sign_index == kNPOS)
215 sign_index = color.First('-');
216
217 TString color_name = "";
218 if (sign_index == kNPOS)
219 color_name = color;
220 else
221 color_name = color(0, sign_index);
222
223 Int_t color_value;
224 if (color_name.EqualTo("kwhite")) color_value = 0;
225 else if (color_name.EqualTo("kblack")) color_value = 1;
226 else if (color_name.EqualTo("kgray")) color_value = 920;
227 else if (color_name.EqualTo("kred")) color_value = 632;
228 else if (color_name.EqualTo("kgreen")) color_value = 416;
229 else if (color_name.EqualTo("kblue")) color_value = 600;
230 else if (color_name.EqualTo("kyellow")) color_value = 400;
231 else if (color_name.EqualTo("kmagenta")) color_value = 616;
232 else if (color_name.EqualTo("kcyan")) color_value = 432;
233 else if (color_name.EqualTo("korange")) color_value = 800;
234 else if (color_name.EqualTo("kspring")) color_value = 820;
235 else if (color_name.EqualTo("kteal")) color_value = 840;
236 else if (color_name.EqualTo("kazure")) color_value = 860;
237 else if (color_name.EqualTo("kviolet")) color_value = 880;
238 else if (color_name.EqualTo("kpink")) color_value = 900;
239 else if (color_name.EqualTo("kkhaki")) color_value = 403;
240 else
241 {
242 cout<<color_name<<" not found. Color set to default blue"<<endl;
243 color_value = 600;
244 }
245
246 if ((sign_index != kNPOS) && (color.Length() > sign_index+2))
247 {
248 TString strNumber = color(sign_index+1, color.Length() - sign_index-1);
249 if (strNumber.IsDigit())
250 {
251 if (color(sign_index) == '+')
252 color_value += strNumber.Atoi();
253 else
254 color_value -= strNumber.Atoi();
255 }
256 }
257
258 return color_value;
259 }
260 else
261 return color.Atoi();
262}
263
264void MpdEventManager::InitColorStructure()
265{
266 auto file_path = gSystem->ExpandPathName("$VMCWORKDIR/config/eventdisplay.json");
267 ifstream file(file_path);
268 if (file.is_open())
269 {
270 json data;
271 file >> data;
272
273 try
274 {
275 for (auto &particle : data["coloring"]["particles"])
276 fPDGToColor[(int) particle["pdg"]] = StringToColor((string) particle["color"]);
277 }
278 catch(const json::type_error &e)
279 {
280 cout << "MpdEventManager::InitColorStructure() Using default coloring for particles!" << endl;
281 }
282
283 try
284 {
285 structSelectedColoring *selected_coloring;
286 structLevelColoring *level_coloring;
287
288 string type = data["coloring"]["type"];
289
290 if (type == "detectors")
291 {
293
294 string scheme = data["coloring"][type]["scheme"];
295
296 for (auto &detector : data["coloring"][type][scheme])
297 {
298 selected_coloring = new structSelectedColoring(((string) detector["name"]),
299 ((string) detector["color"]),
300 detector.value("transparency", 0),
301 detector.value("isRecursiveColoring", kTRUE));
302 vecSelectedColoring.push_back(selected_coloring);
303 }
304 }
305 else
306 {
308
309 for (auto &level : data["coloring"][type])
310 {
311 level_coloring = new structLevelColoring((string) level["color"],
312 level["isFillLine"],
313 level.value("visibility", kFALSE),
314 level.value("transparency", 0));
315 vecLevelColoring.push_back(level_coloring);
316 }
317 }
318 }
319 catch(const json::type_error &e)
320 {
321 cout << "MpdEventManager::InitColorStructure() Using default ROOT coloring for detectors!" << endl;
323 }
324 }
325 else
326 {
327 cout << "MpdEventManager::InitColorStructure() File " << file_path << "not found! Using default coloring!" << endl;
329 }
330 file.close();
331}
332
333//______________________________________________________________________________
334void MpdEventManager::Init(Int_t visopt, Int_t vislvl, Int_t maxvisnds)
335{
336 TEveManager::Create();
337 fRunAna->Init();
338
339 if (gGeoManager == NULL)
340 return;
341 TGeoNode* N = gGeoManager->GetTopNode();
342 TEveGeoTopNode* TNod = new TEveGeoTopNode(gGeoManager, N, visopt, vislvl, maxvisnds);
343
344 // change color and visibility of geometry nodes
345 if (!fXMLConfig.EqualTo(""))
347 else
348 {
350 {
352 SelectedGeometryColoring();
353 else
354 LevelChangeNodeProperty(N, 0);
355 }
356 }
357
358 gEve->AddGlobalElement(TNod);
359 gEve->FullRedraw3D(kTRUE);
360 fEvent = gEve->AddEvent(this);
361
362 // create projection managers
363 fRPhiMng = new TEveProjectionManager(TEveProjection::kPT_RPhi);
364 fRhoZMng = new TEveProjectionManager(TEveProjection::kPT_RhoZ);
365 gEve->AddToListTree(fRPhiMng, kFALSE);
366 gEve->AddToListTree(fRhoZMng, kFALSE);
367
368 // create axes for viewers
369 fAxesPhi = new TEveProjectionAxes(fRPhiMng);
370 fAxesPhi->SetMainColor(kRed);
371 fAxesRho = new TEveProjectionAxes(fRhoZMng);
372 fAxesRho->SetMainColor(kRed);
373
374 // first 3D viewer
375 gEve->GetDefaultViewer()->SetElementName("3D View");
376 // display axes
377 //gEve->GetDefaultViewer()->GetGLViewer()->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0);
378 // switch off left and right light sources for first window
379 gEve->GetDefaultViewer()->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
380 gEve->GetDefaultViewer()->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
381 if (!isDarkColor)
382 gEve->GetDefaultViewer()->GetGLViewer()->UseLightColorSet();
383 gEve->GetDefaultViewer()->GetGLViewer()->SetClearColor(background_color);
384
385 // use only one View in Online mode
386 if (isOnline)
387 return;
388
389 // ADD WINDOW in EventDisplay for RPhi projection
390 TEveWindowSlot* RPhiSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
391 TEveWindowPack* RPhiPack = RPhiSlot->MakePack();
392 RPhiPack->SetElementName("RPhi View");
393 RPhiPack->SetShowTitleBar(kFALSE);
394 RPhiPack->NewSlot()->MakeCurrent();
395 fRPhiView = gEve->SpawnNewViewer("RPhi View", "");
396 // create scene holding projected geometry for the RPhi view
397 fRPhiGeomScene = gEve->SpawnNewScene("RPhi", "Scene holding geometry for RPhi.");
398 // add axes for scene of RPhi view
399 fRPhiGeomScene->AddElement(fAxesPhi);
400
401 // ADD WINDOW in EvenDisplay for RhoZ projection
402 TEveWindowSlot* RhoZSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
403 TEveWindowPack* RhoZPack = RhoZSlot->MakePack();
404 RhoZPack->SetElementName("RhoZ View");
405 RhoZPack->SetShowTitleBar(kFALSE);
406 RhoZPack->NewSlot()->MakeCurrent();
407 fRhoZView = gEve->SpawnNewViewer("RhoZ View", "");
408 // create scene holding projected geometry for the RhoZ view.
409 fRhoZGeomScene = gEve->SpawnNewScene("RhoZ", "Scene holding geometry for RhoZ.");
410 // add axes for scene of RPhoZ view
411 fRhoZGeomScene->AddElement(fAxesRho);
412
413 SetViewers(fRPhiView, fRhoZView);
414
415 // ADD WINDOW in EvenDisplay for MultiView
416 TEveWindowSlot* MultiSlot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
417 TEveWindowPack* MultiPack = MultiSlot->MakePack();
418 MultiPack->SetElementName("Multi View");
419 MultiPack->SetHorizontal();
420 MultiPack->SetShowTitleBar(kFALSE);
421 MultiPack->NewSlot()->MakeCurrent();
422 fMulti3DView = gEve->SpawnNewViewer("3D View (multi)", "");
423 // switch off left and right light sources for 3D MultiView
424 fMulti3DView->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
425 fMulti3DView->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
426 if (!isDarkColor)
427 fMulti3DView->GetGLViewer()->UseLightColorSet();
428 fMulti3DView->GetGLViewer()->SetClearColor(background_color);
429 // add 3D scenes (first tab) to 3D MultiView
430 fMulti3DView->AddScene(gEve->GetGlobalScene());
431 fMulti3DView->AddScene(gEve->GetEventScene());
432
433 // add slots for RPhi and RhoZ projections on Multi View tab
434 MultiPack = MultiPack->NewSlot()->MakePack();
435 MultiPack->SetShowTitleBar(kFALSE);
436 MultiPack->NewSlot()->MakeCurrent();
437 fMultiRPhiView = gEve->SpawnNewViewer("RPhi View (multi)", "");
438 MultiPack->NewSlot()->MakeCurrent();
439 fMultiRhoZView = gEve->SpawnNewViewer("RhoZ View (multi)", "");
440
441 SetViewers(fMultiRPhiView, fMultiRhoZView);
442
443 // don't change reposition camera on each update
444 fRPhiView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
445 fRhoZView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
446 fMulti3DView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
447 fMultiRPhiView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
448 fMultiRhoZView->GetGLViewer()->SetResetCamerasOnUpdate(kFALSE);
449
450 // from FairRoot (not checked yet)
451 fMulti3DView->GetEveFrame()->HideAllDecorations();
452 fMultiRPhiView->GetEveFrame()->HideAllDecorations();
453 fMultiRhoZView->GetEveFrame()->HideAllDecorations();
454}//MpdEventManager::Init
455
456void MpdEventManager::SetViewers(TEveViewer* RPhi, TEveViewer* RhoZ)
457{
458 RPhi->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
459 // set camera parameters
460 RPhi->GetGLViewer()->GetCameraOverlay()->SetOrthographicMode(TGLCameraOverlay::kAxis);
461 RPhi->GetGLViewer()->GetCameraOverlay()->SetShowOrthographic(kTRUE);
462 // switch off left, right, top and bottom light sources
463 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
464 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
465 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightTop, false);
466 RPhi->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightBottom, false);
467 if (!isDarkColor)
468 RPhi->GetGLViewer()->UseLightColorSet();
469 RPhi->GetGLViewer()->SetClearColor(background_color);
470
471 RhoZ->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoZOY);
472 // set camera parameters
473 RhoZ->GetGLViewer()->GetCameraOverlay()->SetOrthographicMode(TGLCameraOverlay::kAxis);
474 RhoZ->GetGLViewer()->GetCameraOverlay()->SetShowOrthographic(kTRUE);
475 // switch off left, right and front light sources
476 RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightLeft, false);
477 RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightRight, false);
478 RhoZ->GetGLViewer()->GetLightSet()->SetLight(TGLLightSet::kLightFront, false);
479 if (!isDarkColor)
480 RhoZ->GetGLViewer()->UseLightColorSet();
481 RhoZ->GetGLViewer()->SetClearColor(background_color);
482
483 RPhi->AddScene(fRPhiGeomScene);
484 RPhi->AddScene(gEve->GetGlobalScene());
485 RPhi->AddScene(gEve->GetEventScene());
486 RhoZ->AddScene(fRhoZGeomScene);
487 RhoZ->AddScene(gEve->GetGlobalScene());
488 RhoZ->AddScene(gEve->GetEventScene());
489
490 // set clip planes
491 RPhi->GetGLViewer()->GetClipSet()->SetClipType(TGLClip::kClipPlane);
492 RPhi->GetGLViewer()->GetClipSet()->SetClipState(TGLClip::kClipPlane, fRPhiPlane);
493 RhoZ->GetGLViewer()->GetClipSet()->SetClipType(TGLClip::kClipPlane);
494 RhoZ->GetGLViewer()->GetClipSet()->SetClipState(TGLClip::kClipPlane, fRhoZPlane);
495}
496
497// setting of geometry colors for DETECTOR COLORING MODE
498void MpdEventManager::SelectedGeometryColoring()
499{
500 TGeoVolume* curVolume;
501 for (size_t i = 0; i < vecSelectedColoring.size(); i++)
502 {
503 structSelectedColoring* selected_coloring = vecSelectedColoring[i];
504 curVolume = gGeoManager->GetVolume(selected_coloring->detector_name);
505 if (!curVolume)
506 {
507 cout<<"There is no volume with given name: "<<selected_coloring->detector_name<<endl;
508 // delete wrong detector name from the array
509 vecSelectedColoring.erase(vecSelectedColoring.begin() + i);
510 i--;
511 continue;
512 }
513 Int_t curColor = StringToColor(selected_coloring->detector_color);
514 Int_t curTransparency = selected_coloring->detector_transparency;
515
516 curVolume->SetFillColor(curColor);
517 curVolume->SetLineColor(curColor);
518 curVolume->SetTransparency(curTransparency);
519
520 if (selected_coloring->isRecursiveColoring)
521 {
522 for (int j = 0; j < curVolume->GetNdaughters(); j++)
523 {
524 TGeoNode* child = curVolume->GetNode(j);
525 TGeoVolume* subVolume = child->GetVolume();
526
527 subVolume->SetFillColor(curColor);
528 subVolume->SetLineColor(curColor);
529 subVolume->SetTransparency(curTransparency);
530
531 if (child->GetNdaughters() != 0)
532 RecursiveChangeNodeProperty(child, curColor, curTransparency);
533 }// for (int j = 0; j < curVolume->GetNdaughters(); j++)
534 }// if (selected_coloring->isRecursiveColoring)
535 }// for (int i = 0; i < vecSelectedColoring.size(); i++)
536
537 return;
538}
539
540void MpdEventManager::RecursiveChangeNodeProperty(TGeoNode* node, Int_t color, int transparency)
541{
542 for (int i = 0; i < node->GetNdaughters(); i++)
543 {
544 TGeoNode* child = node->GetDaughter(i);
545 TGeoVolume* curVolume = child->GetVolume();
546
547 curVolume->SetFillColor(color);
548 curVolume->SetLineColor(color);
549 curVolume->SetTransparency(transparency);
550
551 if (child->GetNdaughters() != 0) RecursiveChangeNodeProperty(child, color, transparency);
552 }
553}
554
555// set transparent geometry
557{
559 {
560 case selectedColoring:
561 {
562 TGeoVolume* curVolume;
563 for (size_t i = 0; i < vecSelectedColoring.size(); i++)
564 {
565 structSelectedColoring* selected_coloring = vecSelectedColoring[i];
566 curVolume = gGeoManager->GetVolume(selected_coloring->detector_name);
567 if (!curVolume)
568 {
569 cout<<"There is no volume with given name: "<< selected_coloring->detector_name<<endl;
570 // delete wrong detector name from the array
571 vecSelectedColoring.erase(vecSelectedColoring.begin() + i);
572 i--;
573 continue;
574 }
575
576 Int_t curTransparency = 80;
577 if (!is_on)
578 curTransparency = selected_coloring->detector_transparency;
579
580 curVolume->SetTransparency(curTransparency);
581
582 for (int j = 0; j < curVolume->GetNdaughters(); j++)
583 {
584 TGeoNode* child = curVolume->GetNode(j);
585 TGeoVolume* subVolume = child->GetVolume();
586
587 subVolume->SetTransparency(curTransparency);
588
589 if (child->GetNdaughters() != 0)
590 RecursiveChangeNodeTransparent(child, curTransparency);
591 }// or (int j = 0; j < curVolume->GetNdaughters(); j++)
592 }// for (int i = 0; i < vecSelectedColoring.size(); i++)
593
594 break;
595 }// case selectedColoring:
596 case levelColoring:
597 {
598 // NOT IMPLEMENTED
599 break;
600 }
601 case defaultColoring:
602 {
603 // NOT IMPLEMENTED
604 break;
605 }
606 }// switch (gVisualizationColoring)
607
608 return;
609}
610
611void MpdEventManager::RecursiveChangeNodeTransparent(TGeoNode* node, int transparency)
612{
613 for (int i = 0; i < node->GetNdaughters(); i++)
614 {
615 TGeoNode* child = node->GetDaughter(i);
616 TGeoVolume* curVolume = child->GetVolume();
617
618 curVolume->SetTransparency(transparency);
619
620 if (child->GetNdaughters() != 0) RecursiveChangeNodeTransparent(child, transparency);
621 }
622}
623
624// hierarchical changing of nodes' properties: visibility, transparency, fill color and line color
625void MpdEventManager::LevelChangeNodeProperty(TGeoNode* node, size_t level)
626{
627 for (Int_t i = 0; i < node->GetNdaughters(); i++)
628 {
629 TGeoNode* child = node->GetDaughter(i);
630 if (level < vecLevelColoring.size())
631 {
632 TGeoVolume* curVolume = child->GetVolume();
633
634 structLevelColoring* level_coloring = vecLevelColoring[level];
635 curVolume->SetVisibility(level_coloring->visibility);
636 curVolume->SetTransparency(level_coloring->transparency);
637 curVolume->SetFillColor(StringToColor(level_coloring->fill_color));
638 if (level_coloring->isFillLine) curVolume->SetLineColor(StringToColor(level_coloring->fill_color));
639
640 if (child->GetNdaughters() != 0)
641 LevelChangeNodeProperty(child, ++level);
642 }//if (level < arr_size)
643 }
644}
645
648
651
654
657
658// MpdEventManager destructor
660{
661 if (!vecSelectedColoring.empty())
662 {
663 for (size_t i = 0; i < vecSelectedColoring.size(); i++)
664 delete (vecSelectedColoring[i]);
665 vecSelectedColoring.clear();
666 }
667 if (!vecLevelColoring.empty())
668 {
669 for (size_t i = 0; i < vecLevelColoring.size(); i++)
670 delete (vecLevelColoring[i]);
671 vecLevelColoring.clear();
672 }
673}
674
675// go to FairRunAna event with given number for scene data getting
677{
678 iCurrentEvent = event;
679 fRunAna->Run((Long64_t)event);
680}
681
682// go to next FairRunAna event for scene data getting
684{
685 fRunAna->Run((Long64_t)++iCurrentEvent);
686}
687
688// go to previous FairRunAna event for scene data getting
690{
691 fRunAna->Run((Long64_t)--iCurrentEvent);
692}
693
694// assign different colors for differrent particles
695// return integer value of color for track by particle pdg (default, white)
696Int_t MpdEventManager::Color(int pdg)
697{
698 if (fPDGToColor.find(pdg) != fPDGToColor.end())
699 return fPDGToColor[pdg];
700
701 return 0;
702}
703
704// add particles to the PDG data base: Deuteron, Triton, Alpha, HE3; Cherenkov, FeedbackPhoton
706{
707 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
708
709 const Double_t kAu2Gev = 0.9314943228;
710 const Double_t khSlash = 1.0545726663e-27;
711 const Double_t kErg2Gev = 1/1.6021773349e-3;
712 const Double_t khShGev = khSlash*kErg2Gev;
713 const Double_t kYear2Sec = 3600*24*365.25;
714
715 // Ions
716 if (!pdgDB->GetParticle(1000010020))
717 pdgDB->AddParticle("Deuteron","Deuteron", 2*kAu2Gev+8.071e-3,kTRUE, 0, 3, "Ion", 1000010020);
718
719 if (!pdgDB->GetParticle(1000010030))
720 pdgDB->AddParticle("Triton","Triton", 3*kAu2Gev+14.931e-3, kFALSE, khShGev/(12.33*kYear2Sec), 3, "Ion", 1000010030);
721
722 if (!pdgDB->GetParticle(1000020040))
723 pdgDB->AddParticle("Alpha","Alpha", 4*kAu2Gev+2.424e-3, kTRUE, khShGev/(12.33*kYear2Sec), 6, "Ion", 1000020040);
724
725 if (!pdgDB->GetParticle(1000020030))
726 pdgDB->AddParticle("HE3","HE3", 3*kAu2Gev+14.931e-3, kFALSE, 0, 6, "Ion", 1000020030);
727
728 // Special particles
729 if (!pdgDB->GetParticle(50000050))
730 pdgDB->AddParticle("Cherenkov","Cherenkov", 0, kFALSE, 0, 0, "Special", 50000050);
731
732 if (!pdgDB->GetParticle(50000051))
733 pdgDB->AddParticle("FeedbackPhoton","FeedbackPhoton", 0, kFALSE, 0, 0, "Special", 50000051);
734}
735
736void MpdEventManager::AddEventElement(TEveElement* element, ElementList element_list)
737{
738 switch (element_list)
739 {
740 case MCPointList:
741 {
742 if (EveMCPoints == NULL)
743 {
744 EveMCPoints = new TEveElementList("MC points");
745 gEve->AddElement(EveMCPoints, this);
746 EveMCPoints->SetRnrState(kFALSE);
747 GetEventEditor()->fShowMCPoints->SetEnabled(kTRUE);
748 }
749
750 gEve->AddElement(element, EveMCPoints);
751 break;
752 }
753 case MCTrackList:
754 {
755 if (EveMCTracks == NULL)
756 {
757 EveMCTracks = new TEveElementList("MC tracks");
758 gEve->AddElement(EveMCTracks, this);
759 EveMCTracks->SetRnrState(kFALSE);
760 GetEventEditor()->fShowMCTracks->SetEnabled(kTRUE);
761 }
762
763 gEve->AddElement(element, EveMCTracks);
764 break;
765 }
766 case RecoPointList:
767 {
768 if (EveRecoPoints == NULL)
769 {
770 EveRecoPoints = new TEveElementList("Reco points");
771 gEve->AddElement(EveRecoPoints, this);
772 EveRecoPoints->SetRnrState(kFALSE);
773 GetEventEditor()->fShowRecoPoints->SetEnabled(kTRUE);
774 }
775
776 gEve->AddElement(element, EveRecoPoints);
777 break;
778 }
779 case RecoTrackList:
780 {
781 if (EveRecoTracks == NULL)
782 {
783 EveRecoTracks = new TEveElementList("Reco tracks");
784 gEve->AddElement(EveRecoTracks, this);
785 EveRecoTracks->SetRnrState(kFALSE);
786 GetEventEditor()->fShowRecoTracks->SetEnabled(kTRUE);
787 }
788
789 gEve->AddElement(element, EveRecoTracks);
790 break;
791 }
792 }// switch (element_list)
793}
794
795
797{
798 TDOMParser* Parser = new TDOMParser();
799 Parser->SetValidate(kFALSE);
800 Parser->ParseFile(fXMLConfig);
801
802 //TXMLNode* MainNode = Parser->GetXMLDocument()->GetRootNode();
803 MpdXMLFile xmlfile(fXMLConfig,"read");
804 MpdXMLNode* xml = xmlfile.GetRootNode();
805 for (int i = 0; i < xml->GetNChildren(); i++)
806 {
807 TString nodename = xml->GetChild(i)->GetName();
808 if (nodename.EqualTo("Detectors"))
809 {
810 TGeoNode* top = gGeoManager->GetTopNode();
811 MpdXMLNode* top_xml = xml->GetChild(i)->GetChild(0);
812 if(top_xml != nullptr)
813 LoadXMLDetector(top, top_xml);
814 }
815 else if (nodename.EqualTo("MCTracksColors"))
816 {
817 MpdXMLNode* colors = xml->GetChild(i);
818 for (int j = 0; j < colors->GetNChildren(); j++)
819 {
820 MpdXMLNode* color = colors->GetChild(j);
821 TString pgd_code = color->GetAttrib("pdg")->GetValue();
822 TString color_code = color->GetAttrib("color")->GetValue();
823 fPDGToColor[pgd_code.Atoi()] = StringToColor(color_code);
824 }
825 }
826 }
827}
828
829void MpdEventManager::LoadXMLDetector(TGeoNode* node, MpdXMLNode* xml, Int_t depth)
830{
831 TString name = xml->GetAttrib("name")->GetValue();
832 TString node_name = node->GetName();
833
834 Bool_t recursive = (xml->GetAttrib("recursive")->GetValue().Length()!=0&&!name.EqualTo(node_name));
835 if (recursive && depth == 0)
836 return;
837
838 TString color = xml->GetAttrib("color")->GetValue();
839 if (!color.EqualTo(""))
840 {
841 node->GetVolume()->SetFillColor(StringToColor(color));
842 node->GetVolume()->SetLineColor(StringToColor(color));
843 }
844
845 TString transparency = xml->GetAttrib("transparency")->GetValue();
846 if (!transparency.EqualTo(""))
847 node->GetVolume()->SetTransparency((Char_t)(transparency.Atoi()));
848
849 if (xml->GetAttrib("recursive")->GetValue().Length()>0)
850 {
851 TString val = xml->GetAttrib("recursive")->GetValue();
852 Int_t xml_depth = val.Atoi();
853 if (recursive)
854 xml_depth =depth-1;
855
856 for (int i = 0; i < node->GetNdaughters(); i++)
857 {
858 TGeoNode* daughter_node = node->GetDaughter(i);
859 LoadXMLDetector(daughter_node, xml, xml_depth);
860 }
861 }
862
863 if (xml->GetNChildren() > 0 && !recursive)
864 {
865 for (int i = 0; i < node->GetNdaughters(); i++)
866 {
867 TString subdetector_name = node->GetDaughter(i)->GetName();
868 for (int j = 0; j < xml->GetNChildren(); j++)
869 {
870 MpdXMLNode* subnode = xml->GetChild(j);
871 TString subnode_name = subnode->GetAttrib("name")->GetValue();
872 if (subnode_name == subdetector_name)
873 LoadXMLDetector(node->GetDaughter(i), subnode);
874 }
875 }
876 }
877}
878
879// extend energy limits and modify sliders for energy cut if 'check_energy' is out of the limits
880void MpdEventManager::ExpandEnergyLimits(Float_t check_energy, float add_multiplier)
881{
882 if (check_energy < fMinEnergyLimit)
883 fMinEnergyLimit = check_energy;
884 if (check_energy > fMaxEnergyLimit)
885 {
886 bool isIncreaseCut = false;
887 if (fMaxEnergyLimit == fMaxEnergyCut) isIncreaseCut = true;
888 fMaxEnergyLimit = ceil(check_energy*add_multiplier);
889 if (isIncreaseCut) fMaxEnergyCut = fMaxEnergyLimit;
890 fEventEditor->UpdateEnergySlider();
891 }
892}
int hex_string_to_int(string hex_string)
int i
Definition P4_F32vec4.h:22
TEveElementList * EveRecoPoints
virtual void Init(Int_t visopt=1, Int_t vislvl=3, Int_t maxvisnds=10000)
FairRunAna * fRunAna
virtual void NextEvent()
VisualizationColoring gVisualizationColoring
virtual void ExpandEnergyLimits(Float_t check_energy, float add_multiplier=1)
static MpdEventManager * Instance()
MpdEventManagerEditor * GetEventEditor()
TEveElementList * EveRecoTracks
virtual void GotoEvent(Int_t event)
virtual void Open()
TEveElementList * EveMCTracks
virtual void Close()
void SetTransparentGeometry(bool is_on)
void LoadXMLDetector(TGeoNode *node, MpdXMLNode *xml, Int_t depth=0)
virtual void PrevEvent()
virtual void AddParticlesToPdgDataBase()
void AddEventElement(TEveElement *element, ElementList element_list)
virtual Int_t Color(Int_t pdg)
virtual void LoadXMLSettings()
TEveElementList * EveMCPoints
virtual void DisplaySettings()
TString GetValue() const
Definition MpdXMLNode.h:38
MpdXMLNode * GetRootNode() const
Definition MpdXMLNode.h:171
MpdXMLNode * GetChild(TString name, Int_t count=0) const
MpdXMLAttrib * GetAttrib(TString name) const
Int_t GetNChildren() const
Definition MpdXMLNode.h:96
a class to store JSON values
Definition json.hpp:17282
exception indicating executing a member function with a wrong type
Definition json.hpp:2972
ElementList
@ RecoPointList
@ MCPointList
@ MCTrackList
@ RecoTrackList
basic_json<> json
default specialization
Definition json.hpp:3337