|
aegir
Phlex-based simulation framework for the SHiP experiment.
|
aegir uses a direct worker integration pattern where Phlex framework threads act as Geant4 worker threads directly, with no separate G4 thread pool or event queue. This is inspired by the CMSSW OscarMTProducer pattern used in CMS.
We evaluated five integration strategies in the ship-phlex-sim benchmarking repository:
G4RunManager::BeamOn(1) on a dedicated thread.std::future for synchronisation.G4TaskRunManager with per-worker rendezvous slots.G4MTRunManager on a dedicated thread; G4 workers pop from a concurrent queue.BeamOn.Strategies 1–4 all involve cross-thread handoff overhead (queues, promises, condition variables). The direct worker approach eliminates this entirely: the thread that receives the event from the framework is the same thread that processes it through Geant4.
In benchmarks with particle gun events on a 4-core machine, the direct pattern matched the best queue-based strategy (sync MT slots) while being simpler to configure and reason about. It also removes the num_events configuration footgun present in the queue-based MT module, where the configured event count had to exactly match the driver's total.
A dedicated std::thread creates a G4MTRunManager and runs the full Geant4 initialisation sequence (geometry, physics, run initialisation). It then stores the world physical volume, physics list, and detector construction pointers for workers to use. The master thread blocks on a shutdown future until the module is destroyed.
Each Phlex thread lazily initialises on its first call to simulate():
G4Threading::G4SetThreadId()G4WorkerThread::BuildGeometryAndPhysicsVector()G4WorkerRunManagerKernel and defines the world volumeInstead of G4RunManager::BeamOn(), the module:
G4Event directly from the input MCParticle vector, creating G4PrimaryVertex and G4PrimaryParticle objects (no G4VUserPrimaryGeneratorAction involved)G4State_GeomClosedG4EventManager::ProcessOneEvent(event)This bypasses the G4 run loop entirely, giving the framework full control over event scheduling.
The G4MTRunManager is intentionally leaked at shutdown. Its destructor accesses global singletons that may already be torn down during plugin unloading, causing crashes. This is a known Geant4 limitation.
| Parameter | Type | Default | Description |
|---|---|---|---|
physics_list | string | FTFP_BERT | Geant4 reference physics list name |
concurrency | int | 1 | Number of concurrent worker threads |
verbosity | int | 0 | Geant4 run verbosity level |
sd_mode | string | scoring | Sensitive detector mode: scoring or crossing |
ke_threshold | double | 0.0 | Kinetic energy threshold for crossing SD (GeV) |
energy_cut | bool | false | Enable stepping energy cut |
energy_cut_threshold | double | ke_threshold | KE below which tracks are killed (GeV) |
particle_ke_cut | double | 0.0 | KE below which secondary particles are not recorded (GeV) |
regions | map | {} | Volume name pattern to production cut (mm) mapping |
Example workflow configuration: