Stack

class Stack.Stack(name=None, *args, **kwargs)[source]

Bases: MethodProxy.MethodProxy, THStack

Class for a stack of 1-dimensional histograms.

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

Collect multiple 1-dimensional histograms in a Stack object. Print stacked histograms and overlay unstacked histograms, e.g. for data or signal vs. background plots. Other plots can be added to Pad s below the main one where the Stack object is drawn, see the Print() method.

The properties of the stacksum object (which is of type Histo1D), which represents the sum of all stacked histograms, can be accessed by prepending the prefix ‘stacksum’ in front of the property name.

In order to avoid memory leaks, name and histogram are inaccessible properties 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=None, *args, **kwargs)[source]

Initialize a collection of 1-dimensional histograms.

Create an instance of Stack with the specified name. Can also be used to copy another histogram (or upgrade from a ROOT.THStack).

Parameters:
  • name (str) – name of the stack (default: random 8-digits HEX hash value)
  • *args – see below
  • **kwargsStack properties
Arguments:

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

  • zero arguments: an empty stack is created

  • one argument:

    1. stack (Stack, THStack) – existing stack to be copied
Register(histo, **kwargs)[source]

Register a histogram to the stack.

If the stack keyword arguments (or the associated property of the Histo1D histo) is True the histo will be drawn in a stack. Otherwise the histogram will be displayed overlayed to the stack.

The properties of the histo registered to the stack can be changed by simply passing them as keyword arguments.

Parameters:
  • histo (Histo1D, TH1D) – histogram to be added to the Stack object
  • **kwargsHisto1D properties + additional properties (see below)
Keyword Arguments:
 
  • stack (bool) – if set to True the histogram will be displayed in the stack of all stacked histograms
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 stack, pad and canvas can be configured via their respective properties passed as keyword arguments.

Additional plots can be added to Pad s below the main one where the Stack object is drawn using the ratio, contribution and/or sensitivity flag (see below).

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

Keyword Arguments:

  • sort (bool) – define whether the stack is sorted before it is drawn (see Stack.SetStackSorting(), default: True)
  • contribution (bool) – draw the relative per-bin contribution of each stacked histogram in an additional Pad (default: False)
  • ratio (bool) – draw a RatioPlot of (assumed) data versus the (assumed) total background in an additional Pad (default: False)
  • sensitivity (bool) – draw a sensitivity scan for all (assumed) signal histograms and using the (asumed) total background as reference in an additional Pad (default: False)
  • inject<N> (list, tuple, ROOT.TObject) – inject a (list of) drawable ROOT object(s) to pad <N> (default: 0), 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)
PrintYieldTable(path=None, **kwargs)[source]

Print the yields of all registered histograms.

If the path is not None the table is saved to a CSV, TEX or PDF file as specified by the extension.

Parameters:
  • path (str) – path of the output file (must end with ‘.csv’, ‘.tex’ or ‘.pdf’, default: None)
  • **kwargs – see below
Keyword argument:
 
  • aliases (‘’dict’‘) – set new title for each histogram that will be
    shown in the table via a dictionary where the key is the histogram name and the value is the new title (default: ‘’{}’‘: use current histogram title)
  • silent (bool) – do not print the table to stdout (default: False)
  • precision (int) – amount of decimals given for the yields (default: 2)
  • crop (bool) – remove empty space from the final PDF file (default: True)
  • overwrite (bool) – overwrite an existing file located at path (default: True)
  • mkdir (bool) – create non-existing directories in path (default: False)
AddStackSortingProperty(property, reverse=False)[source]

Append a Histo1D property to the hierarchical list sorting criteria.

Parameters:
  • property (str) – Histo1D property
  • reverse (bool) – reverse sorting order (default: False)
SetStackSorting(*args)[source]

Define a hierarchical list sorting criteria (Histo1D properties).

Parameters:*args (list, tuple) – list or tuple of the format [property (str), reverse (bool)] (see Stack.AddStackSortingProperty())
GetStackSorting()[source]

Return the hierarchical list sorting criteria (Histo1D properties).

Returntype:list
SetDrawStackSum(boolean)[source]

Define whether the stacksum should be drawn.

Parameters:boolean (bool) – if set to True the stacksum will be drawn, overlaying the stack
GetDrawStackSum()[source]

Return whether the stacksum should be drawn.

Returntype:bool