Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:08

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 
0014 if "__main__" == __name__:
0015     odd_xml = getOpenDataDetectorDirectory() / "xml" / "OpenDataDetector.xml"
0016 
0017     print("Using the following xml file: ", odd_xml)
0018 
0019     # Create the dd4hep geometry service and detector
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     # Uncomment if you want to use the geometry id mapping
0029     # This map can be produced with the 'geometry.py' script
0030     geoIdMappingFile = None  # "odd-dd4hep-geoid-mapping-wo-extra.json"
0031     if geoIdMappingFile is not None:
0032         # Load the geometry id mapping json file
0033         with open(geoIdMappingFile) as f:
0034             # load the file as is
0035             geometry_id_mapping = json.load(f)
0036             # create a dictionary with GeometryIdentifier as value
0037             geometry_id_mapping_patched = {
0038                 int(k): acts.GeometryIdentifier(int(v))
0039                 for k, v in geometry_id_mapping.items()
0040             }
0041             # patch the options struct
0042             acts.examples.dd4hep.attachDD4hepGeoIdMapper(
0043                 cOptions, geometry_id_mapping_patched
0044             )
0045 
0046     # Context and options
0047     geoContext = acts.GeometryContext()
0048     [detector, contextors, store] = dd4hepDetector.finalize(geoContext, cOptions)
0049 
0050     surfaceStyle = acts.svg.Style()
0051     surfaceStyle.fillColor = [5, 150, 245]
0052     surfaceStyle.fillOpacity = 0.5
0053 
0054     surfaceOptions = acts.svg.SurfaceOptions()
0055     surfaceOptions.style = surfaceStyle
0056 
0057     viewRange = acts.Extent([])
0058     volumeOptions = acts.svg.DetectorVolumeOptions()
0059     volumeOptions.surfaceOptions = surfaceOptions
0060 
0061     for ivol in range(detector.number_volumes()):
0062         acts.svg.viewDetector(
0063             geoContext,
0064             detector,
0065             "odd-xy",
0066             [[ivol, volumeOptions]],
0067             [["xy", ["sensitives"], viewRange]],
0068             "vol_" + str(ivol),
0069         )
0070 
0071     xyRange = acts.Extent([[acts.Binning.z, [-50, 50]]])
0072     zrRange = acts.Extent([[acts.Binning.phi, [-0.1, 0.1]]])
0073 
0074     acts.svg.viewDetector(
0075         geoContext,
0076         detector,
0077         "odd",
0078         [[ivol, volumeOptions] for ivol in range(detector.number_volumes())],
0079         [["xy", ["sensitives"], xyRange], ["zr", ["materials"], zrRange]],
0080         "detector",
0081     )
0082 
0083     # acts.examples.writeDetectorToJsonDetray(geoContext, detector, "odd-detray")