CMS 3D CMS Logo

Classes | Functions | Variables
plotting Namespace Reference

Classes

class  AggregateBins
 
class  AggregateHistos
 
class  CutEfficiency
 
class  DQMSubFolder
 
class  FakeDuplicate
 
class  Frame
 
class  FrameRatio
 
class  FrameTGraph2D
 
class  GetDirectoryCode
 
class  Plot
 
class  PlotEmpty
 
class  PlotFolder
 
class  PlotGroup
 
class  PlotOnSideGroup
 
class  Plotter
 
class  PlotterFolder
 
class  PlotterInstance
 
class  PlotterItem
 
class  PlotterTableItem
 
class  PlotText
 
class  PlotTextBox
 
class  ROC
 
class  Subtract
 
class  Transform
 

Functions

def _calculateRatios (histos, ratioUncertainty=False)
 
def _copyStyle (src, dst)
 
def _createCanvas (name, width, height)
 
def _drawFrame (pad, bounds, zmax=None, xbinlabels=None, xbinlabelsize=None, xbinlabeloption=None, ybinlabels=None, suffix="")
 
def _findBounds (th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None)
 
def _findBoundsY (th1s, ylog, ymin=None, ymax=None, coverage=None, coverageRange=None)
 
def _getDirectory (args, kwargs)
 
def _getDirectoryDetailed (tfile, possibleDirs, subDir=None)
 
def _getObject (tdirectory, name)
 
def _getOrCreateObject (tdirectory, nameOrCreator)
 
def _getXmax (obj, limitToNonZeroContent=False)
 
def _getXmin (obj, limitToNonZeroContent=False)
 
def _getYmax (obj, limitToNonZeroContent=False)
 
def _getYmaxWithError (th1)
 
def _getYmin (obj, limitToNonZeroContent=False)
 
def _getYminIgnoreOutlier (th1)
 
def _getYminMaxAroundMedian (obj, coverage, coverageRange=None)
 
def _mergeBinLabels (labelsAll)
 
def _mergeBinLabelsX (histos)
 
def _mergeBinLabelsY (histos)
 
def _modifyPadForRatio (pad, ratioFactor)
 
def _setStyle ()
 
def _th1IncludeOnlyBins (histos, xbinlabels)
 
def _th1RemoveEmptyBins (histos, xbinlabels)
 
def _th1ToOrderedDict (th1, renameBin=None)
 
def _th2RemoveEmptyBins (histos, xbinlabels, ybinlabels)
 

Variables

 _gr
 
 _plotStylesColor
 
 _plotStylesMarker
 
 _ratio
 
 _ratioYTitle
 
 _th1
 
 _uncertainty
 
 _xerrshigh
 
 _xerrslow
 
 _xvalues
 
 _yerrshigh
 
 _yerrslow
 
 _yvalues
 
 IgnoreCommandLineOptions
 
 verbose
 

Function Documentation

◆ _calculateRatios()

def plotting._calculateRatios (   histos,
  ratioUncertainty = False 
)
private
Calculate the ratios for a list of histograms

Definition at line 148 of file plotting.py.

References submitPVValidationJobs.__init__(), funct.abs(), cond::serialization.equal(), and SiStripPI.max.

Referenced by ntuplePlotting.drawSingle().

148 def _calculateRatios(histos, ratioUncertainty=False):
149  """Calculate the ratios for a list of histograms"""
150 
151  def _divideOrZero(numerator, denominator):
152  if denominator == 0:
153  return 0
154  return numerator/denominator
155 
156  def equal(a, b):
157  if a == 0. and b == 0.:
158  return True
159  return abs(a-b)/max(abs(a),abs(b)) < 1e-3
160 
161  def findBins(wrap, bins_xvalues):
162  ret = []
163  currBin = wrap.begin()
164  i = 0
165  while i < len(bins_xvalues) and currBin < wrap.end():
166  (xcenter, xlow, xhigh) = bins_xvalues[i]
167  xlowEdge = xcenter-xlow
168  xupEdge = xcenter+xhigh
169 
170  (curr_center, curr_low, curr_high) = wrap.xvalues(currBin)
171  curr_lowEdge = curr_center-curr_low
172  curr_upEdge = curr_center+curr_high
173 
174  if equal(xlowEdge, curr_lowEdge) and equal(xupEdge, curr_upEdge):
175  ret.append(currBin)
176  currBin += 1
177  i += 1
178  elif curr_upEdge <= xlowEdge:
179  currBin += 1
180  elif curr_lowEdge >= xupEdge:
181  ret.append(None)
182  i += 1
183  else:
184  ret.append(None)
185  currBin += 1
186  i += 1
187  if len(ret) != len(bins_xvalues):
188  ret.extend([None]*( len(bins_xvalues) - len(ret) ))
189  return ret
190 
191  # Define wrappers for TH1/TGraph/TGraph2D to have uniform interface
192  # TODO: having more global wrappers would make some things simpler also elsewhere in the code
193  class WrapTH1:
194  def __init__(self, th1, uncertainty):
195  self._th1 = th1
196  self._uncertainty = uncertainty
197 
198  xaxis = th1.GetXaxis()
199  xaxis_arr = xaxis.GetXbins()
200  if xaxis_arr.GetSize() > 0: # unequal binning
201  lst = [xaxis_arr[i] for i in range(0, xaxis_arr.GetSize())]
202  arr = array.array("d", lst)
203  self._ratio = ROOT.TH1F("foo", "foo", xaxis.GetNbins(), arr)
204  else:
205  self._ratio = ROOT.TH1F("foo", "foo", xaxis.GetNbins(), xaxis.GetXmin(), xaxis.GetXmax())
206  _copyStyle(th1, self._ratio)
207  self._ratio.SetStats(0)
208  self._ratio.SetLineColor(ROOT.kBlack)
209  self._ratio.SetLineWidth(1)
210  def draw(self, style=None):
211  st = style
212  if st is None:
213  if self._uncertainty:
214  st = "EP"
215  else:
216  st = "HIST P"
217  self._ratio.Draw("same "+st)
218  def begin(self):
219  return 1
220  def end(self):
221  return self._th1.GetNbinsX()+1
222  def xvalues(self, bin):
223  xval = self._th1.GetBinCenter(bin)
224  xlow = xval-self._th1.GetXaxis().GetBinLowEdge(bin)
225  xhigh = self._th1.GetXaxis().GetBinUpEdge(bin)-xval
226  return (xval, xlow, xhigh)
227  def yvalues(self, bin):
228  yval = self._th1.GetBinContent(bin)
229  yerr = self._th1.GetBinError(bin)
230  return (yval, yerr, yerr)
231  def y(self, bin):
232  return self._th1.GetBinContent(bin)
233  def divide(self, bin, scale):
234  self._ratio.SetBinContent(bin, _divideOrZero(self._th1.GetBinContent(bin), scale))
235  self._ratio.SetBinError(bin, _divideOrZero(self._th1.GetBinError(bin), scale))
236  def makeRatio(self):
237  pass
238  def getRatio(self):
239  return self._ratio
240 
241  class WrapTGraph:
242  def __init__(self, gr, uncertainty):
243  self._gr = gr
244  self._uncertainty = uncertainty
245  self._xvalues = []
246  self._xerrslow = []
247  self._xerrshigh = []
248  self._yvalues = []
249  self._yerrshigh = []
250  self._yerrslow = []
251  def draw(self, style=None):
252  if self._ratio is None:
253  return
254  st = style
255  if st is None:
256  if self._uncertainty:
257  st = "PZ"
258  else:
259  st = "PX"
260  self._ratio.Draw("same "+st)
261  def begin(self):
262  return 0
263  def end(self):
264  return self._gr.GetN()
265  def xvalues(self, bin):
266  return (self._gr.GetX()[bin], self._gr.GetErrorXlow(bin), self._gr.GetErrorXhigh(bin))
267  def yvalues(self, bin):
268  return (self._gr.GetY()[bin], self._gr.GetErrorYlow(bin), self._gr.GetErrorYhigh(bin))
269  def y(self, bin):
270  return self._gr.GetY()[bin]
271  def divide(self, bin, scale):
272  # Ignore bin if denominator is zero
273  if scale == 0:
274  return
275  # No more items in the numerator
276  if bin >= self._gr.GetN():
277  return
278  # denominator is missing an item
279  xvals = self.xvalues(bin)
280  xval = xvals[0]
281 
282  self._xvalues.append(xval)
283  self._xerrslow.append(xvals[1])
284  self._xerrshigh.append(xvals[2])
285  yvals = self.yvalues(bin)
286  self._yvalues.append(yvals[0] / scale)
287  if self._uncertainty:
288  self._yerrslow.append(yvals[1] / scale)
289  self._yerrshigh.append(yvals[2] / scale)
290  else:
291  self._yerrslow.append(0)
292  self._yerrshigh.append(0)
293  def makeRatio(self):
294  if len(self._xvalues) == 0:
295  self._ratio = None
296  return
297  self._ratio = ROOT.TGraphAsymmErrors(len(self._xvalues), array.array("d", self._xvalues), array.array("d", self._yvalues),
298  array.array("d", self._xerrslow), array.array("d", self._xerrshigh),
299  array.array("d", self._yerrslow), array.array("d", self._yerrshigh))
300  _copyStyle(self._gr, self._ratio)
301  def getRatio(self):
302  return self._ratio
303  class WrapTGraph2D(WrapTGraph):
304  def __init__(self, gr, uncertainty):
305  WrapTGraph.__init__(self, gr, uncertainty)
306  def xvalues(self, bin):
307  return (self._gr.GetX()[bin], self._gr.GetErrorX(bin), self._gr.GetErrorX(bin))
308  def yvalues(self, bin):
309  return (self._gr.GetY()[bin], self._gr.GetErrorY(bin), self._gr.GetErrorY(bin))
310 
311  def wrap(o):
312  if isinstance(o, ROOT.TH1) and not isinstance(o, ROOT.TH2):
313  return WrapTH1(o, ratioUncertainty)
314  elif isinstance(o, ROOT.TGraph):
315  return WrapTGraph(o, ratioUncertainty)
316  elif isinstance(o, ROOT.TGraph2D):
317  return WrapTGraph2D(o, ratioUncertainty)
318 
319  wrappers = [wrap(h) for h in histos if wrap(h) is not None]
320  if len(wrappers) < 1:
321  return []
322  ref = wrappers[0]
323 
324  wrappers_bins = []
325  ref_bins = [ref.xvalues(b) for b in range(ref.begin(), ref.end())]
326  for w in wrappers:
327  wrappers_bins.append(findBins(w, ref_bins))
328 
329  for i, bin in enumerate(range(ref.begin(), ref.end())):
330  (scale, ylow, yhigh) = ref.yvalues(bin)
331  for w, bins in zip(wrappers, wrappers_bins):
332  if bins[i] is None:
333  continue
334  w.divide(bins[i], scale)
335 
336  for w in wrappers:
337  w.makeRatio()
338 
339  return wrappers
340 
341 
def _copyStyle(src, dst)
Definition: plotting.py:1641
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
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)
bool equal(const T &first, const T &second)
Definition: Equal.h:32
void divide(dqm::legacy::MonitorElement *eff, const dqm::legacy::MonitorElement *numerator, const dqm::legacy::MonitorElement *denominator)
Function to fill an efficiency histograms with binomial errors.
Definition: Histograms.h:20
def _calculateRatios(histos, ratioUncertainty=False)
Definition: plotting.py:148
def draw(name, histos, styles=_defaultStyles, legendLabels=[], kwargs)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
auto wrap(F iFunc) -> decltype(iFunc())

◆ _copyStyle()

def plotting._copyStyle (   src,
  dst 
)
private

Definition at line 1641 of file plotting.py.

1641 def _copyStyle(src, dst):
1642  properties = []
1643  if hasattr(src, "GetLineColor") and hasattr(dst, "SetLineColor"):
1644  properties.extend(["LineColor", "LineStyle", "LineWidth"])
1645  if hasattr(src, "GetFillColor") and hasattr(dst, "SetFillColor"):
1646  properties.extend(["FillColor", "FillStyle"])
1647  if hasattr(src, "GetMarkerColor") and hasattr(dst, "SetMarkerColor"):
1648  properties.extend(["MarkerColor", "MarkerSize", "MarkerStyle"])
1649 
1650  for prop in properties:
1651  getattr(dst, "Set"+prop)(getattr(src, "Get"+prop)())
1652 
def _copyStyle(src, dst)
Definition: plotting.py:1641

◆ _createCanvas()

def plotting._createCanvas (   name,
  width,
  height 
)
private

Definition at line 109 of file plotting.py.

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

109 def _createCanvas(name, width, height):
110  # silence warning of deleting canvas with the same name
111  if not verbose:
112  backup = ROOT.gErrorIgnoreLevel
113  ROOT.gErrorIgnoreLevel = ROOT.kError
114  canvas = ROOT.TCanvas(name, name, width, height)
115  if not verbose:
116  ROOT.gErrorIgnoreLevel = backup
117  return canvas
118 
def _createCanvas(name, width, height)
Definition: plotting.py:109

◆ _drawFrame()

def plotting._drawFrame (   pad,
  bounds,
  zmax = None,
  xbinlabels = None,
  xbinlabelsize = None,
  xbinlabeloption = None,
  ybinlabels = None,
  suffix = "" 
)
private
Function to draw a frame

Arguments:
pad    -- TPad to where the frame is drawn
bounds -- List or 4-tuple for (xmin, ymin, xmax, ymax)

Keyword arguments:
zmax            -- Maximum Z, needed for TH2 histograms
xbinlabels      -- Optional list of strings for x axis bin labels
xbinlabelsize   -- Optional number for the x axis bin label size
xbinlabeloption -- Optional string for the x axis bin options (passed to ROOT.TH1.LabelsOption())
suffix          -- Optional string for a postfix of the frame name

Definition at line 1187 of file plotting.py.

References FastTimerService_cff.range.

1187 def _drawFrame(pad, bounds, zmax=None, xbinlabels=None, xbinlabelsize=None, xbinlabeloption=None, ybinlabels=None, suffix=""):
1188  """Function to draw a frame
1189 
1190  Arguments:
1191  pad -- TPad to where the frame is drawn
1192  bounds -- List or 4-tuple for (xmin, ymin, xmax, ymax)
1193 
1194  Keyword arguments:
1195  zmax -- Maximum Z, needed for TH2 histograms
1196  xbinlabels -- Optional list of strings for x axis bin labels
1197  xbinlabelsize -- Optional number for the x axis bin label size
1198  xbinlabeloption -- Optional string for the x axis bin options (passed to ROOT.TH1.LabelsOption())
1199  suffix -- Optional string for a postfix of the frame name
1200  """
1201  if xbinlabels is None and ybinlabels is None:
1202  frame = pad.DrawFrame(*bounds)
1203  else:
1204  # Special form needed if want to set x axis bin labels
1205  nbins = len(xbinlabels)
1206  if ybinlabels is None:
1207  frame = ROOT.TH1F("hframe"+suffix, "", nbins, bounds[0], bounds[2])
1208  frame.SetMinimum(bounds[1])
1209  frame.SetMaximum(bounds[3])
1210  frame.GetYaxis().SetLimits(bounds[1], bounds[3])
1211  else:
1212  ybins = len(ybinlabels)
1213  frame = ROOT.TH2F("hframe"+suffix, "", nbins,bounds[0],bounds[2], ybins,bounds[1],bounds[3])
1214  frame.SetMaximum(zmax)
1215 
1216  frame.SetBit(ROOT.TH1.kNoStats)
1217  frame.SetBit(ROOT.kCanDelete)
1218  frame.Draw("")
1219 
1220  xaxis = frame.GetXaxis()
1221  for i in range(nbins):
1222  xaxis.SetBinLabel(i+1, xbinlabels[i])
1223  if xbinlabelsize is not None:
1224  xaxis.SetLabelSize(xbinlabelsize)
1225  if xbinlabeloption is not None:
1226  frame.LabelsOption(xbinlabeloption)
1227 
1228  if ybinlabels is not None:
1229  yaxis = frame.GetYaxis()
1230  for i, lab in enumerate(ybinlabels):
1231  yaxis.SetBinLabel(i+1, lab)
1232  if xbinlabelsize is not None:
1233  yaxis.SetLabelSize(xbinlabelsize)
1234  if xbinlabeloption is not None:
1235  frame.LabelsOption(xbinlabeloption, "Y")
1236 
1237  return frame
1238 
def _drawFrame(pad, bounds, zmax=None, xbinlabels=None, xbinlabelsize=None, xbinlabeloption=None, ybinlabels=None, suffix="")
Definition: plotting.py:1187

◆ _findBounds()

def plotting._findBounds (   th1s,
  ylog,
  xmin = None,
  xmax = None,
  ymin = None,
  ymax = None 
)
private
Find x-y axis boundaries encompassing a list of TH1s if the bounds are not given in arguments.

Arguments:
th1s -- List of TH1s
ylog -- Boolean indicating if y axis is in log scale or not (affects the automatic ymax)

Keyword arguments:
xmin -- Minimum x value; if None, take the minimum of TH1s
xmax -- Maximum x value; if None, take the maximum of TH1s
ymin -- Minimum y value; if None, take the minimum of TH1s
ymax -- Maximum y value; if None, take the maximum of TH1s

Definition at line 459 of file plotting.py.

References _findBoundsY(), _getXmax(), _getXmin(), SiStripPI.max, SiStripPI.min, print(), and str.

Referenced by ntuplePlotting.drawSingle().

459 def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None):
460  """Find x-y axis boundaries encompassing a list of TH1s if the bounds are not given in arguments.
461 
462  Arguments:
463  th1s -- List of TH1s
464  ylog -- Boolean indicating if y axis is in log scale or not (affects the automatic ymax)
465 
466  Keyword arguments:
467  xmin -- Minimum x value; if None, take the minimum of TH1s
468  xmax -- Maximum x value; if None, take the maximum of TH1s
469  ymin -- Minimum y value; if None, take the minimum of TH1s
470  ymax -- Maximum y value; if None, take the maximum of TH1s
471  """
472 
473  (ymin, ymax) = _findBoundsY(th1s, ylog, ymin, ymax)
474 
475  if xmin is None or xmax is None or isinstance(xmin, list) or isinstance(max, list):
476  xmins = []
477  xmaxs = []
478  for th1 in th1s:
479  xmins.append(_getXmin(th1, limitToNonZeroContent=isinstance(xmin, list)))
480  xmaxs.append(_getXmax(th1, limitToNonZeroContent=isinstance(xmax, list)))
481 
482  # Filter out cases where histograms have zero content
483  xmins = [h for h in xmins if h is not None]
484  xmaxs = [h for h in xmaxs if h is not None]
485 
486  if xmin is None:
487  xmin = min(xmins)
488  elif isinstance(xmin, list):
489  if len(xmins) == 0: # all histograms zero
490  xmin = min(xmin)
491  if verbose:
492  print("Histogram is zero, using the smallest given value for xmin from", str(xmin))
493  else:
494  xm = min(xmins)
495  xmins_below = [x for x in xmin if x<=xm]
496  if len(xmins_below) == 0:
497  xmin = min(xmin)
498  if xm < xmin:
499  if verbose:
500  print("Histogram minimum x %f is below all given xmin values %s, using the smallest one" % (xm, str(xmin)))
501  else:
502  xmin = max(xmins_below)
503 
504  if xmax is None:
505  xmax = max(xmaxs)
506  elif isinstance(xmax, list):
507  if len(xmaxs) == 0: # all histograms zero
508  xmax = max(xmax)
509  if verbose:
510  print("Histogram is zero, using the smallest given value for xmax from", str(xmin))
511  else:
512  xm = max(xmaxs)
513  xmaxs_above = [x for x in xmax if x>xm]
514  if len(xmaxs_above) == 0:
515  xmax = max(xmax)
516  if xm > xmax:
517  if verbose:
518  print("Histogram maximum x %f is above all given xmax values %s, using the maximum one" % (xm, str(xmax)))
519  else:
520  xmax = min(xmaxs_above)
521 
522  for th1 in th1s:
523  th1.GetXaxis().SetRangeUser(xmin, xmax)
524 
525  return (xmin, ymin, xmax, ymax)
526 
def _findBoundsY(th1s, ylog, ymin=None, ymax=None, coverage=None, coverageRange=None)
Definition: plotting.py:527
def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None)
Definition: plotting.py:459
def _getXmax(obj, limitToNonZeroContent=False)
Definition: plotting.py:358
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def _getXmin(obj, limitToNonZeroContent=False)
Definition: plotting.py:342
#define str(s)

◆ _findBoundsY()

def plotting._findBoundsY (   th1s,
  ylog,
  ymin = None,
  ymax = None,
  coverage = None,
  coverageRange = None 
)
private
Find y axis boundaries encompassing a list of TH1s if the bounds are not given in arguments.

Arguments:
th1s -- List of TH1s
ylog -- Boolean indicating if y axis is in log scale or not (affects the automatic ymax)

Keyword arguments:
ymin -- Minimum y value; if None, take the minimum of TH1s
ymax -- Maximum y value; if None, take the maximum of TH1s
coverage -- If set, use only values within the 'coverage' part around the median are used for min/max (useful for ratio)
coverageRange -- If coverage and this are set, use only the x axis specified by an (xmin,xmax) pair for the coverage

Definition at line 527 of file plotting.py.

References _getYmax(), _getYmin(), _getYminIgnoreOutlier(), _getYminMaxAroundMedian(), SiStripPI.max, SiStripPI.min, print(), and str.

Referenced by _findBounds().

527 def _findBoundsY(th1s, ylog, ymin=None, ymax=None, coverage=None, coverageRange=None):
528  """Find y axis boundaries encompassing a list of TH1s if the bounds are not given in arguments.
529 
530  Arguments:
531  th1s -- List of TH1s
532  ylog -- Boolean indicating if y axis is in log scale or not (affects the automatic ymax)
533 
534  Keyword arguments:
535  ymin -- Minimum y value; if None, take the minimum of TH1s
536  ymax -- Maximum y value; if None, take the maximum of TH1s
537  coverage -- If set, use only values within the 'coverage' part around the median are used for min/max (useful for ratio)
538  coverageRange -- If coverage and this are set, use only the x axis specified by an (xmin,xmax) pair for the coverage
539  """
540  if coverage is not None or isinstance(th1s[0], ROOT.TH2):
541  # the only use case for coverage for now is ratio, for which
542  # the scalings are not needed (actually harmful), so let's
543  # just ignore them if 'coverage' is set
544  #
545  # Also for TH2 do not adjust automatic y bounds
546  y_scale_max = lambda y: y
547  y_scale_min = lambda y: y
548  else:
549  if ylog:
550  y_scale_max = lambda y: y*1.5
551  else:
552  y_scale_max = lambda y: y*1.05
553  y_scale_min = lambda y: y*0.9 # assuming log
554 
555  if ymin is None or ymax is None or isinstance(ymin, list) or isinstance(ymax, list):
556  ymins = []
557  ymaxs = []
558  for th1 in th1s:
559  if coverage is not None:
560  (_ymin, _ymax) = _getYminMaxAroundMedian(th1, coverage, coverageRange)
561  else:
562  if ylog and isinstance(ymin, list):
563  _ymin = _getYminIgnoreOutlier(th1)
564  else:
565  _ymin = _getYmin(th1, limitToNonZeroContent=isinstance(ymin, list))
566  _ymax = _getYmax(th1, limitToNonZeroContent=isinstance(ymax, list))
567 # _ymax = _getYmaxWithError(th1)
568 
569  ymins.append(_ymin)
570  ymaxs.append(_ymax)
571 
572  if ymin is None:
573  ymin = min(ymins)
574  elif isinstance(ymin, list):
575  ym_unscaled = min(ymins)
576  ym = y_scale_min(ym_unscaled)
577  ymins_below = [y for y in ymin if y<=ym]
578  if len(ymins_below) == 0:
579  ymin = min(ymin)
580  if ym_unscaled < ymin:
581  if verbose:
582  print("Histogram minimum y %f is below all given ymin values %s, using the smallest one" % (ym, str(ymin)))
583  else:
584  ymin = max(ymins_below)
585 
586  if ymax is None:
587  # in case ymax is automatic, ymin is set by list, and the
588  # histograms are zero, ensure here that ymax > ymin
589  ymax = y_scale_max(max(ymaxs+[ymin]))
590  elif isinstance(ymax, list):
591  ym_unscaled = max(ymaxs)
592  ym = y_scale_max(ym_unscaled)
593  ymaxs_above = [y for y in ymax if y>ym]
594  if len(ymaxs_above) == 0:
595  ymax = max(ymax)
596  if ym_unscaled > ymax:
597  if verbose:
598  print("Histogram maximum y %f is above all given ymax values %s, using the maximum one" % (ym_unscaled, str(ymax)))
599  else:
600  ymax = min(ymaxs_above)
601 
602  for th1 in th1s:
603  th1.GetYaxis().SetRangeUser(ymin, ymax)
604 
605  return (ymin, ymax)
606 
def _getYmax(obj, limitToNonZeroContent=False)
Definition: plotting.py:389
def _findBoundsY(th1s, ylog, ymin=None, ymax=None, coverage=None, coverageRange=None)
Definition: plotting.py:527
def _getYmin(obj, limitToNonZeroContent=False)
Definition: plotting.py:374
def _getYminIgnoreOutlier(th1)
Definition: plotting.py:407
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def _getYminMaxAroundMedian(obj, coverage, coverageRange=None)
Definition: plotting.py:423
#define str(s)

◆ _getDirectory()

def plotting._getDirectory (   args,
  kwargs 
)
private

Definition at line 97 of file plotting.py.

References _getDirectoryDetailed().

Referenced by plotting.PlotterTableItem.create().

97 def _getDirectory(*args, **kwargs):
98  return GetDirectoryCode.codesToNone(_getDirectoryDetailed(*args, **kwargs))
99 
def _getDirectory(args, kwargs)
Definition: plotting.py:97
def _getDirectoryDetailed(tfile, possibleDirs, subDir=None)
Definition: plotting.py:73

◆ _getDirectoryDetailed()

def plotting._getDirectoryDetailed (   tfile,
  possibleDirs,
  subDir = None 
)
private
Get TDirectory from TFile.

Definition at line 73 of file plotting.py.

References join(), and print().

Referenced by _getDirectory(), and plotting.PlotterFolder.create().

73 def _getDirectoryDetailed(tfile, possibleDirs, subDir=None):
74  """Get TDirectory from TFile."""
75  if tfile is None:
76  return GetDirectoryCode.FileNotExist
77  for pdf in possibleDirs:
78  d = tfile.Get(pdf)
79  if d:
80  if subDir is not None:
81  # Pick associator if given
82  d = d.Get(subDir)
83  if d:
84  return d
85  else:
86  if verbose:
87  print("Did not find subdirectory '%s' from directory '%s' in file %s" % (subDir, pdf, tfile.GetName()))
88 # if "Step" in subDir:
89 # raise Exception("Foo")
90  return GetDirectoryCode.SubDirNotExist
91  else:
92  return d
93  if verbose:
94  print("Did not find any of directories '%s' from file %s" % (",".join(possibleDirs), tfile.GetName()))
95  return GetDirectoryCode.PossibleDirsNotExist
96 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def _getDirectoryDetailed(tfile, possibleDirs, subDir=None)
Definition: plotting.py:73
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ _getObject()

def plotting._getObject (   tdirectory,
  name 
)
private

Definition at line 49 of file plotting.py.

References print().

Referenced by _getOrCreateObject(), plotting.Subtract.create(), plotting.FakeDuplicate.create(), plotting.AggregateHistos.create(), and plotting.PlotterFolder.create().

49 def _getObject(tdirectory, name):
50  obj = tdirectory.Get(name)
51  if not obj:
52  if verbose:
53  print("Did not find {obj} from {dir}".format(obj=name, dir=tdirectory.GetPath()))
54  return None
55  return obj
56 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def _getObject(tdirectory, name)
Definition: plotting.py:49

◆ _getOrCreateObject()

def plotting._getOrCreateObject (   tdirectory,
  nameOrCreator 
)
private

Definition at line 57 of file plotting.py.

References _getObject().

Referenced by trackingPlots.TimePerEventPlot._create(), plotting.Plot._createOne(), plotting.Transform.create(), plotting.CutEfficiency.create(), plotting.AggregateBins.create(), plotting.ROC.create(), and trackingPlots.TimePerTrackPlot.create().

57 def _getOrCreateObject(tdirectory, nameOrCreator):
58  if hasattr(nameOrCreator, "create"):
59  return nameOrCreator.create(tdirectory)
60  return _getObject(tdirectory, nameOrCreator)
61 
def _getOrCreateObject(tdirectory, nameOrCreator)
Definition: plotting.py:57
def _getObject(tdirectory, name)
Definition: plotting.py:49

◆ _getXmax()

def plotting._getXmax (   obj,
  limitToNonZeroContent = False 
)
private

Definition at line 358 of file plotting.py.

References SiStripPI.max, FastTimerService_cff.range, and str.

Referenced by _findBounds().

358 def _getXmax(obj, limitToNonZeroContent=False):
359  if isinstance(obj, ROOT.TH1):
360  xaxis = obj.GetXaxis()
361  if limitToNonZeroContent:
362  for i in range(obj.GetNbinsX(), 0, -1):
363  if obj.GetBinContent(i) != 0:
364  return xaxis.GetBinUpEdge(i)
365  # None for all bins being zero
366  return None
367  else:
368  return xaxis.GetBinUpEdge(xaxis.GetLast())
369  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
370  m = max([obj.GetX()[i] for i in range(0, obj.GetN())])
371  return m*1.1 if m > 0 else m*0.9
372  raise Exception("Unsupported type %s" % str(obj))
373 
def _getXmax(obj, limitToNonZeroContent=False)
Definition: plotting.py:358
#define str(s)

◆ _getXmin()

def plotting._getXmin (   obj,
  limitToNonZeroContent = False 
)
private

Definition at line 342 of file plotting.py.

References SiStripPI.min, FastTimerService_cff.range, and str.

Referenced by _findBounds().

342 def _getXmin(obj, limitToNonZeroContent=False):
343  if isinstance(obj, ROOT.TH1):
344  xaxis = obj.GetXaxis()
345  if limitToNonZeroContent:
346  for i in range(1, obj.GetNbinsX()+1):
347  if obj.GetBinContent(i) != 0:
348  return xaxis.GetBinLowEdge(i)
349  # None for all bins being zero
350  return None
351  else:
352  return xaxis.GetBinLowEdge(xaxis.GetFirst())
353  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
354  m = min([obj.GetX()[i] for i in range(0, obj.GetN())])
355  return m*0.9 if m > 0 else m*1.1
356  raise Exception("Unsupported type %s" % str(obj))
357 
def _getXmin(obj, limitToNonZeroContent=False)
Definition: plotting.py:342
#define str(s)

◆ _getYmax()

def plotting._getYmax (   obj,
  limitToNonZeroContent = False 
)
private

Definition at line 389 of file plotting.py.

References SiStripPI.max, FastTimerService_cff.range, and str.

Referenced by _findBoundsY().

