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 create
 
def draw
 

Private Member Functions

def _createLegend
 
def _drawSeparate
 
def _save
 

Private Attributes

 _canvas
 
 _canvasSingle
 
 _name
 
 _plots
 

Detailed Description

Group of plots, results a TCanvas

Definition at line 566 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:
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)
overrideLegendLabels -- List of strings for legend labels, if given, these are used instead of the ones coming from Plotter (default None)

Definition at line 568 of file plotting.py.

569  def __init__(self, name, plots, **kwargs):
570  """Constructor.
571 
572  Arguments:
573  name -- String for name of the TCanvas, used also as the basename of the picture files
574  plots -- List of Plot objects
575 
576  Keyword arguments:
577  legendDx -- Float for moving TLegend in x direction (default None)
578  legendDy -- Float for moving TLegend in y direction (default None)
579  legendDw -- Float for changing TLegend width (default None)
580  legendDh -- Float for changing TLegend height (default None)
581  overrideLegendLabels -- List of strings for legend labels, if given, these are used instead of the ones coming from Plotter (default None)
582  """
583  self._name = name
584  self._plots = plots
585 
586  if len(self._plots) <= 2:
587  self._canvas = ROOT.TCanvas(self._name, self._name, 1000, 500)
588  elif len(self._plots) <= 4:
589  self._canvas = ROOT.TCanvas(self._name, self._name, 1000, 1050)
590  elif len(self._plots) <= 6:
591  self._canvas = ROOT.TCanvas(self._name, self._name, 1000, 1400)
592  elif len(self._plots) <= 8:
593  self._canvas = ROOT.TCanvas(self._name, self._name, 1000, 1750)
594  elif len(self._plots) <= 10:
595  self._canvas = ROOT.TCanvas(self._name, self._name, 1000, 2100)
596  else:
597  self._canvas = ROOT.TCanvas(self._name, self._name, 1000, 2450)
599  self._canvasSingle = ROOT.TCanvas(self._name+"Single", self._name, 500, 500)
600  # from TDRStyle
601  self._canvasSingle.SetTopMargin(0.05)
602  self._canvasSingle.SetBottomMargin(0.13)
603  self._canvasSingle.SetLeftMargin(0.16)
604  self._canvasSingle.SetRightMargin(0.05)
605 
606 
607  def _set(attr, default):
608  setattr(self, "_"+attr, kwargs.get(attr, default))
609 
610  _set("legendDx", None)
611  _set("legendDy", None)
612  _set("legendDw", None)
613  _set("legendDh", None)
614 
615  _set("overrideLegendLabels", None)

Member Function Documentation

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

Definition at line 707 of file plotting.py.

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

708  def _createLegend(self, plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.016):
709  l = ROOT.TLegend(lx1, ly1, lx2, ly2)
710  l.SetTextSize(textSize)
711  l.SetLineColor(1)
712  l.SetLineWidth(1)
713  l.SetLineStyle(1)
714  l.SetFillColor(0)
715  l.SetMargin(0.07)
716 
717  plot.addToLegend(l, legendLabels)
718  l.Draw()
719  return l
def plotting.PlotGroup._drawSeparate (   self,
  algo,
  legendLabels,
  prefix,
  saveFormat 
)
private

Definition at line 672 of file plotting.py.

References plotting.PlotGroup._canvasSingle, plotting.PlotGroup._createLegend(), plotting.PlotGroup._plots, and plotting.PlotGroup._save().

Referenced by plotting.PlotGroup.draw().

673  def _drawSeparate(self, algo, legendLabels, prefix, saveFormat):
674  lx1def = 0.6
675  lx2def = 0.95
676  ly1def = 0.85
677  ly2def = 0.95
678 
679  ret = []
680 
681  for plot in self._plots:
682  # Draw plot to canvas
683  self._canvasSingle.cd()
684  plot.draw(algo)
685 
686  # Setup legend
687  lx1 = lx1def
688  lx2 = lx2def
689  ly1 = ly1def
690  ly2 = ly2def
691 
692  if plot._legendDx is not None:
693  lx1 += plot._legendDx
694  lx2 += plot._legendDx
695  if plot._legendDy is not None:
696  ly1 += plot._legendDy
697  ly2 += plot._legendDy
698  if plot._legendDw is not None:
699  lx2 += plot._legendDw
700  if plot._legendDh is not None:
701  ly1 -= plot._legendDh
702 
703  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.03)
704 
705  ret.extend(self._save(self._canvasSingle, saveFormat, prefix=prefix, postfix="_"+plot.getName()))
706  return ret
def plotting.PlotGroup._save (   self,
  canvas,
  saveFormat,
  prefix = None,
  postfix = None 
)
private

