Ejemplo n.º 1
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()
Ejemplo n.º 2
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()