CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
plotting.PlotGroup Class Reference
Inheritance diagram for plotting.PlotGroup:
plotting.PlotOnSideGroup

Public Member Functions

def __init__ (self, name, plots, **kwargs)
 
def append (self, plot)
 
def clear (self)
 
def create (self, tdirectoryNEvents, requireAllHistograms=False)
 
def draw (self, legendLabels, prefix=None, separate=False, saveFormat=".pdf", ratio=True, directory="")
 
def getName (self)
 
def getPlot (self, name)
 
def getPlots (self)
 
def onlyForPileup (self)
 
def remove (self, name)
 
def setProperties (self, **kwargs)
 

Private Member Functions

def _createLegend (self, plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.016, denomUncertainty=True)
 
def _drawSeparate (self, legendLabels, prefix, saveFormat, ratio, directory)
 
def _modifyPadForRatio (self, pad)
 
def _save (self, canvas, saveFormat, prefix=None, postfix=None, single=False, directory="")
 

Private Attributes

 _name
 
 _plots
 
 _ratioFactor
 

Detailed Description

Group of plots, results a TCanvas

Definition at line 2251 of file plotting.py.

Constructor & Destructor Documentation

◆ __init__()

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 2253 of file plotting.py.

2253  def __init__(self, name, plots, **kwargs):
2254  """Constructor.
2255 
2256  Arguments:
2257  name -- String for name of the TCanvas, used also as the basename of the picture files
2258  plots -- List of Plot objects
2259 
2260  Keyword arguments:
2261  ncols -- Number of columns (default 2)
2262  legendDx -- Float for moving TLegend in x direction (default None)
2263  legendDy -- Float for moving TLegend in y direction (default None)
2264  legendDw -- Float for changing TLegend width (default None)
2265  legendDh -- Float for changing TLegend height (default None)
2266  legend -- Bool for disabling legend (default True for legend being enabled)
2267  overrideLegendLabels -- List of strings for legend labels, if given, these are used instead of the ones coming from Plotter (default None)
2268  onlyForPileup -- Plots this group only for pileup samples
2269  """
2270  super(PlotGroup, self).__init__()
2271 
2272  self._name = name
2273  self._plots = plots
2274 
2275  def _set(attr, default):
2276  setattr(self, "_"+attr, kwargs.get(attr, default))
2277 
2278  _set("ncols", 2)
2279 
2280  _set("legendDx", None)
2281  _set("legendDy", None)
2282  _set("legendDw", None)
2283  _set("legendDh", None)
2284  _set("legend", True)
2285 
2286  _set("overrideLegendLabels", None)
2287 
2288  _set("onlyForPileup", False)
2289 
2290  self._ratioFactor = 1.25
2291 

Member Function Documentation

◆ _createLegend()

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

Definition at line 2480 of file plotting.py.

2480  def _createLegend(self, plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.016, denomUncertainty=True):
2481  if not self._legend:
2482  return None
2483 
2484  l = ROOT.TLegend(lx1, ly1, lx2, ly2)
2485  l.SetTextSize(textSize)
2486  l.SetLineColor(1)
2487  l.SetLineWidth(1)
2488  l.SetLineStyle(1)
2489  l.SetFillColor(0)
2490  l.SetMargin(0.07)
2491 
2492  plot.addToLegend(l, legendLabels, denomUncertainty)
2493  l.Draw()
2494  return l
2495 

References GeometryComparisonPlotter._legend.

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

◆ _drawSeparate()

def plotting.PlotGroup._drawSeparate (   self,
  legendLabels,
  prefix,
  saveFormat,
  ratio,
  directory 
)
private
Internal method to do the drawing to separate files per Plot instead of a file per PlotGroup

Definition at line 2414 of file plotting.py.

2414  def _drawSeparate(self, legendLabels, prefix, saveFormat, ratio, directory):
2415  """Internal method to do the drawing to separate files per Plot instead of a file per PlotGroup"""
2416  width = 500
2417  height = 500
2418 
2419  lx1def = 0.6
2420  lx2def = 0.95
2421  ly1def = 0.85
2422  ly2def = 0.95
2423 
2424  ret = []
2425 
2426  for plot in self._plots:
2427  if plot.isEmpty():
2428  continue
2429 
2430  canvas = _createCanvas(self._name+"Single", width, height)
2431  canvasRatio = _createCanvas(self._name+"SingleRatio", width, int(height*self._ratioFactor))
2432 
2433  # from TDRStyle
2434  for c in [canvas, canvasRatio]:
2435  c.SetTopMargin(0.05)
2436  c.SetBottomMargin(0.13)
2437  c.SetLeftMargin(0.16)
2438  c.SetRightMargin(0.05)
2439 
2440  ratioForThisPlot = plot.isRatio(ratio)
2441  c = canvas
2442  if ratioForThisPlot:
2443  c = canvasRatio
2444  c.cd()
2445  self._modifyPadForRatio(c)
2446 
2447  # Draw plot to canvas
2448  c.cd()
2449  plot.draw(c, ratioForThisPlot, self._ratioFactor, 1)
2450 
2451  if plot._legend:
2452  # Setup legend
2453  lx1 = lx1def
2454  lx2 = lx2def
2455  ly1 = ly1def
2456  ly2 = ly2def
2457 
2458  if plot._legendDx is not None:
2459  lx1 += plot._legendDx
2460  lx2 += plot._legendDx
2461  if plot._legendDy is not None:
2462  ly1 += plot._legendDy
2463  ly2 += plot._legendDy
2464  if plot._legendDw is not None:
2465  lx2 += plot._legendDw
2466  if plot._legendDh is not None:
2467  ly1 -= plot._legendDh
2468 
2469  c.cd()
2470  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.03,
2471  denomUncertainty=(ratioForThisPlot and plot.drawRatioUncertainty))
2472 
2473  ret.extend(self._save(c, saveFormat, prefix=prefix, postfix="/"+plot.getName(), single=True, directory=directory))
2474  return ret
2475 

References plotting._createCanvas(), plotting.PlotGroup._createLegend(), plotting.PlotGroup._modifyPadForRatio(), 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, 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.PlotGroup._name, plotting.PlotGroup._plots, plotting.PlotGroup._ratioFactor, plotting.PlotGroup._save(), and createfilelist.int.

Referenced by plotting.PlotGroup.draw().

◆ _modifyPadForRatio()

def plotting.PlotGroup._modifyPadForRatio (   self,
  pad 
)
private
Internal method to set divide a pad to two for ratio plots

Definition at line 2476 of file plotting.py.

2476  def _modifyPadForRatio(self, pad):
2477  """Internal method to set divide a pad to two for ratio plots"""
2478  _modifyPadForRatio(pad, self._ratioFactor)
2479 

References plotting.PlotGroup._ratioFactor.

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

◆ _save()

def plotting.PlotGroup._save (   self,
  canvas,
  saveFormat,
  prefix = None,
  postfix = None,
  single = False,
  directory = "" 
)
private

Definition at line 2496 of file plotting.py.

2496  def _save(self, canvas, saveFormat, prefix=None, postfix=None, single=False, directory=""):
2497  # Save the canvas to file and clear
2498  name = self._name
2499  if not os.path.exists(directory+'/'+name):
2500  os.makedirs(directory+'/'+name)
2501  if prefix is not None:
2502  name = prefix+name
2503  if postfix is not None:
2504  name = name+postfix
2505  name = os.path.join(directory, name)
2506 
2507  if not verbose: # silence saved file printout
2508  backup = ROOT.gErrorIgnoreLevel
2509  ROOT.gErrorIgnoreLevel = ROOT.kWarning
2510  canvas.SaveAs(name+saveFormat)
2511  if not verbose:
2512  ROOT.gErrorIgnoreLevel = backup
2513 
2514  if single:
2515  canvas.Clear()
2516  canvas.SetLogx(False)
2517  canvas.SetLogy(False)
2518  else:
2519  canvas.Clear("D") # keep subpads
2520 
2521  return [name+saveFormat]
2522 

