Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:18:32

0001 #!/usr/bin/env python3
0002 import os
0003 import argparse
0004 from pathlib import Path
0005 
0006 from acts.examples import (
0007     AlignedDetector,
0008     WhiteBoard,
0009     AlgorithmContext,
0010     ProcessCode,
0011     JsonSurfacesWriter,
0012     JsonMaterialWriter,
0013     JsonFormat,
0014 )
0015 
0016 import acts
0017 import json
0018 
0019 from acts import MaterialMapJsonConverter
0020 import build_geometry_ePIC as geo
0021 
0022 
0023 def runGeometry(
0024     trackingGeometry,
0025     # decorators,
0026     outputDir="",
0027     outputName="geometry-map",
0028     outputObj=False,
0029     outputCsv=False,
0030     outputJson=True,
0031     outputRoot=False,
0032 ):
0033     wb = WhiteBoard(acts.logging.INFO)
0034     context = AlgorithmContext(0, 0, wb)
0035 
0036     writer = JsonSurfacesWriter(
0037         level=acts.logging.INFO,
0038         trackingGeometry=trackingGeometry,
0039         outputDir=outputDir,
0040         writePerEvent=True,
0041         writeSensitive=True,
0042     )
0043     writer.write(context)
0044 
0045     jmConverterCfg = MaterialMapJsonConverter.Config(
0046         processSensitives=True,
0047         processApproaches=True,
0048         processRepresenting=True,
0049         processBoundaries=True,
0050         processVolumes=True,
0051         processNonMaterial=True,
0052         context=context.geoContext,
0053     )
0054 
0055     outpath = os.path.join(outputDir, outputName)
0056     jmw = JsonMaterialWriter(
0057         level=acts.logging.VERBOSE,
0058         converterCfg=jmConverterCfg,
0059         fileName=outpath,
0060         writeFormat=JsonFormat.Json,
0061     )
0062     print("Done! Output geometry file at "+outpath+".json")
0063     jmw.write(trackingGeometry)
0064 
0065 
0066 if "__main__" == __name__:
0067     p = argparse.ArgumentParser(
0068         description="Script to generate geometry-map.json for ePIC geometry"
0069     )
0070     p.add_argument(
0071         "-i","--xmlFile",
0072         default=os.environ.get("DETECTOR_PATH", "")+"epic_craterlake.xml",
0073         help="Input xml file containing ePIC geometry",
0074     )
0075     p.add_argument(
0076         "-o","--geoFile",
0077         type=str,
0078         default="geometry-map.json",
0079         help="Output Json file to define volumes and layers used in material mapping",
0080     )
0081 
0082     args = p.parse_args()
0083     print(args)
0084     detector, trackingGeometry, decorators = geo.buildePICGeometry(
0085         args.xmlFile)
0086 
0087     runGeometry(trackingGeometry, outputDir=os.getcwd(), outputName=args.geoFile.split(".")[0])
0088 
0089     # Uncomment if you want to create the geometry id mapping for DD4hep
0090     # dd4hepIdGeoIdMap = acts.examples.dd4hep.createDD4hepIdGeoIdMap(trackingGeometry)
0091     # dd4hepIdGeoIdValueMap = {}
0092     # for key, value in dd4hepIdGeoIdMap.items():
0093     #     dd4hepIdGeoIdValueMap[key] = value.value()
0094 
0095     # with open('odd-dd4hep-geoid-mapping.json', 'w') as outfile:
0096     #    json.dump(dd4hepIdGeoIdValueMap, outfile)