Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/opengate_core/opengate_lib/GateVActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class GateVActor : public G4VPrimitiveScorer {

virtual void AddActions(std::set<std::string> &actions);

// Called at initialisation in late G4 PreInit state
virtual void InitializeG4PreInitState() {}

// Called at initialisation
virtual void InitializeCpp();

Expand Down
1 change: 1 addition & 0 deletions core/opengate_core/opengate_lib/pyGateVActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void init_GateVActor(py::module &m) {
// .def_readonly("fActions", &GateVActor::fActions) // avoid wrapping
// this -> problems with pickle
.def_readwrite("fFilters", &GateVActor::fFilters)
.def("InitializeG4PreInitState", &GateVActor::InitializeG4PreInitState)
.def("InitializeCpp", &GateVActor::InitializeCpp)
.def("InitializeUserInfo", &GateVActor::InitializeUserInfo)
.def("AddActions", &GateVActor::AddActions)
Expand Down
15 changes: 15 additions & 0 deletions opengate/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,13 @@ def close(self):
actor.close()
super().close()

def initialize_preinit(self):
for actor in self.actor_manager.sorted_actors:
global_log.debug(
f"Actor: initialize_preinit [{actor.type_name}] {actor.name}"
)
actor.InitializeG4PreInitState()

def initialize(self):
for actor in self.actor_manager.sorted_actors:
global_log.debug(f"Actor: initialize [{actor.type_name}] {actor.name}")
Expand Down Expand Up @@ -1278,6 +1285,9 @@ def initialize(self):
"""
Build the main geant4 objects and initialize them.
"""

# From this line, G4 is in G4State_PreInit state

# get log
log = global_log

Expand Down Expand Up @@ -1346,6 +1356,9 @@ def initialize(self):
self.action_engine
) # G4 internally calls action_engine.Build()

# late-G4 PreInit state actor initialisation phase
self.actor_engine.initialize_preinit()

# Important: The volumes are constructed
# when the G4RunManager calls the Construct method of the VolumeEngine,
# which happens in the InitializeGeometry() method of the
Expand All @@ -1360,6 +1373,8 @@ def initialize(self):
else:
self.g4_RunManager.Initialize()

# From this line, G4 is in G4State_Idle state

log.info("Simulation: initialize PhysicsEngine after RunManager initialization")
self.physics_engine.initialize_after_runmanager()
self.g4_RunManager.PhysicsHasBeenModified()
Expand Down
Loading