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

Public Member Functions

def __init__ (self, figure=None)
 
def add (self, data, column, cut_column, quantiles, signal_mask=None, bckgrd_mask=None, weight_column=None)
 
def finish (self)
 

Public Attributes

 figure
 create figure
 
 axis
 define first subplot
 
 axis_d1
 define second subplot
 
 axis_d2
 define third subplot
 

Static Public Attributes

None figure = None
 figure which is used to draw
 
None axis = None
 Main axis which is used to draw.
 
None axis_d1 = None
 Axis which shows shape of signal.
 
None axis_d2 = None
 Axis which shows shape of background.
 

Detailed Description

Plots change of a distribution of a quantity depending on the cut on a classifier

Definition at line 1065 of file plotting.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  figure = None 
)
Creates a new figure if None is given, sets the default plot parameters
@param figure default draw figure which is used

Reimplemented from Plotter.

Definition at line 1078 of file plotting.py.

1078 def __init__(self, figure=None):
1079 """
1080 Creates a new figure if None is given, sets the default plot parameters
1081 @param figure default draw figure which is used
1082 """
1083 if figure is None:
1084
1085 self.figure = matplotlib.figure.Figure(figsize=(32, 18))
1086 self.figure.set_tight_layout(True)
1087 else:
1088 self.figure = figure
1089
1090 gs = matplotlib.gridspec.GridSpec(3, 2)
1091
1092 self.axis = self.figure.add_subplot(gs[0, :])
1093
1094 self.axis_d1 = self.figure.add_subplot(gs[1, :], sharex=self.axis)
1095
1096 self.axis_d2 = self.figure.add_subplot(gs[2, :], sharex=self.axis)
1097
1098 super().__init__(self.figure, self.axis)
1099

Member Function Documentation

◆ add()

def add (   self,
  data,
  column,
  cut_column,
  quantiles,
  signal_mask = None,
  bckgrd_mask = None,
  weight_column = None 
)
Add a new correlation plot.
@param data pandas.DataFrame containing all data
@param column which is used to calculate distribution histogram
@param cut_column which is used to calculate cut on the other quantity defined by column
@param quantiles list of quantiles between 0 and 100, defining the different cuts
@param weight_column column in data containing the weights for each event

Reimplemented from Plotter.

Definition at line 1100 of file plotting.py.

1100 def add(self, data, column, cut_column, quantiles, signal_mask=None, bckgrd_mask=None, weight_column=None):
1101 """
1102 Add a new correlation plot.
1103 @param data pandas.DataFrame containing all data
1104 @param column which is used to calculate distribution histogram
1105 @param cut_column which is used to calculate cut on the other quantity defined by column
1106 @param quantiles list of quantiles between 0 and 100, defining the different cuts
1107 @param weight_column column in data containing the weights for each event
1108 """
1109 if len(data[cut_column]) == 0:
1110 b2.B2WARNING("Ignore empty Correlation.")
1111 return self
1112
1113 axes = [self.axis, self.axis_d1, self.axis_d2]
1114
1115 for i, (l, m) in enumerate([('.', signal_mask | bckgrd_mask), ('S', signal_mask), ('B', bckgrd_mask)]):
1116
1117 if weight_column is not None:
1118 weights = numpy.array(data[weight_column][m])
1119 else:
1120 weights = numpy.ones(len(data[column][m]))
1121
1122 xrange = numpy.percentile(data[column][m], [5, 95])
1123
1124 colormap = plt.get_cmap('coolwarm')
1125 tmp, x = numpy.histogram(data[column][m], bins=100,
1126 range=xrange, density=True, weights=weights)
1127 bin_center = ((x + numpy.roll(x, 1)) / 2)[1:]
1128 axes[i].plot(bin_center, tmp, color='black', lw=1)
1129
1130 for quantil in numpy.arange(5, 100, 5):
1131 cut = numpy.percentile(data[cut_column][m], quantil)
1132 sel = data[cut_column][m] >= cut
1133 y, x = numpy.histogram(data[column][m][sel], bins=100,
1134 range=xrange, density=True, weights=weights[sel])
1135 bin_center = ((x + numpy.roll(x, 1)) / 2)[1:]
1136 axes[i].fill_between(bin_center, tmp, y, color=colormap(quantil / 100.0))
1137 tmp = y
1138
1139 axes[i].set_ylim(bottom=0)
1140
1141 flatness_score = basf2_mva_util.calculate_flatness(data[column][m], data[cut_column][m], weights)
1142 axes[i].set_title(r'Distribution for different quantiles: $\mathrm{{Flatness}}_{} = {:.3f}$'.format(l, flatness_score))
1143 return self
1144
def calculate_flatness(f, p, w=None)
Definition: plot.py:1

◆ finish()

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

Reimplemented from Plotter.

Definition at line 1145 of file plotting.py.

1145 def finish(self):
1146 """
1147 Sets limits, title, axis-labels and legend of the plot
1148 """
1149 return self
1150
1151

Member Data Documentation

◆ axis [1/2]

None axis = None
static

Main axis which is used to draw.

Definition at line 1072 of file plotting.py.

◆ axis [2/2]

axis

define first subplot

Definition at line 1092 of file plotting.py.

◆ axis_d1 [1/2]

None axis_d1 = None
static

Axis which shows shape of signal.

Definition at line 1074 of file plotting.py.

◆ axis_d1 [2/2]

axis_d1

define second subplot

Definition at line 1094 of file plotting.py.

◆ axis_d2 [1/2]

None axis_d2 = None
static

Axis which shows shape of background.

Definition at line 1076 of file plotting.py.

◆ axis_d2 [2/2]

axis_d2

define third subplot

Definition at line 1096 of file plotting.py.

◆ figure [1/2]

None figure = None
static

figure which is used to draw

Definition at line 1070 of file plotting.py.

◆ figure [2/2]

figure

create figure

Definition at line 1085 of file plotting.py.


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