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

2231  def __init__(self, name, plots, **kwargs):
2232  """Constructor.
2233 
2234  Arguments:
2235  name -- String for name of the TCanvas, used also as the basename of the picture files
2236  plots -- List of Plot objects
2237 
2238  Keyword arguments:
2239  ncols -- Number of columns (default 2)
2240  legendDx -- Float for moving TLegend in x direction (default None)
2241  legendDy -- Float for moving TLegend in y direction (default None)
2242  legendDw -- Float for changing TLegend width (default None)
2243  legendDh -- Float for changing TLegend height (default None)
2244  legend -- Bool for disabling legend (default True for legend being enabled)
2245  overrideLegendLabels -- List of strings for legend labels, if given, these are used instead of the ones coming from Plotter (default None)
2246  onlyForPileup -- Plots this group only for pileup samples
2247  """
2248  super(PlotGroup, self).__init__()
2249 
2250  self._name = name
2251  self._plots = plots
2252 
2253  def _set(attr, default):
2254  setattr(self, "_"+attr, kwargs.get(attr, default))
2255 
2256  _set("ncols", 2)
2257 
2258  _set("legendDx", None)
2259  _set("legendDy", None)
2260  _set("legendDw", None)
2261  _set("legendDh", None)
2262  _set("legend", True)
2263 
2264  _set("overrideLegendLabels", None)
2265 
2266  _set("onlyForPileup", False)
2267 
2268  self._ratioFactor = 1.25
2269 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ _createLegend()

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

Definition at line 2459 of file plotting.py.

References GeometryComparisonPlotter._legend.

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

2459  def _createLegend(self, plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.016, denomUncertainty=True):
2460  if not self._legend:
2461  return None
2462 
2463  l = ROOT.TLegend(lx1, ly1, lx2, ly2)
2464  l.SetTextSize(textSize)
2465  l.SetLineColor(1)
2466  l.SetLineWidth(1)
2467  l.SetLineStyle(1)
2468  l.SetFillColor(0)
2469  l.SetMargin(0.07)
2470 
2471  plot.addToLegend(l, legendLabels, denomUncertainty)
2472  l.Draw()
2473  return l
2474 

◆ _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 2393 of file plotting.py.

References plotting._createCanvas(), plotting.PlotGroup._createLegend(), plotting.PlotGroup._modifyPadForRatio(), ModulesProxy._ModuleProxy._name, FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, TrackingRecHitAlgorithm._name, Logger._name, hcaldqm::DQModule._name, citk::IsolationConeDefinitionBase._name, condhdf5tohdf5.H5DataProduct._name, WValidation._name, DrellYanValidation._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, HistoParams< T >._name, condhdf5tohdf5.H5Tag._name, CutApplicatorBase._name, condhdf5tohdf5.H5GlobalTag._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, conddb2hdf5.DBGlobalTag._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._TaskBasePlaceholder._name, plotting.Plot._name, plotting.PlotGroup._name, plotting.PlotGroup._plots, plotting.PlotGroup._ratioFactor, plotting.PlotGroup._save(), and createfilelist.int.

Referenced by plotting.PlotGroup.draw().

2393  def _drawSeparate(self, legendLabels, prefix, saveFormat, ratio, directory):
2394  """Internal method to do the drawing to separate files per Plot instead of a file per PlotGroup"""
2395  width = 500
2396  height = 500
2397 
2398  lx1def = 0.6
2399  lx2def = 0.95
2400  ly1def = 0.85
2401  ly2def = 0.95
2402 
2403  ret = []
2404 
2405  for plot in self._plots:
2406  if plot.isEmpty():
2407  continue
2408 
2409  canvas = _createCanvas(self._name+"Single", width, height)
2410  canvasRatio = _createCanvas(self._name+"SingleRatio", width, int(height*self._ratioFactor))
2411 
2412  # from TDRStyle
2413  for c in [canvas, canvasRatio]:
2414  c.SetTopMargin(0.05)
2415  c.SetBottomMargin(0.13)
2416  c.SetLeftMargin(0.16)
2417  c.SetRightMargin(0.05)
2418 
2419  ratioForThisPlot = plot.isRatio(ratio)
2420  c = canvas
2421  if ratioForThisPlot:
2422  c = canvasRatio
2423  c.cd()
2424  self._modifyPadForRatio(c)
2425 
2426  # Draw plot to canvas
2427  c.cd()
2428  plot.draw(c, ratioForThisPlot, self._ratioFactor, 1)
2429 
2430  if plot._legend:
2431  # Setup legend
2432  lx1 = lx1def
2433  lx2 = lx2def
2434  ly1 = ly1def
2435  ly2 = ly2def
2436 
2437  if plot._legendDx is not None:
2438  lx1 += plot._legendDx
2439  lx2 += plot._legendDx
2440  if plot._legendDy is not None:
2441  ly1 += plot._legendDy
2442  ly2 += plot._legendDy
2443  if plot._legendDw is not None:
2444  lx2 += plot._legendDw
2445  if plot._legendDh is not None:
2446  ly1 -= plot._legendDh
2447 
2448  c.cd()
2449  legend = self._createLegend(plot, legendLabels, lx1, ly1, lx2, ly2, textSize=0.03,
2450  denomUncertainty=(ratioForThisPlot and plot.drawRatioUncertainty))
2451 
2452  ret.extend(self._save(c, saveFormat, prefix=prefix, postfix="/"+plot.getName(), single=True, directory=directory))
2453  return ret
2454 
def _createCanvas(name, width, height)
Definition: plotting.py:109

◆ _modifyPadForRatio()

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

Definition at line 2455 of file plotting.py.

References plotting.PlotGroup._ratioFactor.

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

