diff --git a/DDSim/DD4hepSimulation.py b/DDSim/DD4hepSimulation.py index 76b16c856e764e905284135b63d916693359de56..b27dba242196b3ad4c8743510796a538108b3df2 100644 --- a/DDSim/DD4hepSimulation.py +++ b/DDSim/DD4hepSimulation.py @@ -322,7 +322,7 @@ class DD4hepSimulation(object): if self.enableGun: gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/"+"Gun") - self.__setGunOptions( gun ) + self.gun.setOptions( gun ) gun.Standalone = False gun.Mask = 1 actionList.append(gun) @@ -431,30 +431,6 @@ class DD4hepSimulation(object): kernel.run() kernel.terminate() - def __setGunOptions(self, gun): - """set the starting properties of the DDG4 particle gun""" - try: - gun.energy = self.gun.energy - gun.particle = self.gun.particle - gun.multiplicity = self.gun.multiplicity - gun.position = self.gun.position - gun.isotrop = self.gun.isotrop - gun.direction = self.gun.direction - if self.gun.thetaMin is not None: - gun.ThetaMin = self.gun.thetaMin - gun.isotrop = True - if self.gun.thetaMax is not None: - gun.ThetaMax = self.gun.thetaMax - gun.isotrop = True - if self.gun.phiMin is not None: - gun.PhiMin = self.gun.phiMin - gun.isotrop = True - if self.gun.phiMax is not None: - gun.PhiMax = self.gun.phiMax - gun.isotrop = True - except Exception as e: #pylint: disable=W0703 - print "ERROR: parsing gun options:\n%s\nException: %s " % (self.gun, e ) - exit(1) def __setupRandomGenerator(self, rndm): """set the properties for the random number generator""" diff --git a/DDSim/Helper/Gun.py b/DDSim/Helper/Gun.py index 2ccac701e1a557493072a1d908813cf0bbdf3c13..bbeff4616c7c2bae9d20460d7b5cd60c66e65cf6 100644 --- a/DDSim/Helper/Gun.py +++ b/DDSim/Helper/Gun.py @@ -17,6 +17,35 @@ class Gun( ConfigHelper ): self.phiMax = None self.thetaMin = None self.thetaMax = None + self._distribution = None + + + @property + def distribution( self ): + """choose the distribution of the random direction for theta + + Options for isotropic distributions in: 'uniform', 'cos(theta)', 'eta' (or + 'pseudorapidity'), 'ffbar' (distributed flat in 1+cos^2 theta) + + 'uniform' is the default distribution + + Setting a distribution will set isotrop = True + """ + return self._distribution + @distribution.setter + def distribution( self, val ): + if val is None: + return + possibleDistributions = ['uniform', 'cos(theta)', 'eta', 'pseudorapidity', 'ffbar'] ## (1+cos^2 theta) + if not isinstance( val, basestring): + raise RuntimeError( "malformed input '%s' for gun.distribution. Need a string : %s " % (val, ",".join(possibleDistributions)) ) + if val not in possibleDistributions: + ## surround options by quots to be explicit + stringified = [ "'%s'" % _ for _ in possibleDistributions ] + raise RuntimeError( "Unknown distribution '%s', Use one of: %s " % (val, + ", ".join(stringified)) ) + self._distribution = val + self._isotrop = True @property def isotrop( self ): @@ -33,6 +62,8 @@ class Gun( ConfigHelper ): self._isotrop = ConfigHelper.makeBool( val ) except RuntimeError: raise RuntimeError( "malformed input '%s' for gun.isotrop " % val) + if val and self.distribution is None: + self.distribution = 'uniform' @property def direction( self ): @@ -56,3 +87,30 @@ class Gun( ConfigHelper ): self._position = ConfigHelper.makeTuple( val ) if len(self._position) != 3: raise RuntimeError(" gun.position: malformed input '%s', needs to be a string representing a three vector " % val ) + + + def setOptions( self, ddg4Gun ): + """set the starting properties of the DDG4 particle gun""" + try: + ddg4Gun.energy = self.energy + ddg4Gun.particle = self.particle + ddg4Gun.multiplicity = self.multiplicity + ddg4Gun.position = self.position + ddg4Gun.isotrop = self.isotrop + ddg4Gun.direction = self.direction + ddg4Gun.Distribution = self.distribution + if self.thetaMin is not None: + ddg4Gun.ThetaMin = self.thetaMin + ddg4Gun.isotrop = True + if self.thetaMax is not None: + ddg4Gun.ThetaMax = self.thetaMax + ddg4Gun.isotrop = True + if self.phiMin is not None: + ddg4Gun.PhiMin = self.phiMin + ddg4Gun.isotrop = True + if self.phiMax is not None: + ddg4Gun.PhiMax = self.phiMax + ddg4Gun.isotrop = True + except Exception as e: #pylint: disable=W0703 + print "ERROR: parsing gun options:\n%s\nException: %s " % (self, e ) + exit(1)