Loading Geometry

Generally, a reader class is provided for each format. The reader is created, then told to load a file, and it creates a Registry object (see Registry) containing the model. The registry is the final object from a reader, and its top-most volume can be used for visualisation or other operations.

In directory pyg4ometry/test/gdmlG4examples/ChargeExchangeMC/

1import pyg4ometry
2
3r = pyg4ometry.gdml.Reader("lht.gdml")
4l = r.getRegistry().getWorldVolume()
5v = pyg4ometry.visualisation.VtkViewerColouredMaterial()
6v.addLogicalVolume(l)
7v.view()
../_images/viewing-gdml.png

Geant4 example GDML from ChargeExchangeMC example.

In directory pyg4ometry/test/flukaCompoundExamples

Note FLUKA geometry can be loaded but cannot be visualised directly without conversion to a Geant4 model. This is not necessary for loading, but shown here.

 1import pyg4ometry
 2
 3r = pyg4ometry.fluka.Reader("corrector-dipole2.inp")
 4flukaRegistry = r.flukaregistry
 5
 6geantRegistry = pyg4ometry.convert.fluka2Geant4(flukaRegistry)
 7
 8l = geantRegistry.getWorldVolume()
 9v = pyg4ometry.visualisation.VtkViewerColouredMaterial()
10v.addLogicalVolume(l)
11v.view()
../_images/viewing-fluka.png

FLUKA example of a dipole magnet.

In directory pyg4ometry/test/root2Gdml

1import pyg4ometry
2
3r = pyg4ometry.io.ROOTTGeo.Reader("example.root")
4l = r.getRegistry().getWorldVolume()
5v = pyg4ometry.visualisation.VtkViewerColouredMaterial()
6v.addLogicalVolume(l)
7v.view()
../_images/viewing-root.png

ROOT example of Geant4’s LHT geometry.

In directory pyg4ometry/test/stl

STL files are typically used for a single watertight solid mesh. This mesh is converted to a TesselatedSolid and then a logical volume which can be placed in a geometry. In directory pyg4ometry/test/stl.

import pyg4ometry

reg = pyg4ometry.geant4.Registry()
r = pyg4ometry.stl.Reader("utahteapot.stl", reg)
s = r.getSolid()
copper = pyg4ometry.geant4.MaterialPredefined("G4_Cu", reg)
l = pyg4ometry.geant4.LogicalVolume(s, copper, "utahteapot_lv", reg)
v = pyg4ometry.visualisation.VtkViewerColouredMaterial()
v.addLogicalVolume(l)
v.view()
../_images/tutorial2.png
alt:

Example of STL loading in pyg4ometry

In directory pyg4ometry/test/freecad

1import pyg4ometry
2
3r = pyg4ometry.freecad.Reader("08_AshTray.step")
4r.relabelModel()
5r.convertFlat()
6l = r.getRegistry().getWorldVolume()
7v = pyg4ometry.visualisation.VtkViewer()
8v.addLogicalVolume(l)
9v.view()
Example of STEP loading in pyg4ometry