References 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, 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, and plotting.PlotGroup._name.

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

◆ append()

def plotting.PlotGroup.append (   self,
  plot 
)

Definition at line 2314 of file plotting.py.

2314  def append(self, plot):
2315  self._plots.append(plot)
2316 

References plotting.PlotGroup._plots.

Referenced by diclist.diclist.add().

◆ clear()

def plotting.PlotGroup.clear (   self)

Definition at line 2311 of file plotting.py.

2311  def clear(self):
2312  self._plots = []
2313 

References plotting.PlotGroup._plots.

◆ create()

def plotting.PlotGroup.create (   self,
  tdirectoryNEvents,
  requireAllHistograms = False 
)
Create histograms from a list of TDirectories.

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

Reimplemented in plotting.PlotOnSideGroup.

Definition at line 2327 of file plotting.py.

2327  def create(self, tdirectoryNEvents, requireAllHistograms=False):
2328  """Create histograms from a list of TDirectories.
2329 
2330  Arguments:
2331  tdirectoryNEvents -- List of (TDirectory, nevents) pairs
2332  requireAllHistograms -- If True, a plot is produced if histograms from all files are present (default: False)
2333  """
2334  for plot in self._plots:
2335  plot.create(tdirectoryNEvents, requireAllHistograms)
2336 

References plotting.PlotGroup._plots.

◆ draw()

def plotting.PlotGroup.draw (   self,
  legendLabels,
  prefix = None,
  separate = False,
  saveFormat = ".pdf",
  ratio = True,
  directory = "" 
)
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 True)
directory     -- Directory where to save the file (default "")

Definition at line 2337 of file plotting.py.

2337  def draw(self, legendLabels, prefix=None, separate=False, saveFormat=".pdf", ratio=True, directory=""):
2338  """Draw the histograms using values for a given algorithm.
2339 
2340  Arguments:
2341  legendLabels -- List of strings for legend labels (corresponding to the tdirectories in create())
2342  prefix -- Optional string for file name prefix (default None)
2343  separate -- Save the plots of a group to separate files instead of a file per group (default False)
2344  saveFormat -- String specifying the plot format (default '.pdf')
2345  ratio -- Add ratio to the plot (default True)
2346  directory -- Directory where to save the file (default "")
2347  """
2348 
2349  if self._overrideLegendLabels is not None:
2350  legendLabels = self._overrideLegendLabels
2351 
2352  # Do not draw the group if it would be empty
2353  onlyEmptyPlots = True
2354  for plot in self._plots:
2355  if not plot.isEmpty():
2356  onlyEmptyPlots = False
2357  break
2358  if onlyEmptyPlots:
2359  return []
2360 
2361  if separate:
2362  return self._drawSeparate(legendLabels, prefix, saveFormat, ratio, directory)
2363 
2364  cwidth = 500*self._ncols
2365  nrows = int((len(self._plots)+self._ncols-1)/self._ncols) # this should work also for odd n
2366  cheight = 500 * nrows
2367 
2368  if ratio:
2369  cheight = int(cheight*self._ratioFactor)
2370 
2371  canvas = _createCanvas(self._name, cwidth, cheight)
2372 
2373  canvas.Divide(self._ncols, nrows)
2374  if ratio:
2375  for i, plot in enumerate(self._plots):
2376  pad = canvas.cd(i+1)
2377  self._modifyPadForRatio(pad)
2378 
2379  # Draw plots to canvas
2380  for i, plot in enumerate(self._plots):
2381  pad = canvas.cd(i+1)
2382  if not plot.isEmpty():
2383  plot.draw(pad, ratio, self._ratioFactor, nrows)
2384 
2385  # Setup legend
2386  canvas.cd()
2387  if len(self._plots) <= 4:
2388  lx1 = 0.2
2389  lx2 = 0.9
2390  ly1 = 0.48
2391  ly2 = 0.53
2392  else:
2393  lx1 = 0.1
2394  lx2 = 0.9
2395  ly1 = 0.64
2396  ly2 = 0.67
2397  if self._legendDx is not None:
2398  lx1 += self._legendDx
2399  lx2 += self._legendDx
2400  if self._legendDy is not None:
2401  ly1 += self._legendDy
2402  ly2 += self._legendDy
2403  if self._legendDw is not None:
2404  lx2 += self._legendDw
2405  if self._legendDh is not None:
2406  ly1 -= self._legendDh
2407  plot = max(self._plots, key=lambda p: p.getNumberOfHistograms())
2408  denomUnc = sum([p.drawRatioUncertainty() for p in self._plots]) > 0
2409  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2,
2410  denomUncertainty=(ratio and denomUnc))
2411 
2412  return self._save(canvas, saveFormat, prefix=prefix, directory=directory)
2413 

