def main(args):

    parser = argparse.ArgumentParser(description='usage: %prog [options]')
    parser.add_argument(
        '-i',
        '--input',
        dest='input',
        default=
        '/eos/cms/store/cmst3/user/psilva/ExclusiveAna/final/ab05162/analysis_0p04/',
        help='input directory with the files [default: %default]')
    parser.add_argument(
        '--selCuts',
        dest='selCuts',
        default='bosonpt>40 && l1pt>30 && l2pt>20',
        help='preselection for Z categories [default: %default]')
    parser.add_argument('--doPerNch',
                        dest='doPerNch',
                        default=False,
                        action='store_true',
                        help='break-down per Nch [default: %default]')
    parser.add_argument('--doPerEra',
                        dest='doPerEra',
                        default=False,
                        action='store_true',
                        help='break-down per era [default: %default]')
    parser.add_argument(
        '--doPerPU',
        dest='doPerPU',
        default=False,
        action='store_true',
        help='break-down per pileup category [default: %default]')
    parser.add_argument('--doPerAngle',
                        dest='doPerAngle',
                        default=False,
                        action='store_true',
                        help='break-down per angle [default: %default]')
    parser.add_argument('--lumi',
                        dest='lumi',
                        default=37500.,
                        type=float,
                        help='integrated luminosity [default: %default]')
    parser.add_argument('-o',
                        '--output',
                        dest='output',
                        default='analysis/bkg',
                        help='Output directory [default: %default]')
    opt = parser.parse_args(args)

    ROOT.gROOT.SetBatch(True)
    ROOT.gStyle.SetOptTitle(0)
    ROOT.gStyle.SetOptStat(0)

    os.system('mkdir -p %s' % opt.output)

    #do all possible combinations of these categories
    baseCats = ['protonCat==%d' % (i + 1) for i in range(4)]
    subCats = ['']
    if opt.doPerEra: subCats += ['era==%d' % int(ord(x)) for x in 'BCDEF']
    if opt.doPerPU: subCats += ['nvtx<20', 'nvtx>=20']
    if opt.doPerAngle:
        subCats += ['xangle==%d' % i for i in [120, 130, 140, 150]]
    if opt.doPerNch: subCats += ['nch<15', 'nch>=15']
    catList = list(itertools.product(baseCats, subCats))

    outF = '%s/plotter_embkg.root' % opt.output
    os.system('rm %s' % outF)

    print '[doBackgroundValidation] with %d variations to test' % len(catList)
    print '\t output will be available in', outF
    for i, cat in enumerate(catList):

        selCut = ''
        for c in cat:
            if len(c) == 0: continue
            selCut += '%s&&' % c
        selCut += opt.selCuts
        titleCut = parseTitleFromCut(selCut)
        print '\t', i, selCut

        data = fillShapes(inputDir=opt.input, selCuts=selCut, proc='MuonEG')

        for dist in data:

            pname = '%s_%d' % (dist, i)
            for c in [':', ',', '>', '=', '(', ')', '-', '<', '?']:
                pname = pname.replace(c, '')
            p = Plot(pname)
            p.doChi2 = False  #True
            p.nominalDistForSystsName = 'background'

            #if dist=='mmiss':
            #    newBins=range(0,1000,40)+[1000,1100,1200,1500,2000]
            #    print 'Rebinning',dist,'to',newBins
            #    for k in data[dist]:
            #        data[dist][k]=rebinUnequalBinSize(data[dist][k],newBins)

            p.add(data[dist]['data'],
                  title='data',
                  color=ROOT.kBlack,
                  isData=True,
                  spImpose=False,
                  isSyst=False)
            p.add(data[dist]['bkg'],
                  title='background',
                  color=ROOT.kCyan - 6,
                  isData=False,
                  spImpose=False,
                  isSyst=False)

            #background systematics
            ci = 1
            for syst in [
                    '{0}_bkgshape_MuonEG_obsUp',
                    '{0}_bkgshape_MuonEG_obsDown',
                    '{0}_bkgsinglediffUp_MuonEG_obs',
                    '{0}_bkgsinglediffDown_MuonEG_obs',
            ]:
                ci = ci + 1
                p.add(
                    data[dist][syst.format(dist)],
                    title=syst,
                    color=ROOT.kCyan - 6,  #ci
                    isData=False,
                    spImpose=False,  #True,
                    isSyst=True)  #False)

            #p.ratiorange=[0.78,1.22]
            p.ratiorange = [0.58, 1.43]
            p.show(opt.output, opt.lumi, extraText='\\'.join(titleCut))
            p.appendTo(outF)
            p.reset()
