def drawPlots(plots, plotopts, rootopts, output, optzero, optmean, opth, optw): from ROOT import TPostScript, TCanvas, TLegend from ROOT import gROOT, gStyle, gPad gROOT.Reset() gROOT.SetStyle("Plain") gStyle.SetOptStat(0) gStyle.SetPalette(1) leg = TLegend(0.54, 0.71, 0.9, 0.9) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(10) leg.SetFillStyle(0) leg.SetBorderSize(0) if output != "DISPLAY": ps = TPostScript(output, 111) ps.NewPage() canv = TCanvas('c1', "Validation Plot Viewer", 600, 800) canv.Divide(opth, optw) maxperlist = opth * optw #current pad num = 0 #for stupid drawing system legends = [] #drawing hists for plotopt in plotopts: print "Drawing", plotopt.display_name num += 1 if (num > maxperlist and output != "DISPLAY"): #end of a current PS page ps.NewPage() print "new page" num = 1 canv.cd(num) gPad.SetLogy(plotopt.logy) leg.Clear() entries = {} valuemax = -999999.9 valuemin = 999999.9 entryZ = 0 for rootopt in rootopts: #get the max entries entries[rootopt] = plots[plotopt][rootopt].GetEntries() if (plots[plotopt][rootopt].GetEntries() > entryZ): entryZ = plots[plotopt][rootopt].GetEntries() for rootopt in rootopts: #get the max entries plot = plots[plotopt][rootopt] if (plotopt.profile): print rootopt.legendname, "is a profile: no need to scale" else: if not (entries[rootopt] == 0): print "scaling", rootopt.legendname, "to", entryZ / entries[ rootopt] plot.Scale(entryZ / entries[rootopt]) else: print rootopt.legendname, "is an empty hist, no scale" for rootopt in rootopts: #get the highest peak if (plots[plotopt][rootopt].GetMaximum() > valuemax): valuemax = plots[plotopt][rootopt].GetMaximum() entryZ = plots[plotopt][rootopt].GetEntries() sameDrawOpt = "" #now we plot all fillers, as otherwise they will render invisible everything behind them for rootopt in rootopts: if (rootopt.markerstyle > 0): #not filler continue plot = plots[plotopt][rootopt] print "Drawing filler from", rootopt.legendname if optzero: if (plotopt.logy == 1): plot.SetMinimum(1.0) else: plot.SetMinimum(0.0) plot.SetMaximum(valuemax * 1.1) plot.GetXaxis().SetTitle( plotopt.axis_captions[plotopt.vars_to_draw[0].lstrip("+")]) if len(plotopt.vars_to_draw) > 1: plot.GetYaxis().SetTitle( plotopt.axis_captions[plotopt.vars_to_draw[1].lstrip("+")]) if (plotopt.i2d): plot.Draw("CONT4Z " + sameDrawOpt) else: plot.Draw(rootopt.drawopt + sameDrawOpt) sameDrawOpt = " SAME" #plot the rest & fill the legend in the normal order for rootopt in rootopts: plot = plots[plotopt][rootopt] prname = rootopt.legendname if optmean and (not plotopt.profile): prname += " (mean: " + ("%.4f" % plot.GetMean()) + ")" leg.AddEntry(plot, prname, "L") if (rootopt.markerstyle == 0): #filler continue #fillers are already drawn print "Drawing plot from", rootopt.legendname if optzero: if (plotopt.logy == 1): plot.SetMinimum(1.0) else: plot.SetMinimum(0.0) plot.SetMaximum(valuemax * 1.1) plot.GetXaxis().SetTitle( plotopt.axis_captions[plotopt.vars_to_draw[0].lstrip("+")]) if len(plotopt.vars_to_draw) > 1: plot.GetYaxis().SetTitle( plotopt.axis_captions[plotopt.vars_to_draw[1].lstrip("+")]) if (plotopt.i2d): plot.Draw("CONT4Z " + sameDrawOpt) else: plot.Draw(rootopt.drawopt + sameDrawOpt) sameDrawOpt = " SAME" if not plotopt.i2d: legends.append(leg.Clone()) legends[len(legends) - 1].Draw() canv.Update() if output != "DISPLAY": canv.Close() ps.Close() return canv, legends
gROOT.SetBatch(args.batch) SetGlobalStyle(padleftmargin=0.18, padbottommargin=0.14) cCrossSec = TCanvas(f'c{histoName}', '', 700, 800) cCrossSec.SetLogy() hCrossSection.Draw() gCrossSectionSyst['Tot'].Draw('2') legFrac = TLegend(0.2, 0.84, 0.4, 0.94) legFrac.SetBorderSize(0) legFrac.SetFillStyle(0) legFrac.SetTextSize(0.045) legFrac.AddEntry(hPromptFrac, 'Prompt', 'p') legFrac.AddEntry(hFDFrac, 'Non-prompt', 'p') legEff = legFrac.Clone('legEff') legEff.SetY1(0.2) legEff.SetY2(0.4) cCrossSec.Update() cFrac = TCanvas('cFrac', '', 800, 800) cFrac.DrawFrame(hPromptFrac.GetBinLowEdge(1), 0., ptMax, 1.2, ';#it{p}_{T} (GeV/#it{c}); fraction') hPromptFrac.Draw('same') hFDFrac.Draw('same') legFrac.Draw() cFrac.Update() cEff = TCanvas('cEff', '', 800, 800) cEff.DrawFrame(hPromptFrac.GetBinLowEdge(1), 1.e-4, ptMax, 1., ';#it{p}_{T} (GeV/#it{c}); (Acc#times#font[152]{e})')
fMassKKMC[-1].Draw('same') hConfIntMassKKData[-1].DrawCopy('e3same') fMassKKData[-1].Draw('same') legMassKKsubFunc.Draw() cPtInt.Modified() cPtInt.Update() cEfficiencyVsCut = TCanvas('cEfficiencyVsCut', '', 500, 500) hFrameEff = cEfficiencyVsCut.DrawFrame( 4.5, 0., 25.5, 1., ';|#Delta#it{M}(KK)| selection;efficiency') hFrameEff.GetYaxis().SetDecimals() hEffPtIntMC.DrawCopy('epsame') hEffPtIntData.DrawCopy('epsame') cEfficiencyVsCut.Modified() cEfficiencyVsCut.Update() legEffPtInt = legMassKKsub.Clone() legEffPtInt.SetY1NDC(0.3) legEffPtInt.SetY2NDC(0.5) legEffPtInt.SetX1NDC(0.5) legEffPtInt.SetX2NDC(0.7) legEffPtInt.Draw() cEfficiencyVsCut.Modified() cEfficiencyVsCut.Update() # save outputs if not os.path.isdir(args.outputPath): os.mkdir(args.outputPath) cMassKKvsMassKKpiMC.SaveAs( os.path.join(args.outputPath, 'MassKK_vs_MassKKpi_vs_pt_MC.pdf')) cMassKKvsMassKKpiData.SaveAs( os.path.join(args.outputPath, 'MassKK_vs_MassKKpi_vs_pt_Data.pdf'))
SetObjectStyle(gFracTrigEventsDouble2ProngB, color=632, markerstyle=24) SetObjectStyle(gFracTrigEventsDouble3ProngB, color=418, markerstyle=25) SetObjectStyle(gFracTrigEvents2ProngAnd3ProngB, color=864, markerstyle=26) SetObjectStyle(gPurityTrigEvents2ProngB, color=632, markerstyle=24) SetObjectStyle(gPurityTrigEvents3ProngB, color=418, markerstyle=25) SetObjectStyle(gPurityTrigEvents2ProngOr3ProngB, color=864, markerstyle=26) SetObjectStyle(gPurityTrigEventsDouble2ProngB, color=632, markerstyle=24) SetObjectStyle(gPurityTrigEventsDouble3ProngB, color=418, markerstyle=25) SetObjectStyle(gPurityTrigEvents2ProngAnd3ProngB, color=864, markerstyle=26) legSingle = TLegend(0.2, 0.2, 0.4, 0.4) legSingle.SetTextSize(0.045) legSingle.SetBorderSize(0) legSingle.SetHeader('Events with at least:') legSingle.SetFillStyle(0) legDouble = legSingle.Clone() legSingle.AddEntry(gFracTrigEvents2Prong, 'one 2-prong', 'p') legSingle.AddEntry(gFracTrigEvents3Prong, 'one 3-prong', 'p') legSingle.AddEntry(gFracTrigEvents2ProngOr3Prong, 'one 2-prong or one 3-prong', 'p') legDouble.AddEntry(gFracTrigEventsDouble2Prong, 'two 2-prong', 'p') legDouble.AddEntry(gFracTrigEventsDouble3Prong, 'two 3-prong', 'p') legDouble.AddEntry(gFracTrigEvents2ProngAnd3Prong, 'one 2-prong and one 3-prong', 'p') lat = TLatex() lat.SetNDC() lat.SetTextColor(1) lat.SetTextSize(0.045) lat.SetTextFont(42) cEffSingle = TCanvas('cEffSingle', '', 500, 500) cEffSingle.DrawFrame(-0.5, 1.e-8, 10.5, 1., ';#it{p}_{T} (GeV/#it{c}) > ;Fraction of events;')
canvas_rate.cd(1).SetGridy() canvas_rate.cd(2).SetGridx() canvas_rate.cd(2).SetGridy() #legendEff1 = TLegend(0.06, 0.8, 0.57, 0.997) legendEff1 = TLegend(0.06, 0.9, 0.5, 0.99) #legend.SetHeader(header.c_str()) # leg -> SetBorderSize(0); legendEff1.SetFillStyle(0) legendEff1.SetBorderSize(0) legendEff1.SetTextSize(0.03) legendEff1.SetMargin(0.2) legendEff2 = legendEff1.Clone() legendEff3 = legendEff1.Clone() # eff_c1.SetTopMargin(0.2) # eff_c2.SetTopMargin(0.2) # eff_c3.SetTopMargin(0.2) effFiles = [] def drawEffs(fileDir, type, quality, lineColor, pTresh = "0.5" ) : global first global logScalePadNum print ("first " + str(first) ) effFile = TFile(plotsDir + fileDir + 'efficiencyPlots.root' ) effFiles.append(effFile)
ptBinUp = ptAxis.GetBinUpEdge(i + 1) sPDFTitle = str(ptBinLow) + "_p_{T}_" + str(ptBinUp) legArr = [] for j in range(nEtaBins - 1): k = j if (j > 2): k += 1 etaBinLow = etaAxis.GetBinLowEdge(k + 1) etaBinUp = etaAxis.GetBinUpEdge(k + 1) sLegendHeader = str(etaBinLow) + "<|#eta|<" + str( etaBinUp) + ", " + str(ptBinLow) + "<p_{T}<" + str(ptBinUp) sName = str(etaBinLow) + "_" + str(etaBinUp) + "__" + str( ptBinLow) + "_" + str(ptBinUp) + "_" legArr.append(leg.Clone()) legArr[j].SetHeader(sLegendHeader) hProj = [] hProj.append(h[0].ProjectionZ(sName + "DEall", k + 1, k + 1, i + 1, i + 1)) hProj.append(h[1].ProjectionZ(sName + "DEflipped", k + 1, k + 1, i + 1, i + 1)) hProj.append(h[2].ProjectionZ(sName + "DEok", k + 1, k + 1, i + 1, i + 1)) hProj.append(h[3].ProjectionZ(sName + "DPTall", k + 1, k + 1, i + 1, i + 1)) hProj.append(h[4].ProjectionZ(sName + "DPTflipped", k + 1, k + 1, i + 1, i + 1)) hProj.append(h[5].ProjectionZ(sName + "DPTok", k + 1, k + 1, i + 1,
lat.SetTextSize(0.05) lat.SetTextColor(1) lat.SetTextFont(42) lineAtFive = TLine(0.1, 5., 200., 5.) lineAtFive.SetLineColor(1) lineAtFive.SetLineStyle(9) lineAtFive.SetLineWidth(2) gDummy = TGraphAsymmErrors(0) SetObjectStyle(gDummy, fillcolor=1, fillalpha=0.2, linecolor=0) legSignif = TLegend(0.2, 0.2, 0.8, 0.4) legSignif.SetTextSize(0.045) legSignif.SetFillStyle(0) legSignifVsLumi = legSignif.Clone() for (hist, legname) in zip(hEffAccPrompt, cfg['legendnames']): legSignif.AddEntry(hist, legname, 'lp') legSignifVsLumi.AddEntry(hist, legname, 'l') legSignif.AddEntry(gDummy, 'FONLL uncertainty', 'f') legSignifVsLumi.AddEntry(gDummy, 'FONLL uncertainty', 'f') legEff = TLegend(0.4, 0.2, 0.8, 0.45) legEff.SetTextSize(0.05) legEff.SetFillStyle(0) for (hist, legname) in zip(hEffAccPrompt, cfg['legendnames']): legEff.AddEntry(hist, legname, 'lp') cSignificanceVsPt = TCanvas('cSignificanceVsPt', '', 500, 500) hFrameVsPt = cSignificanceVsPt.DrawFrame(hSignificanceCent[0].GetBinLowEdge(1), 1.e-1, \ hSignificanceCent[0].GetXaxis().GetBinUpEdge(hSignificanceCent[0].GetNbinsX()), 4.e3, \