Exemple #1
0
def produceNormalizedPlots(processes, selections, variables, colors, intLumi, pdir, lt, rt, log, hfile):
    
    print ''
    print 'Preparing normalized plots ...'

    gROOT.SetBatch(True)

    intLumiab = intLumi/1e+06 

    yl = "Normalized Event Rate"

    ff = "eps"

    logstr = ''
    if log:
       logstr = 'log'
    else:
       logstr = 'lin'
    
    stackstr = ''

    hfile.cd()

    nsel = 0
    for s in selections:
        selstr = 'sel{}'.format(int(nsel))
        nsel += 1
        for v, dic in variables.iteritems() :
             histos = []
             i = 0

             filename = '{}_{}_{}'.format(v, selstr, logstr)
             
             leg = TLegend(0.60,0.65,0.90,0.88)
             leg.SetFillColor(0)
             leg.SetFillStyle(0)
             leg.SetLineColor(0)
             leg.SetShadowColor(10)
             leg.SetTextSize(0.035)
             leg.SetTextFont(42)


             cols = []
             for p in processes:
                 hname = '{}_{}_{}'.format(p, selstr, v)
                 h = hfile.Get(hname)
                 hh = TH1D.Clone(h)

                 # rebin if needed
                 hh.Rebin(int(hh.GetNbinsX()/dic['bin']))

                 if hh.Integral(0, hh.GetNbinsX()+1) > 0:
                     hh.Scale(1./hh.Integral(0, hh.GetNbinsX()+1))
                 histos.append(hh)
                 cols.append(colors[p])
                 leg.AddEntry(hh,p,"l")
                 i+=1
             drawNormalized(filename, yl, leg, lt, rt, ff, pdir, log, histos, cols)

    print 'DONE.'
Exemple #2
0
def produceStackedPlots(processes, selections, variables, colors, intLumi, pdir, delphesVersion, log, stacksig, hfile):
    
    print ''
    print 'Preparing distribution plots ...'

    myStyle()
    gROOT.SetBatch(True)

    intLumiab = intLumi/1e+06 

    yl = "Events"
    rt = "RECO: Delphes-{}".format(delphesVersion)
    lt = "#sqrt{{s}} = 100 TeV, L = {} ab^{{-1}}".format(intLumiab)

    ff = "png"

    logstr = ''
    if log:
       logstr = 'log'
    else:
       logstr = 'lin'
    
    stackstr = ''
    if stacksig:
       stackstr = 'stack'
    else:
       stackstr = 'nostack'

    hfile.cd()

    nsel = 0
    for s in selections:
        selstr = 'sel{}'.format(int(nsel))
        nsel += 1
        for v in variables.keys() :
             histos = []
             i = 0

             filename = '{}_{}_{}_{}'.format(v, selstr, stackstr, logstr)

             leg = TLegend(0.70,0.65,0.95,0.88)
             leg.SetFillColor(0)
             leg.SetFillStyle(0)
             leg.SetLineColor(0)

             cols = []
             for p in processes:
                 hname = '{}_{}_{}'.format(p, selstr, v)
                 h = hfile.Get(hname)
                 hh = TH1D.Clone(h)
                 hh.Scale(intLumi)
                 histos.append(hh)
                 cols.append(colors[p])
                 if i > 0: 
                     leg.AddEntry(hh,p,"f")
                 else: 
                     leg.AddEntry(hh,p,"l")
                 i+=1
             drawStack(filename, yl, leg, lt, rt, ff, pdir, log, stacksig, histos, cols)
    print 'DONE.'
