Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:46:07

0001 #!/usr/bin/env python3
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 if "__main__" == __name__:
0014     odd_xml = getOpenDataDetectorDirectory() / "xml" / "OpenDataDetector.xml"
0015 
0016     print("Using the following xml file: ", odd_xml)
0017 
0018     # Create the dd4hep geometry service and detector
0019     dd4hepConfig = DD4hepGeometryService.Config()
0020     dd4hepConfig.logLevel = acts.logging.INFO
0021     dd4hepConfig.xmlFileNames = [str(odd_xml)]
0022     dd4hepGeometryService = DD4hepGeometryService(dd4hepConfig)
0023     dd4hepDetector = DD4hepDetector(dd4hepGeometryService)
0024 
0025     cOptions = DD4hepDetectorOptions(logLevel=acts.logging.INFO, emulateToGraph="")
0026 
0027     # Uncomment if you want to use the geometry id mapping
0028     # This map can be produced with the 'geometry.py' script
0029     geoIdMappingFile = None  # "odd-dd4hep-geoid-mapping-wo-extra.json"
0030     if geoIdMappingFile is not None:
0031         # Load the geometry id mapping json file
0032         with open(geoIdMappingFile) as f:
0033             # load the file as is
0034             geometry_id_mapping = json.load(f)
0035             # create a dictionary with GeometryIdentifier as value
0036             geometry_id_mapping_patched = {
0037                 int(k): acts.GeometryIdentifier(int(v))
0038                 for k, v in geometry_id_mapping.items()
0039             }
0040             # patch the options struct
0041             acts.examples.dd4hep.attachDD4hepGeoIdMapper(
0042                 cOptions, geometry_id_mapping_patched
0043             )
0044 
0045     # Context and options
0046     geoContext = acts.GeometryContext.dangerouslyDefaultConstruct()
0047     [detector, contextors, store] = dd4hepDetector.finalize(geoContext, cOptions)
0048 
0049     # OBJ style output
0050     surfaces = []
0051     viewConfig = acts.ViewConfig()
0052     viewConfig.nSegments = 100
0053     for vol in detector.volumePtrs():
0054         for surf in vol.surfacePtrs():
0055             if surf.geometryId.sensitive > 0:
0056                 surfaces.append(surf)
0057     acts.examples.writeSurfacesObj(surfaces, geoContext, viewConfig, "odd-surfaces.obj")
0058 
0059     # SVG style output
0060     surfaceStyle = acts.svg.Style()
0061     surfaceStyle.fillColor = [5, 150, 245]
0062     surfaceStyle.fillOpacity = 0.5
0063 
0064     surfaceOptions = acts.svg.SurfaceOptions()
0065     surfaceOptions.style = surfaceStyle
0066 
0067     viewRange = acts.Extent([])
0068     volumeOptions = acts.svg.DetectorVolumeOptions()
0069     volumeOptions.surfaceOptions = surfaceOptions
0070 
0071     # Transverse view
0072     xyRange = acts.Extent([[acts.AxisDirection.AxisZ, [-50, 50]]])
0073     xyView = acts.svg.drawDetector(
0074         geoContext,
0075         detector,
0076         "odd",
0077         [[ivol, volumeOptions] for ivol in range(detector.numberVolumes())],
0078         [["xy", ["sensitives"], xyRange]],
0079     )
0080     xyFile = acts.svg.file()
0081     xyFile.addObjects(xyView)
0082     xyFile.write("odd_xy.svg")
0083 
0084     # Longitudinal view
0085     zrRange = acts.Extent([[acts.AxisDirection.AxisPhi, [-0.1, 0.1]]])
0086     zrView = acts.svg.drawDetector(
0087         geoContext,
0088         detector,
0089         "odd",
0090         [[ivol, volumeOptions] for ivol in range(detector.numberVolumes())],
0091         [["zr", ["sensitives", "portals"], zrRange]],
0092     )
0093     zrFile = acts.svg.file()
0094     zrFile.addObjects(zrView)
0095     zrFile.write("odd_zr.svg")