REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestEveEventViewer.cxx
1 
15 #include "TRestEveEventViewer.h"
16 
17 #include "TRestStringOutput.h"
18 
19 using namespace std;
20 
21 ClassImp(TRestEveEventViewer);
22 
23 TRestEveEventViewer::TRestEveEventViewer() {
24  Initialize();
25  fEnergyDeposits = new TEvePointSet();
26  fEnergyDeposits->SetElementName("Energy deposits");
27 
28  RESTWarning << "There are some issues with geometry representation in Eve 3D scenes!" << RESTendl;
29  RESTWarning
30  << "We use a geometry scaling factor to place the hits in the scene and correct a placement problem"
31  << RESTendl;
32  RESTWarning << "Presently the default value of fGeomScale is " << fGeomScale << RESTendl;
33  RESTWarning << "Please, report to the dev team if you experience problems visualizing the geometry."
34  << RESTendl;
35  RESTWarning << "For example: when hit positions seem to do not match geometry positions" << RESTendl;
36 
37  RESTWarning << " " << RESTendl;
38  RESTWarning << "You may try to fix this using TRestEventViewer::SetGeomScale(1.0);" << RESTendl;
39 }
40 
41 TRestEveEventViewer::~TRestEveEventViewer() {
42  delete fEnergyDeposits;
43  // TRestEveEventViewer destructor
44  DeleteCurrentEvent();
45  DeleteGeometry();
46 }
47 
48 void InitializePerspectiveView() {
49  const std::map<TString, TGLViewer::ECameraType> projectionsMap = {
50  {"Projection XY", TGLViewer::kCameraOrthoXOY}, //
51  {"Projection XZ", TGLViewer::kCameraOrthoXnOZ}, //
52  {"Projection YZ", TGLViewer::kCameraOrthoZOY} //
53  };
54  for (const auto& [name, cameraType] : projectionsMap) {
55  auto slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
56  auto pack = slot->MakePack();
57  pack->SetElementName(name);
58  pack->SetHorizontal();
59  pack->SetShowTitleBar(kFALSE);
60  pack->NewSlot()->MakeCurrent();
61  auto f3DView = gEve->SpawnNewViewer("3D View", pack->GetName());
62  f3DView->AddScene(gEve->GetGlobalScene());
63  f3DView->AddScene(gEve->GetEventScene());
64  f3DView->GetGLViewer()->SetCurrentCamera(cameraType);
65  }
66 }
67 
68 void TRestEveEventViewer::Initialize() {
69  gEve = TEveManager::Create();
70  gEve->GetBrowser()->DontCallClose();
71 
72  gEve->AddEvent(new TEveEventManager("Event", "Event"));
73 
74  auto singleViewer = gEve->GetDefaultViewer();
75  singleViewer->SetElementName("SingleView");
76 
77  singleViewer->GetGLViewer()->SetClearColor(kBlack);
78 
79  InitializePerspectiveView();
80  MultiView();
81  DrawTab();
82 
83  singleViewer->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
84 
85  gEve->GetBrowser()->GetTabRight()->SetTab(0); // select the "SingleView" viewer as active
86 
87  singleViewer->GetGLViewer()->CurrentCamera().Reset();
88  gEve->FullRedraw3D(kTRUE);
89 }
90 
91 void TRestEveEventViewer::SetGeometry(TGeoManager* geo) {
92  TRestEventViewer::SetGeometry(geo);
93 
94  if (fGeometry == nullptr) {
95  return;
96  }
97 
98  const unsigned int nVolumes = fGeometry->GetListOfVolumes()->GetEntries();
99  double transparencyLevel = 85;
100  if (nVolumes > 30) {
101  transparencyLevel = 90;
102  }
103  for (int i = 0; i < fGeometry->GetListOfVolumes()->GetEntries(); i++) {
104  auto volume = fGeometry->GetVolume(i);
105  auto material = volume->GetMaterial();
106  if (material->GetDensity() <= 0.01) {
107  volume->SetTransparency(99);
108  if (material->GetDensity() <= 0.001) {
109  // We consider this vacuum for display purposes
110  volume->SetVisibility(kFALSE);
111  }
112  } else {
113  volume->SetTransparency(transparencyLevel);
114  }
115  }
116 
117  TEveGeoTopNode* eveGeoTopNode = new TEveGeoTopNode(fGeometry, fGeometry->GetTopNode());
118  eveGeoTopNode->SetVisLevel(5);
119 
120  gEve->AddGlobalElement(eveGeoTopNode);
121 
122  viewer3D->AddScene(gEve->GetGlobalScene());
123 }
124 
125 void TRestEveEventViewer::DeleteCurrentEvent() {
126  cout << "Removing event" << endl;
127  delete fEnergyDeposits;
128  fEnergyDeposits = new TEvePointSet();
129  fEnergyDeposits->SetElementName("Energy deposits");
130  gEve->GetViewers()->DeleteAnnotations();
131  gEve->GetCurrentEvent()->DestroyElements();
132 }
133 
134 void TRestEveEventViewer::DeleteGeometry() {
135  cout << "Removing geometry" << endl;
136  gEve->GetGlobalScene()->DestroyElements();
137 }
138 
139 void TRestEveEventViewer::MultiView() {
140  slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
141 
142  pack = slot->MakePack();
143  pack->SetElementName("MultiView");
144  pack->SetHorizontal();
145  pack->SetShowTitleBar(kFALSE);
146  pack->NewSlot()->MakeCurrent();
147 
148  viewer3D = gEve->SpawnNewViewer("3DView");
149  viewer3D->AddScene(gEve->GetEventScene());
150 
151  pack = pack->NewSlot()->MakePack();
152  pack->SetShowTitleBar(kFALSE);
153  pack->NewSlot()->MakeCurrent();
154  rphiViewer = gEve->SpawnNewViewer("RPhi View");
155  rphiViewer->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
156 
157  rphiScene = gEve->SpawnNewScene("RPhi");
158  rphiViewer->AddScene(rphiScene);
159 
160  rphi = new TEveProjectionManager(TEveProjection::kPT_RPhi);
161  rphiScene->AddElement(rphi);
162 
163  rphiAxes = new TEveProjectionAxes(rphi);
164  rphiScene->AddElement(rphiAxes);
165 
166  pack = pack->NewSlot()->MakePack();
167  pack->SetShowTitleBar(kFALSE);
168  pack->NewSlot()->MakeCurrent();
169  rhozViewer = gEve->SpawnNewViewer("RhoZ View");
170  rhozViewer->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
171 
172  rhozScene = gEve->SpawnNewScene("RhoZ");
173  rhozViewer->AddScene(rhozScene);
174 
175  rhoz = new TEveProjectionManager(TEveProjection::kPT_RhoZ);
176  rhozScene->AddElement(rhoz);
177 
178  rhozAxes = new TEveProjectionAxes(rhoz);
179  rhozScene->AddElement(rhozAxes);
180 }
181 
182 void TRestEveEventViewer::DrawTab() {
183  TGLViewer* v2 = viewer3D->GetGLViewer();
184  v2->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, nullptr);
185  v2->SetStyle(TGLRnrCtx::kOutline);
186 }
187 
188 void TRestEveEventViewer::Update() {
189  gEve->AddElement(fEnergyDeposits);
190  rphi->ImportElements(gEve->GetCurrentEvent());
191  rhoz->ImportElements(gEve->GetCurrentEvent());
192 
193  rphiViewer->Redraw(kTRUE);
194  rhozViewer->Redraw(kTRUE);
195 }
196 
197 void TRestEveEventViewer::AddSphericalHit(double x, double y, double z, double radius, double en) {
198  fEnergyDeposits->SetOwnIds(kTRUE);
199  fEnergyDeposits->SetNextPoint(x * fGeomScale, y * fGeomScale, z * fGeomScale);
200  fEnergyDeposits->SetMarkerColor(kYellow);
201  fEnergyDeposits->SetMarkerSize(Size_t(radius));
202  fEnergyDeposits->SetMarkerStyle(4);
203 }