CombineHarvester
python.plotting Namespace Reference

Functions

def getOverlayMarkerAndLegend (legend, entries, options, borderSize=2.0/3, markerStyle="P")
 
Global Style

Set the properties of the global gStyle object and create colours and colour palettes

def SetTDRStyle ()
 Sets the PubComm recommended style. More...
 
def ModTDRStyle (width=600, height=600, t=0.06, b=0.12, l=0.16, r=0.04)
 Modified version of the tdrStyle. More...
 
def SetBirdPalette ()
 
def SetDeepSeaPalette ()
 
def SetCorrMatrixPalette ()
 
def CreateTransparentColor (color, alpha)
 
def Set (obj, **kwargs)
 
TPad Layout

Create TPads for pre-defined layouts, for example adding a smaller lower TPad to contain ratios of objects in the main pad.

def OnePad ()
 
def TwoPadSplit (split_point, gap_low, gap_high)
 
def ThreePadSplit (upper_split_point, split_point, gap_low, gap_high)
 
def MultiRatioSplit (split_points, gaps_low, gaps_high)
 Create a set of TPads split vertically on the TCanvas. More...
 
def TwoPadSplitColumns (split_point, gap_left, gap_right)
 
def MultiRatioSplitColumns (split_points, gaps_left, gaps_right)
 
def SetupTwoPadSplitAsRatio (pads, upper, lower, y_title, y_centered, y_min, y_max)
 
def StandardAxes (xaxis, yaxis, var, units, fmt='.1f')
 
Axis histograms

By default the first TH1 or TGraph drawn on a pad takes control of the x- and y-axis settings. A better way is to create dedicated "axis" TH1s that can be drawn first, one per pad, which will then control all the axis properties.

def CreateAxisHist (src, at_limits=True)
 
def CreateAxisHists (n, src, at_limits)
 
def GetAxisHist (pad)
 
TFile functions

A collection of functions for working with TFiles.

def TFileIsGood (filename)
 Performs a series of tests on a TFile to ensure that it can be opened without errors. More...
 
def MakeTChain (files, tree)
 
def Get (file, obj)
 
def ParamFromFilename (filename, param)
 
Object creation

These functions take existing objects (TH1s, TGraphs, TTrees, etc) and build new objects

def TGraphFromTree (tree, xvar, yvar, selection)
 
def TGraph2DFromTree (tree, xvar, yvar, zvar, selection)
 
def RocCurveFrom1DHists (h_x, h_y, cut_is_greater_than)
 
def TH2FromTGraph2D (graph, method='BinEdgeAligned', force_x_width=None, force_y_width=None)
 Build an empty TH2 from the set of points in a TGraph2D. More...
 
def MakeErrorBand (LowerGraph, UpperGraph)
 
def LimitTGraphFromJSON (js, label)
 
def LimitTGraphFromJSONFile (jsfile, label)
 
def ToyTGraphFromJSON (js, label)
 
def ToyTGraphFromJSONFile (jsfile, label)
 
def LimitBandTGraphFromJSON (js, central, lo, hi)
 
def StandardLimitsFromJSONFile (json_file, draw=['obs', 'exp0', 'exp1', 'exp2'])
 
def bestFit (tree, x, y, cut)
 
def treeToHist2D (t, x, y, name, cut, xmin, xmax, ymin, ymax, xbins, ybins)
 
def makeHist1D (name, xbins, graph, scaleXrange=1.0, absoluteXrange=None)
 
def makeHist2D (name, xbins, ybins, graph2d)
 
def makeVarBinHist2D (name, xbins, ybins)
 
def GraphDifference (graph1, graph2, relative)
 
def GraphDivide (num, den)
 
def MakeRatioHist (num, den, num_err, den_err)
 Make a new ratio TH1 from numerator and denominator TH1s with optional error propagation. More...
 
Graph manipulation

These functions are mostly used to modify TGraphs corresponding to likelihood scans.

def RemoveGraphXDuplicates (graph)
 
def ApplyGraphYOffset (graph, y_off)
 
def RemoveGraphYAll (graph, val)
 
def RemoveSmallDelta (graph, val)
 
def RemoveGraphYAbove (graph, val)
 
def SetMinToZero (graph)
 
def ImproveMinimum (graph, func, doIt=False)
 
def FindCrossingsWithSpline (graph, func, yval)
 
def ReZeroTGraph (gr, doIt=False)
 
def FilterGraph (gr, n=3)
 
def RemoveInXRange (gr, xmin=0, xmax=1)
 
def RemoveNearMin (graph, val, spacing=None)
 
def SortGraph (Graph)
 
TPad adjustments

These functions are mostly concerned with adjusting the axis ranges to make sure objects are not being drawn outside the range of the pad or underneath other objects, e.g. the legend.

def FixTopRange (pad, fix_y, fraction)
 
def FixBothRanges (pad, fix_y_lo, frac_lo, fix_y_hi, frac_hi)
 Adjusts y-axis range such that a lower and a higher value are located a fixed fraction of the frame height away from a new minimum and maximum respectively. More...
 
def GetPadYMaxInRange (pad, x_min, x_max, do_min=False)
 
def GetPadYMax (pad, do_min=False)
 
def GetPadYMin (pad)
 
def FixOverlay ()
 
def FixBoxPadding (pad, box, frac)
 
Decoration

Functions for drawing legends, logos, title, lines and boxes

def StandardAxes (xaxis, yaxis, var, units)
 
def DrawCMSLogo (pad, cmsText, extraText, iPosX, relPosX, relPosY, relExtraDY, extraText2='', cmsTextSize=0.8)
 Blah. More...
 
def PositionedLegend (width, height, pos, offset, horizontaloffset=None)
 
def DrawHorizontalLine (pad, line, yval)
 
def DrawVerticalLine (pad, line, xval)
 
def DrawVerticalBand (pad, box, x1, x2)
 
def DrawTitle (pad, text, align, textOffset=0.2, textSize=0.6)
 
Limit plotting

Common limit-plotting tasks, for example setting the Brazilian colour scheme for expected limit bands and drawing the associated TGraphs in the correct order

def isclose (a, b, rel_tol=1e-9, abs_tol=0.0)
 
def StyleLimitBand (graph_dict, overwrite_style_dict=None)
 
def DrawLimitBand (pad, graph_dict, draw=['exp2', 'exp1', 'exp0', 'obs'], draw_legend=None, legend=None, legend_overwrite=None)
 
Contour plotting

Creating contour TGraphs using TH2s and TGraph2Ds

def contourFromTH2 (h2in, threshold, minPoints=10, frameValue=1000.)
 
def frameTH2D (hist, threshold, frameValue=1000)
 
def fastFillTH2 (hist2d, graph, initalValue=99999, interpolateMissing=False)
 
def fillTH2 (hist2d, graph)
 
def fillInvertedTH2 (hist2d, graph)
 
def NewInterpolate (hist)
 
def rebin (hist)
 
def higgsConstraint (model, higgstype)
 

Variables

list COL_STORE = []
 

Function Documentation

◆ SetTDRStyle()

def python.plotting.SetTDRStyle ( )

Sets the PubComm recommended style.

Just a copy of http://ghm.web.cern.ch/ghm/plots/MacroExample/tdrstyle.C

See also
ModTDRStyle() to use this style with some additional customisation.

Definition at line 26 of file plotting.py.

◆ ModTDRStyle()

def python.plotting.ModTDRStyle (   width = 600,
  height = 600,
  t = 0.06,
  b = 0.12,
  l = 0.16,
  r = 0.04 
)

Modified version of the tdrStyle.

Parameters
widthCanvas width in pixels
heightCanvas height in pixels
tPad top margin [0-1]
bPad bottom margin [0-1]
lPad left margin [0-1]
rPad right margin [0-1]

Definition at line 177 of file plotting.py.

◆ SetBirdPalette()

def python.plotting.SetBirdPalette ( )

Definition at line 251 of file plotting.py.

◆ SetDeepSeaPalette()

def python.plotting.SetDeepSeaPalette ( )

Definition at line 264 of file plotting.py.

◆ SetCorrMatrixPalette()

def python.plotting.SetCorrMatrixPalette ( )

Definition at line 277 of file plotting.py.

◆ CreateTransparentColor()

def python.plotting.CreateTransparentColor (   color,
  alpha 
)

Definition at line 286 of file plotting.py.

