How to delete subdetector geometry (subtree) in gGeoManager

I have encountered with the following problem:
I have gGeoManager (from geometry file) with full facility geometry and another data. This facility geometry tree has many branches with different subdetectors.
I need to regularly change the geometry of a single subdetector from a separate *.root file in the full gGeoManager. But I can’t find function to delete subdetector geometry branch (subtree) in the gGeoManager in order to add new geometry from the file instead of old one.
Please, advice me how to do it.
Thank you.

With best wishes, Konstantin.

Hi Konstantin,

The answer is simple: you just cannot do it… The geometry manager is the object keeper in terms of volumes, transformations, materials, … and does not organize the information per geometry branch. The only way you can try is to delete the full geometry and then create a new one attaching only the modules you are interested in.


Oh, i thought that it’s possible to recursively delete nodes and volumes in the sub-tree upwards and in the corresponding fVolumeList and fNodeList (or something like that).

Do You mean I need to copy required geometry branches from the old TGeoManager object to a new one instead of deleting?


You cannot just copy objects, there will be problems with the ownership. It depends how you are storing the modules in files. Ideally they are exported not as TGeoManager geometries, but as volumes. Assuming your volume hierarchy looks like:

Top volume
detector1 detector2 detector3 …

you can export in different files only detector1, detector2, … as:

detector1->Export("Detector1.root", "detector1");

You can recreate then the geometry from these files by creating just the TGeoManager and the top volume, then:

TGeoVolume *detector1 = TGeoVolume::Import("Detector1.root", "detector1");
top_volume->AddNode(detector1, ...)
... same with other detectors

Now you can have several versions for detector1, stored in the same file or in different files. You can easily compose a geometry from the modules you want, using the recipe above. In this way you do not need to copy anything, you will have a single consistent geometry manager from the very beginning. If you don’t have your modules exported as volumes, you can easily do it after importing each of these geometries.

Hope this helps,

Thank you very much. I have exactly the same volume hierarchy, this is what I need.