Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:22

0001 """Helper object for Geant4 Geometry conversion."""
0002 
0003 from DDSim.Helper.ConfigHelper import ConfigHelper
0004 
0005 
0006 class Geometry(ConfigHelper):
0007   """Configuration for the Detector Construction."""
0008 
0009   def __init__(self):
0010     super(Geometry, self).__init__()
0011 
0012     self._enableDebugMaterials_EXTRA = {"help": "Print Debug information about Materials"}
0013     self.enableDebugMaterials = False
0014     self._enableDebugElements_EXTRA = {"help": "Print Debug information about Elements"}
0015     self.enableDebugElements = False
0016     self._enableDebugVolumes_EXTRA = {"help": "Print Debug information about Volumes"}
0017     self.enableDebugVolumes = False
0018     self._enableDebugShapes_EXTRA = {"help": "Print Debug information about Shapes"}
0019     self.enableDebugShapes = False
0020     self._enableDebugPlacements_EXTRA = {"help": "Print Debug information about Placements"}
0021     self.enableDebugPlacements = False
0022     self._enableDebugReflections_EXTRA = {"help": "Print Debug information about Reflections"}
0023     self.enableDebugReflections = False
0024     self._enableDebugRegions_EXTRA = {"help": "Print Debug information about Regions"}
0025     self.enableDebugRegions = False
0026     self._enableDebugSurfaces_EXTRA = {"help": "Print Debug information about Surfaces"}
0027     self.enableDebugSurfaces = False
0028     self._dumpHierachy_EXTRA = {"help": "If larger than 0, the depth up to which detector hierarchy is dumped"}
0029     self.dumpHierarchy = 0
0030 
0031     self._enablePrintPlacements_EXTRA = {"help": "Print information about placements"}
0032     self.enablePrintPlacements = False
0033     self._enablePrintSensitives_EXTRA = {"help": "Print information about Sensitives"}
0034     self.enablePrintSensitives = False
0035 
0036     self._dumpDGDML_EXTRA = {"help": "If not empty, filename to dump the Geometry as GDML"}
0037     self.dumpGDML = ""
0038 
0039     self._regexSDDict = {}
0040 
0041     self._closeProperties()
0042 
0043   @property
0044   def regexSensitiveDetector(self):
0045     """ The map key is the name of the Detector, and 'Match' is a mandatory elements of the dictionary, other Keys are
0046         assigned as property to the object. OutputLevel _sets_ the outputlevel of the plugin, so lower numbers mean more
0047         output from the plugin.
0048 
0049         >>> SIM.geometry.regexSensitiveDetector['DRcalo'] = {
0050                                                    'Match': ['(core|clad)'],
0051                                                    'OutputLevel': 3,
0052                                                   }
0053     """
0054     return self._regexSDDict
0055 
0056   @regexSensitiveDetector.setter
0057   def regexSensitiveDetector(self, val):
0058     if isinstance(val, dict):
0059       self._regexSDDict = val
0060       return
0061     raise RuntimeError(f"Unsupported type for regexSensitiveDetector: {val!r}")
0062 
0063   def constructGeometry(self, kernel, geant4, geoPrintLevel=2, numberOfThreads=1):
0064     """Construct Geant4 geometry."""
0065     from DDG4 import DetectorConstruction
0066 
0067     seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
0068     act.DebugMaterials = self.enableDebugMaterials
0069     act.DebugElements = self.enableDebugElements
0070     act.DebugVolumes = self.enableDebugVolumes
0071     act.DebugShapes = self.enableDebugShapes
0072     act.DebugPlacements = self.enableDebugPlacements
0073     act.DebugReflections = self.enableDebugReflections
0074     act.DebugRegions = self.enableDebugRegions
0075     act.DebugSurfaces = self.enableDebugSurfaces
0076     act.PrintPlacements = self.enablePrintPlacements
0077     act.PrintSensitives = self.enablePrintSensitives
0078     act.GeoInfoPrintLevel = geoPrintLevel
0079     act.DumpHierarchy = self.dumpHierarchy
0080     act.DumpGDML = self.dumpGDML
0081 
0082     # Apply sensitive detectors
0083     sensitives = DetectorConstruction(kernel, str('Geant4DetectorSensitivesConstruction/ConstructSD'))
0084     sensitives.enableUI()
0085     seq.adopt(sensitives)
0086 
0087     for index, (detName, regexDetectors) in enumerate(sorted(self._regexSDDict.items())):
0088       seq, act = geant4.addDetectorConstruction(f'Geant4RegexSensitivesConstruction/ConstrSDRegEx_{index}_{detName}')
0089       act.Detector = detName
0090       # this will set Match, and other properties if possible
0091       for key, value in regexDetectors.items():
0092         setattr(act, key, value)