Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:35:25

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 
0011 import epic
0012 from geometry import runGeometry
0013 
0014 if "__main__" == __name__:
0015     p = argparse.ArgumentParser(
0016         description="Script to generate geometry-map.json for ePIC geometry"
0017     )
0018     p.add_argument(
0019         "-i",
0020         "--xmlFile",
0021         default=(
0022             os.environ.get("DETECTOR_PATH", "")
0023             + "/"
0024             + os.environ.get("DETECTOR_CONFIG", "")
0025             + ".xml"
0026         ),
0027         help="Input xml file containing ePIC geometry",
0028     )
0029     p.add_argument(
0030         "-o",
0031         "--outputName",
0032         type=str,
0033         default="geometry-map",
0034         help="output name for the geometry JSON file (without .json extension)",
0035     )
0036     args = p.parse_args()
0037 
0038     detector = epic.getDetector(args.xmlFile)
0039     trackingGeometry = detector.trackingGeometry()
0040     decorators = detector.contextDecorators()
0041 
0042     import tempfile
0043     import shutil
0044 
0045     # Generate geometry to a temporary directory, then rename the output file
0046     tmpdir = Path(tempfile.mkdtemp())
0047     try:
0048         runGeometry(
0049             trackingGeometry,
0050             decorators,
0051             outputDir=tmpdir,
0052             outputObj=False,
0053             outputCsv=False,
0054             outputSurfacesJson=True,
0055         )
0056         # Move the generated geometry-map.json to the desired output name
0057         src_file = tmpdir / "geometry-map.json"
0058         dst_file = Path.cwd() / f"{args.outputName}.json"
0059         if src_file.exists():
0060             shutil.move(str(src_file), str(dst_file))
0061         else:
0062             raise FileNotFoundError(f"Expected geometry file not found at {src_file}")
0063     finally:
0064         shutil.rmtree(tmpdir)