16 """This class represents a loaded validation root file. It has methods for plotting the typically needed graphs."""
18 def __init__(self, filename, label=None, color_index=0, additional_information=None):
19 """Create a new validation result from the given filename.
20 Additional options for plotting (e.g. color
or label) can be given.
"""
26 np.sqrt(self.
pr_data.x_truth ** 2 + self.
pr_data.y_truth ** 2) < 0.5) & (self.
pr_data.is_primary == 1)
30 np.sqrt(self.
mc_data.x_truth ** 2 + self.
mc_data.y_truth ** 2) < 0.5) & (self.
mc_data.is_primary == 1)
39 colors = sb.color_palette()
44 self.
color = colors[color_index % len(colors)]
61 """Create validation results from an ipython calculation."""
66 label=c.get_parameters()[parameter_part],
68 c
in enumerate(calculations)]
73 label=c.get_parameters(),
75 c
in enumerate(calculations)]
78 """Return the figures of merit from the file. Mostly used for internal setting of the properties."""
80 overview = uproot.open(
81 self.
filename)[
"ExpertMCSideTrackingValidationModule_overview_figures_of_merit"].arrays(
86 overview = uproot.open(
87 self.
filename)[
"ExpertPRSideTrackingValidationModule_overview_figures_of_merit"].arrays(
98 """Print out the figures of merit as a LaTeX-ready table."""
101 latex_string =
r'\begin{table}' +
"\n"
102 latex_string +=
r' \begin{tabular}{cc} \toprule' +
"\n"
103 latex_string +=
r' & \\ \midrule' +
"\n"
104 latex_string +=
r' Finding Efficiency & ' + f
"{100 * results['finding_efficiency']:.2f}" +
r' \% \\' +
"\n"
105 latex_string +=
r' Hit Efficiency & ' + f
"{100 * results['hit_efficiency']:.2f}" +
r' \% \\' +
"\n"
106 latex_string +=
r' Fake Rate & ' + f
"{100 * results['fake_rate']:.2f}" +
r' \% \\' +
"\n"
107 latex_string +=
r' Clone Rate & ' + f
"{100 * results['clone_rate']:.2f}" +
r' \% \\ \bottomrule' +
"\n"
108 latex_string +=
r' \end{tabular}' +
"\n"
109 latex_string +=
r'\end{table}'
114 """Plot a point in the finding-efficiency/hit-efficiency plane."""
115 import matplotlib.pyplot
as plt
117 plt.xlabel(
"finding efficiency")
118 plt.ylabel(
"hit efficiency")
121 """Convenience function to return the input data (or the internal mc_data) grouped by pt."""
125 pt_values = pd.cut(mc_data.pt_truth, np.linspace(mc_data.pt_truth.min(), mc_data.pt_truth.max(), 10))
126 grouped = mc_data.groupby(pt_values)
130 def plot(self, data_x, data_y, loc=4, yerr=None):
131 """Plot data_y over data_x with the correct settings for this result. Mostly used internally."""
132 import matplotlib.pyplot
as plt
134 plt.errorbar(data_x, data_y, ls=
"-", marker=
"o",
135 color=self.
color, label=self.
label, yerr=yerr, lw=4)
137 plt.plot(data_x, data_y, ls=
"-", marker=
"o",
140 if self.
label is not None:
141 plt.legend(loc=loc, frameon=
True)
144 """Plot the finding efficiency over pt."""
145 import matplotlib.pyplot
as plt
148 self.
plot(grouped.median().pt_truth, grouped.mean().is_matched, yerr=1 / np.sqrt(grouped.count().is_matched))
149 plt.xlabel(
r"$p_T$ of the MC tracks (in GeV)")
150 plt.ylabel(
"Finding Efficiency")
153 """Plot the hit efficiency over pt."""
154 import matplotlib.pyplot
as plt
157 self.
plot(grouped.median().pt_truth, grouped.mean().hit_efficiency, yerr=1 / np.sqrt(grouped.sum().mc_number_of_hits))
158 plt.xlabel(
r"$p_T$ of the MC tracks (in GeV)")
159 plt.ylabel(
"Hit Efficiency")
162 """Print mostfully useful information about this result."""
165 primaries = pr_data[self.
pr_data.is_prompt == 1]
166 primaries_mc = mc_data[self.
mc_data.is_prompt == 1]
169 print(
"Fake", 100 * primaries.is_fake.mean(), 100 * pr_data.is_fake.mean())
170 print(
"Clone", 100 * primaries.is_clone.mean(), 100 * pr_data.is_clone.mean())
171 print(
"Ghost", 100 * primaries.is_ghost.mean(), 100 * pr_data.is_ghost.mean())
172 print(
"Fitted", 100 * primaries.is_fitted.mean(), 100 * pr_data.is_fitted.mean())
173 print(
"Found", 100 * primaries_mc.is_matched.mean(), 100 * mc_data.is_matched.mean())
174 print(
"Found2", 100.0 - 100 * primaries_mc.is_missing.mean(), 100.0 - 100 * mc_data.is_missing.mean())
175 print(
"Merged", 100 * primaries_mc.is_merged.mean(), 100 * mc_data.is_merged.mean())
176 print(
"Hit-Eff", 100 * primaries_mc.hit_efficiency.mean(), 100 * mc_data.hit_efficiency.mean())
177 print(
"Wrong Hits", primaries.number_of_wrong_hits.mean(), pr_data.number_of_wrong_hits.mean())
180 """Append the main results to a already consisting dataframe."""
188 return df.append(result, ignore_index=
True)
additional_information
the additional information
def plot(self, data_x, data_y, loc=4, yerr=None)
def print_useful_information(self)
def plot_hit_efficiency(self, data=None)
def grouped_by_pt_data(self, mc_data=None)
pr_prompts
the pr prompt data
def __init__(self, filename, label=None, color_index=0, additional_information=None)
filename
The root filename.
def plot_finding_efficiency(self, data=None)
def get_figure_of_merits(self)
def get_figures_of_merit_latex(self)
def append_to_dataframe(self, df)
hit_efficiency
the hit efficiency
def plot_efficiency_point(self)
finding_efficiency
the finding efficiency
mc_prompts
the mc prompt data
def from_calculations(calculations, key="output_file_name", parameter_part=None)