CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
plotting Namespace Reference

Classes

class  AggregateBins
 
class  AggregateHistos
 
class  DQMSubFolder
 
class  FakeDuplicate
 
class  Frame
 
class  FrameRatio
 
class  FrameTGraph2D
 
class  Plot
 
class  PlotFolder
 
class  PlotGroup
 
class  Plotter
 
class  PlotterFolder
 
class  PlotterInstance
 
class  PlotterItem
 
class  ROC
 
class  Subtract
 

Functions

def _copyStyle
 
def _drawFrame
 
def _findBounds
 
def _getObject
 
def _getOrCreateObject
 
def _getXmax
 
def _getXmin
 
def _getYmax
 
def _getYmaxWithError
 
def _getYmin
 
def _getYminIgnoreOutlier
 

Variables

list _plotStylesColor = [4, 2, ROOT.kBlack, ROOT.kOrange+7, ROOT.kMagenta-3]
 
list _plotStylesMarker = [21, 20, 22, 34, 33]
 

Function Documentation

def plotting._copyStyle (   src,
  dst 
)
private

Definition at line 770 of file plotting.py.

771 def _copyStyle(src, dst):
772  properties = []
773  if hasattr(src, "GetLineColor") and hasattr(dst, "SetLineColor"):
774  properties.extend(["LineColor", "LineStyle", "LineWidth"])
775  if hasattr(src, "GetFillColor") and hasattr(dst, "SetFillColor"):
776  properties.extend(["FillColor", "FillStyle"])
777  if hasattr(src, "GetMarkerColor") and hasattr(dst, "SetMarkerColor"):
778  properties.extend(["MarkerColor", "MarkerSize", "MarkerStyle"])
779 
780  for prop in properties:
781  getattr(dst, "Set"+prop)(getattr(src, "Get"+prop)())
def _copyStyle
Definition: plotting.py:770
def plotting._drawFrame (   pad,
  bounds,
  xbinlabels = None,
  xbinlabelsize = None,
  xbinlabeloption = 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:
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 437 of file plotting.py.

438 def _drawFrame(pad, bounds, xbinlabels=None, xbinlabelsize=None, xbinlabeloption=None, suffix=""):
439  """Function to draw a frame
440 
441  Arguments:
442  pad -- TPad to where the frame is drawn
443  bounds -- List or 4-tuple for (xmin, ymin, xmax, ymax)
444 
445  Keyword arguments:
446  xbinlabels -- Optional list of strings for x axis bin labels
447  xbinlabelsize -- Optional number for the x axis bin label size
448  xbinlabeloption -- Optional string for the x axis bin options (passed to ROOT.TH1.LabelsOption())
449  suffix -- Optional string for a postfix of the frame name
450  """
451  if xbinlabels is None:
452  frame = pad.DrawFrame(*bounds)
453  else:
454  # Special form needed if want to set x axis bin labels
455  nbins = len(xbinlabels)
456  frame = ROOT.TH1F("hframe"+suffix, "", nbins, bounds[0], bounds[2])
457  frame.SetBit(ROOT.TH1.kNoStats)
458  frame.SetBit(ROOT.kCanDelete)
459  frame.SetMinimum(bounds[1])
460  frame.SetMaximum(bounds[3])
461  frame.GetYaxis().SetLimits(bounds[1], bounds[3])
462  frame.Draw("")
463 
464  xaxis = frame.GetXaxis()
465  for i in xrange(nbins):
466  xaxis.SetBinLabel(i+1, xbinlabels[i])
467  if xbinlabelsize is not None:
468  xaxis.SetLabelSize(xbinlabelsize)
469  if xbinlabeloption is not None:
470  frame.LabelsOption(xbinlabeloption)
471 
472  return frame
def _drawFrame
Definition: plotting.py:437
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
xmin -- Minimum y value; if None, take the minimum of TH1s
xmax -- Maximum y value; if None, take the maximum of TH1s

Definition at line 71 of file plotting.py.

References _getXmax(), _getXmin(), _getYmax(), _getYmin(), _getYminIgnoreOutlier(), alcazmumu_cfi.filter, bookConverter.max, and min().

Referenced by plotting.Plot.draw().

71 
72 def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None):
73  """Find x-y axis boundaries encompassing a list of TH1s if the bounds are not given in arguments.
74 
75  Arguments:
76  th1s -- List of TH1s
77  ylog -- Boolean indicating if y axis is in log scale or not (affects the automatic ymax)
78 
79  Keyword arguments:
80  xmin -- Minimum x value; if None, take the minimum of TH1s
81  xmax -- Maximum x value; if None, take the maximum of TH1s
82  xmin -- Minimum y value; if None, take the minimum of TH1s
83  xmax -- Maximum y value; if None, take the maximum of TH1s
84  """
85 
86  def y_scale_max(y):
87  if ylog:
88  return 1.5*y
89  return 1.05*y
90 
91  def y_scale_min(y):
92  # assuming log
93  return 0.9*y
94 
95  if xmin is None or xmax is None or ymin is None or ymax is None or isinstance(ymin, list) or isinstance(ymax, list):
96  xmins = []
97  xmaxs = []
98  ymins = []
99  ymaxs = []
100  for th1 in th1s:
101  xmins.append(_getXmin(th1))
102  xmaxs.append(_getXmax(th1))
103  if ylog and isinstance(ymin, list):
104  ymins.append(_getYminIgnoreOutlier(th1))
105  else:
106  ymins.append(_getYmin(th1))
107  ymaxs.append(_getYmax(th1))
108 # ymaxs.append(_getYmaxWithError(th1))
109 
110  if xmin is None:
111  xmin = min(xmins)
112  if xmax is None:
113  xmax = max(xmaxs)
114  if ymin is None:
115  ymin = min(ymins)
116  elif isinstance(ymin, list):
117  ym_unscaled = min(ymins)
118  ym = y_scale_min(ym_unscaled)
119  ymins_below = filter(lambda y: y<=ym, ymin)
120  if len(ymins_below) == 0:
121  ymin = min(ymin)
122  if ym_unscaled < ymin:
123  print "Histogram minimum y %f is below all given ymin values %s, using the smallest one" % (ym, str(ymin))
124  else:
125  ymin = max(ymins_below)
126 
127  if ymax is None:
128  ymax = y_scale_max(max(ymaxs))
129  elif isinstance(ymax, list):
130  ym_unscaled = max(ymaxs)
131  ym = y_scale_max(ym_unscaled)
132  ymaxs_above = filter(lambda y: y>ym, ymax)
133  if len(ymaxs_above) == 0:
134  ymax = max(ymax)
135  if ym_unscaled > ymax:
136  print "Histogram maximum y %f is above all given ymax values %s, using the maximum one" % (ym_unscaled, str(ymax))
137  else:
138  ymax = min(ymaxs_above)
139 
140 
141  for th1 in th1s:
142  th1.GetXaxis().SetRangeUser(xmin, xmax)
143  th1.GetYaxis().SetRangeUser(ymin, ymax)
144 
145  return (xmin, ymin, xmax, ymax)
def _getYmin
Definition: plotting.py:37
def _getXmax
Definition: plotting.py:29
def _getYminIgnoreOutlier
Definition: plotting.py:54
def _getXmin
Definition: plotting.py:21
def _getYmax
Definition: plotting.py:44
def _findBounds
Definition: plotting.py:71
T min(T a, T b)
Definition: MathUtil.h:58
def plotting._getObject (   tdirectory,
  name 
)
private

