Skip to content

Instantly share code, notes, and snippets.

@JeremyMcCormick
Created September 1, 2020 21:11
Show Gist options
  • Save JeremyMcCormick/bab0f3201157f59dc4a2d524eba56daa to your computer and use it in GitHub Desktop.
Save JeremyMcCormick/bab0f3201157f59dc4a2d524eba56daa to your computer and use it in GitHub Desktop.
#include <vector>
void MakeGeometry() {
TGeoManager *geom = new TGeoManager ("simple1", "Simple geometry");
//--- define some materials
TGeoMaterial *matVacuum = new TGeoMaterial ("Vacuum", 0, 0, 0);
TGeoMaterial *matAl = new TGeoMaterial ("Al", 26.98, 13, 2.7);
//--- define some media
TGeoMedium *Vacuum = new TGeoMedium ("Vacuum", 1, matVacuum);
TGeoMedium *Al = new TGeoMedium ("Root Material", 2, matAl);
TGeoVolume *top = geom->MakeBox ("TOP", Vacuum, 270., 270., 120.);
geom->SetTopVolume (top);
TGeoVolume *box = geom->MakeBox ("Box", Al, 10., 10., 10.);
top->AddNode (box, 1, new TGeoTranslation (-15, 0, 0));
top->AddNode (box, 2, new TGeoTranslation (15, 0, 0));
//--- close the geometry
geom->CloseGeometry ();
// gGeoManager = geom;
geom->Export ("testgeo.root", "TestGeo");
}
void CleanScene(TString projection, TEveElement *scene) {
TString toBeRemoved;
if (projection == "YZ")
return;
else if (projection == "XZ")
toBeRemoved = "Box_1";
else if (projection == "XY")
toBeRemoved = "Box_2";
for (TEveElement::List_i it = scene->BeginChildren ();
it != scene->EndChildren (); it++) {
std::cout << projection << " " << (*it)->GetElementName () << " " << *it
<< '\n';
if ((*it)->GetElementName () == toBeRemoved) {
std::cout << projection << " Trying to remove "
<< (*it)->GetElementName () << " " << *it << '\n';
dynamic_cast<TEveGeoNode*> (*it)->SetRnrSelf (false);
}
else {
CleanScene (projection, *it);
}
}
}
void test2() {
gEve = new TEveManager (1200, 600, true, "");
auto _slot = TEveWindow::CreateWindowInTab (
gEve->GetBrowser ()->GetTabRight ());
auto _pack = _slot->MakePack ();
_pack->SetElementName ("Multi View");
_pack->SetHorizontal ();
_pack->SetShowTitleBar (kFALSE);
auto _XZGeomScene = gEve->SpawnNewScene ("XOZG", "XOZ Geometry Scene");
auto _YZGeomScene = gEve->SpawnNewScene ("YOZG", "YOZ Geometry Scene");
auto _XYGeomScene = gEve->SpawnNewScene ("XOYG", "XOY Geometry Scene");
_pack->NewSlot ()->MakeCurrent ();
auto _XZView = gEve->SpawnNewViewer ("XZ View", "");
_XZView->AddScene (_XZGeomScene);
_XZView->GetGLViewer ()->SetCurrentCamera (TGLViewer::kCameraOrthoZOX);
_pack->NewSlot ()->MakeCurrent ();
auto _YZView = gEve->SpawnNewViewer ("YZ View", "");
_YZView->AddScene (_YZGeomScene);
_YZView->GetGLViewer ()->SetCurrentCamera (TGLViewer::kCameraOrthoZnOY);
_pack->NewSlot ()->MakeCurrent ();
auto _XYView = gEve->SpawnNewViewer ("XY View", "");
_XYView->AddScene (_XYGeomScene);
_XYView->GetGLViewer ()->SetCurrentCamera (TGLViewer::kCameraOrthoXOY);
gEve->GetBrowser ()->HideBottomTab ();
gEve->GetBrowser ()->GetTabRight ()->SetTab (1);
MakeGeometry ();
TEveScene *scenes[] = { _XZGeomScene, _YZGeomScene, _XYGeomScene };
const char *names[] = { "XZ", "YZ", "XY" };
for (int i = 0; i < 3; ++i) {
// NOTE: created by: gGeoManager->Export("testgeo.root", "TestGeo")
gEve->RegisterGeometryAlias (names[i], "testgeo.root");
TEveGeoManagerHolder gmgr (gEve->GetGeometryByAlias (names[i]));
TGeoNode *_wnode = (TGeoNode*) gGeoManager->GetListOfNodes ()->At (0);
while (_wnode != gGeoManager->GetTopNode ()) {
gGeoManager->CdUp ();
_wnode = gGeoManager->GetCurrentNode ();
}
gGeoManager->DefaultColors ();
TEveGeoTopNode *_node = new TEveGeoTopNode (gGeoManager, _wnode);
std::cout << names[i] << " " << _node << '\n';
//gEve->AddGlobalElement(_node);
//_node->ExpandIntoListTreesRecursively();
//_XZGeomScene->AddElement(_node);
//_YZGeomScene->AddElement(_node);
// _XYGeomScene->AddElement(_node);
scenes[i]->AddElement (_node);
_node->ExpandIntoListTreesRecursively ();
CleanScene (names[i], scenes[i]);
//CleanScene("XZ", _XZGeomScene);
//CleanScene("YZ", _YZGeomScene);
//CleanScene("XY", _XYGeomScene);
}
gEve->FullRedraw3D ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment