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 typeHisto2D
) 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 containsZ
) are tied to theHisto2D
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 aROOT.TH2
).Parameters: - name (
str
) – name of the histogram - *args – see below
- **kwargs –
Histo2D
properties
Arguments: Depending on the number of arguments (besides name) there are three ways to initialize a
Histo2D
object:one argument:
- histo (
Histo2D
,TH2
) – histogram to be copied
- histo (
three 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) - ylowbinedges (
list
,tuple
) – list of lower bin-edges on the y-axis (for a histogram with variable bin widths)
- title (
five arguments (variable x-axis binning):
- 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) - nbinsy (
int
) – number of bins on the y-axis (for a histogram with equal widths) - ymin (
float
) – minimum y-axis value (lower bin-edge of first bin) - ymax (
float
) – maximal y-axis value (upper bin-edge of last bin)
- title (
five arguments (variable y-axis binning):
- 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) - ylowbinedges (
list
,tuple
) – list of lower bin-edges on the y-axis (for a histogram with variable bin widths)
- title (
seven 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) - nbinsy (
int
) – number of bins on the y-axis (for a histogram with equal widths) - ymin (
float
) – minimum y-axis value (lower bin-edge of first bin) - ymax (
float
) – maximal y-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.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
:- 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 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 (seeROOT.THistPainter
class reference)
-
SetPalette
(num)[source]¶ Define the color palette ID for the histogram.
Parameters: num – color palette ID (see
ROOT.TColor
class reference)
-
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 (
-
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
’sinterpolate.griddata()
function is used.Parameters: - *args – See
ROOT
documentation ofROOT.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
- *args – See
-