22formatter = TolerateMissingKeyFormatter()
26 """Perform resolution analysis"""
29 default_outlier_z_score = 5.0
31 default_min_required_entries = 50
33 default_plot_name =
"{plot_name_prefix}_{subplot_name}{plot_name_postfix}"
35 default_plot_title =
"{subplot_title} of {quantity_name}{plot_title_postfix}"
37 default_which_plots = [
42 default_is_expert =
True
55 min_required_entries=None,
58 plot_title_postfix='',
59 referenceFileName=None,
61 """Performs a comparison of an estimated quantity to their truths by generating standardized validation plots."""
66 self.
unit = unit
or get_unit(quantity_name)
74 if outlier_z_score
is None:
100 self.
plots = collections.OrderedDict()
113 """Compares the concrete estimate to the truth and generates plots of the resolution
117 bin_values : array_like(float
118 The parameter used for binning
119 truths : array_like(float)
120 Sample of the true values
121 estimates : array_like(float)
122 Corresponding estimations
125 if is_expert
is None:
128 if which_plots
is None:
139 if plot_name
is None:
142 plot_name = formatter.format(plot_name,
143 quantity_name=quantity_name,
144 plot_name_prefix=plot_name_prefix,
148 if plot_title
is None:
151 plot_title = formatter.format(plot_title,
152 quantity_name=quantity_name,
156 residuals = estimates - truths
160 if "resolution" in which_plots:
164 resolution_values = []
169 assert (lower_bin < upper_bin)
170 bin_center = lower_bin + (upper_bin - lower_bin) / 2.0
171 assert (len(bin_values) == len(residuals))
174 sel_residuals = collections.deque()
176 for i
in range(len(bin_values)):
177 if bin_values[i] >= lower_bin
and bin_values[i] < upper_bin:
178 sel_residuals.append(residuals[i])
180 residuals_hist_name = formatter.format(plot_name, subplot_name=
"residuals") + \
181 f
"{lower_bin}_to_{upper_bin}"
183 vplot.hist(sel_residuals,
184 outlier_z_score=outlier_z_score,
186 vplot.xlabel = compose_axis_label(
"#Delta " + quantity_name +
" (estimate - truth)", self.
unit)
187 vplot.title = formatter.format(plot_title, subplot_title=
'Residual distribution')
191 gaus_sigma_err =
None
195 fit_res = vplot.fit_gaus(z_score=1)
198 params = fit_res.GetParams()
199 errs = fit_res.Errors()
202 gaus_sigma = params[2]
203 gaus_sigma_err = errs[2]
205 res_histogram += [(lower_bin, upper_bin, bin_center, vplot)]
206 self.
plots[
'residuals' + residuals_hist_name] = vplot
209 resolution_values += [(lower_bin, upper_bin, bin_center, gaus_sigma, gaus_sigma_err)]
211 resolution_graph_name = formatter.format(plot_name, subplot_name=
"resolution")
220 for v
in resolution_values:
229 resolution_graph.grapherrors((np.array(xs), np.array(xs_err)), (np.array(ys), np.array(ys_err)),
233 resolution_graph.title = formatter.format(plot_title, subplot_title=
'Resolution')
235 self.
plots[resolution_graph_name] = resolution_graph
242 """Get the contact person's name"""
247 """Set the contact person's name"""
249 for validation_plot
in list(self.
plots.values()):
250 validation_plot.contact = contact
253 """Write all validation plot to the given Root directory"""
254 for validation_plot
in list(self.
plots.values()):
255 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
str default_plot_title
default plot title
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
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
bool default_is_expert
by default, create expert plots
list default_which_plots
default list of plots to create
str default_plot_name
default plot name
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)