Belle II Software development
ResolutionAnalysis Class Reference

Public Member Functions

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)
 
def analyse (self, bin_values, truths, estimates, which_plots=None, is_expert=None)
 
def contact (self)
 
def contact (self, contact)
 
def write (self, tDirectory=None)
 

Public Attributes

 quantity_name
 cached name of the quantity in the truth-classification analysis
 
 unit
 cached measurement unit for this truth-classification analysis
 
 bin_spacing
 cached value of the histogram bin spacing
 
 bin_name
 cached value of the bin name
 
 bin_unit
 cached value of the bin measurement unit
 
 outlier_z_score
 cached value of the Z-score (for outlier detection)
 
 min_required_entries
 cached value of the minimum number of entries
 
 plot_name
 cached value of the base name of the plot
 
 plot_title
 cached value of the plot title
 
 plot_name_prefix
 cached value of the prefix prepended to the plot name
 
 plot_name_postfix
 cached value of the suffix appended to the plot name
 
 plot_title_postfix
 cached value of the suffix appended to the plot title
 
 plots
 cached value of the dictionary of plots to be created
 
 referenceFileName
 cached value of the reference filename
 
 contact
 Forward the contact to all plots by reassigning the contact.
 

Static Public Attributes

float default_outlier_z_score = 5.0
 default Z-score (for outlier detection)
 
int default_min_required_entries = 50
 default minimum number of entries
 
str default_plot_name = "{plot_name_prefix}_{subplot_name}{plot_name_postfix}"
 default plot name
 
str default_plot_title = "{subplot_title} of {quantity_name}{plot_title_postfix}"
 default plot title
 
list default_which_plots
 default list of plots to create
 
bool default_is_expert = True
 by default, create expert plots
 

Protected Attributes

 _contact
 cached value of the contact person
 

Detailed Description

Perform resolution analysis

Definition at line 25 of file resolution.py.

Constructor & Destructor Documentation

◆ __init__()

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 
)
Performs a comparison of an estimated quantity to their truths by generating standardized validation plots.

Definition at line 44 of file resolution.py.

60 ):
61 """Performs a comparison of an estimated quantity to their truths by generating standardized validation plots."""
62
63
64 self.quantity_name = quantity_name
65
66 self.unit = unit or get_unit(quantity_name)
67
68 self.bin_spacing = bin_spacing
69
70 self.bin_name = bin_name
71
72 self.bin_unit = bin_unit
73
74 if outlier_z_score is None:
75
76 self.outlier_z_score = self.default_outlier_z_score
77 else:
78 self.outlier_z_score = outlier_z_score
79
80
81 self.min_required_entries = min_required_entries
82 if self.min_required_entries is None:
83 self.min_required_entries = self.default_min_required_entries
84
85
86 self.plot_name = plot_name
87
88 self.plot_title = plot_title
89
90
91 self.plot_name_prefix = plot_name_prefix or root_save_name(quantity_name)
92
93 self.plot_name_postfix = plot_name_postfix
94
95 self.plot_title_postfix = plot_title_postfix
96
97
98 self._contact = contact
99
100 self.plots = collections.OrderedDict()
101
102
103 self.referenceFileName = referenceFileName
104

Member Function Documentation

◆ analyse()

def analyse (   self,
  bin_values,
  truths,
  estimates,
  which_plots = None,
  is_expert = None 
)
Compares the concrete estimate to the truth and generates plots of the resolution

