def main():
    #get the list of bg and data files from the unusal config
    sampleinfos, basedir = getSampleInfo("201705_mergedext.config")
    lumi = sampleinfos.values()[-1]["lumi"]
    useRoot = False

    #we will use the same colors as the .c plotter for now
    colors = [100, 90, 80, 70, 60, 95, 85, 75, 65, 55]
    #reverse order and change to RGB
    colors = [getRGBTColor(i) for i in colors[::-1]]

    #make storage containers for the bgs and data
    bghists = HistStorage(xs=sampleinfos,
                          xstype="BSM3G",
                          lumi=lumi,
                          path=basedir,
                          useRoot=useRoot)
    dat_hist = HistStorage(path=basedir, isData=True, useRoot=useRoot)

    #make some lists that we will put into the containers
    colorList = {}
    bglist = OrderedDict()

    #the idea is to have a readable dict:

    bglist['DY+Jets'] = [
        'DYJetsToLL_M-50_HT-70To100',
        'DYJetsToLL_M-50_HT-600To800',
        'DYJetsToLL_M-50_HT-400To600',
        'DYJetsToLL_M-50_HT-800To1200',
        'DYJetsToLL_M-50_HT-1200To2500',
        'DYJetsToLL_M-50_HT-2500ToInf',
        'DYJetsToLL_M-50_HT-200To400',
        'DYJetsToLL_M-50_HT-0To70',
        'DYJetsToLL_M-50_HT-100To200',
    ]
    bglist['VV'] = [
        'ZZ_TuneCUETP8M1_13TeV',
        'WZ_TuneCUETP8M1_13TeV',
        'WW_TuneCUETP8M1_13TeV',
    ]
    bglist['SingleTop'] = [
        'ST_tW_antitop_5f_inclusiveDecays_13TeV',
        'ST_t-channel_top_4f_inclusiveDecays_13TeV',
        'ST_tW_top_5f_inclusiveDecays_13TeV',
        'ST_t-channel_antitop_4f_inclusiveDecays_13TeV',
    ]
    bglist['$\mathsf{t\bar{t}}$'] = [
        'TT_TuneCUETP8M2T4_13TeV',
    ]
    bglist['W+Jets'] = [
        'WJetsToLNu_HT-0To70',
    ]

    ##you can reverse the order
    bglist = OrderedDict(reversed(list(bglist.items())))

    #now actually add the backgrounds
    bghists.addFileList(bglist)
    bghists.colorList = colorList

    hists = [
        "NDiMuonCombinations/MHT",
        "NDiMuonCombinations/Meff",
    ]

    histContainer = HistStorageContainer(bg=bghists, data=dat_hist)
    #histContainer=HistStorageContainer(bg=bghists,sg=sghist,data=dat_hist)

    bghists.initStyle(style="bg")
    for hist in hists:
        #this is the magic line
        histContainer.getHist(hist)

        #now you can do what you want with the hists
        allbg = sum(histContainer.getBGList())
        allbg.Draw()
        for bg in histContainer.getBGList():
            bg.Draw("same")
        data = histContainer.getData()
        data.Draw("same p")
