#print '{:<15}'.format('category') + '{:<15}'.format('mean_roch') + '{:<15}'.format('mean_kamu') + '{:<15}'.format('sigma_roch') + '{:<15}'.format('sigma_kamu') 
#for i in range(0,len(ggf_ratios)):
#    print ('{:<15}'.format(categories[i]) + '{:<15.2f}'.format(ggf_mean_roch[i]) + '{:<15.2f}'.format(ggf_mean_kamu[i]) + 
#          '{:<15.2f}'.format(ggf_sigma_roch[i]) + '{:<15.2f}'.format(ggf_sigma_kamu[i]) )
#
#print "\n =========== LIST VBF INFO ================ \n" 
#
#print '{:<15}'.format('category') + '{:<15}'.format('mean_roch') + '{:<15}'.format('mean_kamu') + '{:<15}'.format('sigma_roch') + '{:<15}'.format('sigma_kamu')
#for i in range(0,len(vbf_ratios)):
#    print ('{:<15}'.format(categories[i]) + '{:<15.2f}'.format(vbf_mean_roch[i]) + '{:<15.2f}'.format(vbf_mean_kamu[i]) + 
#          '{:<15.2f}'.format(vbf_sigma_roch[i]) + '{:<15.2f}'.format(vbf_sigma_kamu[i]) )

print "\n =========== REBIN and RATIO ================ \n" 

for i in range(0,len(roch_plots)):
    hroch = roch_plots[i]
    hkamu = kamu_plots[i]
    hroch.SetName(hroch.GetName()+"_Roch")
    hroch.SetTitle(hroch.GetTitle()+"_Roch")
    hkamu.SetName(hkamu.GetName()+"_KaMu")
    hkamu.SetTitle(hkamu.GetTitle()+"_KaMu")
    print "\n  /// %d /// Stack and Ratio for %s, %s" % (i, hroch.GetName(), hkamu.GetName())
    hlist = [hkamu, hroch]
    #newBins = tools.getRebinEdges(hroch, hkamu, max_err=0.1)
    newBins = np.linspace(110, 160, 50) 
    #print newBins
    rebin_hlist = tools.rebin(hlist, newBins)
    hroch = rebin_hlist[1]
    hkamu = rebin_hlist[0]
    tools.stackAndRatio(rebin_hlist, title=hroch.GetName()+"_vs_KaMu", ytitleratio='Roch/KaMu', log=False, yrange=(0, hroch.GetMaximum()*1.15), yrange_ratio=(0.85,1.15))
        h.SetTitle("Inclusive")
        inclusive = h

#print "\n =========== OVERLAY ================== \n"
#tools.overlay(hlist, title="Background Shapes", savename="compare_bkg_shapes", xtitle="dimu_mass", ytitle="Events / 0.2 GeV",
#              ldim=[0.85, 0.4, 0.98, 0.98], draw='fill-transparent')

print "\n =========== STACKS ================== \n"
list_to_stack = []

for h in hlist:
    if 'cAll' in h.GetName():
        continue

    l = [h, inclusive]
    e = tools.getRebinEdges(h, inclusive, max_err=0.05)
    lrebin = tools.scaleByBinWidth(tools.rebin(l, e), e)
    tools.stackAndRatio(lrebin,
                        log=False,
                        name=h.GetTitle(),
                        savename="bkg_shapes_stack_%s" % h.GetTitle(),
                        title=h.GetTitle(),
                        ytitleratio="%s/%s" % ("Inclusive", h.GetTitle()),
                        errband="Error Band",
                        ldim=[0.6, 0.55, 0.92, 0.92])

