Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-16 08:48:25

0001 """Generate illustrative figures for the Python performance documentation.
0002 
0003 Run with: uv run --no-project --with matplotlib docs/examples/generate_python_performance_plots.py
0004 The values are illustrative, not ACTS performance measurements.
0005 """
0006 
0007 from math import exp, sqrt
0008 from pathlib import Path
0009 from random import Random
0010 
0011 import matplotlib
0012 
0013 matplotlib.use("Agg")
0014 import matplotlib.pyplot as plt
0015 
0016 FIGURES = Path(__file__).resolve().parents[1] / "figures" / "python"
0017 
0018 
0019 def save(fig, name):
0020     FIGURES.mkdir(parents=True, exist_ok=True)
0021     path = FIGURES / name
0022     fig.savefig(path, bbox_inches="tight")
0023     path.write_text(
0024         "\n".join(line.rstrip() for line in path.read_text().splitlines()) + "\n"
0025     )
0026     plt.close(fig)
0027 
0028 
0029 def main():
0030     plt.rcParams.update({"font.size": 11, "svg.fonttype": "none"})
0031     rng = Random(42)
0032 
0033     pt = [0.5 * i for i in range(1, 21)]
0034     trials = 150
0035     efficiency = [
0036         sum(rng.random() < 0.94 * (1 - exp(-p / 1.3)) for _ in range(trials)) / trials
0037         for p in pt
0038     ]
0039     efficiency_error = [sqrt(value * (1 - value) / trials) for value in efficiency]
0040     fig, ax = plt.subplots(figsize=(6, 3.5))
0041     ax.errorbar(
0042         pt,
0043         efficiency,
0044         yerr=efficiency_error,
0045         fmt="o",
0046         markersize=3,
0047         capsize=2,
0048         color="#16669e",
0049     )
0050     ax.set(xlabel=r"$p_T$ [GeV]", ylabel="Tracking efficiency", ylim=(0, 1.02))
0051     ax.grid(alpha=0.2)
0052     save(fig, "tracking_efficiency.svg")
0053 
0054     residual = [0.03 * i for i in range(-15, 16)]
0055     expected = [125 * exp(-0.5 * (x / 0.09) ** 2) for x in residual]
0056     counts = [max(0, round(rng.gauss(value, sqrt(value)))) for value in expected]
0057     count_error = [sqrt(count) for count in counts]
0058     fig, ax = plt.subplots(figsize=(6, 3.5))
0059     ax.step(residual, counts, where="mid", color="#a4493b")
0060     ax.errorbar(
0061         residual, counts, yerr=count_error, fmt="none", capsize=2, color="#a4493b"
0062     )
0063     ax.set(xlabel=r"$d_0$ residual [mm]", ylabel="Tracks")
0064     ax.grid(alpha=0.2)
0065     save(fig, "track_residual.svg")
0066 
0067 
0068 if __name__ == "__main__":
0069     main()