Histo2D

class Histo2D.Histo2D(name, *args, **kwargs)[source]

Bases: MethodProxy.MethodProxy, TH2D

Class for 2-dimensional histograms.

Inherits from ROOT.TH2D, see official documentation as well!

By default ROOT.TH2.SumW2() is called upon initialization. The properties of the contour (which is itself of type Histo2D) of the histogram object can be accessed by prepending the prefix ‘contour’ in front of the property name.

In order to avoid memory leaks, name is an inaccessible property despite having corresponding getter and setter methods. Furthermore the properties xtitle, ytitle are defined to be exclusive to the Pad class. However, the title and other properties of the z-axis (automatically created if the specified drawoption contains Z) are tied to the Histo2D class.

__init__(name, *args, **kwargs)[source]

Initialize a 2-dimensional histograms.

Create an instance of Histo2D with the specified name and binning (either with uniform or vairable bin widths). Can also be used to copy another histogram (or upgrade from a ROOT.TH2).

Parameters:
  • name (str) – name of the histogram
  • *args – see below
  • **kwargsHisto2D properties
Arguments:

Depending on the number of arguments (besides name) there are three ways to initialize a Histo2D object:

  • one argument:

    1. histo (Histo2D, TH2) – histogram to be copied
  • three arguments:

    1. title (str) – histogram title that will be used by the Legend class
    2. xlowbinedges (list, tuple) – list of lower bin-edges on the x-axis (for a histogram with variable bin widths)
    3. ylowbinedges (list, tuple) – list of lower bin-edges on the y-axis (for a histogram with variable bin widths)
  • five arguments (variable x-axis binning):

    1. title (str) – histogram title that will be used by the Legend class
    2. xlowbinedges (list, tuple) – list of lower bin-edges on the x-axis (for a histogram with variable bin widths)
    3. nbinsy (int) – number of bins on the y-axis (for a histogram with equal widths)
    4. ymin (float) – minimum y-axis value (lower bin-edge of first bin)
    5. ymax (float) – maximal y-axis value (upper bin-edge of last bin)
  • five arguments (variable y-axis binning):

    1. title (str) – histogram title that will be used by the Legend class
    2. nbinsx (int) – number of bins on the x-axis (for a histogram with equal widths)
    3. xmin (float) – minimum x-axis value (lower bin-edge of first bin)
    4. xmax (float) – maximal x-axis value (upper bin-edge of last bin)
    5. ylowbinedges (list, tuple) – list of lower bin-edges on the y-axis (for a histogram with variable bin widths)
  • seven arguments:

    1. title (str) – histogram title that will be used by the Legend class
    2. nbinsx (int) – number of bins on the x-axis (for a histogram with equal widths)
    3. xmin (float) – minimum x-axis value (lower bin-edge of first bin)
    4. xmax (float) – maximal x-axis value (upper bin-edge of last bin)
    5. nbinsy (int) – number of bins on the y-axis (for a histogram with equal widths)
    6. ymin (float) – minimum y-axis value (lower bin-edge of first bin)
    7. ymax (float) – maximal y-axis value (upper bin-edge of last bin)
Fill(*args, **kwargs)[source]

Fill the histogram with entries.

If a path (str) to an infile is given as the only argument the histogram if filled using the events in there as specified by the keyword arguments. Otherwise the standard ROOT.TH2.Fill() functionality is used.

Parameters:
  • *args – see below
  • **kwargs – see below
Arguments:

Depending on the number of arguments (besides name) there are three ways to initialize a Histo2D object:

  • one argument of type str:

    1. infile (str) – path to the input ROOT file (use keyword arguments to define which events to select)
  • otherwise:

    see ROOT documentation of TH1.Fill() (keyword arguments will be ignored)

Keyword Arguments:
 
  • tree (str) – name of the input tree
  • varexp (str) – name of the branch to be plotted on the x-axis and y-axis (format ‘y:x’)
  • cuts (str, list, tuple) – string or list of strings of boolean expressions, the latter will default to a logical AND of all items (default: ‘1’)
  • weight (str) – number or branch name to be applied as a weight (default: ‘1’)
  • append (bool) – append entries to the histogram instead of overwriting it (default: False)
SetDrawOption(option)[source]

Define the draw option for the histogram.

Parameters:option (str) – draw option (see ROOT.THistPainter class reference)
GetDrawOption()[source]

Return the draw option defined for the histogram.

Returntype:str
SetPalette(num)[source]

Define the color palette ID for the histogram.

Parameters:num

color palette ID (see ROOT.TColor class reference)

GetPalette()[source]

Return the color palette ID defined for the histogram.

Returntype:int
SetZMin(value)[source]
GetZMin()[source]
SetZMax(value)[source]
GetZMax()[source]
Print(path, **kwargs)[source]

Print the histogram to a file.

Creates a PDF/PNG/… file with the absolute path defined by path. If a file with the same name already exists it will be overwritten (can be changed with the overwrite keyword argument). If mkdir is set to True (default: False) directories in path with do not yet exist will be created automatically. The styling of the histogram, pad and canvas can be configured via their respective properties passed as keyword arguments.

Parameters:
  • path (str) – path of the output file (must end with ‘.pdf’, ‘.png’, …)
  • **kwargsHisto2D, Plot, Canvas and Pad properties + additional properties (see below)

Keyword Arguments:

  • inject (list, tuple, ROOT.TObject) – inject a (list of) drawable ROOT object(s) to the main pad, object properties can be specified by passing instead a tuple of the format (obj, props) where props is a dict holding the object properties (default: [])
  • overwrite (bool) – overwrite an existing file located at path (default: True)
  • mkdir (bool) – create non-existing directories in path (default: False)
Interpolate(*args, **kwargs)[source]

Replace zero valued data points by interpolating between all non-zero data point of the grid if no arguments are given. Otherwise the standard ROOT.TH2.Interpolate() functionality is used.

In the former case the scipy’s interpolate.griddata() function is used.

Parameters:
  • *args – See ROOT documentation of ROOT.TH2.Interpolate()
  • **kwargs – see below
Keyword Arguments:
 
  • method (str) – method of interpolation (default: ‘cubic’)

    • nearest: return the value at the data point closest to the point of interpolation
    • linear: tessellate the input point set to n-dimensional simplices, and interpolate linearly on each simplex
    • cubic: return the value determined from a piecewise cubic, continuously differentiable and approximately curvature-minimizing polynomial surface
SetContour(*args)[source]

Define the contour levels.

A contour line will be drawn at values of the histogram equal to the specified levels.

Parameters:*args (float) – contour levels
GetContour()[source]

Return a list of all contour levels.

Returntype:list
RetrieveContourGraphDict()[source]

Return a dictionary with a list of graphs representing the contour lines for any given contour level.

Returntype:dict