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

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

Member Function Documentation

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

Definition at line 2475 of file plotting.py.

References GeometryComparisonPlotter._legend.

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

2475  def _createLegend(self, plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.016, denomUncertainty=True):
2476  if not self._legend:
2477  return None
2478 
2479  l = ROOT.TLegend(lx1, ly1, lx2, ly2)
2480  l.SetTextSize(textSize)
2481  l.SetLineColor(1)
2482  l.SetLineWidth(1)
2483  l.SetLineStyle(1)
2484  l.SetFillColor(0)
2485  l.SetMargin(0.07)
2486 
2487  plot.addToLegend(l, legendLabels, denomUncertainty)
2488  l.Draw()
2489  return l
2490 
def _createLegend(self, plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.016, denomUncertainty=True)
Definition: plotting.py:2475
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 2409 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, DrellYanValidation._name, WValidation._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, GeometricDetExtra._name, GeometricTimingDetExtra._name, HistoParams< T >._name, CutApplicatorBase._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, Vispa.Views.PropertyView.Property._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().

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

Definition at line 2471 of file plotting.py.

References plotting.PlotGroup._ratioFactor.

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

2471  def _modifyPadForRatio(self, pad):
2472  """Internal method to set divide a pad to two for ratio plots"""
2473  _modifyPadForRatio(pad, self._ratioFactor)
2474 
def _modifyPadForRatio(self, pad)
Definition: plotting.py:2471
def plotting.PlotGroup._save (   self,
  canvas,
  saveFormat,
  prefix = None,
  postfix = None,
  single = False,
  directory = "" 
)
private

Definition at line 2491 of file plotting.py.

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, GeometricDetExtra._name, GeometricTimingDetExtra._name, HistoParams< T >._name, CutApplicatorBase._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, Vispa.Views.PropertyView.Property._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().

2491  def _save(self, canvas, saveFormat, prefix=None, postfix=None, single=False, directory=""):
2492  # Save the canvas to file and clear
2493  name = self._name
2494  if prefix is not None:
2495  name = prefix+name
2496  if postfix is not None:
2497  name = name+postfix
2498  name = os.path.join(directory, name)
2499 
2500  if not verbose: # silence saved file printout
2501  backup = ROOT.gErrorIgnoreLevel
2502  ROOT.gErrorIgnoreLevel = ROOT.kWarning
2503  canvas.SaveAs(name+saveFormat)
2504  if not verbose:
2505  ROOT.gErrorIgnoreLevel = backup
2506 
2507  if single:
2508  canvas.Clear()
2509  canvas.SetLogx(False)
2510  canvas.SetLogy(False)
2511  else:
2512  canvas.Clear("D") # keep subpads
2513 
2514  return [name+saveFormat]
2515 
def _save(self, canvas, saveFormat, prefix=None, postfix=None, single=False, directory="")
Definition: plotting.py:2491
def plotting.PlotGroup.append (   self,
  plot 
)

Definition at line 2309 of file plotting.py.

Referenced by diclist.diclist.add().

2309  def append(self, plot):
2310  self._plots.append(plot)
2311 
def append(self, plot)
Definition: plotting.py:2309
def plotting.PlotGroup.clear (   self)

Definition at line 2306 of file plotting.py.

References plotting.PlotGroup._plots.

2306  def clear(self):
2307  self._plots = []
2308 
def clear(self)
Definition: plotting.py:2306
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 2322 of file plotting.py.

References plotting.PlotGroup._plots.

2322  def create(self, tdirectoryNEvents, requireAllHistograms=False):
2323  """Create histograms from a list of TDirectories.
2324 
2325  Arguments:
2326  tdirectoryNEvents -- List of (TDirectory, nevents) pairs
2327  requireAllHistograms -- If True, a plot is produced if histograms from all files are present (default: False)
2328  """
2329  for plot in self._plots:
2330  plot.create(tdirectoryNEvents, requireAllHistograms)
2331 
def create(self, tdirectoryNEvents, requireAllHistograms=False)
Definition: plotting.py:2322
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 2332 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, DrellYanValidation._name, WValidation._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, GeometricDetExtra._name, GeometricTimingDetExtra._name, HistoParams< T >._name, CutApplicatorBase._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, Vispa.Views.PropertyView.Property._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.

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

Definition at line 2312 of file plotting.py.

References plotting.PlotGroup._plots.

2312  def getPlot(self, name):
2313  for plot in self._plots:
2314  if plot.getName() == name:
2315  return plot
2316  raise Exception("No Plot named '%s'" % name)
2317 
def getPlot(self, name)
Definition: plotting.py:2312
def plotting.PlotGroup.getPlots (   self)

Definition at line 2296 of file plotting.py.

References plotting.PlotGroup._plots.

2296  def getPlots(self):
2297  return self._plots
2298 
def getPlots(self)
Definition: plotting.py:2296
def plotting.PlotGroup.onlyForPileup (   self)
Return True if the PlotGroup is intended only for pileup samples

Definition at line 2318 of file plotting.py.

References plotting.PlotFolder._onlyForPileup.

2318  def onlyForPileup(self):
2319  """Return True if the PlotGroup is intended only for pileup samples"""
2320  return self._onlyForPileup
2321 
def onlyForPileup(self)
Definition: plotting.py:2318
def plotting.PlotGroup.remove (   self,
  name 
)
def plotting.PlotGroup.setProperties (   self,
  kwargs 
)

Definition at line 2287 of file plotting.py.

2287  def setProperties(self, **kwargs):
2288  for name, value in six.iteritems(kwargs):
2289  if not hasattr(self, "_"+name):
2290  raise Exception("No attribute '%s'" % name)
2291  setattr(self, "_"+name, value)
2292 
def setProperties(self, kwargs)
Definition: plotting.py:2287

Member Data Documentation

plotting.PlotGroup._name
private
plotting.PlotGroup._plots
private
plotting.PlotGroup._ratioFactor
private