def draw(self): ## Make auxiliary lists of indices and hitogram names indices = range(len(self.trees)) hnames = ['h_%s_%d' % (self.name, i) for i in indices] ## Make the histograms for t, hname in zip(self.trees, hnames): expr = '%s>>%s' % (self.expression, hname) sel = '&'.join(['(%s)' % c for c in self.cuts if c.strip()]) if self.binning: expr += '(%s)' % self.binning t.Draw(expr, sel, 'goff') else: ## No binning is specified. ## Take extra care to use the same binning for all. ## Use automatic binning fro the first tree and apply it ## to all others. if id(t) == id(self.trees[0]): ## This is the first tree, use auto-binning. t.Draw(expr, sel) else: ## This is no the first tree, use same binning as ## for the first one t.Draw(expr, sel, 'same') ## Retrieve the histograms in put them in a list self.histos = [ROOT.gDirectory.Get(hn) for hn in hnames] ## Customize histos for h, c, ms in zip(self.histos, self.colors, self.markerstyles): h.Sumw2() if self.normalize_to_unit_area: nbins = h.GetXaxis().GetNbins() area = h.GetBinWidth(1) * h.Integral(1, nbins) h.Scale(1./area) h.GetXaxis().SetTitle(self.xtitle) h.GetYaxis().SetTitle(self.ytitle) h.SetTitle(self.title) h.SetStats(0) h.SetLineColor(c) h.SetMarkerColor(c) h.SetMarkerStyle(ms) ## Find the histogram with greatest y range maxima = [h.GetMaximum() for h in self.histos] highest = max(maxima) imax = maxima.index(highest) ## Draw the "highest" histo first to guarantee nice the y-range. self.histos[imax].Draw(self.drawopts[imax]) ## Draw all histograms for h, opt in zip(self.histos, self.drawopts): h.Draw(opt + 'same') ## Add the legend legend = Legend(self.histos, self.ltitles, **self.legendkwargs) legend.draw() ## Add latex labels latex = Latex(self.labels, self.labels_layout) latex.draw()
def draw(self): ## Make auxiliary lists of indices and hitogram names indices = range(len(self.trees)) hnames = ['h_%s_%d' % (self.name, i) for i in indices] ## Make the histograms for t, hname in zip(self.trees, hnames): expr = '%s>>%s' % (self.expression, hname) sel = '&'.join(['(%s)' % c for c in self.cuts if c.strip()]) if self.binning: expr += '(%s)' % self.binning t.Draw(expr, sel, 'goff') else: ## No binning is specified. ## Take extra care to use the same binning for all. ## Use automatic binning fro the first tree and apply it ## to all others. if id(t) == id(self.trees[0]): ## This is the first tree, use auto-binning. t.Draw(expr, sel) else: ## This is no the first tree, use same binning as ## for the first one t.Draw(expr, sel, 'same') ## Retrieve the histograms in put them in a list self.histos = [ROOT.gDirectory.Get(hn) for hn in hnames] ## Customize histos for h, c, ms in zip(self.histos, self.colors, self.markerstyles): h.Sumw2() if self.normalize_to_unit_area: nbins = h.GetXaxis().GetNbins() area = h.GetBinWidth(1) * h.Integral(1, nbins) h.Scale(1. / area) h.GetXaxis().SetTitle(self.xtitle) h.GetYaxis().SetTitle(self.ytitle) h.SetTitle(self.title) h.SetStats(0) h.SetLineColor(c) h.SetMarkerColor(c) h.SetMarkerStyle(ms) ## Find the histogram with greatest y range maxima = [h.GetMaximum() for h in self.histos] highest = max(maxima) imax = maxima.index(highest) ## Draw the "highest" histo first to guarantee nice the y-range. self.histos[imax].Draw(self.drawopts[imax]) ## Draw all histograms for h, opt in zip(self.histos, self.drawopts): h.Draw(opt + 'same') ## Add the legend legend = Legend(self.histos, self.ltitles, **self.legendkwargs) legend.draw() ## Add latex labels latex = Latex(self.labels, self.labels_layout) latex.draw()
def plot_mmgmass_with_fit_for_multiple_smearings(name, stargets, rtargets, colors, plotrange=(60, 105)): """Plot the smeared mmg mass for a number of different smearings.""" canvases.next(name).SetGrid() mmgMass.setRange('plot', *plotrange) plot = mmgMass.frame(roo.Range('plot')) plot.SetTitle("") slabels = [] rlabels = [] ## Loop over the various smearings. for starget, rtarget, color in zip(stargets, rtargets, colors): mydata = calibrator.get_smeared_data(starget, rtarget) model = ParametrizedKeysPdf('model', 'model', mmgMass, mmgMassSmearPeak, mmgMassSmearWidth, mydata, ROOT.RooKeysPdf.NoMirror, 1.5) model.fitTo(mydata, roo.PrintLevel(-1), roo.Range(60, 120), roo.SumW2Error(False)) mydata.plotOn(plot, roo.LineColor(color), roo.MarkerColor(color)) model.plotOn(plot, roo.LineColor(color), roo.Range('plot'), roo.NormRange('plot')) slabels.append([ 's\' = % 3.f %%, ' % starget + '#Delta m_{#mu#mu#gamma} = %.2f #pm %.2f %%' % ( 100 * (mmgMassSmearPeak.getVal() / 91.2 - 1.), 100 * mmgMassSmearPeak.getError() / 91.2 ), ]) rlabels.append([ 'r\' = %.1f %%, ' % rtarget + '#sigma_{eff}/#mu(m_{\mu\mu\gamma}) = % .2f #pm %.2f %%' % ( 100 * mmgMassSmearWidth.getVal() / mmgMassSmearPeak.getVal(), 100 * mmgMassSmearWidth.getError() / mmgMassSmearPeak.getVal(), ), ]) ## End of loop over the various smearings. plot.Draw() for i, (labels, color) in enumerate(zip(slabels, colors)): latex = Latex(labels, position=(0.18, 0.85 - i*0.055)) latex.SetTextColor(color) latex.draw() for i, (labels, color) in enumerate(zip(rlabels, colors)): latex = Latex(labels, position=(0.18, 0.85 - (len(slabels)+1) * 0.055 - i*0.055)) latex.SetTextColor(color) latex.draw()
def plot_mmgmass_for_multiple_smearings(name, stargets, rtargets, colors, plotrange=(76, 106)): canvases.next(name).SetGrid() plot = mmgMass.frame(roo.Range(*plotrange)) plot.SetTitle("MC for multiple smearing scenarious") multilabels = [] ## Loop over the various smearings. for starget, rtarget, color in zip(stargets, rtargets, colors): mydata = calibrator.get_smeared_data(starget, rtarget) mydata.plotOn(plot, roo.LineColor(color), roo.MarkerColor(color)) multilabels.append(['s_{target}: %.1f %%' % starget, 'r_{target}: %.1f %%'% rtarget,]) ## End of loop over the various smearings. plot.Draw() for i, (labels, color) in enumerate(zip(multilabels, colors)): latex = Latex(labels, position=(0.2, 0.85 - i*0.11)) latex.SetTextColor(color) latex.draw()
def plot_phoeres_with_fit_for_multiple_smearings(name, stargets, rtargets, colors, plotrange=(-30, 30)): """Plot the smeared photon energy response for a number of different smearings.""" canvases.next(name).SetGrid() phoERes.setRange('plot', *plotrange) plot = phoERes.frame(roo.Range('plot')) #plot.SetTitle("MC with paremetrized fit for multiple smearing scenarious") plot.SetTitle("") slabels = [] rlabels = [] ## Loop over the various smearings. for starget, rtarget, color in zip(stargets, rtargets, colors): mydata = calibrator.get_smeared_data(starget, rtarget) phoEResPdf.fitTo(mydata, roo.PrintLevel(-1), roo.SumW2Error(False)) mydata.plotOn(plot, roo.LineColor(color), roo.MarkerColor(color)) phoEResPdf.plotOn(plot, roo.LineColor(color), roo.Range('plot'), roo.NormRange('plot')) slabels.append([ 's\' = % 3.f %%, #Delta s_{fit} = % .2f #pm %.2f %%' % ( starget, phoScale.getVal() - starget, phoScale.getError() ), ]) rlabels.append([ 'r\' = %3.1f %%, #Delta r_{fit} = % .2f #pm %.2f %%' % ( rtarget, phoRes.getVal() - rtarget, phoRes.getError() ), ]) ## End of loop over the various smearings. plot.Draw() for i, (labels, color) in enumerate(zip(slabels, colors)): latex = Latex(labels, position=(0.18, 0.85 - i*0.055)) latex.SetTextColor(color) latex.draw() for i, (labels, color) in enumerate(zip(rlabels, colors)): latex = Latex(labels, position=(0.18, 0.85 - (len(slabels) + 1) * 0.055 - i * 0.055)) latex.SetTextColor(color) latex.draw()
# theory2.plotOn(plot, LineColor(kRed), LineStyle(kDashed)) plot.Draw() plots.append(plot) ## Photon Resolution canvases.next('phoERes').SetLogy() phoERes.SetTitle('E^{#gamma}_{reco}/E^{#gamma}_{gen} - 1') phoERes.setRange(-0.9,3.2) plot = phoERes.frame() plot.SetTitle('Photon Resolution Modeling Zoom Out') reducedData['phoERes'].plotOn(plot) phoEResShape.plotOn(plot) plot.Draw() plot.GetYaxis().SetRangeUser(1e-3, 1e4) llabels.position = (0.6, 0.83) llabels.draw() plots.append(plot) ## Photon Resolution Zoom In canvases.next('phoEResZoom') plot = phoERes.frame(Range(-0.25 + phoEScaleMC, 0.33 + phoEScaleMC)) plot.SetTitle('Photon Resolution Modeling Zoom In') reducedData['phoERes'].plotOn(plot) phoEResShape.plotOn(plot) plot.Draw() llabels.draw() llabels.position = (0.21, 0.83) plots.append(plot) ## ## Photon Resolution Zoom Out ## canvases.next('phoEResZoomOut')
labels.append('#Deltas = %.2f #pm %.2f %%' % (phoScale.getVal(), phoScale.getError())) latexlabels = Latex(labels, position = (0.25, 0.8)) ## Scan -log(L) vs photon scale sframe = phoScale.frame(Bins(100), Range(sFitted[-1] - 5*sFittedErr[-1], sFitted[-1] + 5*sFittedErr[-1])) nll = RooNLLVar('nll', 'nll', tmodel, data) nll.plotOn(sframe, ShiftToZero()) canvases.next(name + '_nll') phoScale.SetTitle('#Deltas') # sframe.GetXaxis().SetTitle('#Deltas (%)') sframe.GetYaxis().SetTitle('-#Delta log L(#Deltas)') sframe.Draw() latexlabels.draw() canvases.canvases[-1].Update() ## Display data overlaid with fitted and extrapolated models canvases.next(name + '_mmgMass') frame = mmgMass.frame(Range(60,120)) frame.SetTitle('') frame.GetXaxis().SetTitle( 'm_{#mu#mu#gamma} (GeV)' ) data.plotOn(frame) # m.plotOn(frame) tmodel.plotOn(frame) #tmodel.paramOn(frame) frame.Draw() latexlabels.draw()