6 import Validation.RecoTrack.plotting.plotting
as plotting
11 h.SetDirectory(tdirectory)
14 h.SetMarkerStyle(markerStyle)
15 h.SetMarkerColor(color)
21 _defaultStyles = [(
lambda c, m: (
lambda h:
applyStyle(h, c, m)))(color, ms)
for color, ms
in itertools.izip(plotting._plotStylesColor, plotting._plotStylesMarker)]
25 def draw(name, histos, styles=_defaultStyles, legendLabels=[], **kwargs):
32 if not "ratioFactor" in args:
33 args[
"ratioFactor"] = _ratioFactor
34 ratio = args.get(
"ratio",
False)
37 height =
int(height*ratioFactor)
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)))
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)
68 for h, l
in zip(histos, legendLabels):
69 legend.AddEntry(h, l,
"L")
83 xtitle=None, ytitle=None,
85 legendDx=0, legendDy=0, legendDw=0, legendDh=0,
86 xmin=None, ymin=0, xmax=None, ymax=None, xlog=False, ylog=False,
87 xgrid=True, ygrid=True,
88 ratio=False, ratioYmin=0.5, ratioYmax=1.5, ratioYTitle=plotting._ratioYTitle, ratioFactor=1.25):
92 ratioBounds = (bounds[0], ratioYmin, bounds[2], ratioYmax)
93 frame =
plotting.FrameRatio(pad, bounds, ratioBounds, ratioFactor, ratioYTitle=ratioYTitle, nrows=nrows)
98 if xtitle
is not None:
99 frame.setXTitle(xtitle)
100 if ytitle
is not None:
101 frame.setYTitle(ytitle)
105 frame.setGridx(xgrid)
106 frame.setGridy(ygrid)
110 for i, h
in enumerate(histos):
111 st = styles[i%len(styles)]
113 h.Draw(drawOpt+
" same")
126 def drawMany(name, histoDicts, styles=_defaultStyles, opts={}, ncolumns=4):
127 if len(histoDicts) == 0:
130 histoNames = histoDicts[0].
keys()
132 ratioFactor = _ratioFactor
133 for opt
in six.itervalues(opts):
136 if "ratioFactor" in opt:
137 ratioFactor =
max(ratioFactor, opt[
"ratioFactor"])
139 nhistos = len(histoNames)
140 nrows =
int((nhistos+ncolumns-1)/ncolumns)
145 height =
int(_ratioFactor*height)
148 canvas.Divide(ncolumns, nrows)
150 histos = collections.defaultdict(list)
153 for n, h
in six.iteritems(d):
156 for i, histoName
in enumerate(histoNames):
160 args.update(opts.get(histoName, {}))
162 if not "ratioFactor" in args:
163 args[
"ratioFactor"] = _ratioFactor
166 frame =
drawSingle(pad, histos[histoName], styles, nrows, **args)
169 frame._pad.RedrawAxis()
171 canvas.SaveAs(name+
".png")
172 canvas.SaveAs(name+
".pdf")