Definition at line 9 of file plotting.py.

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

9 
10 def _getObject(tdirectory, name):
11  obj = tdirectory.Get(name)
12  if not obj:
13  print "Did not find {obj} from {dir}".format(obj=name, dir=tdirectory.GetPath())
14  return None
15  return obj
def _getObject
Definition: plotting.py:9
def plotting._getOrCreateObject (   tdirectory,
  nameOrCreator 
)
private

Definition at line 16 of file plotting.py.

References _getObject().

Referenced by plotting.Plot._createOne(), plotting.AggregateBins.create(), and plotting.ROC.create().

16 
17 def _getOrCreateObject(tdirectory, nameOrCreator):
18  if hasattr(nameOrCreator, "create"):
19  return nameOrCreator.create(tdirectory)
20  return _getObject(tdirectory, nameOrCreator)
def _getObject
Definition: plotting.py:9
def _getOrCreateObject
Definition: plotting.py:16
def plotting._getXmax (   obj)
private

Definition at line 29 of file plotting.py.

References bookConverter.max.

Referenced by _findBounds().

29 
30 def _getXmax(obj):
31  if isinstance(obj, ROOT.TH1):
32  xaxis = obj.GetXaxis()
33  return xaxis.GetBinUpEdge(xaxis.GetLast())
34  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
35  return max([obj.GetX()[i] for i in xrange(0, obj.GetN())])*1.02
36  raise Exception("Unsupported type %s" % str(obj))
def _getXmax
Definition: plotting.py:29
def plotting._getXmin (   obj)
private