Definition at line 720 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, plotting.FakeDuplicate._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, plotting.AggregateBins._name, plotting.AggregateHistos._name, HistoParams< TProfile2D >._name, plotting.Plot._name, Vispa.Views.PropertyView.Property._name, SequenceTypes.SequencePlaceholder._name, and plotting.PlotGroup._name.

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

721  def _save(self, canvas, saveFormat, prefix=None, postfix=None):
722  # Save the canvas to file and clear
723  name = self._name
724  if prefix is not None:
725  name = prefix+name
726  if postfix is not None:
727  name = name+postfix
728  canvas.SaveAs(name+saveFormat)
729  canvas.Clear()
730 
731  return [name+saveFormat]
732 
def plotting.PlotGroup.create (   self,
  tdirectories 
)
Create histograms from a list of TDirectories.

Definition at line 616 of file plotting.py.

References plotting.PlotGroup._plots.

617  def create(self, tdirectories):
618  """Create histograms from a list of TDirectories."""
619  for plot in self._plots:
620  plot.create(tdirectories)
def plotting.PlotGroup.draw (   self,
  algo,
  legendLabels,
  prefix = None,
  separate = False,
  saveFormat = ".pdf" 
)
Draw the histograms using values for a given algorithm.

Arguments:
algo          -- string for algorithm
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')

Definition at line 621 of file plotting.py.

References DQMIO2histo.DQMIO._canvas, plotting.PlotGroup._canvas, plotting.PlotGroup._createLegend(), plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._plots, plotting.PlotGroup._save(), and bookConverter.max.

622  def draw(self, algo, legendLabels, prefix=None, separate=False, saveFormat=".pdf"):
623  """Draw the histograms using values for a given algorithm.
624 
625  Arguments:
626  algo -- string for algorithm
627  legendLabels -- List of strings for legend labels (corresponding to the tdirectories in create())
628  prefix -- Optional string for file name prefix (default None)
629  separate -- Save the plots of a group to separate files instead of a file per group (default False)
630  saveFormat -- String specifying the plot format (default '.pdf')
631  """
632 
633  if self._overrideLegendLabels is not None:
634  legendLabels = self._overrideLegendLabels
635 
636  if separate:
637  return self._drawSeparate(algo, legendLabels, prefix, saveFormat)
638 
639  self._canvas.Divide(2, int((len(self._plots)+1)/2)) # this should work also for odd n
640 
641  # Draw plots to canvas
642  for i, plot in enumerate(self._plots):
643  self._canvas.cd(i+1)
644  plot.draw(algo)
645 
646  # Setup legend
647  self._canvas.cd()
648  if len(self._plots) <= 4:
649  lx1 = 0.2
650  lx2 = 0.9
651  ly1 = 0.48
652  ly2 = 0.53
653  else:
654  lx1 = 0.1
655  lx2 = 0.9
656  ly1 = 0.64
657  ly2 = 0.69
658  if self._legendDx is not None:
659  lx1 += self._legendDx
660  lx2 += self._legendDx
661  if self._legendDy is not None:
662  ly1 += self._legendDy
663  ly2 += self._legendDy
664  if self._legendDw is not None:
665  lx2 += self._legendDw
666  if self._legendDh is not None:
667  ly1 -= self._legendDh
668  plot = max(self._plots, key=lambda p: p.getNumberOfHistograms())
669  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2)
670 
671  return self._save(self._canvas, saveFormat, prefix=prefix)

Member Data Documentation

plotting.PlotGroup._canvas
private

Definition at line 586 of file plotting.py.

Referenced by plotting.PlotGroup.draw().

plotting.PlotGroup._canvasSingle
private

Definition at line 598 of file plotting.py.

Referenced by plotting.PlotGroup._drawSeparate().

plotting.PlotGroup._name
private

Definition at line 582 of file plotting.py.

Referenced by plotting.PlotGroup._save().

plotting.PlotGroup._plots
private

Definition at line 583 of file plotting.py.

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