Skip to content

Commit

Permalink
DDSim: move UI commands to separate helper to give better documentati…
Browse files Browse the repository at this point in the history
…on for it
  • Loading branch information
andresailer committed Jul 14, 2023
1 parent 83387bf commit c0d076c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 52 deletions.
13 changes: 7 additions & 6 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from DDSim.Helper.MagneticField import MagneticField
from DDSim.Helper.ParticleHandler import ParticleHandler
from DDSim.Helper.Gun import Gun
from DDSim.Helper.UI import UI
import argparse
import ddsix as six
import logging
Expand Down Expand Up @@ -99,6 +100,7 @@ def __init__(self):
self.geometry = Geometry()
self.filter = Filter()
self.physics = Physics()
self.ui = UI()

self._argv = None

Expand Down Expand Up @@ -331,12 +333,11 @@ def run(self):
exit(1)

# User Configuration for the Geant4Phases
uiaction.ConfigureCommands = self.physics._commandsConfigure
uiaction.TerminateCommands = self.physics._commandsTerminate
uiaction.PostRunCommands = self.physics._commandsPostRun
uiaction.PreRunCommands = self.physics._commandsPreRun
uiaction.InitializeCommands = self.physics._commandsInitialize

uiaction.ConfigureCommands = self.ui._commandsConfigure
uiaction.InitializeCommands = self.ui._commandsInitialize
uiaction.PostRunCommands = self.ui._commandsPostRun
uiaction.PreRunCommands = self.ui._commandsPreRun
uiaction.TerminateCommands = self.ui._commandsTerminate

kernel.NumEvents = self.numberOfEvents

Expand Down
46 changes: 0 additions & 46 deletions DDG4/python/DDSim/Helper/Physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ def __init__(self):
self._zeroTimePDGs = {11, 13, 15, 17}
self._userFunctions = []

self._commandsConfigure = []
self._commandsTerminate = []
self._commandsPostRun = []
self._commandsPreRun = []
self._commandsInitialize = []

@property
def rejectPDGs(self):
"""Set of PDG IDs that will not be passed from the input record to Geant4.
Expand Down Expand Up @@ -122,46 +116,6 @@ def list(self): # noqa: A003
def list(self, val): # noqa: A003
self._list = val

@property
def commandsConfigure(self):
"""List of UI commands to run during the 'Configure' phase."""
return self._commandsConfigure
@commandsConfigure.setter
def commandsConfigure(self, val):
self._commandsConfigure = self.makeList(val)

@property
def commandsInitialize(self):
"""List of UI commands to run during the 'Initialize' phase."""
return self._commandsInitialize
@commandsInitialize.setter
def commandsInitialize(self, val):
self._commandsInitialize = self.makeList(val)

@property
def commandsTerminate(self):
"""List of UI commands to run during the 'Terminate' phase."""
return self._commandsTerminate
@commandsTerminate.setter
def commandsTerminate(self, val):
self._commandsTerminate = self.makeList(val)

@property
def commandsPreRun(self):
"""List of UI commands to run during the 'PreRun' phase."""
return self._commandsPreRun
@commandsPreRun.setter
def commandsPreRun(self, val):
self._commandsPreRun = self.makeList(val)

@property
def commandsPostRun(self):
"""List of UI commands to run during the 'PostRun' phase."""
return self._commandsPostRun
@commandsPostRun.setter
def commandsPostRun(self, val):
self._commandsPostRun = self.makeList(val)

def setupPhysics(self, kernel, name=None):
seq = kernel.physicsList()
seq.extends = name if name is not None else self.list
Expand Down
82 changes: 82 additions & 0 deletions DDG4/python/DDSim/Helper/UI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""Helper object for configuration of Geant4 commands to run during different phases."""

from __future__ import absolute_import, unicode_literals
import os

from DDSim.Helper.ConfigHelper import ConfigHelper
import logging

logger = logging.getLogger(__name__)


class UI(ConfigHelper):
"""Configuration for setting commands to run during different phases.
In this section, one can configure commands that should be run during the different phases of the Geant4 execution.
1. Initialization
2. Configuration
3. Pre Run
4. Post Run
5. Terminate / Finalization
For example, one can add
>>> SIM.ui.commandsConfigure = ['/physics_lists/em/SyncRadiation true']
Further details should be taken from the Geant4 documentation.
"""

def __init__(self):
super(UI, self).__init__()

self._commandsConfigure = []
self._commandsTerminate = []
self._commandsPostRun = []
self._commandsPreRun = []
self._commandsInitialize = []

@property
def commandsConfigure(self):
"""List of UI commands to run during the 'Configure' phase."""
return self._commandsConfigure

@commandsConfigure.setter
def commandsConfigure(self, val):
self._commandsConfigure = self.makeList(val)

@property
def commandsInitialize(self):
"""List of UI commands to run during the 'Initialize' phase."""
return self._commandsInitialize

@commandsInitialize.setter
def commandsInitialize(self, val):
self._commandsInitialize = self.makeList(val)

@property
def commandsPostRun(self):
"""List of UI commands to run during the 'PostRun' phase."""
return self._commandsPostRun

@commandsPostRun.setter
def commandsPostRun(self, val):
self._commandsPostRun = self.makeList(val)

@property
def commandsPreRun(self):
"""List of UI commands to run during the 'PreRun' phase."""
return self._commandsPreRun

@commandsPreRun.setter
def commandsPreRun(self, val):
self._commandsPreRun = self.makeList(val)

@property
def commandsTerminate(self):
"""List of UI commands to run during the 'Terminate' phase."""
return self._commandsTerminate

@commandsTerminate.setter
def commandsTerminate(self, val):
self._commandsTerminate = self.makeList(val)

0 comments on commit c0d076c

Please sign in to comment.