Skip to content
Snippets Groups Projects
Commit 5c5c7891 authored by Andre Sailer's avatar Andre Sailer
Browse files

DDSim: Gun options, add distribution steering (needs DD4hep r2121)

Add control over distributions
if a distribution is set activate isotrop
if isotrop is activated use uniform by default

Move set up gun function to Helper/Gun, keeps functionality closer together
parent 1b0519ee
No related branches found
No related tags found
No related merge requests found
...@@ -322,7 +322,7 @@ class DD4hepSimulation(object): ...@@ -322,7 +322,7 @@ class DD4hepSimulation(object):
if self.enableGun: if self.enableGun:
gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/"+"Gun") gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/"+"Gun")
self.__setGunOptions( gun ) self.gun.setOptions( gun )
gun.Standalone = False gun.Standalone = False
gun.Mask = 1 gun.Mask = 1
actionList.append(gun) actionList.append(gun)
...@@ -431,30 +431,6 @@ class DD4hepSimulation(object): ...@@ -431,30 +431,6 @@ class DD4hepSimulation(object):
kernel.run() kernel.run()
kernel.terminate() 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): def __setupRandomGenerator(self, rndm):
"""set the properties for the random number generator""" """set the properties for the random number generator"""
......
...@@ -17,6 +17,35 @@ class Gun( ConfigHelper ): ...@@ -17,6 +17,35 @@ class Gun( ConfigHelper ):
self.phiMax = None self.phiMax = None
self.thetaMin = None self.thetaMin = None
self.thetaMax = 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 @property
def isotrop( self ): def isotrop( self ):
...@@ -33,6 +62,8 @@ class Gun( ConfigHelper ): ...@@ -33,6 +62,8 @@ class Gun( ConfigHelper ):
self._isotrop = ConfigHelper.makeBool( val ) self._isotrop = ConfigHelper.makeBool( val )
except RuntimeError: except RuntimeError:
raise RuntimeError( "malformed input '%s' for gun.isotrop " % val) raise RuntimeError( "malformed input '%s' for gun.isotrop " % val)
if val and self.distribution is None:
self.distribution = 'uniform'
@property @property
def direction( self ): def direction( self ):
...@@ -56,3 +87,30 @@ class Gun( ConfigHelper ): ...@@ -56,3 +87,30 @@ class Gun( ConfigHelper ):
self._position = ConfigHelper.makeTuple( val ) self._position = ConfigHelper.makeTuple( val )
if len(self._position) != 3: if len(self._position) != 3:
raise RuntimeError(" gun.position: malformed input '%s', needs to be a string representing a three vector " % val ) 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment