test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
plotting.PlotGroup Class Reference

Public Member Functions

def __init__
 
def append
 
def create
 
def draw
 
def getName
 
def getPlot
 
def getPlots
 
def onlyForPileup
 
def remove
 

Private Member Functions

def _createLegend
 
def _drawSeparate
 
def _modifyPadForRatio
 
def _save
 

Private Attributes

 _name
 
 _plots
 
 _ratioFactor
 

Detailed Description

Group of plots, results a TCanvas

Definition at line 1542 of file plotting.py.

Constructor & Destructor Documentation

def plotting.PlotGroup.__init__ (   self,
  name,
  plots,
  kwargs 
)
Constructor.

Arguments:
name  -- String for name of the TCanvas, used also as the basename of the picture files
plots -- List of Plot objects

Keyword arguments:
ncols    -- Number of columns (default 2)
legendDx -- Float for moving TLegend in x direction (default None)
legendDy -- Float for moving TLegend in y direction (default None)
legendDw -- Float for changing TLegend width (default None)
legendDh -- Float for changing TLegend height (default None)
legend   -- Bool for disabling legend (default True for legend being enabled)
overrideLegendLabels -- List of strings for legend labels, if given, these are used instead of the ones coming from Plotter (default None)
onlyForPileup  -- Plots this group only for pileup samples

Definition at line 1544 of file plotting.py.

1545  def __init__(self, name, plots, **kwargs):
1546  """Constructor.
1547 
1548  Arguments:
1549  name -- String for name of the TCanvas, used also as the basename of the picture files
1550  plots -- List of Plot objects
1551 
1552  Keyword arguments:
1553  ncols -- Number of columns (default 2)
1554  legendDx -- Float for moving TLegend in x direction (default None)
1555  legendDy -- Float for moving TLegend in y direction (default None)
1556  legendDw -- Float for changing TLegend width (default None)
1557  legendDh -- Float for changing TLegend height (default None)
1558  legend -- Bool for disabling legend (default True for legend being enabled)
1559  overrideLegendLabels -- List of strings for legend labels, if given, these are used instead of the ones coming from Plotter (default None)
1560  onlyForPileup -- Plots this group only for pileup samples
1561  """
1562  self._name = name
1563  self._plots = plots
1564 
1565  def _set(attr, default):
1566  setattr(self, "_"+attr, kwargs.get(attr, default))
1567 
1568  _set("ncols", 2)
1569 
1570  _set("legendDx", None)
1571  _set("legendDy", None)
1572  _set("legendDw", None)
1573  _set("legendDh", None)
1574  _set("legend", True)
1575 
1576  _set("overrideLegendLabels", None)
1577 
1578  _set("onlyForPileup", False)
1580  self._ratioFactor = 1.25

Member Function Documentation

def plotting.PlotGroup._createLegend (   self,
  plot,
  legendLabels,
  lx1,
  ly1,
  lx2,
  ly2,
  textSize = 0.016,
  denomUncertainty = True 
)
private

Definition at line 1781 of file plotting.py.

References GeometryComparisonPlotter._legend.

Referenced by plotting.PlotGroup._drawSeparate(), and plotting.PlotGroup.draw().

1782  def _createLegend(self, plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.016, denomUncertainty=True):
1783  if not self._legend:
1784  return None
1785 
1786  l = ROOT.TLegend(lx1, ly1, lx2, ly2)
1787  l.SetTextSize(textSize)
1788  l.SetLineColor(1)
1789  l.SetLineWidth(1)
1790  l.SetLineStyle(1)
1791  l.SetFillColor(0)
1792  l.SetMargin(0.07)
1793 
1794  plot.addToLegend(l, legendLabels, denomUncertainty)
1795  l.Draw()
1796  return l
def plotting.PlotGroup._drawSeparate (   self,
  legendLabels,
  prefix,
  saveFormat,
  ratio 
)
private
Internal method to do the drawing to separate files per Plot instead of a file per PlotGroup

Definition at line 1693 of file plotting.py.

References plotting._createCanvas(), plotting.PlotGroup._createLegend(), plotting.PlotGroup._modifyPadForRatio(), FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, L1TMuon::PtAssignmentUnit._name, L1TMuon::PtRefinementUnit._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, Logger._name, hcaldqm::DQModule._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, ElectronMVAEstimatorRun2Spring15Trig._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, plotting.Subtract._name, plotting.FakeDuplicate._name, plotting.AggregateBins._name, Vispa.Views.PropertyView.Property._name, plotting.AggregateHistos._name, SequenceTypes.SequencePlaceholder._name, plotting.ROC._name, plotting.Plot._name, plotting.PlotGroup._name, plotting.PlotGroup._plots, plotting.PlotGroup._ratioFactor, and plotting.PlotGroup._save().

Referenced by plotting.PlotGroup.draw().

1694  def _drawSeparate(self, legendLabels, prefix, saveFormat, ratio):
1695  """Internal method to do the drawing to separate files per Plot instead of a file per PlotGroup"""
1696  width = 500
1697  height = 500
1698  if ratio:
1699  height = int(height*self._ratioFactor)
1700 
1701  canvas = _createCanvas(self._name+"Single", width, height)
1702  # from TDRStyle
1703  canvas.SetTopMargin(0.05)
1704  canvas.SetBottomMargin(0.13)
1705  canvas.SetLeftMargin(0.16)
1706  canvas.SetRightMargin(0.05)
1707 
1708  lx1def = 0.6
1709  lx2def = 0.95
1710  ly1def = 0.85
1711  ly2def = 0.95
1712 
1713  ret = []
1714 
1715  for plot in self._plots:
1716  if plot.isEmpty():
1717  continue
1718 
1719  if ratio:
1720  canvas.cd()
1721  self._modifyPadForRatio(canvas)
1722 
1723  # Draw plot to canvas
1724  canvas.cd()
1725  plot.draw(canvas, ratio, self._ratioFactor, 1)
1726 
1727 
1728  # Setup legend
1729  lx1 = lx1def
1730  lx2 = lx2def
1731  ly1 = ly1def
1732  ly2 = ly2def
1733 
1734  if plot._legendDx is not None:
1735  lx1 += plot._legendDx
1736  lx2 += plot._legendDx
1737  if plot._legendDy is not None:
1738  ly1 += plot._legendDy
1739  ly2 += plot._legendDy
1740  if plot._legendDw is not None:
1741  lx2 += plot._legendDw
1742  if plot._legendDh is not None:
1743  ly1 -= plot._legendDh
1744 
1745  canvas.cd()
1746  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.03,
1747  denomUncertainty=(ratio and plot.drawRatioUncertainty))
1748 
1749  ret.extend(self._save(canvas, saveFormat, prefix=prefix, postfix="_"+plot.getName(), single=True))
1750  return ret
def _createCanvas
Definition: plotting.py:65
def plotting.PlotGroup._modifyPadForRatio (   self,
  pad 
)
private
Internal method to set divide a pad to two for ratio plots

Definition at line 1751 of file plotting.py.

References plotting.PlotGroup._ratioFactor.

Referenced by plotting.PlotGroup._drawSeparate(), and plotting.PlotGroup.draw().

1752  def _modifyPadForRatio(self, pad):
1753  """Internal method to set divide a pad to two for ratio plots"""
1754  pad.Divide(1, 2)
1755 
1756  divisionPoint = 1-1/self._ratioFactor
1757 
1758  topMargin = pad.GetTopMargin()
1759  bottomMargin = pad.GetBottomMargin()
1760  divisionPoint += (1-divisionPoint)*bottomMargin # correct for (almost-)zeroing bottom margin of pad1
1761  divisionPointForPad1 = 1-( (1-divisionPoint) / (1-0.02) ) # then correct for the non-zero bottom margin, but for pad1 only
1762 
1763  # Set the lower point of the upper pad to divisionPoint
1764  pad1 = pad.cd(1)
1765  yup = 1.0
1766  ylow = divisionPointForPad1
1767  xup = 1.0
1768  xlow = 0.0
1769  pad1.SetPad(xlow, ylow, xup, yup)
1770  pad1.SetFillStyle(4000) # transparent
1771  pad1.SetBottomMargin(0.02) # need some bottom margin here for eps/pdf output (at least in ROOT 5.34)
1772 
1773  # Set the upper point of the lower pad to divisionPoint
1774  pad2 = pad.cd(2)
1775  yup = divisionPoint
1776  ylow = 0.0
1777  pad2.SetPad(xlow, ylow, xup, yup)
1778  pad2.SetFillStyle(4000) # transparent
1779  pad2.SetTopMargin(0.0)
1780  pad2.SetBottomMargin(bottomMargin/(self._ratioFactor*divisionPoint))
def plotting.PlotGroup._save (   self,
  canvas,
  saveFormat,
  prefix = None,
  postfix = None,
  single = False 
)
private

Definition at line 1797 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, L1TMuon::PtAssignmentUnit._name, L1TMuon::PtRefinementUnit._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, Logger._name, hcaldqm::DQModule._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15Trig._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, plotting.Subtract._name, plotting.FakeDuplicate._name, plotting.AggregateBins._name, Vispa.Views.PropertyView.Property._name, plotting.AggregateHistos._name, SequenceTypes.SequencePlaceholder._name, plotting.ROC._name, plotting.Plot._name, and plotting.PlotGroup._name.

Referenced by plotting.PlotGroup._drawSeparate(), and plotting.PlotGroup.draw().

1798  def _save(self, canvas, saveFormat, prefix=None, postfix=None, single=False):
1799  # Save the canvas to file and clear
1800  name = self._name
1801  if prefix is not None:
1802  name = prefix+name
1803  if postfix is not None:
1804  name = name+postfix
1805 
1806  if not verbose: # silence saved file printout
1807  backup = ROOT.gErrorIgnoreLevel
1808  ROOT.gErrorIgnoreLevel = ROOT.kWarning
1809  canvas.SaveAs(name+saveFormat)
1810  if not verbose:
1811  ROOT.gErrorIgnoreLevel = backup
1812 
1813  if single:
1814  canvas.Clear()
1815  canvas.SetLogx(False)
1816  canvas.SetLogy(False)
1817  else:
1818  canvas.Clear("D") # keep subpads
1819 
1820  return [name+saveFormat]
def plotting.PlotGroup.append (   self,
  plot 
)

Definition at line 1594 of file plotting.py.

Referenced by diclist.diclist.add(), and BeautifulSoup.Tag.setString().

1595  def append(self, plot):
1596  self._plots.append(plot)
def plotting.PlotGroup.create (   self,
  tdirectories,
  requireAllHistograms = False 
)
Create histograms from a list of TDirectories.

Arguments:
tdirectories         -- List of TDirectory objects
requireAllHistograms -- If True, a plot is produced if histograms from all files are present (default: False)

Definition at line 1607 of file plotting.py.

References plotting.PlotGroup._plots.

1608  def create(self, tdirectories, requireAllHistograms=False):
1609  """Create histograms from a list of TDirectories.
1610 
1611  Arguments:
1612  tdirectories -- List of TDirectory objects
1613  requireAllHistograms -- If True, a plot is produced if histograms from all files are present (default: False)
1614  """
1615  for plot in self._plots:
1616  plot.create(tdirectories, requireAllHistograms)
def plotting.PlotGroup.draw (   self,
  legendLabels,
  prefix = None,
  separate = False,
  saveFormat = ".pdf",
  ratio = False 
)
Draw the histograms using values for a given algorithm.

Arguments:
legendLabels  -- List of strings for legend labels (corresponding to the tdirectories in create())
prefix        -- Optional string for file name prefix (default None)
separate      -- Save the plots of a group to separate files instead of a file per group (default False)
saveFormat   -- String specifying the plot format (default '.pdf')
ratio        -- Add ratio to the plot (default False)

Definition at line 1617 of file plotting.py.

References plotting._createCanvas(), plotting.PlotGroup._createLegend(), plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._modifyPadForRatio(), FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, L1TMuon::PtRefinementUnit._name, L1TMuon::PtAssignmentUnit._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, Logger._name, hcaldqm::DQModule._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15Trig._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, plotting.Subtract._name, plotting.FakeDuplicate._name, plotting.AggregateBins._name, Vispa.Views.PropertyView.Property._name, plotting.AggregateHistos._name, SequenceTypes.SequencePlaceholder._name, plotting.ROC._name, plotting.Plot._name, plotting.PlotGroup._name, plotting.PlotGroup._plots, plotting.PlotGroup._ratioFactor, plotting.PlotGroup._save(), and bookConverter.max.

1618  def draw(self, legendLabels, prefix=None, separate=False, saveFormat=".pdf", ratio=False):
1619  """Draw the histograms using values for a given algorithm.
1620 
1621  Arguments:
1622  legendLabels -- List of strings for legend labels (corresponding to the tdirectories in create())
1623  prefix -- Optional string for file name prefix (default None)
1624  separate -- Save the plots of a group to separate files instead of a file per group (default False)
1625  saveFormat -- String specifying the plot format (default '.pdf')
1626  ratio -- Add ratio to the plot (default False)
1627  """
1628 
1629  if self._overrideLegendLabels is not None:
1630  legendLabels = self._overrideLegendLabels
1631 
1632  # Do not draw the group if it would be empty
1633  onlyEmptyPlots = True
1634  for plot in self._plots:
1635  if not plot.isEmpty():
1636  onlyEmptyPlots = False
1637  break
1638  if onlyEmptyPlots:
1639  return []
1640 
1641  if separate:
1642  return self._drawSeparate(legendLabels, prefix, saveFormat, ratio)
1643 
1644  cwidth = 500*self._ncols
1645  nrows = int((len(self._plots)+self._ncols-1)/self._ncols) # this should work also for odd n
1646  cheight = 500 * nrows
1647 
1648  if ratio:
1649  cheight = int(cheight*self._ratioFactor)
1650 
1651  canvas = _createCanvas(self._name, cwidth, cheight)
1652 
1653  canvas.Divide(self._ncols, nrows)
1654  if ratio:
1655  for i in xrange(0, len(self._plots)):
1656  pad = canvas.cd(i+1)
1657  self._modifyPadForRatio(pad)
1658 
1659  # Draw plots to canvas
1660  for i, plot in enumerate(self._plots):
1661  pad = canvas.cd(i+1)
1662  if not plot.isEmpty():
1663  plot.draw(pad, ratio, self._ratioFactor, nrows)
1664 
1665  # Setup legend
1666  canvas.cd()
1667  if len(self._plots) <= 4:
1668  lx1 = 0.2
1669  lx2 = 0.9
1670  ly1 = 0.48
1671  ly2 = 0.53
1672  else:
1673  lx1 = 0.1
1674  lx2 = 0.9
1675  ly1 = 0.64
1676  ly2 = 0.67
1677  if self._legendDx is not None:
1678  lx1 += self._legendDx
1679  lx2 += self._legendDx
1680  if self._legendDy is not None:
1681  ly1 += self._legendDy
1682  ly2 += self._legendDy
1683  if self._legendDw is not None:
1684  lx2 += self._legendDw
1685  if self._legendDh is not None:
1686  ly1 -= self._legendDh
1687  plot = max(self._plots, key=lambda p: p.getNumberOfHistograms())
1688  denomUnc = sum([p.drawRatioUncertainty() for p in self._plots]) > 0
1689  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2,
1690  denomUncertainty=(ratio and denomUnc))
1691 
1692  return self._save(canvas, saveFormat, prefix=prefix)
def _createCanvas
Definition: plotting.py:65
def plotting.PlotGroup.getName (   self)

