The GSensitiveDetector module provides the thread-local sensitive detector implementation used by GEMC to translate Geant4 step information into GHit objects stored in a Geant4 hits collection.
Conceptually, this module is the bridge between:
the Geant4 sensitive-detector callback interface (G4VSensitiveDetector), and
GEMC digitization plugins (GDynamicDigitization) that decide whether to process a step and how to interpret a touchable.
The high-level event flow is:
Event initialization: allocate and register the hits collection and reset per-event caches.
Step processing: optionally skip steps, build one or more touchables, and create or update hits accordingly.
End of event: finalize any per-event bookkeeping (the actual storage is handled by the Geant4 event).
Ownership and lifecycle
Threading model: GSensitiveDetector instances are expected to be thread-local, as indicated by inline comments and usage patterns.
Touchable registry: a registry of volume-name to GTouchable mappings is populated during detector construction (e.g., by GDetectorConstruction). After registration, this module treats the registry as authoritative for the run.
Event-owned hit collection: the Geant4 hits collection is created at Initialize() and registered into the event. The event lifecycle determines when the hits collection is reclaimed.
Architecture
Architecture and design notes
Key responsibilities
Maintain a per-event map of hit-cell keys (hitsByCellKey) to decide whether a step creates a new hit or updates an existing one.
Store hits in a G4THitsCollection<GHit> (typedef GHitsCollection).
Processing model
For each step, the plugin can return one or more processed touchables. This supports cases such as segmentation or step splitting where a single Geant4 step contributes to multiple logical detector elements.
For each processed touchable:
assign the track id for later identification and grouping,
decide if it is new for this event,
either create a new GHit or locate the existing GHit and append step information.
Available options and usage
gsensitivedetector::defineOptions() returns a logger-scoped GOptions container but defines no module-specific keys. The shared verbosity and debug option groups control messages for the gsd logger.
Module verbosity
This module logs through the logger name "gsd".
Typical verbosity meaning:
level 0: critical errors only (e.g., missing hit collection or missing touchable mappings).
level 1: event-level messages (e.g., start/end of event hooks).
level 2: detailed step and touchable processing (e.g., processed-touchable counts and new versus existing hits).
debug: constructor-level diagnostics and very verbose internal traces.
Continuous Integration
This module is built and tested as part of the overall GEMC CI pipeline.