def closure_plot(predict, estimate): # Glob the file lists bkg_list_wjets = [output_dirpath + "/wj_ht.root"] bkg_list_ttbar = [output_dirpath + "/tt_1l.root"] # Get all the histogram objects h_wjets_predict = ru.get_summed_histogram(bkg_list_wjets, predict) h_ttbar_predict = ru.get_summed_histogram(bkg_list_ttbar, predict) h_wjets_estimate = ru.get_summed_histogram(bkg_list_wjets, estimate) h_ttbar_estimate = ru.get_summed_histogram(bkg_list_ttbar, estimate) # Set the names of the histograms h_wjets_predict.SetName("W predict") h_ttbar_predict.SetName("Top predict") h_wjets_estimate.SetName("W estimate") h_ttbar_estimate.SetName("Top estimate") # Color settings colors = [ 2005, 2001, ] # Options alloptions = { "ratio_range": [0.0, 2.0], "nbins": 1, "autobin": False, "legend_scalex": 1.8, "legend_scaley": 1.1, "output_name": "plots/closure/{}.pdf".format(predict + "__" + estimate), "bkg_sort_method": "unsorted", "no_ratio": False, "print_yield": False, "yaxis_log": True if "ptcorr" in predict else False, "legend_smart": False if "ptcorr" in predict else True, "lumi_value": 41.3, "legend_datalabel": "Estimate", "yield_prec": 3, "print_yield": True, } # The bkg histogram list bgs_list = [ h_ttbar_predict, h_wjets_predict, ] #bgs_list = [ h_ttbar_predict ] h_estimate = h_wjets_estimate.Clone("Estimate") h_estimate.Add(h_ttbar_estimate) # Plot them p.plot_hist(bgs=bgs_list, data=h_estimate, colors=colors, syst=None, options=alloptions)
def plot(histnames, ps=0, sf=0): # Glob the file lists # bkg_list_wjets = glob.glob(output_dirpath+"/WJetsToLNu_Tune*.root") # bkg_list_dy = glob.glob(output_dirpath+"/DY*.root") # bkg_list_ttbar = glob.glob(output_dirpath+"/TTJets_Tune*.root") # bkg_list_vv = glob.glob(output_dirpath+"/WW*.root") + glob.glob(output_dirpath+"/WW*.root") # bkg_list_qcd_mu = glob.glob(output_dirpath+"/QCD*MuEn*.root") # bkg_list_qcd_el = glob.glob(output_dirpath+"/QCD*EMEn*.root") # bkg_list_qcd_bc = glob.glob(output_dirpath+"/QCD*bcToE*.root") bkg_list_wjets = [output_dirpath + "/wj_incl.root"] bkg_list_dy = [output_dirpath + "/dy.root"] bkg_list_ttbar = [output_dirpath + "/tt_incl.root"] bkg_list_vv = [output_dirpath + "/ww.root", output_dirpath + "/wz.root"] bkg_list_qcd_mu = [output_dirpath + "/qcd_mu.root"] bkg_list_qcd_el = [output_dirpath + "/qcd_em.root"] bkg_list_qcd_bc = [output_dirpath + "/qcd_bc.root"] bkg_list_all = bkg_list_wjets + bkg_list_dy + bkg_list_ttbar + bkg_list_vv # Glob the data file list depending on the region if "Mu" in histnames: data_list = [output_dirpath + "/data_mu.root"] elif "El" in histnames: data_list = [output_dirpath + "/data_el.root"] else: data_list = [ output_dirpath + "/data_mu.root", output_dirpath + "/data_el.root" ] # Get all the histogram objects h_wjets = ru.get_summed_histogram(bkg_list_wjets, histnames) h_dy = ru.get_summed_histogram(bkg_list_dy, histnames) h_ttbar = ru.get_summed_histogram(bkg_list_ttbar, histnames) h_vv = ru.get_summed_histogram(bkg_list_vv, histnames) h_qcd_mu = ru.get_summed_histogram(bkg_list_qcd_mu, histnames) h_qcd_el = ru.get_summed_histogram(bkg_list_qcd_el, histnames) h_qcd_bc = ru.get_summed_histogram(bkg_list_qcd_bc, histnames) h_data = ru.get_summed_histogram(data_list, histnames) # Set the names of the histograms h_wjets.SetName("W") h_dy.SetName("Z") h_ttbar.SetName("Top") h_vv.SetName("VV") h_qcd_mu.SetName("QCD(#mu)") h_qcd_el.SetName("QCD(e)") h_qcd_bc.SetName("QCD(bc)") h_data.SetName("Data") # Scale the histograms appropriately from SF from the EWKCR if sf > 0: h_wjets.Scale(sf) h_dy.Scale(sf) h_ttbar.Scale(sf) h_vv.Scale(sf) # If the data needs some additional correction for the prescale if ps > 0: h_data.Scale(ps) # Color settings colors = [2007, 2005, 2003, 2001, 920, 2] # Options alloptions = { "ratio_range": [0.0, 2.0], "nbins": 30, "autobin": False, "legend_scalex": 1.8, "legend_scaley": 1.1, "output_name": "plots/plot/{}.pdf".format(histnames), "bkg_sort_method": "unsorted", "no_ratio": False, "print_yield": False, "yaxis_log": True if "ptcorr" in histnames else False, #"yaxis_log": False, "divide_by_bin_width": True, "legend_smart": False if "ptcorr" in histnames else True, "lumi_value": 41.3, } # The bkg histogram list bgs_list = [h_vv, h_ttbar, h_dy, h_wjets, h_qcd_mu], bgs_list = [ h_vv, h_ttbar, h_dy, h_wjets, h_qcd_mu ] if "Mu" in histnames else [h_vv, h_ttbar, h_dy, h_wjets, h_qcd_el] # Plot them p.plot_hist(bgs=bgs_list, data=h_data.Clone("Data"), colors=colors, syst=None, options=alloptions) # Obtain the histogram again to return the object for further calculations # Data-driven QCD = data - bkg h_ddqcd = ru.get_summed_histogram(data_list, histnames) h_bkg = ru.get_summed_histogram(bkg_list_all, histnames) if ps > 0: h_ddqcd.Scale(ps) if sf > 0: h_bkg.Scale(sf) h_ddqcd.Add(h_bkg, -1) # MC QCD h_qcd_mu = ru.get_summed_histogram(bkg_list_qcd_mu, histnames).Clone("QCD(#mu)") h_qcd_el = ru.get_summed_histogram(bkg_list_qcd_el, histnames).Clone("QCD(EM)") h_qcd_bc = ru.get_summed_histogram(bkg_list_qcd_bc, histnames).Clone("QCD(HF)") return h_ddqcd, h_data, h_bkg, h_qcd_mu, h_qcd_el, h_qcd_bc
def fakerate(num, den, ps=0, sf=0, sferr=0, tfile=None): # Obtain histograms h_num, h_num_qcd_mu, h_num_qcd_esum, h_num_qcd_el, h_num_qcd_bc = get_fakerate_histograms( num, den, ps, sf) herr_num, herr_num_qcd_mu, herr_num_qcd_esum, herr_num_qcd_el, herr_num_qcd_bc = get_fakerate_histograms( num, den, ps, sf + sferr) # Set data-driven QCD estimate systematics stemming from EWK SF uncertainty add_systematics(h_num, herr_num) # Options alloptions = { "ratio_range": [0.0, 2.0], "nbins": 180, "autobin": False, "legend_scalex": 1.8, "legend_scaley": 1.1, "output_name": "plots/fakerate/{}.pdf".format(num + "__" + den), "bkg_sort_method": "unsorted", "no_ratio": False, "print_yield": True, "yield_prec": 3, "draw_points": True, "lumi_value": 41.3, } bgs_list = [h_num_qcd_mu] if "Mu" in num else [h_num_qcd_esum] #bgs_list = [h_num_qcd_mu] if "Mu" in num else [h_num_qcd_esum, h_num_qcd_el, h_num_qcd_bc] sigs_list = [] if "Mu" in num else [h_num_qcd_el, h_num_qcd_bc] p.plot_hist( sigs=sigs_list, bgs=bgs_list, data=h_num, #data = None, syst=None, options=alloptions) if tfile: tfile.cd() channel = "Mu" if "Mu" in num else "El" histname = num.split("__")[1] data_fakerate = h_num.Clone(channel + "_" + histname + "_data_fakerate") qcd_fakerate = bgs_list[0].Clone(channel + "_" + histname + "_qcd_fakerate") if histname == "etacorrvarbin": create_varbin(data_fakerate, "eta_bounds").Write() create_varbin(qcd_fakerate, "eta_bounds").Write() elif histname == "ptcorrvarbin": create_varbin(data_fakerate, "ptcorr_bounds").Write() create_varbin(qcd_fakerate, "ptcorr_bounds").Write() elif histname == "ptcorrvarbincoarse": create_varbin(data_fakerate, "ptcorrcoarse_bounds").Write() create_varbin(qcd_fakerate, "ptcorrcoarse_bounds").Write() elif histname == "ptcorretarolled": create_varbin(data_fakerate, "ptcorr_bounds", "eta_bounds").Write() create_varbin(qcd_fakerate, "ptcorr_bounds", "eta_bounds").Write() elif histname == "ptcorretarolledcoarse": create_varbin(data_fakerate, "ptcorrcoarse_bounds", "eta_bounds").Write() create_varbin(qcd_fakerate, "ptcorrcoarse_bounds", "eta_bounds").Write()