Definition at line 21 of file plotting.py.

References min().

Referenced by _findBounds().

21 
22 def _getXmin(obj):
23  if isinstance(obj, ROOT.TH1):
24  xaxis = obj.GetXaxis()
25  return xaxis.GetBinLowEdge(xaxis.GetFirst())
26  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
27  return min([obj.GetX()[i] for i in xrange(0, obj.GetN())])*0.9
28  raise Exception("Unsupported type %s" % str(obj))
def _getXmin
Definition: plotting.py:21
T min(T a, T b)
Definition: MathUtil.h:58
def plotting._getYmax (   obj)
private

Definition at line 44 of file plotting.py.

References bookConverter.max.

Referenced by _findBounds().

44 
45 def _getYmax(obj):
46  if isinstance(obj, ROOT.TH1):
47  return obj.GetMaximum()
48  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
49  return max([obj.GetY()[i] for i in xrange(0, obj.GetN())])
50  raise Exception("Unsupported type %s" % str(obj))
def _getYmax
Definition: plotting.py:44
def plotting._getYmaxWithError (   th1)
private

Definition at line 51 of file plotting.py.

References bookConverter.max.

51 
52 def _getYmaxWithError(th1):
53  return max([th1.GetBinContent(i)+th1.GetBinError(i) for i in xrange(1, th1.GetNbinsX()+1)])
def _getYmaxWithError
Definition: plotting.py:51
def plotting._getYmin (   obj)
private

Definition at line 37 of file plotting.py.

References min().

Referenced by _findBounds().

37 
38 def _getYmin(obj):
39  if isinstance(obj, ROOT.TH1):
40  return obj.GetMinimum()
41  elif isinstance(obj, ROOT.TGraph) or isinstance(obj, ROOT.TGraph2D):
42  return min([obj.GetY()[i] for i in xrange(0, obj.GetN())])
43  raise Exception("Unsupported type %s" % str(obj))
def _getYmin
Definition: plotting.py:37
T min(T a, T b)
Definition: MathUtil.h:58
def plotting._getYminIgnoreOutlier (   th1)
private

Definition at line 54 of file plotting.py.

References alcazmumu_cfi.filter.

Referenced by _findBounds().

54 
55 def _getYminIgnoreOutlier(th1):
56  yvals = filter(lambda n: n>0, [th1.GetBinContent(i) for i in xrange(1, th1.GetNbinsX()+1)])
57  yvals.sort()
58  if len(yvals) == 0:
59  return th1.GetMinimum()
60  if len(yvals) == 1:
61  return yvals[0]
62 
63  # Define outlier as being x10 less than minimum of the 95 % of the non-zero largest values
64  ind_min = len(yvals)-1 - int(len(yvals)*0.95)
65  min_val = yvals[ind_min]
66  for i in xrange(0, ind_min):
67  if yvals[i] > 0.1*min_val:
68  return yvals[i]
69 
70  return min_val
def _getYminIgnoreOutlier
Definition: plotting.py:54

Variable Documentation

list plotting._plotStylesColor = [4, 2, ROOT.kBlack, ROOT.kOrange+7, ROOT.kMagenta-3]

Definition at line 434 of file plotting.py.

list plotting._plotStylesMarker = [21, 20, 22, 34, 33]

Definition at line 435 of file plotting.py.