389 def _getYmax(obj, limitToNonZeroContent=False):
390  if isinstance(obj, ROOT.TH2):
391  yaxis = obj.GetYaxis()
392  return yaxis.GetBinUpEdge(yaxis.GetLast())
393  elif isinstance(obj, ROOT.TH1):
394  if limitToNonZeroContent:
395  lst = [obj.GetBinContent(i) for i in range(1, obj.GetNbinsX()+1) if obj.GetBinContent(i) != 0 ]
396  return max(lst) if len(lst) != 0 else 0
397  else:
398  return obj.GetMaximum()
399  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
400  m = max([obj.GetY()[i] for i in range(0, obj.GetN())])
401  return m*1.1 if m > 0 else m*0.9
402  raise Exception("Unsupported type %s" % str(obj))
403 
def _getYmax(obj, limitToNonZeroContent=False)
Definition: plotting.py:389
#define str(s)

◆ _getYmaxWithError()

def plotting._getYmaxWithError (   th1)
private

Definition at line 404 of file plotting.py.

References SiStripPI.max, and FastTimerService_cff.range.

404 def _getYmaxWithError(th1):
405  return max([th1.GetBinContent(i)+th1.GetBinError(i) for i in range(1, th1.GetNbinsX()+1)])
406 
def _getYmaxWithError(th1)
Definition: plotting.py:404

◆ _getYmin()

def plotting._getYmin (   obj,
  limitToNonZeroContent = False 
)
private

Definition at line 374 of file plotting.py.

References SiStripPI.min, FastTimerService_cff.range, and str.

Referenced by _findBoundsY().

374 def _getYmin(obj, limitToNonZeroContent=False):
375  if isinstance(obj, ROOT.TH2):
376  yaxis = obj.GetYaxis()
377  return yaxis.GetBinLowEdge(yaxis.GetFirst())
378  elif isinstance(obj, ROOT.TH1):
379  if limitToNonZeroContent:
380  lst = [obj.GetBinContent(i) for i in range(1, obj.GetNbinsX()+1) if obj.GetBinContent(i) != 0 ]
381  return min(lst) if len(lst) != 0 else 0
382  else:
383  return obj.GetMinimum()
384  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
385  m = min([obj.GetY()[i] for i in range(0, obj.GetN())])
386  return m*0.9 if m > 0 else m*1.1
387  raise Exception("Unsupported type %s" % str(obj))
388 
def _getYmin(obj, limitToNonZeroContent=False)
Definition: plotting.py:374
#define str(s)

◆ _getYminIgnoreOutlier()

def plotting._getYminIgnoreOutlier (   th1)
private

Definition at line 407 of file plotting.py.

References createfilelist.int, and FastTimerService_cff.range.

Referenced by _findBoundsY().

407 def _getYminIgnoreOutlier(th1):
408  yvals = sorted([n for n in [th1.GetBinContent(i) for i in range(1, th1.GetNbinsX()+1)] if n>0])
409  if len(yvals) == 0:
410  return th1.GetMinimum()
411  if len(yvals) == 1:
412  return yvals[0]
413 
414  # Define outlier as being x10 less than minimum of the 95 % of the non-zero largest values
415  ind_min = len(yvals)-1 - int(len(yvals)*0.95)
416  min_val = yvals[ind_min]
417  for i in range(0, ind_min):
418  if yvals[i] > 0.1*min_val:
419  return yvals[i]
420 
421  return min_val
422 
def _getYminIgnoreOutlier(th1)
Definition: plotting.py:407

◆ _getYminMaxAroundMedian()

def plotting._getYminMaxAroundMedian (   obj,
  coverage,
  coverageRange = None 
)
private

Definition at line 423 of file plotting.py.

References createfilelist.int, FastTimerService_cff.range, and str.

Referenced by _findBoundsY().

423 def _getYminMaxAroundMedian(obj, coverage, coverageRange=None):
424  inRange = lambda x: True
425  inRange2 = lambda xmin,xmax: True
426  if coverageRange:
427  inRange = lambda x: coverageRange[0] <= x <= coverageRange[1]
428  inRange2 = lambda xmin,xmax: coverageRange[0] <= xmin and xmax <= coverageRange[1]
429 
430  if isinstance(obj, ROOT.TH1):
431  yvals = [obj.GetBinContent(i) for i in range(1, obj.GetNbinsX()+1) if inRange2(obj.GetXaxis().GetBinLowEdge(i), obj.GetXaxis().GetBinUpEdge(i))]
432  yvals = [x for x in yvals if x != 0]
433  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
434  yvals = [obj.GetY()[i] for i in range(0, obj.GetN()) if inRange(obj.GetX()[i])]
435  else:
436  raise Exception("Unsupported type %s" % str(obj))
437  if len(yvals) == 0:
438  return (0, 0)
439  if len(yvals) == 1:
440  return (yvals[0], yvals[0])
441  if len(yvals) == 2:
442  return (yvals[0], yvals[1])
443 
444  yvals.sort()
445  nvals = int(len(yvals)*coverage)
446  if nvals < 2:
447  # Take median and +- 1 values
448  if len(yvals) % 2 == 0:
449  half = len(yvals)//2
450  return ( yvals[half-1], yvals[half] )
451  else:
452  middle = len(yvals)//2
453  return ( yvals[middle-1], yvals[middle+1] )
454  ind_min = (len(yvals)-nvals)//2
455  ind_max = len(yvals)-1 - ind_min
456 
457  return (yvals[ind_min], yvals[ind_max])
458 
def _getYminMaxAroundMedian(obj, coverage, coverageRange=None)
Definition: plotting.py:423
#define str(s)

◆ _mergeBinLabels()

def plotting._mergeBinLabels (   labelsAll)
private

Definition at line 713 of file plotting.py.

References SiStripPI.max.

Referenced by _mergeBinLabelsX(), and _mergeBinLabelsY().

713 def _mergeBinLabels(labelsAll):
714  labels_merged = labelsAll[0]
715  for labels in labelsAll[1:]:
716  diff = difflib.unified_diff(labels_merged, labels, n=max(len(labels_merged), len(labels)))
717  labels_merged = []
718  operation = []
719  for item in diff: # skip the "header" lines
720  if item[:2] == "@@":
721  break
722  for item in diff:
723  operation.append(item[0])
724  lab = item[1:]
725  if lab in labels_merged:
726  # pick the last addition of the bin
727  ind = labels_merged.index(lab)
728  if operation[ind] == "-" and operation[-1] == "+":
729  labels_merged.remove(lab)
730  del operation[ind] # to keep xbinlabels and operation indices in sync
731  elif operation[ind] == "+" and operation[-1] == "-":
732  del operation[-1] # to keep xbinlabels and operation indices in sync
733  continue
734  else:
735  raise Exception("This should never happen")
736  labels_merged.append(lab)
737  # unified_diff returns empty diff if labels_merged and labels are equal
738  # so if labels_merged is empty here, it can be just set to labels
739  if len(labels_merged) == 0:
740  labels_merged = labels
741 
742  return labels_merged
743 
def _mergeBinLabels(labelsAll)
Definition: plotting.py:713