Exemple #3
0
def produceNormalizedPlots(processes, selections, variables, colors, intLumi,
                           pdir, delphesVersion, log, hfile):

    print ''
    print 'Preparing normalized plots ...'

    myStyle()
    gROOT.SetBatch(True)

    intLumiab = intLumi / 1e+06

    yl = "Normalized Event Rate"
    rt = "RECO: Delphes-{}".format(delphesVersion)
    lt = "#sqrt{{s}} = 100 TeV, L = {} ab^{{-1}}".format(intLumiab)

    ff = "png"

    logstr = ''
    if log:
        logstr = 'log'
    else:
        logstr = 'lin'

    stackstr = ''

    hfile.cd()

    nsel = 0
    for s in selections:
        selstr = 'sel{}'.format(int(nsel))
        nsel += 1
        for v in variables.keys():
            histos = []
            i = 0

            filename = '{}_{}_{}'.format(v, selstr, logstr)

            leg = TLegend(0.60, 0.65, 0.90, 0.88)
            leg.SetFillColor(0)
            leg.SetFillStyle(0)
            leg.SetLineColor(0)

            cols = []
            for p in processes:
                hname = '{}_{}_{}'.format(p, selstr, v)
                h = hfile.Get(hname)
                hh = TH1D.Clone(h)
                if hh.Integral(0, hh.GetNbinsX() + 1) > 0:
                    hh.Scale(1. / hh.Integral(0, hh.GetNbinsX() + 1))
                histos.append(hh)
                cols.append(colors[p])
                leg.AddEntry(hh, p, "l")
                i += 1
            drawNormalized(filename, yl, leg, lt, rt, ff, pdir, log, histos,
                           cols)

    print 'DONE.'
graphs = {}
dymva = [
    0.05, 0.2, 0.4, 0.6, 0.75, 0.825, 0.875, 0.9125, 0.9375, 0.9625, 0.9875
]
e_dymva = [
    0.05, 0.1, 0.1, 0.1, 0.05, 0.025, 0.025, 0.0125, 0.0125, 0.0125, 0.0125
]

