Belle II Software light-2406-ragdoll
Correlation Class Reference
Inheritance diagram for Correlation:
Collaboration diagram for Correlation:

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

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

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

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

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

Member Data Documentation

◆ axis [1/2]

None axis = None
static

Main axis which is used to draw.

Definition at line 1071 of file plotting.py.

◆ axis [2/2]

axis

define first subplot

Definition at line 1091 of file plotting.py.

◆ axis_d1 [1/2]

None axis_d1 = None
static

Axis which shows shape of signal.

Definition at line 1073 of file plotting.py.

◆ axis_d1 [2/2]

axis_d1

define second subplot

Definition at line 1093 of file plotting.py.

◆ axis_d2 [1/2]

None axis_d2 = None
static

Axis which shows shape of background.

Definition at line 1075 of file plotting.py.

◆ axis_d2 [2/2]

axis_d2

define third subplot

Definition at line 1095 of file plotting.py.

◆ figure [1/2]

None figure = None
static

figure which is used to draw

Definition at line 1069 of file plotting.py.

◆ figure [2/2]

figure

create figure

Definition at line 1084 of file plotting.py.


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