File indexing completed on 2026-07-26 08:22:17
0001 import subprocess
0002 import logging
0003 import re
0004 import shutil
0005 import os
0006 import json
0007 import pathlib
0008
0009 log = logging.getLogger("traccc_physics_plots.run")
0010
0011 SEEDING_EXAMPLE_ARGS = [
0012 "--input-directory=/data/Acts/odd-simulations-20240506/geant4_ttbar_mu200",
0013 "--digitization-file=geometries/odd/odd-digi-geometric-config.json",
0014 "--conditions-file=geometries/odd/odd-conditions.json",
0015 "--detector-file=geometries/odd/odd-detray_geometry_detray.json",
0016 "--grid-file=geometries/odd/odd-detray_surface_grids_detray.json",
0017 "--material-file=geometries/odd/odd-detray_material_detray.json",
0018 "--input-events=10",
0019 "--use-acts-geom-source=on",
0020 "--check-performance",
0021 "--truth-finding-min-track-candidates=5",
0022 "--truth-finding-min-pt=1.0",
0023 "--truth-finding-min-z=-150",
0024 "--truth-finding-max-z=150",
0025 "--truth-finding-max-r=10",
0026 "--seed-matching-ratio=0.99",
0027 "--track-matching-ratio=0.5",
0028 "--track-candidates-range=5:100",
0029 "--seedfinder-vertex-range=-150:150",
0030 ]
0031
0032
0033 def run_convert_seeding_example(
0034 seeding_example_executable,
0035 seeding_example_args,
0036 tmpdirname,
0037 output_dir,
0038 root_to_csv_exec=None,
0039 ):
0040 log.info("Running seeding example...")
0041
0042 if root_to_csv_exec is None:
0043 root_to_csv_exec = "./root_to_csv/root_to_csv"
0044
0045 if seeding_example_executable.name != "traccc_seeding_example_cuda":
0046 log.warning(
0047 'Executable name is not "traccc_seeding_example_cuda" but "%s"; this will likely fail',
0048 seeding_example_executable.name,
0049 )
0050
0051 result = subprocess.run(
0052 [seeding_example_executable] + seeding_example_args,
0053 check=True,
0054 cwd=tmpdirname,
0055 stdout=subprocess.PIPE,
0056 stderr=subprocess.STDOUT,
0057 )
0058
0059 stdout = result.stdout.decode("utf-8")
0060
0061 if match := re.search(r"- created \(cuda\)\s+(\d+) seeds", stdout):
0062 num_seeds = int(match.group(1))
0063 else:
0064 raise ValueError("Seed count could not be parsed from stdout!")
0065
0066 if match := re.search(r"- created \(cuda\)\s+(\d+) found tracks", stdout):
0067 num_found_tracks = int(match.group(1))
0068 else:
0069 raise ValueError("Found track count could not be parsed from stdout!")
0070
0071 if match := re.search(r"- created \(cuda\)\s+(\d+) fitted tracks", stdout):
0072 num_fitted_tracks = int(match.group(1))
0073 else:
0074 raise ValueError("Fitted track count could not be parsed from stdout!")
0075
0076 with open(output_dir / "counts.json", "w") as f:
0077 json.dump(
0078 {
0079 "seeds": num_seeds,
0080 "found": num_found_tracks,
0081 "fitted": num_fitted_tracks,
0082 },
0083 f,
0084 )
0085
0086 for f in ["seeding", "finding", "fitting"]:
0087 fn = "performance_track_%s.root" % f
0088 shutil.copy(pathlib.Path(tmpdirname) / fn, output_dir)
0089
0090 try:
0091 os.mkdir(output_dir / f)
0092 except FileExistsError:
0093 pass
0094
0095 subprocess.run(
0096 [
0097 root_to_csv_exec,
0098 str(output_dir / fn),
0099 str(output_dir / f),
0100 ],
0101 check=True,
0102 stdout=subprocess.DEVNULL,
0103 )