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.
 
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.
 
std::unordered_map< std::string, G4Volume * > get_g4volumes_map () const
 Returns a map of built Geant4 volumes indexed by their GEMC/G4World 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 59 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 22 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 31 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 74 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 132 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 144 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 155 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 106 of file gdetectorConstruction.h.

◆ 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 triggers a re-definition of the world volume and re-installs sensitive detectors and fields.

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 190 of file gdetectorConstruction.cc.


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