Exemplo n.º 2
0
def main():
    #get the list of bg and data files from the unusal config
    sampleinfos, basedir = getSampleInfo("201705_mergedext.config")
    lumi = sampleinfos.values()[-1]["lumi"]
    useRoot = False

    #we will use the same colors as the .c plotter for now
    colors = [100, 90, 80, 70, 60, 95, 85, 75, 65, 55]
    #reverse order and change to RGB
    colors = [getRGBTColor(i) for i in colors[::-1]]

    #make storage containers for the bgs and data
    bghists = HistStorage(xs=sampleinfos,
                          xstype="BSM3G",
                          lumi=lumi,
                          path=basedir,
                          useRoot=useRoot)
    dat_hist = HistStorage(path=basedir, isData=True, useRoot=useRoot)

    #make some lists that we will put into the containers
    colorList = {}
    bglist = OrderedDict()
    for sample in sampleinfos:
        info = sampleinfos[sample]
        sample = sample.replace(".root", "")
        if info["type"] == "bg":
            shortName = info["output"].replace(".root", "")
            if "#" in shortName:
                shortName = "$\mathsf{" + shortName.replace("#", "\\") + "}$"
            if shortName not in bglist:
                bglist[shortName] = [sample]
                colorList[shortName] = colors.pop()
            else:
                bglist[shortName].append(sample)
        #for data directly add the file
        if info["type"] == "data":
            dat_hist.addFile(sample)
    for bg in bglist:
        print("bglist['%s']=[" % (bg))
        for ibg in bglist[bg]:
            print("'ibg',")
        print("]")

    #now actually add the backgrounds
    bghists.addFileList(bglist)
    bghists.colorList = colorList

    hists = [
        "NDiMuonCombinations/MHT",
        "NDiMuonCombinations/Meff",
    ]

    histContainer = HistStorageContainer(bg=bghists, data=dat_hist)
    #histContainer=HistStorageContainer(bg=bghists,sg=sghist,data=dat_hist)

    binning = {
        "_pt": 25,
        "_mt": 25,
        "_met": 25,
        "MC_W_m_Gen": 10,
        "_jet_ht": 10,
    }

    xranges = {
        "_pt": [0, 1000],
        "_jet_ht": [0, 1600],
        "_mt": [150, 1600],
        "boson_qt": [0, 600],
        "_met": [0, 1300],
        "_ET_MET": [0, 4],
        "_DeltaPhi": [0.2, math.pi],
        "MC_W_m_Gen": [0, 1300],
        "relIso": [0, 0.05],
    }
    yranges = {
        "_ET_MET": [1.01e-3, 1e8],
        "_DeltaPhi": [1.01e-3, 1e8],
    }

    bghists.initStyle(style="bg")
    #sghist.initStyle(style="sg")
    for hist in hists:

        ##use different out dirs
        dir_name = "test"
        if not os.path.exists(dir_name):
            os.mkdir(dir_name)

        if "prof" in hist:
            hist_style = sc.style_container(kind="Lines",
                                            style='CMS',
                                            useRoot=useRoot,
                                            cmsPositon="upper left",
                                            lumi=lumi,
                                            cms=13)
        else:
            hist_style = sc.style_container(style='CMS',
                                            useRoot=useRoot,
                                            cmsPositon="upper left",
                                            lumi=lumi,
                                            cms=13)

        #change the style if you want
        #hist_style._error_bands_fcol=["grey","yellow"]
        #hist_style._error_bands_ecol=["lightgrey","yellow"]
        #hist_style._error_bands_alph=0.4
        #hist_style.Set_error_line_width(0.0000000001)
        hist_style.Set_poisson_error_off()
        #hist_style.Set_minor_ticks()
        #hist_style.Set_n_legend_columns(2)
        #hist_style.Set_xerr()
        #hist_style.Set_do_overflowbin()

        #get the actual histograms
        histContainer.getHist(hist)

        #programmable binning
        binf = getDictValue(hist, binning)
        if binf is not None:
            if isinstance(binf, list):
                histContainer.rebin(vector=binf)
            else:
                histContainer.rebin(width=binf)

        name = hist.replace("/", "")
        #test = plotter(hist=histContainer.getBGList(),data_hist=histContainer.getData(),data=True,style=hist_style)
        test = plotter(hist=histContainer.getBGList(), style=hist_style)
        test.Add_data(histContainer.getData())

        test.Add_plot('Ratio', pos=1, height=15)
        test.Add_plot('DiffRatio_width_increase', pos=2, height=15)
        mplt = test.create_plot()
        test.SavePlot('%s/%s.png' % (dir_name, name))
        test.SavePlot('%s/%s.pdf' % (dir_name, name))