References plotting._createCanvas(), plotting.PlotGroup._createLegend(), plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._modifyPadForRatio(), 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, 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.PlotGroup._name, plotting.PlotGroup._plots, plotting.PlotGroup._ratioFactor, plotting.PlotGroup._save(), createfilelist.int, and SiStripPI.max.

◆ getName()

def plotting.PlotGroup.getName (   self)

◆ getPlot()

def plotting.PlotGroup.getPlot (   self,
  name 
)

Definition at line 2317 of file plotting.py.

2317  def getPlot(self, name):
2318  for plot in self._plots:
2319  if plot.getName() == name:
2320  return plot
2321  raise Exception("No Plot named '%s'" % name)
2322 

References plotting.PlotGroup._plots.

◆ getPlots()

def plotting.PlotGroup.getPlots (   self)

Definition at line 2301 of file plotting.py.

2301  def getPlots(self):
2302  return self._plots
2303 

References plotting.PlotGroup._plots.

◆ onlyForPileup()

def plotting.PlotGroup.onlyForPileup (   self)
Return True if the PlotGroup is intended only for pileup samples

Definition at line 2323 of file plotting.py.

2323  def onlyForPileup(self):
2324  """Return True if the PlotGroup is intended only for pileup samples"""
2325  return self._onlyForPileup
2326 

References plotting.PlotFolder._onlyForPileup.

◆ remove()

def plotting.PlotGroup.remove (   self,
  name 
)

◆ setProperties()

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

Definition at line 2292 of file plotting.py.

2292  def setProperties(self, **kwargs):
2293  for name, value in kwargs.items():
2294  if not hasattr(self, "_"+name):
2295  raise Exception("No attribute '%s'" % name)
2296  setattr(self, "_"+name, value)
2297 

Member Data Documentation

◆ _name

plotting.PlotGroup._name
private

◆ _plots

plotting.PlotGroup._plots
private

◆ _ratioFactor

plotting.PlotGroup._ratioFactor
private
ntuplePlotting.draw
def draw(name, histos, styles=_defaultStyles, legendLabels=[], **kwargs)
Definition: ntuplePlotting.py:24
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
plotting._modifyPadForRatio
def _modifyPadForRatio(pad, ratioFactor)
Definition: plotting.py:119
plotting._createCanvas
def _createCanvas(name, width, height)
Definition: plotting.py:109
getName
TString getName(TString structure, int layer, TString geometry)
Definition: DMRtrends.cc:235
clear
void clear(HadCaloObj &c)
Definition: data.h:124
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
mps_setup.append
append
Definition: mps_setup.py:85
createfilelist.int
int
Definition: createfilelist.py:10
trackingPlots.onlyForPileup
onlyForPileup
Definition: trackingPlots.py:299
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:219