pygeomtools package

Subpackages

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:
  • detector_type (Literal['optical', 'germanium', 'scintillator'])

  • uid (int)

  • metadata (object | None)

  • allow_uid_reuse (bool)

  • ntuple_name (str | None)

allow_uid_reuse: bool = False

Allow assigning multiple volumes to this detector UID.

detector_type: Literal['optical', 'germanium', 'scintillator']

remage detector type.

metadata: object | None = None

Attach arbitrary metadata to this sensitive volume. This will be written to GDML as JSON.

ntuple_name: str | None = None

Optional override of the ntuple name.

uid: int

remage detector UID.

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)
Parameters:
Return type:

Auxiliary | None

pygeomtools.detectors.check_detector_uniqueness(registry, ignore_duplicate_uids=None)

Check that each sensitive detector uid is only used once.

Parameters:
  • ignore_duplicate_uids (set[int] | None) – a set of uids to exclude from the uniqueness check.

  • registry (Registry)

Return type:

bool

pygeomtools.detectors.generate_detector_macro(registry, filename)

Create a Geant4 macro file containing the defined active detector volumes for use in remage.

Parameters:
Return type:

None

pygeomtools.detectors.get_all_senstables(registry, type_filter=None)

Load all registered sensitive detector tables with their metadata (from GDML).

Parameters:
Return type:

dict[str, RemageDetectorInfo]

pygeomtools.detectors.get_all_sensvols(registry, type_filter=None)

Load all registered sensitive detectors with their metadata (from GDML).

Parameters:
Return type:

dict[str, RemageDetectorInfo]

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).

Parameters:
Return type:

AttrsDict | None

pygeomtools.detectors.walk_detectors(pv)

Iterate over all physical volumes that have a RemageDetectorInfo attached.

Important

this only returns instances previously set via get_pygeom_active_detector(), not data loaded from GDML. Use get_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:

Quantity

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: object

Store 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_to_gdml(registry)
Parameters:

registry (Registry)

Return type:

Auxiliary

add_volume(vol)
Parameters:

vol (str | LogicalVolume)

Return type:

None

ecut: Quantity | None = None

Production cut (length) for electrons.

gamcut: Quantity | None = None

Production cut (length) for gammas.

name: str

name of this Geant4 region.

pcut: Quantity | None = None

Production cut (length) for protons.

poscut: Quantity | None = None

Production cut (length) for positrons.

set_cuts(default=<Quantity(0.1, 'millimeter')>)

Set all production cuts to the specified length.

Parameters:

default (Quantity)

Return type:

None

uekinMin: Quantity | None = None

Minimum remaining kinetic energy for a track.

urangMin: Quantity | None = None

Minimum remaining range for a track.

ustepMax: Quantity | None = None

Maximum step length.

utimeMax: Quantity | None = None

Maximum global time for a track.

utrakMax: Quantity | None = None

Maximum total track length.

volumes: list[str]

volumes to add this region to.

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.

Parameters:
  • fname (str)

  • ftype (str | None)

Return type:

dict

pygeomtools.utils.load_dict_from_config(config, key, default)

Helper functions to load nested data from a config file.

  • If key is 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 directly

  • else, the default value is loaded via the default callable.

Parameters:
Return type:

AttrsDict

pygeomtools.viewer module

An opionionated wrapper around pyg4ometry.visualization.VtkViewerNew.

pygeomtools.viewer._add_light_and_shadow(v, light_pos, shadow)
Parameters:
Return type:

None

pygeomtools.viewer._add_points(v, points, color=(1, 1, 0, 1), size=5)
Return type:

None

pygeomtools.viewer._color_override_matches(overrides, name)
Parameters:
pygeomtools.viewer._color_recursive(lv, viewer, overrides, level=0)
Parameters:
Return type:

None

pygeomtools.viewer._export_png(v, file_name='scene.png')
Parameters:
Return type:

None

pygeomtools.viewer._load_points(lh5_file, point_table, columns, n_rows, evtid=None)
Parameters:
Return type:

ndarray

pygeomtools.viewer._set_camera(v, focus=None, up=None, pos=None, dolly=None, parallel=None)
Parameters:
Return type:

None

pygeomtools.viewer._set_camera_scene(v, sc)
Parameters:
Return type:

None

pygeomtools.viewer.vis_gdml_cli(args=None)
Parameters:

args (list[str] | None)

Return type:

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:
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. Use load_color_auxvals_recursive() to load these values, if necessary.

Parameters:
Return type:

None

pygeomtools.visualization.load_color_auxvals_recursive(lv)

Load the color values committed to the auxiliary structure for later use.

This populates pygeom_color_rgba again.

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)
Parameters:
Return type:

None

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 None just 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 None just 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