def showRatios(ratios, outUrl):
    """shows the ratio plots"""

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

    os.system('rm %s' % outUrl)
    outDir = os.path.dirname(outUrl)

    COLOURS = [1, '#f4a582', '#bababa', '#abdda4']
    for key in ratios:
        p = Plot(key + '_ratio', com='13 TeV')
        p.doPoissonErrorBars = False
        p.ratiorange = (0.68, 1.34)
        p.spimposeWithErrors = True
        ic = 0
        for h in ratios[key]:
            p.add(h=h,
                  title=h.GetTitle(),
                  color=COLOURS[ic],
                  isData=False,
                  spImpose=True,
                  isSyst=False)
            ic += 1
        p.show(outDir=outDir,
               lumi=41400,
               noStack=False,
               saveTeX=False,
               noRatio=True)
        p.appendTo(outUrl)
        p.reset()
Example #2
0
def drawVariations(h, exp, cat):

    for c in comp:
        projs = getProjections(exp, comp[c])

        p = Plot('%s_%s' % (cat, c))
        p.doPoissonErrorBars = False
        p.add(h, 'nominal', 1, True, False, False)
        for px in projs:
            if c == 'qg':
                px.Scale(h.Integral() / px.Integral())
            p.add(px, px.GetTitle(), px.GetLineColor(), False, False, False)
        p.show('./', 41000, True)
Example #3
0
def showShapes(resultsDir,name,plotTitle,mass,boson,lumi,plotData=True,showPseudoData=True,showAllBkgs=True,plotpfix=''):

    """ show the shapes corresponding to a given analysis """

    colors=[ROOT.kGreen+1,ROOT.kAzure+3,ROOT.kOrange+2,ROOT.kGray,ROOT.kRed+2]
    
    shapeFiles=[os.path.join(resultsDir,f) for f in os.listdir(resultsDir) if 'shapes_' in f and '.root' in f]

    for f in shapeFiles:

        fIn=ROOT.TFile.Open(f)

        #check consistency of the file with the boson to plot
        if 'shapes_22' in f and boson=='g':
            v='g'
            channel='#gamma'
        elif 'shapes_169' in f and boson=='z': 
            v='zmm'
            channel='Z#rightarrow#mu#mu'
        elif 'shapes_121' in f and boson=='z': 
            v='zee'
            channel='Z#rightarrowee'
        else:
            continue
        

        bkgH       = fIn.Get('bkg_%s'%v)
        fidsigH    = fIn.Get('fidsig_%s_m%d'%(v,mass))
        outfidsigH = fIn.Get('outfidsig_%s_m%d'%(v,mass))
        dataH      = fIn.Get('data_obs_%s'%(v))

        if showPseudoData:
            dataH.Reset('ICE')
            nexp=bkgH.Integral()
            if fidsigH: nexp+=bkgH.Integral()
            if outfidsigH: nexp+=outfidsigH.Integral()
            for iev in range( ROOT.gRandom.Poisson( nexp ) ):
                dataH.Fill( bkgH.GetRandom() )
       
        try:
            p=Plot('%s_%s_inc%s'%(name,v,plotpfix))
            p.xtit='Missing mass [GeV]'
            p.ytit='Events'
            if fidsigH:
                p.add(fidsigH,            title='fiducial #scale[0.8]{(%d)}'%mass, color=ROOT.TColor.GetColor('#fdc086'), isData=False, spImpose=False, isSyst=False)
    
            if showAllBkgs:
                if outfidsigH:
                    p.add(outfidsigH,         title='non-fiducial',  color=ROOT.TColor.GetColor('#a6cee3'), isData=False, spImpose=False, isSyst=False)
                p.add(bkgH,               title='background',    color=ROOT.TColor.GetColor('#1f78b4'), isData=False, spImpose=False, isSyst=False)
            else:
                allBkg=bkgH.Clone('allbkg')
                if outfidsigH : 
                    allBkg.Add(outfidsigH)
                p.add(allBkg,               title='background',    color=ROOT.TColor.GetColor('#1f78b4'), isData=False, spImpose=False, isSyst=False)

            if plotData:
                dtitle='pseudo-data' if showPseudoData else 'Data'
                p.add(dataH, title=dtitle,   color=1, isData=True, spImpose=False, isSyst=False)

            if fidsigH:
                p.add(fidsigH.Clone(),    title=plotTitle+'#scale[0.8]{(%d)}'%mass, color=ROOT.TColor.GetColor('#fdc086'), isData=False, spImpose=True,  isSyst=False)

            if showAllBkgs and outfidsigH:
                p.add(outfidsigH.Clone(), title='non-fiducial',  color=ROOT.TColor.GetColor('#a6cee3'), isData=False, spImpose=True,  isSyst=False)
            
            p.ratiorange=[0.68,1.32]
            p.show('./',lumi*1000,extraText=plotTitle)

            

            #background systs
            p=Plot('%s_%s_inc_bkgunc%s'%(name,v,plotpfix))
            p.noErrorsOnRatio=True
            p.doPoissonErrorBars=False
            p.xtit='Missing mass [GeV]'
            p.ytit='Events'
            p.add(bkgH, title='background', color=1, isData=True,spImpose=False, isSyst=False)
            ic=0
            for syst,title in [('Up',            'e#mu mix'),
                               ('SingleDiffUp',  'single arm mix')]:
                h=fIn.Get('bkg_%s_bkgShape%s'%(v,syst))
                p.add(h, title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False)
                ic+=1
            p.ratiorange=[0.76,1.24]                
            p.show('./',lumi,noStack=True,extraText=plotTitle)

            #signal systs
            if fidsigH:
                p=Plot('%s_%s_sigunc%s'%(name,v,plotpfix))
                #fidsigH.Scale(1./5.)
                p.doPoissonErrorBars=False
                p.noErrorsOnRatio=True
                p.xtit='Missing mass [GeV]'
                p.ytit='Events'
                p.add(fidsigH, title='signal', color=1, isData=True,spImpose=False, isSyst=False)
                ic=0
                for syst,title in [('ShapeUp',   'e#mu mix.'),
                                   ('CalibUp',   'Time dependence'),                     
                                   ('PPSEffUp',  'PPS efficiency'),
                                   ('PzModelUp', 'p_{z}(pp)')]:
                    h=fIn.Get('fidsig_%s_m%d_sig%s'%(v,mass,syst))
                    print ic,syst,title,h
                    p.add(h, title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False)
                    ic+=1
                p.ratiorange=[0.5,1.46]
                p.show('./',lumi,noStack=True,extraText=plotTitle)

            #out fiducial signal systs
            if outfidsigH:
                p=Plot('%s_%s_outfidsigunc%s'%(name,v,plotpfix))
                #outfidsigH.Scale(1./5.)
                p.doPoissonErrorBars=False
                p.noErrorsOnRatio=True
                p.xtit='Missing mass [GeV]'
                p.ytit='Events'
                p.add(outfidsigH, title='out-fid. signal', color=1, isData=True,spImpose=False, isSyst=False)
                ic=0
                for syst,title in [('ShapeUp',   'e#mu mix.'),
                                   ('CalibUp',   'Time dependence'),
                                   ('PPSEffUp',  'PPS efficiency'),
                                   ('PzModelUp', 'p_{z}(pp)')]:
                    h=fIn.Get('outfidsig_%s_m%d_sig%s'%(v,mass,syst))
                    p.add(h, title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False)
                    ic+=1

                p.ratiorange=[0.5,1.46]                    
                p.show('./',lumi,noStack=True,extraText=plotTitle)

        except Exception as e:
            print e
            pass

        fIn.Close()
