Initialization sequence for actors#
Here is the chronological initialization sequence for actors, mapping the bridge between Python and C++.
Single threaded (ST) Initialization Sequence#
actor_engine.initialize()(Python): Python master loop triggers actor configuration before Geant4 builds the geometry.InitializeUserInfo()&InitializeCpp()(C++): Extracts parameters from the Python dictionary (e.g., splitting factors, kill volumes) and registers the C++ actor instance.g4_RunManager.Initialize()(C++): Geant4 constructs the master mass and parallel geometries.ConstructSDandField()(Python/C++): Geant4 triggers OpenGATE to handle sensitive detectors and biasing operators.ConfigureForWorker()(C++): The actor looks up the mainG4LogicalVolumeand attaches itself (and to all daughter volumes).actor_engine.register_actions()(Python): Binds the Python actor to the master thread’s Tracking, Stepping, Event, and Run action lists.StartTracking()(C++): Triggered natively by Geant4 when a particle track begins, resetting tracking flags.
Multithreaded (MT) Initialization Sequence#
actor_engine.initialize()(Python): Executed strictly on the Master Thread to push Python parameters to C++ before workers exist.InitializeUserInfo()&InitializeCpp()(C++): Executes on the Master Thread to save variables (must not initialize thread-local pointers here).g4_RunManager.InitializeWithoutFakeRun()(C++): Geant4 builds the master geometry but holds off on worker creation.FakeBeamOn()(C++): Geant4 officially spawns the worker threads.ConstructSDandField()(Python/C++): Triggered by Geant4 independently for every single worker thread.ConfigureForWorker()(C++): Called per worker. The actor securely attaches itself to the thread-local instances of theG4LogicalVolume.actor_engine.register_actions()(Python): Binds the Python actor to the newly created, thread-local Geant4 action lists.PreUserTrackingAction()(C++): OpenGATE’s mandatory MT hook to force tracking initialization (since Geant4 skips nativeStartTrackingfor MT biasing operators).StartTracking()(C++): Triggered byPreUserTrackingAction. Lazy-initializes the thread-local caches (threadLocalData.Get()), instantiates the thread-local operations, and resets flags.