Welcome to legendtools’s documentation!¶
This package provides shared code for the pyg4ometry-based Monte Carlo geometries for the LEGEND-200 and LEGEND-1000 experiments.
For geometry writers¶
If your geometry creation script/notebook/application is already set up correctly, you can use our extensions to the pyg4ometry API to control the package’s output.
Detector registration and visualization attributes will be stored into the output GDML file.
Registering detectors for use with remage¶
On a physical volume instance, you can attach a
pygeom_active_detector,
e.g.
from pygeomtools import RemageDetectorInfo
pv = g4.PhysicalVolume(...)
# attach an active detector to this physical volume.
pv.set_pygeom_active_detector(
RemageDetectorInfo(
"optical", # detector type. The available options are defined by remage.
1, # detector id in remage.
{"some": "metadata"}, # user-defined data (optional) that is stored into GDML.
)
)
More optional attributes available to control the detector registration are
documented in pygeomtools.detectors.RemageDetectorInfo.
Adjusting the visualization¶
On a logical volume instance, you can set
pygeom_color_rgba,
e.g.
lv = g4.LogicalVolume(...)
# hide this volume in the visualization
lv.pygeom_color_rgba = False
# set the vis coloring to the given RGBA value. All 4 numbers should be given in the range 0–1.
lv.pygeom_color_rgba = (r, g, b, a)
For application developers (general setup)¶
The added information will not be written out directly when using only
pyg4ometry’s writing functionality. However, legend-pygeom-tools provides the
single function pygeomtools.write.write_pygeom() that combines committing
the extra information to the auxiliary data stores and writing everything to the
output file:
from pygeomtools import detectors, geometry, visualization, write_pygeom
reg = geant4.Registry()
# your geometry building
# include some of the things described above (detectors, coloring)
# ...
# commit all auxiliary data to the registry and write out the GDML file. Use None as
# file name to suppress writing a file (e.g. when you only want to visualize)
write_pygeom(reg, "test.gdml")
For geometry reading applications¶
legend-pygeom-tools also provides functionality for applications that need to
load geometry files. These operate on a registry loaded via
pyg4ometry.gdml.Reader from a file previously created with
legend-pygeom-tools. These functions can be used to get the mapping of volumes
to detector uid, and can also get the attached metadata snippets:
Some functions also operate on the mapping of output tables to detector properties. This follows the default behaviour of remage that combines multiple detectors into a signel output table if advised to do so: