GDML and CAD Factories

Importing GDML and CAD models in gemc

gemc can import models in GDML [1] format or directly from CAD models [2].

For example, to import three detectors:

  • one in the usual TEXT format, named “drift_chambers”
  • one in GDML, named “target” (filename is target.gdml)
  • one in CAD, named “beamline” (filename is target.stl or target.ply)

you would add the following lines in the gcard:

<detector name="drift_chambers" factory="TEXT" variation="lH2"/>
<detector name="target" factory="GDML"/>
<detector name="beamline" factory="CAD"/>

Notice you do not need the variation tag for the GDML and CAD detector factories.

Importing CAD models from a directory

A single directory can be specified in the gcard. GEMC will look for and load all valid CAD files inside that directory. For example:

<detector name="beamline/" factory="CAD"/>

will load all CAD files inside “beamline”. Only files with these extensions will be loaded: ”.stl” or ”.ply” or ”.obj”. Any other format will be ignored.

GEMC attributes to models

Attributes can be added on the fly. This includes:

  • material
  • visualization attributes (color, surface style)
  • sensitivity

Attributes are assigned by using XML files (extension: ”.gxml”). For example the following line will change the color, material of an imported volume named “target” and assign flux sensitivity so that hits can be recorded:

<volume name="target" color="99ff00" material="G4_Pb" sensitivity="flux" identifiers="id manual 1"/>

CAD vs GDML Attributes

  • A GDML file can contain many volumes. Their attributes are assigned by a .gxml file with the same name as the system. For example, to set the attributes of the target of the gcard above, a filename “target.gxml” can be used:

          <volume name="inner_target_vol" color="8899dd" material="lH2"/>
  • A CAD file contains only one volume. Many cad files can be imported and the attributes of all of them can be set by filename “cad.gxml””:

          <volume name="beamline" color="8899dd" material="G4_Al"/>

CAD Examples

You can find many autocad examples here.

Step to Mesh with FreeCad

Most autocad software can export models directly in the mesh format needed (STL, PLY or OBJ). If that’s not possible you can use Freecad [3] to convert step objects to stl format. Here are the steps:

  1. Change the View > Workbench > Mesh Design
  2. Select the object
  3. Click on Meshes > Create Mesh From Shape
  4. Select precision desired - click OK
  5. Click on the new meshed object and File > Export to a STL file (or PLY or OBJ).


[1]Geometry Description Markup Language. It’s an application independent geometry description based on XML. See gdml at cern.
[2]STL (STereoLithography), PLY (Standard Polygon Format), OBJ (Alias Waveform Object) file formats are available.