3 from root_pandas
import read_root
9 """This class represents a loaded validation root file. It has methods for plotting the typically needed graphs."""
11 def __init__(self, filename, label=None, color_index=0, additional_information=None):
12 """Create a new validation result from the given filename.
13 Additional options for plotting (e.g. color or label) can be given."""
19 np.sqrt(self.
pr_data.x_truth ** 2 + self.
pr_data.y_truth ** 2) < 0.5) & (self.
pr_data.is_primary == 1)
23 np.sqrt(self.
mc_data.x_truth ** 2 + self.
mc_data.y_truth ** 2) < 0.5) & (self.
mc_data.is_primary == 1)
32 colors = sb.color_palette()
37 self.
color = colors[color_index % len(colors)]
54 """Create validation results from an ipython calculation."""
59 label=c.get_parameters()[parameter_part],
61 c
in enumerate(calculations)]
66 label=c.get_parameters(),
68 c
in enumerate(calculations)]
71 """Return the figures of merit from the file. Mosty used for internal seeting of the properties."""
73 overview = read_root(self.
filename, tree_key=
"ExpertMCSideTrackingValidationModule_overview_figures_of_merit")
77 overview = read_root(self.
filename, tree_key=
"ExpertPRSideTrackingValidationModule_overview_figures_of_merit")
87 """Print out the figures of merit as a LaTeX-ready table."""
90 latex_string =
r'\begin{table}' +
"\n"
91 latex_string +=
r' \begin{tabular}{cc} \toprule' +
"\n"
92 latex_string +=
r' & \\ \midrule' +
"\n"
93 latex_string +=
r' Finding Efficiency & ' +
"%.2f" % (100 * results[
"finding_efficiency"]) +
r' \% \\' +
"\n"
94 latex_string +=
r' Hit Efficiency & ' +
"%.2f" % (100 * results[
"hit_efficiency"]) +
r' \% \\' +
"\n"
95 latex_string +=
r' Fake Rate & ' +
"%.2f" % (100 * results[
"fake_rate"]) +
r' \% \\' +
"\n"
96 latex_string +=
r' Clone Rate & ' +
"%.2f" % (100 * results[
"clone_rate"]) +
r' \% \\ \bottomrule' +
"\n"
97 latex_string +=
r' \end{tabular}' +
"\n"
98 latex_string +=
r'\end{table}'
103 """Plot a oint in the finding-efficiency/hit-efficiency plane."""
104 import matplotlib.pyplot
as plt
106 plt.xlabel(
"finding efficiency")
107 plt.ylabel(
"hit efficiency")
110 """Convenience function to return the input data (or the internal mc_data) grouped by pt."""
114 pt_values = pd.cut(mc_data.pt_truth, np.linspace(mc_data.pt_truth.min(), mc_data.pt_truth.max(), 10))
115 grouped = mc_data.groupby(pt_values)
119 def plot(self, data_x, data_y, loc=4, yerr=None):
120 """Plot data_y over data_x with the correct settings for this result. Mostly used internally."""
121 import matplotlib.pyplot
as plt
123 plt.errorbar(data_x, data_y, ls=
"-", marker=
"o",
124 color=self.
color, label=self.
label, yerr=yerr, lw=4)
126 plt.plot(data_x, data_y, ls=
"-", marker=
"o",
129 if self.
label is not None:
130 plt.legend(loc=loc, frameon=
True)
133 """Plot the finding efficiency over pt."""
134 import matplotlib.pyplot
as plt
137 self.
plot(grouped.median().pt_truth, grouped.mean().is_matched, yerr=1 / np.sqrt(grouped.count().is_matched))
138 plt.xlabel(
r"$p_T$ of the MC tracks (in GeV)")
139 plt.ylabel(
"Finding Efficiency")
142 """Plot the hit efficiency over pt."""
143 import matplotlib.pyplot
as plt
146 self.
plot(grouped.median().pt_truth, grouped.mean().hit_efficiency, yerr=1 / np.sqrt(grouped.sum().mc_number_of_hits))
147 plt.xlabel(
r"$p_T$ of the MC tracks (in GeV)")
148 plt.ylabel(
"Hit Efficiency")
151 """Print mostfully useful information about this result."""
154 primaries = pr_data[self.
pr_data.is_prompt == 1]
155 primaries_mc = mc_data[self.
mc_data.is_prompt == 1]
158 print(
"Fake", 100 * primaries.is_fake.mean(), 100 * pr_data.is_fake.mean())
159 print(
"Clone", 100 * primaries.is_clone.mean(), 100 * pr_data.is_clone.mean())
160 print(
"Ghost", 100 * primaries.is_ghost.mean(), 100 * pr_data.is_ghost.mean())
161 print(
"Fitted", 100 * primaries.is_fitted.mean(), 100 * pr_data.is_fitted.mean())
162 print(
"Found", 100 * primaries_mc.is_matched.mean(), 100 * mc_data.is_matched.mean())
163 print(
"Found2", 100.0 - 100 * primaries_mc.is_missing.mean(), 100.0 - 100 * mc_data.is_missing.mean())
164 print(
"Merged", 100 * primaries_mc.is_merged.mean(), 100 * mc_data.is_merged.mean())
165 print(
"Hit-Eff", 100 * primaries_mc.hit_efficiency.mean(), 100 * mc_data.hit_efficiency.mean())
166 print(
"Wrong Hits", primaries.number_of_wrong_hits.mean(), pr_data.number_of_wrong_hits.mean())
169 """Append the main results to a already consisting dataframe."""
177 return df.append(result, ignore_index=
True)