Skip to content

Commit 2637ab0

Browse files
committed
Updated the efficiency plotter script.
So that it would overlay the seed-finding and track-finding efficiencies on top of each other. In a super hard-coded way.
1 parent ebd2d38 commit 2637ab0

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

extras/traccc_plot_tracking_efficiencies.py

+43-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import ROOT
1313

1414

15-
def plotEfficiency(graph):
15+
def plotEfficiency(graph, col=ROOT.kBlack, opts="AP"):
1616
"""Plot one efficiency histogram"""
1717

1818
# Set the properties of the histogram.
@@ -23,12 +23,14 @@ def plotEfficiency(graph):
2323
graph.GetYaxis().SetRangeUser(0.0, 1.1)
2424
graph.GetXaxis().SetTitleSize(0.07)
2525
graph.GetXaxis().SetTitleOffset(0.6)
26+
graph.SetLineColor(col)
27+
graph.SetMarkerColor(col)
2628

2729
# Draw the histogram.
28-
graph.Draw("AP")
30+
graph.Draw(opts)
2931

3032
# Return gracefully.
31-
return
33+
return graph
3234

3335

3436
def main():
@@ -42,7 +44,8 @@ def main():
4244
parser.add_argument(
4345
"-i",
4446
"--input",
45-
help="Input ROOT file",
47+
nargs=2,
48+
help="Input ROOT files",
4649
default="track_finding_efficiency.root",
4750
)
4851
parser.add_argument(
@@ -53,28 +56,51 @@ def main():
5356
)
5457
args = parser.parse_args()
5558

56-
# Open the input file.
57-
input_file = ROOT.TFile.Open(args.input, "READ")
58-
if not input_file:
59-
print(f"Failed to open input file '{args.input}'")
60-
return 1
61-
6259
# Create a canvas to draw on.
6360
canvas = ROOT.TCanvas("canvas", "canvas", 1000, 1000)
6461
canvas.Divide(1, 2)
6562

66-
# Get the efficiency histograms from the input file.
67-
eta_plot = input_file.Get("track_finding_eff_eta")
68-
phi_plot = input_file.Get("track_finding_eff_phi")
69-
if not eta_plot or not phi_plot:
70-
print("Failed to retrieve efficiency histograms")
63+
# Open the seeding efficiency file.
64+
seeding_efficiency_file = ROOT.TFile.Open(args.input[0], "READ")
65+
if not seeding_efficiency_file:
66+
print(f"Failed to open input file '{args.input[0]}'")
67+
return 1
68+
69+
# Get the seeding efficiency histograms.
70+
seeding_efficiency_eta = seeding_efficiency_file.Get("seed_finding_eff_eta")
71+
seeding_efficiency_phi = seeding_efficiency_file.Get("seed_finding_eff_phi")
72+
if not seeding_efficiency_eta or not seeding_efficiency_phi:
73+
print("Failed to retrieve efficiency histograms in %s" % args.input[0])
74+
return 1
75+
76+
# Open the tracking efficiency file.
77+
tracking_efficiency_file = ROOT.TFile.Open(args.input[1], "READ")
78+
if not tracking_efficiency_file:
79+
print(f"Failed to open input file '{args.input[1]}'")
80+
return 1
81+
82+
# Get the tracking efficiency histograms.
83+
tracking_efficiency_eta = tracking_efficiency_file.Get("track_finding_eff_eta")
84+
tracking_efficiency_phi = tracking_efficiency_file.Get("track_finding_eff_phi")
85+
if not tracking_efficiency_eta or not tracking_efficiency_phi:
86+
print("Failed to retrieve efficiency histograms in %s" % args.input[1])
7187
return 1
7288

7389
# Draw the histograms.
7490
canvas.cd(1)
75-
plotEfficiency(eta_plot.CreateGraph())
91+
seeding_legend = plotEfficiency(seeding_efficiency_eta.CreateGraph(), ROOT.kBlue)
92+
tracking_legend = plotEfficiency(
93+
tracking_efficiency_eta.CreateGraph(), ROOT.kRed, "P"
94+
)
7695
canvas.cd(2)
77-
plotEfficiency(phi_plot.CreateGraph())
96+
plotEfficiency(seeding_efficiency_phi.CreateGraph(), ROOT.kBlue)
97+
plotEfficiency(tracking_efficiency_phi.CreateGraph(), ROOT.kRed, "P")
98+
99+
# Create a legend.
100+
legend = ROOT.TLegend(0.6, 0.2, 0.9, 0.4)
101+
legend.AddEntry(seeding_legend, "Seed finding efficiency", "lpe")
102+
legend.AddEntry(tracking_legend, "Track finding efficiency", "lpe")
103+
legend.Draw()
78104

79105
# Save the canvas to a file.
80106
canvas.SaveAs(args.output)

0 commit comments

Comments
 (0)