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 431 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 440 of file plotting.py.

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

◆ finish()

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

Reimplemented from Plotter.

Definition at line 474 of file plotting.py.

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

Member Data Documentation

◆ xmax

xmax

Maximum x value.

Definition at line 461 of file plotting.py.

◆ ymax

ymax

Maximum y value.

Definition at line 462 of file plotting.py.


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