def Dump_BKGCompare(tag="FourTag", title="SR_Varations", region="Signal"): column_lst = ["Prediction", "QCD", "ttbar"] column_key_lst = ["data_est", "qcd_est", "ttbar_est"] #for looping through the objects texoutpath = inputpath + inputdir + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open(texoutpath + tag + "_" + title + ".tex", "w") ### tableList = [] ### #start the table add_table_head(tableList, column_lst, title=" " + tag) ##save a temp value nominal = {} for i, syst in enumerate(syst_lst): #get the corresponding region outstr = "" outstr += syst.replace("_", " ") if syst is not "" else "Nominal" systpath = "_" + syst if syst is not "" else "" inputtex = inputpath + inputdir + (systpath + "/" + "sum_" + inputdir + systpath + ".txt") f1 = open(inputtex, 'r') masterdic = json.load(f1) #save the noiminal values if (syst is ""): for Types in column_key_lst: nominal[Types] = helpers.round_sig( masterdic[Types][tag][region], 2) nominal[Types + "_err"] = helpers.round_sig( masterdic[Types][tag][region + "_err"], 2) #print masterdic, tag for Types in column_key_lst: value = (masterdic[Types][tag][region] / nominal[Types] - 1) * 100 error = helpers.ratioerror(masterdic[Types][tag][region], nominal[Types], masterdic[Types][tag][region + "_err"], nominal[Types + "_err"]) * 100 outstr += add_entry(value, error, percent=True) #finish up del (masterdic) f1.close() #finish the current entry outstr += "\\\\" if (syst != syst_lst[0]): tableList.append(outstr) #finish the table add_table_tail(tableList, column_lst) #return the table for line in tableList: print line outFile.write(line + " \n")
def Dump_BKGCompare(tag="FourTag", title="SR_Varations", region="Signal"): column_lst = ["Prediction", "Diff", "QCD", "ttbar"] column_key_lst = ["data_est", "data_est", "qcd_est", "ttbar_est"] #for looping through the objects texoutpath = inputpath + inputdir + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + tag + "_" + title + ".tex", "w") ### tableList = [] ### #start the table add_table_head(tableList, column_lst, title=" " + tag) ##save a temp value nominal = {} for i, syst in enumerate(syst_lst): #get the corresponding region outstr = "" outstr += syst.replace("_", " ") if syst is not "" else "Nominal" systpath = "_" + syst if syst is not "" else reweightpath inputtex = inputpath + inputdir + (systpath + "/" + "sum_" + inputdir + systpath + ".txt") f1 = open(inputtex, 'r') masterdic = json.load(f1) #save the noiminal values if (syst is ""): for Types in column_key_lst: nominal[Types] = helpers.round_sig(masterdic[Types][tag][region], 2) nominal[Types+"_err"] = helpers.round_sig(masterdic[Types][tag][region+"_err"], 2) #print masterdic, tag for j, Types in enumerate(column_key_lst): if j == 0: ##for the first entry value = masterdic[Types][tag][region] error = masterdic[Types][tag][region+"_err"] outstr += add_entry(value, error, percent=True) else: ##do percentage value = (masterdic[Types][tag][region]/nominal[Types] - 1) * 100 error = helpers.ratioerror(masterdic[Types][tag][region], nominal[Types], masterdic[Types][tag][region+"_err"], nominal[Types+"_err"]) * 100 outstr += add_entry(value, error, percent=True) #finish up del(masterdic) f1.close() #finish the current entry outstr+="\\\\" if (syst!=syst_lst[-1]): tableList.append(outstr) #finish the table add_table_tail(tableList, column_lst) #return the table for line in tableList: print line outFile.write(line+" \n")
def find_syst(masterdic, c, systag, col): sys_lst = {} #loopoing throught the dictionary for key1 in masterdic:#get to the 2b/3b/4b region; containes the systemtaic info as well if (c in key1) and (systag in key1): for key2 in masterdic[key1]:#get to the qcd/ttbar/rsg region if col in key2: value_def = abs(masterdic[key1][key2]["int"] / masterdic[c][key2]["int"] - 1) value_def_err = abs(helpers.ratioerror(masterdic[key1][key2]["int"], masterdic[c][key2]["int"], masterdic[key1][key2]["int_err"], masterdic[c][key2]["int_err"])) sys_lst.update({key1: (value_def, value_def_err)}) if debug: print systag, col, key1, key2, value_def return sys_lst
def find_syst(masterdic, c, systag, col): debug = False sys_lst = {} #loopoing throught the dictionary for key1 in masterdic:#get to the 2b/3b/4b region; containes the systemtaic info as well if (c in key1) and (systag in key1): for key2 in masterdic[key1]:#get to the qcd/ttbar/rsg region if col in key2: if debug: print systag, col, key1, key2 value_def = abs(masterdic[key1][key2]["int"] / masterdic[c][key2]["int"] - 1) value_def_err = abs(helpers.ratioerror(masterdic[key1][key2]["int"], masterdic[c][key2]["int"], masterdic[key1][key2]["int_err"], masterdic[c][key2]["int_err"])) sys_lst.update({key1: (value_def, value_def_err)}) return sys_lst
def GetDiff(dic1, dic2, histname=""): result = {} for i, cut in enumerate(cut_lst): #get the corresponding region cutcounts = {} for j, region in enumerate(region_lst): if dic2[cut][region]!= 0: cutcounts[region] = (dic1[cut][region] - dic2[cut][region])/dic2[cut][region] * 100 cutcounts[region + "_err"] = helpers.ratioerror(dic1[cut][region], dic2[cut][region], \ dic1[cut][region + "_err"], dic2[cut][region + "_err"]) * 100 else: cutcounts[region] = 0 cutcounts[region + "_err"] = 0 result[cut] = cutcounts return {histname:result}
def DrawMulticomparison(inputlst, keyword="", prename="", Xrange=[0, 0], Yrange=[0, 0], norm=True, Logy=0, Rebin=1): #print inputdir tempname = "directcompare" + "_" + keyword + ("" if Logy == 0 else "_" + str(Logy)) canv = ROOT.TCanvas(tempname, tempname, 800, 800) # two pad pad0 = ROOT.TPad("pad0", "pad0", 0.0, 0.31, 1., 1.) pad0.SetRightMargin(0.05) pad0.SetBottomMargin(0.0001) pad0.SetFrameFillColor(0) pad0.SetFrameBorderMode(0) pad0.SetFrameFillColor(0) pad0.SetBorderMode(0) pad0.SetBorderSize(0) pad1 = ROOT.TPad("pad1", "pad1", 0.0, 0.0, 1., 0.30) pad1.SetRightMargin(0.05) pad1.SetBottomMargin(0.38) pad1.SetTopMargin(0.0001) pad1.SetFrameFillColor(0) pad1.SetFillStyle(0) # transparent pad1.SetFrameBorderMode(0) pad1.SetFrameFillColor(0) pad1.SetBorderMode(0) pad1.SetBorderSize(0) #top pad canv.cd() pad0.SetLogy(Logy) pad0.Draw() pad0.cd() xleg, yleg = 0.5, 0.6 legend = ROOT.TLegend(xleg, yleg, xleg+0.2, yleg+0.3) counter = 0 maxbincontent = (0.05 if Logy ==0 else 10) temphst_lst = [] graph_lst = [] tempratio_lst = [] for i, dic in enumerate(inputlst): #print dic["file"], dic["path"] ##????? refroot = ROOT.TFile.Open(inputpath + dic["file"]) temphst_lst.append(refroot.Get(dic["path"]).Clone()) tempratio_lst.append(refroot.Get(dic["path"]).Clone(dic["path"] + "_ratio")) temphst_lst[i].SetDirectory(0) #otherwise the hist lives in the current open file tempratio_lst[i].SetDirectory(0) #otherwise the hist lives in the current open file if Rebin != 1: temphst_lst[i].Rebin(Rebin) tempratio_lst[i].Rebin(Rebin) if norm: if Xrange != [0, 0]: temphst_lst[i].Scale(temphst_lst[0].Integral(temphst_lst[0].GetXaxis().FindBin(Xrange[0]), temphst_lst[0].GetXaxis().FindBin(Xrange[1] + 1))/temphst_lst[i].Integral(temphst_lst[0].GetXaxis().FindBin(Xrange[0]), temphst_lst[0].GetXaxis().FindBin(Xrange[1] + 1))) else: temphst_lst[i].Scale(temphst_lst[0].Integral(0, temphst_lst[0].GetXaxis().GetNbins()+1)/temphst_lst[i].Integral(0, temphst_lst[i].GetXaxis().GetNbins()+1)) for j in range(1, temphst_lst[0].GetNbinsX()+1): try: tempratio_lst[i].SetBinContent(j, temphst_lst[i].GetBinContent(j) / temphst_lst[0].GetBinContent(j)) tempratio_lst[i].SetBinError(j, helpers.ratioerror(\ temphst_lst[i].GetBinContent(j), temphst_lst[0].GetBinContent(j), \ temphst_lst[i].GetBinError(j), temphst_lst[0].GetBinError(j))) except ZeroDivisionError: pass #print "Divide by zero! Check bin content in", canv.GetName() maxbincontent = max(maxbincontent, temphst_lst[i].GetMaximum()) #graph_lst.append(helpers.TH1toTAsym(temphst_lst[i], efficiency=False)) temphst_lst[i].SetLineColor(1 if i == 0 else CONF.clr_lst[i]) #temphst_lst[i].SetLineStyle(1 + i) temphst_lst[i].SetMarkerStyle(20 + i) temphst_lst[i].SetMarkerColor(1 if i == 0 else CONF.clr_lst[i]) temphst_lst[i].SetMarkerSize(1) temphst_lst[i].SetMaximum(maxbincontent * (1.5 if Logy == 0 else 150)) temphst_lst[i].SetMinimum(0.001 if Logy == 0 else 0.02) if Xrange != [0, 0]: #print Xrange temphst_lst[i].GetXaxis().SetRangeUser(Xrange[0], Xrange[1]) chi2 = temphst_lst[i].Chi2Test(temphst_lst[0], "QU CHI2/NDF") #legend.AddEntry(temphst_lst[i], dic["leg"] + " KS: " + str(('%.3g' % temphst_lst[i].KolmogorovTest(temphst_lst[0], "QU"))), "pl") legend.AddEntry(temphst_lst[i], dic["leg"] + " chi2: " + str(('%.3g' % (chi2))), "pl") temphst_lst[i].Draw("EP" if i==0 else "hist same") refroot.Close() legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() # draw watermarks xatlas, yatlas = 0.28, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas-0.06, "Simulations") lumi = ROOT.TLatex(xatlas, yatlas-0.12, "MC #sqrt{s} = 13 TeV") info = ROOT.TLatex(xatlas, yatlas-0.06, keyword.replace("data_est_", "").replace("_mHH_l", "").replace("_", " ")) watermarks = [atlas, info] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() #bottom pad canv.cd() pad1.Draw() pad1.cd() for i, dic in enumerate(inputlst): tempratio_lst[i].SetLineColor(1 if i == 0 else CONF.clr_lst[i]) #tempratio_lst[i].SetLineStyle(1 + i) tempratio_lst[i].SetMarkerStyle(20 + i) tempratio_lst[i].SetMarkerColor(1 if i == 0 else CONF.clr_lst[i]) tempratio_lst[i].SetMarkerSize(1) tempratio_lst[i].GetYaxis().SetTitleFont(43) tempratio_lst[i].GetYaxis().SetTitleSize(28) tempratio_lst[i].GetYaxis().SetLabelFont(43) tempratio_lst[i].GetYaxis().SetLabelSize(28) tempratio_lst[i].GetYaxis().SetTitle("ratio to ref") tempratio_lst[i].GetYaxis().SetRangeUser(0.6, 1.5) #set range for ratio plot tempratio_lst[i].GetYaxis().SetNdivisions(405) tempratio_lst[i].GetXaxis().SetTitleFont(43) tempratio_lst[i].GetXaxis().SetTitleOffset(3.5) tempratio_lst[i].GetXaxis().SetTitleSize(28) tempratio_lst[i].GetXaxis().SetLabelFont(43) tempratio_lst[i].GetXaxis().SetLabelSize(28) if Xrange != [0, 0]: tempratio_lst[i].GetXaxis().SetRangeUser(Xrange[0], Xrange[1]) if i > 0: tempratio_lst[i].Draw("ep" if i == 1 else "ep same") # draw the ratio 1 line line = ROOT.TLine(Xrange[0], 1.0, Xrange[1], 1.0) line.SetLineStyle(1) line.Draw() #save and clean up canv.SaveAs(outputpath + (prename + "_" if prename is not "" else "") + canv.GetName() + ".pdf") pad0.Close() pad1.Close() canv.Close() del(tempratio_lst) del(temphst_lst) del(graph_lst)
def DrawTrigEff(cut_lst, inputdir, outputname="", normalization="All"): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region canv = ROOT.TCanvas(inputdir + "_" + "Efficiency" + "_" + normalization, "Efficiency", 800, 800) xleg, yleg = 0.55, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2) # setup basic plot parameters # load input MC file eff_lst = [] maxbincontent = 1 minbincontent = -0.01 for i, cut in enumerate(cut_lst): eff_lst.append( ROOT.TH1F(inputdir + "_" + cut, "%s; Mass, GeV; Efficiency" % cut, int((highmass - lowmass) / 100), lowmass, highmass)) eff_lst[i].SetLineColor(2 + i) eff_lst[i].SetMarkerStyle(20 + i) eff_lst[i].SetMarkerColor(2 + i) eff_lst[i].SetMarkerSize(1) for mass in mass_lst: #here could be changed to have more options input_mc = ROOT.TFile.Open( inputpath + "signal_G_hh_c10_M%i/hist-MiniNTuple.root" % mass) cutflow_mc = input_mc.Get( "CutFlowNoWeight") #notice here we use no weight for now! totevt_mc = 0 totevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(normalization)) maxbincontent = 1 cutevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(cut)) eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), cutevt_mc / totevt_mc) eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), helpers.ratioerror(cutevt_mc, totevt_mc)) # print ratioerror(cutevt_mc, totevt_mc) input_mc.Close() eff_lst[i].SetMaximum(maxbincontent * 1.5) eff_lst[i].SetMinimum(minbincontent) legend.AddEntry( eff_lst[i], cut.replace("_", " ") if cut is not "PassTrig" else "PassJ420 lcw", "apl") canv.cd() if cut == cut_lst[0]: eff_lst[i].Draw("epl") else: eff_lst[i].Draw("same epl") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() # draw reference lines xline90 = ROOT.TLine(lowmass, 0.9, highmass, 0.9) xline90.SetLineStyle(3) xline90.Draw() xline95 = ROOT.TLine(lowmass, 0.95, highmass, 0.95) xline95.SetLineStyle(4) xline95.Draw() xline98 = ROOT.TLine(lowmass, 0.98, highmass, 0.98) xline98.SetLineStyle(5) xline98.Draw() yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) yline10.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() # finish up canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf") canv.Close()
def DrawSignalEff(cut_lst, inputdir="b77", inputroot="sum", outputname="", normalization=1.0, plotrange=(0, 3100), logy=0): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region histname = "_Signal_Significance" canv = ROOT.TCanvas( outputname + "_" + str(plotrange[0]) + "_" + str(plotrange[1]), "Efficiency", 800, 800) xleg, yleg = 0.65, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg + 0.2, yleg + 0.2) # two pad pad0 = ROOT.TPad("pad0", "pad0", 0.0, 0.31, 1., 1.) pad0.SetRightMargin(0.05) pad0.SetBottomMargin(0.0001) pad0.SetFrameFillColor(0) pad0.SetFrameBorderMode(0) pad0.SetFrameFillColor(0) pad0.SetBorderMode(0) pad0.SetBorderSize(0) pad1 = ROOT.TPad("pad1", "pad1", 0.0, 0.0, 1., 0.30) pad1.SetRightMargin(0.05) pad1.SetBottomMargin(0.38) pad1.SetTopMargin(0.0001) pad1.SetFrameFillColor(0) pad1.SetFillStyle(0) # transparent pad1.SetFrameBorderMode(0) pad1.SetFrameFillColor(0) pad1.SetBorderMode(0) pad1.SetBorderSize(0) #top pad canv.cd() pad0.SetLogy(logy) pad0.Draw() pad0.cd() # setup basic plot parameters lowmass = -50 highmass = 3150 # load input MC file input_mc = ROOT.TFile.Open(CONF.inputpath + inputdir + "/" + inputroot + "_" + inputdir + ".root") maxbincontent = normalization minbincontent = 0.0001 temp_all = input_mc.Get(cut_lst[0] + histname).Clone() temp_all.SetName("Combined") input_mc_ref = ROOT.TFile.Open(CONF.inputpath + "ref/" + "sum_ref" + ".root") temp_ref = input_mc_ref.Get(cut_lst[0] + histname).Clone() temp_ref.SetName("Run2-ref") temp_ratio = input_mc.Get(cut_lst[0] + histname).Clone() temp_ratio.SetName("Ratio") for j in range(1, temp_all.GetNbinsX() + 1): temp_all.SetBinContent(j, 0) temp_all.SetBinError(j, 0) temp_ref.SetBinContent(j, 0) temp_ref.SetBinError(j, 0) temp_all.SetMinimum(minbincontent) temp_ref.SetMinimum(minbincontent) graph_lst = [] for i, cut in enumerate(cut_lst): #print cut sig_mc = input_mc.Get(cut + histname) #get the input histogram sig_mc_ref = input_mc_ref.Get(cut + histname) #get the input histogram for j in range(1, temp_all.GetNbinsX() + 1): #temp_all.SetBinContent(j, ROOT.TMath.Sqrt(temp_all.GetBinContent(j) * temp_all.GetBinContent(j) + sig_mc.GetBinContent(j) * sig_mc.GetBinContent(j))) temp_ref.SetBinContent( j, ROOT.TMath.Sqrt( temp_ref.GetBinContent(j) * temp_ref.GetBinContent(j) + sig_mc_ref.GetBinContent(j) * sig_mc_ref.GetBinContent(j))) temp_all.SetBinContent( j, ROOT.TMath.Sqrt( temp_all.GetBinContent(j) * temp_all.GetBinContent(j) + sig_mc.GetBinContent(j) * sig_mc.GetBinContent(j))) temp_ref.SetBinError( j, ROOT.TMath.Sqrt( temp_ref.GetBinError(j) * temp_ref.GetBinError(j) + sig_mc_ref.GetBinError(j) * sig_mc_ref.GetBinError(j))) temp_all.SetBinError( j, ROOT.TMath.Sqrt( temp_all.GetBinError(j) * temp_all.GetBinError(j) + sig_mc.GetBinError(j) * sig_mc.GetBinError(j))) del (sig_mc_ref) graph_lst.append(helpers.TH1toTAsym(sig_mc, pltrange=plotrange)) graph_lst[i].SetMaximum(maxbincontent * 1.5) graph_lst[i].SetMinimum(minbincontent) graph_lst[i].SetLineColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerStyle(20 + i) graph_lst[i].SetMarkerColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerSize(1) legend.AddEntry(graph_lst[i], cut.replace("_", " "), "APL") if cut == cut_lst[0]: graph_lst[i].Draw("APC") else: graph_lst[i].Draw("PC") del (sig_mc) graph_all = helpers.TH1toTAsym(temp_all) graph_all.SetLineColor(2) graph_all.SetLineStyle(2) graph_all.SetMarkerStyle(5) graph_all.SetMarkerColor(2) graph_all.SetMarkerSize(1) graph_all.GetXaxis().SetRangeUser(plotrange[0], plotrange[1]) legend.AddEntry(graph_all, graph_all.GetName().replace("_", " "), "APL") graph_all.Draw("PC") graph_ref = helpers.TH1toTAsym(temp_ref) graph_ref.SetLineColor(1) graph_ref.SetLineStyle(3) graph_ref.SetMarkerStyle(4) graph_ref.SetMarkerColor(1) graph_ref.SetMarkerSize(1) graph_ref.GetXaxis().SetRangeUser(plotrange[0], plotrange[1]) legend.AddEntry(graph_ref, graph_ref.GetName().replace("_", " "), "APL") graph_ref.Draw("PC") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.02) legend.Draw() # draw reference lines xline05 = ROOT.TLine(lowmass, 0.05, highmass, 0.05) xline05.SetLineStyle(3) xline05.Draw() xline10 = ROOT.TLine(lowmass, 0.1, highmass, 0.1) xline10.SetLineStyle(4) xline10.Draw() yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) yline10.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() #bottom pad canv.cd() pad1.Draw() pad1.cd() for j in range(1, temp_ratio.GetNbinsX() + 1): try: temp_ratio.SetBinContent( j, temp_all.GetBinContent(j) / temp_ref.GetBinContent(j)) temp_ratio.SetBinError(j, helpers.ratioerror(\ temp_all.GetBinContent(j), temp_ref.GetBinContent(j), \ temp_all.GetBinError(j), temp_ref.GetBinError(j))) except ZeroDivisionError: pass #print "Divide by zero! Check bin content in", canv.GetName() temp_ratio.SetMarkerStyle(20) temp_ratio.SetMarkerColor(1) temp_ratio.SetMarkerSize(1) temp_ratio.GetYaxis().SetTitleFont(43) temp_ratio.GetYaxis().SetTitleSize(28) temp_ratio.GetYaxis().SetLabelFont(43) temp_ratio.GetYaxis().SetLabelSize(28) temp_ratio.GetYaxis().SetTitle(" %s/ ref" % inputdir) temp_ratio.GetYaxis().SetRangeUser(0.7, 1.2) #set range for ratio plot temp_ratio.GetYaxis().SetNdivisions(405) temp_ratio.GetXaxis().SetTitleFont(43) temp_ratio.GetXaxis().SetTitleOffset(3.5) temp_ratio.GetXaxis().SetTitleSize(28) temp_ratio.GetXaxis().SetLabelFont(43) temp_ratio.GetXaxis().SetLabelSize(28) temp_ratio.GetXaxis().SetRangeUser(plotrange[0], plotrange[1]) temp_ratio.GetXaxis().SetTitle("mass, GeV") temp_ratio.Draw("ep") # draw the ratio 1 line line = ROOT.TLine(plotrange[0], 1.0, plotrange[1], 1.0) line.SetLineStyle(1) line.Draw() # finish up if logy != 0: canv.SetName(canv.GetName() + "_1") canv.SaveAs(outputpath + canv.GetName() + ".pdf") pad0.Close() pad1.Close() canv.Close() input_mc.Close() input_mc_ref.Close() #clean up all the pointers... del (temp_all) del (temp_ref) del (temp_ratio) del (graph_all) del (graph_ref) del (graph_lst)
def fitestimation(histname="", inputdic={}, weight=False): '''weight controls whether the a/b tag ratio is applied''' #now do the real work print "***** estimation *****" #do a dump fill first outroot.cd() est = {} for i, cut in enumerate(cut_lst): #get the corresponding region cutcounts = {} for j, region in enumerate(region_lst): #start the histogram as a dumb holder Ftransfer = 1.0 Ftransfer_err = 0.0 Ftransfer_corr = 0.0 Ntransfer = 1.0 #define where the qcd come from ref_cut = "NoTag" if cut in bkgest_dict.keys(): ref_cut = bkgest_dict[cut] #reset for top, use the correct MCs if "ttbar" in histname: ref_cut = cut #print ref_cut, histname, cut, region #start the temp calculation of Ftransfer #print fitresult if fitresult and cut in word_dict.keys(): if word_dict[cut] < len( fitresult["mu" + histname.replace("_est", "")]): Ftransfer = fitresult["mu" + histname.replace("_est", "")][ word_dict[cut]] Ftransfer_err = fitresult["mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] corr_temp = fitresult["corr_m"][word_dict[cut]] Ftransfer_corr = corr_temp[ word_dict[cut] + len(corr_temp) / 2] if not useOneTop else corr_temp[-1] #print "cor is, ", fitresult["corr_m"], Ftransfer_corr, cut, histname, word_dict[cut] else: Ftransfer = inputdic["qcd"][cut]["Sideband"] / inputdic[ "qcd"][ref_cut]["Sideband"] Ftransfer_err = helpers.ratioerror( inputdic["qcd"][cut]["Sideband"], inputdic["qcd"][ref_cut]["Sideband"]) #print histname, Ftransfer for hst in plt_lst: htemp_qcd = outroot.Get( histname.replace("_est", "") + "_" + ref_cut + "_" + region + "_" + hst).Clone() #for ttbar, for mscale and mll, use 3b instead of 4b if "ttbar" in histname and ("FourTag" in cut or "ThreeTag" in cut): #print ref_cut, histname, cut, region, htemp_qcd.Integral(0, htemp_qcd.GetNbinsX()+1) hist_temp = outroot.Get( histname.replace("_est", "") + "_" + "TwoTag_split" + "_" + region + "_" + hst).Clone() hist_temp.Scale( htemp_qcd.Integral(0, htemp_qcd.GetNbinsX() + 1) / hist_temp.Integral(0, hist_temp.GetNbinsX() + 1)) #print ref_cut, histname, cut, region, hist_temp.Integral(0, hist_temp.GetNbinsX()+1) htemp_qcd = hist_temp.Clone() del (hist_temp) #proceed! Ntransfer = htemp_qcd.Integral(0, htemp_qcd.GetNbinsX() + 1) htemp_qcd.SetName(histname + "_" + cut + "_" + region + "_" + hst) htemp_qcd.Scale(Ftransfer) ## add weight! if weight: #print ref_cut, histname, cut, region if cut in weight_dict.keys(): hist_temp_base = outroot.Get( histname.replace("_est", "") + "_" + weight_dict[cut][0] + "_" + "Sideband" + "_" + hst).Clone("base") hist_temp_model = outroot.Get( histname.replace("_est", "") + "_" + weight_dict[cut][1] + "_" + "Sideband" + "_" + hst).Clone("model") hist_temp_base.Scale(hist_temp_model.Integral() / hist_temp_base.Integral()) hist_temp_model.Divide(hist_temp_base) htemp_qcd.Multiply(hist_temp_model) hist_temp_model.SetName(histname + "_" + cut + "_" + region + "_" + hst + "_weight") hist_temp_model.Write() del (hist_temp_model) del (hist_temp_base) else: pass ## end of add weight htemp_qcd.Write() del (htemp_qcd) #get the notag sideband for the current version plttemp = outroot.Get(histname + "_" + cut + "_" + region + "_" + plt_m) err = ROOT.Double(0.) cutcounts[region] = plttemp.IntegralAndError( 0, plttemp.GetXaxis().GetNbins() + 1, err) cutcounts[region + "_err"] = float(err) cutcounts[region + "_syst_muqcd_fit_up"] = Ftransfer_err * Ntransfer cutcounts[region + "_syst_muqcd_fit_down"] = -Ftransfer_err * Ntransfer cutcounts[region + "_scale_factor"] = Ftransfer cutcounts[region + "_corr"] = Ftransfer_corr #print plttemp.GetName(), cut, region, cutcounts[region], cutcounts[region + "_err"], cutcounts[region + "_syst_muqcd_fit_up"] del (plttemp) est[cut] = cutcounts return {histname: est}
def DrawPtEff(inputdir, outputname=""): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region canv = ROOT.TCanvas(inputdir + "_pT_" + "Efficiency", "Efficiency", 800, 800) xleg, yleg = 0.55, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2) # setup basic plot parameters # load input MC file eff_lst = [] graph_lst = [] maxbincontent = 1 minbincontent = -0.01 year = (outputname.split("_")[1] if "_" in outputname else "") file_lst = [ "data_test", "signal_G_hh_c10_M1000", "signal_G_hh_c10_M1100", "signal_G_hh_c10_M1200" ] leg_lst = ["Data" + year, "RSG 1TeV", "RSG 1.1TeV", "RSG 1.2TeV"] for i, file in enumerate(file_lst): input_mc = ROOT.TFile.Open(inputpath + file + (year if "data" in file else "") + "/hist-MiniNTuple" + ".root") hist_tag = input_mc.Get( "h_leadHCand_pT_pre_trig").Clone() #hist before trigger hist_prob = input_mc.Get( "h_leadHCand_pT_aft_trig").Clone() #hist after trigger xMin = hist_tag.GetXaxis().GetXmin() xMax = hist_tag.GetXaxis().GetXmax() #print xMin, xMax eff_lst.append( ROOT.TH1F(file + "_pT_eff", ";p_{T} [GeV]; Efficiency", hist_tag.GetXaxis().GetNbins(), xMin, xMax)) for j in range(hist_tag.GetXaxis().GetNbins() + 1): #print j, hist_prob.GetBinContent(j), hist_prob.GetBinCenter(j) if hist_prob.GetBinContent(j) > 0: eff_lst[i].SetBinContent( j, hist_prob.GetBinContent(j) / hist_tag.GetBinContent(j)) eff_lst[i].SetBinError( j, helpers.ratioerror(hist_prob.GetBinContent(j), hist_tag.GetBinContent(j), hist_prob.GetBinError(j), hist_tag.GetBinError(j))) graph_lst.append(helpers.TH1toTAsym(eff_lst[i])) graph_lst[i].SetLineColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerStyle(20 + i) graph_lst[i].SetMarkerColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerSize(1) graph_lst[i].SetMaximum(maxbincontent * 1.5) graph_lst[i].SetMinimum(minbincontent) legend.AddEntry(graph_lst[i], leg_lst[i].replace("_", " "), "apl") canv.cd() if i == 0: graph_lst[i].Draw("APC") else: graph_lst[i].Draw("PC") input_mc.Close() legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() # draw reference lines xline90 = ROOT.TLine(xMin, 0.9, xMax, 0.9) xline90.SetLineStyle(3) xline90.Draw() xline95 = ROOT.TLine(xMin, 0.95, xMax, 0.95) xline95.SetLineStyle(4) xline95.Draw() xline98 = ROOT.TLine(xMin, 0.98, xMax, 0.98) xline98.SetLineStyle(5) xline98.Draw() yline45 = ROOT.TLine(450, 0.00, 450, 1.00) yline45.SetLineStyle(5) yline45.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() # finish up canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf") canv.Close()
def DrawSignalEff(cut_lst, inputdir="b77", inputroot="sum", outputname="", normalization=1.0, plotrange=(0, 3100), logy=0): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region histname = "_Signal_Significance" canv = ROOT.TCanvas(outputname + "_" + str(plotrange[0]) + "_" + str(plotrange[1]), "Efficiency", 800, 800) xleg, yleg = 0.65, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg+0.2, yleg+0.2) # two pad pad0 = ROOT.TPad("pad0", "pad0", 0.0, 0.31, 1., 1.) pad0.SetRightMargin(0.05) pad0.SetBottomMargin(0.0001) pad0.SetFrameFillColor(0) pad0.SetFrameBorderMode(0) pad0.SetFrameFillColor(0) pad0.SetBorderMode(0) pad0.SetBorderSize(0) pad1 = ROOT.TPad("pad1", "pad1", 0.0, 0.0, 1., 0.30) pad1.SetRightMargin(0.05) pad1.SetBottomMargin(0.38) pad1.SetTopMargin(0.0001) pad1.SetFrameFillColor(0) pad1.SetFillStyle(0) # transparent pad1.SetFrameBorderMode(0) pad1.SetFrameFillColor(0) pad1.SetBorderMode(0) pad1.SetBorderSize(0) #top pad canv.cd() pad0.SetLogy(logy) pad0.Draw() pad0.cd() # setup basic plot parameters lowmass = -50 highmass = 3150 # load input MC file input_mc = ROOT.TFile.Open(CONF.inputpath + inputdir + "/" + inputroot + "_" + inputdir + ".root") maxbincontent = normalization minbincontent = 0.0001 temp_all = input_mc.Get(cut_lst[0] + histname).Clone() temp_all.SetName("Combined") input_mc_ref = ROOT.TFile.Open(CONF.inputpath +"ref/" + "sum_ref" + ".root") temp_ref = input_mc_ref.Get(cut_lst[0] + histname).Clone() temp_ref.SetName("Run2-ref") temp_ratio = input_mc.Get(cut_lst[0] + histname).Clone() temp_ratio.SetName("Ratio") for j in range(1, temp_all.GetNbinsX()+1): temp_all.SetBinContent(j, 0) temp_all.SetBinError(j, 0) temp_ref.SetBinContent(j, 0) temp_ref.SetBinError(j, 0) temp_all.SetMinimum(minbincontent) temp_ref.SetMinimum(minbincontent) graph_lst = [] for i, cut in enumerate(cut_lst): #print cut sig_mc = input_mc.Get(cut + histname) #get the input histogram sig_mc_ref = input_mc_ref.Get(cut + histname) #get the input histogram for j in range(1, temp_all.GetNbinsX()+1): #temp_all.SetBinContent(j, ROOT.TMath.Sqrt(temp_all.GetBinContent(j) * temp_all.GetBinContent(j) + sig_mc.GetBinContent(j) * sig_mc.GetBinContent(j))) temp_ref.SetBinContent(j, ROOT.TMath.Sqrt(temp_ref.GetBinContent(j) * temp_ref.GetBinContent(j) + sig_mc_ref.GetBinContent(j) * sig_mc_ref.GetBinContent(j))) temp_all.SetBinContent(j, ROOT.TMath.Sqrt(temp_all.GetBinContent(j) * temp_all.GetBinContent(j) + sig_mc.GetBinContent(j) * sig_mc.GetBinContent(j))) temp_ref.SetBinError(j, ROOT.TMath.Sqrt(temp_ref.GetBinError(j) * temp_ref.GetBinError(j) + sig_mc_ref.GetBinError(j) * sig_mc_ref.GetBinError(j))) temp_all.SetBinError(j, ROOT.TMath.Sqrt(temp_all.GetBinError(j) * temp_all.GetBinError(j) + sig_mc.GetBinError(j) * sig_mc.GetBinError(j))) del(sig_mc_ref) graph_lst.append(helpers.TH1toTAsym(sig_mc, pltrange=plotrange)) graph_lst[i].SetMaximum(maxbincontent * 1.5) graph_lst[i].SetMinimum(minbincontent) graph_lst[i].SetLineColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerStyle(20 + i) graph_lst[i].SetMarkerColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerSize(1) legend.AddEntry(graph_lst[i], cut.replace("_", " "), "APL") if cut==cut_lst[0]: graph_lst[i].Draw("APC") else: graph_lst[i].Draw("PC") del(sig_mc) graph_all = helpers.TH1toTAsym(temp_all) graph_all.SetLineColor(2) graph_all.SetLineStyle(2) graph_all.SetMarkerStyle(5) graph_all.SetMarkerColor(2) graph_all.SetMarkerSize(1) graph_all.GetXaxis().SetRangeUser(plotrange[0], plotrange[1]) legend.AddEntry(graph_all, graph_all.GetName().replace("_", " "), "APL") graph_all.Draw("PC") graph_ref = helpers.TH1toTAsym(temp_ref) graph_ref.SetLineColor(1) graph_ref.SetLineStyle(3) graph_ref.SetMarkerStyle(4) graph_ref.SetMarkerColor(1) graph_ref.SetMarkerSize(1) graph_ref.GetXaxis().SetRangeUser(plotrange[0], plotrange[1]) legend.AddEntry(graph_ref, graph_ref.GetName().replace("_", " "), "APL") graph_ref.Draw("PC") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.02) legend.Draw() # draw reference lines xline05 = ROOT.TLine(lowmass, 0.05, highmass, 0.05) xline05.SetLineStyle(3) xline05.Draw() xline10 = ROOT.TLine(lowmass, 0.1, highmass, 0.1) xline10.SetLineStyle(4) xline10.Draw() yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) yline10.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas-0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas-0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() #bottom pad canv.cd() pad1.Draw() pad1.cd() for j in range(1, temp_ratio.GetNbinsX()+1): try: temp_ratio.SetBinContent(j, temp_all.GetBinContent(j) / temp_ref.GetBinContent(j)) temp_ratio.SetBinError(j, helpers.ratioerror(\ temp_all.GetBinContent(j), temp_ref.GetBinContent(j), \ temp_all.GetBinError(j), temp_ref.GetBinError(j))) except ZeroDivisionError: pass #print "Divide by zero! Check bin content in", canv.GetName() temp_ratio.SetMarkerStyle(20) temp_ratio.SetMarkerColor(1) temp_ratio.SetMarkerSize(1) temp_ratio.GetYaxis().SetTitleFont(43) temp_ratio.GetYaxis().SetTitleSize(28) temp_ratio.GetYaxis().SetLabelFont(43) temp_ratio.GetYaxis().SetLabelSize(28) temp_ratio.GetYaxis().SetTitle(" %s/ ref" % inputdir) temp_ratio.GetYaxis().SetRangeUser(0.7, 1.2) #set range for ratio plot temp_ratio.GetYaxis().SetNdivisions(405) temp_ratio.GetXaxis().SetTitleFont(43) temp_ratio.GetXaxis().SetTitleOffset(3.5) temp_ratio.GetXaxis().SetTitleSize(28) temp_ratio.GetXaxis().SetLabelFont(43) temp_ratio.GetXaxis().SetLabelSize(28) temp_ratio.GetXaxis().SetRangeUser(plotrange[0], plotrange[1]) temp_ratio.GetXaxis().SetTitle("mass, GeV") temp_ratio.Draw("ep") # draw the ratio 1 line line = ROOT.TLine(plotrange[0], 1.0, plotrange[1], 1.0) line.SetLineStyle(1) line.Draw() # finish up if logy != 0: canv.SetName(canv.GetName() + "_1") canv.SaveAs(outputpath + canv.GetName() + ".pdf") pad0.Close() pad1.Close() canv.Close() input_mc.Close() input_mc_ref.Close() #clean up all the pointers... del(temp_all) del(temp_ref) del(temp_ratio) del(graph_all) del(graph_ref) del(graph_lst)
def DrawSignalEff(cut_lst, inputdir="b77", outputname="", normalization="All", doint=False, donormint=False, dorel=False, dorelfcomp=False): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region afterscript = ("_rel" if dorel else "") + ("_ref" if dorelfcomp else "") canv = ROOT.TCanvas( inputdir + "_" + "Efficiency" + "_" + normalization + afterscript, "Efficiency", 800, 800) xleg, yleg = 0.52, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2) # setup basic plot parameters # load input MC file eff_lst = [] graph_lst = [] maxbincontent = 0.001 minbincontent = -0.001 for i, cut in enumerate(cut_lst): eff_lst.append( ROOT.TH1F(inputdir + "_" + cut, "%s; Mass, GeV; Efficiency" % cut, int((highmass - lowmass) / 100), lowmass, highmass)) for mass in mass_lst: #here could be changed to have more options input_mc_type = "signal_G_hh_c10_M" if not ops.Xhh else "signal_X_hh_M" input_mc = ROOT.TFile.Open(inputpath + input_mc_type + "%i/hist-MiniNTuple.root" % mass) cutflow_mc = input_mc.Get("CutFlowNoWeight").Clone( "CutFlowNoWeight") #notice here we use no weight for now! cutflow_mc_w = input_mc.Get("CutFlowWeight").Clone("CutFlowWeight") if dorel: maxbincontent = 1.0 if i > 0: normalization = cut_lst[i - 1] totevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(normalization)) cutevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(cut)) #this is a really dirty temp fix scale_weight = (cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)\ / (cutflow_mc_w.GetBinContent(cutflow_mc_w.GetXaxis().FindBin("All")) * 1.0) #this is really only for doing reference comparison only! input_mc_ref = ROOT.TFile.Open(CONF.inputpath + "ref" + "/" + "signal_G_hh_c10_M" + "%i/hist-MiniNTuple.root" % mass) cutflow_mc_ref = input_mc_ref.Get("CutFlowNoWeight").Clone( "CutFlowNoWeight_ref") #notice here we use no weight for now! cutflow_mc_w_ref = input_mc_ref.Get("CutFlowWeight").Clone( "CutFlowWeight_ref") totevt_mc_ref = cutflow_mc_ref.GetBinContent( cutflow_mc_ref.GetXaxis().FindBin(normalization)) cutevt_mc_ref = cutflow_mc_ref.GetBinContent( cutflow_mc_ref.GetXaxis().FindBin(cut)) scale_weight_ref = (cutflow_mc_ref.GetBinContent(cutflow_mc_ref.GetXaxis().FindBin("All")) * 1.0)\ / (cutflow_mc_w_ref.GetBinContent(cutflow_mc_w_ref.GetXaxis().FindBin("All")) * 1.0) #print cut, mass, cutevt_mc, totevt_mc, cutevt_mc_ref, totevt_mc_ref #for cuts that are defined in folders but not in the cutflow table... if doint: cuthist_temp = input_mc.Get(cut + "/mHH_l") cutevt_mc = cuthist_temp.Integral( 0, cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight cuthist_temp_ref = input_mc_ref.Get(cut + "/mHH_l") cutevt_mc_ref = cuthist_temp_ref.Integral( 0, cuthist_temp_ref.GetXaxis().GetNbins() + 1) * scale_weight_ref if donormint: cuthist_temp = input_mc.Get(normalization + "/mHH_l") totevt_mc = cuthist_temp.Integral( 0, cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight cuthist_temp_ref = input_mc_ref.Get(normalization + "/mHH_l") totevt_mc_ref = cuthist_temp_ref.Integral( 0, cuthist_temp_ref.GetXaxis().GetNbins() + 1) * scale_weight_ref #for ref comparison if dorel and dorelfcomp: totevt_mc = totevt_mc * (cutevt_mc_ref / totevt_mc_ref) * 1.0 elif dorelfcomp: totevt_mc = cutevt_mc_ref * 1.0 minbincontent = 0.5 # if mass == 2500: # print "m:{:>5} c:{:>24} evt:{:>8};".format(mass, cut, cutevt_mc) #continue as usual eff_content = cutevt_mc / totevt_mc eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), cutevt_mc / totevt_mc) eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), helpers.ratioerror(cutevt_mc, totevt_mc)) maxbincontent = max(maxbincontent, eff_content) # print ratioerror(cutevt_mc, totevt_mc) input_mc.Close() input_mc_ref.Close() canv.cd() #convert it to a TGraph graph_lst.append(helpers.TH1toTAsym(eff_lst[i])) graph_lst[i].SetLineColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerStyle(20 + i) graph_lst[i].SetMarkerColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerSize(1) graph_lst[i].SetMaximum(maxbincontent * 1.5) graph_lst[i].SetMinimum(minbincontent) legend.AddEntry(graph_lst[i], cut.replace("_", " "), "apl") if cut == cut_lst[0]: graph_lst[i].Draw("APC") #gr.Draw("same L hist") else: graph_lst[i].Draw("PC") #gr.Draw("same L hist") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.03) legend.Draw() # draw reference lines yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) yline10.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0" if not ops.Xhh else "2HDM") lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] if not CONF.thesis else [hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() # finish up canv.SaveAs(outputpath + outputname + ("_" if not ops.Xhh else "_2HDM_") + canv.GetName() + ".pdf") canv.Close()
def DrawSignalEff(cut_lst, inputdir="b77", outputname="", normalization="All", doint=False, donormint=False, dorel=False): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region afterscript = "_rel" if dorel else "" canv = ROOT.TCanvas( inputdir + "_" + "Efficiency" + "_" + normalization + afterscript, "Efficiency", 800, 800) xleg, yleg = 0.52, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2) # setup basic plot parameters # load input MC file eff_lst = [] maxbincontent = 0.001 minbincontent = -0.001 for i, cut in enumerate(cut_lst): eff_lst.append( ROOT.TH1F(inputdir + "_" + cut, "%s; Mass, GeV; Efficiency" % cut, int((highmass - lowmass) / 100), lowmass, highmass)) eff_lst[i].SetLineColor(CONF.clr_lst[i]) eff_lst[i].SetMarkerStyle(20 + i) eff_lst[i].SetMarkerColor(CONF.clr_lst[i]) eff_lst[i].SetMarkerSize(1) for mass in mass_lst: #here could be changed to have more options input_mc = ROOT.TFile.Open( inputpath + "signal_G_hh_c10_M%i/hist-MiniNTuple.root" % mass) cutflow_mc = input_mc.Get( "CutFlowNoWeight") #notice here we use no weight for now! cutflow_mc_w = input_mc.Get("CutFlowWeight") if dorel: if i > 0: normalization = cut_lst[i - 1] totevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(normalization)) cutevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(cut)) #this is a really dirty temp fix scale_weight = (cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)\ / (cutflow_mc_w.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0) #for cuts that are defined in folders but not in the cutflow table... if doint: cuthist_temp = input_mc.Get(cut + "/mHH_l") cutevt_mc = cuthist_temp.Integral( 0, cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight if donormint: cuthist_temp = input_mc.Get(normalization + "/mHH_l") totevt_mc = cuthist_temp.Integral( 0, cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight eff_content = cutevt_mc / totevt_mc eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), cutevt_mc / totevt_mc) eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), helpers.ratioerror(cutevt_mc, totevt_mc)) maxbincontent = max(maxbincontent, eff_content) # print ratioerror(cutevt_mc, totevt_mc) input_mc.Close() eff_lst[i].SetMaximum(maxbincontent * 1.5) eff_lst[i].SetMinimum(minbincontent) legend.AddEntry(eff_lst[i], cut.replace("_", " "), "apl") canv.cd() if cut == cut_lst[0]: eff_lst[i].Draw("epl") else: eff_lst[i].Draw("same epl") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() # draw reference lines yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) yline10.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas - 0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas - 0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() # finish up canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf") canv.Close()
def DrawMuqcd_split(prename="", qcdmc=True): input_data = ROOT.TFile.Open(inputpath + "data_test/hist.root", "read") input_ttbar = ROOT.TFile.Open(inputpath + "ttbar_comb_test/hist.root", "read") input_zjet = ROOT.TFile.Open(inputpath + "zjets_test/hist.root", "read") outputroot.cd() if (qcdmc): input_qcd = ROOT.TFile.Open(inputpath + "signal_QCD/hist.root", "read") for j, cut in enumerate(tag_lst): for i in range(4): #4 regions data_muqcd = ROOT.TH1D( str(i) + "_" + "data_" + cut + "_" + "muqcd", "muqcd", 1, 1, 2) data_muqcd.GetYaxis().SetTitle("#mu qcd") if (qcdmc): mc_muqcd = ROOT.TH1D( str(i) + "_" + "mc_" + cut + "_" + "muqcd", "muqcd", 1, 1, 2) mc_muqcd.GetYaxis().SetTitle("#mu qcd") #very stupid protection to distinguish 2b and 2bs for k, ch in enumerate(channels): aftercutname = "_" + "r" + str(i) + "_" + ch + "/mHH_l" histname = cut + aftercutname #print histname hist_data = input_data.Get(histname).Clone() hist_ttbar = input_ttbar.Get(histname).Clone() hist_zjet = input_zjet.Get(histname).Clone() hist_temp = hist_data.Clone() hist_temp.Add(hist_ttbar, -1) hist_temp.Add(hist_zjet, -1) Nqcd_err = ROOT.Double(0.) Nqcd = hist_temp.IntegralAndError( 0, hist_temp.GetXaxis().GetNbins() + 1, Nqcd_err) #get the 0 tag numbers refname = "NoTag" + aftercutname ref_data = input_data.Get(refname).Clone() ref_ttbar = input_ttbar.Get(refname).Clone() ref_zjet = input_zjet.Get(refname).Clone() ref_temp = ref_data.Clone() ref_temp.Add(ref_ttbar, -1) ref_temp.Add(ref_zjet, -1) refqcd_err = ROOT.Double(0.) refqcd = ref_temp.IntegralAndError( 0, ref_temp.GetXaxis().GetNbins() + 1, refqcd_err) #print cut, ch, Nmcqcd, refmcqcd #compute mu qcd if refqcd > 0: data_muqcd.Fill(ch, Nqcd / refqcd) data_muqcd.SetBinError( data_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nqcd, refqcd, ea=Nqcd_err, eb=refqcd_err)) else: #print refqcd, histname data_muqcd.Fill(ch, 0) data_muqcd.SetBinError(data_muqcd.GetXaxis().FindBin(ch), 0) if (qcdmc): hist_mcqcd = input_qcd.Get(histname).Clone() Nmcqcd_err = ROOT.Double(0.) Nmcqcd = hist_mcqcd.IntegralAndError( 0, hist_mcqcd.GetXaxis().GetNbins() + 1, Nmcqcd_err) ref_mcqcd = input_qcd.Get(refname).Clone() refmcqcd_err = ROOT.Double(0.) refmcqcd = ref_mcqcd.IntegralAndError( 0, ref_mcqcd.GetXaxis().GetNbins() + 1, refmcqcd_err) if refmcqcd > 0: mc_muqcd.Fill(ch, Nmcqcd / refmcqcd) mc_muqcd.SetBinError( mc_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nmcqcd, refmcqcd, ea=Nmcqcd_err, eb=refmcqcd_err)) outputroot.cd() data_muqcd.SetMaximum(data_muqcd.GetMaximum() * 1.5) data_muqcd.Write() if (qcdmc): mc_muqcd.SetMaximum(data_muqcd.GetMaximum() * 1.5) mc_muqcd.Write() input_data.Close() input_ttbar.Close() input_zjet.Close() if (qcdmc): input_qcd.Close() #make the plot from the saved macro, it is stupid for j, cut in enumerate(tag_lst): drawsplit_overlayed("data_" + cut + "_" + "muqcd", cut + "_" + "mustudy", labelname=cut + " data") if (qcdmc): drawsplit_overlayed("mc_" + cut + "_" + "muqcd", cut + "_" + "mc_mustudy", labelname=cut + " MC")
def DrawMuqcd_split(prename="", qcdmc=True): input_data = ROOT.TFile.Open(inputpath + "data_test/hist.root", "read") input_ttbar = ROOT.TFile.Open(inputpath + "ttbar_comb_test/hist.root", "read") input_zjet = ROOT.TFile.Open(inputpath + "zjets_test/hist.root", "read") outputroot.cd() if (qcdmc): input_qcd = ROOT.TFile.Open(inputpath + "signal_QCD/hist.root", "read") for j, cut in enumerate(tag_lst): for i in range(4):#4 regions data_muqcd = ROOT.TH1D(str(i) + "_" + "data_" + cut + "_" + "muqcd", "muqcd",1,1,2) data_muqcd.GetYaxis().SetTitle("#mu qcd") if (qcdmc): mc_muqcd = ROOT.TH1D(str(i) + "_" + "mc_" + cut + "_" + "muqcd","muqcd",1,1,2) mc_muqcd.GetYaxis().SetTitle("#mu qcd") #very stupid protection to distinguish 2b and 2bs for k, ch in enumerate(channels): aftercutname = "_" + "r" + str(i) + "_" + ch + "/mHH_l" histname = cut + aftercutname #print histname hist_data = input_data.Get(histname).Clone() hist_ttbar = input_ttbar.Get(histname).Clone() hist_zjet = input_zjet.Get(histname).Clone() hist_temp = hist_data.Clone() hist_temp.Add(hist_ttbar, -1) hist_temp.Add(hist_zjet, -1) Nqcd_err = ROOT.Double(0.) Nqcd = hist_temp.IntegralAndError(0, hist_temp.GetXaxis().GetNbins()+1, Nqcd_err) #get the 0 tag numbers refname = "NoTag" + aftercutname ref_data = input_data.Get(refname).Clone() ref_ttbar = input_ttbar.Get(refname).Clone() ref_zjet = input_zjet.Get(refname).Clone() ref_temp = ref_data.Clone() ref_temp.Add(ref_ttbar, -1) ref_temp.Add(ref_zjet, -1) refqcd_err = ROOT.Double(0.) refqcd = ref_temp.IntegralAndError(0, ref_temp.GetXaxis().GetNbins()+1, refqcd_err) #print cut, ch, Nmcqcd, refmcqcd #compute mu qcd if refqcd > 0: data_muqcd.Fill(ch, Nqcd/refqcd) data_muqcd.SetBinError(data_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nqcd, refqcd, ea=Nqcd_err, eb=refqcd_err)) else: #print refqcd, histname data_muqcd.Fill(ch, 0) data_muqcd.SetBinError(data_muqcd.GetXaxis().FindBin(ch), 0) if (qcdmc): hist_mcqcd = input_qcd.Get(histname).Clone() Nmcqcd_err = ROOT.Double(0.) Nmcqcd = hist_mcqcd.IntegralAndError(0, hist_mcqcd.GetXaxis().GetNbins()+1, Nmcqcd_err) ref_mcqcd = input_qcd.Get(refname).Clone() refmcqcd_err = ROOT.Double(0.) refmcqcd = ref_mcqcd.IntegralAndError(0, ref_mcqcd.GetXaxis().GetNbins()+1, refmcqcd_err) if refmcqcd > 0: mc_muqcd.Fill(ch, Nmcqcd/refmcqcd) mc_muqcd.SetBinError(mc_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nmcqcd, refmcqcd, ea=Nmcqcd_err, eb=refmcqcd_err)) outputroot.cd() data_muqcd.SetMaximum(data_muqcd.GetMaximum() * 1.5) data_muqcd.Write() if (qcdmc): mc_muqcd.SetMaximum(data_muqcd.GetMaximum() * 1.5) mc_muqcd.Write() input_data.Close() input_ttbar.Close() input_zjet.Close() if (qcdmc): input_qcd.Close() #make the plot from the saved macro, it is stupid for j, cut in enumerate(tag_lst): drawsplit_overlayed("data_" + cut + "_" + "muqcd", cut + "_" + "mustudy", labelname=cut + " data") if (qcdmc): drawsplit_overlayed("mc_" + cut + "_" + "muqcd", cut + "_" + "mc_mustudy", labelname=cut + " MC")
def DrawMuqcd(qcdmc=False): outputroot.cd() input_data = ROOT.TFile.Open(inputpath + "data_test/hist.root", "read") input_ttbar = ROOT.TFile.Open(inputpath + "ttbar_comb_test/hist.root", "read") input_zjet = ROOT.TFile.Open(inputpath + "zjets_test/hist.root", "read") if (qcdmc): input_qcd = ROOT.TFile.Open(inputpath + "signal_QCD/hist.root", "read") for j, cut in enumerate(tag_lst): canv = ROOT.TCanvas(cut + "_" + "mustudy", "mustudy", 800, 800) xleg, yleg = 0.52, 0.67 legend = ROOT.TLegend(xleg, yleg, xleg+0.3, yleg+0.2) data_muqcd = ROOT.TH1D("data_" + cut + "_" + "muqcd","muqcd",1,1,2) data_muqcd.SetMarkerStyle(20) data_muqcd.SetMarkerColor(1) data_muqcd.SetLineColor(1) data_muqcd.SetMarkerSize(1) data_muqcd.GetYaxis().SetTitle("#mu qcd") legend.AddEntry(data_muqcd, "Data Est", "apl") if (qcdmc): mc_muqcd = ROOT.TH1D("mc_" + cut + "_" + "muqcd","muqcd",1,1,2) mc_muqcd.SetMarkerStyle(20) mc_muqcd.SetMarkerColor(2) mc_muqcd.SetLineColor(2) mc_muqcd.SetMarkerSize(1) mc_muqcd.GetYaxis().SetTitle("#mu qcd") legend.AddEntry(mc_muqcd, "Dijet MC", "apl") #very stupid protection to distinguish 2b and 2bs for k, ch in enumerate(channels): histname = cut + "_" + ch + "/mHH_l" #print histname hist_data = input_data.Get(histname).Clone() hist_ttbar = input_ttbar.Get(histname).Clone() hist_zjet = input_zjet.Get(histname).Clone() hist_temp = hist_data.Clone() hist_temp.Add(hist_ttbar, -1) hist_temp.Add(hist_zjet, -1) Nqcd_err = ROOT.Double(0.) Nqcd = hist_temp.IntegralAndError(0, hist_temp.GetXaxis().GetNbins()+1, Nqcd_err) #get the 0 tag numbers refname = "NoTag" + "_" + ch + "/mHH_l" ref_data = input_data.Get(refname).Clone() ref_ttbar = input_ttbar.Get(refname).Clone() ref_zjet = input_zjet.Get(refname).Clone() ref_temp = ref_data.Clone() ref_temp.Add(ref_ttbar, -1) ref_temp.Add(ref_zjet, -1) refqcd_err = ROOT.Double(0.) refqcd = ref_temp.IntegralAndError(0, ref_temp.GetXaxis().GetNbins()+1, refqcd_err) #print cut, ch, Nmcqcd, refmcqcd #compute mu qcd if refqcd > 0: data_muqcd.Fill(ch, Nqcd/refqcd) data_muqcd.SetBinError(data_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nqcd, refqcd, ea=Nqcd_err, eb=refqcd_err)) #for QCD MC if (qcdmc): hist_mcqcd = input_qcd.Get(histname).Clone() Nmcqcd_err = ROOT.Double(0.) Nmcqcd = hist_mcqcd.IntegralAndError(0, hist_mcqcd.GetXaxis().GetNbins()+1, Nmcqcd_err) ref_mcqcd = input_qcd.Get(refname).Clone() refmcqcd_err = ROOT.Double(0.) refmcqcd = ref_mcqcd.IntegralAndError(0, ref_mcqcd.GetXaxis().GetNbins()+1, refmcqcd_err) if refmcqcd > 0: mc_muqcd.Fill(ch, Nmcqcd/refmcqcd) mc_muqcd.SetBinError(mc_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nmcqcd, refmcqcd, ea=Nmcqcd_err, eb=refmcqcd_err)) data_muqcd.SetMaximum(data_muqcd.GetMaximum() * 2.5) data_muqcd.Draw("EPL") #canv.SaveAs(outputpath + data_muqcd.GetName() + ".pdf") #canv.Clear() if (qcdmc): mc_muqcd.SetMaximum(mc_muqcd.GetMaximum() * 2.5) mc_muqcd.Draw("EPL SAME") myText(0.5, 0.87, 1, "Region: %s" % cut, 42) legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() canv.SaveAs(outputpath + data_muqcd.GetName() + ".pdf") canv.Close() input_data.Close() input_ttbar.Close() input_zjet.Close()
def DrawSignalEff(cut_lst, inputdir="b77", outputname="", normalization="All", doint=False, donormint=False, dorel=False): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region afterscript = "_rel" if dorel else "" canv = ROOT.TCanvas(inputdir + "_" + "Efficiency" + "_" + normalization + afterscript, "Efficiency", 800, 800) xleg, yleg = 0.52, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg+0.3, yleg+0.2) # setup basic plot parameters # load input MC file eff_lst = [] maxbincontent = 0.001 minbincontent = -0.001 for i, cut in enumerate(cut_lst): eff_lst.append( ROOT.TH1F(inputdir + "_" + cut, "%s; Mass, GeV; Efficiency" %cut, int((highmass-lowmass)/100), lowmass, highmass) ) eff_lst[i].SetLineColor(CONF.clr_lst[i]) eff_lst[i].SetMarkerStyle(20 + i) eff_lst[i].SetMarkerColor(CONF.clr_lst[i]) eff_lst[i].SetMarkerSize(1) for mass in mass_lst: #here could be changed to have more options input_mc = ROOT.TFile.Open(inputpath + "signal_G_hh_c10_M%i/hist-MiniNTuple.root" % mass) cutflow_mc = input_mc.Get("CutFlowNoWeight") #notice here we use no weight for now! cutflow_mc_w = input_mc.Get("CutFlowWeight") if dorel: if i > 0: normalization = cut_lst[i - 1] totevt_mc = cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin(normalization)) cutevt_mc = cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin(cut)) #this is a really dirty temp fix scale_weight = (cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)\ / (cutflow_mc_w.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0) #for cuts that are defined in folders but not in the cutflow table... if doint: cuthist_temp = input_mc.Get(cut + "/mHH_l") cutevt_mc = cuthist_temp.Integral(0, cuthist_temp.GetXaxis().GetNbins()+1) * scale_weight if donormint: cuthist_temp = input_mc.Get(normalization + "/mHH_l") totevt_mc = cuthist_temp.Integral(0, cuthist_temp.GetXaxis().GetNbins()+1) * scale_weight eff_content = cutevt_mc/totevt_mc eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), cutevt_mc/totevt_mc) eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), helpers.ratioerror(cutevt_mc, totevt_mc)) maxbincontent = max(maxbincontent, eff_content) # print ratioerror(cutevt_mc, totevt_mc) input_mc.Close() eff_lst[i].SetMaximum(maxbincontent * 1.5) eff_lst[i].SetMinimum(minbincontent) legend.AddEntry(eff_lst[i], cut.replace("_", " "), "apl") canv.cd() if cut==cut_lst[0]: eff_lst[i].Draw("epl") else: eff_lst[i].Draw("same epl") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() # draw reference lines yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) yline10.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas-0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas-0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() # finish up canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf") canv.Close()
def DrawTrigEff(cut_lst, inputdir, outputname="", normalization="All"): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region canv = ROOT.TCanvas(inputdir + "_" + "Efficiency" + "_" + normalization, "Efficiency", 800, 800) xleg, yleg = 0.55, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg+0.3, yleg+0.2) # setup basic plot parameters # load input MC file eff_lst = [] maxbincontent = 1 minbincontent = -0.01 for i, cut in enumerate(cut_lst): eff_lst.append( ROOT.TH1F(inputdir + "_" + cut, "%s; Mass, GeV; Efficiency" %cut, int((highmass-lowmass)/100), lowmass, highmass) ) eff_lst[i].SetLineColor(2 + i) eff_lst[i].SetMarkerStyle(20 + i) eff_lst[i].SetMarkerColor(2 + i) eff_lst[i].SetMarkerSize(1) for mass in mass_lst: #here could be changed to have more options input_mc = ROOT.TFile.Open(inputpath + "signal_G_hh_c10_M%i/hist-MiniNTuple.root" % mass) cutflow_mc = input_mc.Get("CutFlowNoWeight") #notice here we use no weight for now! totevt_mc = 0 totevt_mc = cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin(normalization)) maxbincontent = 1 cutevt_mc = cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin(cut)) eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), cutevt_mc/totevt_mc) eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), helpers.ratioerror(cutevt_mc, totevt_mc)) # print ratioerror(cutevt_mc, totevt_mc) input_mc.Close() eff_lst[i].SetMaximum(maxbincontent * 1.5) eff_lst[i].SetMinimum(minbincontent) legend.AddEntry(eff_lst[i], cut.replace("_", " ") if cut is not "PassTrig" else "PassJ420 lcw", "apl") canv.cd() if cut==cut_lst[0]: eff_lst[i].Draw("epl") else: eff_lst[i].Draw("same epl") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() # draw reference lines xline90 = ROOT.TLine(lowmass, 0.9, highmass, 0.9) xline90.SetLineStyle(3) xline90.Draw() xline95 = ROOT.TLine(lowmass, 0.95, highmass, 0.95) xline95.SetLineStyle(4) xline95.Draw() xline98 = ROOT.TLine(lowmass, 0.98, highmass, 0.98) xline98.SetLineStyle(5) xline98.Draw() yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) yline10.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas-0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas-0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() # finish up canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf") canv.Close()
def DrawPtEff(inputdir, outputname=""): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region canv = ROOT.TCanvas(inputdir + "_pT_" + "Efficiency", "Efficiency", 800, 800) xleg, yleg = 0.55, 0.7 legend = ROOT.TLegend(xleg, yleg, xleg+0.3, yleg+0.2) # setup basic plot parameters # load input MC file eff_lst = [] graph_lst = [] maxbincontent = 1 minbincontent = -0.01 year = (outputname.split("_")[1] if "_" in outputname else "") file_lst = ["data_test", "signal_G_hh_c10_M1000", "signal_G_hh_c10_M1100", "signal_G_hh_c10_M1200"] leg_lst = ["Data" + year, "RSG 1TeV", "RSG 1.1TeV", "RSG 1.2TeV"] for i, file in enumerate(file_lst): input_mc = ROOT.TFile.Open(inputpath + file + (year if "data" in file else "") + "/hist-MiniNTuple" + ".root") hist_tag = input_mc.Get("h_leadHCand_pT_pre_trig").Clone() #hist before trigger hist_prob = input_mc.Get("h_leadHCand_pT_aft_trig").Clone() #hist after trigger xMin = hist_tag.GetXaxis().GetXmin() xMax = hist_tag.GetXaxis().GetXmax() #print xMin, xMax eff_lst.append(ROOT.TH1F(file + "_pT_eff", ";p_{T} [GeV]; Efficiency", hist_tag.GetXaxis().GetNbins(), xMin, xMax)) for j in range(hist_tag.GetXaxis().GetNbins() + 1): #print j, hist_prob.GetBinContent(j), hist_prob.GetBinCenter(j) if hist_prob.GetBinContent(j) > 0: eff_lst[i].SetBinContent(j, hist_prob.GetBinContent(j)/hist_tag.GetBinContent(j)) eff_lst[i].SetBinError(j, helpers.ratioerror(hist_prob.GetBinContent(j), hist_tag.GetBinContent(j), hist_prob.GetBinError(j), hist_tag.GetBinError(j))) graph_lst.append(helpers.TH1toTAsym(eff_lst[i])) graph_lst[i].SetLineColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerStyle(20 + i) graph_lst[i].SetMarkerColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerSize(1) graph_lst[i].SetMaximum(maxbincontent * 1.5) graph_lst[i].SetMinimum(minbincontent) legend.AddEntry(graph_lst[i], leg_lst[i].replace("_", " "), "apl") canv.cd() if i == 0: graph_lst[i].Draw("APC") else: graph_lst[i].Draw("PC") input_mc.Close() legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() # draw reference lines xline90 = ROOT.TLine(xMin, 0.9, xMax, 0.9) xline90.SetLineStyle(3) xline90.Draw() xline95 = ROOT.TLine(xMin, 0.95, xMax, 0.95) xline95.SetLineStyle(4) xline95.Draw() xline98 = ROOT.TLine(xMin, 0.98, xMax, 0.98) xline98.SetLineStyle(5) xline98.Draw() yline45 = ROOT.TLine(450, 0.00, 450, 1.00) yline45.SetLineStyle(5) yline45.Draw() # draw watermarks xatlas, yatlas = 0.35, 0.87 atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Internal") hh4b = ROOT.TLatex(xatlas, yatlas-0.06, "RSG c=1.0") lumi = ROOT.TLatex(xatlas, yatlas-0.12, "MC #sqrt{s} = 13 TeV") watermarks = [atlas, hh4b, lumi] for wm in watermarks: wm.SetTextAlign(22) wm.SetTextSize(0.04) wm.SetTextFont(42) wm.SetNDC() wm.Draw() # finish up canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf") canv.Close()
def fitestimation_test(histname="", inputdic={}): #now do the real work print "***** estimation *****" #do a dump fill first outroot.cd() est = {} for i, cut in enumerate(cut_lst): #get the corresponding region cutcounts = {} for j, region in enumerate(region_lst): #start the histogram as a dumb holder Ftransfer = 1.0 Ftransfer_err = 0.0 Ftransfer_OneTag = 1.0 Ftransfer_OneTag_err = 0.0 Ftransfer_NoTag = 1.0 Ftransfer_NoTag_err = 0.0 Ftransfer_corr = 0.0 Ntransfer = 1.0 #define where the qcd come from ref_cut = "NoTag" ref_cut_NoTag = "NoTag" ref_cut_OneTag = "NoTag" if cut in bkgest_dict.keys(): ref_cut = bkgest_dict[cut] ref_cut_NoTag = bkgest_dict_NoTag[cut] ref_cut_OneTag = bkgest_dict_OneTag[cut] #reset for top, use the correct MCs if "ttbar" in histname: ref_cut = cut #start the temp calculation of Ftransfer #print ref_cut, histname, cut, region #print fitresult if fitresult and cut in word_dict.keys(): if word_dict[cut] < len(fitresult["mu" + histname.replace("_est", "")]): Ftransfer = fitresult["mu" + histname.replace("_est", "")][word_dict[cut]] Ftransfer_err = fitresult["mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] Ftransfer_NoTag = fitresult_NoTag["mu" + histname.replace("_est", "")][word_dict[cut]] Ftransfer_NoTag_err = fitresult_NoTag["mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] Ftransfer_OneTag = fitresult_OneTag["mu" + histname.replace("_est", "")][word_dict[cut]] Ftransfer_OneTag_err = fitresult_OneTag["mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] corr_temp = fitresult["corr_m"][word_dict[cut]] Ftransfer_corr = corr_temp[word_dict[cut] + len(corr_temp)/2] if not useOneTop else corr_temp[-1] #print "cor is, ", fitresult["corr_m"], Ftransfer_corr, cut, histname, word_dict[cut] else: Ftransfer = inputdic["qcd"][cut]["Sideband"]/inputdic["qcd"][ref_cut]["Sideband"] Ftransfer_err = helpers.ratioerror(inputdic["qcd"][cut]["Sideband"], inputdic["qcd"][ref_cut]["Sideband"]) #print histname, cut, Ftransfer, Ftransfer_NoTag, Ftransfer_OneTag for hst in plt_lst: htemp_qcd = outroot.Get(histname.replace("_est", "") + "_" + ref_cut + "_" + region + "_" + hst).Clone() htemp_qcd_NoTag = outroot.Get(histname.replace("_est", "") + "_" + ref_cut_NoTag + "_" + region + "_" + hst).Clone() htemp_qcd_OneTag = outroot.Get(histname.replace("_est", "") + "_" + ref_cut_OneTag + "_" + region + "_" + hst).Clone() #for ttbar, for mscale and mll, use 2bs instead of 3/4b if "ttbar" in histname and ("FourTag" in cut or ("ThreeTag" in cut and "Signal" in region)): hist_temp = outroot.Get(histname.replace("_est", "") + "_" + "TwoTag_split" + "_" + region + "_" + hst).Clone() hist_temp.Scale(htemp_qcd.Integral(0, htemp_qcd.GetNbinsX()+1)/hist_temp.Integral(0, hist_temp.GetNbinsX()+1)) htemp_qcd = hist_temp.Clone() del(hist_temp) #proceed! Ntransfer = htemp_qcd.Integral(0, htemp_qcd.GetNbinsX()+1) htemp_qcd.SetName(histname + "_" + cut + "_" + region + "_" + hst) htemp_qcd.Scale(Ftransfer) ##this is nasty for now if "qcd" in histname: if ("split" in cut): ##2bs; this works wonderfully htemp_qcd_NoTag.Scale(Ftransfer_NoTag) htemp_qcd_OneTag.Scale(Ftransfer_OneTag) htemp_qcd.Add(htemp_qcd_OneTag, 1) htemp_qcd.Add(htemp_qcd_NoTag, -1) elif ("ThreeTag" in cut): htemp_qcd_NoTag.Scale(Ftransfer_NoTag) htemp_qcd_OneTag.Scale(Ftransfer_OneTag) htemp_qcd.Add(htemp_qcd_OneTag, 1) htemp_qcd.Add(htemp_qcd_NoTag, -1) #htemp_qcd.Add(htemp_qcd_NoTag, -1) elif ("FourTag" in cut): htemp_qcd_NoTag.Scale(Ftransfer_NoTag) htemp_qcd_OneTag.Scale(Ftransfer_OneTag) htemp_qcd.Add(htemp_qcd_OneTag, 1) htemp_qcd.Add(htemp_qcd_NoTag, -1) ##directly scale from 2tag # htemp_qcd.Scale(2) # htemp_qcd.Add(htemp_qcd_NoTag, -1) elif "ttbar" in histname: htemp_qcd.Scale(1/Ftransfer)#unscale if ("split" in cut): ##2bs; this works wonderfully htemp_qcd.Scale(Ftransfer + Ftransfer_OneTag - Ftransfer_NoTag) elif ("ThreeTag" in cut): htemp_qcd.Scale(Ftransfer + Ftransfer_OneTag - Ftransfer_NoTag ) elif ("FourTag" in cut): htemp_qcd.Scale(Ftransfer + Ftransfer_OneTag - Ftransfer_NoTag) #htemp_qcd.Scale(2 * Ftransfer - Ftransfer_NoTag) htemp_qcd.Write() del(htemp_qcd) del(htemp_qcd_NoTag) del(htemp_qcd_OneTag) #get the notag sideband for the current version plttemp = outroot.Get(histname + "_" + cut + "_" + region + "_" + plt_m) err = ROOT.Double(0.) cutcounts[region] = plttemp.IntegralAndError(0, plttemp.GetXaxis().GetNbins()+1, err) cutcounts[region + "_err"] = float(err) cutcounts[region + "_syst_muqcd_fit_up"] = Ftransfer_err * Ntransfer cutcounts[region + "_syst_muqcd_fit_down"] = -Ftransfer_err * Ntransfer cutcounts[region + "_scale_factor"] = Ftransfer cutcounts[region + "_corr"] = Ftransfer_corr #print cut, region, Ntransfer, Ftransfer_err, cutcounts[region + "_syst_muqcd_fit_up"] del(plttemp) est[cut] = cutcounts return {histname:est}
def DrawMuqcd(qcdmc=False): outputroot.cd() input_data = ROOT.TFile.Open(inputpath + "data_test/hist.root", "read") input_ttbar = ROOT.TFile.Open(inputpath + "ttbar_comb_test/hist.root", "read") input_zjet = ROOT.TFile.Open(inputpath + "zjets_test/hist.root", "read") if (qcdmc): input_qcd = ROOT.TFile.Open(inputpath + "signal_QCD/hist.root", "read") for j, cut in enumerate(tag_lst): canv = ROOT.TCanvas(cut + "_" + "mustudy", "mustudy", 800, 800) xleg, yleg = 0.52, 0.67 legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.2) data_muqcd = ROOT.TH1D("data_" + cut + "_" + "muqcd", "muqcd", 1, 1, 2) data_muqcd.SetMarkerStyle(20) data_muqcd.SetMarkerColor(1) data_muqcd.SetLineColor(1) data_muqcd.SetMarkerSize(1) data_muqcd.GetYaxis().SetTitle("#mu qcd") legend.AddEntry(data_muqcd, "Data Est", "apl") if (qcdmc): mc_muqcd = ROOT.TH1D("mc_" + cut + "_" + "muqcd", "muqcd", 1, 1, 2) mc_muqcd.SetMarkerStyle(20) mc_muqcd.SetMarkerColor(2) mc_muqcd.SetLineColor(2) mc_muqcd.SetMarkerSize(1) mc_muqcd.GetYaxis().SetTitle("#mu qcd") legend.AddEntry(mc_muqcd, "Dijet MC", "apl") #very stupid protection to distinguish 2b and 2bs for k, ch in enumerate(channels): histname = cut + "_" + ch + "/mHH_l" #print histname hist_data = input_data.Get(histname).Clone() hist_ttbar = input_ttbar.Get(histname).Clone() hist_zjet = input_zjet.Get(histname).Clone() hist_temp = hist_data.Clone() hist_temp.Add(hist_ttbar, -1) hist_temp.Add(hist_zjet, -1) Nqcd_err = ROOT.Double(0.) Nqcd = hist_temp.IntegralAndError( 0, hist_temp.GetXaxis().GetNbins() + 1, Nqcd_err) #get the 0 tag numbers refname = "NoTag" + "_" + ch + "/mHH_l" ref_data = input_data.Get(refname).Clone() ref_ttbar = input_ttbar.Get(refname).Clone() ref_zjet = input_zjet.Get(refname).Clone() ref_temp = ref_data.Clone() ref_temp.Add(ref_ttbar, -1) ref_temp.Add(ref_zjet, -1) refqcd_err = ROOT.Double(0.) refqcd = ref_temp.IntegralAndError( 0, ref_temp.GetXaxis().GetNbins() + 1, refqcd_err) #print cut, ch, Nmcqcd, refmcqcd #compute mu qcd if refqcd > 0: data_muqcd.Fill(ch, Nqcd / refqcd) data_muqcd.SetBinError( data_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nqcd, refqcd, ea=Nqcd_err, eb=refqcd_err)) #for QCD MC if (qcdmc): hist_mcqcd = input_qcd.Get(histname).Clone() Nmcqcd_err = ROOT.Double(0.) Nmcqcd = hist_mcqcd.IntegralAndError( 0, hist_mcqcd.GetXaxis().GetNbins() + 1, Nmcqcd_err) ref_mcqcd = input_qcd.Get(refname).Clone() refmcqcd_err = ROOT.Double(0.) refmcqcd = ref_mcqcd.IntegralAndError( 0, ref_mcqcd.GetXaxis().GetNbins() + 1, refmcqcd_err) if refmcqcd > 0: mc_muqcd.Fill(ch, Nmcqcd / refmcqcd) mc_muqcd.SetBinError( mc_muqcd.GetXaxis().FindBin(ch), helpers.ratioerror(Nmcqcd, refmcqcd, ea=Nmcqcd_err, eb=refmcqcd_err)) data_muqcd.SetMaximum(data_muqcd.GetMaximum() * 2.5) data_muqcd.Draw("EPL") #canv.SaveAs(outputpath + data_muqcd.GetName() + ".pdf") #canv.Clear() if (qcdmc): mc_muqcd.SetMaximum(mc_muqcd.GetMaximum() * 2.5) mc_muqcd.Draw("EPL SAME") myText(0.5, 0.87, 1, "Region: %s" % cut, 42) legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextSize(0.04) legend.Draw() canv.SaveAs(outputpath + data_muqcd.GetName() + ".pdf") canv.Close() input_data.Close() input_ttbar.Close() input_zjet.Close()
def fitestimation(histname="", inputdic={}, weight=False): '''weight controls whether the a/b tag ratio is applied''' #now do the real work print "***** estimation *****" #do a dump fill first outroot.cd() est = {} for i, cut in enumerate(cut_lst): #get the corresponding region cutcounts = {} for j, region in enumerate(region_lst): #start the histogram as a dumb holder Ftransfer = 1.0 Ftransfer_err = 0.0 Ftransfer_corr = 0.0 Ntransfer = 1.0 #define where the qcd come from ref_cut = "NoTag" if cut in bkgest_dict.keys(): ref_cut = bkgest_dict[cut] #reset for top, use the correct MCs if "ttbar" in histname: ref_cut = cut #print ref_cut, histname, cut, region #start the temp calculation of Ftransfer #print fitresult if fitresult and cut in word_dict.keys(): if word_dict[cut] < len(fitresult["mu" + histname.replace("_est", "")]): Ftransfer = fitresult["mu" + histname.replace("_est", "")][word_dict[cut]] Ftransfer_err = fitresult["mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] corr_temp = fitresult["corr_m"][word_dict[cut]] Ftransfer_corr = corr_temp[word_dict[cut] + len(corr_temp)/2] if not useOneTop else corr_temp[-1] #print "cor is, ", fitresult["corr_m"], Ftransfer_corr, cut, histname, word_dict[cut] else: Ftransfer = inputdic["qcd"][cut]["Sideband"]/inputdic["qcd"][ref_cut]["Sideband"] Ftransfer_err = helpers.ratioerror(inputdic["qcd"][cut]["Sideband"], inputdic["qcd"][ref_cut]["Sideband"]) #print histname, Ftransfer for hst in plt_lst: htemp_qcd = outroot.Get(histname.replace("_est", "") + "_" + ref_cut + "_" + region + "_" + hst).Clone() #for ttbar, for mscale and mll, use 2bs instead of 3/4b if "ttbar" in histname and ("FourTag" in cut or ("ThreeTag" in cut and "Signal" in region)): #print ref_cut, histname, cut, region, htemp_qcd.Integral(0, htemp_qcd.GetNbinsX()+1) hist_temp = outroot.Get(histname.replace("_est", "") + "_" + "TwoTag_split" + "_" + region + "_" + hst).Clone() hist_temp.Scale(htemp_qcd.Integral(0, htemp_qcd.GetNbinsX()+1)/hist_temp.Integral(0, hist_temp.GetNbinsX()+1)) #print ref_cut, histname, cut, region, hist_temp.Integral(0, hist_temp.GetNbinsX()+1) htemp_qcd = hist_temp.Clone() del(hist_temp) #proceed! Ntransfer = htemp_qcd.Integral(0, htemp_qcd.GetNbinsX()+1) htemp_qcd.SetName(histname + "_" + cut + "_" + region + "_" + hst) htemp_qcd.Scale(Ftransfer) ## add weight! if weight: #print ref_cut, histname, cut, region if cut in weight_dict.keys(): hist_temp_base = outroot.Get(histname.replace("_est", "") + "_" + weight_dict[cut][0] + "_" + "Sideband" + "_" + hst).Clone("base") hist_temp_model = outroot.Get(histname.replace("_est", "") + "_" + weight_dict[cut][1] + "_" + "Sideband" + "_" + hst).Clone("model") hist_temp_base.Scale(hist_temp_model.Integral()/hist_temp_base.Integral()) hist_temp_model.Divide(hist_temp_base) htemp_qcd.Multiply(hist_temp_model) hist_temp_model.SetName(histname + "_" + cut + "_" + region + "_" + hst + "_weight") hist_temp_model.Write() del(hist_temp_model) del(hist_temp_base) else: pass ## end of add weight htemp_qcd.Write() del(htemp_qcd) #get the notag sideband for the current version plttemp = outroot.Get(histname + "_" + cut + "_" + region + "_" + plt_m) err = ROOT.Double(0.) cutcounts[region] = plttemp.IntegralAndError(0, plttemp.GetXaxis().GetNbins()+1, err) cutcounts[region + "_err"] = float(err) cutcounts[region + "_syst_muqcd_fit_up"] = Ftransfer_err * Ntransfer cutcounts[region + "_syst_muqcd_fit_down"] = -Ftransfer_err * Ntransfer cutcounts[region + "_scale_factor"] = Ftransfer cutcounts[region + "_corr"] = Ftransfer_corr #print plttemp.GetName(), cut, region, cutcounts[region], cutcounts[region + "_err"], cutcounts[region + "_syst_muqcd_fit_up"] del(plttemp) est[cut] = cutcounts return {histname:est}
def fitestimation_test(histname="", inputdic={}): #now do the real work print "***** estimation *****" #do a dump fill first outroot.cd() est = {} for i, cut in enumerate(cut_lst): #get the corresponding region cutcounts = {} for j, region in enumerate(region_lst): #start the histogram as a dumb holder Ftransfer = 1.0 Ftransfer_err = 0.0 Ftransfer_OneTag = 1.0 Ftransfer_OneTag_err = 0.0 Ftransfer_NoTag = 1.0 Ftransfer_NoTag_err = 0.0 Ftransfer_corr = 0.0 Ntransfer = 1.0 #define where the qcd come from ref_cut = "NoTag" ref_cut_NoTag = "NoTag" ref_cut_OneTag = "NoTag" if cut in bkgest_dict.keys(): ref_cut = bkgest_dict[cut] ref_cut_NoTag = bkgest_dict_NoTag[cut] ref_cut_OneTag = bkgest_dict_OneTag[cut] #reset for top, use the correct MCs if "ttbar" in histname: ref_cut = cut #start the temp calculation of Ftransfer #print ref_cut, histname, cut, region #print fitresult if fitresult and cut in word_dict.keys(): if word_dict[cut] < len( fitresult["mu" + histname.replace("_est", "")]): Ftransfer = fitresult["mu" + histname.replace("_est", "")][ word_dict[cut]] Ftransfer_err = fitresult["mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] Ftransfer_NoTag = fitresult_NoTag[ "mu" + histname.replace("_est", "")][word_dict[cut]] Ftransfer_NoTag_err = fitresult_NoTag[ "mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] Ftransfer_OneTag = fitresult_OneTag[ "mu" + histname.replace("_est", "")][word_dict[cut]] Ftransfer_OneTag_err = fitresult_OneTag[ "mu" + histname.replace("_est", "") + "_e"][word_dict[cut]] corr_temp = fitresult["corr_m"][word_dict[cut]] Ftransfer_corr = corr_temp[ word_dict[cut] + len(corr_temp) / 2] if not useOneTop else corr_temp[-1] #print "cor is, ", fitresult["corr_m"], Ftransfer_corr, cut, histname, word_dict[cut] else: Ftransfer = inputdic["qcd"][cut]["Sideband"] / inputdic[ "qcd"][ref_cut]["Sideband"] Ftransfer_err = helpers.ratioerror( inputdic["qcd"][cut]["Sideband"], inputdic["qcd"][ref_cut]["Sideband"]) #print histname, cut, Ftransfer, Ftransfer_NoTag, Ftransfer_OneTag for hst in plt_lst: htemp_qcd = outroot.Get( histname.replace("_est", "") + "_" + ref_cut + "_" + region + "_" + hst).Clone() htemp_qcd_NoTag = outroot.Get( histname.replace("_est", "") + "_" + ref_cut_NoTag + "_" + region + "_" + hst).Clone() htemp_qcd_OneTag = outroot.Get( histname.replace("_est", "") + "_" + ref_cut_OneTag + "_" + region + "_" + hst).Clone() #for ttbar, for mscale and mll, use 3b instead of 4b if "ttbar" in histname and ("FourTag" in cut or "ThreeTag" in cut): hist_temp = outroot.Get( histname.replace("_est", "") + "_" + "TwoTag_split" + "_" + region + "_" + hst).Clone() hist_temp.Scale( htemp_qcd.Integral(0, htemp_qcd.GetNbinsX() + 1) / hist_temp.Integral(0, hist_temp.GetNbinsX() + 1)) htemp_qcd = hist_temp.Clone() del (hist_temp) #proceed! Ntransfer = htemp_qcd.Integral(0, htemp_qcd.GetNbinsX() + 1) htemp_qcd.SetName(histname + "_" + cut + "_" + region + "_" + hst) htemp_qcd.Scale(Ftransfer) ##this is nasty for now if "qcd" in histname: if ("split" in cut): ##2bs; this works wonderfully htemp_qcd_NoTag.Scale(Ftransfer_NoTag) htemp_qcd_OneTag.Scale(Ftransfer_OneTag) htemp_qcd.Add(htemp_qcd_OneTag, 1) htemp_qcd.Add(htemp_qcd_NoTag, -1) elif ("ThreeTag" in cut): htemp_qcd_NoTag.Scale(Ftransfer_NoTag) htemp_qcd_OneTag.Scale(Ftransfer_OneTag) htemp_qcd.Add(htemp_qcd_OneTag, 1) htemp_qcd.Add(htemp_qcd_NoTag, -1) #htemp_qcd.Add(htemp_qcd_NoTag, -1) elif ("FourTag" in cut): htemp_qcd_NoTag.Scale(Ftransfer_NoTag) htemp_qcd_OneTag.Scale(Ftransfer_OneTag) htemp_qcd.Add(htemp_qcd_OneTag, 1) htemp_qcd.Add(htemp_qcd_NoTag, -1) ##directly scale from 2tag # htemp_qcd.Scale(2) # htemp_qcd.Add(htemp_qcd_NoTag, -1) elif "ttbar" in histname: htemp_qcd.Scale(1 / Ftransfer) #unscale if ("split" in cut): ##2bs; this works wonderfully htemp_qcd.Scale(Ftransfer + Ftransfer_OneTag - Ftransfer_NoTag) elif ("ThreeTag" in cut): htemp_qcd.Scale(Ftransfer + Ftransfer_OneTag - Ftransfer_NoTag) elif ("FourTag" in cut): htemp_qcd.Scale( Ftransfer + Ftransfer_OneTag - Ftransfer_NoTag ) #htemp_qcd.Scale(2 * Ftransfer - Ftransfer_NoTag) htemp_qcd.Write() del (htemp_qcd) del (htemp_qcd_NoTag) del (htemp_qcd_OneTag) #get the notag sideband for the current version plttemp = outroot.Get(histname + "_" + cut + "_" + region + "_" + plt_m) err = ROOT.Double(0.) cutcounts[region] = plttemp.IntegralAndError( 0, plttemp.GetXaxis().GetNbins() + 1, err) cutcounts[region + "_err"] = float(err) cutcounts[region + "_syst_muqcd_fit_up"] = Ftransfer_err * Ntransfer cutcounts[region + "_syst_muqcd_fit_down"] = -Ftransfer_err * Ntransfer cutcounts[region + "_scale_factor"] = Ftransfer cutcounts[region + "_corr"] = Ftransfer_corr #print cut, region, Ntransfer, Ftransfer_err, cutcounts[region + "_syst_muqcd_fit_up"] del (plttemp) est[cut] = cutcounts return {histname: est}
def DrawSignalEff(cut_lst, inputdir="b77", outputname="", normalization="All", doint=False, donormint=False, dorel=False, dosum=False, signal="G_hh_c10"): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region afterscript = "_rel" if dorel else "" canv = ROOT.TCanvas(inputdir + "_" + "Efficiency" + "_" + normalization + afterscript, "Efficiency", 800, 600) xleg, yleg = 0.55, 0.73 legend = ROOT.TLegend(xleg, yleg, xleg+0.3, yleg+0.18) # setup basic plot parameters # load input MC file eff_lst = [] graph_lst = [] maxbincontent = 0.001 minbincontent = -0.001 for i, cut in enumerate(cut_lst): eff_lst.append( ROOT.TH1F(inputdir + "_" + cut, "%s; Mass [GeV]; Acceptance x Efficiency" %cut, int((highmass-lowmass)/0.1), lowmass, highmass) ) for mass in mass_lst: if signal == "G_hh_c20" and mass == 2750: continue #here could be changed to have more options input_mc = ROOT.TFile.Open(inputpath + "signal_" + signal + "_M%i/hist-MiniNTuple.root" % mass) cutflow_mc = input_mc.Get("CutFlowNoWeight").Clone() #notice here we use no weight for now! cutflow_mc_w = input_mc.Get("CutFlowWeight").Clone() if dorel: maxbincontent = 1.0 if i > 0: normalization = cut_lst[i - 1] totevt_mc = cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin(normalization)) cutevt_mc = cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin(cut)) #this is a really dirty temp fix scale_weight = (cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)\ / (cutflow_mc_w.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0) #for cuts that are defined in folders but not in the cutflow table... if doint: cuthist_temp = input_mc.Get(cut + "/mHH_l") cutevt_mc = cuthist_temp.Integral(0, cuthist_temp.GetXaxis().GetNbins()+1) * scale_weight if donormint: cuthist_temp = input_mc.Get(normalization + "/mHH_l") totevt_mc = cuthist_temp.Integral(0, cuthist_temp.GetXaxis().GetNbins()+1) * scale_weight eff_content = cutevt_mc/totevt_mc eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass/1000.), cutevt_mc/totevt_mc) eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass/1000.), helpers.ratioerror(cutevt_mc, totevt_mc)) # for j in range(1, eff_lst[i].GetNbinsX() + 1): # eff_lst[i].GetXaxis().SetBinLabel(j, str(eff_lst[i].GetXaxis().GetBinLowEdge(j)/1000.)) if signal == "G_hh_c10": eff_lst[i].GetXaxis().SetTitle("m(G_{kk}) [TeV]") if signal == "G_hh_c20": eff_lst[i].GetXaxis().SetTitle("m(G_{kk}) [TeV]") if signal == "X_hh": eff_lst[i].GetXaxis().SetTitle("m(Scalar) [TeV]") maxbincontent = max(maxbincontent, eff_content) # print ratioerror(cutevt_mc, totevt_mc) input_mc.Close() if dosum:##add in a sum curve eff_lst.append( ROOT.TH1F(inputdir + "_" + "sum", "%s; Mass [GeV]; Acceptance x Efficiency" %cut, int((highmass-lowmass)/0.1), lowmass, highmass) ) for i, cut in enumerate(cut_lst): eff_lst[-1].Add(eff_lst[i]) maxbincontent = eff_lst[-1].GetMaximum() for i, cut in enumerate(eff_lst): canv.cd() #maxbincontent = 0.15 #convert it to a TGraph graph_lst.append(helpers.TH1toTAsym(eff_lst[i])) graph_lst[i].SetLineColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerStyle(CONF.mrk_lst[i]) graph_lst[i].SetMarkerColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerSize(1) graph_lst[i].SetMaximum(maxbincontent * 1.6) graph_lst[i].SetMinimum(minbincontent) #print cut_dic[cut] if i < len(cut_lst): legend.AddEntry(graph_lst[i], cut_dic[cut_lst[i]], "apl") else: ##of corse this is do sum as well legend.AddEntry(graph_lst[i], "All of above", "apl") if i == 0: graph_lst[i].Draw("APC") #gr.Draw("same L hist") else: graph_lst[i].Draw("PC") #gr.Draw("same L hist") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextFont(42) legend.SetTextSize(0.03) legend.Draw() # draw reference lines yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) #yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) #yline10.Draw() # draw watermarks xatlas, yatlas = 0.2, 0.87 #atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Preliminary") #ATLASLabel(xatlas, yatlas, "Preliminary") atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS") #atlas.SetTextAlign(22) atlas.SetTextSize(0.04) atlas.SetTextFont(72) atlas.SetNDC() atlas.Draw() status = ROOT.TLatex(xatlas + 0.1, yatlas, "Simulation") #status.SetTextAlign(22) status.SetTextSize(0.04) status.SetTextFont(42) status.SetNDC() status.Draw() if signal == "G_hh_c10": signal_leg = "G_{kk} k/#bar{M}_{Pl} = 1," if signal == "G_hh_c20": signal_leg = "G_{kk} k/#bar{M}_{Pl} = 2," if signal == "X_hh": signal_leg = "Scalar," myText(xatlas, yatlas-0.05, 1, signal_leg + " #sqrt{s} = 13 TeV", CONF.paperlegsize) myText(xatlas, yatlas-0.1, 1, "Boosted", CONF.paperlegsize) # finish up canv.SaveAs(outputpath + signal + "_" + outputname + "_" + canv.GetName() + ".pdf") canv.SaveAs(outputpath + signal + "_" + outputname + "_" + canv.GetName() + ".eps") canv.SaveAs(outputpath + signal + "_" + outputname + "_" + canv.GetName() + ".png") canv.SaveAs(outputpath + signal + "_" + outputname + "_" + canv.GetName() + ".C") canv.Close()
def DrawSignalEff(cut_lst, inputdir="b77", outputname="", normalization="All", doint=False, donormint=False, dorel=False): ### the first argument is the input directory ### the second argument is the output prefix name ### the third argument is relative to what normalization: 0 for total number of events ### 1 for signal mass region afterscript = "_rel" if dorel else "" canv = ROOT.TCanvas( inputdir + "_" + "Efficiency" + "_" + normalization + afterscript, "Efficiency", 800, 800) xleg, yleg = 0.55, 0.73 legend = ROOT.TLegend(xleg, yleg, xleg + 0.3, yleg + 0.18) # setup basic plot parameters # load input MC file eff_lst = [] graph_lst = [] maxbincontent = 0.001 minbincontent = -0.001 for i, cut in enumerate(cut_lst): eff_lst.append( ROOT.TH1F(inputdir + "_" + cut, "%s; Mass [GeV]; Acceptance x Efficiency" % cut, int((highmass - lowmass) / 100), lowmass, highmass)) for mass in mass_lst: #here could be changed to have more options input_mc = ROOT.TFile.Open( inputpath + "signal_G_hh_c10_M%i/hist-MiniNTuple.root" % mass) cutflow_mc = input_mc.Get("CutFlowNoWeight").Clone( ) #notice here we use no weight for now! cutflow_mc_w = input_mc.Get("CutFlowWeight").Clone() if dorel: maxbincontent = 1.0 if i > 0: normalization = cut_lst[i - 1] totevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(normalization)) cutevt_mc = cutflow_mc.GetBinContent( cutflow_mc.GetXaxis().FindBin(cut)) #this is a really dirty temp fix scale_weight = (cutflow_mc.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0)\ / (cutflow_mc_w.GetBinContent(cutflow_mc.GetXaxis().FindBin("All")) * 1.0) #for cuts that are defined in folders but not in the cutflow table... if doint: cuthist_temp = input_mc.Get(cut + "/mHH_l") cutevt_mc = cuthist_temp.Integral( 0, cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight if donormint: cuthist_temp = input_mc.Get(normalization + "/mHH_l") totevt_mc = cuthist_temp.Integral( 0, cuthist_temp.GetXaxis().GetNbins() + 1) * scale_weight eff_content = cutevt_mc / totevt_mc eff_lst[i].SetBinContent(eff_lst[i].GetXaxis().FindBin(mass), cutevt_mc / totevt_mc) eff_lst[i].SetBinError(eff_lst[i].GetXaxis().FindBin(mass), helpers.ratioerror(cutevt_mc, totevt_mc)) maxbincontent = max(maxbincontent, eff_content) # print ratioerror(cutevt_mc, totevt_mc) input_mc.Close() canv.cd() #maxbincontent = 0.15 #convert it to a TGraph graph_lst.append(helpers.TH1toTAsym(eff_lst[i])) graph_lst[i].SetLineColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerStyle(CONF.mrk_lst[i]) graph_lst[i].SetMarkerColor(CONF.clr_lst[i]) graph_lst[i].SetMarkerSize(1) graph_lst[i].SetMaximum(maxbincontent * 1.6) graph_lst[i].SetMinimum(minbincontent) #print cut_dic[cut] legend.AddEntry(graph_lst[i], cut_dic[cut], "apl") if cut == cut_lst[0]: graph_lst[i].Draw("APC") #gr.Draw("same L hist") else: graph_lst[i].Draw("PC") #gr.Draw("same L hist") legend.SetBorderSize(0) legend.SetMargin(0.3) legend.SetTextFont(42) legend.SetTextSize(0.03) legend.Draw() # draw reference lines yline05 = ROOT.TLine(1000, 0.0, 1000, maxbincontent) yline05.SetLineStyle(9) #yline05.Draw() yline10 = ROOT.TLine(2000, 0.0, 2000, maxbincontent) yline10.SetLineStyle(9) #yline10.Draw() # draw watermarks xatlas, yatlas = 0.2, 0.87 #atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS Preliminary") #ATLASLabel(xatlas, yatlas, "Preliminary") atlas = ROOT.TLatex(xatlas, yatlas, "ATLAS") #atlas.SetTextAlign(22) atlas.SetTextSize(0.04) atlas.SetTextFont(72) atlas.SetNDC() atlas.Draw() status = ROOT.TLatex(xatlas + 0.14, yatlas, CONF.StatusLabel) #status.SetTextAlign(22) status.SetTextSize(0.04) status.SetTextFont(42) status.SetNDC() status.Draw() myText(xatlas, yatlas - 0.05, 1, "G c=1.0, #sqrt{s} = 13 TeV", CONF.paperlegsize - 2) myText(xatlas, yatlas - 0.1, 1, "Boosted", CONF.paperlegsize - 2) # finish up canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".pdf") canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".eps") canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".png") canv.SaveAs(outputpath + outputname + "_" + canv.GetName() + ".C") canv.Close()