#loading DY histograms
for dirs in thelist:
    histos['DY_' + dirs.GetName()] = thefile.Get(dirs.GetName() +
                                                 '/dymva_alt_dnn_0j/histo_DY')
    histos['DATA_' +
           dirs.GetName()] = thefile.Get(dirs.GetName() +
                                         '/dymva_alt_dnn_0j/histo_DATA')
    histos['DYDATA_' + dirs.GetName()] = TH1D.Clone(histos['DATA_' +
                                                           dirs.GetName()])
    histos['AMC_' + dirs.GetName()] = TH1D.Clone(histos['DY_' +
                                                        dirs.GetName()])
    histos['VV_' + dirs.GetName()] = TH1D(
        'VV_' + dirs.GetName(), 'VV_' + dirs.GetName(),
        histos['DY_' + dirs.GetName()].GetNbinsX(),
        histos['DY_' + dirs.GetName()].GetXaxis().GetXbins().GetArray())

    # CREATING k histograms
    if 'in' in dirs.GetName(
    ) and not 'btag' in dirs.GetName() and not 'df' in dirs.GetName(
    ) and not 'H_' in dirs.GetName() and not 'ww_' in dirs.GetName(
    ) and not '1j' in dirs.GetName() and not '2j' in dirs.GetName(
    ) and not 'VBF' in dirs.GetName() and not 'VH' in dirs.GetName():
        #print('Histos for K and R: ', dirs.GetName())
        histos['k_MC_' + dirs.GetName()] = TH1D(
        K_ff[iRAndKff][iRegion]['val'] = DYCalc.k_MC(RAndKff[iRAndKff]['KffFile'],RAndKff[iRAndKff]['Regions'][iRegion]['kNum'],RAndKff[iRAndKff]['Regions'][iRegion]['kDen'])
        K_ff[iRAndKff][iRegion]['err'] = DYCalc.Ek_MC(RAndKff[iRAndKff]['KffFile'],RAndKff[iRAndKff]['Regions'][iRegion]['kNum'],RAndKff[iRAndKff]['Regions'][iRegion]['kDen'])
        #R{out/in}
        Rinout[iRAndKff][iRegion] = {}
        DataR[iRAndKff][iRegion]  = {}
        print 'file = ', RAndKff[iRAndKff]['RFile']
        Rfile[iRAndKff] = TFile(RAndKff[iRAndKff]['RFile'])
        thelist[iRAndKff] = Rfile[iRAndKff].GetListOfKeys()
        for dirs in thelist[iRAndKff] :
          if RAndKff[iRAndKff]['Regions'][iRegion]['RNum'] in dirs.GetName():
            currentdir = dirs.ReadObj()
            for subdir in currentdir.GetListOfKeys():
              if subdir.GetName()!='events':
                continue
              DataR[iRAndKff][iRegion]['NumDATA'] = Rfile[iRAndKff].Get(dirs.GetName()+'/'+subdir.GetName()+'/histo_DATA')
              DataR[iRAndKff][iRegion]['RNum'] = TH1D.Clone(DataR[iRAndKff][iRegion]['NumDATA'])
              currentsubdir = subdir.ReadObj()
              previoussample=''
              for sample in currentsubdir.GetListOfKeys():
                if sample.GetName()==previoussample:
                  continue
                previoussample = sample.GetName()
                if not 'histo_DY' in sample.GetName() and not 'histo_DATA' in sample.GetName():
                  DataR[iRAndKff][iRegion][sample.GetName()]= Rfile[iRAndKff].Get(dirs.GetName()+'/'+subdir.GetName()+'/'+sample.GetName())
                  DataR[iRAndKff][iRegion]['RNum'].Add(DataR[iRAndKff][iRegion][sample.GetName()],-1)

          if RAndKff[iRAndKff]['Regions'][iRegion]['RDen'] in dirs.GetName():
            currentdir = dirs.ReadObj()
            currentdir = dirs.ReadObj()
            for subdir in currentdir.GetListOfKeys():
              if subdir.GetName()!='events':
Exemple #6
0
def produceStackedPlots(processes, selections, variables, colors, intLumi, pdir, lt, rt, log, stacksig, hfile, ana_tex):
    
    print ''
    print 'Preparing stacked plots ...'

    gROOT.SetBatch(True)

    intLumiab = intLumi/1e+06 

    yl = "events"

    ff = "eps"

    logstr = ''
    if log:
       logstr = 'log'
    else:
       logstr = 'lin'
    
    stackstr = ''
    if stacksig:
       stackstr = 'stack'
    else:
       stackstr = 'nostack'

    hfile.cd()

    nsel = 0
    
    legsize = 0.04*float(len(processes))
    
    for s in selections:
        selstr = 'sel{}'.format(int(nsel))
        nsel += 1
        for v, dic in variables.iteritems() :
             histos = []
             i = 0

             filename = '{}_{}_{}_{}'.format(v, selstr, stackstr, logstr)

             leg = TLegend(0.58,0.86 - legsize,0.86,0.88)
             leg.SetFillColor(0)
             leg.SetFillStyle(0)
             leg.SetLineColor(0)
             leg.SetShadowColor(10)
             leg.SetTextSize(0.035)
             leg.SetTextFont(42)


             cols = []
             for p in processes:
                 hname = '{}_{}_{}'.format(p, selstr, v)
                 h = hfile.Get(hname)
                 hh = TH1D.Clone(h)
                 hh.Scale(intLumi)
                 
                 # rebin if needed
                 hh.Rebin(int(hh.GetNbinsX()/dic['bin']))

                 histos.append(hh)
                 cols.append(colors[p])
                 # fix names if needed
                 leg_name = p
                 if p.find('m_{Z}')>=0   : leg_name = p.replace('m_{Z}',  'm_{Z\'}'   )
                 if p.find('m_{RSG}')>=0 : leg_name = p.replace('m_{RSG}','m_{G_{RS}}')
                 if p.find('vv')>=0 : leg_name = p.replace('vv','VV (V=Z/W)')
                 if p.find('vj')>=0 : leg_name = p.replace('vj','Vj (V=Z/W)')
                 if p.find('tt')>=0 : leg_name = p.replace('tt','t#bar{t}')
                 if p.find('Drell-Yan')>=0 and ana_tex.find("e^")>=0:   leg_name = p.replace('Drell-Yan','pp #rightarrow Z/#gamma* #rightarrow e^{+}e^{-}')
                 if p.find('Drell-Yan')>=0 and ana_tex.find("mu^")>=0:  leg_name = p.replace('Drell-Yan','pp #rightarrow Z/#gamma* #rightarrow #mu^{+}#mu^{-}')
                 if p.find('Drell-Yan')>=0 and ana_tex.find("tau^")>=0: leg_name = p.replace('Drell-Yan','pp #rightarrow Z/#gamma* #rightarrow #tau^{+}#tau^{-}')
                 if i > 0: 
                     leg.AddEntry(hh,leg_name,"f")
                 else: 
                     leg.AddEntry(hh,leg_name,"l")
                 i+=1
             drawStack(filename, yl, leg, lt, rt, ff, pdir, log, stacksig, histos, cols, ana_tex)
    print 'DONE.'
Exemple #7
0
def produceStackedPlots(processes, selections, variables, colors, intLumi,
                        pdir, lt, rt, log, stacksig, hfile):

    print ''
    print 'Preparing stacked plots ...'

    gROOT.SetBatch(True)

    intLumiab = intLumi / 1e+06

    yl = "events"

    ff = FORMAT

    logstr = ''
    if log:
        logstr = 'log'
    else:
        logstr = 'lin'

    stackstr = ''
    if stacksig:
        stackstr = 'stack'
    else:
        stackstr = 'nostack'

    hfile.cd()

    nsel = 0

    legsize = 0.04 * float(len(processes))

    for s in selections:
        selstr = 'sel{}'.format(int(nsel))
        nsel += 1
        for v, dic in variables.iteritems():
            histos = []
            i = 0

            filename = '{}_{}_{}_{}'.format(v, selstr, stackstr, logstr)

            leg = TLegend(0.60, 0.86 - legsize, 0.86, 0.88)
            leg.SetFillColor(0)
            leg.SetFillStyle(0)
            leg.SetLineColor(0)
            leg.SetShadowColor(10)
            leg.SetTextSize(0.035)
            leg.SetTextFont(42)

            cols = []
            for p in processes:
                hname = '{}_{}_{}'.format(p, selstr, v)
                h = hfile.Get(hname)
                hh = TH1D.Clone(h)
                hh.Scale(intLumi)

                # rebin if needed
                hh.Rebin(int(hh.GetNbinsX() / dic['bin']))

                histos.append(hh)
                cols.append(colors[p])
                if i > 0:
                    leg.AddEntry(hh, p, "f")
                else:
                    leg.AddEntry(hh, p, "l")
                i += 1

            drawStack(filename, yl, leg, lt, rt, ff, pdir, log, stacksig,
                      histos, cols, dic)

    print 'DONE.'
Exemple #8
0
def produceStackedHackedPlots(processes, selections, variables, colors,
                              intLumi, pdir, lt, rt, log, stacksig, hfile):

    print ''
    print 'Preparing stacked HACKED plots ...'

    gROOT.SetBatch(True)

    intLumiab = intLumi / 1e+06

    yl = "events"

    ff = FORMAT

    logstr = ''
    if log:
        logstr = 'log'
    else:
        logstr = 'lin'

    stackstr = ''
    if stacksig:
        stackstr = 'stack'
    else:
        stackstr = 'nostack'

    hfile.cd()

    nsel = 0

    legsize = 0.04 * float(len(processes))

    for s in selections:
        selstr = 'sel{}'.format(int(nsel))
        nsel += 1
        for v, dic in variables.iteritems():
            histos = []
            i = 0

            filename = '{}_{}_{}_{}'.format(v, selstr, stackstr, logstr)

            leg = TLegend(0.60, 0.86 - legsize, 0.86, 0.88)
            leg.SetFillColor(0)
            leg.SetFillStyle(0)
            leg.SetLineColor(0)
            leg.SetShadowColor(10)
            leg.SetTextSize(0.035)
            leg.SetTextFont(42)

            cols = []
            for p in processes:
                hname = '{}_{}_{}'.format(p, selstr, v)
                h = hfile.Get(hname)
                hh = TH1D.Clone(h)
                hh.Scale(intLumi)

                if p == 'HH(#kappa_{#lambda}=1.00)':
                    print 'here'
                    hh.Scale(20)

                r = ROOT.TRandom3(5)

                import math
                '''
                 if '#gamma#gamma + Jets' in p and 'haa_m' in filename and 'sel0' in filename:
                    
                    mean = 0
                    for bin in xrange(1, hh.GetNbinsX()+1):
                       #print '#gamma#gamma + Jets' , hh.GetBinContent(bin)
                       
                       mean += hh.GetBinContent(bin)
                       #hh.SetBinContent(bin,r.Poisson(1750))
                       #hh.SetBinContent(bin,r.Gaus(1000, 0.75*math.sqrt(1000)))
                 
                    mean = mean/hh.GetNbinsX()
                    for bin in xrange(1, hh.GetNbinsX()+1):
                       #hh.SetBinContent(bin,r.Gaus(mean, 0.75*math.sqrt(mean)))
                       hh.SetBinContent(bin,r.Gaus(hh.GetBinContent(bin), 0.99*math.sqrt(mean)))

                 if 'j#gamma + Jets' in p and 'haa_m' in hname and 'sel0' in filename:
                    mean = 0
                    for bin in xrange(1,hh.GetNbinsX()+1):
                       #print 'j#gamma + Jets', hh.GetBinContent(bin)
                       mean += hh.GetBinContent(bin)
                       #hh.SetBinContent(bin,r.Poisson(1000))
                       #hh.SetBinContent(bin,r.Gaus(700, 0.75*math.sqrt(700)))
                    
                    mean = mean/hh.GetNbinsX()
                    for bin in xrange(1, hh.GetNbinsX()+1):
                       #hh.SetBinContent(bin,r.Gaus(mean, 0.75*math.sqrt(mean)))
                       hh.SetBinContent(bin,r.Gaus(hh.GetBinContent(bin), 0.99*math.sqrt(mean)))
                 '''

                print p, hname
                '''
                 #hh.Smooth(1)
                 for bin in xrange(1, hh.GetNbinsX()+1):
                    #print '#gamma#gamma + Jets' , hh.GetBinContent(bin)
                    binc = hh.GetBinContent(bin)
                    hh.SetBinContent(bin,r.Poisson(binc))
                 '''

                if 'j#gamma + Jets' in p and 'sel0' in filename and 'haa_m' in hname:

                    href = hfile.Get('#gamma#gamma + Jets_sel0_haa_m')
                    href2 = TH1D.Clone(href)
                    href2.Scale(intLumi)
                    #href2.Smooth(1)

                    for bin in xrange(1, hh.GetNbinsX() + 1):
                        #print '#gamma#gamma + Jets' , hh.GetBinContent(bin)
                        binc = 1.2 * href2.GetBinContent(bin)
                        hh.SetBinContent(bin, r.Poisson(binc))
                '''
		 if 'j#gamma + Jets' in p and 'sel0' in filename and 'hbb_m' in hname:
                     
                     href = hfile.Get('#gamma#gamma + Jets_sel0_hbb_m')
                     href2 = TH1D.Clone(href)
                     href2.Scale(intLumi)
                     #href2.Smooth(1)
                    
                     for bin in xrange(1, hh.GetNbinsX()+1):
                        #print '#gamma#gamma + Jets' , hh.GetBinContent(bin)
                        binc = 1.2*href2.GetBinContent(bin)
                        hh.SetBinContent(bin,r.Poisson(binc))
                 '''

                ## for bbtahtah final state
                if 'top pair' in p and 'sel0' in filename and 'bdt' in hname:
                    for bin in xrange(1, hh.GetNbinsX() + 1):
                        print 'top', bin, hh.GetBinContent(bin)
                        if bin == 47: hh.SetBinContent(bin, 300000.)
                '''
		 ## for bbtahtal final state
		 if 'top pair' in p and 'sel0' in filename and 'bdt' in hname:
                     for bin in xrange(1, hh.GetNbinsX()+1):
                        print 'top', bin , hh.GetBinContent(bin)
                        if bin == 44: hh.SetBinContent(bin,2500000.)
                        if bin == 46: hh.SetBinContent(bin,1500000.)
                        if bin == 47: hh.SetBinContent(bin,1200000.)
                        if bin == 49: hh.SetBinContent(bin,600000.)
                        if bin == 50: hh.SetBinContent(bin,450000.)
                 '''
                '''
		 ## for bbbb final state
		 if 'QCD' in p and 'sel0' in filename and 'bdt' in hname:

                     for bin in xrange(1, hh.GetNbinsX()+1):
                        print 'qcd', bin , hh.GetBinContent(bin)
                        if bin == 47: hh.SetBinContent(bin,220000000.)
                        if bin == 47: hh.SetBinContent(bin,150000000.)
                        if bin == 48: hh.SetBinContent(bin,110000000.)
                        if bin == 49: hh.SetBinContent(bin,75000000.)
                        if bin == 50: hh.SetBinContent(bin,50000000.)
			
			
                 '''
                # rebin if needed
                #if bin == 47: hh.SetBinContent(bin,450000.)

                hh.Rebin(int(hh.GetNbinsX() / dic['bin']))

                histos.append(hh)
                cols.append(colors[p])
                if i > 0:
                    leg.AddEntry(hh, p, "f")
                else:
                    #leg.AddEntry(hh,p+ ' x20',"l")
                    leg.AddEntry(hh, p, "l")

                i += 1

            drawStack(filename, yl, leg, lt, rt, ff, pdir, log, stacksig,
                      histos, cols, dic)

    print 'DONE.'
        print 'K file = ', RAndKff[iRAndKff]['KffFile']
        Kfile[iRAndKff]   = TFile(RAndKff[iRAndKff]['KffFile'])
        thelist[iRAndKff] = Kfile[iRAndKff].GetListOfKeys()

        # Prepare numerator and denominator for K computation
        for dirs in thelist[iRAndKff] :
          # K numerator
          if RAndKff[iRAndKff]['Regions'][iRegion]['kNum'] in dirs.GetName():
            currentdir = dirs.ReadObj()
            for subdir in currentdir.GetListOfKeys():
              if subdir.GetName()!='events':
                continue
              # Numerator: starting with total data in the actual channel (ee or mm)
              K_ff_data[iRAndKff][iRegion]['NumDATA'] = Kfile[iRAndKff].Get(dirs.GetName()+'/'+subdir.GetName()+'/histo_DATA')
              K_ff_data[iRAndKff][iRegion]['kNum']    = TH1D.Clone(K_ff_data[iRAndKff][iRegion]['NumDATA'])
              print("Total data = {}".format(K_ff_data[iRAndKff][iRegion]['kNum'].Integral()))
              currentsubdir = subdir.ReadObj()
              previoussample=''
              for sample in currentsubdir.GetListOfKeys():
                if sample.GetName()==previoussample:
                  continue
                previoussample = sample.GetName()
                # Numerator: subtract backgrounds
                if not 'histo_DY' in sample.GetName() and not 'histo_DATA' in sample.GetName():
                  K_ff_data[iRAndKff][iRegion][sample.GetName()] = Kfile[iRAndKff].Get(dirs.GetName()+'/'+subdir.GetName()+'/'+sample.GetName())
                  K_ff_data[iRAndKff][iRegion]['kNum'].Add(K_ff_data[iRAndKff][iRegion][sample.GetName()],-1)

          # K denominator
          if RAndKff[iRAndKff]['Regions'][iRegion]['kDen'] in dirs.GetName():
            currentdir = dirs.ReadObj()
Exemple #10
0
                    if not "histo_DY" in process.GetName(
                    ) and not "histo_DATA" in process.GetName():
                        # Subtract from Data non-DY MC
                        print(process.GetName())
                        h_tmp = my_file.Get(cut + "/" + variable + "/" +
                                            process.GetName())
                        h_Data.Add(h_tmp, -1)
                print("Data integral after MC subtraction: {}".format(
                    h_Data.Integral()))

                # Get DY MC histogram
                h_DY = my_file.Get(cut + "/" + variable + "/histo_DY")
                print("DY MC integral: {}".format(h_DY.Integral()))

                # Prepare Data/MC histogram ratio
                h_Ratio = TH1D.Clone(h_Data)
                h_Ratio.Divide(h_DY)
                print("Ratio integral: {}".format(h_Ratio.Integral()))
                h_Ratio.Draw()

                # Define Fit range
                x_min = h_Ratio.GetXaxis().GetXmin()
                x_max = h_Ratio.GetXaxis().GetXmax()

                # Fit
                h_Ratio.Fit(fit_func, "", "", x_min, x_max)

                # Fit result
                fit_result = h_Ratio.FindObject(fit_func)

                # Fitting parameters