Beispiel #2
0
    plot.savelog = True
    plot.wideCanvas = False
    plot.doMCOverData = False
    plot.ratioFrameFill = 3444
    plot.ratioFrameColor = 1
    #plot.ratiorange=(0.655,1.385)
    doDivideByBinWidth = False
    if 'mlb' in outpName or 'ptlb' in outpName: doDivideByBinWidth = True
    if relShapeGr: plot.relShapeGr = relShapeGr
    plot.plotformats = ['root', 'pdf', 'png']
    for key in ['Data', 't#bar{t}', 'Single top', 'W', 'DY', 'Multiboson']:
        if not key in plotsPerProc: continue
        isData = True if 'Data' in plotsPerProc[key].GetTitle() else False
        color = COLORS[plotsPerProc[key].GetTitle()]
        if key == 'DY': plotsPerProc[key].Scale(0.83)
        plot.add(plotsPerProc[key], plotsPerProc[key].GetTitle(), color,
                 isData, False, False, doDivideByBinWidth)
    plot.finalize()
    plot.mcUnc = 0.0

    totalMC = sigH.Clone('tmptotal')
    totalMC.Reset('ICE')
    for h in plot.mc:
        totalMC.Add(plot.mc[h])
    plot.normUncGr = ROOT.TGraphErrors(totalMC)
    plot.normUncGr.SetFillStyle(3444)
    plot.normUncGr.SetFillColor(1)
    plot.normUncGr.SetMarkerStyle(1)
    plot.normUncGr.SetLineColor(1)
    plot.normUncGr.SetName("normuncgr")
    plot.normUncGr.SetTitle('Stat #oplus norm')
    totalMC.Delete()
Beispiel #3
0
xangle=120

ROOT.gROOT.SetBatch(True)
ROOT.gStyle.SetOptStat(0)
ROOT.gStyle.SetOptTitle(0)
ROOT.gStyle.SetPaintTextFormat("4.2f");


for ppsEffFile in ['PreliminaryEfficiencies_October92019_1D2DMultiTrack.root', #'pixelEfficiencies.root'
               ]:
    ppsEffReader=PPSEfficiencyReader(os.path.join(baseDir,ppsEffFile))

    for rp in [23,123]:

        
        p=Plot('raddameff_%d'%rp,com='13 TeV')
        p.range=[0,1]
        p.xtit='#xi'
        p.ytit='Efficiency'
        for i,era in enumerate(['B','C','D','E','F']):
            gr=ROOT.TGraphErrors()
            gr.SetMarkerStyle(20+i)
            gr.SetTitle('2017'+era)
            for xi in np.linspace(0,0.2,50):
                ip=gr.GetN()
                eff,effUnc=ppsEffReader.getPPSEfficiency('2017'+era,xangle,xi,rp)
                gr.SetPoint(ip,xi,eff)
                gr.SetPointError(ip,0,effUnc)
            p.add(gr,'2017'+era, color=1, isData=False, spImpose=True, isSyst=False)
        p.show(outDir='./', lumi=37500)
    print '\t weighted ZeroBias histos'
    wzbh = getHistos(zb,
                     'wzb',
                     'ZeroBias (weighted)',
                     lw=1,
                     lc=ROOT.kRed,
                     ms=1,
                     weights=weights)

    for key in zbh:

        p = Plot('%s_2017%s' % (key, era), com='13 TeV')
        p.doPoissonErrorBars = False
        p.add(zbh[key],
              title=zbh[key].GetTitle(),
              color=ROOT.kGray,
              isData=False,
              spImpose=False,
              isSyst=False)
        p.add(wzbh[key],
              title=wzbh[key].GetTitle(),
              color=ROOT.kRed,
              isData=False,
              spImpose=False,
              isSyst=False)
        p.add(mmh[key],
              title=mmh[key].GetTitle(),
              color=1,
              isData=True,
              spImpose=False,
              isSyst=False)
        p.show(outDir='./', lumi=41833, noStack=True)