CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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__
 
def append
 
def clear
 
def create
 
def draw
 
def getName
 
def getPlot
 
def getPlots
 
def onlyForPileup
 
def remove
 
def setProperties
 

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 2251 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 2253 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__()
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)
2291  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 2481 of file plotting.py.

References GeometryComparisonPlotter._legend.

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

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

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, WValidation._name, DrellYanValidation._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, and plotting.PlotGroup._save().

Referenced by plotting.PlotGroup.draw().

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

References plotting.PlotGroup._ratioFactor.

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

2478  def _modifyPadForRatio(self, pad):
2479  """Internal method to set divide a pad to two for ratio plots"""
2480  _modifyPadForRatio(pad, self._ratioFactor)
def plotting.PlotGroup._save (   self,
  canvas,
  saveFormat,
  prefix = None,
  postfix = None,
  single = False,
  directory = "" 
)
private

Definition at line 2497 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, TrackingRecHitAlgorithm._name, Logger._name, hcaldqm::DQModule._name, citk::IsolationConeDefinitionBase._name, WValidation._name, DrellYanValidation._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().

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

Definition at line 2314 of file plotting.py.

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

2315  def append(self, plot):
2316  self._plots.append(plot)
def plotting.PlotGroup.clear (   self)

Definition at line 2311 of file plotting.py.

References plotting.PlotGroup._plots.

2312  def clear(self):
2313  self._plots = []
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)

Definition at line 2327 of file plotting.py.

References plotting.PlotGroup._plots.

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)
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.

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, WValidation._name, DrellYanValidation._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 SiStripPI.max.

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  if plot._legend:
2387  # Setup legend
2388  canvas.cd()
2389  if len(self._plots) <= 4:
2390  lx1 = 0.2
2391  lx2 = 0.9
2392  ly1 = 0.48
2393  ly2 = 0.53
2394  else:
2395  lx1 = 0.1
2396  lx2 = 0.9
2397  ly1 = 0.64
2398  ly2 = 0.67
2399  if self._legendDx is not None:
2400  lx1 += self._legendDx
2401  lx2 += self._legendDx
2402  if self._legendDy is not None:
2403  ly1 += self._legendDy
2404  ly2 += self._legendDy
2405  if self._legendDw is not None:
2406  lx2 += self._legendDw
2407  if self._legendDh is not None:
2408  ly1 -= self._legendDh
2409  plot = max(self._plots, key=lambda p: p.getNumberOfHistograms())
2410  denomUnc = sum([p.drawRatioUncertainty() for p in self._plots]) > 0
2411  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2,
2412  denomUncertainty=(ratio and denomUnc))
2413 
2414  return self._save(canvas, saveFormat, prefix=prefix, directory=directory)
def _createCanvas
Definition: plotting.py:109
def plotting.PlotGroup.getName (   self)

Definition at line 2298 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, TrackingRecHitAlgorithm._name, Logger._name, hcaldqm::DQModule._name, citk::IsolationConeDefinitionBase._name, WValidation._name, DrellYanValidation._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.

2299  def getName(self):
2300  return self._name
def plotting.PlotGroup.getPlot (   self,
  name 
)

Definition at line 2317 of file plotting.py.

References plotting.PlotGroup._plots.

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)
def plotting.PlotGroup.getPlots (   self)

Definition at line 2301 of file plotting.py.

References plotting.PlotGroup._plots.

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

Definition at line 2323 of file plotting.py.

References plotting.PlotFolder._onlyForPileup.

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

Definition at line 2304 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, TrackingRecHitAlgorithm._name, Logger._name, hcaldqm::DQModule._name, citk::IsolationConeDefinitionBase._name, WValidation._name, DrellYanValidation._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, and plotting.PlotGroup._plots.

2305  def remove(self, name):
2306  for i, plot in enumerate(self._plots):
2307  if plot.getName() == name:
2308  del self._plots[i]
2309  return
2310  raise Exception("Did not find Plot '%s' from PlotGroup '%s'" % (name, self._name))
def plotting.PlotGroup.setProperties (   self,
  kwargs 
)

Definition at line 2292 of file plotting.py.

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

Member Data Documentation

plotting.PlotGroup._name
private

Definition at line 2272 of file plotting.py.

Referenced by trackingPlots.TimePerEventPlot.__str__(), trackingPlots.TimePerTrackPlot.__str__(), trackingPlots.TimePerEventPlot._create(), plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._save(), trackingPlots.TimePerTrackPlot.create(), 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 2273 of file plotting.py.

Referenced by plotting.PlotGroup._drawSeparate(), plotting.Plotter.appendTable(), plotting.PlotGroup.clear(), plotting.Plotter.clear(), trackingPlots.TrackingSeedingLayerTable.create(), plotting.PlotGroup.create(), trackingPlots.TrackingSeedingLayerTable.draw(), 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 2290 of file plotting.py.

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