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

Public Member Functions

def __init__ (self, figure=None, axis=None, normed=False, shift_to_zero=False)
 
def add (self, data, column, minuend_mask, subtrahend_mask, weight_column=None, label=None)
 
def finish (self, line_color='black')
 

Public Attributes

 normed
 Minuend and subtrahend are normed before comparing them if this is true.
 
 shift_to_zero
 Mean difference is shifted to zero (removes constant offset) if this is true.
 
 ymin
 min y value
 
 ymax
 Maximum y value.
 
 xmax
 Maximum x value.
 
 x_axis_label
 Label on x axis.
 

Detailed Description

Plots the difference between two histograms

Definition at line 770 of file plotting.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  figure = None,
  axis = None,
  normed = False,
  shift_to_zero = False 
)
Creates a new figure and axis if None is given, sets the default plot parameters
@param figure default draw figure which is used
@param axis default draw axis which is used
@param normed normalize minuend and subtrahend before comparing them
@param shift_to_zero mean difference is shifted to zero, to remove constant offset due to e.g. different sample sizes

Reimplemented from Plotter.

Definition at line 787 of file plotting.py.

787 def __init__(self, figure=None, axis=None, normed=False, shift_to_zero=False):
788 """
789 Creates a new figure and axis if None is given, sets the default plot parameters
790 @param figure default draw figure which is used
791 @param axis default draw axis which is used
792 @param normed normalize minuend and subtrahend before comparing them
793 @param shift_to_zero mean difference is shifted to zero, to remove constant offset due to e.g. different sample sizes
794 """
795 super().__init__(figure, axis)
796 self.normed = normed
797 self.shift_to_zero = shift_to_zero
798 if self.normed:
799 self.ymin = -0.01
800 self.ymax = 0.01
801 else:
802 self.ymin = -1
803 self.ymax = 1
804

Member Function Documentation

◆ add()

def add (   self,
  data,
  column,
  minuend_mask,
  subtrahend_mask,
  weight_column = None,
  label = None 
)
Add a new difference plot
@param data pandas.DataFrame containing all data
@param column which is used to calculate distribution histogram
@param minuend_mask boolean numpy.array defining which events are for the minuend histogram
@param subtrahend_mask boolean numpy.array defining which events are for the subtrahend histogram
@param weight_column column in data containing the weights for each event
@param label label for the legend if None, the column name is used

Reimplemented from Plotter.

Definition at line 805 of file plotting.py.

805 def add(self, data, column, minuend_mask, subtrahend_mask, weight_column=None, label=None):
806 """
807 Add a new difference plot
808 @param data pandas.DataFrame containing all data
809 @param column which is used to calculate distribution histogram
810 @param minuend_mask boolean numpy.array defining which events are for the minuend histogram
811 @param subtrahend_mask boolean numpy.array defining which events are for the subtrahend histogram
812 @param weight_column column in data containing the weights for each event
813 @param label label for the legend if None, the column name is used
814 """
815 hists = histogram.Histograms(data, column, {'Minuend': minuend_mask, 'Subtrahend': subtrahend_mask},
816 weight_column=weight_column, equal_frequency=False)
817 minuend, minuend_error = hists.get_hist('Minuend')
818 subtrahend, subtrahend_error = hists.get_hist('Subtrahend')
819
820 difference_error = histogram.poisson_error(minuend + subtrahend)
821 if self.normed:
822 difference_error = difference_error / (numpy.sum(minuend) + numpy.sum(subtrahend))
823 minuend = minuend / numpy.sum(minuend)
824 subtrahend = subtrahend / numpy.sum(subtrahend)
825 difference = minuend - subtrahend
826
827 if self.shift_to_zero:
828 difference = difference - numpy.mean(difference)
829
830 self.xmin, self.xmax = min(hists.bin_centers.min(), self.xmin), max(hists.bin_centers.max(), self.xmax)
831 self.ymin = min((difference - difference_error).min(), self.ymin)
832 self.ymax = max((difference + difference_error).max(), self.ymax)
833
834 p = self._plot_datapoints(self.axis, hists.bin_centers, difference, xerr=hists.bin_widths / 2, yerr=difference_error)
835 self.plots.append(p)
836 if label is None:
837 self.labels.append(label)
838 else:
839 self.labels.append(column)
840 self.x_axis_label = column
841 return self
842
def poisson_error(n_tot)
Definition: histogram.py:24

◆ finish()

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

Reimplemented from Plotter.

Definition at line 843 of file plotting.py.

843 def finish(self, line_color='black'):
844 """
845 Sets limits, title, axis-labels and legend of the plot
846 """
847 self.axis.plot((self.xmin, self.xmax), (0, 0), color=line_color, linewidth=4, rasterized=True)
848 self.scale_limits()
849 self.axis.set_xlim((self.xmin, self.xmax))
850 self.axis.set_ylim((self.ymin, self.ymax))
851 self.axis.set_title("Difference Plot")
852 self.axis.get_yaxis().set_major_locator(matplotlib.ticker.MaxNLocator(5))
853 self.axis.get_xaxis().set_label_text(self.x_axis_label)
854 self.axis.get_yaxis().set_label_text('Diff.')
855 self.axis.legend([x[0] for x in self.plots], self.labels, loc='best', fancybox=True, framealpha=0.5)
856 return self
857
858
Definition: plot.py:1

Member Data Documentation

◆ normed

normed

Minuend and subtrahend are normed before comparing them if this is true.

Definition at line 796 of file plotting.py.

◆ shift_to_zero

shift_to_zero

Mean difference is shifted to zero (removes constant offset) if this is true.

Definition at line 797 of file plotting.py.

◆ x_axis_label

x_axis_label

Label on x axis.

Definition at line 840 of file plotting.py.

◆ xmax

xmax

Maximum x value.

Definition at line 830 of file plotting.py.

◆ ymax

ymax

Maximum y value.

Definition at line 800 of file plotting.py.

◆ ymin

ymin

min y value

Definition at line 799 of file plotting.py.


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