Parameters
----------
bin_values : array_like(float
    The parameter used for binning
truths : array_like(float)
    Sample of the true values
estimates : array_like(float)
    Corresponding estimations

Definition at line 105 of file resolution.py.

112 ):
113 """Compares the concrete estimate to the truth and generates plots of the resolution
114
115 Parameters
116 ----------
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
123 """
124
125 if is_expert is None:
126 is_expert = self.default_is_expert
127
128 if which_plots is None:
129 which_plots = self.default_which_plots
130
131 quantity_name = self.quantity_name
132
133 # axis_label = compose_axis_label(quantity_name, self.unit)
134
135 plot_name_prefix = self.plot_name_prefix
136 outlier_z_score = self.outlier_z_score
137
138 plot_name = self.plot_name
139 if plot_name is None:
140 plot_name = self.default_plot_name
141
142 plot_name = formatter.format(plot_name,
143 quantity_name=quantity_name,
144 plot_name_prefix=plot_name_prefix,
145 plot_name_postfix=self.plot_name_postfix)
146
147 plot_title = self.plot_title
148 if plot_title is None:
149 plot_title = self.default_plot_title
150
151 plot_title = formatter.format(plot_title,
152 quantity_name=quantity_name,
153 plot_title_postfix=self.plot_title_postfix)
154
155 # compute residuals
156 residuals = estimates - truths
157
158 # Resolution #
159
160 if "resolution" in which_plots:
161
162 # creating plots for all configured bins
163 res_histogram = []
164 resolution_values = []
165
166 for i in range(len(self.bin_spacing) - 1):
167 lower_bin = self.bin_spacing[i]
168 upper_bin = self.bin_spacing[i + 1]
169 assert (lower_bin < upper_bin)
170 bin_center = lower_bin + (upper_bin - lower_bin) / 2.0
171 assert (len(bin_values) == len(residuals))
172
173 # compile a list of values which are in this bin
174 sel_residuals = collections.deque()
175
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])
179
180 residuals_hist_name = formatter.format(plot_name, subplot_name="residuals") + \
181 f"{lower_bin}_to_{upper_bin}"
182 vplot = ValidationPlot(residuals_hist_name, self.referenceFileName)
183 vplot.hist(sel_residuals,
184 outlier_z_score=outlier_z_score,
185 is_expert=is_expert)
186 vplot.xlabel = compose_axis_label("#Delta " + quantity_name + " (estimate - truth)", self.unit)
187 vplot.title = formatter.format(plot_title, subplot_title='Residual distribution')
188
189 # this values will stay None if no fit could be performed
190 gaus_sigma = None
191 gaus_sigma_err = None
192
193 # check if the minimum number of entries are in the histogram
194 if vplot.histograms[0].GetEntries() >= self.min_required_entries:
195 fit_res = vplot.fit_gaus(z_score=1)
196
197 # extract fit result from ROOT's TFitResut
198 params = fit_res.GetParams()
199 errs = fit_res.Errors()
200
201 # gaus_mean = params[1]
202 gaus_sigma = params[2]
203 gaus_sigma_err = errs[2]
204
205 res_histogram += [(lower_bin, upper_bin, bin_center, vplot)]
206 self.plots['residuals' + residuals_hist_name] = vplot
207
208 # store the fit results
209 resolution_values += [(lower_bin, upper_bin, bin_center, gaus_sigma, gaus_sigma_err)]
210
211 resolution_graph_name = formatter.format(plot_name, subplot_name="resolution")
212 resolution_graph = ValidationPlot(resolution_graph_name, self.referenceFileName)
213
214 # compile all required data going into the final TGraphErrors
215 xs = []
216 xs_err = []
217 ys = []
218 ys_err = []
219
220 for v in resolution_values:
221 # could be None if no fit was possible for this bin
222 if v[3]:
223 xs += [v[2]]
224 xs_err = [0.0]
225 ys += [v[3]]
226 ys_err = [v[4]]
227
228 # convert to numpy array before giving to the plotting code
229 resolution_graph.grapherrors((np.array(xs), np.array(xs_err)), (np.array(ys), np.array(ys_err)),
230 is_expert=is_expert)
231 resolution_graph.xlabel = compose_axis_label(self.bin_name, self.bin_unit)
232 resolution_graph.ylabel = compose_axis_label(self.quantity_name, self.unit)
233 resolution_graph.title = formatter.format(plot_title, subplot_title='Resolution')
234
235 self.plots[resolution_graph_name] = resolution_graph
236
237
238 self.contact = self.contact
239

