Skip to content

Commit

Permalink
feat: allow ddsim --action.step etc for action plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
wdconinc committed Jan 25, 2024
1 parent 447475e commit 359c757
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
18 changes: 18 additions & 0 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,24 @@ def run(self):
# configure geometry creation
self.geometry.constructGeometry(kernel, geant4, self.output.geometry)

# ----------------------------------------------------------------------------------
# Configure run, event, track, step actions, if present
for action_name in self.action.run:
action = DDG4.RunAction(kernel, action_name)
kernel.runAction().add(action)
for action_name in self.action.event:
action = DDG4.EventAction(kernel, action_name)
kernel.eventAction().add(action)
for action_name in self.action.track:
action = DDG4.TrackingAction(kernel, action_name)
kernel.trackingAction().add(action)
for action_name in self.action.step:
action = DDG4.SteppingAction(kernel, action_name)
kernel.steppingAction().add(action)
for action_name in self.action.stack:
action = DDG4.StackingAction(kernel, action_name)
kernel.stackingAction().add(action)

# ----------------------------------------------------------------------------------
# Configure Run actions
run1 = DDG4.RunAction(kernel, 'Geant4TestRunAction/RunInit')
Expand Down
64 changes: 62 additions & 2 deletions DDG4/python/DDSim/Helper/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@


class Action(ConfigHelper):
"""Helper holding sensitive detector actions.
"""Helper holding sensitive detector and other actions.
The default tracker and calorimeter actions can be set with
The default tracker and calorimeter sensitive actions can be set with
>>> SIM = DD4hepSimulation()
>>> SIM.action.tracker=('Geant4TrackerWeightedAction', {'HitPositionCombination': 2, 'CollectSingleDeposits': False})
Expand All @@ -30,6 +30,15 @@ class Action(ConfigHelper):
>>> SIM = DD4hepSimulation()
>>> SIM.action.mapActions['ecal'] =( "CaloPreShowerSDAction", {"FirstLayerNumber": 1} )
Additional actions can be set as well with
>>> SIM = DD4hepSimulation()
>>> SIM.action.run = "Geant4TestRunAction"
>>> SIM.action.event = "Geant4TestEventAction"
>>> SIM.action.track = "Geant4TestTrackAction"
>>> SIM.action.step = "Geant4TestStepAction"
>>> SIM.action.stack = "Geant4TestStackAction"
"""

def __init__(self):
Expand All @@ -39,6 +48,11 @@ def __init__(self):
self._mapActions = dict()
self._trackerSDTypes = ['tracker']
self._calorimeterSDTypes = ['calorimeter']
self._run = []
self._event = []
self._track = []
self._step = []
self._stack = []
self._closeProperties()

@property
Expand Down Expand Up @@ -108,3 +122,49 @@ def calorimeterSDTypes(self):
@calorimeterSDTypes.setter
def calorimeterSDTypes(self, val):
self._calorimeterSDTypes = ConfigHelper.makeList(val)

@property
def run(self):
""" set the default run action """
return self._run

@run.setter
def run(self, val):
self._run = ConfigHelper.makeList(val)

@property
def event(self):
""" set the default event action """
return self._event

@event.setter
def event(self, val):
self._event = ConfigHelper.makeList(val)

@property
def track(self):
""" set the default track action """
return self._track

@track.setter
def track(self, val):
self._track = ConfigHelper.makeList(val)

@property
def step(self):
""" set the default step action """
return self._step

@step.setter
def step(self, val):
self._step = ConfigHelper.makeList(val)

@property
def stack(self):
""" set the default stack action """
return self._stack

@stack.setter
def stack(self, val):
self._stack = ConfigHelper.makeList(val)

0 comments on commit 359c757

Please sign in to comment.