Skip to content

Geant4

The Geant4 converter produces two files: a GDML geometry file and a macro file that configures the beam, physics, and scoring.

FilePurposeFormat
geometry.gdmlGeometry definitionXML (Geometry Description Markup Language)
run.macSimulation parametersGeant4 macro commands

GDML (Geometry Description Markup Language) is an XML schema for describing detector geometries. The converter generates a valid GDML file that Geant4 loads at runtime.

<?xml version="1.0" encoding="UTF-8"?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/...">
<define>
<!-- Positions and rotations -->
<position name="pos_water" x="0" y="0" z="10" unit="cm"/>
<rotation name="rot_water" x="0" y="0" z="0" unit="deg"/>
</define>
<materials>
<!-- Material definitions -->
<material name="G4_WATER"/>
</materials>
<solids>
<!-- Geometry primitives -->
<box name="world_solid" x="200" y="200" z="200" lunit="cm"/>
<tube name="water_solid" rmin="0" rmax="5" z="20"
startphi="0" deltaphi="360" aunit="deg" lunit="cm"/>
</solids>
<structure>
<!-- Logical and physical volumes -->
<volume name="water_log">
<materialref ref="G4_WATER"/>
<solidref ref="water_solid"/>
</volume>
<volume name="world_log">
<materialref ref="G4_Galactic"/>
<solidref ref="world_solid"/>
<physvol>
<volumeref ref="water_log"/>
<positionref ref="pos_water"/>
<rotationref ref="rot_water"/>
</physvol>
</volume>
</structure>
<setup name="Default" version="1.0">
<world ref="world_log"/>
</setup>
</gdml>
Editor FigureGDML SolidElement
Box<box>x, y, z (half-lengths)
Cylinder<tube>rmin, rmax, z, startphi, deltaphi
Sphere<orb>r

Important: GDML uses half-lengths for box dimensions. The converter divides the editor’s full dimensions by 2.

GDML organizes geometry as a tree of volumes:

  1. World volume — outermost bounding box (auto-generated)
  2. Physical volumes — placed inside the world with position and rotation
  3. Logical volumes — link a solid shape to a material

The converter flattens the editor’s zone-based CSG into GDML’s volume hierarchy. Each zone becomes a physical volume placed in the world.

Note: Geant4’s GDML supports boolean solids (<subtraction>, <union>, <intersection>) for CSG. The converter may use these for complex zone definitions, but simple zones map directly to placed volumes.

The macro file configures everything that isn’t geometry:

/run/initialize
/gun/particle proton
/gun/energy 150 MeV
/gun/position 0 0 -50 cm
/gun/direction 0 0 1
/run/beamOn 10000
SectionCommandsPurpose
Initialization/run/initializeInitialize the Geant4 kernel
Beam/gun/particle, /gun/energy, /gun/position, /gun/directionPrimary particle source
PhysicsPhysics list configurationEnergy thresholds, models
Scoring/score/create/..., /score/quantity/...Detector meshes and quantities
Execution/run/beamOn NStart simulation with N primaries
geant4/
├── __init__.py
├── parser.py # Geant4Parser orchestration
└── ...
class Geant4Parser(Parser):
def parse_configs(self, json_data):
# Parse beam, geometry, materials, scoring from JSON
self._parse_beam(json_data)
self._parse_geometry(json_data)
self._parse_materials(json_data)
self._parse_scoring(json_data)
def get_configs_json(self):
return {
"geometry.gdml": self._render_gdml(),
"run.mac": self._render_macro(),
}

The Geant4 parser is more compact than SHIELD-HIT12A or FLUKA because:

  • GDML is XML (structured, not fixed-width)
  • The macro format is line-oriented commands (no column alignment needed)

The converter builds the GDML XML using string templates (not an XML library). Sections are rendered in order:

  1. <define> — positions and rotations for each figure
  2. <materials> — material references (Geant4 built-in names like G4_WATER)
  3. <solids> — one solid element per figure, plus the world solid
  4. <structure> — logical volumes (solid + material) and physical volumes (placement)
  5. <setup> — points to the world volume

Geant4 uses the NIST material database. The converter maps YAPTIDE materials to Geant4 names:

YAPTIDE MaterialGeant4 Name
WaterG4_WATER
AirG4_AIR
AluminumG4_Al
VacuumG4_Galactic
CustomDefined inline with element composition

When running via the Geant4 WebAssembly build in the browser, the converter’s output is consumed directly by the in-browser Geant4 instance. The files are passed as in-memory strings — never written to disk.

See Geant4 WebAssembly for the browser execution flow.

LimitationDetail
CSG complexityComplex boolean zone operations may not translate cleanly to GDML volume hierarchy
ScoringNot all YAPTIDE scoring quantities have Geant4 equivalents
Physics listsLimited physics list configuration compared to native Geant4 macros
RotationNested rotations require careful coordinate transformation
ProblemCauseFix
Invalid GDML schemaMalformed XML outputCheck GDML rendering for unclosed tags
Volume overlapPlaced volumes intersect without boolean subtractionVerify zone-to-volume mapping
Wrong unitsGDML defaults may differ from editor conventionsEnsure lunit="cm" and aunit="deg" are set
Missing materialMaterial name not in Geant4 NIST databaseMap to correct G4_* name or define custom