diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py index dac758cde3cc055ecb7356b84d0f68b76d89836e..0548a71f409651f8ea9945b84de746730e9d600c 100644 --- a/DDG4/python/DDSim/DD4hepSimulation.py +++ b/DDG4/python/DDSim/DD4hepSimulation.py @@ -418,29 +418,7 @@ class DD4hepSimulation(object): if self.part.enableDetailedHitsAndParticleInfo: self.part.setDumpDetailedParticleInfo( kernel, DDG4 ) - #---------------------------------- - - - - - user = DDG4.Action(kernel,"Geant4TCUserParticleHandler/UserParticleHandler") - try: - user.TrackingVolume_Zmax = DDG4.tracker_region_zmax - user.TrackingVolume_Rmax = DDG4.tracker_region_rmax - - print " *** definition of tracker region *** " - print " tracker_region_zmax = " , user.TrackingVolume_Zmax - print " tracker_region_rmax = " , user.TrackingVolume_Rmax - print " ************************************ " - - except AttributeError as e: - print "ERROR - attribute of tracker region missing in detector model ", str(e) - print " make sure to specify the global constants tracker_region_zmax and tracker_region_rmax " - print " this is needed for the MC-truth link of created sim-hits ! " - exit(1) - - # user.enableUI() - part.adopt(user) + self.part.setupUserParticleHandler(part) #================================================================================= diff --git a/DDG4/python/DDSim/Helper/ParticleHandler.py b/DDG4/python/DDSim/Helper/ParticleHandler.py index f66c4b02e6bf917b3a52908ffd8db1bdcbbed984..aaabea68f171e1cec447ab42ac0d45a76dce9e90 100644 --- a/DDG4/python/DDSim/Helper/ParticleHandler.py +++ b/DDG4/python/DDSim/Helper/ParticleHandler.py @@ -14,6 +14,7 @@ class ParticleHandler( ConfigHelper ): self._printStartTracking = False self._minDistToParentVertex = 2.2e-14*mm self._enableDetailedHitsAndParticleInfo = False + self._userParticleHandler = "Geant4TCUserParticleHandler" @property def enableDetailedHitsAndParticleInfo(self): @@ -24,6 +25,13 @@ class ParticleHandler( ConfigHelper ): def enableDetailedHitsAndParticleInfo( self, val ): self._enableDetailedHitsAndParticleInfo = val + @property + def userParticleHandler( self ): + """Optionally enable an extended Particle Handler""" + return self._userParticleHandler + @userParticleHandler.setter + def userParticleHandler( self, val ): + self._userParticleHandler = val @property def minDistToParentVertex( self ): @@ -93,3 +101,31 @@ class ParticleHandler( ConfigHelper ): evt = DDG4.EventAction(kernel,"Geant4HitDumpAction/HitDump") kernel.eventAction().adopt(evt) evt.enableUI() + + def setupUserParticleHandler(self, part): + """Create the UserParticleHandler and configure it. + + FIXME: this is not extensible at the moment + """ + if not self.userParticleHandler: + return + + if self.userParticleHandler == "Geant4TCUserParticleHandler": + user = DDG4.Action(kernel,"%s/UserParticleHandler" % self.userParticleHandler) + try: + user.TrackingVolume_Zmax = DDG4.tracker_region_zmax + user.TrackingVolume_Rmax = DDG4.tracker_region_rmax + print " *** definition of tracker region *** " + print " tracker_region_zmax = " , user.TrackingVolume_Zmax + print " tracker_region_rmax = " , user.TrackingVolume_Rmax + print " ************************************ " + except AttributeError as e: + print "ERROR - attribute of tracker region missing in detector model ", str(e) + print " make sure to specify the global constants tracker_region_zmax and tracker_region_rmax " + print " this is needed for the MC-truth link of created sim-hits ! " + print " Or Disable the User Particle Handler with --part.userParticleHandler=''" + exit(1) + part.adopt(user) + + print "ERROR: unknown UserParticleHandler: %r" % self.userParticleHandler + exit(1)