Definition at line 1581 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, L1TMuon::PtAssignmentUnit._name, L1TMuon::PtRefinementUnit._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, Logger._name, hcaldqm::DQModule._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15Trig._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, plotting.Subtract._name, plotting.FakeDuplicate._name, plotting.AggregateBins._name, Vispa.Views.PropertyView.Property._name, plotting.AggregateHistos._name, SequenceTypes.SequencePlaceholder._name, plotting.ROC._name, plotting.Plot._name, and plotting.PlotGroup._name.

1582  def getName(self):
1583  return self._name
def plotting.PlotGroup.getPlot (   self,
  name 
)

Definition at line 1597 of file plotting.py.

References plotting.PlotGroup._plots.

1598  def getPlot(self, name):
1599  for plot in self._plots:
1600  if plot.getName() == name:
1601  return plot
1602  raise Exception("No Plot named '%s'" % name)
def plotting.PlotGroup.getPlots (   self)

Definition at line 1584 of file plotting.py.

References plotting.PlotGroup._plots.

1585  def getPlots(self):
1586  return self._plots
def plotting.PlotGroup.onlyForPileup (   self)
Return True if the PlotGroup is intended only for pileup samples

Definition at line 1603 of file plotting.py.

References plotting.PlotFolder._onlyForPileup.

1604  def onlyForPileup(self):
1605  """Return True if the PlotGroup is intended only for pileup samples"""
1606  return self._onlyForPileup
def plotting.PlotGroup.remove (   self,
  name 
)

Definition at line 1587 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, L1TMuon::PtAssignmentUnit._name, L1TMuon::PtRefinementUnit._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, Logger._name, hcaldqm::DQModule._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15Trig._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, plotting.Subtract._name, plotting.FakeDuplicate._name, plotting.AggregateBins._name, Vispa.Views.PropertyView.Property._name, plotting.AggregateHistos._name, SequenceTypes.SequencePlaceholder._name, plotting.ROC._name, plotting.Plot._name, plotting.PlotGroup._name, and plotting.PlotGroup._plots.

1588  def remove(self, name):
1589  for i, plot in enumerate(self._plots):
1590  if plot.getName() == name:
1591  del self._plots[i]
1592  return
1593  raise Exception("Did not find Plot '%s' from PlotGroup '%s'" % (name, self._name))

Member Data Documentation

plotting.PlotGroup._name
private

Definition at line 1561 of file plotting.py.

Referenced by plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._save(), plotting.PlotGroup.draw(), plotting.PlotGroup.getName(), plotting.PlotterFolder.getName(), plotting.PlotterItem.getName(), plotting.PlotterFolder.getSelectionNameIterator(), validation.SimpleSample.name(), trackingPlots.Iteration.name(), plotting.PlotterItem.readDirs(), and plotting.PlotGroup.remove().

plotting.PlotGroup._plots
private

Definition at line 1562 of file plotting.py.

Referenced by plotting.PlotGroup._drawSeparate(), plotting.Plotter.appendTable(), plotting.Plotter.clear(), plotting.PlotGroup.create(), plotting.PlotGroup.draw(), plotting.PlotGroup.getPlot(), plotting.Plotter.getPlotFolder(), plotting.Plotter.getPlotFolderNames(), plotting.Plotter.getPlotFolders(), plotting.PlotGroup.getPlots(), plotting.Plotter.readDirs(), and plotting.PlotGroup.remove().

plotting.PlotGroup._ratioFactor
private

Definition at line 1579 of file plotting.py.

Referenced by plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._modifyPadForRatio(), and plotting.PlotGroup.draw().