diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py index bcb5019aae4f218e4d922eeeda6a879fdce811b5..9c4fb52e3ca8377dcfe80d82d17a9a0ba118032f 100644 --- a/DDG4/python/DDSim/DD4hepSimulation.py +++ b/DDG4/python/DDSim/DD4hepSimulation.py @@ -396,8 +396,8 @@ class DD4hepSimulation(object): self.__applyBoostOrSmear(kernel, actionList, index) if actionList: - simple.buildInputStage( actionList , output_level=self.output.inputStage, - have_mctruth = self._enablePrimaryHandler() ) + self._buildInputStage(simple, actionList, output_level=self.output.inputStage, + have_mctruth=self._enablePrimaryHandler() ) #================================================================================================ @@ -490,8 +490,6 @@ class DD4hepSimulation(object): if self._g4gps is not None: self._g4gps.generator() - #DDG4.setPrintLevel(Output.DEBUG) - startUpTime, _sysTime, _cuTime, _csTime, _elapsedTime = os.times() kernel.run() @@ -726,6 +724,53 @@ SIM = DD4hepSimulation() print "Disabling the PrimaryHandler" return enablePrimaryHandler + + def _buildInputStage(self, simple, generator_input_modules, output_level=None, have_mctruth=True): + """ + Generic build of the input stage with multiple input modules. + Actions executed are: + 1) Register Generation initialization action + 2) Append all modules to build the complete input record + These modules are readers/particle sources, boosters and/or smearing actions. + 3) Merge all existing interaction records + 4) Add the MC truth handler + """ + from DDG4 import GeneratorAction + ga = simple.kernel().generatorAction() + + # Register Generation initialization action + gen = GeneratorAction(simple.kernel(),"Geant4GeneratorActionInit/GenerationInit") + if output_level is not None: + gen.OutputLevel = output_level + ga.adopt(gen) + + # Now append all modules to build the complete input record + # These modules are readers/particle sources, boosters and/or smearing actions + for gen in generator_input_modules: + gen.enableUI() + if output_level is not None: + gen.OutputLevel = output_level + ga.adopt(gen) + + # Merge all existing interaction records + gen = GeneratorAction(simple.kernel(),"Geant4InteractionMerger/InteractionMerger") + gen.enableUI() + if output_level is not None: + gen.OutputLevel = output_level + ga.adopt(gen) + + # Finally generate Geant4 primaries + if have_mctruth: + gen = GeneratorAction(simple.kernel(),"Geant4PrimaryHandler/PrimaryHandler") + gen.RejectPDGs=ConfigHelper.makeString(self.physics.rejectPDGs) + gen.enableUI() + if output_level is not None: + gen.OutputLevel = output_level + ga.adopt(gen) + # Puuuhh! All done. + return None + + ################################################################################ ### MODULE FUNCTIONS GO HERE ################################################################################ @@ -756,3 +801,4 @@ def getOutputLevel(level): 6: OutputLevel.FATAL, 7: OutputLevel.ALWAYS } return levels[level] + diff --git a/DDG4/python/DDSim/Helper/ConfigHelper.py b/DDG4/python/DDSim/Helper/ConfigHelper.py index e4bac6a1e984b319b5af7c705a2438bb7ef65d29..89f5c3e39d7a96c82af96626fe2505b725dd7a4e 100644 --- a/DDG4/python/DDSim/Helper/ConfigHelper.py +++ b/DDG4/python/DDSim/Helper/ConfigHelper.py @@ -70,6 +70,25 @@ class ConfigHelper( object ): else: return stringVal.split(sep) + @staticmethod + def makeSet(stringVal, sep=" "): + """returns a set from a string separated by sep""" + if not stringVal: + return set() + if isinstance(stringVal, (list, set, tuple)): + return set(stringVal) + else: + return set(stringVal.split(sep)) + + + @staticmethod + def makeString(container): + """Return a string that can be parsed by dd4hep into a vector.""" + if not container: + return "" + if isinstance(container, set): + return '{%s}' % ','.join([str(s) for s in container]) + @staticmethod def makeTuple( val ): """ returns a tuple of the string, separators are space or comma """ diff --git a/DDG4/python/DDSim/Helper/Physics.py b/DDG4/python/DDSim/Helper/Physics.py index f84f0a69b85cec54600c1db6799083296aff7136..344404cf112ae81e0cb9b3150b403a370388ef6e 100644 --- a/DDG4/python/DDSim/Helper/Physics.py +++ b/DDG4/python/DDSim/Helper/Physics.py @@ -13,7 +13,18 @@ class Physics( ConfigHelper ): self.list ="FTFP_BERT" self.decays = True self._pdgfile = None + self._rejectPDGs = {1,2,3,4,5,6,21,23,24} + @property + def rejectPDGs( self ): + """Set of PDG IDs that will not be passed from the input record to Geant4. + + Quarks, gluons and W's Z's etc should not be treated by Geant4 + """ + return self._rejectPDGs + @rejectPDGs.setter + def rejectPDGs( self, val ): + self._rejectPDGs = val @property def rangecut( self ):