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

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

Member Function Documentation

◆ _createLegend()

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

Definition at line 2481 of file plotting.py.

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

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

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

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

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

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

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

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

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

References plotting.PlotGroup._plots.

Referenced by diclist.diclist.add().

◆ clear()

def plotting.PlotGroup.clear (   self)

Definition at line 2312 of file plotting.py.

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

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

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

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

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

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

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

References plotting.PlotGroup._plots.

◆ getPlots()

def plotting.PlotGroup.getPlots (   self)

Definition at line 2302 of file plotting.py.

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

References plotting.PlotGroup._plots.

◆ onlyForPileup()

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

Definition at line 2324 of file plotting.py.

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

References plotting.PlotFolder._onlyForPileup.

◆ remove()

def plotting.PlotGroup.remove (   self,
  name 
)

◆ setProperties()

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

Definition at line 2293 of file plotting.py.

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

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:25
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
plotting._modifyPadForRatio
def _modifyPadForRatio(pad, ratioFactor)
Definition: plotting.py:120
plotting._createCanvas
def _createCanvas(name, width, height)
Definition: plotting.py:110
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:300
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:219