From b211790ef812e7ea7079df431b47615197d14a02 Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Wed, 3 Aug 2022 17:26:56 +0200 Subject: [PATCH] DDSim: userInputPlugins: allow arbitrary number, add boost/smear application --- DDG4/python/DDSim/DD4hepSimulation.py | 11 ++++++++--- DDG4/python/DDSim/Helper/InputConfig.py | 23 +++++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py index df80f7113..50b258792 100644 --- a/DDG4/python/DDSim/DD4hepSimulation.py +++ b/DDG4/python/DDSim/DD4hepSimulation.py @@ -393,11 +393,16 @@ class DD4hepSimulation(object): logger.info("++++ Adding Geant4 General Particle Source ++++") actionList.append(self._g4gps) - if self.inputConfig.userInputPlugin: - gen = self.inputConfig.userInputPlugin(self) + start = 4 + for index, plugin in enumerate(self.inputConfig.userInputPlugin, start=start): + gen = plugin(self) + gen.Mask = index + start = index + 1 actionList.append(gen) + self.__applyBoostOrSmear(kernel, actionList, index) + logger.info("++++ Adding User Plugin %s ++++", gen.Name) - for index, inputFile in enumerate(self.inputFiles, start=4): + for index, inputFile in enumerate(self.inputFiles, start=start): if inputFile.endswith(".slcio"): gen = DDG4.GeneratorAction(kernel, "LCIOInputAction/LCIO%d" % index) gen.Parameters = self.lcio.getParameters() diff --git a/DDG4/python/DDSim/Helper/InputConfig.py b/DDG4/python/DDSim/Helper/InputConfig.py index 200ca79b7..3392f8c89 100644 --- a/DDG4/python/DDSim/Helper/InputConfig.py +++ b/DDG4/python/DDSim/Helper/InputConfig.py @@ -9,13 +9,13 @@ class InputConfig(ConfigHelper): def __init__(self): super(InputConfig, self).__init__() - self._userPlugin = None + self._userPlugin = [] @property def userInputPlugin(self): - """Set a function to configure an inputStep. + """Set one or more functions to configure input steps. - The function must take a ``DD4hepSimulation`` object as its only argument and return the created generatorAction + The functions must take a ``DD4hepSimulation`` object as their only argument and return the created generatorAction ``gen`` (for example). For example one can add this to the ddsim steering file: @@ -37,13 +37,24 @@ class InputConfig(ConfigHelper): return gen SIM.inputConfig.userInputPlugin = exampleUserPlugin + + Repeat function definition and assignment to add multiple input steps + """ return self._userPlugin @userInputPlugin.setter def userInputPlugin(self, userInputPluginConfig): - if userInputPluginConfig is None: + if not userInputPluginConfig: return + + if isinstance(userInputPluginConfig, list): + if not all(callable(func) for func in userInputPluginConfig): + raise RuntimeError("Some provided userPlugins are not a callable function") + self._userPlugin = userInputPluginConfig + return + if not callable(userInputPluginConfig): - raise RuntimeError("The provided userPlugin is not a callable function.") - self._userPlugin = userInputPluginConfig + raise RuntimeError("The provided userPlugin is not a callable function: %s, %s" % (type(userInputPluginConfig), + repr(userInputPluginConfig))) + self._userPlugin.append(userInputPluginConfig) -- GitLab