CMS 3D CMS Logo

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

Functions

def applyStyle
 
def draw
 
def drawMany
 
def drawSingle
 
def saveHistograms
 

Variables

list _defaultStyles = [(lambda c, m: (lambda h: applyStyle(h, c, m)))(color, ms) for color, ms in itertools.izip(plotting._plotStylesColor, plotting._plotStylesMarker)]
 
float _ratioFactor = 1.25
 

Function Documentation

def ntuplePlotting.applyStyle (   h,
  color,
  markerStyle 
)

Definition at line 12 of file ntuplePlotting.py.

12 
13 def applyStyle(h, color, markerStyle):
14  h.SetMarkerStyle(markerStyle)
15  h.SetMarkerColor(color)
16  h.SetMarkerSize(1.2)
17  h.SetLineColor(color)
18  h.SetLineWidth(2)
19 
# https://stackoverflow.com/questions/6076270/python-lambda-function-in-list-comprehensions
def ntuplePlotting.draw (   name,
  histos,
  styles = _defaultStyles,
  legendLabels = [],
  kwargs 
)

Definition at line 24 of file ntuplePlotting.py.

References plotting._createCanvas(), plotting._modifyPadForRatio(), drawSingle(), and ComparisonHelper.zip().

Referenced by SiPixelRecHitQuality::Packing.setProbabilityQ(), and SiPixelRecHitQuality::Packing.setProbabilityXY().

24 
25 def draw(name, histos, styles=_defaultStyles, legendLabels=[], **kwargs):
26  width = 600
27  height = 600
28  ratioFactor = 1.25
29 
30  args = {}
31  args.update(kwargs)
32  if not "ratioFactor" in args:
33  args["ratioFactor"] = _ratioFactor
34  ratio = args.get("ratio", False)
35 
36  if ratio:
37  height = int(height*ratioFactor)
38  c = plotting._createCanvas(name, width, height)
39  if ratio:
40  plotting._modifyPadForRatio(c, ratioFactor)
41 
42  frame = drawSingle(c, histos, styles, **args)
43 
44  if len(legendLabels) > 0:
45  if len(legendLabels) != len(histos):
46  raise Exception("Got %d histos but %d legend labels" % (len(histos), len(legendLabels)))
47  lx1 = 0.6
48  lx2 = 0.9
49  ly1 = 0.7
50  ly2 = 0.85
51 
52  lx1 += legendDx
53  lx2 += legendDx
54  ly1 += legendDy
55  ly2 += legendDy
56 
57  lx2 += legendDw
58  ly1 -= legendDh
59 
60  legend = ROOT.TLegend(lx1, ly1, lx2, ly2)
61  legend.SetLineColor(1)
62  legend.SetLineWidth(1)
63  legend.SetLineStyle(1)
64  legend.SetFillColor(0)
65  legend.SetMargin(0.07)
66  legend.SetBorderSize(0)
67 
68  for h, l in zip(histos, legendLabels):
69  legend.AddEntry(h, l, "L")
70 
71  legend.Draw()
72 
73  frame._pad.cd()
74 
75  c.Update()
76  c.RedrawAxis()
77  c.SaveAs(name+".png")
78  c.SaveAs(name+".pdf")
79 
def _createCanvas
Definition: plotting.py:109
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def _modifyPadForRatio
Definition: plotting.py:119
def ntuplePlotting.drawMany (   name,
  histoDicts,
  styles = _defaultStyles,
  opts = {},
  ncolumns = 4 
)

Definition at line 125 of file ntuplePlotting.py.

References plotting._createCanvas(), plotting._modifyPadForRatio(), bitset_utilities.append(), drawSingle(), relativeConstraints.keys, and SiStripPI.max.