#for l in list_to_stack:
#    h = l[0]
#    tools.stackAndRatio(l, log=False, name=h.GetName(), savename="bkg_shapes_stack_%s" % h.GetName(), title=h.GetName(),
#                        ytitleratio="%s/%s" % (h.GetName(), 'inclusive'))
        in_list.append( (filename, 'net_histos/%s_%s' % (c, s)) )

        # Up and Down uncertainty histograms to get for this category, e.g. JES_up, JES_down, ...
        if s == 'Net_Data': 
            continue       # Data does not have up/down uncertainty histograms, only MC

        for key,value in in_unc_map.iteritems():
            value.append( (filename, 'net_histos/%s_%s_%s' % (c, s, key)) ) 
    
    # list of histograms to make the stack and ratio plots for this category
    hlist = tools.get(in_list)

    # map to lists of up/down uncertainty histograms for this category
    # 'JES_up' -> list of JES_up histos for this category
    for in_key, in_value in in_unc_map.iteritems():
        unc_hist_map[in_key] = tools.get(in_value) 

    #hmc = tools.add(hlist[0:-1])
    #hdata = hlist[-1]
    #newBins = tools.getRebinEdges(hdata, hmc, max_err=0.05)
    #print newBins
    #rebin_hlist = tools.rebin(hlist, newBins) #rebinned to var bin width
    #srebin_hlist = tools.scaleByBinWidth(rebin_hlist, newBins) # rebinned to var bin width and wide bins are scaled down
    
    print "\n =========== STACK AND RATIO ====== \n" 
    
    tools.stackAndRatio(hlist, unc_map=unc_hist_map, savename=varname+'_%s' % c, title=('%s '+ vartitle) % c, ldim=[0.6, 0.55, 0.92, 0.92], xtitle=vartitle+units)
    #tools.stackAndRatio(srebin_hlist, savename=varname+'_%s' % c, title=('%s '+ vartitle) % c, ldim=[0.6, 0.55, 0.92, 0.92], xtitle=vartitle+units)
    #tdrstyle.cmsPrel(35900, 13, False, onLeft=True)
    c = TCanvas();
Exemple #4
0
gg_h130 = gg_hlist[2]

gg_h125.SetTitle("GGF_M125");
gg_h120.SetTitle("GGF_M120");
gg_h130.SetTitle("GGF_M130");

gg_l120 = [gg_h120, gg_h125]
gg_l130 = [gg_h130, gg_h125]

# -- vbf -----------------------
vbf_h125 = vbf_hlist[0]
vbf_h120 = vbf_hlist[1]
vbf_h130 = vbf_hlist[2]

vbf_h125.SetTitle("VBF_M125");
vbf_h120.SetTitle("VBF_M120");
vbf_h130.SetTitle("VBF_M130");

vbf_l120 = [vbf_h120, vbf_h125]
vbf_l130 = [vbf_h130, vbf_h125]

print "\n =========== STACK AND RATIO ====== \n" 
tools.stackAndRatio(gg_l120, title='BDT_Score_GGF_M125_vs_M120', ytitleratio='M125/M120', log=False, yrange=(0,0.06), xtitle="bdt_score")
tools.stackAndRatio(gg_l130, title='BDT_Score_GGF_M125_vs_M130', ytitleratio='M125/M130', log=False, yrange=(0,0.06), xtitle="bdt_score")

tools.stackAndRatio(vbf_l120, title='BDT_Score_VBF_M125_vs_M120', ytitleratio='M125/M120', log=False, yrange=(0,0.08), xtitle="bdt_score", 
                    ldim=[0.13, 0.67, 0.41, 0.88])
tools.stackAndRatio(vbf_l130, title='BDT_Score_VBF_M125_vs_M130', ytitleratio='M125/M130', log=False, yrange=(0,0.08), xtitle="bdt_score",
                    ldim=[0.13, 0.67, 0.41, 0.88])

Exemple #5
0
    'Drell_Yan', 'Net_Data'
]

filename = dirname + filenames[2]
getlist = []

#for sample in samples:
#    getlist.append((filename, 'net_histos/%s_%s' % (category, sample)))

getlist.append((filename, 'Net_DY_HT'))
getlist.append((filename, 'ZJets_AMC'))

print "\n =========== GET ================== \n"
hlist = tools.get(getlist)
print "\n =========== REBIN ================ \n"
hmc = tools.add(hlist[0:-1])
hdata = hlist[-1]
newBins = tools.getRebinEdges(hdata, hmc, max_err=0.1)
print newBins
rebin_hlist = tools.rebin(hlist, newBins)  #rebinned to var bin width
srebin_hlist = tools.scaleByBinWidth(
    rebin_hlist,
    newBins)  # rebinned to var bin width and wide bins are scaled down
srebin_hlist[0].SetTitle('ZJets_MG')