Exemplo n.º 3
0
def main():

    basedir="/disk1/erdweg/out/output2015_2_13_15_47/merged//"
    lumi=1000

    xs= ConfigObj("/disk1/erdweg/plotting/xs_Phys14.cfg")
    bghists=HistStorage(xs,lumi,path=basedir)
    # bghists.setDataDriven("dataDrivenQCD")

    bglist=OrderedDict()

    bglist["PU20bx25"]=['ZprimeToTauTau_M-5000_PU20bx25_PHYS14',
     'ZprimeToTauTau_M-1000_PU20bx25_PHYS14',
    ]
    bglist["AVE30BX50"]=['ZprimeToTauTau_M-1000_AVE30BX50_PHYS14',
     'ZprimeToTauTau_M-5000_AVE30BX50_PHYS14',
     ]
    bglist["PU40bx25"]=['ZprimeToTauTau_M-1000_PU40bx25_PHYS14',
     'ZprimeToTauTau_M-5000_PU40bx25_PHYS14',
    ]

    colorList={}
    colorList["PU20bx25"]="lightblue"
    colorList["AVE30BX50"]="lightgreen"
    colorList["PU40bx25"]="darkmagenta"

    bghists.addFileList(bglist)

    dat_hist=HistStorage(xs,lumi,path=basedir,isData=True)
    # dat_hist.addFile("Data")

    hists=[#'Taus/h1_1_Tau_eta',
    #'Taus/h1_1_Tau_phi',
    #'Taus/h1_2_Tau_pt',
    #'Taus/h1_Tau_pt_resolution_0_500',
    'Eles/h1_Ele_pt_resolution_0_500',
    'Eles/h1_Ele_pt_resolution_500_1000',
    #'Eles/h1_2_Ele_pt',
    'Muons/h1_Muon_pt_resolution_0_500',
    'Muons/h1_Muon_pt_resolution_500_1000',
    #'Muons/h1_2_Muon_pt',
    #'emu/Stage_0/h1_0_emu_Mass',
    #'mutau/Stage_0/h1_0_mutau_Mass',
    #'mutau/Stage_6/h1_6_mutau_Mass',
    #'Ctr/h1_Ctr_Vtx_unweighted',
    #'Ctr/h1_Ctr_Vtx_weighted',
    #'Ctr/h1_Ctr_Vtx_emu_unweighted',
    #'Ctr/h1_Ctr_Vtx_emu_weighted',
    #'Ctr/h1_Ctr_HT',
    #'Ctr/h1_Ctr_pT_hat',
    #'emu/Stage_0/h1_0_emu_Mass_resolution',
    #'mutau/Stage_0/h1_0_mutau_Mass_resolution'
    ]

    sghist=HistStorage(xs,lumi,path=basedir)
    # sgName="$\mathsf{W' \, M=2.3\,TeV \cdot 0.02}$"
    # sghist.additionalWeight={"WprimeToTauNu_M-2300_TuneZ2star_8TeV-pythia6-tauola_Summer12_DR53X-PU_S10_START53_V7A-v1SIM":0.02}
    # sghist.addAllFiles(tag="WprimeToTauNu_M-2300",joinName=sgName)
    # sghist.colorList={sgName :"darkred"}

    histContainer=HistStorageContainer(sg=bghists,data=dat_hist,bg=sghist)

    binning={
            "Taus/h1_2_Tau_pt":10,
            # "emu/Stage_0/h1_0_emu_Mass":range(200,300,20)+range(300,400,50)+range(400,1600,100)+range(1600,2000,200),
            # "mutau/Stage_0/h1_0_mutau_Mass":range(200,300,20)+range(300,400,50)+range(400,1600,100)+range(1600,2000,200),
            # "mutau/Stage_6/h1_6_mutau_Mass":range(200,300,20)+range(300,400,50)+range(400,1600,100)+range(1600,2000,200),
            "_met_et":30,
    }

    xranges={
            "Taus/h1_2_Tau_pt":[0,2000],
            "emu/Stage_0/h1_0_emu_Mass":[0,2000],
            "mutau/Stage_0/h1_0_mutau_Mass":[0,2000],
            "mutau/Stage_6/h1_6_mutau_Mass":[0,2000],
            "emu/Stage_0/h1_0_emu_Mass_resolution":[-2,2],
            "mutau/Stage_0/h1_0_mutau_Mass_resolution":[-2,2],
            "Taus/h1_Tau_pt_resolution_0_500":[-2,2],
            "Eles/h1_Ele_pt_resolution_0_500":[-2,2],
            "Eles/h1_Ele_pt_resolution_500_1000":[-2,2],
            "Muons/h1_Muon_pt_resolution_0_500":[-2,2],
            "Muons/h1_Muon_pt_resolution_500_1000":[-2,2],
            "Ctr/h1_Ctr_Vtx_unweighted":[0,40],
            "Ctr/h1_Ctr_Vtx_weighted":[0,40],
            "Ctr/h1_Ctr_Vtx_emu_unweighted":[0,40],
            "Ctr/h1_Ctr_Vtx_emu_weighted":[0,40],
    }

    bghists.initStyle(style="sg",colors=colorList)
    # sghist.initStyle(style="sg")

    for hist in hists:
        print("Now plotting: " + hist)
        histContainer.getHist(hist)

        binf=getDictValue(hist,binning)
        if binf is not None:
            # dat_hist.rebin(width=binf)
            bghists.rebin(width=binf)
        bghists.colorList=colorList
        # bghists.setStyle(bgcolors=colorList)
        # dat_hist.getHistList()[0].SetTitle("data")

        hist_style = sc.style_container(style = 'CMS', useRoot = False,cms=13,lumi=19700)
        hist_style.Set_additional_text('plot dummy')

        test = plotter(sig=bghists.getHistList(),style=hist_style)
        # test.Add_data(dat_hist.getHistList()[0])
        # test.Add_plot('Signi',pos=0, height=15)

        #test.Add_plot('DiffRatio',pos=1, height=15)
        # test.Add_plot('Signi',pos=2, height=15)
        # test.Add_plot('Diff',pos=1, height=15)

        # test.Add_plot('Ratio',pos=2, height=15)
        #test.Add_error_hist([sys_hist_2,sys_hist], band_center = 'ref')

        test._cms_text_x         = 0.12
        test._cms_text_y         = 0.91
# 
        # mxrange=getDictValue(hist,xranges)
        if hist in xranges.keys():
            test.Set_axis(xmin=xranges[hist][0],xmax=xranges[hist][1],ymin=1e-3,ymax=1e3)

        name=hist.replace("/","")

        test.create_plot()

        plot_gauss_fit(test.Get_axis1(), bghists.getHistList()[0], xmin = -0.5, xmax = 0.5)

        # test.show_fig()

        test.SavePlot('plots/%s.pdf'%(name))
    return 42