ATLAS Offline Software
Loading...
Searching...
No Matches
stepPlot.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""
3compare_volumes.py
4Compare two G4Debugger “volumeSummary” histograms and plot their ratio. These histograms are
5Created by G4DebuggingTools.G4DebuggingToolsConfig.StepHistogramToolCfg.
6
7Example
8-------
9python compare_volumes.py \
10 --base path_where_hisgrom\
11 --in1 root_file_name_1 \
12 --in2 root_file_name_2 \
13 --atlas-style path_to_AtlasStyle \
14 --out-dir ./plots
15"""
16import argparse
17import os
18import ROOT
19from ROOT import gROOT
20
21from G4Debugger import G4Debugger
22from G4DebuggerUtils import plotSummaryRatio
23
24
25# ---------------------------------------------------------------------------
26def parse_args() -> argparse.Namespace:
27 """Define and parse CLI arguments."""
28 parser = argparse.ArgumentParser(
29 description="Compare volume summaries from two G4Debugger runs."
30 )
31
32 parser.add_argument(
33 "--base",
34 required=True,
35 help="Base directory containing the StepHistograms_* sub-directories.",
36 )
37 parser.add_argument(
38 "--in1", required=True, metavar="SUBDIR_1",
39 help="First StepHistograms_* sub-directory."
40 )
41 parser.add_argument(
42 "--in2", required=True, metavar="SUBDIR_2",
43 help="Second StepHistograms_* sub-directory."
44 )
45 parser.add_argument(
46 "--atlas-style", required=True,
47 help="Directory holding AtlasStyle.C / AtlasLabels.C / AtlasUtils.C."
48 )
49 parser.add_argument(
50 "--out-dir", default=".",
51 help="Where to write the output plot [default: current directory]."
52 )
53 parser.add_argument("--v1-label", default="Non Opt", help="Legend label for first sample.")
54 parser.add_argument("--v2-label", default="Opt", help="Legend label for second sample.")
55
56 return parser.parse_args()
57
58
59def set_atlas_style(style_dir: str) -> None:
60 """Load ATLAS style macros if they exist."""
61 if not os.path.isdir(style_dir):
62 raise FileNotFoundError(f"AtlasStyle directory not found: {style_dir}")
63
64 print(f"Loading ATLAS style from {style_dir}")
65 gROOT.LoadMacro(os.path.join(style_dir, "AtlasStyle.C"))
66 gROOT.LoadMacro(os.path.join(style_dir, "AtlasLabels.C"))
67 gROOT.LoadMacro(os.path.join(style_dir, "AtlasUtils.C"))
68 ROOT.SetAtlasStyle()
69
70
71# ---------------------------------------------------------------------------
72def main() -> None:
73 args = parse_args()
74 gROOT.SetBatch(True)
75 set_atlas_style(args.atlas_style)
76
77 dbg1 = G4Debugger(args.base, args.in1)
78 dbg2 = G4Debugger(args.base, args.in2)
79
80 print(dbg1.volumeSummary) # quick sanity check
81
82 plotSummaryRatio(
83 dbg1.volumeSummary,
84 dbg2.volumeSummary,
85 xaxis="Volumes",
86 v1=args.v1_label,
87 v2=args.v2_label,
88 directory=args.out_dir,
89 name="volumeSummary",
90 )
91
92
93if __name__ == "__main__":
94 main()
void print(char *figname, TCanvas *c1)
argparse.Namespace parse_args()
Definition stepPlot.py:26
None set_atlas_style(str style_dir)
Definition stepPlot.py:59