126 def drawMany(name, histoDicts, styles=_defaultStyles, opts={}, ncolumns=4):
127  if len(histoDicts) == 0:
128  return
129 
130  histoNames = histoDicts[0].keys()
131  ratio = False
132  ratioFactor = _ratioFactor
133  for opt in opts.values():
134  if "ratio" in opt:
135  ratio = True
136  if "ratioFactor" in opt:
137  ratioFactor = max(ratioFactor, opt["ratioFactor"])
138 
139  nhistos = len(histoNames)
140  nrows = int((nhistos+ncolumns-1)/ncolumns)
141 
142  width = 500*ncolumns
143  height = 500*nrows
144  if ratio:
145  height = int(_ratioFactor*height)
146 
147  canvas = plotting._createCanvas(name, width, height)
148  canvas.Divide(ncolumns, nrows)
149 
150  histos = collections.defaultdict(list)
151 
152  for d in histoDicts:
153  for n, h in d.items():
154  histos[n].append(h)
155 
156  for i, histoName in enumerate(histoNames):
157  pad = canvas.cd(i+1)
158 
159  args = {}
160  args.update(opts.get(histoName, {}))
161  if "ratio" in args:
162  if not "ratioFactor" in args:
163  args["ratioFactor"] = _ratioFactor # use the default, not the max
164  plotting._modifyPadForRatio(pad, args["ratioFactor"])
165 
166  frame = drawSingle(pad, histos[histoName], styles, nrows, **args)
167  frame._pad.cd()
168  frame._pad.Update()
169  frame._pad.RedrawAxis()
170 
171  canvas.SaveAs(name+".png")
172  canvas.SaveAs(name+".pdf")
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
def _createCanvas
Definition: plotting.py:109
def _modifyPadForRatio
Definition: plotting.py:119
def ntuplePlotting.drawSingle (   pad,
  histos,
  styles = _defaultStyles,
  nrows = 1,
  xtitle = None,
  ytitle = None,
  drawOpt = "HIST",
  legendDx = 0,
  legendDy = 0,
  legendDw = 0,
  legendDh = 0,
  xmin = None,
  ymin = 0,
  xmax = None,
  ymax = None,
  xlog = False,
  ylog = False,
  xgrid = True,
  ygrid = True,
  ratio = False,
  ratioYmin = 0.5,
  ratioYmax = 1.5,
  ratioYTitle = plotting._ratioYTitle,
  ratioFactor = 1.25 
)

Definition at line 87 of file ntuplePlotting.py.

References plotting._calculateRatios(), and plotting._findBounds().

Referenced by draw(), and drawMany().

87 
88  ratio=False, ratioYmin=0.5, ratioYmax=1.5, ratioYTitle=plotting._ratioYTitle, ratioFactor=1.25):
89 
90  bounds = plotting._findBounds(histos, ylog, xmin, xmax, ymin, ymax)
91  if ratio:
92  ratioBounds = (bounds[0], ratioYmin, bounds[2], ratioYmax)
93  frame = plotting.FrameRatio(pad, bounds, ratioBounds, ratioFactor, ratioYTitle=ratioYTitle, nrows=nrows)
94  #frame._frameRatio.GetYaxis().SetLabelSize(0.12)
95  else:
96  frame = plotting.Frame(pad, bounds, nrows=nrows)
97 
98  if xtitle is not None:
99  frame.setXTitle(xtitle)
100  if ytitle is not None:
101  frame.setYTitle(ytitle)
102 
103  frame.setLogx(xlog)
104  frame.setLogy(ylog)
105  frame.setGridx(xgrid)
106  frame.setGridy(ygrid)
107 
108  if ratio:
109  frame._pad.cd()
110  for i, h in enumerate(histos):
111  st = styles[i%len(styles)]
112  st(h)
113  h.Draw(drawOpt+" same")
114 
115  ratios = None
116  if ratio:
117  frame._padRatio.cd()
118  ratios = plotting._calculateRatios(histos)
119  for r in ratios[1:]:
120  r.draw()
121  frame._pad.cd()
122 
123  return frame
124 
def _findBounds
Definition: plotting.py:459
def _calculateRatios
Definition: plotting.py:148
def ntuplePlotting.saveHistograms (   tdirectory,
  histos 
)

Definition at line 8 of file ntuplePlotting.py.

8 
9 def saveHistograms(tdirectory, histos):
10  for h in histos:
11  h.SetDirectory(tdirectory)

Variable Documentation

list ntuplePlotting._defaultStyles = [(lambda c, m: (lambda h: applyStyle(h, c, m)))(color, ms) for color, ms in itertools.izip(plotting._plotStylesColor, plotting._plotStylesMarker)]

Definition at line 20 of file ntuplePlotting.py.

float ntuplePlotting._ratioFactor = 1.25

Definition at line 22 of file ntuplePlotting.py.