2455  def _modifyPadForRatio(self, pad):
2456  """Internal method to set divide a pad to two for ratio plots"""
2457  _modifyPadForRatio(pad, self._ratioFactor)
2458 
def _modifyPadForRatio(pad, ratioFactor)
Definition: plotting.py:119

◆ _save()

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

Definition at line 2475 of file plotting.py.

References ModulesProxy._ModuleProxy._name, FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, TrackingRecHitAlgorithm._name, Logger._name, hcaldqm::DQModule._name, citk::IsolationConeDefinitionBase._name, condhdf5tohdf5.H5DataProduct._name, WValidation._name, DrellYanValidation._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, HistoParams< T >._name, condhdf5tohdf5.H5Tag._name, CutApplicatorBase._name, condhdf5tohdf5.H5GlobalTag._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, conddb2hdf5.DBGlobalTag._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._TaskBasePlaceholder._name, plotting.Plot._name, and plotting.PlotGroup._name.

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

2475  def _save(self, canvas, saveFormat, prefix=None, postfix=None, single=False, directory=""):
2476  # Save the canvas to file and clear
2477  name = self._name
2478  if not os.path.exists(directory+'/'+name):
2479  os.makedirs(directory+'/'+name, exist_ok=True)
2480  if prefix is not None:
2481  name = prefix+name
2482  if postfix is not None:
2483  name = name+postfix
2484  name = os.path.join(directory, name)
2485 
2486  if not verbose: # silence saved file printout
2487  backup = ROOT.gErrorIgnoreLevel
2488  ROOT.gErrorIgnoreLevel = ROOT.kWarning
2489  canvas.SaveAs(name+saveFormat)
2490  if not verbose:
2491  ROOT.gErrorIgnoreLevel = backup
2492 
2493  if single:
2494  canvas.Clear()
2495  canvas.SetLogx(False)
2496  canvas.SetLogy(False)
2497  else:
2498  canvas.Clear("D") # keep subpads
2499 
2500  return [name+saveFormat]
2501 

◆ append()

def plotting.PlotGroup.append (   self,
  plot 
)

Definition at line 2292 of file plotting.py.

References plotting.PlotGroup._plots.

Referenced by diclist.diclist.add().

2292  def append(self, plot):
2293  self._plots.append(plot)
2294 

◆ clear()

def plotting.PlotGroup.clear (   self)

Definition at line 2289 of file plotting.py.

References plotting.PlotGroup._plots.

2289  def clear(self):
2290  self._plots = []
2291 
void clear(EGIsoObj &c)
Definition: egamma.h:82

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

Definition at line 2305 of file plotting.py.

References plotting.PlotGroup._plots.

2305  def create(self, tdirectoryNEvents, requireAllHistograms=False):
2306  """Create histograms from a list of TDirectories.
2307 
2308  Arguments:
2309  tdirectoryNEvents -- List of (TDirectory, nevents) pairs
2310  requireAllHistograms -- If True, a plot is produced if histograms from all files are present (default: False)
2311  """
2312  for plot in self._plots:
2313  plot.create(tdirectoryNEvents, requireAllHistograms)
2314 
def create(alignables, pedeDump, additionalData, outputFile, config)

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

References plotting._createCanvas(), plotting.PlotGroup._createLegend(), plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._modifyPadForRatio(), ModulesProxy._ModuleProxy._name, FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, TrackingRecHitAlgorithm._name, Logger._name, hcaldqm::DQModule._name, citk::IsolationConeDefinitionBase._name, condhdf5tohdf5.H5DataProduct._name, WValidation._name, DrellYanValidation._name, hcaldqm::flag::Flag._name, hcaldqm::quantity::Quantity._name, HistoParams< T >._name, condhdf5tohdf5.H5Tag._name, CutApplicatorBase._name, condhdf5tohdf5.H5GlobalTag._name, HistoParams< TH2F >._name, HistoParams< TProfile2D >._name, conddb2hdf5.DBGlobalTag._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._TaskBasePlaceholder._name, plotting.Plot._name, plotting.PlotGroup._name, plotting.PlotGroup._plots, plotting.PlotGroup._ratioFactor, plotting.PlotGroup._save(), createfilelist.int, and SiStripPI.max.

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

◆ getName()

def plotting.PlotGroup.getName (   self)

◆ getPlot()

def plotting.PlotGroup.getPlot (   self,
  name 
)

Definition at line 2295 of file plotting.py.

References plotting.PlotGroup._plots.

2295  def getPlot(self, name):
2296  for plot in self._plots:
2297  if plot.getName() == name:
2298  return plot
2299  raise Exception("No Plot named '%s'" % name)
2300 

◆ getPlots()

def plotting.PlotGroup.getPlots (   self)

Definition at line 2279 of file plotting.py.

References plotting.PlotGroup._plots.

2279  def getPlots(self):
2280  return self._plots
2281 

◆ onlyForPileup()

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

Definition at line 2301 of file plotting.py.

References plotting.PlotFolder._onlyForPileup.

2301  def onlyForPileup(self):
2302  """Return True if the PlotGroup is intended only for pileup samples"""
2303  return self._onlyForPileup
2304 

◆ remove()

def plotting.PlotGroup.remove (   self,
  name 
)

◆ setProperties()

def plotting.PlotGroup.setProperties (   self,
  kwargs 
)

Definition at line 2270 of file plotting.py.

2270  def setProperties(self, **kwargs):
2271  for name, value in kwargs.items():
2272  if not hasattr(self, "_"+name):
2273  raise Exception("No attribute '%s'" % name)
2274  setattr(self, "_"+name, value)
2275 

Member Data Documentation

◆ _name

plotting.PlotGroup._name
private

◆ _plots

plotting.PlotGroup._plots
private

◆ _ratioFactor

plotting.PlotGroup._ratioFactor
private