23 formatter = TolerateMissingKeyFormatter()
27 """Perform resolution analysis"""
30 default_outlier_z_score = 5.0
32 default_min_required_entries = 50
34 default_plot_name =
"{plot_name_prefix}_{subplot_name}{plot_name_postfix}"
36 default_plot_title =
"{subplot_title} of {quantity_name}{plot_title_postfix}"
38 default_which_plots = [
43 default_is_expert =
True
56 min_required_entries=None,
59 plot_title_postfix='',
60 referenceFileName=None,
62 """Performs a comparison of an estimated quantity to their truths by generating standardized validation plots."""
67 self.
unitunit = unit
or get_unit(quantity_name)
75 if outlier_z_score
is None:
92 self.
plot_name_prefixplot_name_prefix = plot_name_prefix
or root_save_name(quantity_name)
101 self.
plotsplots = collections.OrderedDict()
114 """Compares the concrete estimate to the truth and generates plots of the resolution
118 bin_values : array_like(float
119 The parametr used for binning
120 truths : array_like(float)
121 Sample of the true values
122 estimates : array_like(float)
123 Corresponding estimations
126 if is_expert
is None:
129 if which_plots
is None:
140 if plot_name
is None:
143 plot_name = formatter.format(plot_name,
144 quantity_name=quantity_name,
145 plot_name_prefix=plot_name_prefix,
149 if plot_title
is None:
152 plot_title = formatter.format(plot_title,
153 quantity_name=quantity_name,
157 residuals = estimates - truths
161 if "resolution" in which_plots:
165 resolution_values = []
167 for i
in range(len(self.
bin_spacingbin_spacing) - 1):
170 assert (lower_bin < upper_bin)
171 bin_center = lower_bin + (upper_bin - lower_bin) / 2.0
172 assert (len(bin_values) == len(residuals))
175 sel_residuals = collections.deque()
177 for i
in range(len(bin_values)):
178 if bin_values[i] >= lower_bin
and bin_values[i] < upper_bin:
179 sel_residuals.append(residuals[i])
181 residuals_hist_name = formatter.format(plot_name, subplot_name=
"residuals") + \
182 "{}_to_{}".format(lower_bin, upper_bin)
184 vplot.hist(sel_residuals,
185 outlier_z_score=outlier_z_score,
187 vplot.xlabel = compose_axis_label(
"#Delta " + quantity_name +
" (estimate - truth)", self.
unitunit)
188 vplot.title = formatter.format(plot_title, subplot_title=
'Residual distribution')
192 gaus_sigma_err =
None
196 fit_res = vplot.fit_gaus(z_score=1)
199 params = fit_res.GetParams()
200 errs = fit_res.Errors()
203 gaus_sigma = params[2]
204 gaus_sigma_err = errs[2]
206 res_histogram += [(lower_bin, upper_bin, bin_center, vplot)]
207 self.
plotsplots[
'residuals' + residuals_hist_name] = vplot
210 resolution_values += [(lower_bin, upper_bin, bin_center, gaus_sigma, gaus_sigma_err)]
212 resolution_graph_name = formatter.format(plot_name, subplot_name=
"resolution")
221 for v
in resolution_values:
230 resolution_graph.grapherrors((np.array(xs), np.array(xs_err)), (np.array(ys), np.array(ys_err)),
232 resolution_graph.xlabel = compose_axis_label(self.
bin_namebin_name, self.
bin_unitbin_unit)
233 resolution_graph.ylabel = compose_axis_label(self.
quantity_namequantity_name, self.
unitunit)
234 resolution_graph.title = formatter.format(plot_title, subplot_title=
'Resolution')
236 self.
plotsplots[resolution_graph_name] = resolution_graph
243 """Get the contact person's name"""
248 """Set the contact person's name"""
250 for validation_plot
in list(self.
plotsplots.values()):
251 validation_plot.contact = contact
254 """Write all validation plot to the given Root directory"""
255 for validation_plot
in list(self.
plotsplots.values()):
256 validation_plot.write(tDirectory)
int default_min_required_entries
default minimum number of entries
quantity_name
cached name of the quantity in the truth-classification analysis
contact
Forward the contact to all plots by reassigning the contact.
plot_title
cached value of the plot title
outlier_z_score
cached value of the Z-score (for outlier detection)
plots
cached value of the dictionary of plots to be created
float default_outlier_z_score
default Z-score (for outlier detection)
unit
cached measurement unit for this truth-classification analysis
def write(self, tDirectory=None)
_contact
cached value of the contact person
plot_name_postfix
cached value of the suffix appended to the plot name
def contact(self, contact)
plot_name
cached value of the base name of the plot
bin_unit
cached value of the bin measurement unit
plot_title_postfix
cached value of the suffix appended to the plot title
def analyse(self, bin_values, truths, estimates, which_plots=None, is_expert=None)
min_required_entries
cached value of the minimum number of entries
bin_spacing
cached value of the histogram bin spacing
plot_name_prefix
cached value of the prefix prepended to the plot name
string default_plot_title
default plot title
bool default_is_expert
by default, create expert plots
list default_which_plots
default list of plots to create
bin_name
cached value of the bin name
referenceFileName
cached value of the reference filename
def __init__(self, quantity_name, bin_spacing, bin_name, bin_unit=None, unit=None, outlier_z_score=None, contact='', plot_name=None, plot_title=None, min_required_entries=None, plot_name_prefix='', plot_name_postfix='', plot_title_postfix='', referenceFileName=None)
string default_plot_name
default plot name