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 1067 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 1080 of file plotting.py.

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

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

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

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

Member Data Documentation

◆ axis [1/2]

None axis = None
static

Main axis which is used to draw.

Definition at line 1074 of file plotting.py.

◆ axis [2/2]

axis

define first subplot

Definition at line 1094 of file plotting.py.

◆ axis_d1 [1/2]

None axis_d1 = None
static

Axis which shows shape of signal.

Definition at line 1076 of file plotting.py.

◆ axis_d1 [2/2]

axis_d1

define second subplot

Definition at line 1096 of file plotting.py.

◆ axis_d2 [1/2]

None axis_d2 = None
static

Axis which shows shape of background.

Definition at line 1078 of file plotting.py.

◆ axis_d2 [2/2]

axis_d2

define third subplot

Definition at line 1098 of file plotting.py.

◆ figure [1/2]

None figure = None
static

figure which is used to draw

Definition at line 1072 of file plotting.py.

◆ figure [2/2]

figure

create figure

Definition at line 1087 of file plotting.py.


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