Merging gdml using TGeoManager

Dear ROOTers,

I am a beginner to ROOT, hence my experience is quite limited and I have a general question on geometry objects.
Assuming two (or even more) gdml files describing different parts of a geometry - is there a way within ROOT to merge them and write out a top-level gdml file holding all information from the single files?

Any help and information is highly appreciated!

maybe @agheata knows…

You can try something like:

std::vector<std::string> listOfGDMLFiles;
// -> fill the list with files
TGeoManager *geom = new TGeoManager("gometry from many files", "");
TGeoVolume *topVolume = nullptr;
TGDMLParse parser;
for (auto file : listOfGDMLFiles) {
  TGeoVolume *top = parser.GDMLReadFile(file.c_str());
  if (top) topVolume = top;
if (topVolume) {

Never tested, but there is hope that this might work. At least one of the gdml files should define the world volume, otherwise it has to be set by hand. The assumption is that the gdml files are complementary, i.e. if you would concatenate them the Import should work.
Let me know if there are issues.

Thanks a lot for the quick reply! I could actually execute the code above and read in a vector of files. However, I do not yet understand where in this code both gdml files are merged.
And when I use the gGeoManager to plot the result, like

TGeoVolume *top = gGeoManager->GetTopVolume();

it displays only the last geometry but not both as I would expect. Maybe I have implemented the vector holding the strings in a wrong way:

std::vector<std::string> listOfGDMLFiles;
listOfGDMLFiles = {"geom_1.gdml","geom_2.gdml"};

Maybe it is just a matter of how to display them; If I use GetListOfVolumes(), volumes from both files are listed.
Thanks again for support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.