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 typeHisto1D
) 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 aROOT.TH1
).Parameters: - name (
str
) – name of the histogram - *args – see below
- **kwargs –
Histo1D
properties
Arguments: Depending on the number of arguments (besides name) there are three ways to initialize a
Histo1D
object:one argument:
- histo (
Histo1D
,TH1
) – histogram to be copied
- histo (
two arguments:
- title (
str
) – histogram title that will be used by theLegend
class - xlowbinedges (
list
,tuple
) – list of lower bin-edges on the x-axis (for a histogram with variable bin widths)
- title (
four arguments:
- title (
str
) – histogram title that will be used by theLegend
class - nbinsx (
int
) – number of bins on the x-axis (for a histogram with equal widths) - xmin (
float
) – minimum x-axis value (lower bin-edge of first bin) - xmax (
float
) – maximal x-axis value (upper bin-edge of last bin)
- title (
- name (
-
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 standardROOT.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
:- infile (
str
) – path to the inputROOT
file (use keyword arguments to define which events to select)
- infile (
otherwise:
see
ROOT
documentation ofTH1.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: Keyword Arguments:
- inject (
list
,tuple
,ROOT.TObject
) – inject a (list of) drawableROOT
object(s) to the main pad, 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
)
- inject (
-
SetDrawOption
(option)[source]¶ Define the draw option for the histogram.
Parameters: option ( str
) – draw option (seeROOT.THistPainter
class reference)
-
SetDrawErrorband
(boolean)[source]¶ Define whether the errorband should be drawn for the histogram.
Parameters: boolean ( bool
) – if set toTrue
the errorband will be drawn
-
GetDrawErrorband
()[source]¶ Return whether the errorband should be drawn for the histogram.
Returntype: bool
-
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)
- scale –
float
- histo (
-
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)
- scale –
float
-
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 toTrue
the histogram will be added to theLegend
-
GetAddToLegend
()[source]¶ Return whether the histogram should be added to the
Legend
.Returntype: bool
-