◆ _mergeBinLabelsX()

def plotting._mergeBinLabelsX (   histos)
private

Definition at line 707 of file plotting.py.

References _mergeBinLabels(), and FastTimerService_cff.range.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw(), and plotting.Plot.draw().

707 def _mergeBinLabelsX(histos):
708  return _mergeBinLabels([[h.GetXaxis().GetBinLabel(i) for i in range(1, h.GetNbinsX()+1)] for h in histos])
709 
def _mergeBinLabels(labelsAll)
Definition: plotting.py:713
def _mergeBinLabelsX(histos)
Definition: plotting.py:707

◆ _mergeBinLabelsY()

def plotting._mergeBinLabelsY (   histos)
private

Definition at line 710 of file plotting.py.

References _mergeBinLabels(), and FastTimerService_cff.range.

Referenced by plotting.Plot.draw().

710 def _mergeBinLabelsY(histos):
711  return _mergeBinLabels([[h.GetYaxis().GetBinLabel(i) for i in range(1, h.GetNbinsY()+1)] for h in histos])
712 
def _mergeBinLabelsY(histos)
Definition: plotting.py:710
def _mergeBinLabels(labelsAll)
Definition: plotting.py:713

◆ _modifyPadForRatio()

def plotting._modifyPadForRatio (   pad,
  ratioFactor 
)
private

Definition at line 119 of file plotting.py.

Referenced by ntuplePlotting.draw(), and ntuplePlotting.drawMany().

119 def _modifyPadForRatio(pad, ratioFactor):
120  pad.Divide(1, 2)
121 
122  divisionPoint = 1-1/ratioFactor
123 
124  topMargin = pad.GetTopMargin()
125  bottomMargin = pad.GetBottomMargin()
126  divisionPoint += (1-divisionPoint)*bottomMargin # correct for (almost-)zeroing bottom margin of pad1
127  divisionPointForPad1 = 1-( (1-divisionPoint) / (1-0.02) ) # then correct for the non-zero bottom margin, but for pad1 only
128 
129  # Set the lower point of the upper pad to divisionPoint
130  pad1 = pad.cd(1)
131  yup = 1.0
132  ylow = divisionPointForPad1
133  xup = 1.0
134  xlow = 0.0
135  pad1.SetPad(xlow, ylow, xup, yup)
136  pad1.SetFillStyle(4000) # transparent
137  pad1.SetBottomMargin(0.02) # need some bottom margin here for eps/pdf output (at least in ROOT 5.34)
138 
139  # Set the upper point of the lower pad to divisionPoint
140  pad2 = pad.cd(2)
141  yup = divisionPoint
142  ylow = 0.0
143  pad2.SetPad(xlow, ylow, xup, yup)
144  pad2.SetFillStyle(4000) # transparent
145  pad2.SetTopMargin(0.0)
146  pad2.SetBottomMargin(bottomMargin/(ratioFactor*divisionPoint))
147 
def _modifyPadForRatio(pad, ratioFactor)
Definition: plotting.py:119

◆ _setStyle()

def plotting._setStyle ( )
private

Definition at line 21 of file plotting.py.

21 def _setStyle():
22  _absoluteSize = True
23  if _absoluteSize:
24  font = 43
25  titleSize = 22
26  labelSize = 22
27  statSize = 14
28  else:
29  font = 42
30  titleSize = 0.05
31  labelSize = 0.05
32  statSize = 0.025
33 
34  ROOT.gROOT.SetStyle("Plain")
35  ROOT.gStyle.SetPadRightMargin(0.07)
36  ROOT.gStyle.SetPadLeftMargin(0.13)
37  ROOT.gStyle.SetTitleFont(font, "XYZ")
38  ROOT.gStyle.SetTitleSize(titleSize, "XYZ")
39  ROOT.gStyle.SetTitleOffset(1.2, "Y")
40  #ROOT.gStyle.SetTitleFontSize(0.05)
41  ROOT.gStyle.SetLabelFont(font, "XYZ")
42  ROOT.gStyle.SetLabelSize(labelSize, "XYZ")
43  ROOT.gStyle.SetTextSize(labelSize)
44  ROOT.gStyle.SetStatFont(font)
45  ROOT.gStyle.SetStatFontSize(statSize)
46 
47  ROOT.TGaxis.SetMaxDigits(4)
48 
def _setStyle()
Definition: plotting.py:21

◆ _th1IncludeOnlyBins()

def plotting._th1IncludeOnlyBins (   histos,
  xbinlabels 
)
private

Definition at line 744 of file plotting.py.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw(), and plotting.Plot.draw().

744 def _th1IncludeOnlyBins(histos, xbinlabels):
745  histos_new = []
746  for h in histos:
747  h_new = h.Clone(h.GetName()+"_xbinlabels")
748  h_new.SetBins(len(xbinlabels), h.GetBinLowEdge(1), h.GetBinLowEdge(1)+len(xbinlabels))
749  for i, label in enumerate(xbinlabels):
750  bin = h.GetXaxis().FindFixBin(label)
751  if bin >= 0:
752  h_new.SetBinContent(i+1, h.GetBinContent(bin))
753  h_new.SetBinError(i+1, h.GetBinError(bin))
754  else:
755  h_new.SetBinContent(i+1, 0)
756  h_new.SetBinError(i+1, 0)
757  histos_new.append(h_new)
758  return histos_new
759 
760 
def _th1IncludeOnlyBins(histos, xbinlabels)
Definition: plotting.py:744

◆ _th1RemoveEmptyBins()

def plotting._th1RemoveEmptyBins (   histos,
  xbinlabels 
)
private

Definition at line 607 of file plotting.py.

References FastTimerService_cff.range.

Referenced by trackingPlots.TrackingSeedingLayerTable.draw().

