File indexing completed on 2025-01-18 09:12:08
0001
0002
0003 import json
0004
0005 import acts
0006 from acts.examples.dd4hep import (
0007 DD4hepDetector,
0008 DD4hepDetectorOptions,
0009 DD4hepGeometryService,
0010 )
0011 from acts.examples.odd import getOpenDataDetectorDirectory
0012
0013
0014 if "__main__" == __name__:
0015 odd_xml = getOpenDataDetectorDirectory() / "xml" / "OpenDataDetector.xml"
0016
0017 print("Using the following xml file: ", odd_xml)
0018
0019
0020 dd4hepConfig = DD4hepGeometryService.Config()
0021 dd4hepConfig.logLevel = acts.logging.INFO
0022 dd4hepConfig.xmlFileNames = [str(odd_xml)]
0023 dd4hepGeometryService = DD4hepGeometryService(dd4hepConfig)
0024 dd4hepDetector = DD4hepDetector(dd4hepGeometryService)
0025
0026 cOptions = DD4hepDetectorOptions(logLevel=acts.logging.INFO, emulateToGraph="")
0027
0028
0029
0030 geoIdMappingFile = None
0031 if geoIdMappingFile is not None:
0032
0033 with open(geoIdMappingFile) as f:
0034
0035 geometry_id_mapping = json.load(f)
0036
0037 geometry_id_mapping_patched = {
0038 int(k): acts.GeometryIdentifier(int(v))
0039 for k, v in geometry_id_mapping.items()
0040 }
0041
0042 acts.examples.dd4hep.attachDD4hepGeoIdMapper(
0043 cOptions, geometry_id_mapping_patched
0044 )
0045
0046
0047 geoContext = acts.GeometryContext()
0048 [detector, contextors, store] = dd4hepDetector.finalize(geoContext, cOptions)
0049
0050
0051 surfaces = []
0052 viewConfig = acts.ViewConfig()
0053 viewConfig.nSegments = 100
0054 for vol in detector.volumePtrs():
0055 for surf in vol.surfacePtrs():
0056 if surf.geometryId().sensitive() > 0:
0057 surfaces.append(surf)
0058 acts.examples.writeSurfacesObj(surfaces, geoContext, viewConfig, "odd-surfaces.obj")
0059
0060
0061 surfaceStyle = acts.svg.Style()
0062 surfaceStyle.fillColor = [5, 150, 245]
0063 surfaceStyle.fillOpacity = 0.5
0064
0065 surfaceOptions = acts.svg.SurfaceOptions()
0066 surfaceOptions.style = surfaceStyle
0067
0068 viewRange = acts.Extent([])
0069 volumeOptions = acts.svg.DetectorVolumeOptions()
0070 volumeOptions.surfaceOptions = surfaceOptions
0071
0072
0073 xyRange = acts.Extent([[acts.AxisDirection.AxisZ, [-50, 50]]])
0074 xyView = acts.svg.drawDetector(
0075 geoContext,
0076 detector,
0077 "odd",
0078 [[ivol, volumeOptions] for ivol in range(detector.numberVolumes())],
0079 [["xy", ["sensitives"], xyRange]],
0080 )
0081 xyFile = acts.svg.file()
0082 xyFile.addObjects(xyView)
0083 xyFile.write("odd_xy.svg")
0084
0085
0086 zrRange = acts.Extent([[acts.AxisDirection.AxisPhi, [-0.1, 0.1]]])
0087 zrView = acts.svg.drawDetector(
0088 geoContext,
0089 detector,
0090 "odd",
0091 [[ivol, volumeOptions] for ivol in range(detector.numberVolumes())],
0092 [["zr", ["sensitives", "portals"], zrRange]],
0093 )
0094 zrFile = acts.svg.file()
0095 zrFile.addObjects(zrView)
0096 zrFile.write("odd_zr.svg")