1 #include <display/EveGeometry.h>
3 #include <geometry/GeometryManager.h>
4 #include <framework/logging/Logger.h>
5 #include <framework/utilities/FileSystem.h>
6 #include <framework/utilities/ColorPalette.h>
8 #include <TGeoManager.h>
10 #include <TEveManager.h>
11 #include <TEveGeoNode.h>
12 #include <TEveGeoShapeExtract.h>
21 static TEveGeoTopNode* s_eveTopNode =
nullptr;
22 static TEveGeoShape* s_simplifiedShape =
nullptr;
23 static std::vector<std::string> s_hideVolumes = {};
24 static std::vector<std::string> s_deleteVolumes = {};
25 static std::string s_eveGeometryExtractPath =
"/data/display/geometry_extract.root";
30 B2DEBUG(100,
"Setting up geometry for TEve...");
32 B2FATAL(
"gEve must be set up before EveGeometry!");
40 B2FATAL(
"Couldn't create TGeo geometry! Please make sure you add the Geometry module before Display");
45 gGeoManager->DefaultColors();
56 for (
auto& volume : s_hideVolumes)
59 TGeoNode* top_node = gGeoManager->GetTopNode();
60 assert(top_node != NULL);
61 s_eveTopNode =
new TEveGeoTopNode(gGeoManager, top_node);
62 s_eveTopNode->IncDenyDestroy();
63 s_eveTopNode->SetVisLevel(2);
65 gEve->AddGlobalElement(s_eveTopNode);
68 s_eveTopNode->ExpandIntoListTreesRecursively();
71 B2DEBUG(100,
"Loading geometry projections...");
74 TFile* f = TFile::Open(extractPath.c_str(),
"READ");
75 TEveGeoShapeExtract* gse =
dynamic_cast<TEveGeoShapeExtract*
>(f->Get(
"Extract"));
76 s_simplifiedShape = TEveGeoShape::ImportShapeExtract(gse, 0);
77 s_simplifiedShape->SetRnrSelf(
false);
78 s_simplifiedShape->IncDenyDestroy();
79 s_simplifiedShape->SetName(
"Minimal geometry extract");
84 gEve->AddGlobalElement(s_simplifiedShape);
90 for (
auto& volumeRegExp : s_deleteVolumes) {
95 B2DEBUG(100,
"Done.");
100 TPRegexp reAll(
".*");
101 bool onlyChildren =
false;
102 std::string regexp = pattern;
106 if (pattern.substr(0, 1) == std::string(
"#")) {
107 regexp = pattern.substr(1);
111 TPRegexp reMatch(regexp.c_str());
113 std::list<TEveElement*> children;
114 parent->FindChildren(children, reAll);
116 for (TEveElement* child : children) {
117 if (reMatch.MatchB(child->GetElementName())) {
119 B2INFO(
"Removing children of " << child->GetElementName());
120 child->DestroyElements();
122 B2INFO(
"Removing " << child->GetElementName());
133 bool fullgeo = (visMode ==
c_Full);
135 s_eveTopNode->SetRnrSelfChildren(fullgeo, fullgeo);
136 s_simplifiedShape->SetRnrSelfChildren(
false, !fullgeo);
141 if (!gGeoManager)
return;
142 TGeoVolume* vol = gGeoManager->FindVolumeFast(name);
145 vol->SetVisibility(enable);
146 vol->SetVisDaughters(enable);
148 B2DEBUG(100,
"Volume " << name <<
" not found?");
156 if (!gGeoManager)
return;
157 TGeoVolume* vol = gGeoManager->FindVolumeFast(name);
160 vol->SetLineColor(col);
162 B2DEBUG(100,
"Volume " << name <<
" not found?");
168 if (!gGeoManager)
return;
169 TObjArray* volumes = gGeoManager->GetListOfVolumes();
170 for (
int i = 0; i < volumes->GetEntriesFast(); i++) {
171 TGeoVolume* volume =
static_cast<TGeoVolume*
>(volumes->At(i));
172 volume->SetTransparency(percent);
178 if (gGeoManager && gGeoManager->GetTopNode()) {
179 TGeoVolume* top_node = gGeoManager->GetTopNode()->GetVolume();
180 double p[3] = { 380.0, 0.0, 0.0 };
181 while (!top_node->Contains(p)) {
185 }
else if (s_simplifiedShape) {
186 s_simplifiedShape->ComputeBBox();
187 const float* bbox = s_simplifiedShape->GetBBox();
188 return std::min(380.f, std::max({std::abs(bbox[0]), bbox[1], std::abs(bbox[2]), bbox[2]}));
196 TGeoManager* my_tgeomanager = gGeoManager;
198 B2ERROR(
"Couldn't find TEveGeoTopNode");
201 s_eveTopNode->ExpandIntoListTrees();
202 s_eveTopNode->SaveExtract(
"geometry_extract.root",
"Extract",
false);
207 gGeoManager = my_tgeomanager;
212 s_eveGeometryExtractPath = extractPath;
217 s_hideVolumes = volumes;
222 s_deleteVolumes = volumes;