print "\n =========== STACK AND RATIO ====== \n"
tools.stackAndRatio(srebin_hlist,
                    title='Drell_Yan_MC_AMC_vs_Madgraph',
                    ytitleratio='AMC/MG',
                    yrange=(1e3, 1e7))
Exemple #6
0
              'c_01_Jet_Loose_OO',
              'c_01_Jet_Loose_OE',
              'c_01_Jet_Loose_EE'
              ]

category = 'c_01_Jet_Tight_BB'
samples = ['VH', 'H2Mu_VBF', 'H2Mu_gg', 'Diboson_plus', 'TTbar_Plus_SingleTop', 'Drell_Yan', 'Net_Data']

filename = dirname+filenames[2]
getlist = []

#for sample in samples:
#    getlist.append((filename, 'net_histos/%s_%s' % (category, sample)))

getlist.append( (filename, 'Net_DY_HT') )
getlist.append( (filename, 'ZJets_AMC') )

print "\n =========== GET ================== \n" 
hlist = tools.get(getlist)
print "\n =========== REBIN ================ \n" 
hmc = tools.add(hlist[0:-1])
hdata = hlist[-1]
newBins = tools.getRebinEdges(hdata, hmc, max_err=0.1)
print newBins
rebin_hlist = tools.rebin(hlist, newBins) #rebinned to var bin width
srebin_hlist = tools.scaleByBinWidth(rebin_hlist, newBins) # rebinned to var bin width and wide bins are scaled down
srebin_hlist[0].SetTitle('ZJets_MG');

print "\n =========== STACK AND RATIO ====== \n" 
tools.stackAndRatio(srebin_hlist, title='Drell_Yan_MC_AMC_vs_Madgraph', ytitleratio='AMC/MG', yrange=(1e3, 1e7))
# Normalize all of the backgrounds to the same scale
for i,h in enumerate(hlist):
    h.Scale(1/h.Integral())
    #h.SetName(bdt_categories[i])
    h.SetTitle(bdt_categories[i])
    if 'cAll' in h.GetName():
        h.SetTitle("Inclusive")
        inclusive = h

#print "\n =========== OVERLAY ================== \n"
#tools.overlay(hlist, title="Background Shapes", savename="compare_bkg_shapes", xtitle="dimu_mass", ytitle="Events / 0.2 GeV", 
#              ldim=[0.85, 0.4, 0.98, 0.98], draw='fill-transparent')

print "\n =========== STACKS ================== \n"
list_to_stack = []

for h in hlist:
    if 'cAll' in h.GetName():
        continue

    l = [h,inclusive]
    e = tools.getRebinEdges(h, inclusive, max_err=0.05)
    lrebin = tools.scaleByBinWidth(tools.rebin(l, e), e)
    tools.stackAndRatio(lrebin, log=False, name=h.GetTitle(), savename="bkg_shapes_stack_%s" % h.GetTitle(), title=h.GetTitle(), 
                        ytitleratio="%s/%s" % ("Inclusive",h.GetTitle()), errband="Error Band", ldim=[0.6, 0.55, 0.92, 0.92])

#for l in list_to_stack:
#    h = l[0]
#    tools.stackAndRatio(l, log=False, name=h.GetName(), savename="bkg_shapes_stack_%s" % h.GetName(), title=h.GetName(), 
#                        ytitleratio="%s/%s" % (h.GetName(), 'inclusive'))
        for key, value in in_unc_map.iteritems():
            value.append((filename, 'net_histos/%s_%s_%s' % (c, s, key)))

    # list of histograms to make the stack and ratio plots for this category
    hlist = tools.get(in_list)

    # map to lists of up/down uncertainty histograms for this category
    # 'JES_up' -> list of JES_up histos for this category
    for in_key, in_value in in_unc_map.iteritems():
        unc_hist_map[in_key] = tools.get(in_value)

    #hmc = tools.add(hlist[0:-1])
    #hdata = hlist[-1]
    #newBins = tools.getRebinEdges(hdata, hmc, max_err=0.05)
    #print newBins
    #rebin_hlist = tools.rebin(hlist, newBins) #rebinned to var bin width
    #srebin_hlist = tools.scaleByBinWidth(rebin_hlist, newBins) # rebinned to var bin width and wide bins are scaled down

    print "\n =========== STACK AND RATIO ====== \n"

    tools.stackAndRatio(hlist,
                        unc_map=unc_hist_map,
                        savename=varname + '_%s' % c,
                        title=('%s ' + vartitle) % c,
                        ldim=[0.6, 0.55, 0.92, 0.92],
                        xtitle=vartitle + units)
    #tools.stackAndRatio(srebin_hlist, savename=varname+'_%s' % c, title=('%s '+ vartitle) % c, ldim=[0.6, 0.55, 0.92, 0.92], xtitle=vartitle+units)
    #tdrstyle.cmsPrel(35900, 13, False, onLeft=True)
    c = TCanvas()
gg_h125.SetTitle("GGF_M125");
gg_h120.SetTitle("GGF_M120");
gg_h130.SetTitle("GGF_M130");

gg_l120 = [gg_h120, gg_h125]
gg_l130 = [gg_h130, gg_h125]

# -- vbf -----------------------
vbf_h125 = vbf_hlist[0]
vbf_h120 = vbf_hlist[1]
vbf_h130 = vbf_hlist[2]

vbf_h125.SetTitle("VBF_M125");
vbf_h120.SetTitle("VBF_M120");
vbf_h130.SetTitle("VBF_M130");

vbf_l120 = [vbf_h120, vbf_h125]
vbf_l130 = [vbf_h130, vbf_h125]

print "\n =========== STACK AND RATIO ====== \n" 
tools.stackAndRatio(gg_l120, title='BDT_Score_GGF_M125_vs_M120', ytitleratio='M125/M120', log=False, yrange=(0,0.06), xtitle="bdt_score", 
                    ldim=[0.23, 0.65, 0.55, 0.83])
tools.stackAndRatio(gg_l130, title='BDT_Score_GGF_M125_vs_M130', ytitleratio='M125/M130', log=False, yrange=(0,0.06), xtitle="bdt_score",
                    ldim=[0.23, 0.65, 0.55, 0.83])
tools.stackAndRatio(vbf_l120, title='BDT_Score_VBF_M125_vs_M120', ytitleratio='M125/M120', log=False, yrange=(0,0.08), xtitle="bdt_score", 
                    ldim=[0.23, 0.65, 0.55, 0.83])
tools.stackAndRatio(vbf_l130, title='BDT_Score_VBF_M125_vs_M130', ytitleratio='M125/M130', log=False, yrange=(0,0.08), xtitle="bdt_score",
                    ldim=[0.23, 0.65, 0.55, 0.83])

#
#print '{:<15}'.format('category') + '{:<15}'.format('mean_roch') + '{:<15}'.format('mean_kamu') + '{:<15}'.format('sigma_roch') + '{:<15}'.format('sigma_kamu')
#for i in range(0,len(vbf_ratios)):
#    print ('{:<15}'.format(categories[i]) + '{:<15.2f}'.format(vbf_mean_roch[i]) + '{:<15.2f}'.format(vbf_mean_kamu[i]) +
#          '{:<15.2f}'.format(vbf_sigma_roch[i]) + '{:<15.2f}'.format(vbf_sigma_kamu[i]) )

print "\n =========== REBIN and RATIO ================ \n"

for i in range(0, len(roch_plots)):
    hroch = roch_plots[i]
    hkamu = kamu_plots[i]
    hroch.SetName(hroch.GetName() + "_Roch")
    hroch.SetTitle(hroch.GetTitle() + "_Roch")
    hkamu.SetName(hkamu.GetName() + "_KaMu")
    hkamu.SetTitle(hkamu.GetTitle() + "_KaMu")
    print "\n  /// %d /// Stack and Ratio for %s, %s" % (i, hroch.GetName(),
                                                         hkamu.GetName())
    hlist = [hkamu, hroch]
    #newBins = tools.getRebinEdges(hroch, hkamu, max_err=0.1)
    newBins = np.linspace(110, 160, 50)
    #print newBins
    rebin_hlist = tools.rebin(hlist, newBins)
    hroch = rebin_hlist[1]
    hkamu = rebin_hlist[0]
    tools.stackAndRatio(rebin_hlist,
                        title=hroch.GetName() + "_vs_KaMu",
                        ytitleratio='Roch/KaMu',
                        log=False,
                        yrange=(0, hroch.GetMaximum() * 1.15),
                        yrange_ratio=(0.85, 1.15))