607 def _th1RemoveEmptyBins(histos, xbinlabels):
608  binsToRemove = set()
609  for b in range(1, histos[0].GetNbinsX()+1):
610  binEmpty = True
611  for h in histos:
612  if h.GetBinContent(b) > 0:
613  binEmpty = False
614  break
615  if binEmpty:
616  binsToRemove.add(b)
617 
618  if len(binsToRemove) > 0:
619  # filter xbinlabels
620  xbinlab_new = []
621  for i in range(len(xbinlabels)):
622  if (i+1) not in binsToRemove:
623  xbinlab_new.append(xbinlabels[i])
624  xbinlabels = xbinlab_new
625 
626  # filter histogram bins
627  histos_new = []
628  for h in histos:
629  values = []
630  for b in range(1, h.GetNbinsX()+1):
631  if b not in binsToRemove:
632  values.append( (h.GetXaxis().GetBinLabel(b), h.GetBinContent(b), h.GetBinError(b)) )
633 
634  if len(values) > 0:
635  h_new = h.Clone(h.GetName()+"_empty")
636  h_new.SetBins(len(values), h.GetBinLowEdge(1), h.GetBinLowEdge(1)+len(values))
637  for b, (l, v, e) in enumerate(values):
638  h_new.GetXaxis().SetBinLabel(b+1, l)
639  h_new.SetBinContent(b+1, v)
640  h_new.SetBinError(b+1, e)
641 
642  histos_new.append(h_new)
643  histos = histos_new
644 
645  return (histos, xbinlabels)
646 
def _th1RemoveEmptyBins(histos, xbinlabels)
Definition: plotting.py:607

◆ _th1ToOrderedDict()

def plotting._th1ToOrderedDict (   th1,
  renameBin = None 
)
private

Definition at line 100 of file plotting.py.

References FastTimerService_cff.range.

Referenced by trackingPlots.TrackingSummaryTable.create(), and plotting.AggregateBins.create().

100 def _th1ToOrderedDict(th1, renameBin=None):
101  values = collections.OrderedDict()
102  for i in range(1, th1.GetNbinsX()+1):
103  binLabel = th1.GetXaxis().GetBinLabel(i)
104  if renameBin is not None:
105  binLabel = renameBin(binLabel)
106  values[binLabel] = (th1.GetBinContent(i), th1.GetBinError(i))
107  return values
108 
def _th1ToOrderedDict(th1, renameBin=None)
Definition: plotting.py:100

◆ _th2RemoveEmptyBins()

def plotting._th2RemoveEmptyBins (   histos,
  xbinlabels,
  ybinlabels 
)
private

Definition at line 647 of file plotting.py.

References FastTimerService_cff.range.

647 def _th2RemoveEmptyBins(histos, xbinlabels, ybinlabels):
648  xbinsToRemove = set()
649  ybinsToRemove = set()
650  for ih, h in enumerate(histos):
651  for bx in range(1, h.GetNbinsX()+1):
652  binEmpty = True
653  for by in range(1, h.GetNbinsY()+1):
654  if h.GetBinContent(bx, by) > 0:
655  binEmpty = False
656  break
657  if binEmpty:
658  xbinsToRemove.add(bx)
659  elif ih > 0:
660  xbinsToRemove.discard(bx)
661 
662  for by in range(1, h.GetNbinsY()+1):
663  binEmpty = True
664  for bx in range(1, h.GetNbinsX()+1):
665  if h.GetBinContent(bx, by) > 0:
666  binEmpty = False
667  break
668  if binEmpty:
669  ybinsToRemove.add(by)
670  elif ih > 0:
671  ybinsToRemove.discard(by)
672 
673  if len(xbinsToRemove) > 0 or len(ybinsToRemove) > 0:
674  xbinlabels_new = []
675  xbins = []
676  for b in range(1, len(xbinlabels)+1):
677  if b not in xbinsToRemove:
678  xbinlabels_new.append(histos[0].GetXaxis().GetBinLabel(b))
679  xbins.append(b)
680  xbinlabels = xbinlabels_new
681  ybinlabels_new = []
682  ybins = []
683  for b in range(1, len(ybinlabels)+1):
684  if b not in ybinsToRemove:
685  ybinlabels.append(histos[0].GetYaxis().GetBinLabel(b))
686  ybins.append(b)
687  ybinlabels = xbinlabels_new
688 
689  histos_new = []
690  if len(xbinlabels) == 0 or len(ybinlabels) == 0:
691  return (histos_new, xbinlabels, ybinlabels)
692  for h in histos:
693  h_new = ROOT.TH2F(h.GetName()+"_empty", h.GetTitle(), len(xbinlabels),0,len(xbinlabels), len(ybinlabels),0,len(ybinlabels))
694  for b, l in enumerate(xbinlabels):
695  h_new.GetXaxis().SetBinLabel(b+1, l)
696  for b, l in enumerate(ybinlabels):
697  h_new.GetYaxis().SetBinLabel(b+1, l)
698 
699  for ix, bx in enumerate(xbins):
700  for iy, by in enumerate(ybins):
701  h_new.SetBinContent(ix+1, iy+1, h.GetBinContent(bx, by))
702  h_new.SetBinError(ix+1, iy+1, h.GetBinError(bx, by))
703  histos_new.append(h_new)
704  histos = histos_new
705  return (histos, xbinlabels, ybinlabels)
706 
def _th2RemoveEmptyBins(histos, xbinlabels, ybinlabels)
Definition: plotting.py:647

Variable Documentation

◆ _gr

plotting._gr
private

Definition at line 243 of file plotting.py.

◆ _plotStylesColor

plotting._plotStylesColor
private

Definition at line 1184 of file plotting.py.

◆ _plotStylesMarker

plotting._plotStylesMarker
private

Definition at line 1185 of file plotting.py.

◆ _ratio

plotting._ratio
private

Definition at line 203 of file plotting.py.

◆ _ratioYTitle

plotting._ratioYTitle
private

Definition at line 19 of file plotting.py.

◆ _th1

plotting._th1
private

Definition at line 195 of file plotting.py.

◆ _uncertainty

plotting._uncertainty
private

Definition at line 196 of file plotting.py.

◆ _xerrshigh

plotting._xerrshigh
private

Definition at line 247 of file plotting.py.

◆ _xerrslow

plotting._xerrslow
private

Definition at line 246 of file plotting.py.

◆ _xvalues

plotting._xvalues
private

Definition at line 245 of file plotting.py.

◆ _yerrshigh

plotting._yerrshigh
private

Definition at line 249 of file plotting.py.

◆ _yerrslow

plotting._yerrslow
private

Definition at line 250 of file plotting.py.

◆ _yvalues

plotting._yvalues
private

Definition at line 248 of file plotting.py.

◆ IgnoreCommandLineOptions

plotting.IgnoreCommandLineOptions

Definition at line 14 of file plotting.py.

◆ verbose

plotting.verbose

Definition at line 18 of file plotting.py.