◆ contact() [1/2]

def contact (   self)
Get the contact person's name

Definition at line 241 of file resolution.py.

241 def contact(self):
242 """Get the contact person's name"""
243 return self._contact
244

◆ contact() [2/2]

def contact (   self,
  contact 
)
Set the contact person's name

Definition at line 246 of file resolution.py.

246 def contact(self, contact):
247 """Set the contact person's name"""
248 self._contact = contact
249 for validation_plot in list(self.plots.values()):
250 validation_plot.contact = contact
251

◆ write()

def write (   self,
  tDirectory = None 
)
Write all validation plot to the given Root directory

Definition at line 252 of file resolution.py.

252 def write(self, tDirectory=None):
253 """Write all validation plot to the given Root directory"""
254 for validation_plot in list(self.plots.values()):
255 validation_plot.write(tDirectory)

Member Data Documentation

◆ _contact

_contact
protected

cached value of the contact person

Definition at line 98 of file resolution.py.

◆ bin_name

bin_name

cached value of the bin name

Definition at line 70 of file resolution.py.

◆ bin_spacing

bin_spacing

cached value of the histogram bin spacing

Definition at line 68 of file resolution.py.

◆ bin_unit

bin_unit

cached value of the bin measurement unit

Definition at line 72 of file resolution.py.

◆ contact

contact

Forward the contact to all plots by reassigning the contact.

Definition at line 238 of file resolution.py.

◆ default_is_expert

bool default_is_expert = True
static

by default, create expert plots

Definition at line 42 of file resolution.py.

◆ default_min_required_entries

int default_min_required_entries = 50
static

default minimum number of entries

Definition at line 31 of file resolution.py.

◆ default_outlier_z_score

float default_outlier_z_score = 5.0
static

default Z-score (for outlier detection)

Definition at line 29 of file resolution.py.

◆ default_plot_name

str default_plot_name = "{plot_name_prefix}_{subplot_name}{plot_name_postfix}"
static

default plot name

Definition at line 33 of file resolution.py.

◆ default_plot_title

str default_plot_title = "{subplot_title} of {quantity_name}{plot_title_postfix}"
static

default plot title

Definition at line 35 of file resolution.py.

◆ default_which_plots

list default_which_plots
static
Initial value:
= [
"resolution",
]

default list of plots to create

Definition at line 37 of file resolution.py.

◆ min_required_entries

min_required_entries

cached value of the minimum number of entries

Definition at line 81 of file resolution.py.

◆ outlier_z_score

outlier_z_score

cached value of the Z-score (for outlier detection)

Definition at line 76 of file resolution.py.

◆ plot_name

plot_name

cached value of the base name of the plot

Definition at line 86 of file resolution.py.

◆ plot_name_postfix

plot_name_postfix

cached value of the suffix appended to the plot name

Definition at line 93 of file resolution.py.

◆ plot_name_prefix

plot_name_prefix

cached value of the prefix prepended to the plot name

Definition at line 91 of file resolution.py.

◆ plot_title

plot_title

cached value of the plot title

Definition at line 88 of file resolution.py.

◆ plot_title_postfix

plot_title_postfix

cached value of the suffix appended to the plot title

Definition at line 95 of file resolution.py.

◆ plots

plots

cached value of the dictionary of plots to be created

Definition at line 100 of file resolution.py.

◆ quantity_name

quantity_name

cached name of the quantity in the truth-classification analysis

Definition at line 64 of file resolution.py.

◆ referenceFileName

referenceFileName

cached value of the reference filename

Definition at line 103 of file resolution.py.

◆ unit

unit

cached measurement unit for this truth-classification analysis

Definition at line 66 of file resolution.py.


The documentation for this class was generated from the following file: