def GetSignalTable(masterdic, summarydic): texoutpath = CONF.inputpath + ops.inputdir + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + "SR_summary.tex", "w") tableList = [] help_table.add_table_head(tableList, cut_lst, title="Sample") raw_lst = ["qcd", "ttbar", "totalbkg"] for raw in raw_lst: #get the corresponding region outstr = "" outstr += raw #print masterdic, systag for c in cut_lst: totalsyst = add_syst(summarydic[c][raw])[0] valuetuple = (masterdic[c][raw + "_est"]["int"], totalsyst * masterdic[c][raw + "_est"]["int"]) outstr += help_table.add_entry(valuetuple) #finish the current entry outstr+="\\\\" tableList.append(outstr) #add data: tableList.append("\\hline") outstr = "" outstr += "Data" for c in cut_lst: outstr += help_table.add_entry((masterdic[c]["data"]["int"], masterdic[c]["data"]["int_err"])) outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, cut_lst) #return the table for line in tableList: print line outFile.write(line+" \n") outFile.close()
def GetSignalTable(masterdic, summarydic): texoutpath = CONF.inputpath + "Moriond" + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + "SR_summary.tex", "w") tableList = [] help_table.add_table_head(tableList, cut_lst, title="Sample") raw_lst = ["qcd", "ttbar", "totalbkg"] for raw in raw_lst: #get the corresponding region outstr = "" outstr += raw #print masterdic, systag for c in cut_lst: totalsyst = add_syst(summarydic[c][raw])[0] valuetuple = (masterdic[c][raw + "_est"]["int"], totalsyst * masterdic[c][raw + "_est"]["int"]) outstr += help_table.add_entry(valuetuple) #finish the current entry outstr+="\\\\" tableList.append(outstr) #add data: tableList.append("\\hline") outstr = "" outstr += "Data" for c in cut_lst: outstr += help_table.add_entry((masterdic[c]["data"]["int"], masterdic[c]["data"]["int_err"])) outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, cut_lst) #return the table for line in tableList: print line outFile.write(line+" \n") outFile.close()
def SR_table(masterdic, summarydic): texoutpath = CONF.inputpath + CONF.workdir + "_" + CONF.reweightdir + "/" + "PaperPlot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open(texoutpath + "SR_table.tex", "w") tableList = [] tag_lst = ["TwoTag_split", "ThreeTag", "FourTag"] region_lst = ["Signal"] cut_lst = [] for t in tag_lst: for r in region_lst: cut_lst.append(t) help_table.add_table_head(tableList, cut_lst, title="Source") raw_lst = ["qcd", "ttbar", "totalbkg", "RSG1_2000", "Xhh_2000"] raw_lst_dic = { "qcd": "Multijet", "ttbar": "\\ttbar", "totalbkg": "Total", "RSG1_2000": "G*_{KK} (2 TeV)", "Xhh_2000": "S (2 TeV)" } #check and debug # keylist = masterdic.keys() # keylist.sort() # for key in keylist: # print key, masterdic[key] for raw in raw_lst: #get the corresponding region outstr = "" outstr += raw_lst_dic[raw] #print masterdic, systag for c in cut_lst: totalsyst = dump_syst.add_syst(summarydic[c][raw])[0] valuetuple = (masterdic[c][raw + "_est"]["int"], totalsyst * masterdic[c][raw + "_est"]["int"]) outstr += help_table.add_entry(valuetuple) print valuetuple, c, raw #finish the current entry outstr += "\\\\" tableList.append(outstr) #add data: tableList.append("\\hline") outstr = "" outstr += "Data" for c in cut_lst: outstr += help_table.add_entry((masterdic[c]["data"]["int"])) outstr += "\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, cut_lst) #return the table for line in tableList: print line outFile.write(line + " \n") outFile.close()
def SR_table(masterdic, summarydic): texoutpath = CONF.inputpath + CONF.workdir + "_" + CONF.reweightdir + "/" + "PaperPlot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + "SR_table.tex", "w") tableList = [] tag_lst = ["TwoTag_split", "ThreeTag", "FourTag"] region_lst = ["Signal"] cut_lst = [] for t in tag_lst: for r in region_lst: cut_lst.append(t) help_table.add_table_head(tableList, cut_lst, title="Source") raw_lst = ["qcd", "ttbar", "totalbkg", "RSG1_2000", "Xhh_2000"] raw_lst_dic = {"qcd":"Multijet", "ttbar":"\\ttbar", "totalbkg":"Total", "RSG1_2000":"G*_{KK} (2 TeV)", "Xhh_2000":"S (2 TeV)"} #check and debug # keylist = masterdic.keys() # keylist.sort() # for key in keylist: # print key, masterdic[key] for raw in raw_lst: #get the corresponding region outstr = "" outstr += raw_lst_dic[raw] #print masterdic, systag for c in cut_lst: totalsyst = dump_syst.add_syst(summarydic[c][raw])[0] valuetuple = (masterdic[c][raw + "_est"]["int"], totalsyst * masterdic[c][raw + "_est"]["int"]) outstr += help_table.add_entry(valuetuple) print valuetuple, c, raw #finish the current entry outstr+="\\\\" tableList.append(outstr) #add data: tableList.append("\\hline") outstr = "" outstr += "Data" for c in cut_lst: outstr += help_table.add_entry((masterdic[c]["data"]["int"])) outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, cut_lst) #return the table for line in tableList: print line outFile.write(line+" \n") outFile.close()
def GetTable(masterdic, c): texoutpath = CONF.inputpath + ops.inputdir + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + c + "_fullsyst" + ("" if "pole" not in finaldis else "_pole") + ".tex", "w") tableList = [] column_lst = ["totalbkg", "qcd", "ttbar", "RSG1_1000", "RSG1_2000", "RSG1_3000"] if (ops.Xhh): column_lst.append("Xhh_2000") column_dic = {} for col in column_lst: column_dic[col] = {} ###this is super complicated...let's get them one by one help_table.add_table_head(tableList, column_lst, title=c) systag_lst = {"tt":"Top", "JER":"JER", "JMR":"JMR", "Rtrk":"JES/JMS", "method":"Bkg Est", "EFF":"b-tag SF"} #systag_lst = {"method":"Bkg Est"} #add each systematics for systag, systagname in systag_lst.iteritems(): column_dic[systag] = {} #get the corresponding region outstr = "" outstr += systagname #print masterdic, systag #print systag for col in column_lst: temp_col_dic = find_syst(masterdic, c, systag, col) #print col, systag, c, temp_col_dic outstr += help_table.add_entry(add_syst(temp_col_dic), doerr=False, percent=True) column_dic[col].update(temp_col_dic) if ("tt" in systag): print col, systag, temp_col_dic #finish the current entry outstr+="\\\\" tableList.append(outstr) #add all systematics: tableList.append("\\hline") outstr = "" outstr += "Total Sys" for col in column_lst: outstr += help_table.add_entry(add_syst(column_dic[col]), doerr=False, percent=True) outstr+="\\\\" tableList.append(outstr) #add all stat uncertainty: tableList.append("\\hline") outstr = "" outstr += "Stat" for col in column_lst: for key2 in masterdic[c]: if col in key2: outstr += help_table.add_entry(masterdic[c][key2]["int_err"]/masterdic[c][key2]["int"], doerr=False, percent=True) outstr+="\\\\" tableList.append(outstr) #add all values: tableList.append("\\hline") outstr = "" outstr += "Estimated Events" for col in column_lst: for key2 in masterdic[c]: if col in key2: outstr += help_table.add_entry(masterdic[c][key2]["int"], doerr=False, percent=False) outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, column_lst) #return the table for line in tableList: print line outFile.write(line+" \n") outFile.close() return column_dic
def SBCR_table(masterdic): texoutpath = CONF.inputpath + CONF.workdir + "_" + CONF.reweightdir + "/" + "PaperPlot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + "SBCR_table.tex", "w") tableList = [] tag_lst = ["TwoTag_split", "ThreeTag", "FourTag"] region_lst = ["Sideband", "Control"] cut_lst = [] cut_name_lst = [] for t in tag_lst: for r in region_lst: cut_lst.append(t + "__" + r) cut_name_lst.append(r) help_table.add_table_head(tableList, cut_name_lst, title="Source", special_raw=tag_lst) #raw_lst = ["qcd", "ttbar", "zjet", "data"] #raw_lst_dic = {"qcd":"Multijet", "ttbar":"\\ttbar", "zjet":"$Z$+jet", "data":"Total"} raw_lst = ["qcd", "ttbar", "data"] raw_lst_dic = {"qcd":"Multijet", "ttbar":"\\ttbar", "data":"Total"} #check and debug # keylist = masterdic.keys() # keylist.sort() # for key in keylist: # print key, masterdic[key] for raw in raw_lst: #get the corresponding region outstr = "" outstr += raw_lst_dic[raw] #print masterdic, systag for c in cut_lst: if raw == "zjet": raw_tempname = raw else: raw_tempname = raw + "_est" err_fit = 0 if c.split("__")[1] + "_syst_muqcd_fit_up" in masterdic[raw_tempname][c.split("__")[0]].keys(): err_fit = masterdic[raw_tempname][c.split("__")[0]][c.split("__")[1] + "_syst_muqcd_fit_up"] #print err_fit err_all = helpers.syst_adderror(masterdic[raw_tempname][c.split("__")[0]][c.split("__")[1] + "_err"], err_fit) value = masterdic[raw_tempname][c.split("__")[0]][c.split("__")[1]] + (masterdic["zjet"][c.split("__")[0]][c.split("__")[1]] if raw_tempname == "qcd_est" else 0) valuetuple = (value, err_all) outstr += help_table.add_entry(valuetuple) #finish the current entry outstr+="\\\\" tableList.append(outstr) #add data: tableList.append("\\hline") outstr = "" outstr += "Data" for c in cut_lst: valuetuple = (masterdic["data"][c.split("__")[0]][c.split("__")[1]]) outstr += help_table.add_entry(valuetuple) outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, cut_lst) #return the table for line in tableList: print line outFile.write(line+" \n") outFile.close()
def Syst_table(masterdic): texoutpath = CONF.inputpath + CONF.workdir + "_" + CONF.reweightdir + "/" + "PaperPlot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + "Syst_table.tex", "w") tag_lst = ["TwoTag_split", "ThreeTag", "FourTag"] sample_lst = ["totalbkg", "RSG1_2000", "Xhh_2000"] sample_dic = {"totalbkg":"Background", "RSG1_2000":"G*_{KK} (2 TeV)", "Xhh_2000":"S (2 TeV)"} tableList = [] column_lst = [] column_name_lst = [] column_dic = {} for t in tag_lst: for r in sample_lst: column_lst.append(t + "__" + r) column_name_lst.append(sample_dic[r]) for col in column_lst: #print col column_dic[col] = {} ###this is super complicated...let's get them one by one help_table.add_table_head(tableList, column_name_lst, title="Source", special_raw=tag_lst) ##take out ttbar #systag_lst = ["Lumi", "JER", "JMR", "tt", "Rtrk", "EFF", "method", "Stat"] #systag_dic = {"Lumi":"Luminosity", "JER":"JER", "JMR":"JMR", "tt":"\\ttbar MC", "Rtrk":"JES/JMS", "method":"Bkg Est", "EFF":"$b$-tagging", "Stat":"Statistical"} systag_lst = ["Lumi", "JER", "JMR", "Rtrk", "EFF", "method", "Stat"] systag_dic = {"Lumi":"Luminosity", "JER":"JER", "JMR":"JMR", "Rtrk":"JES/JMS", "method":"Bkg Est", "EFF":"$b$-tagging", "Stat":"Statistical"} #add each systematics for systag in systag_lst: #get the corresponding region outstr = "" outstr += systag_dic[systag] #print masterdic, systag for temp_col in column_lst: col = temp_col.split("__")[1] c = temp_col.split("__")[0] #print temp_col, col, systag if (systag == "Stat"): for key2 in masterdic[c]: if col in key2: outstr += help_table.add_entry(masterdic[c][key2]["int_err"]/masterdic[c][key2]["int"], doerr=False, percent=True) temp_col_dic = {"stat":(masterdic[c][key2]["int_err"]/masterdic[c][key2]["int"], 0)} column_dic[temp_col].update(temp_col_dic) elif (systag == "Lumi"): if ("RSG" in col): outstr += help_table.add_entry((0.033, 0), doerr=False, percent=True) temp_col_dic = {"Lumi":(0.033, 0)} column_dic[temp_col].update(temp_col_dic) else: outstr += help_table.add_entry((0, 0), doerr=False, percent=True) else: temp_col_dic = dump_syst.find_syst(masterdic, c, systag, col) outstr += help_table.add_entry(dump_syst.add_syst(temp_col_dic), doerr=False, percent=True) column_dic[temp_col].update(temp_col_dic) #finish the current entry outstr+="\\\\" tableList.append(outstr) #add all systematics: tableList.append("\\hline") outstr = "" outstr += "Total Sys" for temp_col in column_lst: outstr += help_table.add_entry(dump_syst.add_syst(column_dic[temp_col]), doerr=False, percent=True) outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, column_lst) #return the table for line in tableList: print line outFile.write(line+" \n") outFile.close() return column_dic
def SBCR_table(masterdic): texoutpath = CONF.inputpath + CONF.workdir + "_" + CONF.reweightdir + "/" + "PaperPlot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open(texoutpath + "SBCR_table.tex", "w") tableList = [] tag_lst = ["TwoTag_split", "ThreeTag", "FourTag"] region_lst = ["Sideband", "Control"] cut_lst = [] cut_name_lst = [] for t in tag_lst: for r in region_lst: cut_lst.append(t + "__" + r) cut_name_lst.append(r) help_table.add_table_head(tableList, cut_name_lst, title="Source", special_raw=tag_lst) #raw_lst = ["qcd", "ttbar", "zjet", "data"] #raw_lst_dic = {"qcd":"Multijet", "ttbar":"\\ttbar", "zjet":"$Z$+jet", "data":"Total"} raw_lst = ["qcd", "ttbar", "data"] raw_lst_dic = {"qcd": "Multijet", "ttbar": "\\ttbar", "data": "Total"} #check and debug # keylist = masterdic.keys() # keylist.sort() # for key in keylist: # print key, masterdic[key] for raw in raw_lst: #get the corresponding region outstr = "" outstr += raw_lst_dic[raw] #print masterdic, systag for c in cut_lst: if raw == "zjet": raw_tempname = raw else: raw_tempname = raw + "_est" err_fit = 0 if c.split("__")[1] + "_syst_muqcd_fit_up" in masterdic[ raw_tempname][c.split("__")[0]].keys(): err_fit = masterdic[raw_tempname][c.split("__")[0]][ c.split("__")[1] + "_syst_muqcd_fit_up"] #print err_fit err_all = helpers.syst_adderror( masterdic[raw_tempname][c.split("__")[0]][c.split("__")[1] + "_err"], err_fit) value = masterdic[raw_tempname][c.split("__")[0]][c.split( "__")[1]] + (masterdic["zjet"][c.split("__")[0]][c.split( "__")[1]] if raw_tempname == "qcd_est" else 0) valuetuple = (value, err_all) outstr += help_table.add_entry(valuetuple) #finish the current entry outstr += "\\\\" tableList.append(outstr) #add data: tableList.append("\\hline") outstr = "" outstr += "Data" for c in cut_lst: valuetuple = (masterdic["data"][c.split("__")[0]][c.split("__")[1]]) outstr += help_table.add_entry(valuetuple) outstr += "\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, cut_lst) #return the table for line in tableList: print line outFile.write(line + " \n") outFile.close()
def Syst_table(masterdic): texoutpath = CONF.inputpath + CONF.workdir + "_" + CONF.reweightdir + "/" + "PaperPlot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open(texoutpath + "Syst_table.tex", "w") tag_lst = ["TwoTag_split", "ThreeTag", "FourTag"] sample_lst = ["totalbkg", "RSG1_2000", "Xhh_2000"] sample_dic = { "totalbkg": "Background", "RSG1_2000": "G*_{KK} (2 TeV)", "Xhh_2000": "S (2 TeV)" } tableList = [] column_lst = [] column_name_lst = [] column_dic = {} for t in tag_lst: for r in sample_lst: column_lst.append(t + "__" + r) column_name_lst.append(sample_dic[r]) for col in column_lst: #print col column_dic[col] = {} ###this is super complicated...let's get them one by one help_table.add_table_head(tableList, column_name_lst, title="Source", special_raw=tag_lst) ##take out ttbar #systag_lst = ["Lumi", "JER", "JMR", "tt", "Rtrk", "EFF", "method", "Stat"] #systag_dic = {"Lumi":"Luminosity", "JER":"JER", "JMR":"JMR", "tt":"\\ttbar MC", "Rtrk":"JES/JMS", "method":"Bkg Est", "EFF":"$b$-tagging", "Stat":"Statistical"} systag_lst = ["Lumi", "JER", "JMR", "Rtrk", "EFF", "method", "Stat"] systag_dic = { "Lumi": "Luminosity", "JER": "JER", "JMR": "JMR", "Rtrk": "JES/JMS", "method": "Bkg Est", "EFF": "$b$-tagging", "Stat": "Statistical" } #add each systematics for systag in systag_lst: #get the corresponding region outstr = "" outstr += systag_dic[systag] #print masterdic, systag for temp_col in column_lst: col = temp_col.split("__")[1] c = temp_col.split("__")[0] #print temp_col, col, systag if (systag == "Stat"): for key2 in masterdic[c]: if col in key2: outstr += help_table.add_entry( masterdic[c][key2]["int_err"] / masterdic[c][key2]["int"], doerr=False, percent=True) temp_col_dic = { "stat": (masterdic[c][key2]["int_err"] / masterdic[c][key2]["int"], 0) } column_dic[temp_col].update(temp_col_dic) elif (systag == "Lumi"): if ("RSG" in col): outstr += help_table.add_entry((0.033, 0), doerr=False, percent=True) temp_col_dic = {"Lumi": (0.033, 0)} column_dic[temp_col].update(temp_col_dic) else: outstr += help_table.add_entry((0, 0), doerr=False, percent=True) else: temp_col_dic = dump_syst.find_syst(masterdic, c, systag, col) outstr += help_table.add_entry( dump_syst.add_syst(temp_col_dic), doerr=False, percent=True) column_dic[temp_col].update(temp_col_dic) #finish the current entry outstr += "\\\\" tableList.append(outstr) #add all systematics: tableList.append("\\hline") outstr = "" outstr += "Total Sys" for temp_col in column_lst: outstr += help_table.add_entry(dump_syst.add_syst( column_dic[temp_col]), doerr=False, percent=True) outstr += "\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, column_lst) #return the table for line in tableList: print line outFile.write(line + " \n") outFile.close() return column_dic
def plotRegion(config, cut, xTitle, yTitle="N Events", Logy=0, rebin=None, rebinarry=None, outputFolder=""): #load configurations from config file filepath = config["root"] filename = config["inputdir"] outputFolder= config["outputdir"] blinded = config["blind"] selsyst = config["syst"] #print selsyst #print blinded, " blinded!", config["blind"] #print config, filepath, filename #print cut gStyle.SetErrorX(0) gStyle.SetHatchesSpacing(0.7) gStyle.SetHatchesLineWidth(1) # input file: this part is different!! ifile = ROOT.TFile(filepath) data = ifile.Get("totalbkg_hh" ) if not blinded: data = ifile.Get("data_hh") data_est = ifile.Get("totalbkg_hh") qcd = ifile.Get("qcd_hh") #get all the systematics syst_up = [] syst_down = [] ifile.cd() for key in ROOT.gDirectory.GetListOfKeys(): kname = key.GetName() ##print kname # if "QCD" in kname: ##this is are buggy now! # continue # if "smooth" in kname: ##this is reasonable # continue # if "norm" in kname: ##this is reasonable # continue # if "JET" in kname: ##this is reasonable # continue # if "FT_" in kname: ##these are buggy now! # continue if selsyst != "all":## this is only selecting certain systematics, for checking if not (selsyst in kname): continue if "totalbkg_hh" is kname: continue # if "Tracking_All" not in kname: # continue #print kname if "totalbkg_hh" in kname and "up" in kname: syst_up.append(ifile.Get(kname).Clone(kname)) #print kname elif "totalbkg_hh" in kname and "down" in kname: syst_down.append(ifile.Get(kname).Clone(kname)) elif "totalbkg_hh" in kname: syst_up.append(ifile.Get(kname).Clone(kname)) syst_down.append(ifile.Get(kname).Clone(kname)) #print len(syst_up), len(syst_down) #qcd_origin = ifile.Get("qcd_" + cut ) #print "factor is ", qcd.Integral()/qcd_origin.Integral() ttbar = ifile.Get("ttbar_hh") zjet = ifile.Get("zjet_hh") RSG1_1000 = ifile.Get("signal_RSG_c10_hh_m1000") RSG1_1500 = ifile.Get("signal_RSG_c10_hh_m1500") RSG1_2500 = ifile.Get("signal_RSG_c10_hh_m2500") RSG1_2000 = ifile.Get("signal_RSG_c10_hh_m2000") RSG1_2000.Scale(30) RSG1_1500.Scale(10) RSG1_2500.Scale(100) if not rebin == None: data.Rebin(rebin) data_est.Rebin(rebin) qcd.Rebin(rebin) ttbar.Rebin(rebin) #zjet.Rebin(rebin) RSG1_1000.Rebin(rebin) RSG1_1500.Rebin(rebin) RSG1_2000.Rebin(rebin) RSG1_2500.Rebin(rebin) for jhist in syst_up: jhist.Rebin(rebin) for jhist in syst_down: jhist.Rebin(rebin) #use array to rebin histgrams if not rebinarry == None: data = data.Rebin(len(rebinarry) - 1, data.GetName()+"_rebinned", rebinarry) data_est = data_est.Rebin(len(rebinarry) - 1, data_est.GetName()+"_rebinned", rebinarry) qcd = qcd.Rebin(len(rebinarry) - 1, qcd.GetName()+"_rebinned", rebinarry) ttbar = ttbar.Rebin(len(rebinarry) - 1, ttbar.GetName()+"_rebinned", rebinarry) #zjet = zjet.Rebin(len(rebinarry) - 1, zjet.GetName()+"_rebinned", rebinarry) RSG1_1000 = RSG1_1000.Rebin(len(rebinarry) - 1, RSG1_1000.GetName()+"_rebinned", rebinarry) RSG1_1500 = RSG1_1500.Rebin(len(rebinarry) - 1, RSG1_1500.GetName()+"_rebinned", rebinarry) RSG1_2000 = RSG1_2000.Rebin(len(rebinarry) - 1, RSG1_2000.GetName()+"_rebinned", rebinarry) RSG1_2500 = RSG1_2500.Rebin(len(rebinarry) - 1, RSG1_2500.GetName()+"_rebinned", rebinarry) for jhist in syst_up: jhist = jhist.Rebin(len(rebinarry) - 1, jhist.GetName()+"_rebinned", rebinarry) for jhist in syst_down: jhist = jhist.Rebin(len(rebinarry) - 1, jhist.GetName()+"_rebinned", rebinarry) #get QS scores if "Signal" in cut and blinded: ks = 0 else: ks = data.KolmogorovTest(data_est, "QU") int_data = data.Integral(0, data.GetXaxis().GetNbins()+1) int_data_est = data_est.Integral(0, data_est.GetXaxis().GetNbins()+1) percentdiff = (int_data_est - int_data)/int_data * 100.0 #chi2 = data.Chi2Test(data_est, "QU CHI2") #ndf = chi2 / data.Chi2Test(data_est, "QU CHI2/NDF") if chi2 else 0.0 xMin = data.GetXaxis().GetBinLowEdge(1) xMax = data.GetXaxis().GetBinUpEdge(data.GetXaxis().GetNbins()) yMax = data.GetMaximum() * 1.5 if ("FourTag" in cut): yMax = data.GetMaximum() * 2.0 if Logy==1: yMax = yMax * 100 #qcd_fit = ifile.Get("qcd_fit") #qcd_fitUp = ifile.Get("qcd_fitUp") #qcd_fitDown = ifile.Get("qcd_fitDown") #make the total backgroudn with sytematics data = makeTotBkg([data])[1] #bkg = makeTotBkg([ttbar,qcd]) bkg = makeTotBkg([ttbar, qcd], syst_up, syst_down) #bkg = makeTotBkg([ttbar,qcd,zjet]) # bkg/data ratios: [0] band for stat errors, [1] bkg/data with syst errors ratios = makeDataRatio(data, bkg[1]) #comput the integrals! and make the table if (not blinded): texoutpath = CONF.inputpath + ops.inputdir + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outtexFile = open( texoutpath + cut + "_SR_region_compare" + ".tex", "w") tableList = [] int_range_lst = [">1000", ">1500", ">2000", ">2500", ">3000"] help_table.add_table_head(tableList, int_range_lst, title="Mass Range") #get total background outstr = "" outstr += "totalbkg" #print masterdic, systag for int_range in int_range_lst: err = ROOT.Double(0.) ##bkg[2] is the hist with uncertainties int_range = bkg[2].IntegralAndError(bkg[2].GetXaxis().FindBin(int(int_range.replace(">", ""))), bkg[2].GetXaxis().FindBin(3900), err) outstr += help_table.add_entry((int_range, float(err))) #finish the current entry outstr+="\\\\" tableList.append(outstr) #get data outstr = "" outstr += "data" #print masterdic, systag temp_data = ifile.Get("data_hh" ) for int_range in int_range_lst: err = ROOT.Double(0.) int_range = temp_data.IntegralAndError(temp_data.GetXaxis().FindBin(int(int_range.replace(">", ""))), temp_data.GetXaxis().FindBin(3900), err) outstr += help_table.add_entry((int_range, float(err))) #finish the current entry outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, int_range_lst) #return the table for line in tableList: print line outtexFile.write(line+" \n") outtexFile.close() # stack signal on background RSG1_1000.Add(bkg[0]) RSG1_1500.Add(bkg[0]) RSG1_2000.Add(bkg[0]) RSG1_2500.Add(bkg[0]) # canvas c0 = ROOT.TCanvas("c0"+filename+cut, "Insert hilarious TCanvas name here", 800, 800) c0.SetRightMargin(0.05) # top 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) c0.cd() pad0.SetLogy(Logy) pad0.Draw() pad0.cd() bkg[0].SetTitle("") bkg[0].SetStats(0) bkg[0].SetLineColor(ROOT.kBlack) bkg[0].SetLineWidth(2) bkg[0].GetYaxis().SetTitleFont(43) bkg[0].GetYaxis().SetTitleSize(28) bkg[0].GetYaxis().SetLabelFont(43) bkg[0].GetYaxis().SetLabelSize(28) bkg[0].GetYaxis().SetTitle(yTitle) bkg[0].GetYaxis().SetRangeUser(0.006, yMax) bkg[0].SetFillColor(ROOT.kYellow) bkg[0].Draw("HISTO") # RSG1_1000.SetLineWidth(2) # RSG1_1000.SetLineStyle(2) # RSG1_1000.SetLineColor(ROOT.kViolet+7) # RSG1_1000.Draw("HISTO SAME") # RSG1_1500.SetLineWidth(2) # RSG1_1500.SetLineStyle(2) # RSG1_1500.SetLineColor(ROOT.kPink+7) # RSG1_1500.Draw("HISTO SAME") RSG1_2000.SetLineWidth(2) RSG1_2000.SetLineStyle(2) RSG1_2000.SetLineColor(ROOT.kPink+7) RSG1_2000.Draw("HISTO SAME") # RSG1_2500.SetLineWidth(2) # RSG1_2500.SetLineStyle(2) # RSG1_2500.SetLineColor(ROOT.kGreen+4) # RSG1_2500.Draw("HISTO SAME") bkg[1].SetFillColor(CONF.col_dic["syst"]) bkg[1].SetLineColor(CONF.col_dic["syst"]) bkg[1].SetFillStyle(3345) bkg[1].SetMarkerSize(0) bkg[1].Draw("E2 SAME") ttbar.SetLineWidth(2) ttbar.SetLineColor(ROOT.kBlack) ttbar.SetFillColor(ROOT.kAzure-9) ttbar.Draw("HISTO SAME") #zjet.SetLineWidth(2) #zjet.SetLineColor(ROOT.kBlack) #zjet.SetFillColor(ROOT.kGreen+4) #zjet.Draw("HISTO SAME") zeroXerror(data) data.SetMarkerStyle(20) data.SetMarkerSize(1) data.SetLineWidth(2) data.GetXaxis().SetLabelSize(0) data.GetXaxis().SetLabelOffset(999) if not ("Signal" in cut and blinded): data.Draw("EPZ SAME") # bottom pad c0.cd() pad1.Draw() pad1.cd() hratio = ROOT.TH1F("hratio","",1, xMin, xMax) hratio.SetStats(0) hratio.GetYaxis().SetTitleFont(43) hratio.GetYaxis().SetTitleSize(28) hratio.GetYaxis().SetLabelFont(43) hratio.GetYaxis().SetLabelSize(28) hratio.GetYaxis().SetTitle("Data / Bkgd") hratio.GetYaxis().SetRangeUser(0.5, 2.1) #set range for ratio plot h_plt.drawarrow(ratios[1], 0.5, 2.1) hratio.GetYaxis().SetNdivisions(405) hratio.GetXaxis().SetTitleFont(43) hratio.GetXaxis().SetTitleOffset(3.5) hratio.GetXaxis().SetTitleSize(28) hratio.GetXaxis().SetLabelFont(43) hratio.GetXaxis().SetLabelSize(28) hratio.GetXaxis().SetTitle(xTitle) hratio.Draw() # # Add stat uncertianty # ratios[0].SetFillColor(CONF.col_dic["syst"]) ratios[0].SetFillStyle(3345) ratios[0].Draw("E2") #zeroXerror(ratios[1]) ratios[1].SetMarkerStyle(20) ratios[1].SetMarkerSize(1) ratios[1].SetLineWidth(2) if not ("Signal" in cut and blinded): ratios[1].Draw("E0PZ SAME") # qcd_fit.SetLineColor(kRed) # qcd_fitUp.SetLineColor(kRed) # qcd_fitUp.SetLineStyle(2) # qcd_fitDown.SetLineColor(kRed) # qcd_fitDown.SetLineStyle(2) # qcd_fit.Draw("SAME") # qcd_fitUp.Draw("SAME") # qcd_fitDown.Draw("SAME") # Fit the ratio with a TF1 # if not ("Signal" in cut and blinded): # testfit = ROOT.TF1("testfit", "pol2", xMin, xMax) # testfit.SetParameters(1, 0, 0) # ratios[1].Fit("testfit") # testfit.SetLineColor(kRed) # testfit.Draw("SAME") # fitresult = testfit.GetParameters() # myText(0.2, 0.17, 1, "y=%s x^2 + %s x + %s" % (str('%.2g' % fitresult[0]), \ # str('%.2g' % fitresult[1]),str('%.2g' % fitresult[2])), CONF.legsize) # draw the ratio 1 line line = ROOT.TLine(xMin, 1.0, xMax, 1.0) line.SetLineStyle(1) line.Draw() c0.cd() # # Add ks score # myText(0.15, 0.97, 1, "KS = %s" % str(('%.3g' % ks)), CONF.legsize) myText(0.4, 0.97, 1, "(Est-Obs)/Obs = %s; E=%s; O=%s" % (str(('%.1f' % percentdiff)), str(('%.1f' % int_data_est)), str(('%.1f' % int_data))), CONF.legsize) #myText(0.15, 0.92, 1, "#chi^{2} / ndf = %s / %s" % (str(chi2), str(ndf)), CONF.legsize) # labels legHunit=0.05 legH=legHunit*6 # retuned below based on number of entries to 0.05*num_entries legW=0.4 leg = ROOT.TLegend(0.65, 0.75, 0.95, 0.95) # top right, a bit left ATLASLabel(0.19, 0.91, StatusLabel) if "15" in filepath: myText(0.19, 0.87, 1, "#sqrt{s}=13 TeV, 2015, 3.2 fb^{-1}", CONF.legsize) elif "16" in filepath: myText(0.19, 0.87, 1, "#sqrt{s}=13 TeV, 2016, 2.6 fb^{-1}", CONF.legsize) else: myText(0.19, 0.87, 1, "#sqrt{s}=13 TeV, 15+16, " + str(CONF.totlumi) + " fb^{-1}", CONF.legsize) myText(0.19, 0.83, 1, ' ' + cut.replace("_", "; "), CONF.legsize) ##### legend leg.SetNColumns(2) leg.SetTextFont(43) leg.SetTextSize(CONF.legsize) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetBorderSize(0) leg.AddEntry(data, "Data", "PE") leg.AddEntry(bkg[0], "Multijet", "F") leg.AddEntry(ttbar, "t#bar{t}","F") #leg.AddEntry(zjet, "Z+jets","F") leg.AddEntry(bkg[1], "Stat+Syst", "F") #leg.AddEntry(RSG1_1000, "RSG1, 1TeV", "F") #leg.AddEntry(RSG1_1500, "RSG 1.5TeV * 10", "F") leg.AddEntry(RSG1_2000, "RSG 2.0TeV * 30", "F") #leg.AddEntry(RSG1_2500, "RSG 2.5TeV * 100", "F") #leg.AddEntry(qcd_fit, "Fit to Ratio", "L") #leg.AddEntry(qcd_fitUp, "#pm 1#sigma Uncertainty", "L") leg.SetY1(leg.GetY2()-leg.GetNRows()*legHunit) leg.Draw() # save postname = ("" if Logy == 0 else "_" + str(Logy)) + ("" if not ("Signal" in cut and blinded) else "_blind") + ("" if selsyst is "all" else "_" + selsyst) #c0.SaveAs(outputFolder+"/"+filename.replace(".root", ".pdf")) #c0.SaveAs(outputFolder+ "/" + filename + "_" + cut + postname + ".png") c0.SaveAs(outputFolder+ "/" + filename + "_" + cut + postname + ".pdf") #c0.SaveAs(outputFolder+ "/" + filename + "_" + cut + ".pdf") #c0.SaveAs(outputFolder+ "/" + filename + "_" + cut + ".eps") pad0.Close() pad1.Close() c0.Close() del(data) del(data_est) del(qcd) del(ttbar) del(zjet) del(RSG1_1000) del(RSG1_1500) del(RSG1_2500) del(syst_up) del(syst_down)
def plotRegion(config, cut, xTitle, yTitle="N Events", Logy=0, rebin=None, rebinarry=None, outputFolder=""): #load configurations from config file filepath = config["root"] filename = config["inputdir"] outputFolder = config["outputdir"] blinded = config["blind"] selsyst = config["syst"] #print selsyst #print blinded, " blinded!", config["blind"] #print config, filepath, filename #print cut gStyle.SetErrorX(0) gStyle.SetHatchesSpacing(0.7) gStyle.SetHatchesLineWidth(1) # input file: this part is different!! ifile = ROOT.TFile(filepath) data = ifile.Get("totalbkg_hh") if not blinded: data = ifile.Get("data_hh") data_est = ifile.Get("totalbkg_hh") qcd = ifile.Get("qcd_hh") #get all the systematics syst_up = [] syst_down = [] ifile.cd() for key in ROOT.gDirectory.GetListOfKeys(): kname = key.GetName() ##print kname # if "QCD" in kname: ##this is are buggy now! # continue # if "smooth" in kname: ##this is reasonable # continue # if "norm" in kname: ##this is reasonable # continue # if "JET" in kname: ##this is reasonable # continue # if "FT_" in kname: ##these are buggy now! # continue if selsyst != "all": ## this is only selecting certain systematics, for checking if not (selsyst in kname): continue if "totalbkg_hh" is kname: continue # if "Tracking_All" not in kname: # continue #print kname if "totalbkg_hh" in kname and "up" in kname: syst_up.append(ifile.Get(kname).Clone(kname)) #print kname elif "totalbkg_hh" in kname and "down" in kname: syst_down.append(ifile.Get(kname).Clone(kname)) elif "totalbkg_hh" in kname: syst_up.append(ifile.Get(kname).Clone(kname)) syst_down.append(ifile.Get(kname).Clone(kname)) #print len(syst_up), len(syst_down) #qcd_origin = ifile.Get("qcd_" + cut ) #print "factor is ", qcd.Integral()/qcd_origin.Integral() ttbar = ifile.Get("ttbar_hh") zjet = ifile.Get("zjet_hh") RSG1_1000 = ifile.Get("signal_RSG_c10_hh_m1000") RSG1_1500 = ifile.Get("signal_RSG_c10_hh_m1500") RSG1_2500 = ifile.Get("signal_RSG_c10_hh_m2500") RSG1_2000 = ifile.Get("signal_RSG_c10_hh_m2000") RSG1_2000.Scale(30) RSG1_1500.Scale(10) RSG1_2500.Scale(100) if not rebin == None: data.Rebin(rebin) data_est.Rebin(rebin) qcd.Rebin(rebin) ttbar.Rebin(rebin) #zjet.Rebin(rebin) RSG1_1000.Rebin(rebin) RSG1_1500.Rebin(rebin) RSG1_2000.Rebin(rebin) RSG1_2500.Rebin(rebin) for jhist in syst_up: jhist.Rebin(rebin) for jhist in syst_down: jhist.Rebin(rebin) #use array to rebin histgrams if not rebinarry == None: data = data.Rebin( len(rebinarry) - 1, data.GetName() + "_rebinned", rebinarry) data_est = data_est.Rebin( len(rebinarry) - 1, data_est.GetName() + "_rebinned", rebinarry) qcd = qcd.Rebin( len(rebinarry) - 1, qcd.GetName() + "_rebinned", rebinarry) ttbar = ttbar.Rebin( len(rebinarry) - 1, ttbar.GetName() + "_rebinned", rebinarry) #zjet = zjet.Rebin(len(rebinarry) - 1, zjet.GetName()+"_rebinned", rebinarry) RSG1_1000 = RSG1_1000.Rebin( len(rebinarry) - 1, RSG1_1000.GetName() + "_rebinned", rebinarry) RSG1_1500 = RSG1_1500.Rebin( len(rebinarry) - 1, RSG1_1500.GetName() + "_rebinned", rebinarry) RSG1_2000 = RSG1_2000.Rebin( len(rebinarry) - 1, RSG1_2000.GetName() + "_rebinned", rebinarry) RSG1_2500 = RSG1_2500.Rebin( len(rebinarry) - 1, RSG1_2500.GetName() + "_rebinned", rebinarry) for jhist in syst_up: jhist = jhist.Rebin( len(rebinarry) - 1, jhist.GetName() + "_rebinned", rebinarry) for jhist in syst_down: jhist = jhist.Rebin( len(rebinarry) - 1, jhist.GetName() + "_rebinned", rebinarry) #get QS scores if "Signal" in cut and blinded: ks = 0 else: ks = data.KolmogorovTest(data_est, "QU") int_data = data.Integral(0, data.GetXaxis().GetNbins() + 1) int_data_est = data_est.Integral(0, data_est.GetXaxis().GetNbins() + 1) percentdiff = (int_data_est - int_data) / int_data * 100.0 #chi2 = data.Chi2Test(data_est, "QU CHI2") #ndf = chi2 / data.Chi2Test(data_est, "QU CHI2/NDF") if chi2 else 0.0 xMin = data.GetXaxis().GetBinLowEdge(1) xMax = data.GetXaxis().GetBinUpEdge(data.GetXaxis().GetNbins()) yMax = data.GetMaximum() * 1.5 if ("FourTag" in cut): yMax = data.GetMaximum() * 2.0 if Logy == 1: yMax = yMax * 100 #qcd_fit = ifile.Get("qcd_fit") #qcd_fitUp = ifile.Get("qcd_fitUp") #qcd_fitDown = ifile.Get("qcd_fitDown") #make the total backgroudn with sytematics data = makeTotBkg([data])[1] #bkg = makeTotBkg([ttbar,qcd]) bkg = makeTotBkg([ttbar, qcd], syst_up, syst_down) #bkg = makeTotBkg([ttbar,qcd,zjet]) # bkg/data ratios: [0] band for stat errors, [1] bkg/data with syst errors ratios = makeDataRatio(data, bkg[1]) #comput the integrals! and make the table if (not blinded): texoutpath = CONF.inputpath + ops.inputdir + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outtexFile = open(texoutpath + cut + "_SR_region_compare" + ".tex", "w") tableList = [] int_range_lst = [">1000", ">1500", ">2000", ">2500", ">3000"] help_table.add_table_head(tableList, int_range_lst, title="Mass Range") #get total background outstr = "" outstr += "totalbkg" #print masterdic, systag for int_range in int_range_lst: err = ROOT.Double(0.) ##bkg[2] is the hist with uncertainties int_range = bkg[2].IntegralAndError( bkg[2].GetXaxis().FindBin(int(int_range.replace(">", ""))), bkg[2].GetXaxis().FindBin(3900), err) outstr += help_table.add_entry((int_range, float(err))) #finish the current entry outstr += "\\\\" tableList.append(outstr) #get data outstr = "" outstr += "data" #print masterdic, systag temp_data = ifile.Get("data_hh") for int_range in int_range_lst: err = ROOT.Double(0.) int_range = temp_data.IntegralAndError( temp_data.GetXaxis().FindBin(int(int_range.replace(">", ""))), temp_data.GetXaxis().FindBin(3900), err) outstr += help_table.add_entry((int_range, float(err))) #finish the current entry outstr += "\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, int_range_lst) #return the table for line in tableList: print line outtexFile.write(line + " \n") outtexFile.close() # stack signal on background RSG1_1000.Add(bkg[0]) RSG1_1500.Add(bkg[0]) RSG1_2000.Add(bkg[0]) RSG1_2500.Add(bkg[0]) # canvas c0 = ROOT.TCanvas("c0" + filename + cut, "Insert hilarious TCanvas name here", 800, 800) c0.SetRightMargin(0.05) # top 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) c0.cd() pad0.SetLogy(Logy) pad0.Draw() pad0.cd() bkg[0].SetTitle("") bkg[0].SetStats(0) bkg[0].SetLineColor(ROOT.kBlack) bkg[0].SetLineWidth(2) bkg[0].GetYaxis().SetTitleFont(43) bkg[0].GetYaxis().SetTitleSize(28) bkg[0].GetYaxis().SetLabelFont(43) bkg[0].GetYaxis().SetLabelSize(28) bkg[0].GetYaxis().SetTitle(yTitle) bkg[0].GetYaxis().SetRangeUser(0.006, yMax) bkg[0].SetFillColor(ROOT.kYellow) bkg[0].Draw("HISTO") # RSG1_1000.SetLineWidth(2) # RSG1_1000.SetLineStyle(2) # RSG1_1000.SetLineColor(ROOT.kViolet+7) # RSG1_1000.Draw("HISTO SAME") # RSG1_1500.SetLineWidth(2) # RSG1_1500.SetLineStyle(2) # RSG1_1500.SetLineColor(ROOT.kPink+7) # RSG1_1500.Draw("HISTO SAME") RSG1_2000.SetLineWidth(2) RSG1_2000.SetLineStyle(2) RSG1_2000.SetLineColor(ROOT.kPink + 7) RSG1_2000.Draw("HISTO SAME") # RSG1_2500.SetLineWidth(2) # RSG1_2500.SetLineStyle(2) # RSG1_2500.SetLineColor(ROOT.kGreen+4) # RSG1_2500.Draw("HISTO SAME") bkg[1].SetFillColor(CONF.col_dic["syst"]) bkg[1].SetLineColor(CONF.col_dic["syst"]) bkg[1].SetFillStyle(3345) bkg[1].SetMarkerSize(0) bkg[1].Draw("E2 SAME") ttbar.SetLineWidth(2) ttbar.SetLineColor(ROOT.kBlack) ttbar.SetFillColor(ROOT.kAzure - 9) ttbar.Draw("HISTO SAME") #zjet.SetLineWidth(2) #zjet.SetLineColor(ROOT.kBlack) #zjet.SetFillColor(ROOT.kGreen+4) #zjet.Draw("HISTO SAME") zeroXerror(data) data.SetMarkerStyle(20) data.SetMarkerSize(1) data.SetLineWidth(2) data.GetXaxis().SetLabelSize(0) data.GetXaxis().SetLabelOffset(999) if not ("Signal" in cut and blinded): data.Draw("EPZ SAME") # bottom pad c0.cd() pad1.Draw() pad1.cd() hratio = ROOT.TH1F("hratio", "", 1, xMin, xMax) hratio.SetStats(0) hratio.GetYaxis().SetTitleFont(43) hratio.GetYaxis().SetTitleSize(28) hratio.GetYaxis().SetLabelFont(43) hratio.GetYaxis().SetLabelSize(28) hratio.GetYaxis().SetTitle("Data / Bkgd") hratio.GetYaxis().SetRangeUser(0.5, 2.1) #set range for ratio plot h_plt.drawarrow(ratios[1], 0.5, 2.1) hratio.GetYaxis().SetNdivisions(405) hratio.GetXaxis().SetTitleFont(43) hratio.GetXaxis().SetTitleOffset(3.5) hratio.GetXaxis().SetTitleSize(28) hratio.GetXaxis().SetLabelFont(43) hratio.GetXaxis().SetLabelSize(28) hratio.GetXaxis().SetTitle(xTitle) hratio.Draw() # # Add stat uncertianty # ratios[0].SetFillColor(CONF.col_dic["syst"]) ratios[0].SetFillStyle(3345) ratios[0].Draw("E2") #zeroXerror(ratios[1]) ratios[1].SetMarkerStyle(20) ratios[1].SetMarkerSize(1) ratios[1].SetLineWidth(2) if not ("Signal" in cut and blinded): ratios[1].Draw("E0PZ SAME") # qcd_fit.SetLineColor(kRed) # qcd_fitUp.SetLineColor(kRed) # qcd_fitUp.SetLineStyle(2) # qcd_fitDown.SetLineColor(kRed) # qcd_fitDown.SetLineStyle(2) # qcd_fit.Draw("SAME") # qcd_fitUp.Draw("SAME") # qcd_fitDown.Draw("SAME") # Fit the ratio with a TF1 # if not ("Signal" in cut and blinded): # testfit = ROOT.TF1("testfit", "pol2", xMin, xMax) # testfit.SetParameters(1, 0, 0) # ratios[1].Fit("testfit") # testfit.SetLineColor(kRed) # testfit.Draw("SAME") # fitresult = testfit.GetParameters() # myText(0.2, 0.17, 1, "y=%s x^2 + %s x + %s" % (str('%.2g' % fitresult[0]), \ # str('%.2g' % fitresult[1]),str('%.2g' % fitresult[2])), CONF.legsize) # draw the ratio 1 line line = ROOT.TLine(xMin, 1.0, xMax, 1.0) line.SetLineStyle(1) line.Draw() c0.cd() # # Add ks score # myText(0.15, 0.97, 1, "KS = %s" % str(('%.3g' % ks)), CONF.legsize) myText( 0.4, 0.97, 1, "(Est-Obs)/Obs = %s; E=%s; O=%s" % (str( ('%.1f' % percentdiff)), str( ('%.1f' % int_data_est)), str(('%.1f' % int_data))), CONF.legsize) #myText(0.15, 0.92, 1, "#chi^{2} / ndf = %s / %s" % (str(chi2), str(ndf)), CONF.legsize) # labels legHunit = 0.05 legH = legHunit * 6 # retuned below based on number of entries to 0.05*num_entries legW = 0.4 leg = ROOT.TLegend(0.65, 0.75, 0.95, 0.95) # top right, a bit left ATLASLabel(0.19, 0.91, StatusLabel) if "15" in filepath: myText(0.19, 0.87, 1, "#sqrt{s}=13 TeV, 2015, 3.2 fb^{-1}", CONF.legsize) elif "16" in filepath: myText(0.19, 0.87, 1, "#sqrt{s}=13 TeV, 2016, 2.6 fb^{-1}", CONF.legsize) else: myText(0.19, 0.87, 1, "#sqrt{s}=13 TeV, 15+16, " + str(CONF.totlumi) + " fb^{-1}", CONF.legsize) myText(0.19, 0.83, 1, ' ' + cut.replace("_", "; "), CONF.legsize) ##### legend leg.SetNColumns(2) leg.SetTextFont(43) leg.SetTextSize(CONF.legsize) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetBorderSize(0) leg.AddEntry(data, "Data", "PE") leg.AddEntry(bkg[0], "Multijet", "F") leg.AddEntry(ttbar, "t#bar{t}", "F") #leg.AddEntry(zjet, "Z+jets","F") leg.AddEntry(bkg[1], "Stat+Syst", "F") #leg.AddEntry(RSG1_1000, "RSG1, 1TeV", "F") #leg.AddEntry(RSG1_1500, "RSG 1.5TeV * 10", "F") leg.AddEntry(RSG1_2000, "RSG 2.0TeV * 30", "F") #leg.AddEntry(RSG1_2500, "RSG 2.5TeV * 100", "F") #leg.AddEntry(qcd_fit, "Fit to Ratio", "L") #leg.AddEntry(qcd_fitUp, "#pm 1#sigma Uncertainty", "L") leg.SetY1(leg.GetY2() - leg.GetNRows() * legHunit) leg.Draw() # save postname = ("" if Logy == 0 else "_" + str(Logy)) + ( "" if not ("Signal" in cut and blinded) else "_blind") + ("" if selsyst is "all" else "_" + selsyst) #c0.SaveAs(outputFolder+"/"+filename.replace(".root", ".pdf")) #c0.SaveAs(outputFolder+ "/" + filename + "_" + cut + postname + ".png") c0.SaveAs(outputFolder + "/" + filename + "_" + cut + postname + ".pdf") #c0.SaveAs(outputFolder+ "/" + filename + "_" + cut + ".pdf") #c0.SaveAs(outputFolder+ "/" + filename + "_" + cut + ".eps") pad0.Close() pad1.Close() c0.Close() del (data) del (data_est) del (qcd) del (ttbar) del (zjet) del (RSG1_1000) del (RSG1_1500) del (RSG1_2500) del (syst_up) del (syst_down)
def GetTable(masterdic, c): texoutpath = CONF.inputpath + "Moriond" + "/" + "Plot/Tables/" if not os.path.exists(texoutpath): os.makedirs(texoutpath) outFile = open( texoutpath + c + "_fullsyst" + ("" if "pole" not in finaldis else "_pole") + ".tex", "w") tableList = [] column_lst = ["totalbkg", "qcd", "ttbar", "RSG1_1000", "RSG1_2000", "RSG1_3000"] column_dic = {} for col in column_lst: column_dic[col] = {} ###this is super complicated...let's get them one by one help_table.add_table_head(tableList, column_lst, title=c) systag_lst = {"tt":"Top", "JER":"JER", "JMR":"JMR", "Rtrk":"JES/JMS", "method":"Bkg Est", "EFF":"b-tag SF"} #systag_lst = {"method":"Bkg Est"} #add each systematics for systag, systagname in systag_lst.iteritems(): column_dic[systag] = {} #get the corresponding region outstr = "" outstr += systagname #print masterdic, systag for col in column_lst: temp_col_dic = find_syst(masterdic, c, systag, col) outstr += help_table.add_entry(add_syst(temp_col_dic), doerr=False, percent=True) column_dic[col].update(temp_col_dic) if ("tt" in systag): print col, systag, temp_col_dic #finish the current entry outstr+="\\\\" tableList.append(outstr) #add all systematics: tableList.append("\\hline") outstr = "" outstr += "Total Sys" for col in column_lst: outstr += help_table.add_entry(add_syst(column_dic[col]), doerr=False, percent=True) outstr+="\\\\" tableList.append(outstr) #add all stat uncertainty: tableList.append("\\hline") outstr = "" outstr += "Stat" for col in column_lst: for key2 in masterdic[c]: if col in key2: outstr += help_table.add_entry(masterdic[c][key2]["int_err"]/masterdic[c][key2]["int"], doerr=False, percent=True) outstr+="\\\\" tableList.append(outstr) #add all values: tableList.append("\\hline") outstr = "" outstr += "Estimated Events" for col in column_lst: for key2 in masterdic[c]: if col in key2: outstr += help_table.add_entry(masterdic[c][key2]["int"], doerr=False, percent=False) outstr+="\\\\" tableList.append(outstr) #finish the table help_table.add_table_tail(tableList, column_lst) #return the table for line in tableList: print line outFile.write(line+" \n") outFile.close() return column_dic