◆ Set()

def python.plotting.Set (   obj,
**  kwargs 
)

Definition at line 296 of file plotting.py.

◆ OnePad()

def python.plotting.OnePad ( )

Definition at line 314 of file plotting.py.

◆ TwoPadSplit()

def python.plotting.TwoPadSplit (   split_point,
  gap_low,
  gap_high 
)

Definition at line 322 of file plotting.py.

◆ ThreePadSplit()

def python.plotting.ThreePadSplit (   upper_split_point,
  split_point,
  gap_low,
  gap_high 
)

Definition at line 335 of file plotting.py.

◆ MultiRatioSplit()

def python.plotting.MultiRatioSplit (   split_points,
  gaps_low,
  gaps_high 
)

Create a set of TPads split vertically on the TCanvas.

This is a generalisation of the two pad main/ratio split but for the case of multiple ratio pads.

Parameters
split_pointsHeight of each ratio pad as a fraction of the canvas height. Pads will be created from the bottom of the frame upwards. The final, main pad will occupy however much space remains, therefore the size of this list should be [number of pads] - 1.
gaps_lowGaps between ratio pad frames created on the lower pad side at each boundary. Give a list of zeroes for no gap between pad frames. Should be the same length as split_points.1
gaps_highGaps between ratio pad frames created on the upper pad side at each boundary. Give a list of zeroes for no gap between pad frames.
Returns
list List of TPads, indexed from top to bottom on the canvas.

Definition at line 374 of file plotting.py.

◆ TwoPadSplitColumns()

def python.plotting.TwoPadSplitColumns (   split_point,
  gap_left,
  gap_right 
)

Definition at line 389 of file plotting.py.

◆ MultiRatioSplitColumns()

def python.plotting.MultiRatioSplitColumns (   split_points,
  gaps_left,
  gaps_right 
)

Definition at line 403 of file plotting.py.

◆ SetupTwoPadSplitAsRatio()

def python.plotting.SetupTwoPadSplitAsRatio (   pads,
  upper,
  lower,
  y_title,
  y_centered,
  y_min,
  y_max 
)

Definition at line 419 of file plotting.py.

◆ StandardAxes() [1/2]

def python.plotting.StandardAxes (   xaxis,
  yaxis,
  var,
  units,
  fmt = '.1f' 
)

Definition at line 437 of file plotting.py.

◆ CreateAxisHist()

def python.plotting.CreateAxisHist (   src,
  at_limits = True 
)

Definition at line 460 of file plotting.py.

◆ CreateAxisHists()

def python.plotting.CreateAxisHists (   n,
  src,
  at_limits 
)

Definition at line 485 of file plotting.py.

◆ GetAxisHist()

def python.plotting.GetAxisHist (   pad)

Definition at line 493 of file plotting.py.

◆ TFileIsGood()

def python.plotting.TFileIsGood (   filename)

Performs a series of tests on a TFile to ensure that it can be opened without errors.

Parameters
filenamestr The name of the TFile to check
Returns
bool True if the file can opened, is not a zombie, and if ROOT did not need to try and recover the contents

Definition at line 527 of file plotting.py.

◆ MakeTChain()

def python.plotting.MakeTChain (   files,
  tree 
)

Definition at line 545 of file plotting.py.

◆ Get()

def python.plotting.Get (   file,
  obj 
)

Definition at line 552 of file plotting.py.

◆ ParamFromFilename()

def python.plotting.ParamFromFilename (   filename,
  param 
)

Definition at line 560 of file plotting.py.

◆ TGraphFromTree()

def python.plotting.TGraphFromTree (   tree,
  xvar,
  yvar,
  selection 
)

Definition at line 581 of file plotting.py.

◆ TGraph2DFromTree()

def python.plotting.TGraph2DFromTree (   tree,
  xvar,
  yvar,
  zvar,
  selection 
)

Definition at line 587 of file plotting.py.

◆ RocCurveFrom1DHists()

def python.plotting.RocCurveFrom1DHists (   h_x,
  h_y,
  cut_is_greater_than 
)

Definition at line 594 of file plotting.py.

◆ TH2FromTGraph2D()

def python.plotting.TH2FromTGraph2D (   graph,
  method = 'BinEdgeAligned',
  force_x_width = None,
  force_y_width = None 
)

Build an empty TH2 from the set of points in a TGraph2D.

There is no unique way to define a TH2 binning given an arbitrary TGraph2D, therefore this function supports multiple named methods:

  • BinEdgeAligned simply takes the sets of x- and y- values in the TGraph2D and uses these as the bin edge arrays in the TH2. The implication of this is that when filling the bin contents interpolation will be required when evaluating the TGraph2D at the bin centres.
  • BinCenterAligned will try to have the TGraph2D points at the bin centers, but this will only work completely correctly when the input point spacing is regular. The algorithm first identifies the bin width as the smallest interval between points on each axis. The start position of the TH2 axis is then defined as the lowest value in the TGraph2D minus half this width, and the axis continues with regular bins until the graph maximum is passed.
Parameters
graphShould have at least two unique x and y values, otherwise we can't define any bins
methodThe binning algorithm to use
force_x_widthOverride the derived x-axis bin width in the CenterAligned method
force_y_widthOverride the derived y-axis bin width in the CenterAligned method
Exceptions
RuntimeErrorIf the method name is not recognised
Returns
TH2F The exact binning of the TH2F depends on the chosen method

Definition at line 670 of file plotting.py.

◆ MakeErrorBand()

def python.plotting.MakeErrorBand (   LowerGraph,
  UpperGraph 
)

Definition at line 712 of file plotting.py.

◆ LimitTGraphFromJSON()

def python.plotting.LimitTGraphFromJSON (   js,
  label 
)

Definition at line 730 of file plotting.py.

◆ LimitTGraphFromJSONFile()

def python.plotting.LimitTGraphFromJSONFile (   jsfile,
  label 
)

Definition at line 741 of file plotting.py.

◆ ToyTGraphFromJSON()

def python.plotting.ToyTGraphFromJSON (   js,
  label 
)

Definition at line 746 of file plotting.py.

◆ ToyTGraphFromJSONFile()

def python.plotting.ToyTGraphFromJSONFile (   jsfile,
  label 
)

Definition at line 768 of file plotting.py.

◆ LimitBandTGraphFromJSON()

def python.plotting.LimitBandTGraphFromJSON (   js,
  central,
  lo,
  hi 
)

Definition at line 773 of file plotting.py.

◆ StandardLimitsFromJSONFile()

def python.plotting.StandardLimitsFromJSONFile (   json_file,
  draw = ['obs', 'exp0', 'exp1', 'exp2'] 
)

Definition at line 789 of file plotting.py.

◆ bestFit()

def python.plotting.bestFit (   tree,
  x,
  y,
  cut 
)

Definition at line 805 of file plotting.py.

◆ treeToHist2D()

def python.plotting.treeToHist2D (   t,
  x,
  y,
  name,
  cut,
  xmin,
  xmax,
  ymin,
  ymax,
  xbins,
  ybins 
)

Definition at line 820 of file plotting.py.

◆ makeHist1D()

def python.plotting.makeHist1D (   name,
  xbins,
  graph,
  scaleXrange = 1.0,
  absoluteXrange = None 
)

Definition at line 838 of file plotting.py.

◆ makeHist2D()

def python.plotting.makeHist2D (   name,
  xbins,
  ybins,
  graph2d 
)

Definition at line 849 of file plotting.py.

◆ makeVarBinHist2D()

def python.plotting.makeVarBinHist2D (   name,
  xbins,
  ybins 
)

Definition at line 859 of file plotting.py.

◆ GraphDifference()

def python.plotting.GraphDifference (   graph1,
  graph2,
  relative 
)

Definition at line 888 of file plotting.py.

◆ GraphDivide()

def python.plotting.GraphDivide (   num,
  den 
)

Definition at line 904 of file plotting.py.

◆ MakeRatioHist()

def python.plotting.MakeRatioHist (   num,
  den,
  num_err,
  den_err 
)

Make a new ratio TH1 from numerator and denominator TH1s with optional error propagation.

Parameters
numNumerator histogram
denDenominator histogram
num_errPropagate the error in the numerator TH1
den_errPropagate the error in the denominator TH1
Returns
TH1 A new TH1 containing the ratio

Definition at line 928 of file plotting.py.

