Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 08:27:56

0001 #!/usr/bin/env python3
0002 # SPDX-License-Identifier: LGPL-3.0-or-later
0003 # Copyright (C) 2024 Shujie Li
0004 
0005 import os
0006 import argparse
0007 from pathlib import Path
0008 
0009 import acts
0010 from material_mapping import runMaterialMapping
0011 
0012 try:
0013     from acts.examples.json import JsonFormat
0014 except ImportError:
0015     from acts.examples import JsonFormat
0016 
0017 import epic
0018 
0019 
0020 if "__main__" == __name__:
0021 
0022     p = argparse.ArgumentParser(
0023         description="Script to generate material map for ePIC geometry"
0024     )
0025     p.add_argument(
0026         "--xmlFile",
0027         default=os.environ.get("DETECTOR_PATH", "")+"epic_craterlake.xml",
0028         help="input xml file containing ePIC geometry",
0029     )
0030     p.add_argument(
0031         "--geoFile",
0032         type=str,
0033         default="geometry-map.json",
0034         help="input json file to define volumes and layers used in material mapping",
0035     )
0036     p.add_argument(
0037         "--matFileBase",
0038         type=str,
0039         default="material-map",
0040         help="base name for the generated material map (without extension)",
0041     )
0042     p.add_argument(
0043         "--matFileFormat",
0044         type=str,
0045         nargs="+",
0046         default=["json", "root"],
0047         help="output format(s) for the material map (json, cbor, root). Default: json, root",
0048     )
0049     p.add_argument(
0050         "--inputRootFile",
0051         type=str,
0052         default="geant4_material_tracks.root",
0053         help="input ROOT file with material tracks (typically from material_recording_epic.py)",
0054     )
0055     args = p.parse_args()
0056 
0057     # Parse material map formats
0058     mapFormats = args.matFileFormat
0059     # Validate formats
0060     valid_formats = {"json", "cbor", "root"}
0061     for fmt in mapFormats:
0062         if fmt not in valid_formats:
0063             print(f'ERROR(material_mapping_epic.py): invalid format "{fmt}". Must be one of: {", ".join(valid_formats)}')
0064             exit(1)
0065 
0066     detector = epic.getDetector(args.xmlFile)
0067     trackingGeometry = detector.trackingGeometry()
0068     decorators = detector.contextDecorators()
0069 
0070     materialSurfaces = trackingGeometry.extractMaterialSurfaces()
0071 
0072     outputFileBase = os.path.join(os.getcwd(), args.matFileBase)
0073 
0074     runMaterialMapping(
0075         surfaces=materialSurfaces,
0076         inputFile=Path(args.inputRootFile),
0077         outputFileBase=outputFileBase,
0078         outputMapFormats=mapFormats,
0079     ).run()