Error: Unsupported GDML Tag Used :loop. Please Check Geometry/Schema

Hi everyone,

I am trying to create a geometry using loops in gdml.

You can find here a simple example of what I’m trying to do:

<!DOCTYPE gdml [
<!ENTITY materials SYSTEM "https://rest-for-physics.github.io/materials/materials.xml">
]>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">

  <define>
    <variable name="world_size" value="700" />

    <!-- The vessel definitions -->  
    <constant name="vesselThickness" value="10" />    <!--in mm's -->
    <constant name="vesselXSize" value="100" />
    <constant name="vesselYSize" value="100" />
    <constant name="vesselZSize" value="100"/>
    <position name="vesselPosition" unit="mm" x="0" y="0" z="0"/>

    <matrix name="m" coldim="5" values="0 100 200 300 400"/>
    <variable name="i" value="0" />
    <variable name="num" value="5" />
    
  </define>

  &materials;

  <solids>
    <box name="WorldSolid" x="world_size" y="world_size" z="world_size" lunit="mm"/>

    <loop for="i" from="1" to="num" step="1">
      <box name="vesselSolid[i]" x="vesselXSize" y="vesselYSize" z="vesselZSize" lunit="mm"/>
    </loop>

    <box name="gasSolid"  x="vesselXSize-2*vesselThickness" y="vesselYSize-2*vesselThickness" z="vesselZSize-2*vesselThickness" lunit="mm" />

    <!-- <subtraction name="vesselSolid"> -->
    <!--   <first ref="solidBox"/> -->
    <!--   <second ref="gasSolid"/> -->
    <!-- </subtraction> -->

  </solids>
  
  <structure>
    <!-- {{{ Volumes definition (material and solid assignment) -->

    <loop for="i" from="1" to="num" step="1">
      <volume name="vesselVolume[i]">
	<materialref ref="G4_Cu" />
	<solidref ref="vesselSolid[i]" />
      </volume>
    </loop>
    
    <volume name="gasVolume">
      <materialref ref="G4_GLASS_PLATE"/>
      <solidref ref="gasSolid"/>      
    </volume>

    <!-- {{{ Physical volume definition (volume and position assignment) -->
    <volume name="World">
      <materialref ref="G4_AIR"/>
      <solidref ref="WorldSolid"/>

      <loop for="i" from="1" to="num" step="1">
	<physvol>
	  <volumeref ref="vesselVolume[i]" />
	  <position name="pos[i]" x="0" y="0" z="m[1,i]"/>
	</physvol>
      </loop>

      <physvol name="gas">
	<volumeref ref="gasVolume"/>
	<position name="gasPosition" x="0" y="0" z="0"/>
      </physvol>

    </volume>
    
  </structure>

  <setup name="Default" version="1.0">
    <world ref="World"/>
  </setup>
</gdml>

In a new root session, I use the TGeoManager() class to visualize the geometry and here is the output:

Filename : box.gdml
TRestGDMLParser: Initializing variables
TRestGDMLParser: Replacing expressions in GDML
TRestGDMLParser: Replacing entity: materials, file: https://rest-for-physics.github.io/materials/materials.xml
TRestGDMLParser: Creating temporary file at: "/uni-mainz.de/homes/cgirardc/.rest/gdml/PID655383_box.gdml"
Info in <TGeoManager::Import>: Reading geometry from file: /uni-mainz.de/homes/cgirardc/.rest/gdml/PID655383_box.gdml
Info in <TGeoManager::TGeoManager>: Geometry GDMLImport, Geometry imported from GDML created
Error: Unsupported GDML Tag Used :loop. Please Check Geometry/Schema.
Error: Unsupported GDML Tag Used :loop. Please Check Geometry/Schema.
Info in <TGeoManager::SetTopVolume>: Top volume is World. Master volume is World
Info in <TGeoNavigator::BuildCache>: --- Maximum geometry depth set to 100
Info in <TGeoManager::CheckGeometry>: Fixing runtime shapes...
Info in <TGeoManager::CheckGeometry>: ...Nothing to fix
Info in <TGeoManager::CloseGeometry>: Counting nodes...
Info in <TGeoManager::Voxelize>: Voxelizing...
Info in <TGeoManager::CloseGeometry>: Building cache...
Info in <TGeoManager::CountLevels>: max level = 1, max placements = 1
Info in <TGeoManager::CloseGeometry>: 2 nodes/ 3 volume UID's in Geometry imported from GDML
Info in <TGeoManager::CloseGeometry>: ----------------modeler ready----------------
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
(int) 0

and the vessels do not appear in the visualization.

Loops are definitely supported by GDML (see documentation section 3.5.1 Loops).

Am I missing something?

Thank you for your help


ROOT Version: 6.26/10
Platform: Debian GNU/Linux 11
Compiler: g++ 10.4.0


Hello @girardcarillo,

Unfortunately I don’t think ROOT supports the full gdml schema and things such as loops are not implemented. There are some older posts suggesting this is the case, and I don’t think this has been implemented since: GDML <loop> tag - #2 by agheata, GDML loop tag v5.22.00

Taking a glance into the GDML parser source code I cannot see anything related to gdml loops: ROOT: geom/gdml/src/TGDMLParse.cxx Source File (around line 390). Perhaps @agheata can confirm this.

Personally what I do when I want to work with a very complex geometry is to use gdml but not write it directy and instead use a tool such as python to write the gdml and leave all the complexity there. This (GitHub - SciProgCentre/gdml.kt: GDML bindings for kotlin-multiplatform) is a tool to do this, you might find it useful, but its not actively maintained and you might face some issues.

Hi @lobis,

Thank you very much for your answer.
I think you’re right, as I found other issues reported with Root not supporting other features of GDML.

So you’re right, writing a Python code that would write my GDML file should be the perfect option.
I just thought that it would be very convenient to use GDML loops.
Maybe in the future!

Thanks again