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

References GeometryComparisonPlotter._legend.

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

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 

◆ _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.

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

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

References plotting.PlotGroup._ratioFactor.

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

2477  def _modifyPadForRatio(self, pad):
2478  """Internal method to set divide a pad to two for ratio plots"""
2479  _modifyPadForRatio(pad, self._ratioFactor)
2480 
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 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._TaskBasePlaceholder._name, plotting.Plot._name, and plotting.PlotGroup._name.

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

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, exist_ok=True)
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 

◆ append()

def plotting.PlotGroup.append (   self,
  plot 
)

Definition at line 2314 of file plotting.py.

References plotting.PlotGroup._plots.

Referenced by diclist.diclist.add().

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

◆ clear()

def plotting.PlotGroup.clear (   self)

Definition at line 2311 of file plotting.py.

References plotting.PlotGroup._plots.

2311  def clear(self):
2312  self._plots = []
2313 
void clear(HadCaloObj &c)
Definition: data.h:124

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

References plotting.PlotGroup._plots.

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 
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 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._TaskBasePlaceholder._name, plotting.Plot._name, plotting.PlotGroup._name, plotting.PlotGroup._plots, plotting.PlotGroup._ratioFactor, plotting.PlotGroup._save(), createfilelist.int, and SiStripPI.max.

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  if plot._legend:
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 
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 2317 of file plotting.py.

References plotting.PlotGroup._plots.

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 

◆ getPlots()

def plotting.PlotGroup.getPlots (   self)

Definition at line 2301 of file plotting.py.

References plotting.PlotGroup._plots.

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

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

References plotting.PlotFolder._onlyForPileup.

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

◆ 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