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 toPad
s below the main one where theStack
object is drawn, see thePrint()
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 aROOT.THStack
).Parameters: - name (
str
) – name of the stack (default: random 8-digits HEX hash value) - *args – see below
- **kwargs –
Stack
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:
- stack (
Stack
,THStack
) – existing stack to be copied
- stack (
- name (
-
Register
(histo, **kwargs)[source]¶ Register a histogram to the stack.
If the stack keyword arguments (or the associated property of the
Histo1D
histo) isTrue
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: Keyword Arguments: - stack (
bool
) – if set toTrue
the histogram will be displayed in the stack of all stacked histograms
- stack (
-
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 theStack
object is drawn using the ratio, contribution and/or sensitivity flag (see below).Parameters: Keyword Arguments:
- sort (
bool
) – define whether the stack is sorted before it is drawn (seeStack.SetStackSorting()
, default:True
) - contribution (
bool
) – draw the relative per-bin contribution of each stacked histogram in an additionalPad
(default:False
) - ratio (
bool
) – draw aRatioPlot
of (assumed) data versus the (assumed) total background in an additionalPad
(default:False
) - sensitivity (
bool
) – draw a sensitivity scan for all (assumed) signal histograms and using the (asumed) total background as reference in an additionalPad
(default:False
) - inject<N> (
list
,tuple
,ROOT.TObject
) – inject a (list of) drawableROOT
object(s) to pad <N> (default: 0), object properties can be specified by passing instead atuple
of the format(obj, props)
whereprops
is adict
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
)
- sort (
-
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 tostdout
(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
)
- path (
-
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
)
- property (
-
SetStackSorting
(*args)[source]¶ Define a hierarchical list sorting criteria (
Histo1D
properties).Parameters: *args ( list
,tuple
) –list
ortuple
of the format [property (str
), reverse (bool
)] (seeStack.AddStackSortingProperty()
)
-
GetStackSorting
()[source]¶ Return the hierarchical list sorting criteria (
Histo1D
properties).Returntype: list
-