Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:08

0001 #!/usr/bin/env python3
0002 
0003 import os
0004 import json
0005 
0006 import acts
0007 from acts import MaterialMapJsonConverter
0008 from acts.examples.odd import getOpenDataDetector
0009 from acts.examples import (
0010     WhiteBoard,
0011     AlgorithmContext,
0012     ProcessCode,
0013     CsvTrackingGeometryWriter,
0014     ObjTrackingGeometryWriter,
0015     JsonSurfacesWriter,
0016     JsonMaterialWriter,
0017     JsonFormat,
0018 )
0019 
0020 
0021 def runGeometry(
0022     trackingGeometry,
0023     decorators,
0024     outputDir,
0025     events=1,
0026     outputObj=True,
0027     outputCsv=True,
0028     outputJson=True,
0029 ):
0030     for ievt in range(events):
0031         eventStore = WhiteBoard(name=f"EventStore#{ievt}", level=acts.logging.INFO)
0032         ialg = 0
0033 
0034         context = AlgorithmContext(ialg, ievt, eventStore)
0035 
0036         for cdr in decorators:
0037             r = cdr.decorate(context)
0038             if r != ProcessCode.SUCCESS:
0039                 raise RuntimeError("Failed to decorate event context")
0040 
0041         if outputCsv:
0042             # if not os.path.isdir(outputDir + "/csv"):
0043             #    os.makedirs(outputDir + "/csv")
0044             writer = CsvTrackingGeometryWriter(
0045                 level=acts.logging.INFO,
0046                 trackingGeometry=trackingGeometry,
0047                 outputDir=os.path.join(outputDir, "csv"),
0048                 writePerEvent=True,
0049             )
0050             writer.write(context)
0051 
0052         if outputObj:
0053             writer = ObjTrackingGeometryWriter(
0054                 level=acts.logging.INFO, outputDir=os.path.join(outputDir, "obj")
0055             )
0056             writer.write(context, trackingGeometry)
0057 
0058         if outputJson:
0059             # if not os.path.isdir(outputDir + "/json"):
0060             #    os.makedirs(outputDir + "/json")
0061             writer = JsonSurfacesWriter(
0062                 level=acts.logging.INFO,
0063                 trackingGeometry=trackingGeometry,
0064                 outputDir=os.path.join(outputDir, "json"),
0065                 writePerEvent=True,
0066                 writeSensitive=True,
0067             )
0068             writer.write(context)
0069 
0070             jmConverterCfg = MaterialMapJsonConverter.Config(
0071                 processSensitives=True,
0072                 processApproaches=True,
0073                 processRepresenting=True,
0074                 processBoundaries=True,
0075                 processVolumes=True,
0076                 processNonMaterial=True,
0077                 context=context.geoContext,
0078             )
0079 
0080             jmw = JsonMaterialWriter(
0081                 level=acts.logging.VERBOSE,
0082                 converterCfg=jmConverterCfg,
0083                 fileName=os.path.join(outputDir, "geometry-map"),
0084                 writeFormat=JsonFormat.Json,
0085             )
0086 
0087             jmw.write(trackingGeometry)
0088 
0089 
0090 if "__main__" == __name__:
0091     # detector = AlignedDetector()
0092     # detector = GenericDetector()
0093     detector = getOpenDataDetector()
0094     trackingGeometry = detector.trackingGeometry()
0095     decorators = detector.contextDecorators()
0096 
0097     runGeometry(trackingGeometry, decorators, outputDir=os.getcwd())
0098 
0099     # Uncomment if you want to create the geometry id mapping for DD4hep
0100     # dd4hepIdGeoIdMap = acts.examples.dd4hep.createDD4hepIdGeoIdMap(trackingGeometry)
0101     # dd4hepIdGeoIdValueMap = {}
0102     # for key, value in dd4hepIdGeoIdMap.items():
0103     #     dd4hepIdGeoIdValueMap[key] = value.value()
0104 
0105     # with open('odd-dd4hep-geoid-mapping.json', 'w') as outfile:
0106     #    json.dump(dd4hepIdGeoIdValueMap, outfile)