pygeomtools package¶
Subpackages¶
- pygeomtools.materials package
- Submodules
- pygeomtools.materials.base module
- pygeomtools.materials.legend module
LegendMaterialRegistryLegendMaterialRegistry._tpb()LegendMaterialRegistry.acrylLegendMaterialRegistry.borosilicateLegendMaterialRegistry.epoxyLegendMaterialRegistry.gaseousargonLegendMaterialRegistry.liquidargonLegendMaterialRegistry.metal_copperLegendMaterialRegistry.metal_phosphor_bronzeLegendMaterialRegistry.metal_siliconLegendMaterialRegistry.metal_steelLegendMaterialRegistry.metal_tantalumLegendMaterialRegistry.nylonLegendMaterialRegistry.peekLegendMaterialRegistry.penLegendMaterialRegistry.pmmaLegendMaterialRegistry.pmma_outLegendMaterialRegistry.pmt_airLegendMaterialRegistry.ps_fibersLegendMaterialRegistry.rockLegendMaterialRegistry.silicaLegendMaterialRegistry.teflonLegendMaterialRegistry.tetratexLegendMaterialRegistry.tpb_on_fibersLegendMaterialRegistry.tpb_on_nylonLegendMaterialRegistry.tpb_on_tetratexLegendMaterialRegistry.tyvekLegendMaterialRegistry.ultemLegendMaterialRegistry.vacuumLegendMaterialRegistry.vm2000LegendMaterialRegistry.water
Submodules¶
pygeomtools.detectors module¶
Assignment of sensitive detectors to physical volumes, for use in remage.
- class pygeomtools.detectors.RemageDetectorInfo(detector_type: "Literal['optical', 'germanium', 'scintillator']", uid: 'int', metadata: 'object | None' = None, allow_uid_reuse: 'bool' = False, ntuple_name: 'str | None' = None)¶
Bases:
object- Parameters:
- pygeomtools.detectors.__patch_pyg4_pv()¶
monkey-patch a new function onto every PhysicalVolume instance.
- pygeomtools.detectors._get_rmg_detector_aux(registry, *, raise_on_missing=True)¶
- pygeomtools.detectors.check_detector_uniqueness(registry, ignore_duplicate_uids=None)¶
Check that each sensitive detector uid is only used once.
- pygeomtools.detectors.generate_detector_macro(registry, filename)¶
Create a Geant4 macro file containing the defined active detector volumes for use in remage.
- pygeomtools.detectors.get_all_senstables(registry, type_filter=None)¶
Load all registered sensitive detector tables with their metadata (from GDML).
- Parameters:
- Return type:
- pygeomtools.detectors.get_all_sensvols(registry, type_filter=None)¶
Load all registered sensitive detectors with their metadata (from GDML).
- Parameters:
- Return type:
- pygeomtools.detectors.get_senstable_by_uid(registry, uid)¶
Get the table name and detector metadata for the detector with remage detector ID uid.
- Parameters:
- Return type:
tuple[str, RemageDetectorInfo] | None
- pygeomtools.detectors.get_sensvol_by_uid(registry, uid)¶
Get the volume name and detector metadata for the detector with remage detector ID uid.
Note
If multiple volumes share the uid, a list of tuples is returned.
- Parameters:
- Return type:
tuple[str, RemageDetectorInfo] | list[tuple[str, RemageDetectorInfo]] | None
- pygeomtools.detectors.get_sensvol_metadata(registry, name)¶
Load metadata attached to the given sensitive volume (from GDML).
- pygeomtools.detectors.walk_detectors(pv)¶
Iterate over all physical volumes that have a
RemageDetectorInfoattached.Important
this only returns instances previously set via
get_pygeom_active_detector(), not data loaded from GDML. Useget_all_sensvols()instead for that use case.- Parameters:
pv (PhysicalVolume | LogicalVolume | Registry)
- Return type:
Generator[tuple[PhysicalVolume, RemageDetectorInfo], None, None]
- pygeomtools.detectors.write_detector_auxvals(registry)¶
Append an auxiliary structure, storing the sensitive detector volume information.
Note
see Metadata stored into GDML for a reference of the written structure.
- Parameters:
registry (Registry)
- Return type:
None
pygeomtools.geometry module¶
Helper functions for geometry construction.
- pygeomtools.geometry.check_materials(registry)¶
Check against some common problems of materials.
- Parameters:
registry (Registry)
- Return type:
None
- pygeomtools.geometry.check_registry_sanity(v, registry)¶
Check recursively if all children in the volume and material tree have the correct registry instance attached.
- Parameters:
v – object to recursively check to have the right registry.
registry (Registry) – the expected registry to compare against
- Return type:
None
Note
This function prevents an easy-to-miss problem using pyg4ometry: If different (or no) registries are used inside an object structure, this might lead to unexpected results in GDML output.
- pygeomtools.geometry.get_approximate_volume(lv)¶
Get the cubic volume of the logical volume, subtracting the cubic volumes of the daughter volumes.
Note
The result is not an exact number, but is based on the mesh calculated internally by pyg4ometry. By using
pyg4ometry.config.setGlobalMeshSliceAndStack()before loading or creating the geometry, you can adjust how fine the mesh will be.- Parameters:
lv (LogicalVolume)
- Return type:
- pygeomtools.geometry.print_volumes(registry, which, include_volume=False)¶
Print details about volume registered in the registry.
- Parameters:
which (Literal['logical' | 'physical' | 'detector']) – the type of volumes to print. Can be logical, physical or detector, to print details about logical volumes, physical volumes or remage detector registrations.
include_volume (bool) – if listing logical volumes, include the approximate volume as determined with
get_approximate_volume().registry (g4.Registry)
- Return type:
None
pygeomtools.region module¶
- class pygeomtools.region.Region(name)¶
Bases:
objectStore the definition of a G4Region in a GDML registry.
Important
All of the values ecut/poscut/pcut/gamcut must be explicitly set, otherwise Geant4 would assume a production cut of 0 mm, which is probably undesired.
- Parameters:
name (str)
- add_volume(vol)¶
- Parameters:
vol (str | LogicalVolume)
- Return type:
None
pygeomtools.utils module¶
- pygeomtools.utils.load_dict(fname, ftype=None)¶
Load a text file as a Python dict.
Deprecated since version 0.0.8: Use
dbetto.utils.load_dict()instead.
- pygeomtools.utils.load_dict_from_config(config, key, default)¶
Helper functions to load nested data from a config file.
If
keyis in the config file - and it refers to a string: load a JSON/YAML file from that path. - and it refers to a dict: use that directlyelse, the default value is loaded via the
defaultcallable.
pygeomtools.viewer module¶
An opionionated wrapper around pyg4ometry.visualization.VtkViewerNew.
- pygeomtools.viewer._add_light_and_shadow(v, light_pos, shadow)¶
- pygeomtools.viewer._add_points(v, points, color=(1, 1, 0, 1), size=5)¶
- Return type:
None
- pygeomtools.viewer._color_override_matches(overrides, name)¶
- pygeomtools.viewer._color_recursive(lv, viewer, overrides, level=0)¶
- Parameters:
lv (LogicalVolume)
viewer (ViewerBase)
overrides (dict)
level (int)
- Return type:
None
- pygeomtools.viewer._export_png(v, file_name='scene.png')¶
- Parameters:
file_name (str)
- Return type:
None
- pygeomtools.viewer._load_points(lh5_file, point_table, columns, n_rows, evtid=None)¶
- pygeomtools.viewer._set_camera(v, focus=None, up=None, pos=None, dolly=None, parallel=None)¶
- pygeomtools.viewer.visualize(registry, scenes=None, points=None)¶
Open a VTK-based viewer for the geometry and scene definition.
- Parameters:
registry (Registry) – registry instance containing the geometry to view.
scenes (dict | None) – loaded scene definition file. note that the fine_mesh key is ignored and has to be set before loading/constructing the geometry.
points – show points, additionally to the points defined in the scene config.
- Return type:
None
pygeomtools.visualization module¶
- pygeomtools.visualization._color_macro_recursive(lv, macro_lines)¶
- Parameters:
lv (LogicalVolume)
macro_lines (dict)
- Return type:
None
- pygeomtools.visualization.generate_color_macro(registry, filename)¶
Create a Geant4 macro file containing the defined visualization attributes.
Note
This only uses the values from
pygeom_color_rgba, and not the values already written to the auxiliary structure in the GDML file. Useload_color_auxvals_recursive()to load these values, if necessary.
- pygeomtools.visualization.load_color_auxvals_recursive(lv)¶
Load the color values committed to the auxiliary structure for later use.
This populates
pygeom_color_rgbaagain.- Parameters:
lv (LogicalVolume)
- Return type:
None
- pygeomtools.visualization.write_color_auxvals(registry)¶
Append an auxiliary structure to the registry, with the color information from
pygeom_color_rgba.- Parameters:
registry (Registry)
- Return type:
None
pygeomtools.write module¶
- pygeomtools.write._run_all_checks(reg, write_vis_auxvals=True, ignore_duplicate_uids=False)¶
- pygeomtools.write.write_pygeom(reg, gdml_file=None, write_vis_auxvals=True, *, ignore_duplicate_uids=False)¶
Commit all auxiliary data to the registry and write out a GDML file.
- Parameters:
reg (Registry) – the pyg4ometry registry containing the geometry to be written.
gdml_file (str | PathLike | None) – GDML file to write, or
Nonejust for performing the other actions.write_vis_auxvals (bool) – if
False, do not store colors in the output file.ignore_duplicate_uids (bool | set[int]) – skip the check for duplicate detector uids for all, or just some, uids.
- Return type:
None
- pygeomtools.write.write_pygeom_aux_only(reg, gdml_file=None, write_vis_auxvals=True, *, ignore_duplicate_uids=False)¶
Commit all auxiliary data to the registry and write out a GDML file that only contains the auxiliary data.
All volumes and their relation will not be written out.
- Parameters:
reg (Registry) – the pyg4ometry registry containing the geometry to be written.
gdml_file (str | PathLike | None) – GDML file to write, or
Nonejust for performing the other actions.write_vis_auxvals (bool) – if
False, do not store colors in the output file.ignore_duplicate_uids (bool | set[int]) – skip the check for duplicate detector uids for all, or just some, uids.
- Return type:
None