Skip to content

Commit

Permalink
DDSim: add interface to created RegexSDs
Browse files Browse the repository at this point in the history
  • Loading branch information
andresailer committed Aug 9, 2024
1 parent f0d9fcb commit cf80134
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions DDG4/python/DDSim/Helper/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,35 @@ def __init__(self):

self._dumpDGDML_EXTRA = {"help": "If not empty, filename to dump the Geometry as GDML"}
self.dumpGDML = ""

self._regexSDDetectorList = []

self._closeProperties()

@property
def regexSDList(self):
"""Configure a sensitive detector for a given detector matched by regular expression (regex).
'Detector' and 'Match' are mandatory elements of the dictionary, other Keys are assigned as property to the object.
>>> SIM.geometry.regexSDList = { 'Detector': 'DRcalo',
'Match': ['(core|clad)'],
'OutputLevel'= 7',
}
This can be assigned repeatedly to add multiple RegexSDs
"""
return self._regexSDDetectorList

@regexSDList.setter
def regexSDList(self, val):
if not val:
return
requiredKeys = ('Detector', 'Match')
if not all(key in val for key in requiredKeys):
raise RuntimeError("RegexSD configuration is missing at least one mandatory key:", requiredKeys)
self._regexSDDetectorList.append(val)

def constructGeometry(self, kernel, geant4, geoPrintLevel=2, numberOfThreads=1):
"""Construct Geant4 geometry."""
from DDG4 import DetectorConstruction
Expand All @@ -60,3 +87,9 @@ def constructGeometry(self, kernel, geant4, geoPrintLevel=2, numberOfThreads=1):
sensitives = DetectorConstruction(kernel, str('Geant4DetectorSensitivesConstruction/ConstructSD'))
sensitives.enableUI()
seq.adopt(sensitives)

for index, regexDetectors in enumerate(self._regexSDDetectorList):
seq, act = geant4.addDetectorConstruction(f'Geant4RegexSensitivesConstruction/ConstrSDRegEx_{index}')
# this will set Match and Detector, and other properties if possible
for key, value in regexDetectors.items():
setattr(act, key, value)

0 comments on commit cf80134

Please sign in to comment.