Example #4
0
def drawPlots(data, mc, period):
    """draw final plots comparing distributions in data and in mc"""

    files = {'data': data, 'mc': mc}

    base = 'passStrip'
    baseTitle = '=2 strip'
    base = 'passPix'
    baseTitle = '=2 px'
    for d, pfix in [
        ('xangle', ''),
            #('nvtx',''),      ('yboson',''),  ('dyboson',''),
            #('n','RP003'),    ('n','RP023'),    ('n','RP103'),   ('n','RP123'),
            #('csi','RP003'),  ('csi','RP023'),  ('csi','RP103'), ('csi','RP123'),
        ('mpp', 'far'),
        ('mpp', 'near'),
        ('mmass', 'far'),
        ('mmass', 'near'),
            #('dmpp',''),      ('dmmass',''),
    ]:

        hpercat = {}

        for tag in ['', 'matched']:
            for x in files:

                for cat in [base, 'passPixandpassStrip']:
                    try:
                        hpercat[(x, tag, cat)] = files[x].Get(
                            '%s_%s%s%s' % (d, cat, tag, pfix))
                        hpercat[(x, tag, cat)].SetDirectory(0)
                        hpercat[(x, tag, cat)].Sumw2()
                        hpercat[(x, tag, cat)].GetYaxis().SetTitle('PDF')
                    except:
                        pass

                #remove overlap
                #hpercat[(x,tag,base)].Add(hpercat[(x,tag,'passPixandpassStrip')],-1)

                #build the total
                hpercat[(x, tag, 'tot')] = hpercat[(x, tag, base)].Clone(
                    'tot_%s_%s' % (d, tag))
                hpercat[(x, tag, 'tot')].Add(hpercat[(x, tag,
                                                      'passPixandpassStrip')])
                hpercat[(x, tag, 'tot')].SetDirectory(0)
                ntot = hpercat[(x, tag, 'tot')].Integral()

                continue
                for cat in [base, 'passPixandpassStrip']:
                    hpercat[(x, tag, cat)].Scale(1. / ntot)

            if tag == '':
                print base, hpercat[('data', '', base)].Integral()
                print base + 'passPixandpassStrip', hpercat[(
                    'data', '', 'passPixandpassStrip')].Integral()
                print '\t', hpercat[('data', '', base)].Integral() / hpercat[
                    ('data', '', 'passPixandpassStrip')].Integral()
            continue

            if tag == 'matched': continue

            p = Plot('%s%s_%s_era%s' % (d, pfix, tag, period), com='13 TeV')
            p.savelog = True
            p.range = [1e-3, 1]
            p.doPoissonErrorBars = False
            p.add(hpercat[('data', tag, base)],
                  title=baseTitle,
                  color=633,
                  isData=False,
                  spImpose=False,
                  isSyst=False)
            p.add(hpercat[('data', tag, 'passPixandpassStrip')],
                  title='=2 px+strip',
                  color="#fdc086",
                  isData=False,
                  spImpose=False,
                  isSyst=False)
            try:
                hpercat[('mc', tag, 'tot')].Scale(
                    1. / hpercat[('mc', tag, 'tot')].Integral())
                p.add(hpercat[('mc', tag, 'tot')],
                      title='signal',
                      color=1,
                      isData=False,
                      spImpose=True,
                      isSyst=False)
            except:
                pass
            p.show(outDir='./', lumi=37500, noStack=False)

        continue
        #efficiency
        effgr = {}
        for x, ms in [('data', 20), ('mc', 24)]:
            effgr[x] = ROOT.TGraphAsymmErrors()
            effgr[x].Divide(hpercat[(x, 'matched', 'tot')],
                            hpercat[(x, '', 'tot')])
            effgr[x].SetMarkerStyle(ms)
            effgr[x].SetTitle(x)
            effgr[x].SetName(x)
        p = Plot('%s%s_eff_era%s' % (d, pfix, period), com='13 TeV')
        p.ytit = 'Efficiency'
        p.xtit = hpercat[(x, 'matched', 'tot')].GetXaxis().GetTitle()
        p.savelog = False
        p.range = [1e-3, 1]
        #p.add(effgr['mc'],   title='MC',   color=ROOT.kCyan+1,  isData=False, spImpose=True,  isSyst=False)
        p.add(effgr['data'],
              title='Data',
              color=1,
              isData=False,
              spImpose=True,
              isSyst=False)
        p.show(outDir='./', lumi=37500, noStack=True)
    rwScenariosMassH[key][0].SetName('mass%d' % len(rwScenariosH))
    rwScenariosMassH[key][1].SetName('rwmass%d' % len(rwScenariosH))
    rwScenariosMassH[key][0].SetTitle('(172.5,1.32)')
    rwScenariosMassH[key][1].SetTitle('(%3.1f,%3.2f) wgt' % key)
    norig = rwScenariosMassH[key][0].Integral()
    rwScenariosMassH[key][0].Scale(1. / norig)
    rwScenariosMassH[key][1].Scale(1. / norig)

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

p = Plot('mlbwidth_closure', '13 TeV')
p.ratiorange = [0.958, 1.042]
p.savelog = True
p.doPoissonErrorBars = False
p.range = (1e-4, 0.014)
p.ytit = 'PDF'
p.add(h=simScenariosH[(172.5, 0.90)].Clone(),
      title=simScenariosH[(172.5, 0.90)].GetTitle(),
      color=1,
      isData=True,
      spImpose=False,
      isSyst=False,
      doDivideByBinWidth=True)
p.add(h=rwScenariosH[(172.5, 0.90)].Clone(),
      title=rwScenariosH[(172.5, 0.90)].GetTitle(),
      color=2,
      isData=False,
      spImpose=False,
      isSyst=False,
Example #6
0
def showShapes(resultsDir,
               name,
               title,
               mass,
               boson,
               r95,
               sig,
               lumi,
               plotData=True,
               showPseudoData=True,
               showAllBkgs=True):
    """ show the shapes corresponding to a given analysis """

    shapeFiles = [
        os.path.join(resultsDir, f) for f in os.listdir(resultsDir)
        if 'shapes_' in f and '.root' in f
    ]
    for f in shapeFiles:

        try:
            angle = int(re.search('_a(\d+)', f).group(1))
        except:
            print 'No angle could be parsed, assuming this is an inclusive analysis'
            angle = None

        fIn = ROOT.TFile.Open(f)

        #check consistency of the file with the boson to plot
        if 'shapes_22' in f and boson == 'g':
            v = 'g'
            channel = '#gamma'
        elif 'shapes_169' in f and boson == 'z':
            v = 'zmm'
            channel = 'Z#rightarrow#mu#mu'
        elif 'shapes_121' in f and boson == 'z':
            v = 'zee'
            channel = 'Z#rightarrowee'
        else:
            continue

        for icat in range(2):

            if angle:
                bkgH = fIn.Get('bkg_%s_a%d_%d' % (v, angle, icat))
                fidsigH = fIn.Get('fidsig_%s_a%d_%d_m%d' %
                                  (v, angle, icat, mass))
                outfidsigH = fIn.Get('outfidsig_%s_a%d_%d_m%d' %
                                     (v, angle, icat, mass))
                dataH = fIn.Get('data_obs_%s_a%d_%d' % (v, angle, icat))
            else:
                bkgH = fIn.Get('bkg_%s_%d' % (v, icat))
                fidsigH = fIn.Get('fidsig_%s_%d_m%d' % (v, icat, mass))
                outfidsigH = fIn.Get('outfidsig_%s_%d_m%d' % (v, icat, mass))
                dataH = fIn.Get('data_obs_%s_%d' % (v, icat))

            print bkgH, fidsigH, outfidsigH, dataH

            try:
                fidsigH.Scale(5)
                outfidsigH.Scale(5)
            except:
                fidsigH = None
                outfidsigH = None

            if showPseudoData:
                dataH.Reset('ICE')
                nexp = bkgH.Integral()
                if fidsigH: nexp += bkgH.Integral()
                if outfidsigH: nexp += outfidsigH.Integral()
                for iev in range(ROOT.gRandom.Poisson(nexp)):
                    dataH.Fill(bkgH.GetRandom())
            try:

                #main shapes
                if angle:
                    p = Plot('%s_%s_a%d_cat%d' % (name, v, angle, icat))
                else:
                    p = Plot('%s_%s_inc_cat%d' % (name, v, icat))

                p.xtit = 'Missing mass [GeV]'
                p.ytit = 'Events'
                if fidsigH:
                    p.add(fidsigH,
                          title='#scale[0.5]{5x}' + title +
                          '#scale[0.8]{(%d)}' % mass,
                          color=ROOT.TColor.GetColor('#fdc086'),
                          isData=False,
                          spImpose=False,
                          isSyst=False)

                if showAllBkgs:
                    if outfidsigH:
                        p.add(outfidsigH,
                              title='#scale[0.5]{5x}non-fiducial',
                              color=ROOT.TColor.GetColor('#a6cee3'),
                              isData=False,
                              spImpose=False,
                              isSyst=False)
                    p.add(bkgH,
                          title='background',
                          color=ROOT.TColor.GetColor('#1f78b4'),
                          isData=False,
                          spImpose=False,
                          isSyst=False)
                else:
                    allBkg = bkgH.Clone('allbkg')
                    if outfidsigH:
                        allBkg.Add(outfidsigH)
                    p.add(allBkg,
                          title='background',
                          color=ROOT.TColor.GetColor('#1f78b4'),
                          isData=False,
                          spImpose=False,
                          isSyst=False)

                if plotData:
                    dtitle = 'pseudo-data' if showPseudoData else 'Data'
                    p.add(dataH,
                          title=dtitle,
                          color=1,
                          isData=True,
                          spImpose=False,
                          isSyst=False)
                if fidsigH:
                    p.add(fidsigH.Clone(),
                          title=title + '#scale[0.8]{(%d)}' % mass,
                          color=ROOT.TColor.GetColor('#fdc086'),
                          isData=False,
                          spImpose=True,
                          isSyst=False)

                if showAllBkgs and outfidsigH:
                    p.add(outfidsigH.Clone(),
                          title='non-fiducial',
                          color=ROOT.TColor.GetColor('#a6cee3'),
                          isData=False,
                          spImpose=True,
                          isSyst=False)
                p.ratiorange = [0.68, 1.32]

                subcatName = 'low pileup' if icat == 0 else 'high pileup'
                if angle:
                    extraText = '%s, %d#murad\\%s' % (channel, angle,
                                                      subcatName)
                else:
                    extraText = '%s, inclusive\\%s' % (channel, subcatName)
                if r95: extraText += '\\#mu_{95}(exp.)<%3.3f' % r95
                if sig: extraText += '\\S(exp.)=%3.3f' % sig
                p.show('./', lumi * 1000, extraText=extraText)

                colors = [ROOT.kGreen + 1, ROOT.kAzure + 3, ROOT.kRed + 2]

                #background systs
                if angle:
                    p = Plot('%s_%s_a%d_cat%d_bkgunc' % (name, v, angle, icat))
                else:
                    p = Plot('%s_%s_inc_cat%d_bkgunc' % (name, v, icat))
                p.noErrorsOnRatio = True
                p.doPoissonErrorBars = False
                p.xtit = 'Missing mass [GeV]'
                p.ytit = 'Events'
                p.add(bkgH,
                      title='background',
                      color=1,
                      isData=True,
                      spImpose=False,
                      isSyst=False)
                ic = 0
                for syst, title in [('Up', 'Pileup spec.'),
                                    ('SingleDiffUp', 'Single diff.')]:
                    if angle:
                        p.add(fIn.Get('bkg_%s_a%d_%d_bkgShape%s' %
                                      (v, angle, icat, syst)),
                              title=title,
                              color=colors[ic],
                              isData=False,
                              spImpose=False,
                              isSyst=False)
                    else:
                        p.add(fIn.Get('bkg_%s_inc_%d_bkgShape%s' %
                                      (v, icat, syst)),
                              title=title,
                              color=colors[ic],
                              isData=False,
                              spImpose=False,
                              isSyst=False)
                    ic += 1
                p.ratiorange = [0.76, 1.24]
                if angle:
                    extraText = '%s, %d#murad' % (channel, angle)
                else:
                    extraText = '%s, inclusive' % (channel)
                p.show('./', lumi, noStack=True, extraText=extraText)

                #signal systs
                if fidsigH:
                    if angle:
                        p = Plot('%s_%s_a%d_cat%d_sigunc' %
                                 (name, v, angle, icat))
                    else:
                        p = Plot('%s_%s_inc_cat%d_sigunc' % (name, v, icat))
                    fidsigH.Scale(1. / 5.)
                    p.doPoissonErrorBars = False
                    p.noErrorsOnRatio = True
                    p.xtit = 'Missing mass [GeV]'
                    p.ytit = 'Events'
                    p.add(fidsigH,
                          title='signal',
                          color=1,
                          isData=True,
                          spImpose=False,
                          isSyst=False)
                    ic = 0
                    for syst, title in [('ShapeUp', 'Pileup spec.'),
                                        ('CalibUp', 'Time dependence'),
                                        ('PzModelUp', 'p_{z}(pp)')]:
                        if angle:
                            p.add(fIn.Get('fidsig_%s_a%d_%d_m%d_sig%s' %
                                          (v, angle, icat, mass, syst)),
                                  title=title,
                                  color=colors[ic],
                                  isData=False,
                                  spImpose=False,
                                  isSyst=False)
                        else:
                            p.add(fIn.Get('fidsig_%s_%d_m%d_sig%s' %
                                          (v, icat, mass, syst)),
                                  title=title,
                                  color=colors[ic],
                                  isData=False,
                                  spImpose=False,
                                  isSyst=False)
                        ic += 1
                    p.ratiorange = [0.76, 1.24]
                    if angle:
                        extraText = '%s, %d#murad\\m_{X}=%d GeV' % (
                            channel, angle, mass)
                    else:
                        extraText = '%s, inclusive\\m_{X}=%d GeV' % (channel,
                                                                     mass)
                    p.show('./', lumi, noStack=True, extraText=extraText)

                #out fiducial signal systs
                if outfidsigH:
                    if angle:
                        p = Plot('%s_%s_a%d_cat%d_outfidsigunc' %
                                 (name, v, angle, icat))
                    else:
                        p = Plot('%s_%s_inc_cat%d_outfidsigunc' %
                                 (name, v, icat))
                    outfidsigH.Scale(1. / 5.)
                    p.doPoissonErrorBars = False
                    p.noErrorsOnRatio = True
                    p.xtit = 'Missing mass [GeV]'
                    p.ytit = 'Events'
                    p.add(outfidsigH,
                          title='out-fid. signal',
                          color=1,
                          isData=True,
                          spImpose=False,
                          isSyst=False)
                    ic = 0
                    for syst, title in [('ShapeUp', 'Pileup spec.'),
                                        ('CalibUp', 'Time dependence'),
                                        ('PzModelUp', 'p_{z}(pp)')]:
                        if angle:
                            p.add(fIn.Get('outfidsig_%s_a%d_%d_m%d_sig%s' %
                                          (v, angle, icat, mass, syst)),
                                  title=title,
                                  color=colors[ic],
                                  isData=False,
                                  spImpose=False,
                                  isSyst=False)
                        else:
                            p.add(fIn.Get('outfidsig_%s_%d_m%d_sig%s' %
                                          (v, icat, mass, syst)),
                                  title=title,
                                  color=colors[ic],
                                  isData=False,
                                  spImpose=False,
                                  isSyst=False)
                        ic += 1

                    p.ratiorange = [0.76, 1.24]
                    if angle:
                        extraText = '%s, %d#murad\\m_{X}=%d GeV' % (
                            channel, angle, mass)
                    else:
                        extraText = '%s, inclusive\\m_{X}=%d GeV' % (channel,
                                                                     mass)
                    p.show('./', lumi, noStack=True, extraText=extraText)

            except Exception as e:
                print e
                pass

        fIn.Close()
def drawPlots():
    """draw final plots comparing distributions in data"""
    def fillHistos(fIn, histos, era, ch):

        eraKey = (era, ch)
        for k in fIn.GetListOfKeys():
            kname = k.GetName()
            hname = kname.split('_')[0]
            tag = ''.join(kname.split('_')[1:])
            key = (hname, tag)
            if not key in histos:
                histos[key] = {}
            histos[key][eraKey] = k.ReadObj().Clone(kname + '%s_%d' %
                                                    (era, ch))
            histos[key][eraKey].SetDirectory(0)
            histos[key][eraKey].GetYaxis().SetTitle('PDF')

        return histos

    histos = {}
    for era, ch in list(product(list('BCDEF'), [11 * 11, 13 * 13])):
        fIn = ROOT.TFile.Open('RPcontrol_era%s_ch%d.root' % (era, ch))
        fillHistos(fIn, histos, era, ch)
        fIn.Close()

    perAlgo = ['multi', 'px', 'strip']
    perAlgoPlusInc = perAlgo + [''] + ['a120', 'a130', 'a140', 'a150']
    perSide = product(perAlgo, ['pos', 'posinc', 'neg', 'neginc'])

    colors = ["#fdc086", "#7fc97f", "#DCDCDC", 633, "#386cb0", 9]
    for d, tags in [  #('n',        perSide),
            #('csi',       perSide),
            #('mpp',      perAlgo),
            ##('mmass',    perAlgo),
        ('nvtx', perAlgoPlusInc),
            #('xangle',   perAlgoPlusInc),
        ('ptll', perAlgoPlusInc),
            #('nch',      perAlgoPlusInc),
            #('rue',      perAlgoPlusInc),
            #('met',      perAlgoPlusInc),
            #('dphimetz', perAlgoPlusInc),
    ]:

        hglobal = None
        hperAlgo = {}
        hperXangle = {}
        for tag in tags:
            hinc = None
            hperEra = {}
            hperCh = {}

            key = (d, ''.join(tag))
            if not key in histos: continue

            for eraKey, h in histos[key].items():

                era, ch = eraKey

                #global inclusive histogram
                if len(tag) == 0:
                    print key, eraKey
                    if hglobal is None:
                        hglobal = h.Clone(d + '_global')
                        hglobal.SetDirectory(0)
                    else:
                        hglobal.Add(h)

                #inclusive histogram (this tag only)
                if hinc is None:
                    hinc = h.Clone(d + '_inc')
                    hinc.SetDirectory(0)
                else:
                    hinc.Add(h)

                #per angle histos
                if len(tag) == 4 and tag[0] == 'a':
                    xangle = tag[1:]
                    print key, xangle
                    if not xangle in hperXangle:
                        hperXangle[xangle] = h.Clone(d + '_' + xangle)
                        hperXangle[xangle].SetDirectory(0)
                    else:
                        hperXangle[xangle].Add(h)

                #per era histogram
                if not era in hperEra:
                    hperEra[era] = h.Clone('%s_%s' % (d, era))
                    hperEra[era].SetDirectory(0)
                else:
                    hperEra[era].Add(h)

                #per ch histogram
                if not ch in hperCh:
                    hperCh[ch] = h.Clone('%s_%d' % (d, ch))
                    hperCh[ch].SetDirectory(0)
                else:
                    hperCh[ch].Add(h)

                #per algo histogram
                algo = tag
                algoExtra = None
                if d == 'csi' and not 'inc' in tag[1]:
                    algo = tag[0]
                    algoExtra = '_pos' if 'pos' in tag[1] else '_neg'
                if isinstance(algo, str) and (algo in perAlgo + ['']):
                    algoKey = algo
                    if algoExtra: algoKey += algoExtra
                    if not algoKey in hperAlgo:
                        hperAlgo[algoKey] = h.Clone('%s_%s' % (d, algoKey))
                        hperAlgo[algoKey].SetDirectory(0)
                    else:
                        hperAlgo[algoKey].Add(h)

            if hinc is None: continue
            hinc.Scale(1. / hinc.Integral())

            #per era
            p = Plot('%s_%s_perEra' % key, com='13 TeV')
            p.savelog = True
            p.range = [1e-3, 1]
            p.doPoissonErrorBars = False
            for i, era in enumerate(hperEra.keys()):
                hperEra[era].Scale(1. / hperEra[era].Integral())
                p.add(hperEra[era],
                      title=era,
                      color=colors[i],
                      isData=False,
                      spImpose=False,
                      isSyst=False)
            p.add(hinc.Clone(),
                  title='total',
                  color=1,
                  isData=False,
                  spImpose=True,
                  isSyst=False)
            p.show(outDir='./', lumi=37500, noStack=True)

            #per ch
            p = Plot('%s_%s_perCh' % key, com='13 TeV')
            p.savelog = True
            p.range = [1e-3, 1]
            p.doPoissonErrorBars = False
            for i, ch in enumerate(hperCh.keys()):
                hperCh[ch].Scale(1. / hperCh[ch].Integral())
                p.add(hperCh[ch],
                      title='ee' if ch == 11 * 11 else '#mu#mu',
                      color=colors[i],
                      isData=False,
                      spImpose=False,
                      isSyst=False)
            p.add(hinc.Clone(),
                  title='total',
                  color=1,
                  isData=False,
                  spImpose=True,
                  isSyst=False)
            p.show(outDir='./', lumi=37500, noStack=True)

        #per xangle
        p = Plot('%s_perxangle' % d, com='13 TeV')
        p.savelog = True
        p.range = [1e-3, 1]
        p.doPoissonErrorBars = False
        for i, xangle in enumerate(['120', '130', '140', '150']):
            hperXangle[xangle].Scale(1. / hperXangle[xangle].Integral())
            spImpose = True if xangle == '' else False
            title = '%s#murad' % xangle
            ci = colors[i]
            p.add(hperXangle[xangle],
                  title=title,
                  color=ci,
                  isData=False,
                  spImpose=spImpose,
                  isSyst=False)
        if hglobal:
            hglobal.Scale(1. / hglobal.Integral())
            p.add(hglobal.Clone(),
                  title='total',
                  color=1,
                  isData=False,
                  spImpose=True,
                  isSyst=False)
        try:
            p.show(outDir='./', lumi=37500, noStack=True)
        except Exception as e:
            print d, e

        #per algo
        p = Plot('%s_peralgo' % d, com='13 TeV')
        p.savelog = True
        p.range = [1e-3, 1]
        p.doPoissonErrorBars = False
        for i, algo in enumerate(hperAlgo.keys()):
            hperAlgo[algo].Scale(1. / hperAlgo[algo].Integral())
            spImpose = True if algo == '' else False
            title = 'inclusive' if algo == '' else algo
            title = title.replace('_pos', ' (+)')
            title = title.replace('_neg', ' (-)')
            ci = colors[i] if algo != '' else 1
            p.add(hperAlgo[algo],
                  title=title,
                  color=ci,
                  isData=False,
                  spImpose=spImpose,
                  isSyst=False)
        p.show(outDir='./', lumi=37500, noStack=True)
Example #8
0
def drawPlots(data, period):
    """draw final plots comparing distributions in data and in mc"""

    base = 'passStrip'
    baseTitle = '=2 strip'
    base = 'passPix'
    baseTitle = '=2 px'
    for d, pfix in [
        ('xangle', ''),
        ('nvtx', ''),
        ('yboson', ''),
        ('dyboson', ''),
        ('n', 'RP003'),
        ('n', 'RP023'),
        ('n', 'RP103'),
        ('n', 'RP123'),
        ('csi', 'RP003'),
        ('csi', 'RP023'),
        ('csi', 'RP103'),
        ('csi', 'RP123'),
        ('mpp', 'far'),
        ('mpp', 'near'),
        ('mmass', 'far'),
        ('mmass', 'near'),
        ('dmpp', ''),
        ('dmmass', ''),
    ]:

        hpercat = {}

        for tag in ['', 'matched']:
            for cat in [base, 'passPixandpassStrip']:
                try:
                    hpercat[(tag, cat)] = data.Get('%s_%s%s%s' %
                                                   (d, cat, tag, pfix))
                    hpercat[(tag, cat)].SetDirectory(0)
                    hpercat[(tag, cat)].Sumw2()
                    hpercat[(tag, cat)].GetYaxis().SetTitle('PDF')
                except Exception as e:
                    print e
                    pass

            #build the total
            hpercat[(tag,
                     'tot')] = hpercat[(tag,
                                        base)].Clone('tot_%s_%s' % (d, tag))
            hpercat[(tag, 'tot')].Add(hpercat[(tag, 'passPixandpassStrip')])
            hpercat[(tag, 'tot')].SetDirectory(0)
            ntot = hpercat[(tag, 'tot')].Integral()

            continue
            for cat in [base, 'passPixandpassStrip']:
                hpercat[(tag, cat)].Scale(1. / ntot)

            if tag == '':
                print base, hpercat[('', base)].Integral()
                print base + 'passPixandpassStrip', hpercat[(
                    '', 'passPixandpassStrip')].Integral()
                print '\t', hpercat[('', base)].Integral() / hpercat[
                    ('', 'passPixandpassStrip')].Integral()
            continue

            if tag == 'matched': continue

            p = Plot('%s%s_%s_era%s' % (d, pfix, tag, period), com='13 TeV')
            p.savelog = True
            p.range = [1e-3, 1]
            p.doPoissonErrorBars = False
            p.add(hpercat[(tag, base)],
                  title=baseTitle,
                  color=633,
                  isData=False,
                  spImpose=False,
                  isSyst=False)
            p.add(hpercat[(tag, 'passPixandpassStrip')],
                  title='=2 px+strip',
                  color="#fdc086",
                  isData=False,
                  spImpose=False,
                  isSyst=False)
            p.show(outDir='./', lumi=37500, noStack=False)

        continue