hct_recodR.SetTitle('') hct_recodR.DrawNormalized('HIST') hct_gendR.DrawNormalized('SAME HIST') l1 = TLegend(0.68, 0.76, 0.85, 0.86) l1.AddEntry(hct_gendR, 'Gen', 'l') l1.AddEntry(hct_recodR, 'Reco', 'l') l1.Draw('SAME') label.Draw("same") #c1.Print('h_hct_comp_dR_nor.pdf') c1.cd() c1.Clear() hct_recodR.SetTitle('') hct_recodR.Draw('HIST') hct_gendR.Draw('SAME HIST') l1.Clear() l1.AddEntry(hct_gendR, 'Gen', 'l') l1.AddEntry(hct_recodR, 'Reco', 'l') l1.Draw('SAME') label.Draw("same") #c1.Print('h_hct_comp_dR.pdf') c1.cd() c1.Clear() hut_gendR.SetLineColor(2) hut_recodR.SetLineColor(4) hut_recodR.SetStats(0) hut_recodR.SetTitle('') hut_recodR.DrawNormalized('HIST') hut_gendR.DrawNormalized('SAME HIST') l1.Clear()
def make_time_rod_evo(error_dict, rod_dict, results, doLock): c2 = TCanvas( 'c2', 'c2', 1000, 600) leg = TLegend(0.18,0.85,0.45,0.55) leg.SetLineColor(0) leg.SetFillStyle(0) leg.SetShadowColor(0) leg.SetBorderSize(0) leg.SetNColumns(2) R15 = TLine(431,0,431,60) R15.SetLineColorAlpha(kPink+10,0.4) R15.SetLineWidth(4) R16 = TLine(1820,0,1820,60) R16.SetLineColorAlpha(kMagenta+10,0.4) R16.SetLineWidth(4) R17 = TLine(3376,0,3376,60) R17.SetLineColorAlpha(kGreen-3,0.4) R17.SetLineWidth(4) TS1 = TLine(431,0,432,60) TS1.SetLineColorAlpha(kPink+10,0.5) TS1.SetLineWidth(5) TS2 = TLine(1415,0,1415,60) TS2.SetLineColorAlpha(kMagenta+3,0.5) TS2.SetLineWidth(5) leg2 = TLegend(0.18,0.45,0.35,0.55) leg2.SetLineColor(0) leg2.SetFillStyle(0) leg2.SetShadowColor(0) leg2.SetBorderSize(0) gStyle.SetLegendTextSize(0.030) leg2.AddEntry(R15, "End of 2015", 'lf') leg2.AddEntry(R16, "End of 2016", 'lf') leg2.AddEntry(R17, "End of 2017", 'lf') #leg2.AddEntry(TS2, "TS2", 'lf') for key,val in rod_dict.items(): TS1.SetY2(val*0.5) TS2.SetY2(val+1) R15.SetY2(val*0.3) R16.SetY2(val*0.5) R17.SetY2(val*0.8) times = {} times.clear() for e in error_bits: times['0x'+e] = [0] for error in results: pos_rod = error.text.find("ROD") + 4 pos_lock = error.text.find("Lock") + 15 pos_buff = error.text.find("buffer") + 17 if error.msgID == 'TRT::ROD05Module': rod = '0x'+str(error.text[pos_rod:pos_rod+6]) else: rod = str(error.text[pos_rod:pos_rod+8]) lock = str(error.text[pos_lock:pos_lock+3]) buff = str(error.text[pos_buff:pos_buff+3]) if key == rod and doLock and lock != '0xf': times[lock].append(error.sb_total_time) leg.Clear() mg = TMultiGraph() for e in error_bits: errs = [] for i,x in enumerate(times['0x'+e]): errs.append(i+0.0) errs.append(errs[-1]) #times['0x'+e].append(1800.0) times['0x'+e].append(results[-1].sb_total_time) gr = TGraph(len(times['0x'+e]), array(times['0x'+e]), array(errs)) gr.SetMarkerSize(0.7) if bin(int('0x'+e, 16))[2:].zfill(4) == '0111': leg.AddEntry(gr,'GOL 3',"lp"); elif bin(int('0x'+e, 16))[2:].zfill(4) == '1011': leg.AddEntry(gr,'GOL 2',"lp"); elif bin(int('0x'+e, 16))[2:].zfill(4) == '1101': leg.AddEntry(gr,'GOL 1',"lp"); elif bin(int('0x'+e, 16))[2:].zfill(4) == '1110': leg.AddEntry(gr,'GOL 0',"lp"); else: leg.AddEntry(gr,bin(int('0x'+e, 16))[2:].zfill(4),"lp"); mg.Add(gr,"pl"); mg.SetTitle("; Hours of stable beams; # of rocketio io lock errors"); mg.Draw("PMC PLC a"); R15.Draw() R16.Draw() R17.Draw() #TS1.Draw() #TS2.Draw() AtlasStyle.ATLAS_LABEL(0.19,.88, 1, "Internal") leg.Draw() leg2.Draw() AtlasStyle.myText(0.4, 0.88, kBlack, "ROD: " + key) leg.SetMargin(0.5) gPad.Modified() mg.GetXaxis().SetLimits(0,results[-1].sb_total_time) mg.SetMinimum(0.) mg.SetMaximum(val+1) c2.Update() c2.Print("plots/time_"+key+".pdf") c2.Clear()
def plotReRecoComparison(path, selection, plots, runRange, isMC, backgrounds, cmsExtra, doLog=True): for name in plots: plot = getPlot(name) plot.addRegion(selection) plot.cleanCuts() plot.cuts = plot.cuts % runRange.runCut hists = {} histsPrompt = {} hists["EE"], hists["MM"], hists["EM"] = getHistograms( path, plot, runRange, isMC, backgrounds) histsPrompt["EE"], histsPrompt["MM"], histsPrompt[ "EM"] = getHistograms("/home/jan/Trees/sw538v0477", plot, runRange, isMC, backgrounds) hCanvas = TCanvas("hCanvas", "Distribution", 800, 800) plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0.3, 1, 1) ratioPad = ROOT.TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3) setTDRStyle() plotPad.UseCurrentStyle() ratioPad.UseCurrentStyle() plotPad.Draw() ratioPad.Draw() plotPad.cd() legend = TLegend(0.6, 0.65, 0.95, 0.95) legend.SetFillStyle(0) legend.SetBorderSize(0) latex = ROOT.TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = ROOT.TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.06) latexCMS.SetNDC(True) latexCMSExtra = ROOT.TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.045) latexCMSExtra.SetNDC(True) for combination in ["EE", "MM", "EM"]: hCanvas.Clear() legend.Clear() plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0.3, 1, 1) ratioPad = ROOT.TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3) style = setTDRStyle() style.SetOptStat(0) plotPad.UseCurrentStyle() ratioPad.UseCurrentStyle() plotPad.Draw() ratioPad.Draw() plotPad.cd() hists[combination].SetMarkerStyle(21) histsPrompt[combination].SetMarkerStyle(22) hists[combination].SetMarkerColor(ROOT.kGreen + 3) histsPrompt[combination].SetMarkerColor(ROOT.kBlack) hists[combination].SetLineColor(ROOT.kGreen + 3) histsPrompt[combination].SetLineColor(ROOT.kBlack) if doLog: yMin = 0.1 yMax = max( hists[combination].GetBinContent( hists[combination].GetMaximumBin()), histsPrompt[combination].GetBinContent( histsPrompt[combination].GetMaximumBin())) * 10 plotPad.SetLogy() else: yMin = 0 yMax = max( hists[combination].GetBinContent( hists[combination].GetMaximumBin()), histsPrompt[combination].GetBinContent( histsPrompt[combination].GetMaximumBin())) * 1.5 plotPad.DrawFrame(plot.firstBin, yMin, plot.lastBin, yMax, "; %s ; %s" % (plot.xaxis, plot.yaxis)) hists[combination].Draw("samep") histsPrompt[combination].Draw("samep") legend.AddEntry(histsPrompt[combination], "Prompt reconstruction", "p") legend.AddEntry(hists[combination], "Jan22 ReReco", "p") #~ #~ legend.Draw("same") latex.DrawLatex(0.94, 0.96, "19.4-%s fb^{-1} (8 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.89, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.82 else: yLabelPos = 0.85 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) latex.DrawLatex( 0.9, 0.25, "yield ReReco: %d#pm%d yield prompt: %d#pm%d ratio: %.3f" % (hists[combination].Integral(), hists[combination].Integral()** 0.5, histsPrompt[combination].Integral(), histsPrompt[combination].Integral()** 0.5, hists[combination].Integral() / histsPrompt[combination].Integral())) print hists[combination].Integral( ), "+/-", hists[combination].Integral( )**0.5, histsPrompt[combination].Integral(), "+/-", histsPrompt[ combination].Integral()**0.5, hists[combination].Integral( ) / histsPrompt[combination].Integral() ratioPad.cd() #~ ratio = ROOT.TGraphAsymmErrors(hists[combination],histsPrompt[combination],"cp") #~ ratio.SetMarkerStyle(20) #~ ratio.SetMarkerColor(ROOT.kGreen+3) #~ ratio.SetLineColor(ROOT.kGreen+3) ratioGraphs = ratios.RatioGraph(hists[combination], histsPrompt[combination], plot.firstBin, plot.lastBin, title="ReReco/Prompt", yMin=0.0, yMax=2, ndivisions=10, color=ROOT.kGreen + 3, adaptiveBinning=0.25, labelSize=0.135) #~ ratioGraphs.draw(ROOT.gPad, True, False, True, chi2Pos=0.8) #~ ratioPad.DrawFrame(plot.firstBin,0,plot.lastBin,2,"; %s ; %s" %("","ReReco/Prompt")) #~ ratio.Draw("saeme") logLabel = "Log" if not doLog: logLabel = "NoLog" hCanvas.Print( "fig/reRecoCompare_%s_%s_%s_%s_%s_%s.pdf" % (selection.name, runRange.label, plot.variablePlotName, plot.additionalName, combination, logLabel))
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
def main(): gStyle.SetOptStat(0) c1 = TCanvas('c1', 'c1', 3) gPad.SetTickx() gPad.SetTicky() c1.SetLeftMargin(0.12) h_frame = TH1F('frame', '', 50, 0, 1000) h_frame.SetXTitle('P^{miss}_{T} (GeV)') h_frame.SetYTitle('Arbitrary units') h_frame.SetMaximum(0.4) h_higgsPt = TH1F('h_higgsPt', 'h_higgsPt', 50, 0, 1000) h_higgsPtList = [] for i in range(6): h_higgsPtList.append(TH1F(histName_zp2HDM[i], '', 50, 0, 1000)) h_higgsPtList[i].SetLineWidth(2) h_higgsPt_BarList = [] for i in range(6): h_higgsPt_BarList.append(TH1F(histName_bar[i], '', 40, 0, 800)) h_higgsPt_BarList[i].SetLineWidth(2) ## test code ''' ivVectList = getPtList(hApath) for fourV in ivVectList: h_higgsPt.Fill(fourV.pt) ''' ## loop all combination leg = TLegend(0.32, 0.57, 0.87, 0.87) leg.SetBorderSize(0) for i in range(3): ivVectList = getPtList(hApathList[i]) h_higgsPtList[i].SetLineColor(87 + 4 * i) leg.AddEntry(h_higgsPtList[i], legtext[i]) for fourV in ivVectList: h_higgsPtList[i].Fill(fourV.pt) for i in range(3): ivVectList = getPtList(hApathList_5[i]) h_higgsPtList[i + 3].SetLineColor(61 + 4 * i) leg.AddEntry(h_higgsPtList[i + 3], legtext_5[i]) for fourV in ivVectList: h_higgsPtList[i + 3].Fill(fourV.pt) h_frame.Draw('hist') #h_higgsPt.Draw('histsame') for i in range(6): h_higgsPtList[i].DrawNormalized('histsame') leg.Draw() c1.Print('Zp2HDM_higgsPt.pdf') colorList = [95, 91, 87, 61, 65, 69] #colorList = [61,95,65,91,69,87] ## Baryonic info_bar = TLatex(0, 0.255, 'CMS') info_bar_2 = TLatex(750, 0.255, '35.9 fb^{-1} (13 TeV)') info_bar.SetTextSize(0.03) info_bar_2.SetTextSize(0.03) info_bar_2.SetTextAlign(31) h_frame.SetMaximum(0.25) h_frame.SetAxisRange(0., 750., "X") leg.Clear() for i in range(6): ivVectList = getPtList('BaryonicFile/' + hApath_barList[i]) h_higgsPt_BarList[i].SetLineColor(colorList[i]) #h_higgsPt_BarList[i].SetLineColor(90-6*i) leg.AddEntry(h_higgsPt_BarList[i], legtext_bar[i]) for fourV in ivVectList: h_higgsPt_BarList[i].Fill(fourV.pt) h_frame.Draw('hist') for i in range(5, -1, -1): h_higgsPt_BarList[i].DrawNormalized('histsame') leg.Draw() info_bar.Draw() info_bar_2.Draw() c1.Print('Baryonic_higgsPt.pdf') f = TFile('rootFile/Zp2HDM_missPt.root', 'recreate') for i in range(6): h_higgsPtList[i].SetLineColor(1) h_higgsPtList[i].Write() f.Close() f = TFile('rootFile/BaryonicZp_missPt.root', 'recreate') for i in range(6): h_higgsPt_BarList[i].SetLineColor(1) h_higgsPt_BarList[i].Write() f.Close()
def compare_num_den(ratio=ratio): ### for i, a in enumerate(sample_list): print a chain[a] = TChain("trigger/tree") for j, ss in enumerate(sign_sampl[a]['files']): print "ss: ", ss chain[a].Add(NTUPLEDIR + ss + ".root") if variable[options.variable]['nbins'] > 0: hist[a] = TH1F(a, ";" + variable[options.variable]['title'], variable[options.variable]['nbins'], variable[options.variable]['min'], variable[options.variable]['max']) hist_num[a] = TH1F(a + "_num", ";" + variable[options.variable]['title'], variable[options.variable]['nbins'], variable[options.variable]['min'], variable[options.variable]['max']) hist_num[a].Sumw2() hist[a].Sumw2() print "variable: ", options.variable if "signal" in a: chain[a].Project(a, options.variable, cut_den_signal) print "cut denominator signal: ", cut_den_signal print "cut numerator signal: ", cut_num_signal else: chain[a].Project(a, options.variable, cut_den) print "cut denominator: ", cut_den print "cut numerator: ", cut_num hist[a].SetOption("%s" % chain[a].GetTree().GetEntriesFast()) if "signal" in a: chain[a].Project(a + "_num", options.variable, cut_num_signal) else: chain[a].Project(a + "_num", options.variable, cut_num) hist_num[a].SetOption("%s" % chain[a].GetTree().GetEntriesFast()) if options.variable == "nPV": bins = np.array([0., 10., 15., 20., 25., 30., 35., 40., 50., 70.]) else: bins = np.array([ 0., 20., 40., 60., 80., 100., 120., 140., 160., 180., 200., 250., 300., 500., 1000. ]) if len(bins_special): bins = bins_special if REBIN: hist[a] = hist[a].Rebin(len(bins) - 1, a + "_den2", bins) hist_num[a] = hist_num[a].Rebin(len(bins) - 1, a + "_num2", bins) can = TCanvas("can", "can", 1000, 800) #900 if ratio else 800) if COMPARE != "": can.Divide(1, 2) setTopPad(can.GetPad(1), ratio) setBotPad(can.GetPad(2), ratio) can.cd(1) can.cd(1).SetGrid() else: ratio = 0 can.SetGrid() can.cd() if ratio: if probe != PROBEL1: #leg = TLegend(0.12+0.3, 0.1, 0.68+0.2, 0.3)#0.45) leg = TLegend(0.12 + 0.3, 0.1, 0.68 + 0.25, 0.3 + 0.15) #0.45)#DCMS else: #leg = TLegend(0.12+0.3, 0.1, 0.68+0.2, 0.3)#0.45) leg = TLegend(0.12 + 0.3, 0.1, 0.68 + 0.5, 0.3 + 0.5) #0.45) leg.SetTextSize(0.032) leg.SetTextSize(0.045) #DCMS else: if probe != PROBEL1: leg = TLegend(0.1, 0.75, 0.68, 0.88) #0.45) else: leg = TLegend(0.1, 0.12, 0.68, 0.25) #0.45) leg.SetTextSize(0.028) if "DPG" in options.cut: leg = TLegend(0.3, 0.12, 0.88, 0.35) if not options.efficiency: can.SetLogy() leg = TLegend(0.5, 0.65, 0.68, 0.9) #0.45) leg.SetTextSize(0.028) #leg.SetFillStyle(0) for i, s in enumerate(sample_list): if options.efficiency: graph[s] = TGraphAsymmErrors() graph[s].BayesDivide(hist_num[s], hist[s]) else: if options.normalized: hist[s].Scale(1. / hist[s].Integral()) hist_num[s].Scale(1. / hist_num[s].Integral()) graph[s] = TGraphAsymmErrors(hist[s]) graph_num[s] = TGraphAsymmErrors(hist_num[s]) graph[s].SetMarkerSize(1.) graph[s].SetMarkerStyle(markers[i]) #(sign_sampl[s]['marker']) graph[s].SetMarkerColor(colors[i]) #(2) graph[s].SetFillColor(colors[i]) #(2) graph[s].SetLineColor(colors[i]) #(2) graph[s].SetLineWidth(2) if options.efficiency: graph[s].GetYaxis().SetRangeUser(0., maxeff) graph[s].GetYaxis().SetTitle( "Efficiency") #("Efficiency (L1+HLT)") graph[s].GetYaxis().SetTitleOffset(0.9) #("Efficiency (L1+HLT)") graph[s].GetYaxis().SetTitleSize(0.05) #DCMS else: graph[s].SetMinimum(0.01) graph_num[s].SetMarkerSize(1.) graph_num[s].SetMarkerStyle(markers[i]) #(sign_sampl[s]['marker']) graph_num[s].SetMarkerColor(colors[i + 3]) #(2) graph_num[s].SetFillColor(colors[i + 3]) #(2) graph_num[s].SetLineColor(colors[i + 3]) #(2) graph_num[s].SetLineWidth(2) graph_num[s].SetLineStyle(2) graph[s].GetXaxis().SetRangeUser(variable[options.variable]['min'], variable[options.variable]['max']) graph[s].GetXaxis().SetTitle(variable[options.variable]['title']) graph[s].GetXaxis().SetTitleSize(0.04) #DCMS graph[s].GetXaxis().SetTitleOffset(1.1) #?#if COMPARE=="": #?# graph[s].GetYaxis().SetTitleOffset(1.5) #?#else: #?# graph[s].GetYaxis().SetTitleOffset(1) eff[s] = TH1F() eff[s].Sumw2() eff[s] = hist_num[s].Clone("eff_" + s) eff[s].Divide(eff[s], hist[s], 1, 1, "cl=0.683 b(1,1) mode") if i == 0: graph[s].Draw("AP") else: graph[s].Draw("P,sames") if not options.efficiency: graph_num[s].Draw("P,sames") if PROBE_label != "": leg.SetHeader("#splitline{Ref: " + ref + "}{" + PROBE_label + "}") else: leg.SetHeader("#splitline{Ref: " + ref + "}{" + probe + "}") leg.AddEntry(graph[s], s + ', den', 'PL') leg.AddEntry(graph_num[s], s + ', num', 'PL') if COMPARE != "" and options.efficiency: if PROBE_label != "": leg.SetHeader("#splitline{Ref: " + ref + "}{Probe: " + PROBE_label + "}") else: leg.SetHeader("#splitline{Ref: " + ref + "}{" + probe + "}") if s == "signal": leg.AddEntry(graph[s], "Signal, m_{#pi} = 15, 20 GeV", 'PL') else: leg.AddEntry(graph[s], s, 'PL') elif COMPARE == "" and options.efficiency: leg.SetHeader("Ref: " + ref) if PROBE_label == "": leg.AddEntry(graph[s], probe, 'PL') else: leg.AddEntry(graph[s], PROBE_label, 'PL') if "DPG" in options.cut: leg.Clear() leg.SetHeader("Den: #mu trigger & 1 offline #mu; num: L1 seed") #leg.AddEntry(graph[s],s,'PL') leg.SetTextSize(0.036) #new_file = TFile("macro/rootfiles/MET_trigger_eff_data_" + sign_sampl[s]['label'] + sign_sampl[s]['howmany'] + "_" + str(options.variable) + "_" + options.dataset+ "_v5.root",'RECREATE') #graph[s].Write("graph_2018") if "DPG" in options.cut: leg.Clear() leg.SetHeader("Den: #mu trigger & 1 offline #mu; num: L1 seed") leg.AddEntry(graph[name_data], 'Data', 'PL') leg.AddEntry(graph[name_mc], 'MC backgrounds', 'PL') leg.SetTextSize(0.036) leg.SetBorderSize(0) leg.Draw() etichetta = TLatex() etichetta.SetNDC() etichetta.SetTextSize(0.04) etichetta.SetTextColor(1) if COMPARE == "": etichetta.DrawLatex(0.3, 0.4, sign_sampl[s]['nice_label']) latex = TLatex() latex.SetNDC() latex.SetTextSize(0.047) latex.SetTextColor(1) latex.SetTextFont(42) latex.SetTextAlign(33) latex.SetTextSize(0.051) #47 if LUMI > 0: if ratio: #latex.DrawLatex(0.9, 0.985, "%.1f fb^{-1} (13 TeV, 2016)" % (float(LUMI/1000.))) latex.DrawLatex(0.9, 0.99, "%.1f fb^{-1} (13 TeV, 2016)" % (float(LUMI / 1000.))) #DCMS else: latex.DrawLatex( 0.9, 0.96, "%.1f fb^{-1} (13 TeV, 2016)" % (float(LUMI / 1000.))) latex.SetTextFont(62) if ratio: latex.DrawLatex(0.20, 0.98, "CMS") else: latex.DrawLatex(0.20, 0.96, "CMS") latex.SetTextFont(52) if "DPG" in options.cut: if ratio: latex.DrawLatex(0.46, 0.98, "Work in Progress") else: latex.DrawLatex(0.46, 0.96, "Work in Progress") else: if ratio: if "SingleMu" in name_data: latex.DrawLatex(0.36, 0.98, "Preliminary") else: latex.DrawLatex(0.36, 0.98, "Simulation") else: if "SingleMu" in name_data: latex.DrawLatex(0.36, 0.96, "Preliminary") else: latex.DrawLatex(0.36, 0.96, "Simulation") can.Update() if COMPARE and name_mc != "" and name_data != "": can.cd(2) can.cd(2).SetGrid() err = eff[name_mc].Clone("EffErr;") err.SetTitle("") err.GetYaxis().SetTitle("Data / MC") err.GetYaxis().SetTitleOffset(0.9) err.GetYaxis().SetTitleSize(0.05) #DCMS err.GetXaxis().SetTitleSize(0.05) #DCMS for a in range(1, err.GetNbinsX() + 1): err.SetBinContent(a, 1) if eff[name_mc].GetBinContent(a) > 0: err.SetBinError(a, eff[name_mc].GetBinError( a)) #?#/eff[name_mc].GetBinContent(a)) setBotStyle(err, miny=0.5, maxy=1.5) errLine = err.Clone("errLine") errLine.SetLineWidth(2) errLine.SetFillStyle(0) errLine.SetLineColor(2) #L# errLine.SetLineStyle(2) #L# err.Draw("E2") errLine.Draw("SAME, HIST") res = eff[name_data].Clone("Residues") for a in range(0, res.GetNbinsX() + 1): if eff[name_mc].GetBinContent(a) > 0: res.SetBinContent( a, res.GetBinContent(a) / eff[name_mc].GetBinContent(a)) res.SetBinError( a, res.GetBinError(a) / eff[name_mc].GetBinContent(a)) setBotStyle(res, miny=0., maxy=2.) res.SetMarkerStyle(21) res.SetMarkerColor(1) res.SetLineColor(1) res.SetLineWidth(1) res.Draw("SAME, PE0") can.Update() outpath = "" outpath += "/afs/desy.de/user/l/lbenato/LLP_code/CMSSW_8_0_26_patch1/src/Analyzer/LLP/macro/TriggerTurnOn/" if not options.efficiency: outpath += "Distributions/" if options.goodplots: outpath = "/afs/desy.de/user/l/lbenato/LLP_code/CMSSW_8_0_26_patch1/src/Analyzer/LLP/macro/TriggerTurnOn/good_plots/" if COMPARE != "": compare_string = "_vs_" + COMPARE + "_" else: compare_string = "" if options.normalized: norm_label = "_norm" else: norm_label = "" if SAVE: if PROBE_label == "": can.Print(outpath + "TriggerTurnOn_" + sign_sampl[s]['label'] + sign_sampl[s]['howmany'] + compare_string + "_" + str((options.variable).replace('.', '_')) + "_" + str(probe) + "_" + str(options.cut) + "_" + options.dataset + goodstring + norm_label + "_v8trigger_DCMS.png") can.Print(outpath + "TriggerTurnOn_" + sign_sampl[s]['label'] + sign_sampl[s]['howmany'] + compare_string + "_" + str((options.variable).replace('.', '_')) + "_" + str(probe) + "_" + str(options.cut) + "_" + options.dataset + goodstring + norm_label + "_v8trigger_DCMS.pdf") else: can.Print(outpath + "TriggerTurnOn_" + sign_sampl[s]['label'] + sign_sampl[s]['howmany'] + compare_string + "_" + str((options.variable).replace('.', '_')) + "_" + PROBE_label + "_" + str(options.cut) + "_" + options.dataset + goodstring + norm_label + "_v8trigger_DCMS.png") can.Print(outpath + "TriggerTurnOn_" + sign_sampl[s]['label'] + sign_sampl[s]['howmany'] + compare_string + "_" + str((options.variable).replace('.', '_')) + "_" + PROBE_label + "_" + str(options.cut) + "_" + options.dataset + goodstring + norm_label + "_v8trigger_DCMS.pdf") if not gROOT.IsBatch(): raw_input("Press Enter to continue...")
def main(argv): VERBOSE = False # color scheme colors = (ROOT.kBlack, ROOT.kRed, ROOT.kYellow + 2, ROOT.kGreen + 2, ROOT.kBlue, ROOT.kMagenta, ROOT.kGray + 1) # XML file to parse parser = OptionParser(usage="\n create_stacked_times.py [XML file]") (options, args) = parser.parse_args(argv) filename = args[0] # Read in xml file and create tree, root tree = ET.parse(filename) # root element is <workflow_status> workflow_status = tree.getroot() summary = workflow_status.find('summary') workflow_name_text = summary.find('workflow_name').text # Create a dictionary between the auger_id # and a dictionary of times for that job dict_auger_id_times = {} # Create a list of auger_ids list_auger_ids = [] # Create a dictionary between the total time for the job # and a dictionary of times for that job dict_totaltime_times = {} # Create a list of total time list_totaltime = [] # Loop over all elements and grab the # - auger_id # - timestamps for each stage of job # and put the auger_id and times into a dictionary nTotal = 0 for attempt in workflow_status.iter('attempt'): # defaults auger_id_text = None auger_ts_submitted_text = None auger_ts_dependency_text = None auger_ts_pending_text = None auger_ts_staging_in_text = None auger_ts_active_text = None auger_ts_staging_out_text = None auger_ts_complete_text = None submitted_time = 0 dependency_time = 0 pending_time = 0 staging_in_time = 0 active_time = 0 staging_out_time = 0 complete_time = 0 auger_id = attempt.find('auger_id') if auger_id != None: auger_id_text = str(auger_id.text) if VERBOSE: print 'auger_id_text = ' + auger_id_text # submitted auger_ts_submitted = attempt.find('auger_ts_submitted') if auger_ts_submitted != None: auger_ts_submitted_text = str( auger_ts_submitted.text.rpartition(".0")[0]) submitted_time = calendar.timegm( datetime.strptime(auger_ts_submitted_text, '%Y-%m-%d %H:%M:%S').timetuple()) if VERBOSE: print 'submitted_time = ' + str(submitted_time) # dependency auger_ts_dependency = attempt.find('auger_ts_dependency') if auger_ts_dependency != None: auger_ts_dependency_text = str( auger_ts_dependency.text.rpartition(".0")[0]) dependency_time = calendar.timegm( datetime.strptime(auger_ts_dependency_text, '%Y-%m-%d %H:%M:%S').timetuple()) if VERBOSE: print 'dependency_time = ' + str(dependency_time) # pending auger_ts_pending = attempt.find('auger_ts_pending') if auger_ts_pending != None: auger_ts_pending_text = str( auger_ts_pending.text.rpartition(".0")[0]) pending_time = calendar.timegm( datetime.strptime(auger_ts_pending_text, '%Y-%m-%d %H:%M:%S').timetuple()) if VERBOSE: print 'pending_time = ' + str(pending_time) # staging_in auger_ts_staging_in = attempt.find('auger_ts_staging_in') if auger_ts_staging_in != None: auger_ts_staging_in_text = str( auger_ts_staging_in.text.rpartition(".0")[0]) staging_in_time = calendar.timegm( datetime.strptime(auger_ts_staging_in_text, '%Y-%m-%d %H:%M:%S').timetuple()) if VERBOSE: print 'staging_in_time = ' + str(staging_in_time) # active auger_ts_active = attempt.find('auger_ts_active') if auger_ts_active != None: auger_ts_active_text = str( auger_ts_active.text.rpartition(".0")[0]) active_time = calendar.timegm( datetime.strptime(auger_ts_active_text, '%Y-%m-%d %H:%M:%S').timetuple()) if VERBOSE: print 'active_time = ' + str(active_time) # staging_out auger_ts_staging_out = attempt.find('auger_ts_staging_out') if auger_ts_staging_out != None: auger_ts_staging_out_text = str( auger_ts_staging_out.text.rpartition(".0")[0]) staging_out_time = calendar.timegm( datetime.strptime(auger_ts_staging_out_text, '%Y-%m-%d %H:%M:%S').timetuple()) if VERBOSE: print 'staging_out_time = ' + str(staging_out_time) # complete auger_ts_complete = attempt.find('auger_ts_complete') if auger_ts_complete != None: auger_ts_complete_text = str( auger_ts_complete.text.rpartition(".0")[0]) complete_time = calendar.timegm( datetime.strptime(auger_ts_complete_text, '%Y-%m-%d %H:%M:%S').timetuple()) if VERBOSE: print 'complete_time = ' + str(complete_time) # Append the auger_id to the list if auger_id_text != None: list_auger_ids.append(int(auger_id_text)) # Update the dictionary of auger_ids and dictionary of times dict_times = { 'submitted': submitted_time, 'dependency': dependency_time, 'pending': pending_time, 'staging_in': staging_in_time, 'active': active_time, 'staging_out': staging_out_time, 'complete': complete_time } new_pair = {int(auger_id_text): dict_times} dict_auger_id_times.update(new_pair) if complete_time != 0 and submitted_time != 0: # Append the total time to the list list_totaltime.append(float(complete_time - submitted_time)) # Update the dictionary of totaltimes and dictionary of times new_pair = {float(complete_time - submitted_time): dict_times} dict_totaltime_times.update(new_pair) nTotal += 1 if VERBOSE: print 'nTotal = ', nTotal # Sort list of auger_ids, fill histograms list_auger_ids.sort() # Histograms for each stage hsubmitted = TH1F('hsubmitted', ';Auger ID;', nTotal, 1, nTotal + 1) hsubmitted.SetFillColor(colors[0]) hsubmitted.SetLineColor(colors[0]) hdependency = TH1F('hdependency', ';Auger ID;', nTotal, 1, nTotal + 1) hdependency.SetFillColor(colors[1]) hdependency.SetLineColor(colors[1]) hpending = TH1F('hpending', ';Auger ID;', nTotal, 1, nTotal + 1) hpending.SetFillColor(colors[2]) hpending.SetLineColor(colors[2]) hstaging_in = TH1F('hstaging_in', ';Auger ID;', nTotal, 1, nTotal + 1) hstaging_in.SetFillColor(colors[3]) hstaging_in.SetLineColor(colors[3]) hactive = TH1F('hactive', ';Auger ID;', nTotal, 1, nTotal + 1) hactive.SetFillColor(colors[4]) hactive.SetLineColor(colors[4]) hstaging_out = TH1F('hstaging_out', ';Auger ID;', nTotal, 1, nTotal + 1) hstaging_out.SetFillColor(colors[5]) hstaging_out.SetLineColor(colors[5]) bin = 1 for auger_id_num in list_auger_ids: duration_submitted = 0 duration_dependency = 0 duration_pending = 0 duration_staging_in = 0 duration_active = 0 duration_staging_out = 0 if dict_auger_id_times[auger_id_num][ 'dependency'] != 0 and dict_auger_id_times[auger_id_num][ 'submitted'] != 0: duration_submitted = float( dict_auger_id_times[auger_id_num]['dependency'] - dict_auger_id_times[auger_id_num]['submitted']) / 3600. if dict_auger_id_times[auger_id_num][ 'pending'] != 0 and dict_auger_id_times[auger_id_num][ 'dependency'] != 0: duration_dependency = float( dict_auger_id_times[auger_id_num]['pending'] - dict_auger_id_times[auger_id_num]['dependency']) / 3600. if dict_auger_id_times[auger_id_num][ 'staging_in'] != 0 and dict_auger_id_times[auger_id_num][ 'pending'] != 0: duration_pending = float( dict_auger_id_times[auger_id_num]['staging_in'] - dict_auger_id_times[auger_id_num]['pending']) / 3600. if dict_auger_id_times[auger_id_num][ 'active'] != 0 and dict_auger_id_times[auger_id_num][ 'staging_in'] != 0: duration_staging_in = float( dict_auger_id_times[auger_id_num]['active'] - dict_auger_id_times[auger_id_num]['staging_in']) / 3600. if dict_auger_id_times[auger_id_num][ 'staging_out'] != 0 and dict_auger_id_times[auger_id_num][ 'active'] != 0: duration_active = float( dict_auger_id_times[auger_id_num]['staging_out'] - dict_auger_id_times[auger_id_num]['active']) / 3600. if dict_auger_id_times[auger_id_num][ 'complete'] != 0 and dict_auger_id_times[auger_id_num][ 'staging_out'] != 0: duration_staging_out = float( dict_auger_id_times[auger_id_num]['complete'] - dict_auger_id_times[auger_id_num]['staging_out']) / 3600. hsubmitted.SetBinContent(bin, duration_submitted) hdependency.SetBinContent(bin, duration_dependency) hpending.SetBinContent(bin, duration_pending) hstaging_in.SetBinContent(bin, duration_staging_in) hactive.SetBinContent(bin, duration_active) hstaging_out.SetBinContent(bin, duration_staging_out) if VERBOSE: print 'bin = ' + str(bin) + '\n' \ + 'auger_id = ' + str(auger_id_num) + '\n' \ + 'submitted = ' + str(dict_auger_id_times[auger_id_num]['submitted']) + '\n' \ + 'dependency = ' + str(dict_auger_id_times[auger_id_num]['dependency']) + '\n' \ + 'pending = ' + str(dict_auger_id_times[auger_id_num]['pending']) + '\n' \ + 'staging_in = ' + str(dict_auger_id_times[auger_id_num]['staging_in']) + '\n' \ + 'active = ' + str(dict_auger_id_times[auger_id_num]['active']) + '\n' \ + 'staging_out = ' + str(dict_auger_id_times[auger_id_num]['staging_out']) + '\n' \ + 'complete = ' + str(dict_auger_id_times[auger_id_num]['complete']) + '\n' \ + ' submitted = ' + str(duration_submitted) + '\n' \ + ' dependency = ' + str(duration_dependency) + '\n' \ + ' pending = ' + str(duration_pending) + '\n' \ + ' staging_in = ' + str(duration_staging_in) + '\n' \ + ' active = ' + str(duration_active) + '\n' \ + ' staging_out = ' + str(duration_staging_out) + '\n' bin += 1 # Create stacked hist and add in all hists hstack_times_auger_id = THStack( "hstack_times_auger_id", ";job # ordered by Auger ID; total time (hrs)") hstack_times_auger_id.Add(hsubmitted) hstack_times_auger_id.Add(hdependency) hstack_times_auger_id.Add(hpending) hstack_times_auger_id.Add(hstaging_in) hstack_times_auger_id.Add(hactive) hstack_times_auger_id.Add(hstaging_out) latex = TLatex() latex.SetTextColor(ROOT.kBlack) latex.SetTextSize(0.05) latex.SetTextAlign(12) latex.SetNDC(1) legend = TLegend(0.20, 0.70, 0.80, 0.90) legend.SetBorderSize(0) legend.SetFillStyle(0) legend.SetNColumns(3) legend.AddEntry(hsubmitted, 'submitted', 'F') legend.AddEntry(hdependency, 'dependency', 'F') legend.AddEntry(hpending, 'pending', 'F') legend.AddEntry(hstaging_in, 'staging in', 'F') legend.AddEntry(hactive, 'active', 'F') legend.AddEntry(hstaging_out, 'staging out', 'F') #-------------------------------------------------------------------- # Draw histograms of stacked times against Auger ID order c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.12) c1.SetBottomMargin(0.12) hstack_times_auger_id.Draw() hstack_times_auger_id.GetXaxis().SetTitleSize(0.06) hstack_times_auger_id.GetXaxis().SetTitleOffset(0.800) hstack_times_auger_id.GetXaxis().SetLabelSize(0.05) hstack_times_auger_id.GetYaxis().SetTitleSize(0.06) hstack_times_auger_id.GetYaxis().SetTitleOffset(0.500) hstack_times_auger_id.GetYaxis().CenterTitle() hstack_times_auger_id.GetYaxis().SetLabelSize(0.05) hstack_times_auger_id.Draw() # need to redraw # Variable nTotal is total number of 'attempt's in XML file. # Compare this to the number of unique auger IDs: if len(list_auger_ids) != nTotal: print '# of attempt in XML file: ' + str(nTotal) + '\n' print '# of unique Auger IDs in list: ' + str( len(list_auger_ids)) + '\n' else: print 'Total number of unique Auger IDs matches number of attempts' text = "total submissions: " + str(nTotal) latex.DrawLatex(0.40, 0.95, text) legend.Draw('same') figureDir = 'html/figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/hstack_times_auger_id.png') c1.Close() # if VERBOSE: # print dict_totaltime_times.keys() # Sort list of totaltime, fill histograms list_totaltime.sort() # Histograms for each stage hsubmitted_totaltime = TH1F('hsubmitted_totaltime', ';Auger ID;', nTotal, 1, nTotal + 1) hsubmitted_totaltime.SetFillColor(colors[0]) hsubmitted_totaltime.SetLineColor(colors[0]) hdependency_totaltime = TH1F('hdependency_totaltime', ';Auger ID;', nTotal, 1, nTotal + 1) hdependency_totaltime.SetFillColor(colors[1]) hdependency_totaltime.SetLineColor(colors[1]) hpending_totaltime = TH1F('hpending_totaltime', ';Auger ID;', nTotal, 1, nTotal + 1) hpending_totaltime.SetFillColor(colors[2]) hpending_totaltime.SetLineColor(colors[2]) hstaging_in_totaltime = TH1F('hstaging_in_totaltime', ';Auger ID;', nTotal, 1, nTotal + 1) hstaging_in_totaltime.SetFillColor(colors[3]) hstaging_in_totaltime.SetLineColor(colors[3]) hactive_totaltime = TH1F('hactive_totaltime', ';Auger ID;', nTotal, 1, nTotal + 1) hactive_totaltime.SetFillColor(colors[4]) hactive_totaltime.SetLineColor(colors[4]) hstaging_out_totaltime = TH1F('hstaging_out_totaltime', ';Auger ID;', nTotal, 1, nTotal + 1) hstaging_out_totaltime.SetFillColor(colors[5]) hstaging_out_totaltime.SetLineColor(colors[5]) bin = 1 for totaltime in list_totaltime: duration_submitted = 0 duration_dependency = 0 duration_pending = 0 duration_staging_in = 0 duration_active = 0 duration_staging_out = 0 if dict_totaltime_times[totaltime][ 'dependency'] != 0 and dict_totaltime_times[totaltime][ 'submitted'] != 0: duration_submitted = float( dict_totaltime_times[totaltime]['dependency'] - dict_totaltime_times[totaltime]['submitted']) / 3600. if dict_totaltime_times[totaltime][ 'pending'] != 0 and dict_totaltime_times[totaltime][ 'dependency'] != 0: duration_dependency = float( dict_totaltime_times[totaltime]['pending'] - dict_totaltime_times[totaltime]['dependency']) / 3600. if dict_totaltime_times[totaltime][ 'staging_in'] != 0 and dict_totaltime_times[totaltime][ 'pending'] != 0: duration_pending = float( dict_totaltime_times[totaltime]['staging_in'] - dict_totaltime_times[totaltime]['pending']) / 3600. if dict_totaltime_times[totaltime][ 'active'] != 0 and dict_totaltime_times[totaltime][ 'staging_in'] != 0: duration_staging_in = float( dict_totaltime_times[totaltime]['active'] - dict_totaltime_times[totaltime]['staging_in']) / 3600. if dict_totaltime_times[totaltime][ 'staging_out'] != 0 and dict_totaltime_times[totaltime][ 'active'] != 0: duration_active = float( dict_totaltime_times[totaltime]['staging_out'] - dict_totaltime_times[totaltime]['active']) / 3600. if dict_totaltime_times[totaltime][ 'complete'] != 0 and dict_totaltime_times[totaltime][ 'staging_out'] != 0: duration_staging_out = float( dict_totaltime_times[totaltime]['complete'] - dict_totaltime_times[totaltime]['staging_out']) / 3600. hsubmitted_totaltime.SetBinContent(bin, duration_submitted) hdependency_totaltime.SetBinContent(bin, duration_dependency) hpending_totaltime.SetBinContent(bin, duration_pending) hstaging_in_totaltime.SetBinContent(bin, duration_staging_in) hactive_totaltime.SetBinContent(bin, duration_active) hstaging_out_totaltime.SetBinContent(bin, duration_staging_out) if VERBOSE: print 'bin = ' + str(bin) + '\n' \ + 'totaltime = ' + str(totaltime) + '\n' \ + 'submitted = ' + str(dict_totaltime_times[totaltime]['submitted']) + '\n' \ + 'dependency = ' + str(dict_totaltime_times[totaltime]['dependency']) + '\n' \ + 'pending = ' + str(dict_totaltime_times[totaltime]['pending']) + '\n' \ + 'staging_in = ' + str(dict_totaltime_times[totaltime]['staging_in']) + '\n' \ + 'active = ' + str(dict_totaltime_times[totaltime]['active']) + '\n' \ + 'staging_out = ' + str(dict_totaltime_times[totaltime]['staging_out']) + '\n' \ + 'complete = ' + str(dict_totaltime_times[totaltime]['complete']) + '\n' \ + ' submitted = ' + str(duration_submitted) + '\n' \ + ' dependency = ' + str(duration_dependency) + '\n' \ + ' pending = ' + str(duration_pending) + '\n' \ + ' staging_in = ' + str(duration_staging_in) + '\n' \ + ' active = ' + str(duration_active) + '\n' \ + ' staging_out = ' + str(duration_staging_out) + '\n' bin += 1 # Create stacked hist and add in all hists hstack_times_totaltime = THStack( "hstack_times_totaltime", ";job # ordered by total time; total time (hrs)") hstack_times_totaltime.Add(hsubmitted_totaltime) hstack_times_totaltime.Add(hdependency_totaltime) hstack_times_totaltime.Add(hpending_totaltime) hstack_times_totaltime.Add(hstaging_in_totaltime) hstack_times_totaltime.Add(hactive_totaltime) hstack_times_totaltime.Add(hstaging_out_totaltime) legend.Clear() legend.AddEntry(hsubmitted_totaltime, 'submitted', 'F') legend.AddEntry(hdependency_totaltime, 'dependency', 'F') legend.AddEntry(hpending_totaltime, 'pending', 'F') legend.AddEntry(hstaging_in_totaltime, 'staging in', 'F') legend.AddEntry(hactive_totaltime, 'active', 'F') legend.AddEntry(hstaging_out_totaltime, 'staging out', 'F') #-------------------------------------------------------------------- # Draw histograms of stacked times against total time order c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.12) c1.SetBottomMargin(0.12) hstack_times_totaltime.Draw() hstack_times_totaltime.GetXaxis().SetTitleSize(0.06) hstack_times_totaltime.GetXaxis().SetTitleOffset(0.800) hstack_times_totaltime.GetXaxis().SetLabelSize(0.05) hstack_times_totaltime.GetYaxis().SetTitleSize(0.06) hstack_times_totaltime.GetYaxis().SetTitleOffset(0.500) hstack_times_totaltime.GetYaxis().CenterTitle() hstack_times_totaltime.GetYaxis().SetLabelSize(0.05) hstack_times_totaltime.Draw() # need to redraw text = "total submissions: " + str(nTotal) latex.DrawLatex(0.40, 0.95, text) # Variable nTotal is total number of 'attempt's in XML file. # Compare this to the number of unique totaltimes: if len(list_totaltime) != nTotal: print '# of attempt in XML file: ' + str(nTotal) + '\n' print '# of unique total times in list: ' + str( len(list_totaltime)) + '\n' else: print 'Total number of unique total times matches number of attempts' legend.Draw('same') figureDir = 'html/figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/hstack_times_totaltime.png') c1.Close()
class DataMCPlot(object): '''Handles a Data vs MC plot. Features a list of histograms (some of them being stacked), and several Drawing functions. ''' _f_keeper = {} _t_keeper = {} def __init__(self, name): self.histosDict = {} self.histos = [] self.supportHist = None self.name = name self.stack = None self.legendOn = True self.legend = None # self.legendBorders = 0.20, 0.46, 0.44, 0.89 # self.legendPos = 'left' self.legendBorders = 0.20, 0.78, 0.80, 0.88 self.legendPos = 'top' # self.lastDraw = None # self.lastDrawArgs = None self.nostack = None self.blindminx = None self.blindmaxx = None self.groups = {} self.axisWasSet = False self.histPref = histPref def __contains__(self, name): return name in self.histosDict def __getitem__(self, name): return self.histosDict[name] def readTree(self, file_name, tree_name='tree', verbose=False, friend_func=None): '''Cache files/trees''' if file_name in self.__class__._t_keeper: ttree = self.__class__._t_keeper[file_name] if verbose: print 'got cached tree', ttree else: tfile = self.__class__._f_keeper[file_name] = TFile.Open(file_name) ttree = self.__class__._t_keeper[file_name] = tfile.Get(tree_name) if verbose: print 'read tree', ttree, 'from file', file_name if friend_func: file_name = friend_func(file_name) friend_tree = self.readTree(file_name, tree_name, verbose) ttree.AddFriend(friend_tree) gROOT.cd() return ttree def Blind(self, minx, maxx, blindStack): self.blindminx = minx self.blindmaxx = maxx if self.stack and blindStack: self.stack.Blind(minx, maxx) if self.nostack: for hist in self.nostack: if hist.style.drawAsData: hist.Blind(minx, maxx) def AddHistogram(self, name, histo, layer=0, legendLine=None, stack=True): '''Add a ROOT histogram, with a given name. Histograms will be drawn by increasing layer.''' tmp = Histogram(name, histo, layer, legendLine, stack=stack) self.histos.append(tmp) self.histosDict[name] = tmp return tmp def Group(self, groupName, namesToGroup, layer=None, style=None, silent=False): '''Group all histos with names in namesToGroup into a single histo with name groupName. All histogram properties are taken from the first histogram in namesToGroup. See UnGroup as well ''' groupHist = None realNames = [] actualNamesInGroup = [] for name in namesToGroup: hist = self.histosDict.get(name, None) if hist is None: if not silent: print 'warning, no histo with name', name continue if groupHist is None: groupHist = hist.Clone(groupName) self.histos.append(groupHist) self.histosDict[groupName] = groupHist else: groupHist.Add(hist) actualNamesInGroup.append(name) realNames.append(hist.realName) hist.on = False if groupHist: self.groups[groupName] = actualNamesInGroup groupHist.realName = ','.join(realNames) if style is not None: groupHist.SetStyle(style) self._ApplyPrefs() def UnGroup(self, groupName): '''Ungroup groupName, recover the histograms in the group''' group = self.groups.get(groupName, None) if group is None: print groupName, 'is not a group in this plot.' return for name in group: self.histosDict[name].on = True self.histosDict[groupName].on = False def Replace(self, name, pyhist): '''Not very elegant... should have a clone function in Histogram...''' oldh = self.histosDict.get(name, None) if oldh is None: print 'histogram', name, 'does not exist, cannot replace it.' return pythist = copy.deepcopy(pyhist) pythist.layer = oldh.layer pythist.stack = oldh.stack pythist.name = oldh.name pythist.legendLine = oldh.legendLine pythist.SetStyle(oldh.style) pythist.weighted.SetFillStyle(oldh.weighted.GetFillStyle()) index = self.histos.index(oldh) self.histosDict[name] = pythist self.histos[index] = pythist def _SortedHistograms(self, reverse=False): '''Returns the histogram dictionary, sorted by increasing layer, excluding histograms which are not "on". This function is used in all the Draw functions.''' byLayer = sorted(self.histos, key=attrgetter('layer')) byLayerOn = [hist for hist in byLayer if (hist.on is True)] if reverse: byLayerOn.reverse() return byLayerOn def Hist(self, histName): '''Returns a histogram. Print the DataMCPlot object to see which histograms are available.''' return self.histosDict[histName] def DrawNormalized(self, opt=''): '''All histograms are drawn as PDFs, even the stacked ones''' same = '' for hist in self._SortedHistograms(): hist.obj.DrawNormalized(same + opt) if same == '': same = 'same' self.DrawLegend() if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawNormalized' # self.lastDrawArgs = [ opt ] def Draw(self, opt=''): '''All histograms are drawn.''' same = '' self.supportHist = None for hist in self._SortedHistograms(): if self.supportHist is None: self.supportHist = hist hist.Draw(same + opt) if same == '': same = 'same' # set_trace() yaxis = self.supportHist.GetYaxis() yaxis.SetRangeUser(0.01, 1.5 * ymax(self._SortedHistograms())) self.DrawLegend() if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'Draw' # self.lastDrawArgs = [ opt ] def CreateLegend(self, ratio=False, print_norm=False): if self.legend is None: self.legend = TLegend(*self.legendBorders) self.legend.SetFillColor(0) self.legend.SetFillStyle(0) self.legend.SetLineColor(0) self.legend.SetLineWidth(1) self.legend.SetNColumns(5) # number of comps / 2 (or 3) + 1 self.legend.SetEntrySeparation(0.2) self.legend.SetColumnSeparation(0.2) self.legend.SetBorderSize(0) self.legend.SetMargin(0.25) else: self.legend.Clear() hists = self._SortedHistograms(reverse=True) if ratio: hists = hists[:-1] # removing the last histo. for index, hist in enumerate(hists): if print_norm: if not hist.legendLine: hist.legendLine = hist.name hist.legendLine += ' ({norm:.1f})'.format(norm=hist.Yield()) hist.AddEntry(self.legend) def DrawLegend(self, ratio=False, print_norm=False): '''Draw the legend.''' if self.legendOn: self.CreateLegend(ratio=ratio, print_norm=print_norm) self.legend.Draw('same') def DrawRatio(self, opt=''): '''Draw ratios : h_i / h_0. h_0 is the histogram with the smallest layer, and h_i, i>0 are the other histograms. if the DataMCPlot object contains N histograms, N-1 ratio plots will be drawn. To take another histogram as the denominator, change the layer of this histogram by doing: dataMCPlot.Hist("histName").layer = -99 ''' same = '' denom = None self.ratios = [] for hist in self._SortedHistograms(): if denom == None: denom = hist continue ratio = copy.deepcopy(hist) ratio.obj.Divide(denom.obj) ratio.obj.Draw(same) self.ratios.append(ratio) if same == '': same = 'same' self.DrawLegend(ratio=True) if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawRatio' # self.lastDrawArgs = [ opt ] def DrawDataOverMCMinus1(self, ymin=-0.5, ymax=0.5): stackedHists = [] dataHist = None for hist in self._SortedHistograms(): if hist.stack is False: dataHist = hist continue stackedHists.append(hist) self._BuildStack(stackedHists, ytitle='Data/MC') mcHist = self.BGHist() if dataHist == None: dataHist = mcHist # this was added to avoid crashes for SR plots (without data) self.dataOverMCHist = copy.deepcopy(dataHist) # self.dataOverMCHist.Add(mcHist, -1) self.dataOverMCHist.Divide(mcHist) self.dataOverMCHist.Draw() yaxis = self.dataOverMCHist.GetYaxis() yaxis.SetRangeUser(ymin + 1., ymax + 1.) yaxis.SetTitle('Data/MC') yaxis.SetNdivisions(5) fraclines = 0.2 if ymax <= 0.2 or ymin >= -0.2: fraclines = 0.1 self.DrawRatioLines(self.dataOverMCHist, fraclines, 1.) if TPad.Pad(): TPad.Pad().Update() def DrawRatioStack(self, opt='', xmin=None, xmax=None, ymin=None, ymax=None): '''Draw ratios. The stack is considered as a single histogram.''' denom = None # import pdb; pdb.set_trace() histForRatios = [] denom = None for hist in self._SortedHistograms(): if hist.stack is False: # if several unstacked histograms, the highest layer is used denom = hist continue histForRatios.append(hist) self._BuildStack(histForRatios, ytitle='MC/Data') self.stack.Divide(denom.obj) if self.blindminx and self.blindmaxx: self.stack.Blind(self.blindminx, self.blindmaxx) self.stack.Draw(opt, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) self.ratios = [] for hist in self.nostack: if hist is denom: continue ratio = copy.deepcopy(hist) ratio.obj.Divide(denom.obj) ratio.obj.Draw('same') self.ratios.append(ratio) self.DrawLegend(ratio=True) self.DrawRatioLines(denom, 0.2, 1) if TPad.Pad(): TPad.Pad().Update() def DrawNormalizedRatioStack(self, opt='', xmin=None, xmax=None, ymin=None, ymax=None): '''Draw ratios. The stack is considered as a single histogram. All histograms are normalized before computing the ratio''' denom = None histForRatios = [] for hist in self._SortedHistograms(): # taking the first histogram (lowest layer) # as the denominator histogram. if denom == None: denom = copy.deepcopy(hist) continue # other histograms will be divided by the denominator histForRatios.append(hist) self._BuildStack(histForRatios, ytitle='MC p.d.f. / Data p.d.f.') self.stack.Normalize() denom.Normalize() self.stack.Divide(denom.weighted) self.stack.Draw(opt, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) self.ratios = [] for hist in self.nostack: # print 'nostack ', hist ratio = copy.deepcopy(hist) ratio.Normalize() ratio.obj.Divide(denom.weighted) ratio.obj.Draw('same') self.ratios.append(ratio) self.DrawLegend(ratio=True) self.DrawRatioLines(denom, 0.2, 1) if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawNormalizedRatioStack' # self.lastDrawArgs = [ opt ] def DrawRatioLines(self, hist, frac=0.2, y0=1.): '''Draw a line at y = 1, at 1+frac, and at 1-frac. hist is used to get the x axis range.''' xmin = hist.obj.GetXaxis().GetXmin() xmax = hist.obj.GetXaxis().GetXmax() line = TLine() line.DrawLine(xmin, y0, xmax, y0) line.SetLineStyle(2) line.DrawLine(xmin, y0 + frac, xmax, y0 + frac) line.DrawLine(xmin, y0 - frac, xmax, y0 - frac) def GetStack(self): '''Returns stack; builds stack if not there yet''' if not self.stack: self._BuildStack(self._SortedHistograms(), ytitle='Events') return self.stack def BGHist(self): return self.GetStack().totalHist def SignalHists(self): return [h for h in self.nostack if not h.style.drawAsData] def DrawStack(self, opt='', xmin=None, xmax=None, ymin=None, ymax=None, print_norm=False, scale_signal=''): '''Draw all histograms, some of them in a stack. if Histogram.stack is True, the histogram is put in the stack. scale_signal: mc_int -> scale to stack integral''' self._BuildStack(self._SortedHistograms(), ytitle='Events') same = 'same' if len(self.nostack) == 0: same = '' self.supportHist = None for hist in self.nostack: if hist.style.drawAsData: hist.Draw('SAME' if self.supportHist else '') else: if scale_signal == 'mc_int': hist.Scale(hist.Yield(weighted=True) / self.stack.integral) hist.Draw('SAME HIST' if self.supportHist else 'HIST') if not self.supportHist: self.supportHist = hist self.stack.Draw(opt + same, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) if self.supportHist is None: self.supportHist = self.BGHist() if not self.axisWasSet: mxsup = self.supportHist.weighted.GetBinContent( self.supportHist.weighted.GetMaximumBin()) mxstack = self.BGHist().weighted.GetBinContent( self.BGHist().weighted.GetMaximumBin()) mx = max(mxsup, mxstack) if ymin is None: ymin = 0.01 if ymax is None: ymax = mx * 2 centrality = self.supportHist.weighted.GetRMS() / ( self.supportHist.weighted.GetXaxis().GetXmax() - self.supportHist.weighted.GetXaxis().GetXmin()) if centrality > 0.15: ymax = mx * 2.2 self.supportHist.GetYaxis().SetRangeUser(ymin, ymax) self.axisWasSet = True for hist in self.nostack: if self.blindminx and hist.style.drawAsData: hist.Blind(self.blindminx, self.blindmaxx) if hist.style.drawAsData: hist.Draw('SAME') else: hist.Draw('SAME HIST') if self.supportHist.weighted.GetMaximumBin( ) < self.supportHist.weighted.GetNbinsX() / 2: # self.legendBorders = 0.62, 0.46, 0.88, 0.89 self.legendBorders = 0.20, 0.78, 0.80, 0.88 # self.legendPos = 'right' self.legendPos = 'top' self.DrawLegend(print_norm=print_norm) if TPad.Pad(): TPad.Pad().Update() # set_trace() def DrawNormalizedStack(self, opt='', xmin=None, xmax=None, ymin=0.001, ymax=None): '''Draw all histograms, some of them in a stack. if Histogram.stack is True, the histogram is put in the stack. all histograms out of the stack, and the stack itself, are shown as PDFs.''' self._BuildStack(self._SortedHistograms(), ytitle='p.d.f.') self.stack.DrawNormalized(opt, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) for hist in self.nostack: hist.obj.DrawNormalized('same') self.DrawLegend() if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawNormalizedStack' # self.lastDrawArgs = [ opt ] def Rebin(self, factor): '''Rebin, and redraw.''' # the dispatching technique is not too pretty, # but keeping a self.lastDraw function initialized to one of the Draw functions # when calling it creates a problem in deepcopy. for hist in self.histos: hist.Rebin(factor) self.axisWasSet = False def NormalizeToBinWidth(self): '''Normalize each Histograms bin to the bin width.''' for hist in self.histos: hist.NormalizeToBinWidth() def WriteDataCard(self, filename=None, verbose=True, mode='RECREATE', dir=None, postfix=''): '''Export current plot to datacard''' if not filename: filename = self.name + '.root' outf = TFile(filename, mode) if dir and outf.Get(dir): print 'Directory', dir, 'already present in output file' if any( outf.Get(dir + '/' + hist.name + postfix) for hist in self._SortedHistograms()): print 'Recreating file because histograms already present' outf = TFile(filename, 'RECREATE') if dir: outf_dir = outf.Get(dir) if not outf_dir: outf_dir = outf.mkdir(dir) outf_dir.cd() for hist in self._SortedHistograms(): 'Writing', hist, 'as', hist.name hist.weighted.Write(hist.name + postfix) outf.Write() def _BuildStack(self, hists, ytitle=None): '''build a stack from a list of Histograms. The histograms for which Histogram.stack is False are put in self.nostack''' self.stack = None self.stack = Stack(self.name + '_stack', ytitle=ytitle) self.nostack = [] for hist in hists: if hist.stack: self.stack.Add(hist) else: self.nostack.append(hist) def _GetHistPref(self, name): '''Return the preference dictionary for a given component''' thePref = None for prefpat, pref in self.histPref.iteritems(): if fnmatch.fnmatch(name, prefpat): if thePref is not None: print 'several matching preferences for', name thePref = pref if thePref is None: print 'cannot find preference for hist', name thePref = {'style': Style(), 'layer': 999, 'legend': name} return thePref def _ApplyPrefs(self): for hist in self.histos: pref = self._GetHistPref(hist.name) hist.layer = pref['layer'] hist.SetStyle(pref['style']) hist.legendLine = pref['legend'] def __str__(self): if self.stack is None: self._BuildStack(self._SortedHistograms(), ytitle='Events') tmp = [' '.join(['DataMCPlot: ', self.name])] tmp.append('Histograms:') for hist in self._SortedHistograms(reverse=True): tmp.append(' '.join(['\t', str(hist)])) tmp.append( 'Stack yield = {integ:7.1f}'.format(integ=self.stack.integral)) return '\n'.join(tmp)
def main(): gStyle.SetOptStat(0) zplist = [600,600,1200,1200,2000,2000] a0list = [300,400,300,500,300,600] c1 = TCanvas('c1','c1',3) gPad.SetTickx() gPad.SetTicky() c1.SetLeftMargin(0.12) h_frame = TH1F('frame','',60,0,1200) h_frame.SetXTitle('P^{miss}_{T} (GeV)') h_frame.SetYTitle('Arbitrary units') h_frame.SetMaximum(0.3) h_higgsPt = TH1F('h_higgsPt','h_higgsPt',60,0,1200) h_higgsPtList = [] rootfilelist = [] for i in range(6): fName = 'higgsPt_MZp'+str(zplist[i])+'_MA0'+str(a0list[i])+'.root' rootfile = TFile(fName) rootfilelist.append(rootfile) colorList = [61,95,65,91,69,87] for i in range(6): hist = rootfilelist[i].Get('h_higgsPt') hist.SetName('h_higgsPt_MZp'+str(zplist[i])+'_MA0'+str(a0list[i])) h_higgsPtList.append(hist) h_higgsPtList[i].SetLineWidth(2) h_higgsPtList[i].SetLineColor(colorList[i]) info_bar = TLatex(0,0.305,'CMS') info_bar_3 = TLatex(700,0.15,'#font[42]{tan#beta=1.0}') info_bar_2 = TLatex(1200,0.305,'35.9 fb^{-1} (13 TeV)') info_bar.SetTextSize(0.03) info_bar_2.SetTextSize(0.03) info_bar_3.SetTextSize(0.04) info_bar_2.SetTextAlign(31) leg = TLegend(0.32,0.57,0.87,0.87) leg.SetBorderSize(0) for j in range(3): i = 2*j text = 'M_{Z\'} = '+str(zplist[i])+' GeV, M_{A} = '+str(a0list[i])+' GeV' leg.AddEntry(h_higgsPtList[i],text) for j in range(3): i = 2*j+1 text = 'M_{Z\'} = '+str(zplist[i])+' GeV, M_{A} = '+str(a0list[i])+' GeV' leg.AddEntry(h_higgsPtList[i],text) h_frame.Draw('hist') for i in range(6): h_higgsPtList[i].DrawNormalized('histsame') leg.Draw() info_bar.Draw() info_bar_2.Draw() info_bar_3.Draw() c1.Print('Zp2HDM_higgsPt.pdf') ## Baryonic histName_bar = ['missPt_MZp1000_MDM500','missPt_MZp1000_MDM100','missPt_MZp1000_MDM1','missPt_MZp500_MDM1','missPt_MZp100_MDM1','missPt_MZp10_MDM1'] legtext_bar = ["M_{Z'}=1000 GeV,M_{#chi}=500 GeV","M_{Z'}=1000 GeV,M_{#chi}=100 GeV","M_{Z'}=1000 GeV,M_{#chi}=1 GeV","M_{Z'}=500 GeV,M_{#chi}=1 GeV",\ "M_{Z'}=100 GeV,M_{#chi}=1 GeV","M_{Z'}=10 GeV,M_{#chi}=1 GeV"] h_frame.SetMaximum(0.25) h_frame.SetAxisRange(0., 750.,"X") leg.Clear() info_bar = TLatex(0,0.255,'CMS') info_bar_2 = TLatex(750,0.255,'35.9 fb^{-1} (13 TeV)') info_bar.SetTextSize(0.03) info_bar_2.SetTextSize(0.03) info_bar_2.SetTextAlign(31) kOrange = 800 colorList = [kOrange-4,kOrange-1,kOrange+3,70,65,55] h_higgsPt_BarList = [] f = TFile('BaryonicZp_missPt.root') for i in range(6): hist = TH1F() hist = f.Get(histName_bar[i]) h_higgsPt_BarList.append(hist) for i in range(6): #h_higgsPt_BarList[i].SetLineColor(93-6*i) h_higgsPt_BarList[i].SetLineColor(colorList[i]) leg.AddEntry(h_higgsPt_BarList[i],legtext_bar[i]) h_frame.Draw('hist') for i in range(5,-1,-1):h_higgsPt_BarList[i].DrawNormalized('histsame') leg.Draw() info_bar.Draw() info_bar_2.Draw() c1.Print('Baryonic_higgsPt.pdf') f.Close() '''
def lumiDependency(path, plotName, selection, runRange, cmsExtra, bins): plot = getPlot(plotName) plot.addRegion(selection) plot.cleanCuts() plot.cuts = plot.cuts % runRange.runCut label = "" if "Forward" in selection.name: label = "forward" elif "Central" in selection.name: label = "central" else: label = "inclusive" corr = getattr(rSFOF, label).val corrUncert = getattr(rSFOF, label).err runCuts = [[190645, 194643], [194644, 195868], [195915, 198955], [198969, 200075], [200091, 201669], [201671, 202972], [202973, 205344], [205515, 206512], [206513, 207491], [207492, 208686]] #~ runCuts = [[190645,194897]] #~ xValues = [2,4,6,8,10,12,14,16,18,19.4] if bins: xValues = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5] xValuesUncert = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5] else: xValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 18.7] xValuesUncert = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0.7] yValues = [] yValuesUncert = [] yValuesBTagged = [] yValuesUncertBTagged = [] yValuesBVeto = [] yValuesUncertBVeto = [] sfList = [] ofList = [] sfValuesUncert = [] ofValuesUncert = [] sfListBTagged = [] ofListBTagged = [] sfValuesUncertBTagged = [] ofValuesUncertBTagged = [] sfListBVeto = [] ofListBVeto = [] sfValuesUncertBVeto = [] ofValuesUncertBVeto = [] eeList = [] mmList = [] eeValuesUncert = [] mmValuesUncert = [] cuts = plot.cuts for cutPair in runCuts: if bins: plot.cuts = plot.cuts + "*(runNr >= %d && runNr <= %d)" % ( cutPair[0], cutPair[1]) else: plot.cuts = plot.cuts + "*(runNr >= %d && runNr <= %d)" % ( runCuts[0][0], cutPair[1]) eeHist, mmHist, emHist = getHistograms(path, plot, runRange, False, [], label) plot.cuts = cuts if bins: plot.cuts = plot.cuts + "*(runNr >= %d && runNr <= %d)" % ( cutPair[0], cutPair[1]) + "*(nBJets == 0)" else: plot.cuts = plot.cuts + "*(runNr >= %d && runNr <= %d)" % ( runCuts[0][0], cutPair[1]) + "*(nBJets == 0)" eeHistBVeto, mmHistBVeto, emHistBVeto = getHistograms( path, plot, runRange, False, [], label) plot.cuts = cuts if bins: plot.cuts = plot.cuts + "*(runNr >= %d && runNr <= %d)" % ( cutPair[0], cutPair[1]) + "*(nBJets >= 1)" else: plot.cuts = plot.cuts + "*(runNr >= %d && runNr <= %d)" % ( runCuts[0][0], cutPair[1]) + "*(nBJets >= 1)" eeHistBTagged, mmHistBTagged, emHistBTagged = getHistograms( path, plot, runRange, False, [], label) plot.cuts = cuts ee = eeHist.Integral() mm = mmHist.Integral() sf = eeHist.Integral() + mmHist.Integral() of = emHist.Integral() * corr eeBTagged = eeHistBTagged.Integral() mmBTagged = mmHistBTagged.Integral() sfBTagged = eeHistBTagged.Integral() + mmHistBTagged.Integral() ofBTagged = emHistBTagged.Integral() eeBVeto = eeHistBVeto.Integral() mmBVeto = mmHistBVeto.Integral() sfBVeto = eeHistBVeto.Integral() + mmHistBVeto.Integral() ofBVeto = emHistBVeto.Integral() yValues.append(sf - of) yValuesUncert.append(getUncert(sf, of, corrUncert)) sfList.append(sf) ofList.append(of) sfValuesUncert.append(sf**0.5) ofValuesUncert.append((of + (of * corrUncert)**2)**0.5) yValuesBTagged.append(sfBTagged - ofBTagged) yValuesUncertBTagged.append(getUncert(sfBTagged, ofBTagged, corrUncert)) sfListBTagged.append(sfBTagged) ofListBTagged.append(ofBTagged) sfValuesUncertBTagged.append(sfBTagged**0.5) ofValuesUncertBTagged.append(ofBTagged**0.5) yValuesBVeto.append(sfBVeto - ofBVeto) yValuesUncertBVeto.append(getUncert(sfBVeto, ofBVeto, corrUncert)) sfListBVeto.append(sfBVeto) ofListBVeto.append(ofBVeto) sfValuesUncertBVeto.append(sfBVeto**0.5) ofValuesUncertBVeto.append(ofBVeto**0.5) eeList.append(ee) mmList.append(mm) eeValuesUncert.append(ee**0.5) mmValuesUncert.append(mm**0.5) hCanvas = TCanvas("hCanvas", "Distribution", 800, 800) plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1) style = setTDRStyle() style.SetTitleYOffset(1.25) plotPad.UseCurrentStyle() plotPad.Draw() plotPad.cd() if bins: legend = TLegend(0.45, 0.6, 0.9, 0.95) else: legend = TLegend(0.19, 0.5, 0.55, 0.85) legend.SetFillStyle(0) legend.SetBorderSize(0) ROOT.gStyle.SetOptStat(0) #~ if label == "forward": #~ hCanvas.DrawFrame(0,-20,20,200,"; %s ; %s" %("integrated luminosity [fb^{-1}]","Events")) #~ #~ else: yMax = sfList[-1] + 150 yMin = min(min(yValues) - max(yValuesUncert) * 1.25, -10) if bins: hCanvas.DrawFrame( 0, yMin, 10, yMax, "; %s ; %s" % ("bin number", "Events / approx. 2 fb^{-1}")) else: hCanvas.DrawFrame( 0, yMin, 20, yMax, "; %s ; %s" % ("integrated luminosity [fb^{-1}]", "Events")) zeroLine = ROOT.TLine(0, 0., 20, 0.) zeroLine.SetLineWidth(1) zeroLine.SetLineColor(ROOT.kBlue) zeroLine.SetLineStyle(2) zeroLine.Draw("same") arg2 = numpy.array(xValues, "d") arg4 = numpy.array(xValuesUncert, "d") arg3 = numpy.array(yValues, "d") arg5 = numpy.array(yValuesUncert, "d") sfArray = numpy.array(sfList, "d") ofArray = numpy.array(ofList, "d") sfUncertArray = numpy.array(sfValuesUncert, "d") ofUncertArray = numpy.array(ofValuesUncert, "d") arg3BTagged = numpy.array(yValuesBTagged, "d") arg5BTagged = numpy.array(yValuesUncertBTagged, "d") sfArrayBTagged = numpy.array(sfListBTagged, "d") ofArrayBTagged = numpy.array(ofListBTagged, "d") sfUncertArrayBTagged = numpy.array(sfValuesUncertBTagged, "d") ofUncertArrayBTagged = numpy.array(ofValuesUncertBTagged, "d") arg3BVeto = numpy.array(yValuesBVeto, "d") arg5BVeto = numpy.array(yValuesUncertBVeto, "d") sfArrayBVeto = numpy.array(sfListBVeto, "d") ofArrayBVeto = numpy.array(ofListBVeto, "d") sfUncertArrayBVeto = numpy.array(sfValuesUncertBVeto, "d") ofUncertArrayBVeto = numpy.array(ofValuesUncertBVeto, "d") eeArray = numpy.array(eeList, "d") mmArray = numpy.array(mmList, "d") eeUncertArray = numpy.array(eeValuesUncert, "d") mmUncertArray = numpy.array(mmValuesUncert, "d") #~ graph1jet = ROOT.TGraphErrors(6,METvalues,Rinout1Jets,METErrors,ErrRinout1Jets) graph = ROOT.TGraphErrors(10, arg2, arg3, arg4, arg5) graphSF = ROOT.TGraphErrors(10, arg2, sfArray, arg4, sfUncertArray) graphOF = ROOT.TGraphErrors(10, arg2, ofArray, arg4, ofUncertArray) graphBTagged = ROOT.TGraphErrors(10, arg2, arg3BTagged, arg4, arg5BTagged) graphSFBTagged = ROOT.TGraphErrors(10, arg2, sfArrayBTagged, arg4, sfUncertArrayBTagged) graphOFBTagged = ROOT.TGraphErrors(10, arg2, ofArrayBTagged, arg4, ofUncertArrayBTagged) graphBVeto = ROOT.TGraphErrors(10, arg2, arg3BVeto, arg4, arg5BVeto) graphSFBVeto = ROOT.TGraphErrors(10, arg2, sfArrayBVeto, arg4, sfUncertArrayBVeto) graphOFBVeto = ROOT.TGraphErrors(10, arg2, ofArrayBVeto, arg4, ofUncertArrayBVeto) graphEE = ROOT.TGraphErrors(10, arg2, eeArray, arg4, eeUncertArray) graphMM = ROOT.TGraphErrors(10, arg2, mmArray, arg4, mmUncertArray) graph.Draw("Psame") graphSF.Draw("Psame") graphSF.SetLineColor(ROOT.kRed) graphSF.SetMarkerColor(ROOT.kRed) graphOF.Draw("Psame") graphOF.SetLineColor(ROOT.kBlue) graphOF.SetMarkerColor(ROOT.kBlue) from ROOT import TH1F, kWhite legendHistDing = TH1F() legendHistDing.SetFillColor(kWhite) if "Signal" in selection.name: legend.AddEntry(legendHistDing, "Signal region %s" % label, "h") else: legend.AddEntry(legendHistDing, "Control region %s" % label, "h") legend.AddEntry(graphSF, "Same Flavour", "p") legend.AddEntry(graphOF, "Prediction from Opposite Flavour", "p") legend.AddEntry(graph, "N_{SF}-N_{prediction}", "p") legend.Draw("same") latex = ROOT.TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = ROOT.TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.06) latexCMS.SetNDC(True) latexCMSExtra = ROOT.TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.045) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (8 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.89, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.82 else: yLabelPos = 0.85 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) if bins: hCanvas.Print("fig/YieldvsLumi_Bins_%s" % (plot.filename % runRange.label)) else: hCanvas.Print("fig/YieldvsLumi_%s" % (plot.filename % runRange.label)) #~ if label == "forward": #~ hCanvas.DrawFrame(0,-20,20,200,"; %s ; %s" %("integrated luminosity [fb^{-1}]","Events")) #~ #~ else: yMax = sfListBTagged[-1] + 150 yMin = min(min(yValuesBTagged) - max(yValuesUncertBTagged) * 1.25, -10) if bins: hCanvas.DrawFrame( 0, yMin, 10, yMax, "; %s ; %s" % ("bin number", "Events / approx. 2 fb^{-1}")) else: hCanvas.DrawFrame( 0, yMin, 20, yMax, "; %s ; %s" % ("integrated luminosity [fb^{-1}]", "Events")) zeroLine.Draw("same") legend.Clear() graphBTagged.Draw("Psame") graphSFBTagged.Draw("Psame") graphSFBTagged.SetLineColor(ROOT.kRed) graphSFBTagged.SetMarkerColor(ROOT.kRed) graphOFBTagged.Draw("Psame") graphOFBTagged.SetLineColor(ROOT.kBlue) graphOFBTagged.SetMarkerColor(ROOT.kBlue) from ROOT import TH1F, kWhite legendHistDing = TH1F() legendHistDing.SetFillColor(kWhite) if "Signal" in selection.name: legend.AddEntry(legendHistDing, "Signal region %s - b tagged" % label, "h") else: legend.AddEntry(legendHistDing, "Control region %s - b tagged" % label, "h") legend.AddEntry(graphSFBTagged, "Same Flavour", "p") legend.AddEntry(graphOFBTagged, "Prediction from Opposite Flavour", "p") legend.AddEntry(graphBTagged, "N_{SF}-N_{prediction}", "p") legend.Draw("same") latex = ROOT.TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = ROOT.TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.06) latexCMS.SetNDC(True) latexCMSExtra = ROOT.TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.045) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (8 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.89, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.82 else: yLabelPos = 0.85 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) if bins: hCanvas.Print("fig/YieldvsLumi_Bins_BTagged_%s" % (plot.filename % runRange.label)) else: hCanvas.Print("fig/YieldvsLumi_BTagged_%s" % (plot.filename % runRange.label)) #~ if label == "forward": #~ hCanvas.DrawFrame(0,-20,20,200,"; %s ; %s" %("integrated luminosity [fb^{-1}]","Events")) #~ #~ else: yMax = sfListBVeto[-1] + 150 yMin = min(min(yValuesBVeto) - max(yValuesUncertBVeto) * 1.25, -10) if bins: hCanvas.DrawFrame( 0, yMin, 10, yMax, "; %s ; %s" % ("bin number", "Events / approx. 2 fb^{-1}")) else: hCanvas.DrawFrame( 0, yMin, 20, yMax, "; %s ; %s" % ("integrated luminosity [fb^{-1}]", "Events")) zeroLine.Draw("same") legend.Clear() graphBVeto.Draw("Psame") graphSFBVeto.Draw("Psame") graphSFBVeto.SetLineColor(ROOT.kRed) graphSFBVeto.SetMarkerColor(ROOT.kRed) graphOFBVeto.Draw("Psame") graphOFBVeto.SetLineColor(ROOT.kBlue) graphOFBVeto.SetMarkerColor(ROOT.kBlue) from ROOT import TH1F, kWhite legendHistDing = TH1F() legendHistDing.SetFillColor(kWhite) if "Signal" in selection.name: legend.AddEntry(legendHistDing, "Signal region %s - b veto" % label, "h") else: legend.AddEntry(legendHistDing, "Control region %s - b veto" % label, "h") legend.AddEntry(graphSFBVeto, "Same Flavour", "p") legend.AddEntry(graphOFBVeto, "Prediction from Opposite Flavour", "p") legend.AddEntry(graphBTagged, "N_{SF}-N_{prediction}", "p") #~ legend.AddEntry(graph,"SF - OF","p") legend.Draw("same") latex = ROOT.TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = ROOT.TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.06) latexCMS.SetNDC(True) latexCMSExtra = ROOT.TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.045) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (8 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.89, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.82 else: yLabelPos = 0.85 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) if bins: hCanvas.Print("fig/YieldvsLumi_Bins_BVeto_%s" % (plot.filename % runRange.label)) else: hCanvas.Print("fig/YieldvsLumi_BVeto_%s" % (plot.filename % runRange.label))
for h_name in h_names: h = f_in.Get('mmPlots/'+h_name).Clone(h_name+'_'+sample) h.Scale(scale) h_names[h_name].append(deepcopy(h)) #f_in.Close() canvas = TCanvas() #leg = TLegend(0.2, 0.7, 0.5, 0.9) leg = TLegend(0.58, 0.6, 0.9, 0.9) configureLegend(leg, 1) hscaling_str = '' for h_name in h_names: hSum = ROOT.THStack() leg.Clear() #DY h_names[h_name][1].SetFillColor(ROOT.kOrange-3) h_names[h_name][1].SetLineColor(ROOT.kBlack) hSum.Add(h_names[h_name][1]) #Zjj-EW h_names[h_name][4].SetFillColor(ROOT.kMagenta+1) h_names[h_name][4].SetLineColor(ROOT.kBlack) hSum.Add(h_names[h_name][4]) #di-boson h_VV = deepcopy(h_names[h_name][11].Clone(h_name+'_VV')) h_VV.Reset() h_VV.Add(h_names[h_name][11]) #WW->2l2nu h_VV.Add(h_names[h_name][12]) #WZ->3l1nu h_VV.Add(h_names[h_name][13]) #WZ->2l2q h_VV.Add(h_names[h_name][14]) #ZZ->2l2nu
def PlotOnCanvas(self, pdf_name): tdrstyle.setTDRStyle() # Plot the histograms on over the other # c1 = TCanvas("c1", "c1", 600, 600) c1.SetLeftMargin(0.16) legend = TLegend(self.legend_pos[0], self.legend_pos[1], self.legend_pos[2], self.legend_pos[3]) legend.SetHeader("Legend", "C") maxY = 0 for leg, obj in zip(self.list_legend, self.list_obj): legend.AddEntry(obj, leg, "l") obj_max = obj.GetMaximum() if obj_max > maxY: maxY = obj_max maxY *= 1.1 for col, obj in zip(self.list_color, self.list_obj): obj.SetLineColor(col) obj.SetLineWidth(3) obj.SetMaximum(maxY) obj.SetTitleOffset(1.8, 'x') obj.SetTitleOffset(2, 'y') obj.Draw(self.option + " same") if self.logx: c1.SetLogx() if self.logy: c1.SetLogy() self.list_obj[0].SetMinimum(10) legend.Draw() c1.Print(pdf_name, 'Title:' + self.list_obj[0].GetTitle() + ' Same') c1.Close() # Plot the stacked histograms # self.stack_hist = THStack("hs", "") for col, obj in zip(self.list_color, self.list_obj): obj.SetFillColor(col) self.stack_hist.Add(obj) c2 = TCanvas("c2", "c2", 600, 600) c2.SetLeftMargin(0.16) legend.Clear() legend.SetHeader("Legend", "C") for leg, obj in zip(self.list_legend, self.list_obj): legend.AddEntry(obj, leg, "f") obj.SetMaximum(self.stack_hist.GetMaximum() * 1.1) obj.SetTitleOffset(1.8, 'x') obj.SetTitleOffset(2, 'y') obj.Draw() self.stack_hist.Draw(self.option + " same") if self.logx: c2.SetLogx() if self.logy: c2.SetLogy() legend.Draw() c2.Print(pdf_name, 'Title:' + self.list_obj[0].GetTitle() + ' Stack') c2.Close()
def main(argv): parser = OptionParser( usage="\n plot_resources_against_ncores.py [RUNPERIOD] [VERSION]") (options, args) = parser.parse_args(argv) if len(args) != 2: print "Usage:" print "plot_resources_against_ncores.py [RUNPERIOD] [VERSION]" print "example: plot_resources_against_ncores.py 2015_03 15" exit() RUNPERIOD = "" VERSION = "" # RUNPERIOD is with underscore RUNPERIOD = args[0] RUNPERIOD = RUNPERIOD.replace('-', '_') RUNPERIOD_HYPHEN = RUNPERIOD.replace('_', '-') VERSION = args[1] XMLDIR = '/home/' + os.environ['USER'] + '/halld/hdswif/xml/' VERBOSE = False # color scheme colors = (ROOT.kRed, ROOT.kSpring - 2, ROOT.kAzure + 10, ROOT.kMagenta - 2, ROOT.kBlack) sp_colors = (ROOT.kBlack, ROOT.kRed, ROOT.kRed - 9, ROOT.kOrange - 2, ROOT.kYellow - 7, ROOT.kYellow - 3, ROOT.kSpring - 2, ROOT.kGreen + 2, ROOT.kCyan - 7, ROOT.kCyan - 3, ROOT.kAzure + 10, ROOT.kBlue - 7, ROOT.kBlue - 10, ROOT.kViolet, ROOT.kViolet - 9, ROOT.kMagenta - 2, ROOT.kMagenta - 7, ROOT.kPink + 10, ROOT.kPink - 7, ROOT.kGray, ROOT.kGray + 3) # Dictionary for #cores and color index # The #cores should match what the jobs ran with. dict_cpu_color = { 1: 0, 2: 1, 3: 2, 4: 3, 5: 4, 6: 5, 7: 6, 8: 7, 9: 8, 12: 9, 15: 10, 18: 11, 20: 12, 24: 13, 32: 14, 42: 15 } # File nevents_resources.txt contains # against [run] [file] [ncores] [#events] # #events is set to -999 if no stdout file was found. dict_run_file_ncores_events = {} dict_run_file_ncores_plugintime = {} nevents_resources_file = open( 'nevents_resources_' + RUNPERIOD + '_ver' + VERSION + '.txt', 'r') for line in nevents_resources_file: runnum = str(line.split()[0]) filenum = str(line.split()[1]) ncores = int(line.split()[2]) nevents = int(line.split()[3]) plugintime = int(line.split()[4]) # Create dict of dict_run_file_ncores_events[runnum][filenum][ncores] = nevents if not dict_run_file_ncores_events.has_key(runnum): # print 'runnum = ' + runnum dict_run_file_ncores_events[runnum] = {} if not dict_run_file_ncores_events[runnum].has_key(filenum): # print 'filenum = ' + filenum dict_run_file_ncores_events[runnum][filenum] = {} dict_run_file_ncores_events[runnum][filenum][ncores] = nevents # Create dict of dict_run_file_ncores_plugintime[runnum][filenum][ncores] = plugintime if not dict_run_file_ncores_plugintime.has_key(runnum): # print 'runnum = ' + runnum dict_run_file_ncores_plugintime[runnum] = {} if not dict_run_file_ncores_plugintime[runnum].has_key(filenum): # print 'filenum = ' + filenum dict_run_file_ncores_plugintime[runnum][filenum] = {} dict_run_file_ncores_plugintime[runnum][filenum][ncores] = plugintime # print dict_run_file_ncores_events # XML file to parse filename = XMLDIR + 'swif_output_offline_monitoring_RunPeriod' + RUNPERIOD + '_ver' + VERSION + '_hd_rawdata.xml' # Read in xml file and create tree, root tree = ET.parse(filename) # root element is <workflow_status> workflow_status = tree.getroot() summary = workflow_status.find('summary') workflow_name_text = summary.find('workflow_name').text # Create a list of run/file numbers. # For each entry we will create a TGraph of # RAM usage vs ncores. list_runfiles = [] # Create dictionary of run/file numbers and TGraphs dict_runfiles_mem = {} dict_runfiles_vmem = {} dict_runfiles_rtime = {} dict_runfiles_rtime_times_ncores = {} dict_runfiles_walltime = {} dict_runfiles_walltime_times_ncores = {} dict_runfiles_eventrate = {} # For TGraph of rtime vs wall time, we want to # separate them into [runfiles][cores] # so we have two dicts, # runfiles -> cores, # cores -> grtime_walltime dict_runfiles_dict_ncores_cputime_walltime = {} # Loop over all job elements and grab # - user_run, user_file # Create a TGraph for the run/file combination if necessary # Loop over all attempt elements and grab # - cpu_cores # - auger_mem_kb # - auger_vmem_kb # - walltime # - rtime # Add a point to the corresponding TGraph for job in workflow_status.iter('job'): # Get user_run, user_file user_run_text = 'None' user_file_text = 'None' for tags in job.iter('tags'): user_run = tags.find('user_run') if user_run != None: user_run_text = str(user_run.text) user_file = tags.find('user_file') if user_file != None: user_file_text = str(user_file.text) # print 'user_run_text = ' + user_run_text + ' user_file_text = ' + user_file_text runfile = '' if (user_run_text is not 'None') and (user_file_text is not 'None'): runfile = user_run_text + '_' + user_file_text # print 'runfile = ' + runfile # Add this runfile to list of list_runfiles # if it is not already included if not runfile in list_runfiles: list_runfiles.append(runfile) # Creat TGraphs corresponding to this run/file number gmem = TGraph() gmem.SetName('gmem_' + runfile) new_pair = {runfile: gmem} dict_runfiles_mem.update(new_pair) gvmem = TGraph() gvmem.SetName('gvmem_' + runfile) new_pair = {runfile: gvmem} dict_runfiles_vmem.update(new_pair) grtime = TGraph() grtime.SetName('grtime_' + runfile) new_pair = {runfile: grtime} dict_runfiles_rtime.update(new_pair) grtime_times_ncores = TGraph() grtime_times_ncores.SetName('grtime_times_ncores_' + runfile) new_pair = {runfile: grtime_times_ncores} dict_runfiles_rtime_times_ncores.update(new_pair) gwalltime = TGraph() gwalltime.SetName('gwalltime_' + runfile) new_pair = {runfile: gwalltime} dict_runfiles_walltime.update(new_pair) gwalltime_times_ncores = TGraph() gwalltime_times_ncores.SetName('gwalltime_times_ncores_' + runfile) new_pair = {runfile: gwalltime_times_ncores} dict_runfiles_walltime_times_ncores.update(new_pair) geventrate = TGraph() geventrate.SetName('geventrate_' + runfile) new_pair = {runfile: geventrate} dict_runfiles_eventrate.update(new_pair) # Create new dict for {ncores : gcputime_walltime} dict_ncores_cputime_walltime = {} new_pair = {runfile: dict_ncores_cputime_walltime} dict_runfiles_dict_ncores_cputime_walltime.update(new_pair) # print list_runfiles # sort list_runfiles.sort() # For each attempt, get cpu_cores, auger_mem_kb, auger_vmem_kb for attempt in job.findall('.//*attempt[last()]'): # for attempt in job.iter('attempt'): cpu_cores_int = 0 auger_mem_kb_int = 0 auger_vmem_kb_int = 0 rtime_float = 0 rtime_times_ncores_float = 0 walltime_float = 0 walltime_times_ncores_float = 0 auger_result_text = '' problem_text = '' cputime_float = 0 REMOVETHIS = False cpu_cores = attempt.find('cpu_cores') if cpu_cores != None: cpu_cores_int = int(cpu_cores.text) auger_mem_kb = attempt.find('auger_mem_kb') if auger_mem_kb != None: auger_mem_kb_int = int(auger_mem_kb.text) auger_vmem_kb = attempt.find('auger_vmem_kb') if auger_vmem_kb != None: auger_vmem_kb_int = int(auger_vmem_kb.text) walltime = attempt.find('auger_wall_sec') if walltime != None: walltime_float = float(walltime.text) if cpu_cores_int is not 0 and walltime_float is not 0: walltime_times_ncores_float = walltime_float * cpu_cores_int rtime = attempt.find('rtime') if rtime != None: rtime_float = float(rtime.text) # Bad event 003079_001 with 4 cores # used only 0.25 s of rtime. # FLAG AS BAD EVENT if rtime_float < 1: REMOVETHIS = True print 'removing this event with rtime = ' + str( rtime_float) cputime = attempt.find('auger_cpu_sec') if cputime != None: cputime_float = float(cputime.text) if cpu_cores_int is not 0 and rtime_float is not 0: rtime_times_ncores_float = rtime_float * cpu_cores_int auger_result = attempt.find('auger_result') if auger_result != None: auger_result_text = auger_result.text problem = attempt.find('problem') if problem != None: problem_text = problem.text # print 'cpu_cores = ' + str(cpu_cores_int) + ' auger_mem_kb_int = ' + str(auger_mem_kb_int) + ' auger_vmem_kb_int = ' + str(auger_vmem_kb_int) + ' walltime_float = ' + str(walltime_float) # Add entries to graphs only if result was success if auger_result_text == 'SUCCESS' and problem_text == '' and REMOVETHIS == False: if auger_mem_kb_int is not 0: dict_runfiles_mem[runfile].SetPoint( dict_runfiles_mem[runfile].GetN(), float(cpu_cores_int), auger_mem_kb_int / 1000. / 1000.) else: print 'runfile = ' + runfile + ' cpu = ' + str( cpu_cores_int) + ' mem = ' + str(auger_mem_kb_int) if auger_vmem_kb_int is not 0: dict_runfiles_vmem[runfile].SetPoint( dict_runfiles_vmem[runfile].GetN(), float(cpu_cores_int), auger_vmem_kb_int / 1000. / 1000.) else: print 'runfile = ' + runfile + ' cpu = ' + str( cpu_cores_int) + ' vmem = ' + str(auger_vmem_kb_int) if walltime_float is not 0: dict_runfiles_walltime[runfile].SetPoint( dict_runfiles_walltime[runfile].GetN(), float(cpu_cores_int), walltime_float / 3600.) else: print 'runfile = ' + runfile + ' cpu = ' + str( cpu_cores_int) + ' walltime = ' + str(walltime_float) if walltime_times_ncores_float is not 0: dict_runfiles_walltime_times_ncores[runfile].SetPoint( dict_runfiles_walltime_times_ncores[runfile].GetN(), float(cpu_cores_int), walltime_times_ncores_float / 3600.) else: print 'runfile = ' + runfile + ' cpu = ' + str( cpu_cores_int) + ' walltime_times_ncores = ' + str( walltime_times_ncores_float) if rtime_float is not 0: dict_runfiles_rtime[runfile].SetPoint( dict_runfiles_rtime[runfile].GetN(), float(cpu_cores_int), rtime_float / 3600.) # print str(rtime_float) + ' ' + str(dict_run_file_ncores_plugintime[user_run_text][user_file_text][cpu_cores_int]) + ' ' + str((rtime_float - float(dict_run_file_ncores_plugintime[user_run_text][user_file_text][cpu_cores_int])) / rtime_float) else: print 'runfile = ' + runfile + ' cpu = ' + str( cpu_cores_int) + ' rtime = ' + str(rtime_float) if rtime_float is not 0 and dict_run_file_ncores_events[ user_run_text][user_file_text][ cpu_cores_int] is not -999: nevents = dict_run_file_ncores_events[user_run_text][ user_file_text][cpu_cores_int] time = float(dict_run_file_ncores_plugintime[user_run_text] [user_file_text][cpu_cores_int]) y = nevents / time dict_runfiles_eventrate[runfile].SetPoint( dict_runfiles_eventrate[runfile].GetN(), float(cpu_cores_int), y) else: print 'runfile = ' + runfile + ' cpu = ' + str( cpu_cores_int) + ' rtime = ' + str(rtime_float) if rtime_times_ncores_float is not 0: dict_runfiles_rtime_times_ncores[runfile].SetPoint( dict_runfiles_rtime_times_ncores[runfile].GetN(), float(cpu_cores_int), rtime_times_ncores_float / 3600.) else: print 'runfile = ' + runfile + ' cpu = ' + str( cpu_cores_int) + ' rtime_times_ncores = ' + str( rtime_times_ncores_float) # Loop over keys in dict_runfiles_dict_ncores_cputime_walltime[runfile] # and check if there is an entry for this # of cores. # If not, create a TGraph. if not dict_runfiles_dict_ncores_cputime_walltime[ runfile].has_key(cpu_cores_int): # print 'creating new dict for runfile = ' + runfile + ' cpu_cores = ' + str(cpu_cores_int) gcputime_walltime = TGraph() gcputime_walltime.SetName('gcputime_walltime_' + runfile + '_' + str(cpu_cores_int)) new_pair = {cpu_cores_int: gcputime_walltime} dict_runfiles_dict_ncores_cputime_walltime[runfile].update( new_pair) # Update the TGraph point if (cputime_float is not 0) and (walltime_float is not 0): dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores_int].SetPoint( dict_runfiles_dict_ncores_cputime_walltime[runfile] [cpu_cores_int].GetN(), walltime_float / 3600., cputime_float / 3600.) else: print 'result ws not SUCCESS for ' + user_run_text + ' ' + user_file_text + ' ' + str( cpu_cores_int) # Draw graphs #-------------------------------------------------------------------- c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend = TLegend(0.13, 0.77, 0.93, 0.97) legend.SetBorderSize(0) legend.SetTextSize(0.045) legend.SetFillStyle(0) legend.SetNColumns(5) ndraw = 0 for runfile in list_runfiles: dict_runfiles_mem[runfile].GetXaxis().SetTitleSize(0.06) dict_runfiles_mem[runfile].GetXaxis().SetTitleOffset(0.800) dict_runfiles_mem[runfile].GetXaxis().SetLabelSize(0.05) dict_runfiles_mem[runfile].GetYaxis().SetTitleSize(0.06) dict_runfiles_mem[runfile].GetYaxis().SetTitleOffset(0.700) dict_runfiles_mem[runfile].GetYaxis().CenterTitle() dict_runfiles_mem[runfile].GetYaxis().SetLabelSize(0.05) dict_runfiles_mem[runfile].SetMarkerColor(colors[ndraw // 5]) dict_runfiles_mem[runfile].SetMarkerStyle(20 + (ndraw % 5)) dict_runfiles_mem[runfile].SetMarkerSize(1.5) dict_runfiles_mem[runfile].SetLineColor(colors[ndraw // 5]) dict_runfiles_mem[runfile].SetLineStyle(1) dict_runfiles_mem[runfile].SetLineWidth(1) dict_runfiles_mem[runfile].GetXaxis().SetTitle('# cores') dict_runfiles_mem[runfile].GetYaxis().SetTitle('mem (GB)') dict_runfiles_mem[runfile].GetXaxis().SetLimits(0, 42.5) dict_runfiles_mem[runfile].SetMinimum(3.5) # 0 dict_runfiles_mem[runfile].SetMaximum(14.0) # 9 dict_runfiles_mem[runfile].Sort() if ndraw == 0: dict_runfiles_mem[runfile].Draw('AP') else: dict_runfiles_mem[runfile].Draw('P') legend.AddEntry(dict_runfiles_mem[runfile], runfile, 'P') # legend.AddEntry(dict_runfiles_mem[runfile],runfile + ' (' + str(dict_runfiles_mem[runfile].GetN()) + ')','P') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/01___mem.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: if ndraw == 0: dict_runfiles_mem[runfile].Draw('ALP') else: dict_runfiles_mem[runfile].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/01___mem_lines.pdf') c1.Close() #-------------------------------------------------------------------- c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend.Clear() ndraw = 0 for runfile in list_runfiles: dict_runfiles_vmem[runfile].GetXaxis().SetTitleSize(0.06) dict_runfiles_vmem[runfile].GetXaxis().SetTitleOffset(0.800) dict_runfiles_vmem[runfile].GetXaxis().SetLabelSize(0.05) dict_runfiles_vmem[runfile].GetYaxis().SetTitleSize(0.06) dict_runfiles_vmem[runfile].GetYaxis().SetTitleOffset(0.700) dict_runfiles_vmem[runfile].GetYaxis().CenterTitle() dict_runfiles_vmem[runfile].GetYaxis().SetLabelSize(0.05) dict_runfiles_vmem[runfile].SetMarkerColor(colors[ndraw // 5]) dict_runfiles_vmem[runfile].SetMarkerStyle(20 + (ndraw % 5)) dict_runfiles_vmem[runfile].SetMarkerSize(1.5) dict_runfiles_vmem[runfile].SetLineColor(colors[ndraw // 5]) dict_runfiles_vmem[runfile].SetLineStyle(1) dict_runfiles_vmem[runfile].SetLineWidth(1) dict_runfiles_vmem[runfile].GetXaxis().SetTitle('# cores') dict_runfiles_vmem[runfile].GetYaxis().SetTitle('vmem (GB)') dict_runfiles_vmem[runfile].GetXaxis().SetLimits(0, 42.5) dict_runfiles_vmem[runfile].SetMinimum(5.0) # 0.0 dict_runfiles_vmem[runfile].SetMaximum(18.0) # 9.0 dict_runfiles_vmem[runfile].Sort() if ndraw == 0: dict_runfiles_vmem[runfile].Draw('AP') else: dict_runfiles_vmem[runfile].Draw('P') # legend.AddEntry(dict_runfiles_vmem[runfile],runfile + ' (' + str(dict_runfiles_vmem[runfile].GetN()) + ')','P') legend.AddEntry(dict_runfiles_vmem[runfile], runfile, 'P') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/02___vmem.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: if ndraw == 0: dict_runfiles_vmem[runfile].Draw('ALP') else: dict_runfiles_vmem[runfile].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/02___vmem_lines.pdf') c1.Close() #-------------------------------------------------------------------- c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend.Clear() ndraw = 0 for runfile in list_runfiles: dict_runfiles_walltime[runfile].GetXaxis().SetTitleSize(0.06) dict_runfiles_walltime[runfile].GetXaxis().SetTitleOffset(0.800) dict_runfiles_walltime[runfile].GetXaxis().SetLabelSize(0.05) dict_runfiles_walltime[runfile].GetYaxis().SetTitleSize(0.06) dict_runfiles_walltime[runfile].GetYaxis().SetTitleOffset(0.700) dict_runfiles_walltime[runfile].GetYaxis().CenterTitle() dict_runfiles_walltime[runfile].GetYaxis().SetLabelSize(0.05) dict_runfiles_walltime[runfile].SetMarkerColor(colors[ndraw // 5]) dict_runfiles_walltime[runfile].SetMarkerStyle(20 + (ndraw % 5)) dict_runfiles_walltime[runfile].SetMarkerSize(1.5) dict_runfiles_walltime[runfile].SetLineColor(colors[ndraw // 5]) dict_runfiles_walltime[runfile].SetLineStyle(1) dict_runfiles_walltime[runfile].SetLineWidth(1) dict_runfiles_walltime[runfile].GetXaxis().SetTitle('# cores') dict_runfiles_walltime[runfile].GetYaxis().SetTitle('walltime (hrs)') dict_runfiles_walltime[runfile].GetXaxis().SetLimits(0, 42.5) dict_runfiles_walltime[runfile].SetMinimum(0) dict_runfiles_walltime[runfile].SetMaximum(22) # 8 dict_runfiles_walltime[runfile].Sort() if ndraw == 0: dict_runfiles_walltime[runfile].Draw('AP') else: dict_runfiles_walltime[runfile].Draw('P') # legend.AddEntry(dict_runfiles_walltime[runfile],runfile + ' (' + str(dict_runfiles_walltime[runfile].GetN()) + ')','P') legend.AddEntry(dict_runfiles_walltime[runfile], runfile, 'P') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/03___walltime.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: if ndraw == 0: dict_runfiles_walltime[runfile].Draw('ALP') else: dict_runfiles_walltime[runfile].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/03___walltime_lines.pdf') c1.Close() #-------------------------------------------------------------------- c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend.Clear() ndraw = 0 for runfile in list_runfiles: dict_runfiles_walltime_times_ncores[runfile].GetXaxis().SetTitleSize( 0.06) dict_runfiles_walltime_times_ncores[runfile].GetXaxis().SetTitleOffset( 0.800) dict_runfiles_walltime_times_ncores[runfile].GetXaxis().SetLabelSize( 0.05) dict_runfiles_walltime_times_ncores[runfile].GetYaxis().SetTitleSize( 0.06) dict_runfiles_walltime_times_ncores[runfile].GetYaxis().SetTitleOffset( 0.700) dict_runfiles_walltime_times_ncores[runfile].GetYaxis().CenterTitle() dict_runfiles_walltime_times_ncores[runfile].GetYaxis().SetLabelSize( 0.05) dict_runfiles_walltime_times_ncores[runfile].SetMarkerColor( colors[ndraw // 5]) dict_runfiles_walltime_times_ncores[runfile].SetMarkerStyle(20 + (ndraw % 5)) dict_runfiles_walltime_times_ncores[runfile].SetMarkerSize(1.5) dict_runfiles_walltime_times_ncores[runfile].SetLineColor( colors[ndraw // 5]) dict_runfiles_walltime_times_ncores[runfile].SetLineStyle(1) dict_runfiles_walltime_times_ncores[runfile].SetLineWidth(1) dict_runfiles_walltime_times_ncores[runfile].GetXaxis().SetTitle( '# cores') dict_runfiles_walltime_times_ncores[runfile].GetYaxis().SetTitle( 'walltime #times ncores (hrs)') dict_runfiles_walltime_times_ncores[runfile].GetXaxis().SetLimits( 0, 42.5) dict_runfiles_walltime_times_ncores[runfile].SetMinimum(0) dict_runfiles_walltime_times_ncores[runfile].SetMaximum(90) # 30 dict_runfiles_walltime_times_ncores[runfile].Sort() if ndraw == 0: dict_runfiles_walltime_times_ncores[runfile].Draw('AP') else: dict_runfiles_walltime_times_ncores[runfile].Draw('P') # legend.AddEntry(dict_runfiles_walltime_times_ncores[runfile],runfile + ' (' + str(dict_runfiles_walltime_times_ncores[runfile].GetN()) + ')','P') legend.AddEntry(dict_runfiles_walltime_times_ncores[runfile], runfile, 'P') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/04___walltime_times_ncores.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: if ndraw == 0: dict_runfiles_walltime_times_ncores[runfile].Draw('ALP') else: dict_runfiles_walltime_times_ncores[runfile].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/04___walltime_times_ncores_lines.pdf') c1.Close() #-------------------------------------------------------------------- c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend.Clear() ndraw = 0 for runfile in list_runfiles: dict_runfiles_rtime[runfile].GetXaxis().SetTitleSize(0.06) dict_runfiles_rtime[runfile].GetXaxis().SetTitleOffset(0.800) dict_runfiles_rtime[runfile].GetXaxis().SetLabelSize(0.05) dict_runfiles_rtime[runfile].GetYaxis().SetTitleSize(0.06) dict_runfiles_rtime[runfile].GetYaxis().SetTitleOffset(0.700) dict_runfiles_rtime[runfile].GetYaxis().CenterTitle() dict_runfiles_rtime[runfile].GetYaxis().SetLabelSize(0.05) dict_runfiles_rtime[runfile].SetMarkerColor(colors[ndraw // 5]) dict_runfiles_rtime[runfile].SetMarkerStyle(20 + (ndraw % 5)) dict_runfiles_rtime[runfile].SetMarkerSize(1.5) dict_runfiles_rtime[runfile].SetLineColor(colors[ndraw // 5]) dict_runfiles_rtime[runfile].SetLineStyle(1) dict_runfiles_rtime[runfile].SetLineWidth(1) dict_runfiles_rtime[runfile].GetXaxis().SetTitle('# cores') dict_runfiles_rtime[runfile].GetYaxis().SetTitle('rtime (hrs)') dict_runfiles_rtime[runfile].GetXaxis().SetLimits(0, 42.5) dict_runfiles_rtime[runfile].SetMinimum(0) dict_runfiles_rtime[runfile].SetMaximum(22) # 8 dict_runfiles_rtime[runfile].Sort() if ndraw == 0: dict_runfiles_rtime[runfile].Draw('AP') else: dict_runfiles_rtime[runfile].Draw('P') # legend.AddEntry(dict_runfiles_rtime[runfile],runfile + ' (' + str(dict_runfiles_rtime[runfile].GetN()) + ')','P') legend.AddEntry(dict_runfiles_rtime[runfile], runfile, 'P') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/05___rtime.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: if ndraw == 0: dict_runfiles_rtime[runfile].Draw('ALP') else: dict_runfiles_rtime[runfile].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/05___rtime_lines.pdf') c1.Close() #-------------------------------------------------------------------- c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend.Clear() ndraw = 0 for runfile in list_runfiles: dict_runfiles_rtime_times_ncores[runfile].GetXaxis().SetTitleSize(0.06) dict_runfiles_rtime_times_ncores[runfile].GetXaxis().SetTitleOffset( 0.800) dict_runfiles_rtime_times_ncores[runfile].GetXaxis().SetLabelSize(0.05) dict_runfiles_rtime_times_ncores[runfile].GetYaxis().SetTitleSize(0.06) dict_runfiles_rtime_times_ncores[runfile].GetYaxis().SetTitleOffset( 0.700) dict_runfiles_rtime_times_ncores[runfile].GetYaxis().CenterTitle() dict_runfiles_rtime_times_ncores[runfile].GetYaxis().SetLabelSize(0.05) dict_runfiles_rtime_times_ncores[runfile].SetMarkerColor( colors[ndraw // 5]) dict_runfiles_rtime_times_ncores[runfile].SetMarkerStyle(20 + (ndraw % 5)) dict_runfiles_rtime_times_ncores[runfile].SetMarkerSize(1.5) dict_runfiles_rtime_times_ncores[runfile].SetLineColor(colors[ndraw // 5]) dict_runfiles_rtime_times_ncores[runfile].SetLineStyle(1) dict_runfiles_rtime_times_ncores[runfile].SetLineWidth(1) dict_runfiles_rtime_times_ncores[runfile].GetXaxis().SetTitle( '# cores') dict_runfiles_rtime_times_ncores[runfile].GetYaxis().SetTitle( 'rtime #times ncores (hrs)') dict_runfiles_rtime_times_ncores[runfile].GetXaxis().SetLimits(0, 42.5) dict_runfiles_rtime_times_ncores[runfile].SetMinimum(0) dict_runfiles_rtime_times_ncores[runfile].SetMaximum(90) # 30 dict_runfiles_rtime_times_ncores[runfile].Sort() if ndraw == 0: dict_runfiles_rtime_times_ncores[runfile].Draw('AP') else: dict_runfiles_rtime_times_ncores[runfile].Draw('P') # legend.AddEntry(dict_runfiles_rtime_times_ncores[runfile],runfile + ' (' + str(dict_runfiles_rtime_times_ncores[runfile].GetN()) + ')','P') legend.AddEntry(dict_runfiles_rtime_times_ncores[runfile], runfile, 'P') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/06___rtime_times_ncores.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: if ndraw == 0: dict_runfiles_rtime_times_ncores[runfile].Draw('ALP') else: dict_runfiles_rtime_times_ncores[runfile].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/06___rtime_times_ncores_lines.pdf') c1.Close() #-------------------------------------------------------------------- c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend.Clear() ndraw = 0 for runfile in list_runfiles: dict_runfiles_eventrate[runfile].GetXaxis().SetTitleSize(0.06) dict_runfiles_eventrate[runfile].GetXaxis().SetTitleOffset(0.800) dict_runfiles_eventrate[runfile].GetXaxis().SetLabelSize(0.05) dict_runfiles_eventrate[runfile].GetYaxis().SetTitleSize(0.06) dict_runfiles_eventrate[runfile].GetYaxis().SetTitleOffset(0.700) dict_runfiles_eventrate[runfile].GetYaxis().CenterTitle() dict_runfiles_eventrate[runfile].GetYaxis().SetLabelSize(0.05) dict_runfiles_eventrate[runfile].SetMarkerColor(colors[ndraw // 5]) dict_runfiles_eventrate[runfile].SetMarkerStyle(20 + (ndraw % 5)) dict_runfiles_eventrate[runfile].SetMarkerSize(1.5) dict_runfiles_eventrate[runfile].SetLineColor(colors[ndraw // 5]) dict_runfiles_eventrate[runfile].SetLineStyle(1) dict_runfiles_eventrate[runfile].SetLineWidth(1) dict_runfiles_eventrate[runfile].GetXaxis().SetTitle('# cores') dict_runfiles_eventrate[runfile].GetYaxis().SetTitle('event rate (Hz)') dict_runfiles_eventrate[runfile].GetXaxis().SetLimits(0, 42.5) dict_runfiles_eventrate[runfile].SetMinimum(0) dict_runfiles_eventrate[runfile].SetMaximum(300.) # 800 dict_runfiles_eventrate[runfile].Sort() if ndraw == 0: dict_runfiles_eventrate[runfile].Draw('AP') else: dict_runfiles_eventrate[runfile].Draw('P') # legend.AddEntry(dict_runfiles_eventrate[runfile],runfile + ' (' + str(dict_runfiles_eventrate[runfile].GetN()) + ')','P') legend.AddEntry(dict_runfiles_eventrate[runfile], runfile, 'P') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/08___eventrate.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: if ndraw == 0: dict_runfiles_eventrate[runfile].Draw('ALP') else: dict_runfiles_eventrate[runfile].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/08___eventrate_lines.pdf') c1.Close() #-------------------------------------------------------------------- # For rtime vs walltime, TGraphs have two indicies, # runfiles and # cores nrunfile = 0 ndraw = 0 c1 = TCanvas('c1', 'canvas', 0, 0, 1600, 800) c1.SetTopMargin(0.02) c1.SetRightMargin(0.02) c1.SetLeftMargin(0.10) c1.SetBottomMargin(0.12) legend.SetNColumns(4) legend.Clear() for runfile in list_runfiles: # print '---------------- runfile = ' + runfile + ' --------------------' nrunfile += 1 for cpu_cores in dict_runfiles_dict_ncores_cputime_walltime[ runfile].keys(): # print 'cpu_cores = ' + str(cpu_cores) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetXaxis().SetTitleSize(0.06) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetXaxis().SetTitleOffset(0.800) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetXaxis().SetLabelSize(0.05) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetYaxis().SetTitleSize(0.06) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetYaxis().SetTitleOffset(0.700) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetYaxis().CenterTitle() dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetYaxis().SetLabelSize(0.05) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetMarkerColor(sp_colors[dict_cpu_color[cpu_cores]]) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetMarkerStyle(20 + (nrunfile % 5)) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetMarkerSize(1.5) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetLineColor(sp_colors[dict_cpu_color[cpu_cores]]) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetLineStyle(1) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetLineWidth(1) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetXaxis().SetTitle('walltime (hrs)') dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetYaxis().SetTitle('cpu time (hrs)') dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].GetXaxis().SetLimits(0, 8) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetMinimum(0) dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].SetMaximum(30) # 15 # dict_runfiles_dict_ncores_cputime_walltime[runfile][cpu_cores].Sort() if ndraw == 0: dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].Draw('AP') else: dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].Draw('P') if runfile == '003185_000': legend.AddEntry( dict_runfiles_dict_ncores_cputime_walltime[runfile] [cpu_cores], runfile + ' (' + str(cpu_cores) + ')', 'P') # Draw lines (for this we need to choose a # runfile combination where all jobs succeeded) if runfile == '003185_000': flinear = [] nkeys = 0 for cpu_cores in dict_runfiles_dict_ncores_cputime_walltime[ runfile].keys(): fname = 'flinear' + '_' + str(cpu_cores) f = TF1(fname, "[0]*x", 0, 8) flinear.append(f) flinear[nkeys].SetParameter(0, cpu_cores) flinear[nkeys].SetLineColor( sp_colors[dict_cpu_color[cpu_cores]]) flinear[nkeys].SetLineStyle(3) flinear[nkeys].SetNpx(1000) flinear[nkeys].DrawClone("same") nkeys += 1 ndraw += 1 # end of loop over cores legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/07___cputime_walltime_' + runfile + '.pdf') # redraw with lines ndraw = 0 for runfile in list_runfiles: for cpu_cores in dict_runfiles_dict_ncores_cputime_walltime[ runfile].keys(): if ndraw == 0: dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].Draw('ALP') else: dict_runfiles_dict_ncores_cputime_walltime[runfile][ cpu_cores].Draw('LP') ndraw += 1 legend.Draw('same') figureDir = 'figures/' + workflow_name_text if not os.path.exists(figureDir): os.makedirs(figureDir) c1.SaveAs(figureDir + '/07___cputime_walltime_' + runfile + '_lines.pdf') c1.Close()
l.AddEntry(trainS, 'Signal (training)', 'p') l.AddEntry(trainB, 'Background (training)', 'p') l.AddEntry(testS, 'Signal (testing)', 'f') l.AddEntry(testB, 'Background (testing)', 'f') #label2.AddText(ch+', '+BDT) testS.Draw('hist') testB.Draw('hist same') trainS.Draw('ep same') trainB.Draw('ep same') label.Draw('same') label2.Draw('same') l.Draw('same') testS.Draw('axis same') c1.Print(ver + '_BDT_score.pdf') l.Clear() label2.Clear() c1.Clear() #Correlation part #axislabel = ["# of jets", "# of b jets", "LepW pT", "LepW #eta", "LepW #Delta#dphi", "LepW mass", "jet0 pT", "jet0 #eta", "jet0 mass", "jet0 CSVv2", "jet0 CvsL", "jet0 CvsB", "jet1 pT", "jet1 #eta", "jet1 mass", "jet1 CSVv2", "jet1 CvsL", "jet1 CvsB", "jet2 pT", "jet2 #eta", "jet2 mass", "jet2 CSV", "jet2 CvsL", "jet2 CvsB", "jet3 pT", "jet3 #eta", "jet3 mass", "jet3 CSVv2", "jet3 CvsL", "jet3 CvsB", "jet12 pT", "jet12 #eta", "jet12 #Delta#eta", "jet12 #Delta#dphi", "jet12 mass", "jet12 #Delta R", "jet23 pT", "jet23 #eta", "jet23 #Delta#eta", "jet23 #Delta#phi", "jet23 mass", "jet31 pT", "jet31 #eta", "jet31 #Delta#eta", "jet31 #Delta#phi", "jet31 mass", "LepT pT", "LepT #eta", "LepT #Delta#eta", "LepT #Delta#phi", "LepT mass", "HadT pT", "HadT #eta", "HadT_Hq #Delta#eta", "HadT_Wb #Delta#eta", "HadT_Hq #Delta#phi", "HadT_Wb #Delta#phi", "HadT mass"]#TTFCNC,old axislabel = [ "jet0 pT", "jet0 #eta", "jet0 mass", "jet1 pT", "jet1 #eta", "jet1 mass", "jet2 pT", "jet2 #eta", "jet2 mass",
def dependencies(source, path, selection, plots, runRange, isMC, backgrounds, cmsExtra): hCanvas = TCanvas("hCanvas", "Distribution", 800, 800) plotPad = ROOT.TPad("plotPad", "plotPad", 0, 0, 1, 1) setTDRStyle() plotPad.UseCurrentStyle() plotPad.Draw() plotPad.cd() legend = TLegend(0.575, 0.16, 0.9, 0.4) legend.SetFillStyle(0) legend.SetBorderSize(0) legendHist1 = TH1F() legendHist2 = TH1F() legendHist3 = TH1F() legendHist1.SetMarkerColor(ROOT.kBlack) legendHist2.SetMarkerColor(ROOT.kRed) legendHist3.SetMarkerColor(ROOT.kBlue) legend.AddEntry(legendHist1, "ee", "p") legend.AddEntry(legendHist2, "#mu#mu", "p") legend.AddEntry(legendHist3, "e#mu", "p") latex = ROOT.TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = ROOT.TLatex() latexCMS.SetTextFont(61) #latexCMS.SetTextAlign(31) latexCMS.SetTextSize(0.06) latexCMS.SetNDC(True) latexCMSExtra = ROOT.TLatex() latexCMSExtra.SetTextFont(52) #latexCMSExtra.SetTextAlign(31) latexCMSExtra.SetTextSize(0.045) latexCMSExtra.SetNDC(True) latexSelection = ROOT.TLatex() #~ latexSelection.SetTextFont(42) latexSelection.SetTextSize(0.03) latexSelection.SetNDC(True) intlumi = ROOT.TLatex() intlumi.SetTextAlign(12) intlumi.SetTextSize(0.03) intlumi.SetNDC(True) if isMC: if os.path.isfile("shelves/triggerEff_%s_%s_%s_MC.pkl" % (selection.name, source, runRange.label)): centralVals = pickle.load( open( "shelves/triggerEff_%s_%s_%s_MC.pkl" % (selection.name, source, runRange.label), "rb")) else: centralVals = centralValues(source, path, selection, runRange, isMC, backgrounds) if os.path.isfile("shelves/triggerEff_%s_%s_%s.pkl" % (selection.name, source, runRange.label)): centralValsData = pickle.load( open( "shelves/triggerEff_%s_%s_%s.pkl" % (selection.name, source, runRange.label), "rb")) else: centralValsData = centralValues(source, path, selection, runRange, False, backgrounds) else: if os.path.isfile("shelves/triggerEff_%s_%s_%s.pkl" % (selection.name, source, runRange.label)): centralVals = pickle.load( open( "shelves/triggerEff_%s_%s_%s.pkl" % (selection.name, source, runRange.label), "rb")) else: centralVals = centralValues(source, path, selection, runRange, isMC, backgrounds) for name in plots: if isMC: plotData = getPlot(name) plotData.addRegion(selection) #~ plot.cleanCuts() plotData.cuts = plotData.cuts % runRange.runCut plotData.cuts = plotData.cuts.replace("mll", "p4.M()") plotData.cuts = plotData.cuts.replace("pt > 25", "p4.Pt() > 25") plotData.cuts = plotData.cuts.replace("triggerSummary > 0 &&", "") plotData.variable = plotData.variable.replace("mll", "p4.M()") if plotData.variable == "pt": plotData.variable = plotData.variable.replace("pt", "p4.Pt()") name = name + "MC" plot = getPlot(name) plot.addRegion(selection) #~ plot.cleanCuts() plot.cuts = plot.cuts % runRange.runCut plot.cuts = plot.cuts.replace("mll", "p4.M()") plot.cuts = plot.cuts.replace("pt > 25", "p4.Pt() > 25") plot.cuts = plot.cuts.replace("triggerSummary > 0 &&", "") plot.variable = plot.variable.replace("mll", "p4.M()") if plot.variable == "pt": plot.variable = plot.variable.replace("pt", "p4.Pt()") #~ if "Forward" in selection.name: #~ plot.nBins = int(plot.nBins/2) denominators, nominators = getHistograms(path, plot, runRange, isMC, backgrounds, source) effEE = TGraphAsymmErrors(nominators["EE"], denominators["EE"], "cp") effMuMu = TGraphAsymmErrors(nominators["MuMu"], denominators["MuMu"], "cp") denominatorHistoOF = denominators["MuEG"].Clone() nominatorHistoOF = nominators["MuEG"].Clone() effOF = TGraphAsymmErrors(nominatorHistoOF, denominatorHistoOF, "cp") if isMC: denominatorsData, nominatorsData = getHistograms( locations.triggerDataSetPath, plotData, runRange, False, backgrounds, source) effEEData = TGraphAsymmErrors(nominatorsData["EE"], denominatorsData["EE"], "cp") effMuMuData = TGraphAsymmErrors(nominatorsData["MuMu"], denominatorsData["MuMu"], "cp") denominatorHistoOFData = denominatorsData["MuEG"].Clone() nominatorHistoOFData = nominatorsData["MuEG"].Clone() effOFData = TGraphAsymmErrors(nominatorHistoOFData, denominatorHistoOFData, "cp") effEE.SetMarkerColor(ROOT.kBlack) effMuMu.SetMarkerColor(ROOT.kRed) effOF.SetMarkerColor(ROOT.kBlue) effEE.SetLineColor(ROOT.kBlack) effMuMu.SetLineColor(ROOT.kRed) effOF.SetLineColor(ROOT.kBlue) effEE.SetMarkerStyle(20) effMuMu.SetMarkerStyle(21) effOF.SetMarkerStyle(22) plotPad.DrawFrame(plot.firstBin, 0.5, plot.lastBin, 1.2, "; %s ; Efficiency" % (plot.xaxis)) selectionLabel = selection.latex if plot.variable == "nJets": selectionLabel = selectionLabel.replace( "#notin (n_{jets}#geq 2 & p_{T}^{miss} > 100 GeV)", "p_{T}^{miss} < 100 GeV") if plot.variable == "met": selectionLabel = selectionLabel.replace( "#notin (n_{jets}#geq 2 & p_{T}^{miss} > 100 GeV)", "n_{jets}=1") legend.Clear() legend.AddEntry(effEE, "ee", "p") legend.AddEntry(effMuMu, "#mu#mu", "p") legend.AddEntry(effOF, "e#mu", "p") effEE.Draw("samep") effMuMu.Draw("samep") effOF.Draw("samep") latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (13 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 #~ yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) latexSelection.DrawLatex(0.20, 0.25, selectionLabel) legend.Draw("same") if isMC: hCanvas.Print("fig/Triggereff_%s_%s_%s_%s_%s_MC.pdf" % (source, selection.name, runRange.label, plot.variablePlotName, plot.additionalName)) else: hCanvas.Print("fig/Triggereff_%s_%s_%s_%s_%s.pdf" % (source, selection.name, runRange.label, plot.variablePlotName, plot.additionalName)) denominatorHistoSF = denominators["EE"].Clone() denominatorHistoOF = denominators["MuEG"].Clone() denominatorHistoSF.Add(denominators["MuMu"].Clone()) nominatorHistoSF = nominators["EE"].Clone() nominatorHistoSFNoTrack = nominators["EE"].Clone() nominatorHistoSF.Add(nominators["MuMu"].Clone()) nominatorHistoOF = nominators["MuEG"].Clone() effSF = TGraphAsymmErrors(nominatorHistoSF, denominatorHistoSF, "cp") effOF = TGraphAsymmErrors(nominatorHistoOF, denominatorHistoOF, "cp") effSF.SetMarkerColor(ROOT.kBlack) effOF.SetMarkerColor(ROOT.kBlue) effSF.SetLineColor(ROOT.kBlack) effOF.SetLineColor(ROOT.kBlue) effSF.SetMarkerStyle(20) effOF.SetMarkerStyle(22) effSFNoFit = effSF.Clone() effOFNoFit = effSF.Clone() plotPad.DrawFrame(plot.firstBin, 0.5, plot.lastBin, 1.2, "; %s ; Efficiency" % (plot.xaxis)) legend.Clear() legend.AddEntry(effSF, "ee and #mu#mu", "p") legend.AddEntry(effOF, "e#mu", "p") effSF.Draw("samep") effOF.Draw("samep") latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (13 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 #~ yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) latexSelection.DrawLatex(0.20, 0.25, selectionLabel) legend.Draw("same") if isMC: hCanvas.Print("fig/Triggereff_SFvsOF_%s_%s_%s_%s_%s_MC.pdf" % (source, selection.name, runRange.label, plot.variablePlotName, plot.additionalName)) else: hCanvas.Print("fig/Triggereff_SFvsOF_%s_%s_%s_%s_%s.pdf" % (source, selection.name, runRange.label, plot.variablePlotName, plot.additionalName)) if source == "SingleLepton": plotPad.DrawFrame(plot.firstBin, .6, plot.lastBin, 1.4, "; %s ; R_{T}" % (plot.xaxis)) else: plotPad.DrawFrame(plot.firstBin, .6, plot.lastBin, 1.4, "; %s ; R_{T}" % (plot.xaxis)) effSFvsOF = efficiencyRatioGeometricMean(effEE, effMuMu, effOF, source) if isMC: effSFvsOFData = efficiencyRatioGeometricMean( effEEData, effMuMuData, effOFData, source) effSFvsOF.SetLineColor(ROOT.kGreen - 2) effSFvsOF.SetMarkerColor(ROOT.kGreen - 2) effSFvsOF.SetMarkerStyle(21) x = array("f", [plot.firstBin, plot.lastBin]) if isMC: yData = array("f", [ float(centralValsData[runRange.label]["RT"]), float(centralValsData[runRange.label]["RT"]) ]) sfLineData = ROOT.TF1("sfLine", str(centralValsData[runRange.label]["RT"]), plot.firstBin, plot.lastBin) y = array("f", [ float(centralVals[runRange.label]["RT"]), float(centralVals[runRange.label]["RT"]) ]) sfLine = ROOT.TF1("sfLine", str(centralVals[runRange.label]["RT"]), plot.firstBin, plot.lastBin) if isMC: eyData = array("f", [ float(centralValsData[runRange.label]["RTErrSyst"]), float(centralValsData[runRange.label]["RTErrSyst"]) ]) eyData = array("f", [ float(centralVals[runRange.label]["RTErrSyst"]), float(centralVals[runRange.label]["RTErrSyst"]) ]) exData = array("f", [0., 0.]) ge = ROOT.TGraphErrors(2, x, yData, exData, eyData) ge.SetFillColor(ROOT.kOrange - 9) ge.SetFillStyle(1001) ge.SetLineColor(ROOT.kWhite) ge.Draw("SAME 3") else: ey = array("f", [ float(centralVals[runRange.label]["RTErrSyst"]), float(centralVals[runRange.label]["RTErrSyst"]) ]) ex = array("f", [0., 0.]) ge = ROOT.TGraphErrors(2, x, y, ex, ey) ge.SetFillColor(ROOT.kOrange - 9) ge.SetFillStyle(1001) ge.SetLineColor(ROOT.kWhite) ge.Draw("SAME 3") effSFvsOF.Draw("samep") if isMC: effSFvsOFData.Draw("samep") sfLine.SetLineColor(ROOT.kGreen - 2) sfLine.SetLineWidth(3) sfLine.SetLineStyle(2) sfLine.Draw("SAME") if isMC: sfLineData.SetLineColor(ROOT.kBlack) sfLineData.SetLineWidth(3) sfLineData.SetLineStyle(2) sfLineData.Draw("SAME") latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (13 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: #~ cmsExtra = "Preliminary" cmsExtraLabel = cmsExtra.replace( "#splitline{Private Work}{Simulation}", "Private Work") #~ yLabelPos = 0.84 else: #~ yLabelPos = 0.84 cmsExtraLabel = cmsExtra yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtraLabel)) legend.Clear() if isMC: legend.AddEntry(effSFvsOF, "R_{T} MC", "p") legend.AddEntry(effSFvsOFData, "R_{T} Data", "p") else: legend.AddEntry(effSFvsOF, "R_{T}", "p") if isMC: legend.AddEntry( sfLine, "Mean R_{T} MC: %.3f" % (centralVals[runRange.label]["RT"]), "l") legend.AddEntry( sfLineData, "Mean R_{T} Data: %.3f" % (centralValsData[runRange.label]["RT"]), "l") else: legend.AddEntry( sfLine, "Mean R_{T}: %.3f" % (centralVals[runRange.label]["RT"]), "l") legend.AddEntry(ge, "syst. uncert. Data", "f") legend.Draw("same") latexSelection.DrawLatex(0.20, 0.25, selectionLabel) ROOT.gPad.RedrawAxis() if isMC: hCanvas.Print("fig/Triggereff_SFvsOF_Syst_%s_%s_%s_%s_%s_MC.pdf" % (source, selection.name, runRange.label, plot.variablePlotName, plot.additionalName)) else: hCanvas.Print("fig/Triggereff_SFvsOF_Syst_%s_%s_%s_%s_%s.pdf" % (source, selection.name, runRange.label, plot.variablePlotName, plot.additionalName))
legend.AddEntry(0, cut[i], "") legend.AddEntry(0, "#N_{j/\Psi}", "") legend.AddEntry(0, "#N_{\Psi(2s)}=", "") legend.AddEntry(0, "#N_{\gamma \gamma}=", "") legend.AddEntry( "tp", "Gaussian with math.exponential and Polynomical background", "P") #legend.AddEntry("HighPt_Mass",MassCut[0:16],"e2p") #cryst.SetParameter(0,const) legend.Draw("SAME") canvas.Write() #histogram.Write() #histogram.clear() #canvas.clear() legend.Clear() i = i + 1 # if (i == len(cut)-1): # break folder.cd("../") nframe = nframe + 1 #cos phi file2.Write() #tree.delete() file2.Close() # Mass
def calc_punzi_FOM_vs_ctau(cutlist, labellist=[],mass_point=40,additional_string="",n_sigma=1,FOM='punzi'): file = {} nevt = {} tree = {} effs = {} chain = {} hist = {} eff_dict = { k:{} for k in cutlist} back_int = { k:{} for k in cutlist} back_int_weight = { k:{} for k in cutlist} back_eff = { k:{} for k in cutlist} punzi_dict = { k:{} for k in cutlist} graph = {} back_graph = {} ncuts = len(cutlist) if labellist == []: labellist=cutlist print NTUPLEDIR print "............." #prepare ctau ordered array for 1D plot mass_array = [] ctau_array = [] #for signal we have the normal efficiency for i, s in enumerate(sign): file[s] = TFile(NTUPLEDIR + samples[s]['files'][0] + ".root", "READ") # Read TFile tree[s] = file[s].Get("ntuple/tree") # Read TTree nevt[s] = (file[s].Get('counter/c_nEvents')).GetBinContent(1)# all gen events before cuts! # tree[s] = file[s].Get("skim") # TODO: add with global variable for skimmed tree # nevt[s] = (file[s].Get('c_nEvents')).GetBinContent(1) # TODO: add with global variable for skimmed tree effs[s] = [0]*(ncuts+1) if samples[s]['mass'] not in mass_array: mass_array.append(samples[s]['mass']) if samples[s]['ctau'] not in ctau_array: ctau_array.append(samples[s]['ctau']) for j, c in enumerate(cutlist): tot_gen = nevt[s] n = tree[s].GetEntries("(" + cutlist[j] + ")") if tot_gen==0: effs[s][j] = float(0.) else: effs[s][j] = (float(n)/(tot_gen)) eff_dict[c][s] = {'mass' : samples[s]['mass'], 'ctau' : samples[s]['ctau'], 'eff' :effs[s][j]} #sort mass array masses = np.array(mass_array) masses.sort() ctaus = np.array(ctau_array) ctaus.sort() #define multigraph mg = TMultiGraph() leg = TLegend(0.78, 0.7, 0.98, 0.98) leg2 = TLegend(0., 0.4, 0.98, 0.98) leg.SetTextSize(0.03) leg2.SetTextSize(0.03) leg.SetBorderSize(0) leg2.SetBorderSize(0) leg.SetHeader("m_{#pi}=" +str(mass_point)+" GeV") leg2.SetHeader("m_{#pi}=" +str(mass_point)+" GeV") #for background let's first consider the cut for j, c in enumerate(cutlist): print "cut: ", c #then loop over background integral = 0 weighted_integral = 0 back_tot_events = 0 for i, s in enumerate(back): chain[s] = TChain("ntuple/tree") # chain[s] = TChain("skim") # TODO: add with global variable for skimmed tree #print "back: ", s back_file = {} for p, ss in enumerate(samples[s]['files']): back_file[ss] = TFile(NTUPLEDIR + ss + ".root", "READ") # Read TFile if verbose: print "file: ", ss if verbose: print "gen events: ", (back_file[ss].Get('counter/c_nEvents')).GetBinContent(1) if verbose: print "tree events: ", (back_file[ss].Get('ntuple/tree')).GetEntries() back_tot_events += (back_file[ss].Get('counter/c_nEvents')).GetBinContent(1) # back_tot_events += (back_file[ss].Get('c_nEvents')).GetBinContent(1) # TODO: add with global variable for skimmed tree chain[s].Add(NTUPLEDIR + ss + ".root") weight = "EventWeight" var = "nPV" # var = "nCHSJets" # TODO: add with global variable for skimmed tree hist[s] = TH1F(s, ";"+variable[var]['title'], variable[var]['nbins'], variable[var]['min'], variable[var]['max']) hist[s].Sumw2() cutstring = "("+weight+")" + ("*("+cutlist[j]+")" if len(cutlist[j])>0 else "") chain[s].Project(s, var, "")#"1*"+"("+weight+")") hist[s].SetOption("%s" % chain[s].GetTree().GetEntriesFast()) if verbose: print "events in the histo with get entries with empty project: ", hist[s].GetEntries() if verbose: print "area under histo with empty project: ", hist[s].Integral() chain[s].Project(s, var, cutstring)#"1*"+"("+weight+")") hist[s].SetOption("%s" % chain[s].GetTree().GetEntriesFast()) hist[s].Scale(samples[s]['weight'] if hist[s].Integral() >= 0 else 0) if verbose: print "events in the histo with get entries after project: ", hist[s].GetEntries() if verbose: print "area under histo after project: ", hist[s].Integral() integral += hist[s].GetEntries() weighted_integral += hist[s].Integral() back_int[c] = integral back_int_weight[c] = weighted_integral if back_tot_events==0: back_eff[c] = float(0.) else: back_eff[c] = float(integral)/float(back_tot_events) if verbose: print "cut: ", c if verbose: print "back tot events (unweighted):", back_tot_events if verbose: print "back integral (unweighted): ", back_int[c] if verbose: print "back integral (weighted): ", back_int_weight[c] if verbose: print "back eff (unweighted): ", back_eff[c]*100 if FOM=="signaleff": punzi_dict[c]['back'] = {'back' : back_eff[c]*100} for i, s in enumerate(sign): if FOM=="punzi": punzi_dict[c][s] = {'sign': eff_dict[c][s]['eff']/(n_sigma*0.5 + math.sqrt(back_int_weight[c]))} elif FOM=="signaleff": punzi_dict[c][s] = {'sign': eff_dict[c][s]['eff']*100} else: print "not punzi FOM, aborting!" exit() #for each cut, we need a graph for j, c in enumerate(cutlist): #first let's build the ordered punzi vector w.r.t. masses, for a chosen ctau punzi_array = [] back_array = [] for la in ctaus: #la = str(a) if la== 0.001: st = "VBFH_M"+str(mass_point)+"_ctau0" elif la==0.05 or la==0.1: st = "VBFH_M"+str(mass_point)+"_ctau"+str(str(la).replace("0.","0p")) else: st = "VBFH_M"+str(mass_point)+"_ctau"+str(int(la)) #st = "VBFH_M"+str(mass_point)+"_ctau"+str(a) punzi_array.append(punzi_dict[c][st]['sign']) mass = array('d', masses) ct = array('d', ctaus) p_array = array('d',punzi_array) #graph[c] = TGraph(len(mass),mass, np.array(p_array)) graph[c] = TGraph(len(ct),ct, np.array(p_array)) graph[c].SetMarkerStyle(21) graph[c].SetLineWidth(2) graph[c].SetMarkerSize(1.) graph[c].SetMarkerColor(colors[j]) graph[c].SetLineColor(colors[j]) graph[c].SetFillColor(colors[j]) #graph[c].SetLogx() leg.AddEntry(graph[c],labellist[j],'PL') leg2.AddEntry(graph[c],labellist[j],'PL') mg.Add(graph[c]) if FOM=="signaleff": #add plot for background for a in ctaus: back_array.append(punzi_dict[c]['back']['back']) mass = array('d', masses) ct = array('d', ctaus) e_array = array('d',back_array) #back_graph[c] = TGraph(len(mass),mass, np.array(e_array)) back_graph[c] = TGraph(len(ct),ct, np.array(e_array)) back_graph[c].SetMarkerStyle(0) back_graph[c].SetLineWidth(2) back_graph[c].SetMarkerSize(1.) back_graph[c].SetMarkerColor(colors[j]) back_graph[c].SetLineColor(colors[j]) back_graph[c].SetLineStyle(2) back_graph[c].SetFillColor(colors[j]) #back_graph[c].SetLogx() leg.AddEntry(back_graph[c],labellist[j]+" bkg.",'PL') #leg2.AddEntry(back_graph[c],labellist[j]+" bkg.",'PL') mg.Add(back_graph[c]) if FOM=="signaleff": dummy = TGraph(len(ct),ct, np.array(e_array)) dummy.SetMarkerStyle(0) dummy.SetLineWidth(2) dummy.SetMarkerSize(1.) dummy.SetLineColor(15) dummy.SetLineStyle(2) leg2.AddEntry(dummy, 'cuts on bkg.','PL') cmg = TCanvas("cmg", "cmg", 2000, 800) cmg.cd() cmg.SetGrid() if FOM=="signaleff": cmg.SetLogx() pad1 = TPad("pad1", "pad1", 0, 0., 0.75, 1.0) pad1.SetGrid() pad1.SetLogx() if FOM=="signaleff": #print "LOL" pad1.SetLogy() pad1.Draw() pad1.cd() if FOM=="signaleff": mg.SetMaximum(101) #mg.SetMinimum(1.e-50) mg.Draw("APL") mg.GetXaxis().SetTitle('c#tau_{#pi} (mm)') mg.GetYaxis().SetTitleOffset(1.2); if FOM=="punzi": mg.GetYaxis().SetTitle('Punzi significance @ '+str(n_sigma)+' #sigma, VBF cuts') mg.GetYaxis().SetTitleOffset(1.5) elif FOM=="signaleff": mg.GetYaxis().SetTitle('Signal (background) efficiency, VBF cuts (%)') else: print "not punzi FOM, aborting" cmg.cd() pad2 = TPad("pad2", "pad2", 0.75, 0., 1, 1.0) pad2.SetGrid() pad2.SetLogx() pad2.Draw() pad2.cd() leg2.SetTextSize(0.07) leg.Clear()#????????? leg2.Draw() cmg.Update() if FOM=="punzi": cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/Punzi_m"+str(mass_point)+"_"+str(n_sigma)+"sigma"+additional_string+"_v0_pfXTag.pdf") cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/Punzi_m"+str(mass_point)+"_"+str(n_sigma)+"sigma"+additional_string+"_v0_pfXTag.png") elif FOM=="signaleff": cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/SignalEff_m"+str(mass_point)+additional_string+"_v0_pfXTag.pdf") cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/SignalEff_m"+str(mass_point)+additional_string+"_v0_pfXTag.png") else: print "not punzi FOM, aborting" if not options.bash: raw_input("Press Enter to continue...") cmg.Close()
class DataMCPlot(object): '''Handles a Data vs MC plot. Features a list of histograms (some of them being stacked), and several Drawing functions. ''' def __init__(self, name): self.histosDict = {} self.histos = [] self.supportHist = None self.name = name self.stack = None self.legendOn = True self.legend = None self.legendBorders = 0.17, 0.46, 0.44, 0.89 # self.lastDraw = None # self.lastDrawArgs = None self.stack = None self.nostack = None self.blindminx = None self.blindmaxx = None self.groups = {} self.axisWasSet = False def Blind(self, minx, maxx, blindStack): self.blindminx = minx self.blindmaxx = maxx if self.stack and blindStack: self.stack.Blind(minx, maxx) if self.nostack: for hist in self.nostack: hist.Blind(minx, maxx) def AddHistogram(self, name, histo, layer=0, legendLine=None): '''Add a ROOT histogram, with a given name. Histograms will be drawn by increasing layer.''' tmp = Histogram(name, histo, layer, legendLine) self.histos.append(tmp) self.histosDict[name] = tmp # tmp.AddEntry( self.legend, legendLine) def Group(self, groupName, namesToGroup, layer=None, style=None): '''Group all histos with names in namesToGroup into a single histo with name groupName. All histogram properties are taken from the first histogram in namesToGroup. See UnGroup as well ''' groupHist = None realNames = [] actualNamesInGroup = [] for name in namesToGroup: hist = self.histosDict.get(name, None) if hist is None: print 'warning, no histo with name', name continue if groupHist is None: groupHist = hist.Clone(groupName) self.histos.append(groupHist) self.histosDict[groupName] = groupHist else: groupHist.Add(hist) actualNamesInGroup.append(name) realNames.append(hist.realName) hist.on = False if groupHist: self.groups[groupName] = actualNamesInGroup groupHist.realName = ','.join(realNames) def UnGroup(self, groupName): '''Ungroup groupName, recover the histograms in the group''' group = self.groups.get(groupName, None) if group is None: print groupName, 'is not a group in this plot.' return for name in group: self.histosDict[name].on = True self.histosDict[groupName].on = False def Replace(self, name, pyhist): '''Not very elegant... should have a clone function in Histogram...''' oldh = self.histosDict.get(name, None) pythist = copy.deepcopy(pyhist) pyhist.layer = oldh.layer pyhist.stack = oldh.stack pyhist.name = oldh.name pyhist.legendLine = oldh.legendLine pyhist.SetStyle(oldh.style) pyhist.weighted.SetFillStyle(oldh.weighted.GetFillStyle()) if oldh is None: print 'histogram', name, 'does not exist, cannot replace it.' return else: index = self.histos.index(oldh) self.histosDict[name] = pyhist self.histos[index] = pyhist def _SortedHistograms(self, reverse=False): '''Returns the histogram dictionary, sorted by increasing layer, excluding histograms which are not "on". This function is used in all the Draw functions.''' byLayer = sorted(self.histos, key=attrgetter('layer')) byLayerOn = [hist for hist in byLayer if (hist.on is True)] if reverse: byLayerOn.reverse() return byLayerOn def Hist(self, histName): '''Returns an histogram. Print the DataMCPlot object to see which histograms are available.''' return self.histosDict[histName] def DrawNormalized(self, opt=''): '''All histograms are drawn as PDFs, even the stacked ones''' same = '' for hist in self._SortedHistograms(): hist.obj.DrawNormalized(same + opt) if same == '': same = 'same' self.DrawLegend() if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawNormalized' # self.lastDrawArgs = [ opt ] def Draw(self, opt=''): '''All histograms are drawn.''' same = '' self.supportHist = None for hist in self._SortedHistograms(): if self.supportHist is None: self.supportHist = hist hist.Draw(same + opt) if same == '': same = 'same' yaxis = self.supportHist.GetYaxis() yaxis.SetRangeUser(0.01, ymax(self._SortedHistograms())) self.DrawLegend() if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'Draw' # self.lastDrawArgs = [ opt ] def CreateLegend(self, ratio=False): if self.legend is None: self.legend = TLegend(*self.legendBorders) self.legend.SetFillColor(0) self.legend.SetFillStyle(0) self.legend.SetLineColor(0) else: self.legend.Clear() hists = self._SortedHistograms(reverse=True) if ratio: hists = hists[:-1] # removing the last histo. for index, hist in enumerate(hists): hist.AddEntry(self.legend) def DrawLegend(self, ratio=False): '''Draw the legend.''' if self.legendOn: self.CreateLegend(ratio) self.legend.Draw('same') def DrawRatio(self, opt=''): '''Draw ratios : h_i / h_0. h_0 is the histogram with the smallest layer, and h_i, i>0 are the other histograms. if the DataMCPlot object contains N histograms, N-1 ratio plots will be drawn. To take another histogram as the denominator, change the layer of this histogram by doing: dataMCPlot.Hist("histName").layer = -99 ''' same = '' denom = None self.ratios = [] for hist in self._SortedHistograms(): if denom == None: denom = hist continue ratio = copy.deepcopy(hist) ratio.obj.Divide(denom.obj) ratio.obj.Draw(same) self.ratios.append(ratio) if same == '': same = 'same' self.DrawLegend(ratio=True) if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawRatio' # self.lastDrawArgs = [ opt ] def DrawDataOverMCMinus1(self, ymin=-0.5, ymax=0.5): stackedHists = [] dataHist = None for hist in self._SortedHistograms(): if hist.stack is False: dataHist = hist continue stackedHists.append(hist) self._BuildStack(stackedHists, ytitle='Data/MC') mcHist = self.stack.totalHist self.dataOverMCHist = copy.deepcopy(dataHist) self.dataOverMCHist.Add(mcHist, -1) self.dataOverMCHist.Divide(mcHist) self.dataOverMCHist.Draw() yaxis = self.dataOverMCHist.GetYaxis() yaxis.SetRangeUser(ymin, ymax) yaxis.SetTitle('Data/MC - 1') yaxis.SetNdivisions(5) fraclines = 0.2 if ymax <= 0.2 or ymin >= -0.2: fraclines = 0.1 self.DrawRatioLines(self.dataOverMCHist, fraclines, 0.) if TPad.Pad(): TPad.Pad().Update() def DrawRatioStack(self, opt='', xmin=None, xmax=None, ymin=None, ymax=None): '''Draw ratios. The stack is considered as a single histogram.''' denom = None # import pdb; pdb.set_trace() histForRatios = [] denom = None for hist in self._SortedHistograms(): if hist.stack is False: # if several unstacked histograms, the highest layer is used denom = hist continue histForRatios.append(hist) self._BuildStack(histForRatios, ytitle='MC/Data') self.stack.Divide(denom.obj) if self.blindminx and self.blindmaxx: self.stack.Blind(self.blindminx, self.blindmaxx) self.stack.Draw(opt, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) self.ratios = [] for hist in self.nostack: if hist is denom: continue ratio = copy.deepcopy(hist) ratio.obj.Divide(denom.obj) ratio.obj.Draw('same') self.ratios.append(ratio) self.DrawLegend(ratio=True) self.DrawRatioLines(denom, 0.2, 1) if TPad.Pad(): TPad.Pad().Update() def DrawNormalizedRatioStack(self, opt='', xmin=None, xmax=None, ymin=None, ymax=None): '''Draw ratios. The stack is considered as a single histogram. All histograms are normalized before computing the ratio''' denom = None histForRatios = [] for hist in self._SortedHistograms(): # taking the first histogram (lowest layer) # as the denominator histogram. if denom == None: denom = copy.deepcopy(hist) continue # other histograms will be divided by the denominator histForRatios.append(hist) self._BuildStack(histForRatios, ytitle='MC p.d.f. / Data p.d.f.') self.stack.Normalize() denom.Normalize() self.stack.Divide(denom.weighted) self.stack.Draw(opt, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) self.ratios = [] for hist in self.nostack: # print 'nostack ', hist ratio = copy.deepcopy(hist) ratio.Normalize() ratio.obj.Divide(denom.weighted) ratio.obj.Draw('same') self.ratios.append(ratio) self.DrawLegend(ratio=True) self.DrawRatioLines(denom, 0.2, 1) if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawNormalizedRatioStack' # self.lastDrawArgs = [ opt ] def DrawRatioLines(self, hist, frac=0.2, y0=1.): '''Draw a line at y = 1, at 1+frac, and at 1-frac. hist is used to get the x axis range.''' xmin = hist.obj.GetXaxis().GetXmin() xmax = hist.obj.GetXaxis().GetXmax() line = TLine() line.DrawLine(xmin, y0, xmax, y0) line.DrawLine(xmin, y0 + frac, xmax, y0 + frac) line.DrawLine(xmin, y0 - frac, xmax, y0 - frac) def DrawStack(self, opt='', xmin=None, xmax=None, ymin=None, ymax=None): '''Draw all histograms, some of them in a stack. if Histogram.stack is True, the histogram is put in the stack.''' self._BuildStack(self._SortedHistograms(), ytitle='Events') same = 'same' if len(self.nostack) == 0: same = '' self.supportHist = None for hist in self.nostack: hist.Draw() if not self.supportHist: self.supportHist = hist self.stack.Draw(opt + same, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) if self.supportHist is None: self.supportHist = self.stack.totalHist if not self.axisWasSet: mxsup = self.supportHist.weighted.GetBinContent( self.supportHist.weighted.GetMaximumBin()) mxstack = self.stack.totalHist.weighted.GetBinContent( self.stack.totalHist.weighted.GetMaximumBin()) mx = max(mxsup, mxstack) if ymin is None: ymin = 0.01 if ymax is None: ymax = mx * 1.3 self.supportHist.GetYaxis().SetRangeUser(ymin, ymax) self.axisWasSet = True for hist in self.nostack: if self.blindminx: hist.Blind(self.blindminx, self.blindmaxx) hist.Draw('same') self.DrawLegend() if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawStack' # self.lastDrawArgs = [ opt ] def DrawNormalizedStack(self, opt='', xmin=None, xmax=None, ymin=0.001, ymax=None): '''Draw all histograms, some of them in a stack. if Histogram.stack is True, the histogram is put in the stack. all histograms out of the stack, and the stack itself, are shown as PDFs.''' self._BuildStack(self._SortedHistograms(), ytitle='p.d.f.') self.stack.DrawNormalized(opt, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) for hist in self.nostack: hist.obj.DrawNormalized('same') self.DrawLegend() if TPad.Pad(): TPad.Pad().Update() # self.lastDraw = 'DrawNormalizedStack' # self.lastDrawArgs = [ opt ] def Rebin(self, factor): '''Rebin, and redraw.''' # the dispatching technique is not too pretty, # but keeping a self.lastDraw function initialized to one of the Draw functions # when calling it creates a problem in deepcopy. for hist in self.histos: hist.Rebin(factor) self.axisWasSet = False def NormalizeToBinWidth(self): '''Normalize each Histograms bin to the bin width.''' for hist in self.histos: hist.NormalizeToBinWidth() def _BuildStack(self, hists, ytitle=None): '''build a stack from a list of Histograms. The histograms for which Histogram.stack is False are put in self.nostack''' self.stack = None self.stack = Stack(self.name + '_stack', ytitle=ytitle) self.nostack = [] for hist in hists: if hist.stack: self.stack.Add(hist) else: self.nostack.append(hist) def __str__(self): if self.stack is None: self._BuildStack(self._SortedHistograms(), ytitle='Events') tmp = [' '.join(['DataMCPlot: ', self.name])] tmp.append('Histograms:') for hist in self._SortedHistograms(reverse=True): tmp.append(' '.join(['\t', str(hist)])) tmp.append( 'Stack yield = {integ:7.1f}'.format(integ=self.stack.integral)) return '\n'.join(tmp)
def dependencies(path, selection, plots, runRange, mc, backgrounds, cmsExtra): hCanvas = TCanvas("hCanvas", "Distribution", 800, 800) legend = TLegend(0.6, 0.7, 0.9, 0.9) legend.SetFillStyle(0) legend.SetBorderSize(0) ROOT.gStyle.SetOptStat(0) for name in plots: hCanvas.Clear() plot = getPlot(name) plot.addRegion(selection) plot.cleanCuts() plot.cuts = plot.cuts % runRange.runCut if not "Forward" in selection.name: relSyst = systematics.rOutIn.central.val if "Central" in selection.name: region = "central" else: region = "inclusive" else: relSyst = systematics.rOutIn.forward.val region = "forward" if len(plot.binning) == 0: bins = [ plot.firstBin + (plot.lastBin - plot.firstBin) / plot.nBins * i for i in range(plot.nBins + 1) ] else: bins = plot.binning #~ rOutIn = {"LowMass":{"EE":[],"MM":[],"SF":[]},"HighMass":{"EE":[],"MM":[],"SF":[]},"BelowZ":{"EE":[],"MM":[],"SF":[]},"AboveZ":{"EE":[],"MM":[],"SF":[]}} #~ rOutInErr = {"LowMass":{"EE":[],"MM":[],"SF":[]},"HighMass":{"EE":[],"MM":[],"SF":[]},"BelowZ":{"EE":[],"MM":[],"SF":[]},"AboveZ":{"EE":[],"MM":[],"SF":[]}} rOutIn = { "EdgeMass": { "EE": [], "MM": [], "SF": [] }, "LowMass": { "EE": [], "MM": [], "SF": [] }, "HighMass": { "EE": [], "MM": [], "SF": [] }, } rOutInErr = { "EdgeMass": { "EE": [], "MM": [], "SF": [] }, "LowMass": { "EE": [], "MM": [], "SF": [] }, "HighMass": { "EE": [], "MM": [], "SF": [] } } binningErrs = [] plotBinning = [] for i in range(0, len(bins) - 1): binningErrs.append((bins[i + 1] - bins[i]) / 2) if i == 0: plotBinning.append((bins[i + 1] - abs(bins[i])) / 2) else: plotBinning.append(plotBinning[i - 1] + (bins[i + 1] - bins[i]) / 2 + binningErrs[i - 1]) tmpCuts = selection.cut cuts = selection.cut.split("&&") cutsUp = [] cutsDown = [] cutsEqual = [] for cut in cuts: if "%s >" % plot.variable in cut: cutsUp.append(cut + "&&") elif "%s <" % plot.variable in cut: cutsDown.append(cut + "&&") elif "%s ==" % plot.variable in cut: cutsEqual.append(cut + "&&") for cut in cutsUp: selection.cut = selection.cut.replace(cut, "") for cut in cutsDown: selection.cut = selection.cut.replace(cut, "") for cut in cutsEqual: selection.cut = selection.cut.replace(cut, "") selection.cut = selection.cut + " && %s > %f && %s < %f" % ( plot.variable, bins[i], plot.variable, bins[i + 1]) + " && %s" % runRange.runCut additionalLabel = "%s_%.2f_%.2f" % (plot.variable, bins[i], bins[i + 1]) centralVal = centralValues(path, selection, runRange, mc, backgrounds, cmsExtra, additionalLabel) for combination in ["EE", "MM", "SF"]: #~ for region in ["LowMass","HighMass","BelowZ","AboveZ"]: for region in ["EdgeMass", "LowMass", "HighMass"]: rOutIn[region][combination].append( centralVal["rOutIn%s%s" % (region, combination)]) rOutInErr[region][combination].append( centralVal["rOutIn%sErr%s" % (region, combination)]) selection.cut = tmpCuts if mc: if os.path.isfile("shelves/rOutIn_%s_%s_MC.pkl" % (selection.name, runRange.label)): centralVals = pickle.load( open( "shelves/rOutIn_%s_%s_MC.pkl" % (selection.name, runRange.label), "rb")) else: centralVals = centralValues(path, selection, runRange, mc, backgrounds, cmsExtra) else: if os.path.isfile("shelves/rOutIn_%s_%s.pkl" % (selection.name, runRange.label)): centralVals = pickle.load( open( "shelves/rOutIn_%s_%s.pkl" % (selection.name, runRange.label), "rb")) else: centralVals = centralValues(path, selection, runRange, mc, backgrounds, cmsExtra) for combination in ["EE", "MM", "SF"]: relSystSave = relSyst #~ for region in ["LowMass","HighMass","BelowZ","AboveZ"]: for region in ["EdgeMass", "LowMass", "HighMass"]: relSyst = relSystSave hCanvas = TCanvas("hCanvas", "Distribution", 800, 800) plotPad = TPad("plotPad", "plotPad", 0, 0, 1, 1) style = setTDRStyle() style.SetTitleYOffset(1.3) style.SetPadLeftMargin(0.16) plotPad.UseCurrentStyle() plotPad.Draw() plotPad.cd() plotPad.DrawFrame(plot.firstBin, 0.0, plot.lastBin, 0.15, "; %s ; %s" % (plot.xaxis, "R_{out/in}")) bandX = array("f", [plot.firstBin, plot.lastBin]) bandY = array("f", [ centralVals["rOutIn%s%s" % (region, combination)], centralVals["rOutIn%s%s" % (region, combination)] ]) bandYErr = array("f", [ centralVals["rOutIn%s%s" % (region, combination)] * relSyst, centralVals["rOutIn%s%s" % (region, combination)] * relSyst ]) bandXErr = array("f", [0, 0]) errorband = ROOT.TGraphErrors(2, bandX, bandY, bandXErr, bandYErr) errorband.GetYaxis().SetRangeUser(0.0, 0.15) errorband.GetXaxis().SetRangeUser(-5, 105) errorband.Draw("3same") errorband.SetFillColor(ROOT.kOrange - 9) rOutInLine = ROOT.TLine( plot.firstBin, centralVals["rOutIn%s%s" % (region, combination)], plot.lastBin, centralVals["rOutIn%s%s" % (region, combination)]) rOutInLine.SetLineStyle(ROOT.kDashed) rOutInLine.SetLineWidth(2) rOutInLine.Draw("same") binning = array("f", plotBinning) rOutInVals = array("f", rOutIn[region][combination]) binningErrs = array("f", binningErrs) rOutInValsErrs = array("f", rOutInErr[region][combination]) graph = ROOT.TGraphErrors(len(binning), binning, rOutInVals, binningErrs, rOutInValsErrs) graph.Draw("Psame0") legend.Clear() if mc: legend.AddEntry(graph, "r_{out,in} MC", "p") else: legend.AddEntry(graph, "r_{out,in} Data", "p") legend.AddEntry( rOutInLine, "Mean r_{out,in} = %.3f" % centralVals["rOutIn%s%s" % (region, combination)], "l") legend.AddEntry(errorband, "Mean r_{out,in} #pm %d %%" % (relSyst * 100), "f") legend.Draw("same") latex = ROOT.TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = ROOT.TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055) latexCMS.SetNDC(True) latexCMSExtra = ROOT.TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "%s fb^{-1} (13 TeV)" % runRange.printval) latexCMS.DrawLatex(0.19, 0.89, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.83 else: yLabelPos = 0.85 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) ROOT.gPad.RedrawAxis() if mc: hCanvas.Print( "fig/rOutInSyst_%s_%s_%s_%s_%s_%s_MC.pdf" % (selection.name, runRange.label, plot.variablePlotName, region, combination, plot.additionalName)) else: hCanvas.Print( "fig/rOutInSyst_%s_%s_%s_%s_%s_%s.pdf" % (selection.name, runRange.label, plot.variablePlotName, region, combination, plot.additionalName))