Histo1D

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

Bases: MethodProxy.MethodProxy, TH1D

Class for 1-dimensional histograms.

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

By default ROOT.TH1.SumW2() is called upon initialization. The properties of the errorband (which is itself of type Histo1D) of the histogram object can be accessed by prepending the prefix ‘errorband’ in front of the property name. By default the errorband’s fillcolor and markercolor matches the histogram’s linecolor.

In order to avoid memory leaks, name is an inaccessible property despite having corresponding getter and setter methods. Furthermore the properties xtitle, ytitle and ztitle are defined to be exclusive to the Pad class.

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

Initialize a 1-dimensional histograms.

Create an instance of Histo1D 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.TH1).

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

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

  • one argument:

    1. histo (Histo1D, TH1) – histogram to be copied
  • two 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)
  • four 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)
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.TH1.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 Histo1D 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
  • 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)
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’, …)
  • **kwargsHisto1D, 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)
IncludeOverflow()[source]
IncludeUnderflow()[source]
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
SetDrawErrorband(boolean)[source]

Define whether the errorband should be drawn for the histogram.

Parameters:boolean (bool) – if set to True the errorband will be drawn
GetDrawErrorband()[source]

Return whether the errorband should be drawn for the histogram.

Returntype:bool
GetXTitle()[source]

Return the histogram’s x-axis title.

Returntype:str
GetYTitle()[source]

Return the histogram’s y-axis title.

Returntype:str
GetBinWidths()[source]

Return a list of all bin widths.

Returntype:list
Add(histo, scale=1)[source]

Add another histo to the current histogram.

A global weight can be set for the histo via the scale. The raw (unweighted) entries of the histograms will be added.

Parameters:
  • histo (Histo1D, TH1D) – histogram to be added to the current object
  • scale – global weight multiplied to histo (default: 1)
  • scalefloat
ApplyScaleFactor(scalefactor, uncertainty=0)[source]

Apply a scale factor to the histogram.

An uncertainty associated to the scale factor is included into the final per-bin uncertainty.

Parameters:
  • scale – scale factor multiplied to current object
  • scale``float`
  • scale – absoulte uncertainty on the scale factor (default: 0)
  • scalefloat
SetLegendDrawOption(option)[source]

Define the draw option for the histogram’s legend.

Parameters:option (str) –

draw option (see ROOT.TLegend class reference)

GetLegendDrawOption()[source]

Return the draw option defined for the histogram’s legend.

Returntype:str
SetLineAlpha(alpha)[source]

Define the transparency of the histogram’s line attribute.

Parameters:option (float) – transparency of the histogram’s line attribute (\(\alpha \in [0,1]\) )
GetLineAlpha()[source]

Return tthe transparency of the histogram’s line attribute.

Returntype:float
SetFillAlpha(alpha)[source]

Define the transparency of the histogram’s fill attribute.

Parameters:option (float) – transparency of the histogram’s fill attribute (\(\alpha \in [0,1]\) )
GetFillAlpha()[source]

Return tthe transparency of the histogram’s fill attribute.

Returntype:float
SetMarkerAlpha(alpha)[source]

Define the transparency of the histogram’s marker attribute.

Parameters:option (float) – transparency of the histogram’s marker attribute (\(\alpha \in [0,1]\) )
GetMarkerAlpha()[source]

Return tthe transparency of the histogram’s marker attribute.

Returntype:float
SetAddToLegend(boolean)[source]

Define whether the histogram should be added to the Legend.

Parameters:boolean (bool) – if set to True the histogram will be added to the Legend
GetAddToLegend()[source]

Return whether the histogram should be added to the Legend.

Returntype:bool
SetStack(boolean)[source]

Set how the object is displayed if added to a Stack.

If set to True and the histogram is registered to a Stack, it will be displayed in the stack of histograms.

Parameters:boolean (bool) – if set to True the histogram will be displayed in the stack of histograms
GetStack()[source]

Return how the object is displayed if added to a Stack.

Returntype:bool