Belle II Software development
RejectionOverEfficiency Class Reference
Inheritance diagram for RejectionOverEfficiency:
Plotter

Public Member Functions

def add (self, data, column, signal_mask, bckgrd_mask, weight_column=None, label=None)
 
def finish (self)
 

Public Attributes

 xmax
 Maximum x value.
 
 ymax
 Maximum y value.
 

Detailed Description

Plots the rejection over the efficiency also known as ROC curve

Definition at line 432 of file plotting.py.

Member Function Documentation

◆ add()

def add (   self,
  data,
  column,
  signal_mask,
  bckgrd_mask,
  weight_column = None,
  label = None 
)
Add a new curve to the ROC plot
@param data pandas.DataFrame containing all data
@param column which is used to calculate efficiency and purity for different cuts
@param signal_mask boolean numpy.array defining which events are signal events
@param bckgrd_mask boolean numpy.array defining which events are background events
@param weight_column column in data containing the weights for each event

Reimplemented from Plotter.

Definition at line 441 of file plotting.py.

441 def add(self, data, column, signal_mask, bckgrd_mask, weight_column=None, label=None):
442 """
443 Add a new curve to the ROC plot
444 @param data pandas.DataFrame containing all data
445 @param column which is used to calculate efficiency and purity for different cuts
446 @param signal_mask boolean numpy.array defining which events are signal events
447 @param bckgrd_mask boolean numpy.array defining which events are background events
448 @param weight_column column in data containing the weights for each event
449 """
450 hists = histogram.Histograms(data, column, {'Signal': signal_mask, 'Background': bckgrd_mask}, weight_column=weight_column)
451 efficiency, efficiency_error = hists.get_efficiency(['Signal'])
452 rejection, rejection_error = hists.get_efficiency(['Background'])
453 rejection = 1 - rejection
454 if isinstance(efficiency, int) and not isinstance(rejection, int):
455 efficiency = numpy.array([efficiency] * len(rejection))
456 elif isinstance(rejection, int) and not isinstance(efficiency, int):
457 rejection = numpy.array([rejection] * len(efficiency))
458 elif isinstance(rejection, int) and isinstance(efficiency, int):
459 efficiency = numpy.array([efficiency])
460 rejection = numpy.array([rejection])
461
462 self.xmin, self.xmax = numpy.nanmin([efficiency.min(), self.xmin]), numpy.nanmax([efficiency.max(), self.xmax])
463 self.ymin, self.ymax = numpy.nanmin([rejection.min(), self.ymin]), numpy.nanmax([rejection.max(), self.ymax])
464
465 auc = numpy.abs(numpy.trapz(rejection, efficiency))
466
467 p = self._plot_datapoints(self.axis, efficiency, rejection, xerr=efficiency_error, yerr=rejection_error)
468 self.plots.append(p)
469 if label is not None:
470 self.labels.append(label[:10] + f" ({auc:.2f})")
471 else:
472 self.labels.append(column[:10] + f" ({auc:.2f})")
473 return self
474

◆ finish()

def finish (   self)
Sets limits, title, axis-labels and legend of the plot

Reimplemented from Plotter.

Definition at line 475 of file plotting.py.

475 def finish(self):
476 """
477 Sets limits, title, axis-labels and legend of the plot
478 """
479 self.axis.set_xlim((self.xmin, self.xmax))
480 self.axis.set_ylim((self.ymin, self.ymax))
481 self.axis.set_title("ROC Rejection Plot")
482 self.axis.get_xaxis().set_label_text('Signal Efficiency')
483 self.axis.get_yaxis().set_label_text('Background Rejection')
484 self.axis.legend([x[0] for x in self.plots], self.labels, loc='best', fancybox=True, framealpha=0.5)
485 return self
486
487

Member Data Documentation

◆ xmax

xmax

Maximum x value.

Definition at line 462 of file plotting.py.

◆ ymax

ymax

Maximum y value.

Definition at line 463 of file plotting.py.


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