gdetector
Loading...
Searching...
No Matches
GDetectorConstruction Class Reference

Builds and (optionally) reloads the Geant4 geometry from GEMC world definitions. More...

#include <gdetectorConstruction.h>

Public Member Functions

 GDetectorConstruction (std::shared_ptr< GOptions > gopts)
 Constructs a detector builder configured by the provided options.
 
G4VPhysicalVolume * Construct () override
 Geant4 geometry construction hook.
 
void ConstructSDandField () override
 Geant4 SD/field construction hook.
 
bool is_empty () const
 Returns whether the currently built geometry is empty.
 
void reload_geometry (SystemList sl)
 Reloads the geometry using a new list of GSystem objects.
 
void prepare_geometry_for_run ()
 Reinitializes geometry through Geant4 before running events.
 
std::shared_ptr< GDynamicDigitizationget_digitization_routines_for_sdname (const std::string &sd_name) const
 Returns the digitization routine for a given sensitive detector name.
 
std::shared_ptr< gdynamicdigitization::dRoutinesMapget_digitization_routines_map () const
 Returns the full map of digitization routines.
 
bool has_built_geometry () const
 Return whether a Geant4 world has been built.
 
std::unordered_map< std::string, G4Volume * > get_g4volumes_map () const
 Returns a map of built Geant4 volumes indexed by their GEMC/G4World names.
 
std::unordered_map< std::string, const GVolume * > get_gvolumes_flat_map () const
 Returns a flat map of GEMC volume descriptors indexed by their G4 names.
 
- Public Member Functions inherited from GBase< GDetectorConstruction >
 GBase (const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
 
 GBase (const std::shared_ptr< GLogger > &logger)
 
 GBase (const GBase &)=default
 
 GBase (GBase &&) noexcept=default
 
virtual ~GBase ()
 
GBaseoperator= (const GBase &)=default
 
GBaseoperator= (GBase &&) noexcept=default
 

Additional Inherited Members

- Protected Attributes inherited from GBase< GDetectorConstruction >
std::shared_ptr< GLoggerlog
 

Detailed Description

GDetectorConstruction is the module’s adapter between GEMC geometry/detector descriptions (GWorld/GSystem/GVolume) and Geant4 runtime objects (solids, logical volumes, physical volumes, sensitive detectors, and field managers).

Responsibilities:

  • Geometry construction:
    • Builds a GEMC world (GWorld) either from options or from an externally supplied list of systems.
    • Builds a Geant4 world (G4World) from that GEMC world.
  • Sensitive detector construction:
  • Electromagnetic field setup:
    • Creates (thread-local) field infrastructure through GMagneto when volumes declare an EM field.
    • Installs per-volume field managers into the Geant4 logical volumes.
  • Digitization routine setup:
    • Loads digitization plugins and associates them with each sensitive detector.

Threading notes:

  • Geant4 supports multi-threading with thread-local resources. The field container pointer (GMagneto) is stored as G4ThreadLocal to keep field state thread-safe.

Ownership notes:

  • The Geant4 runtime owns some resources after registration. For example, the field infrastructure is maintained via a raw pointer because ownership is transferred to Geant4 managers.

Definition at line 61 of file gdetectorConstruction.h.

Constructor & Destructor Documentation

◆ GDetectorConstruction()

GDetectorConstruction::GDetectorConstruction ( std::shared_ptr< GOptions > gopts)
explicit

The options object is retained for later use during Construct() and ConstructSDandField().

Parameters
goptsShared options instance (must remain valid for the lifetime of this detector construction object).

Definition at line 59 of file gdetectorConstruction.cc.

Member Function Documentation

◆ Construct()

G4VPhysicalVolume * GDetectorConstruction::Construct ( )
override

Called by Geant4 when it needs the detector geometry. This method:

  • Clears any previously built geometry stores (when reloading).
  • Constructs a GWorld either from options or from the previously provided systems list (see reload_geometry()).
  • Builds a G4World from the GWorld.
Returns
The Geant4 physical world volume.

Definition at line 68 of file gdetectorConstruction.cc.

◆ ConstructSDandField()

void GDetectorConstruction::ConstructSDandField ( )
override

Called by Geant4 to install sensitive detectors and EM fields after the geometry is built. This method:

  • Creates GSensitiveDetector instances on-demand by digitization name.
  • Assigns each sensitive detector to the relevant Geant4 logical volumes.
  • Creates field managers when volumes declare EM fields and installs them.
  • Loads digitization routines and binds them to the sensitive detectors.

Definition at line 102 of file gdetectorConstruction.cc.

◆ get_digitization_routines_for_sdname()

std::shared_ptr< GDynamicDigitization > GDetectorConstruction::get_digitization_routines_for_sdname ( const std::string & sd_name) const
inline

The returned object is the per-sensitive-detector dynamic digitization plugin.

Parameters
sd_nameSensitive detector name (digitization routine key).
Returns
Shared pointer to the digitization routine associated with sd_name.
Warning
This uses at() on the underlying map and will throw if sd_name is not present. Callers should ensure the detector name exists in the geometry sensitive-detector list.

Definition at line 145 of file gdetectorConstruction.h.

◆ get_digitization_routines_map()

std::shared_ptr< gdynamicdigitization::dRoutinesMap > GDetectorConstruction::get_digitization_routines_map ( ) const
inline

This exposes the internal mapping between sensitive detector names and their corresponding digitization plugins.

Returns
Shared pointer to the digitization routines map.

Definition at line 157 of file gdetectorConstruction.h.

◆ get_g4volumes_map()

std::unordered_map< std::string, G4Volume * > GDetectorConstruction::get_g4volumes_map ( ) const
inline

This method reports an error if the Geant4 world has not been constructed yet.

Returns
A copy of the map from volume name to G4Volume pointer.

Definition at line 178 of file gdetectorConstruction.h.

◆ get_gvolumes_flat_map()

std::unordered_map< std::string, const GVolume * > GDetectorConstruction::get_gvolumes_flat_map ( ) const
inline

Iterates all systems in the GEMC world and assembles a single map keyed by the fully-qualified G4 name ("system/volume"), providing access to pygemc-defined fields (solid type, parameters, position, rotation, mother, description).

Returns
Map from g4name to const GVolume pointer (owned by gworld).

Definition at line 194 of file gdetectorConstruction.h.

◆ has_built_geometry()

bool GDetectorConstruction::has_built_geometry ( ) const
inline

GUI pages can use this to avoid querying volume maps before startup or setup-tab reload has constructed geometry.

Definition at line 167 of file gdetectorConstruction.h.

◆ is_empty()

bool GDetectorConstruction::is_empty ( ) const
inline

This delegates to the underlying G4World instance, which tracks whether volumes were successfully built.

Returns
True if no geometry is currently present, false otherwise.

Definition at line 108 of file gdetectorConstruction.h.

◆ prepare_geometry_for_run()

void GDetectorConstruction::prepare_geometry_for_run ( )

Setup-tab reloads build an immediate master-world preview for the GUI. Before BeamOn, call this method so Geant4 destroys old geometry stores re-invokes detector construction, and initializes the run manager without touching visualization models that still reference the preview world.

Definition at line 357 of file gdetectorConstruction.cc.

◆ reload_geometry()

void GDetectorConstruction::reload_geometry ( SystemList sl)

This method updates the internal systems list used by Construct(). If a Geant4 run manager exists, it immediately replaces the master world volume and re-installs sensitive detectors and fields so GUI pages can inspect the reloaded geometry.

Parameters
slNew list of systems to build from. If empty, the previous system list is kept (useful for tests or when only forcing a rebuild).

Definition at line 331 of file gdetectorConstruction.cc.


The documentation for this class was generated from the following files: