CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
plotting.Plot Class Reference

Public Member Functions

def __init__ (self, name, **kwargs)
 
def addToLegend (self, legend, legendLabels, denomUncertainty)
 
def clone (self, **kwargs)
 
def create (self, tdirNEvents, requireAllHistograms=False)
 
def draw (self, pad, ratio, ratioFactor, nrows)
 
def drawRatioUncertainty (self)
 
def getName (self)
 
def getNumberOfHistograms (self)
 
def isEmpty (self)
 
def isRatio (self, ratio)
 
def isTGraph2D (self)
 
def setProperties (self, **kwargs)
 

Private Member Functions

def _createOne (self, name, index, tdir, nevents)
 
def _normalize (self)
 
def _setStats (self, histos, startingX, startingY)
 

Private Attributes

 _forLegend
 
 _frame
 
 _histograms
 
 _mainAdditional
 
 _name
 
 _ratioAdditional
 
 _ratios
 
 _tmp_histos
 
 _xtitle
 
 _ytitle
 

Detailed Description

Represents one plot, comparing one or more histograms.

Definition at line 1694 of file plotting.py.

Constructor & Destructor Documentation

◆ __init__()

def plotting.Plot.__init__ (   self,
  name,
**  kwargs 
)
Constructor.

Arguments:
name -- String for name of the plot, or Efficiency object

Keyword arguments:
fallback     -- Dictionary for specifying fallback (default None)
outname      -- String for an output name of the plot (default None for the same as 'name')
title        -- String for a title of the plot (default None)
xtitle       -- String for x axis title (default None)
xtitlesize   -- Float for x axis title size (default None)
xtitleoffset -- Float for x axis title offset (default None)
xlabelsize   -- Float for x axis label size (default None)
ytitle       -- String for y axis title (default None)
ytitlesize   -- Float for y axis title size (default None)
ytitleoffset -- Float for y axis title offset (default None)
ztitle       -- String for z axis title (default None)
ztitleoffset -- Float for z axis title offset (default None)
xmin         -- Float for x axis minimum (default None, i.e. automatic)
xmax         -- Float for x axis maximum (default None, i.e. automatic)
ymin         -- Float for y axis minimum (default 0)
ymax         -- Float for y axis maximum (default None, i.e. automatic)
xlog         -- Bool for x axis log status (default False)
ylog         -- Bool for y axis log status (default False)
xgrid        -- Bool for x axis grid status (default True)
ygrid        -- Bool for y axis grid status (default True)
stat         -- Draw stat box? (default False)
fit          -- Do gaussian fit? (default False)
statx        -- Stat box x coordinate (default 0.65)
staty        -- Stat box y coordinate (default 0.8)
statyadjust  -- List of floats for stat box y coordinate adjustments (default None)
normalizeToUnitArea -- Normalize histograms to unit area? (default False)
normalizeToNumberOfEvents -- Normalize histograms to number of events? If yes, the PlotFolder needs 'numberOfEventsHistogram' set to a histogram filled once per event (default False)
profileX     -- Take histograms via ProfileX()? (default False)
fitSlicesY   -- Take histograms via FitSlicesY() (default False)
rebinX       -- rebin x axis (default None)
scale        -- Scale histograms by a number (default None)
xbinlabels   -- List of x axis bin labels (if given, default None)
xbinlabelsize -- Size of x axis bin labels (default None)
xbinlabeloption -- Option string for x axis bin labels (default None)
removeEmptyBins -- Bool for removing empty bins, but only if histogram has bin labels (default False)
printBins    -- Bool for printing bin values, but only if histogram has bin labels (default False)
drawStyle    -- If "hist", draw as line instead of points (default None)
drawCommand  -- Deliver this to Draw() (default: None for same as drawStyle)
lineWidth    -- If drawStyle=="hist", the width of line (default 2)
legendDx     -- Float for moving TLegend in x direction for separate=True (default None)
legendDy     -- Float for moving TLegend in y direction for separate=True (default None)
legendDw     -- Float for changing TLegend width for separate=True (default None)
legendDh     -- Float for changing TLegend height for separate=True (default None)
legend       -- Bool to enable/disable legend (default True)
adjustMarginLeft  -- Float for adjusting left margin (default None)
adjustMarginRight  -- Float for adjusting right margin (default None)
ratio        -- Possibility to disable ratio for this particular plot (default None)
ratioYmin    -- Float for y axis minimum in ratio pad (default: list of values)
ratioYmax    -- Float for y axis maximum in ratio pad (default: list of values)
ratioFit     -- Fit straight line in ratio? (default None)
ratioUncertainty -- Plot uncertainties on ratio? (default True)
ratioCoverageXrange -- Range of x axis values (xmin,xmax) to limit the automatic ratio y axis range calculation to (default None for disabled)
histogramModifier -- Function to be called in create() to modify the histograms (default None)

Definition at line 1696 of file plotting.py.

1696  def __init__(self, name, **kwargs):
1697  """ Constructor.
1698 
1699  Arguments:
1700  name -- String for name of the plot, or Efficiency object
1701 
1702  Keyword arguments:
1703  fallback -- Dictionary for specifying fallback (default None)
1704  outname -- String for an output name of the plot (default None for the same as 'name')
1705  title -- String for a title of the plot (default None)
1706  xtitle -- String for x axis title (default None)
1707  xtitlesize -- Float for x axis title size (default None)
1708  xtitleoffset -- Float for x axis title offset (default None)
1709  xlabelsize -- Float for x axis label size (default None)
1710  ytitle -- String for y axis title (default None)
1711  ytitlesize -- Float for y axis title size (default None)
1712  ytitleoffset -- Float for y axis title offset (default None)
1713  ztitle -- String for z axis title (default None)
1714  ztitleoffset -- Float for z axis title offset (default None)
1715  xmin -- Float for x axis minimum (default None, i.e. automatic)
1716  xmax -- Float for x axis maximum (default None, i.e. automatic)
1717  ymin -- Float for y axis minimum (default 0)
1718  ymax -- Float for y axis maximum (default None, i.e. automatic)
1719  xlog -- Bool for x axis log status (default False)
1720  ylog -- Bool for y axis log status (default False)
1721  xgrid -- Bool for x axis grid status (default True)
1722  ygrid -- Bool for y axis grid status (default True)
1723  stat -- Draw stat box? (default False)
1724  fit -- Do gaussian fit? (default False)
1725  statx -- Stat box x coordinate (default 0.65)
1726  staty -- Stat box y coordinate (default 0.8)
1727  statyadjust -- List of floats for stat box y coordinate adjustments (default None)
1728  normalizeToUnitArea -- Normalize histograms to unit area? (default False)
1729  normalizeToNumberOfEvents -- Normalize histograms to number of events? If yes, the PlotFolder needs 'numberOfEventsHistogram' set to a histogram filled once per event (default False)
1730  profileX -- Take histograms via ProfileX()? (default False)
1731  fitSlicesY -- Take histograms via FitSlicesY() (default False)
1732  rebinX -- rebin x axis (default None)
1733  scale -- Scale histograms by a number (default None)
1734  xbinlabels -- List of x axis bin labels (if given, default None)
1735  xbinlabelsize -- Size of x axis bin labels (default None)
1736  xbinlabeloption -- Option string for x axis bin labels (default None)
1737  removeEmptyBins -- Bool for removing empty bins, but only if histogram has bin labels (default False)
1738  printBins -- Bool for printing bin values, but only if histogram has bin labels (default False)
1739  drawStyle -- If "hist", draw as line instead of points (default None)
1740  drawCommand -- Deliver this to Draw() (default: None for same as drawStyle)
1741  lineWidth -- If drawStyle=="hist", the width of line (default 2)
1742  legendDx -- Float for moving TLegend in x direction for separate=True (default None)
1743  legendDy -- Float for moving TLegend in y direction for separate=True (default None)
1744  legendDw -- Float for changing TLegend width for separate=True (default None)
1745  legendDh -- Float for changing TLegend height for separate=True (default None)
1746  legend -- Bool to enable/disable legend (default True)
1747  adjustMarginLeft -- Float for adjusting left margin (default None)
1748  adjustMarginRight -- Float for adjusting right margin (default None)
1749  ratio -- Possibility to disable ratio for this particular plot (default None)
1750  ratioYmin -- Float for y axis minimum in ratio pad (default: list of values)
1751  ratioYmax -- Float for y axis maximum in ratio pad (default: list of values)
1752  ratioFit -- Fit straight line in ratio? (default None)
1753  ratioUncertainty -- Plot uncertainties on ratio? (default True)
1754  ratioCoverageXrange -- Range of x axis values (xmin,xmax) to limit the automatic ratio y axis range calculation to (default None for disabled)
1755  histogramModifier -- Function to be called in create() to modify the histograms (default None)
1756  """
1757  self._name = name
1758 
1759  def _set(attr, default):
1760  setattr(self, "_"+attr, kwargs.get(attr, default))
1761 
1762  _set("fallback", None)
1763  _set("outname", None)
1764 
1765  _set("title", None)
1766  _set("xtitle", None)
1767  _set("xtitlesize", None)
1768  _set("xtitleoffset", None)
1769  _set("xlabelsize", None)
1770  _set("ytitle", None)
1771  _set("ytitlesize", None)
1772  _set("ytitleoffset", None)
1773  _set("ztitle", None)
1774  _set("ztitleoffset", None)
1775 
1776  _set("xmin", None)
1777  _set("xmax", None)
1778  _set("ymin", 0.)
1779  _set("ymax", None)
1780 
1781  _set("xlog", False)
1782  _set("ylog", False)
1783  _set("xgrid", True)
1784  _set("ygrid", True)
1785 
1786  _set("stat", False)
1787  _set("fit", False)
1788 
1789  _set("statx", 0.65)
1790  _set("staty", 0.8)
1791  _set("statyadjust", None)
1792 
1793  _set("normalizeToUnitArea", False)
1794  _set("normalizeToNumberOfEvents", False)
1795  _set("profileX", False)
1796  _set("fitSlicesY", False)
1797  _set("rebinX", None)
1798 
1799  _set("scale", None)
1800  _set("xbinlabels", None)
1801  _set("xbinlabelsize", None)
1802  _set("xbinlabeloption", None)
1803  _set("removeEmptyBins", False)
1804  _set("printBins", False)
1805 
1806  _set("drawStyle", "EP")
1807  _set("drawCommand", None)
1808  _set("lineWidth", 2)
1809 
1810  _set("legendDx", None)
1811  _set("legendDy", None)
1812  _set("legendDw", None)
1813  _set("legendDh", None)
1814  _set("legend", True)
1815 
1816  _set("adjustMarginLeft", None)
1817  _set("adjustMarginRight", None)
1818 
1819  _set("ratio", None)
1820  _set("ratioYmin", [0, 0.2, 0.5, 0.7, 0.8, 0.9, 0.95])
1821  _set("ratioYmax", [1.05, 1.1, 1.2, 1.3, 1.5, 1.8, 2, 2.5, 3, 4, 5])
1822  _set("ratioFit", None)
1823  _set("ratioUncertainty", True)
1824  _set("ratioCoverageXrange", None)
1825 
1826  _set("histogramModifier", None)
1827 
1828  self._histograms = []
1829 

Member Function Documentation

◆ _createOne()

def plotting.Plot._createOne (   self,
  name,
  index,
  tdir,
  nevents 
)
private
Create one histogram from a TDirectory.

Definition at line 1874 of file plotting.py.

1874  def _createOne(self, name, index, tdir, nevents):
1875  """Create one histogram from a TDirectory."""
1876  if tdir == None:
1877  return None
1878 
1879  # If name is a list, pick the name by the index
1880  if isinstance(name, list):
1881  name = name[index]
1882 
1883  h = _getOrCreateObject(tdir, name)
1884  if h is not None and self._normalizeToNumberOfEvents and nevents is not None and nevents != 0:
1885  h.Scale(1.0/nevents)
1886  return h
1887 

References plotting._getOrCreateObject().

Referenced by plotting.Plot.create().

◆ _normalize()

def plotting.Plot._normalize (   self)
private
Normalise histograms to unit area

Definition at line 1979 of file plotting.py.

1979  def _normalize(self):
1980  """Normalise histograms to unit area"""
1981 
1982  for h in self._histograms:
1983  if h is None:
1984  continue
1985  i = h.Integral()
1986  if i == 0:
1987  continue
1988  if h.GetSumw2().fN <= 0: # to suppress warning
1989  h.Sumw2()
1990  h.Scale(1.0/i)
1991 

References RunHistogramManager._histograms, and plotting.Plot._histograms.

Referenced by plotting.Plot.draw().

◆ _setStats()

def plotting.Plot._setStats (   self,
  histos,
  startingX,
  startingY 
)
private
Set stats box.

Definition at line 1938 of file plotting.py.

1938  def _setStats(self, histos, startingX, startingY):
1939  """Set stats box."""
1940  if not self._stat:
1941  for h in histos:
1942  if h is not None and hasattr(h, "SetStats"):
1943  h.SetStats(0)
1944  return
1945 
1946  def _doStats(h, col, dy):
1947  if h is None:
1948  return
1949  h.SetStats(True)
1950 
1951  if self._fit and h.GetEntries() > 0.5:
1952  h.Fit("gaus", "Q")
1953  f = h.GetListOfFunctions().FindObject("gaus")
1954  if f == None:
1955  h.SetStats(0)
1956  return
1957  f.SetLineColor(col)
1958  f.SetLineWidth(1)
1959  h.Draw()
1960  ROOT.gPad.Update()
1961  st = h.GetListOfFunctions().FindObject("stats")
1962  if self._fit:
1963  st.SetOptFit(0o010)
1964  st.SetOptStat(1001)
1965  st.SetX1NDC(startingX)
1966  st.SetX2NDC(startingX+0.3)
1967  st.SetY1NDC(startingY+dy)
1968  st.SetY2NDC(startingY+dy+0.15)
1969  st.SetTextColor(col)
1970 
1971  dy = 0.0
1972  for i, h in enumerate(histos):
1973  if self._statyadjust is not None and i < len(self._statyadjust):
1974  dy += self._statyadjust[i]
1975 
1976  _doStats(h, _plotStylesColor[i], dy)
1977  dy -= 0.19
1978 

References DTSC._stat, and DTTrigGeom._stat.

◆ addToLegend()

def plotting.Plot.addToLegend (   self,
  legend,
  legendLabels,
  denomUncertainty 
)
Add histograms to a legend.

Arguments:
legend       -- TLegend
legendLabels -- List of strings for the legend labels

Definition at line 2225 of file plotting.py.

2225  def addToLegend(self, legend, legendLabels, denomUncertainty):
2226  """Add histograms to a legend.
2227 
2228  Arguments:
2229  legend -- TLegend
2230  legendLabels -- List of strings for the legend labels
2231  """
2232  first = denomUncertainty
2233  for h, label in zip(self._histograms, legendLabels):
2234  if h is None:
2235  first = False
2236  continue
2237  if first:
2238  self._forLegend = h.Clone()
2239  self._forLegend.SetFillStyle(1001)
2240  self._forLegend.SetFillColor(ROOT.kGray)
2241  entry = legend.AddEntry(self._forLegend, label, "lpf")
2242  first = False
2243  else:
2244  legend.AddEntry(h, label, "LP")
2245 

References RunHistogramManager._histograms, plotting.Plot._histograms, and ComparisonHelper.zip().

◆ clone()

def plotting.Plot.clone (   self,
**  kwargs 
)

◆ create()

def plotting.Plot.create (   self,
  tdirNEvents,
  requireAllHistograms = False 
)
Create histograms from list of TDirectories

Definition at line 1888 of file plotting.py.

1888  def create(self, tdirNEvents, requireAllHistograms=False):
1889  """Create histograms from list of TDirectories"""
1890  self._histograms = [self._createOne(self._name, i, tdirNEvent[0], tdirNEvent[1]) for i, tdirNEvent in enumerate(tdirNEvents)]
1891 
1892  if self._fallback is not None:
1893  profileX = [self._profileX]*len(self._histograms)
1894  for i in range(0, len(self._histograms)):
1895  if self._histograms[i] is None:
1896  self._histograms[i] = self._createOne(self._fallback["name"], i, tdirNEvents[i][0], tdirNEvents[i][1])
1897  profileX[i] = self._fallback.get("profileX", self._profileX)
1898 
1899  if self._histogramModifier is not None:
1900  self._histograms = self._histogramModifier(self._histograms)
1901 
1902  if len(self._histograms) > len(_plotStylesColor):
1903  raise Exception("More histograms (%d) than there are plot styles (%d) defined. Please define more plot styles in this file" % (len(self._histograms), len(_plotStylesColor)))
1904 
1905  # Modify histograms here in case self._name returns numbers
1906  # and self._histogramModifier creates the histograms from
1907  # these numbers
1908  def _modifyHisto(th1, profileX):
1909  if th1 is None:
1910  return None
1911 
1912  if profileX:
1913  th1 = th1.ProfileX()
1914 
1915  if self._fitSlicesY:
1916  ROOT.TH1.AddDirectory(True)
1917  th1.FitSlicesY()
1918  th1 = ROOT.gDirectory.Get(th1.GetName()+"_2")
1919  th1.SetDirectory(None)
1920  #th1.SetName(th1.GetName()+"_ref")
1921  ROOT.TH1.AddDirectory(False)
1922 
1923  if self._title is not None:
1924  th1.SetTitle(self._title)
1925 
1926  if self._scale is not None:
1927  th1.Scale(self._scale)
1928 
1929  return th1
1930 
1931  if self._fallback is not None:
1932  self._histograms = map(_modifyHisto, self._histograms, profileX)
1933  else:
1934  self._histograms = map(lambda h: _modifyHisto(h, self._profileX), self._histograms)
1935  if requireAllHistograms and None in self._histograms:
1936  self._histograms = [None]*len(self._histograms)
1937 

References plotting.Plot._createOne(), RunHistogramManager._histograms, plotting.Plot._histograms, FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, TrackingRecHitAlgorithm._name, Logger._name, hcaldqm::DQModule._name, citk::IsolationConeDefinitionBase._name, DrellYanValidation._name, WValidation._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, GeometricDetExtra._name, GeometricTimingDetExtra._name, HistoParams< T >._name, CutApplicatorBase._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, SequenceTypes.SequencePlaceholder._name, plotting.Subtract._name, plotting.Transform._name, plotting.FakeDuplicate._name, plotting.CutEfficiency._name, plotting.AggregateBins._name, plotting.AggregateHistos._name, plotting.ROC._name, SequenceTypes.TaskPlaceholder._name, plotting.Plot._name, plotting.AggregateBins._scale, HistoParams< T >._title, HistoParams< TH2F >._title, SiStripHitEffFromCalibTree._title, HistoParams< TProfile2D >._title, html.PageSet._title, html.HtmlReport._title, plotting.Subtract._title, plotting.Transform._title, plotting.FakeDuplicate._title, plotting.CutEfficiency._title, genParticles_cff.map, and FastTimerService_cff.range.

◆ draw()

def plotting.Plot.draw (   self,
  pad,
  ratio,
  ratioFactor,
  nrows 
)
Draw the histograms using values for a given algorithm.

Definition at line 1992 of file plotting.py.

1992  def draw(self, pad, ratio, ratioFactor, nrows):
1993  """Draw the histograms using values for a given algorithm."""
1994 # if len(self._histograms) == 0:
1995 # print "No histograms for plot {name}".format(name=self._name)
1996 # return
1997 
1998  isTGraph2D = self.isTGraph2D()
1999  if isTGraph2D:
2000  # Ratios for the TGraph2Ds is not that interesting
2001  ratioOrig = ratio
2002  ratio = False
2003 
2004  if self._normalizeToUnitArea:
2005  self._normalize()
2006 
2007  if self._rebinX is not None:
2008  for h in self._histograms:
2009  h.Rebin(self._rebinX)
2010 
2011  def _styleMarker(h, msty, col):
2012  h.SetMarkerStyle(msty)
2013  h.SetMarkerColor(col)
2014  h.SetMarkerSize(0.7)
2015  h.SetLineColor(1)
2016  h.SetLineWidth(1)
2017 
2018  def _styleHist(h, msty, col):
2019  _styleMarker(h, msty, col)
2020  h.SetLineColor(col)
2021  h.SetLineWidth(self._lineWidth)
2022 
2023  # Use marker or hist style
2024  style = _styleMarker
2025  if "hist" in self._drawStyle.lower():
2026  style = _styleHist
2027  if len(self._histograms) > 0 and isinstance(self._histograms[0], ROOT.TGraph):
2028  if "l" in self._drawStyle.lower():
2029  style = _styleHist
2030 
2031  # Apply style to histograms, filter out Nones
2032  histos = []
2033  for i, h in enumerate(self._histograms):
2034  if h is None:
2035  continue
2036  style(h, _plotStylesMarker[i], _plotStylesColor[i])
2037  histos.append(h)
2038  if len(histos) == 0:
2039  if verbose:
2040  print("No histograms for plot {name}".format(name=self.getName()))
2041  return
2042 
2043  # Extract x bin labels, make sure that only bins with same
2044  # label are compared with each other
2045  histosHaveBinLabels = len(histos[0].GetXaxis().GetBinLabel(1)) > 0
2046  xbinlabels = self._xbinlabels
2047  ybinlabels = None
2048  if xbinlabels is None:
2049  if histosHaveBinLabels:
2050  xbinlabels = _mergeBinLabelsX(histos)
2051  if isinstance(histos[0], ROOT.TH2):
2052  ybinlabels = _mergeBinLabelsY(histos)
2053 
2054  if len(histos) > 1: # don't bother if only one histogram
2055  # doing this for TH2 is pending for use case, for now there is only 1 histogram/plot for TH2
2056  histos = _th1IncludeOnlyBins(histos, xbinlabels)
2057  self._tmp_histos = histos # need to keep these in memory too ...
2058 
2059  # Remove empty bins, but only if histograms have bin labels
2060  if self._removeEmptyBins and histosHaveBinLabels:
2061  # at this point, all histograms have been "equalized" by their x binning and labels
2062  # therefore remove bins which are empty in all histograms
2063  if isinstance(histos[0], ROOT.TH2):
2064  (histos, xbinlabels, ybinlabels) = _th2RemoveEmptyBins(histos, xbinlabels, ybinlabels)
2065  else:
2066  (histos, xbinlabels) = _th1RemoveEmptyBins(histos, xbinlabels)
2067  self._tmp_histos = histos # need to keep these in memory too ...
2068  if len(histos) == 0:
2069  if verbose:
2070  print("No histograms with non-empty bins for plot {name}".format(name=self.getName()))
2071  return
2072 
2073  if self._printBins and histosHaveBinLabels:
2074  print("####################")
2075  print(self._name)
2076  width = max([len(l) for l in xbinlabels])
2077  tmp = "%%-%ds " % width
2078  for b in range(1, histos[0].GetNbinsX()+1):
2079  s = tmp % xbinlabels[b-1]
2080  for h in histos:
2081  s += "%.3f " % h.GetBinContent(b)
2082  print(s)
2083  print()
2084 
2085  bounds = _findBounds(histos, self._ylog,
2086  xmin=self._xmin, xmax=self._xmax,
2087  ymin=self._ymin, ymax=self._ymax)
2088  zmax = None
2089  if isinstance(histos[0], ROOT.TH2):
2090  zmax = max([h.GetMaximum() for h in histos])
2091 
2092  # need to keep these in memory
2093  self._mainAdditional = []
2094  self._ratioAdditional = []
2095 
2096  if ratio:
2097  self._ratios = _calculateRatios(histos, self._ratioUncertainty) # need to keep these in memory too ...
2098  ratioHistos = [h for h in [r.getRatio() for r in self._ratios[1:]] if h is not None]
2099 
2100  if len(ratioHistos) > 0:
2101  ratioBoundsY = _findBoundsY(ratioHistos, ylog=False, ymin=self._ratioYmin, ymax=self._ratioYmax, coverage=0.68, coverageRange=self._ratioCoverageXrange)
2102  else:
2103  ratioBoundsY = (0.9, 1,1) # hardcoded default in absence of valid ratio calculations
2104 
2105  if self._ratioFit is not None:
2106  for i, rh in enumerate(ratioHistos):
2107  tf_line = ROOT.TF1("line%d"%i, "[0]+x*[1]")
2108  tf_line.SetRange(self._ratioFit["rangemin"], self._ratioFit["rangemax"])
2109  fitres = rh.Fit(tf_line, "RINSQ")
2110  tf_line.SetLineColor(rh.GetMarkerColor())
2111  tf_line.SetLineWidth(2)
2112  self._ratioAdditional.append(tf_line)
2113  box = PlotTextBox(xmin=self._ratioFit.get("boxXmin", 0.14), ymin=None, # None for automatix
2114  xmax=self._ratioFit.get("boxXmax", 0.35), ymax=self._ratioFit.get("boxYmax", 0.09),
2115  color=rh.GetMarkerColor(), font=43, size=11, lineheight=0.02)
2116  box.move(dx=(box.width()+0.01)*i)
2117  #box.addText("Const: %.4f" % fitres.Parameter(0))
2118  #box.addText("Slope: %.4f" % fitres.Parameter(1))
2119  box.addText("Const: %.4f#pm%.4f" % (fitres.Parameter(0), fitres.ParError(0)))
2120  box.addText("Slope: %.4f#pm%.4f" % (fitres.Parameter(1), fitres.ParError(1)))
2121  self._mainAdditional.append(box)
2122 
2123 
2124  # Create bounds before stats in order to have the
2125  # SetRangeUser() calls made before the fit
2126  #
2127  # stats is better to be called before frame, otherwise get
2128  # mess in the plot (that frame creation cleans up)
2129  if ratio:
2130  pad.cd(1)
2131  self._setStats(histos, self._statx, self._staty)
2132 
2133  # Create frame
2134  if isTGraph2D:
2135  frame = FrameTGraph2D(pad, bounds, histos, ratioOrig, ratioFactor)
2136  else:
2137  if ratio:
2138  ratioBounds = (bounds[0], ratioBoundsY[0], bounds[2], ratioBoundsY[1])
2139  frame = FrameRatio(pad, bounds, zmax, ratioBounds, ratioFactor, nrows, xbinlabels, self._xbinlabelsize, self._xbinlabeloption)
2140  else:
2141  frame = Frame(pad, bounds, zmax, nrows, xbinlabels, self._xbinlabelsize, self._xbinlabeloption, ybinlabels=ybinlabels)
2142 
2143  # Set log and grid
2144  frame.setLogx(self._xlog)
2145  frame.setLogy(self._ylog)
2146  frame.setGridx(self._xgrid)
2147  frame.setGridy(self._ygrid)
2148 
2149  # Construct draw option string
2150  opt = "sames" # s for statbox or something?
2151  ds = ""
2152  if self._drawStyle is not None:
2153  ds = self._drawStyle
2154  if self._drawCommand is not None:
2155  ds = self._drawCommand
2156  if len(ds) > 0:
2157  opt += " "+ds
2158 
2159  # Set properties of frame
2160  frame.setTitle(histos[0].GetTitle())
2161  if self._xtitle == 'Default':
2162  frame.setXTitle( histos[0].GetXaxis().GetTitle() )
2163  elif self._xtitle is not None:
2164  frame.setXTitle(self._xtitle)
2165  if self._xtitlesize is not None:
2166  frame.setXTitleSize(self._xtitlesize)
2167  if self._xtitleoffset is not None:
2168  frame.setXTitleOffset(self._xtitleoffset)
2169  if self._xlabelsize is not None:
2170  frame.setXLabelSize(self._xlabelsize)
2171  if self._ytitle == 'Default':
2172  frame.setYTitle( histos[0].GetYaxis().GetTitle() )
2173  elif self._ytitle is not None:
2174  frame.setYTitle(self._ytitle)
2175  if self._ytitlesize is not None:
2176  frame.setYTitleSize(self._ytitlesize)
2177  if self._ytitleoffset is not None:
2178  frame.setYTitleOffset(self._ytitleoffset)
2179  if self._ztitle is not None:
2180  frame.setZTitle(self._ztitle)
2181  if self._ztitleoffset is not None:
2182  frame.setZTitleOffset(self._ztitleoffset)
2183  if self._adjustMarginLeft is not None:
2184  frame.adjustMarginLeft(self._adjustMarginLeft)
2185  if self._adjustMarginRight is not None:
2186  frame.adjustMarginRight(self._adjustMarginRight)
2187  elif "z" in opt:
2188  frame.adjustMarginLeft(0.03)
2189  frame.adjustMarginRight(0.08)
2190 
2191  # Draw histograms
2192  if ratio:
2193  frame._pad.cd()
2194 
2195  for i, h in enumerate(histos):
2196  o = opt
2197  if isTGraph2D and i == 0:
2198  o = o.replace("sames", "")
2199  h.Draw(o)
2200 
2201  for addl in self._mainAdditional:
2202  addl.Draw("same")
2203 
2204  # Draw ratios
2205  if ratio and len(histos) > 0:
2206  frame._padRatio.cd()
2207  firstRatio = self._ratios[0].getRatio()
2208  if self._ratioUncertainty and firstRatio is not None:
2209  firstRatio.SetFillStyle(1001)
2210  firstRatio.SetFillColor(ROOT.kGray)
2211  firstRatio.SetLineColor(ROOT.kGray)
2212  firstRatio.SetMarkerColor(ROOT.kGray)
2213  firstRatio.SetMarkerSize(0)
2214  self._ratios[0].draw("E2")
2215  frame._padRatio.RedrawAxis("G") # redraw grid on top of the uncertainty of denominator
2216  for r in self._ratios[1:]:
2217  r.draw()
2218 
2219  for addl in self._ratioAdditional:
2220  addl.Draw("same")
2221 
2222  frame.redrawAxis()
2223  self._frame = frame # keep the frame in memory for sure
2224 

References RunHistogramManager._histograms, plotting.Plot._histograms, plotting._mergeBinLabelsX(), plotting._mergeBinLabelsY(), plotting.Plot._normalize(), plotting._th1IncludeOnlyBins(), HistoData.getName(), trklet::MemoryBase.getName(), emtf::Node.getName(), EcalLogicID.getName(), PCaloHit.getName(), trklet::ProcessBase.getName(), CocoaMaterialElementary.getName(), ecaldqm::DBReaderWorker.getName(), ParticleFlux.getName(), ecaldqm::DBWriterWorker.getName(), hcaldqm::mapper::Mapper.getName(), FittedEntry.getName(), TkOfflineVariables.getName(), FieldHandlerBase< TOutput >.getName(), hcaldqm::mapper::HashMapper.getName(), PassiveHit.getName(), TrackingRecHitAlgorithm.getName(), AnyMVAEstimatorRun2Base.getName(), jsoncollector::JsonMonitorable.getName(), QCriterion.getName(), CSGAction.getName(), L1TUtmScale.getName(), MVAVariableManager< ParticleType >.getName(), DTTPGLutFile.getName(), L1TUtmCondition.getName(), L1TriggerLutFile.getName(), L1TUtmAlgorithm.getName(), fastsim::InteractionModel.getName(), L1MuGMTReg.getName(), GenericMVAComputer::TaggingVariableIterator< Iter_t >::Value.getName(), pos::PixelPortcardMap.getName(), GEMStation.getName(), PhysicsTools::Variable::Value.getName(), RPCAMCLink.getName(), RPCDCCLink.getName(), ecaldqm::DQWorker.getName(), L1TUtmCut.getName(), L1TUtmObject.getName(), L1TUtmTriggerMenu.getName(), edm::ELslProxy< ELgen >.getName(), L1MuGMTRegMMConfig.getName(), PhysicsTools::MVAModuleHelper< Record, Object, Filler >::Value.getName(), cscdqm::HistoDef.getName(), FourVectorHLT::PathInfo.getName(), jsoncollector::DataPoint.getName(), RPCLBLink.getName(), PhysicsTools::Variable.getName(), edm::ELseverityLevel.getName(), dqm::impl::MonitorElement.getName(), L1MuGMTRegSortRankOffset.getName(), L1MuGMTRegCDLConfig.getName(), cscdqm::CSCHistoDef.getName(), plotting.PlotEmpty.getName(), plotting.Plot.getName(), plotting.Plot.isTGraph2D(), and edm.print().

◆ drawRatioUncertainty()

def plotting.Plot.drawRatioUncertainty (   self)
Return true if the ratio uncertainty should be drawn

Definition at line 1870 of file plotting.py.

1870  def drawRatioUncertainty(self):
1871  """Return true if the ratio uncertainty should be drawn"""
1872  return self._ratioUncertainty
1873 

◆ getName()

def plotting.Plot.getName (   self)

◆ getNumberOfHistograms()

def plotting.Plot.getNumberOfHistograms (   self)
Return number of existing histograms.

Definition at line 1843 of file plotting.py.

1843  def getNumberOfHistograms(self):
1844  """Return number of existing histograms."""
1845  return len([h for h in self._histograms if h is not None])
1846 

References RunHistogramManager._histograms, and plotting.Plot._histograms.

Referenced by plotting.Plot.isEmpty().

◆ isEmpty()

def plotting.Plot.isEmpty (   self)
Return true if there are no histograms created for the plot

Definition at line 1847 of file plotting.py.

1847  def isEmpty(self):
1848  """Return true if there are no histograms created for the plot"""
1849  return self.getNumberOfHistograms() == 0
1850 

References plotting.PlotEmpty.getNumberOfHistograms(), and plotting.Plot.getNumberOfHistograms().

Referenced by plotting.Plot.clone().

◆ isRatio()

def plotting.Plot.isRatio (   self,
  ratio 
)

Definition at line 1857 of file plotting.py.

1857  def isRatio(self, ratio):
1858  if self._ratio is None:
1859  return ratio
1860  return ratio and self._ratio
1861 

◆ isTGraph2D()

def plotting.Plot.isTGraph2D (   self)

Definition at line 1851 of file plotting.py.

1851  def isTGraph2D(self):
1852  for h in self._histograms:
1853  if isinstance(h, ROOT.TGraph2D):
1854  return True
1855  return False
1856 

References RunHistogramManager._histograms, and plotting.Plot._histograms.

Referenced by plotting.Plot.draw().

◆ setProperties()

def plotting.Plot.setProperties (   self,
**  kwargs 
)

Definition at line 1830 of file plotting.py.

1830  def setProperties(self, **kwargs):
1831  for name, value in six.iteritems(kwargs):
1832  if not hasattr(self, "_"+name):
1833  raise Exception("No attribute '%s'" % name)
1834  setattr(self, "_"+name, value)
1835 

Member Data Documentation

◆ _forLegend

plotting.Plot._forLegend
private

Definition at line 2238 of file plotting.py.

◆ _frame

plotting.Plot._frame
private

Definition at line 2223 of file plotting.py.

◆ _histograms

plotting.Plot._histograms
private

◆ _mainAdditional

plotting.Plot._mainAdditional
private

Definition at line 2093 of file plotting.py.

◆ _name

plotting.Plot._name
private

◆ _ratioAdditional

plotting.Plot._ratioAdditional
private

Definition at line 2094 of file plotting.py.

◆ _ratios

plotting.Plot._ratios
private

Definition at line 2097 of file plotting.py.

◆ _tmp_histos

plotting.Plot._tmp_histos
private

Definition at line 2057 of file plotting.py.

◆ _xtitle

plotting.Plot._xtitle
private

Definition at line 2161 of file plotting.py.

◆ _ytitle

plotting.Plot._ytitle
private

Definition at line 2171 of file plotting.py.

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
plotting._mergeBinLabelsX
def _mergeBinLabelsX(histos)
Definition: plotting.py:706
plotting._th2RemoveEmptyBins
def _th2RemoveEmptyBins(histos, xbinlabels, ybinlabels)
Definition: plotting.py:646
plotting._calculateRatios
def _calculateRatios(histos, ratioUncertainty=False)
Definition: plotting.py:149
ntuplePlotting.draw
def draw(name, histos, styles=_defaultStyles, legendLabels=[], **kwargs)
Definition: ntuplePlotting.py:25
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
plotting._findBounds
def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None)
Definition: plotting.py:458
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
plotting._th1IncludeOnlyBins
def _th1IncludeOnlyBins(histos, xbinlabels)
Definition: plotting.py:743
getName
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:235
str
#define str(s)
Definition: TestProcessor.cc:48
plotting._th1RemoveEmptyBins
def _th1RemoveEmptyBins(histos, xbinlabels)
Definition: plotting.py:606
style
Definition: style.py:1
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
mps_setup.append
append
Definition: mps_setup.py:85
plotting._mergeBinLabelsY
def _mergeBinLabelsY(histos)
Definition: plotting.py:709
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:38
plotting._getOrCreateObject
def _getOrCreateObject(tdirectory, nameOrCreator)
Definition: plotting.py:58
format
plotting._findBoundsY
def _findBoundsY(th1s, ylog, ymin=None, ymax=None, coverage=None, coverageRange=None)
Definition: plotting.py:526
genParticles_cff.map
map
Definition: genParticles_cff.py:11