◆ RemoveGraphXDuplicates()

def python.plotting.RemoveGraphXDuplicates (   graph)

Definition at line 947 of file plotting.py.

◆ ApplyGraphYOffset()

def python.plotting.ApplyGraphYOffset (   graph,
  y_off 
)

Definition at line 957 of file plotting.py.

◆ RemoveGraphYAll()

def python.plotting.RemoveGraphYAll (   graph,
  val 
)

Definition at line 962 of file plotting.py.

◆ RemoveSmallDelta()

def python.plotting.RemoveSmallDelta (   graph,
  val 
)

Definition at line 971 of file plotting.py.

◆ RemoveGraphYAbove()

def python.plotting.RemoveGraphYAbove (   graph,
  val 
)

Definition at line 981 of file plotting.py.

◆ SetMinToZero()

def python.plotting.SetMinToZero (   graph)

Definition at line 991 of file plotting.py.

◆ ImproveMinimum()

def python.plotting.ImproveMinimum (   graph,
  func,
  doIt = False 
)

Definition at line 1003 of file plotting.py.

◆ FindCrossingsWithSpline()

def python.plotting.FindCrossingsWithSpline (   graph,
  func,
  yval 
)

Definition at line 1040 of file plotting.py.

◆ ReZeroTGraph()

def python.plotting.ReZeroTGraph (   gr,
  doIt = False 
)

Definition at line 1087 of file plotting.py.

◆ FilterGraph()

def python.plotting.FilterGraph (   gr,
  n = 3 
)

Definition at line 1112 of file plotting.py.

◆ RemoveInXRange()

def python.plotting.RemoveInXRange (   gr,
  xmin = 0,
  xmax = 1 
)

Definition at line 1126 of file plotting.py.

◆ RemoveNearMin()

def python.plotting.RemoveNearMin (   graph,
  val,
  spacing = None 
)

Definition at line 1138 of file plotting.py.

◆ SortGraph()

def python.plotting.SortGraph (   Graph)

Definition at line 1166 of file plotting.py.

◆ FixTopRange()

def python.plotting.FixTopRange (   pad,
  fix_y,
  fraction 
)

Definition at line 1186 of file plotting.py.

◆ FixBothRanges()

def python.plotting.FixBothRanges (   pad,
  fix_y_lo,
  frac_lo,
  fix_y_hi,
  frac_hi 
)

Adjusts y-axis range such that a lower and a higher value are located a fixed fraction of the frame height away from a new minimum and maximum respectively.

This function is useful in conjunction with GetPadYMax which returns the maximum or minimum y value of all histograms and graphs drawn on the pad.

In the example below, the minimum and maximum values found via this function are used as the fix_y_lo and fix_y_hi arguments, and the spacing fractions as 0.15 and 0.30 respectively.

FixBothRanges(pad, GetPadYMin(pad), 0.15, GetPadYMax(pad), 0.30)
Parameters
padA TPad on which histograms and graphs have already been drawn
fix_y_loThe y value which will end up a fraction frac_lo above the new axis minimum.
frac_loA fraction of the y-axis height
fix_y_hiThe y value which will end up a fraction frac_hi below from the new axis maximum.
frac_hiA fraction of the y-axis height

Definition at line 1226 of file plotting.py.

◆ GetPadYMaxInRange()

def python.plotting.GetPadYMaxInRange (   pad,
  x_min,
  x_max,
  do_min = False 
)

Definition at line 1252 of file plotting.py.

◆ GetPadYMax()

def python.plotting.GetPadYMax (   pad,
  do_min = False 
)

Definition at line 1310 of file plotting.py.

◆ GetPadYMin()

def python.plotting.GetPadYMin (   pad)

Definition at line 1319 of file plotting.py.

◆ FixOverlay()

def python.plotting.FixOverlay ( )

Definition at line 1323 of file plotting.py.

◆ FixBoxPadding()

def python.plotting.FixBoxPadding (   pad,
  box,
  frac 
)

Definition at line 1328 of file plotting.py.

◆ StandardAxes() [2/2]

def python.plotting.StandardAxes (   xaxis,
  yaxis,
  var,
  units 
)

Definition at line 1372 of file plotting.py.

◆ DrawCMSLogo()

def python.plotting.DrawCMSLogo (   pad,
  cmsText,
  extraText,
  iPosX,
  relPosX,
  relPosY,
  relExtraDY,
  extraText2 = '',
  cmsTextSize = 0.8 
)

Blah.

Parameters
padDescription
cmsTextDescription
extraTextDescription
iPosXDescription
relPosXDescription
relPosYDescription
relExtraDYDescription
extraText2Description
cmsTextSizeDescription
Returns
TYPE Description

Definition at line 1399 of file plotting.py.

◆ PositionedLegend()

def python.plotting.PositionedLegend (   width,
  height,
  pos,
  offset,
  horizontaloffset = None 
)

Definition at line 1492 of file plotting.py.

◆ DrawHorizontalLine()

def python.plotting.DrawHorizontalLine (   pad,
  line,
  yval 
)

Definition at line 1519 of file plotting.py.

◆ DrawVerticalLine()

def python.plotting.DrawVerticalLine (   pad,
  line,
  xval 
)

Definition at line 1526 of file plotting.py.

◆ DrawVerticalBand()

def python.plotting.DrawVerticalBand (   pad,
  box,
  x1,
  x2 
)

Definition at line 1532 of file plotting.py.

◆ DrawTitle()

def python.plotting.DrawTitle (   pad,
  text,
  align,
  textOffset = 0.2,
  textSize = 0.6 
)

Definition at line 1539 of file plotting.py.

◆ isclose()

def python.plotting.isclose (   a,
  b,
  rel_tol = 1e-9,
  abs_tol = 0.0 
)

Definition at line 1583 of file plotting.py.

◆ StyleLimitBand()

def python.plotting.StyleLimitBand (   graph_dict,
  overwrite_style_dict = None 
)

Definition at line 1586 of file plotting.py.

◆ DrawLimitBand()

def python.plotting.DrawLimitBand (   pad,
  graph_dict,
  draw = ['exp2', 'exp1', 'exp0', 'obs'],
  draw_legend = None,
  legend = None,
  legend_overwrite = None 
)

Definition at line 1602 of file plotting.py.

◆ contourFromTH2()

def python.plotting.contourFromTH2 (   h2in,
  threshold,
  minPoints = 10,
  frameValue = 1000. 
)

Definition at line 1636 of file plotting.py.

◆ frameTH2D()

def python.plotting.frameTH2D (   hist,
  threshold,
  frameValue = 1000 
)

Definition at line 1675 of file plotting.py.

◆ fastFillTH2()

def python.plotting.fastFillTH2 (   hist2d,
  graph,
  initalValue = 99999,
  interpolateMissing = False 
)

Definition at line 1742 of file plotting.py.

◆ fillTH2()

def python.plotting.fillTH2 (   hist2d,
  graph 
)

Definition at line 1761 of file plotting.py.

◆ fillInvertedTH2()

def python.plotting.fillInvertedTH2 (   hist2d,
  graph 
)

Definition at line 1769 of file plotting.py.

◆ NewInterpolate()

def python.plotting.NewInterpolate (   hist)

Definition at line 1782 of file plotting.py.

◆ rebin()

def python.plotting.rebin (   hist)

Definition at line 1871 of file plotting.py.

◆ higgsConstraint()

def python.plotting.higgsConstraint (   model,
  higgstype 
)

Definition at line 1898 of file plotting.py.

◆ getOverlayMarkerAndLegend()

def python.plotting.getOverlayMarkerAndLegend (   legend,
  entries,
  options,
  borderSize = 2.0/3,
  markerStyle = "P" 
)

Definition at line 1920 of file plotting.py.

Variable Documentation

◆ COL_STORE

list python.plotting.COL_STORE = []

Definition at line 12 of file plotting.py.

python.plotting.GetPadYMax
def GetPadYMax(pad, do_min=False)
Definition: plotting.py:1310
python.plotting.FixBothRanges
def FixBothRanges(pad, fix_y_lo, frac_lo, fix_y_hi, frac_hi)
Adjusts y-axis range such that a lower and a higher value are located a fixed fraction of the frame h...
Definition: plotting.py:1226
python.plotting.GetPadYMin
def GetPadYMin(pad)
Definition: plotting.py:1319