コード例 #1
0
ファイル: plotmod.py プロジェクト: pallabidas/cmg-cmssw
def plot_W(anaDir, comps, weights, 
           nbins, xmin, xmax,
           cut, weight,
           embed, VVgroup=None, TTgroup=None, treeName=None):

    # get WJet scaling factor for same sign
    var = 'mt'
    sscut = '{cut} && mt>{min} && mt<{max} && diTau_charge!=0'.format(
        cut = cut, 
        min=xmin,
        max=xmax
        )
    oscut = sscut.replace('diTau_charge!=0', 'diTau_charge==0')


    # get WJet scaling factor for opposite sign
    print 'extracting WJets data/MC factor in high mt region, OS'
    print oscut
    mtOS = H2TauTauDataMC( var, anaDir, comps, weights,
                           nbins, xmin, xmax, 
                           cut = oscut, weight=weight,
                           embed=embed, treeName=treeName)
    if VVgroup != None :
        mtOS.Group ('VV',VVgroup)
    if TTgroup != None:
        mtOS.Group('TTJets', TTgroup)

    print TTgroup, mtOS
    
    print 'W SCALE FACTOR OS:'
    data_OS, mc_OS = fW( mtOS, 'Data', xmin, xmax, VVgroup)
    fW_OS = data_OS / mc_OS


    print 'extracting WJets data/MC factor in high mt region, SS'
    print sscut 
    mtSS = H2TauTauDataMC(var, anaDir, comps, weights,
                          nbins, xmin, xmax,
                          cut = sscut, weight=weight,
                          embed=embed, treeName=treeName)
    if VVgroup != None :
        mtSS.Group ('VV',VVgroup)
    if TTgroup != None:
        mtSS.Group('TTJets', TTgroup)

    print 'W SCALE FACTOR SS:'
    data_SS, mc_SS = fW( mtSS, 'Data', xmin, xmax, VVgroup)

    fW_SS = data_SS / mc_SS if mc_SS else -1.

    
    print 'fW_SS=',fW_SS,'fW_OS=',fW_OS
 
    return fW_SS, fW_OS, mtSS, mtOS
コード例 #2
0
def makePlot(var,
             weights,
             wJetScaleSS,
             wJetScaleOS,
             nbins=None,
             xmin=None,
             xmax=None,
             weight='weight',
             embed=False):

    if nbins is None: nbins = NBINS
    if xmin is None: xmin = XMIN
    if xmax is None: xmax = XMAX

    oscut = str(inc_sig & Cut('l1_charge*l2_charge<0 && mt<40') & cat_VBF)
    print '[OS]', oscut
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           embed=embed)
    osign.Hist(EWK).Scale(wJetScaleOS)
    osign = replaceWJets(osign, var, 'l1_charge*l2_charge<0', weight, embed)
    osign = replaceZtt(osign, var, 'l1_charge*l2_charge<0', weight, embed)

    # boxss = box.replace('OS','SS')
    # sscut = str(inc_sig & Cut('l1_charge*l2_charge>0') & cat_VBF)
    sscut = ' && '.join([cat_Inc_RlxMuIso, 'l1_charge*l2_charge>0', cat_VBF])
    print '[SS]', sscut
    ssign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=sscut,
                           weight=weight,
                           embed=embed)
    ssign.Hist(EWK).Scale(wJetScaleSS)
    ssign = replaceWJets(ssign, var, 'l1_charge*l2_charge>0 && mt<40', weight,
                         embed)
    ssign = replaceZtt(ssign, var, 'l1_charge*l2_charge>0 && mt<40', weight,
                       embed)

    ssQCD, osQCD = getQCD_VBF(ssign, osign, 'Data')

    groupEWK(osQCD)
    return ssign, osign, ssQCD, osQCD
コード例 #3
0
def makePlot(var,
             anaDir,
             selComps,
             weights,
             nbins=None,
             xmin=None,
             xmax=None,
             cut='',
             weight='weight',
             embed=False,
             shift=None,
             VVgroup=None,
             treeName='TauMu'):

    oscut = cut + ' && diTau_charge==0'
    print 'making the plot:', var, 'cut', oscut
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           shift=shift,
                           embed=embed,
                           treeName=treeName)
    # if VVgroup:
    #     osign.Group('VV',VVgroup)
    # osign.Group('electroweak', ['WJets', 'Ztt_ZJ','VV'])
    return osign
コード例 #4
0
def makePlot(var,
             anaDir,
             selComps,
             weights,
             nbins=None,
             xmin=None,
             xmax=None,
             cut='',
             weight='weight',
             embed=False):

    print 'making the plot:', var, 'cut', cut

    oscut = cut + ' && diTau_charge==0'
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           embed=embed)

    osign.Group('VV', ['WW', 'WZ', 'ZZ'])
    osign.Group('EWK', ['WJets', 'Ztt_ZL', 'Ztt_ZJ', 'VV'])
    osign.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])
    return osign
コード例 #5
0
ファイル: plotmod.py プロジェクト: pallabidas/cmg-cmssw
def buildPlot( var, anaDir,
               comps, weights, nbins, xmin, xmax,
               cut, weight,
               embed, shift=None, treeName=None ):
    pl = H2TauTauDataMC(var, anaDir,
                        comps, weights, nbins, xmin, xmax,
                        str(cut), weight,
                        embed, shift, treeName )
    return pl
コード例 #6
0
def getQCD_VBF( plotSS, plotOS, dataName, var, weights, wJetScaleSS, wJetScaleOS,
                nbins, xmin, xmax,
                weight, embed  ):
    # use SS data as a control region
    # to get the expected QCD shape and yield
    plotSSWithQCD = addQCD( plotSS, dataName )

    # extrapolate the expected QCD shape and yield to the
    # signal region

    plotOSWithQCD = copy.deepcopy( plotOS )

    qcdyield = plotSSWithQCD.Hist('QCD').Integral()
    qcdyield *= 1.11
    qcdyield *= factor_QCD_nonIsoToIso() 


    ssrelcut = ' && '.join( [cat_Inc_RlxMuIso, 'l1_charge*l2_charge>0', cat_VBF] )
    print '[SSREL]', ssrelcut
    ssignrel = H2TauTauDataMC(var, anaDir,
                              selComps, weights, nbins, xmin, xmax,
                              cut=ssrelcut, weight=weight,
                              embed=embed)
    ssignrel.Hist(EWK).Scale( wJetScaleSS ) 
    # ssignrel = replaceWJets(ssignrel, var, 'l1_charge*l2_charge>0 && mt<40' , weight, embed)
    # ssignrel = replaceZtt(ssignrel, var, 'l1_charge*l2_charge>0 && mt<40' , weight, embed)
    ssignrelQCD = addQCD( ssignrel, dataName )
    
    qcdOS = copy.deepcopy( ssignrelQCD.Hist('QCD') )
    qcdOS.RemoveNegativeValues()
    qcdOS.Normalize()
    qcdOS.Scale( qcdyield )

    import pdb; pdb.set_trace()

    # qcdOS.Scale( 1.11 )
    # qcdOS.Scale( factor_QCD_nonIsoToIso() )

    plotOSWithQCD.AddHistogram('QCD', qcdOS.weighted, 1030)
    plotOSWithQCD.Hist('QCD').layer=1.5

    return plotSSWithQCD, plotOSWithQCD
コード例 #7
0
def replaceShape(compName, shapeCut, osign, shapePlotInfo):
    var, anaDir, selComps, weights, nbins, xmin, xmax, weight, embed, shift = shapePlotInfo
    # print compName, 'replacing shape', shapeCut

    fileCompName = compName
    if 'Ztt_' in compName:
        fileCompName = 'Ztt'

    pl = H2TauTauDataMC(var, anaDir,
                        {selComps[fileCompName].name: selComps[fileCompName]},
                        weights, nbins, xmin, xmax, shapeCut, weight, embed,
                        shift)
    shape = copy.deepcopy(pl.Hist(compName))
    print compName, 'Int(shape)', shape.Integral(), 'Int(tight)', osign.Hist(
        compName).Integral()
    if shape.Integral() > 0. and osign.Hist(compName).Integral() > 0.:
        print 'Scaling new shape', osign.Hist(
            compName).Integral() / shape.Integral()
        shape.Scale(osign.Hist(compName).Integral() / shape.Integral())
        osign.Replace(compName, shape)
    else:
        print 'WARNING in shape replacement, integral 0 for component', compName
コード例 #8
0
def replaceShape(compName, shapeCut, osign, shapePlotInfo):
    var, anaDir, selComps, weights, nbins, xmin, xmax, weight, embed, shift = shapePlotInfo
    # print compName, 'replacing shape', shapeCut

    fileCompName = compName
    if 'Ztt_' in compName:
        fileCompName = 'Ztt'

    if osign.Hist(compName).Integral() == 0.:
        print 'INFO: in shape replacement, integral 0 for component', compName, 'returning'
        return

    pl = H2TauTauDataMC(var,
                        anaDir,
                        {selComps[fileCompName].name: selComps[fileCompName]},
                        weights,
                        nbins,
                        xmin,
                        xmax,
                        shapeCut,
                        weight,
                        embed,
                        shift,
                        treeName='H2TauTauTreeProducerTauEle')

    print '\nDEBUG for', compName
    print 'DEBUG', shapeCut
    print 'DEBUG', selComps[fileCompName].name, '\n'

    shape = copy.deepcopy(pl.Hist(compName))
    print compName, 'Int(shape)', shape.Integral(), 'Int(tight)', osign.Hist(
        compName).Integral()
    if shape.Integral() > 0. and osign.Hist(compName).Integral() > 0.:
        print 'Scaling new shape', osign.Hist(
            compName).Integral() / shape.Integral()
        shape.Scale(osign.Hist(compName).Integral() / shape.Integral())
        osign.Replace(compName, shape)
    else:
        print 'WARNING in shape replacement, integral 0 for component', compName, 'SHOULD NOT HAPPEN'
コード例 #9
0
def makePlot( var, anaDir, selComps, weights, wJetScaleSS, wJetScaleOS,
              w_mt_ratio_ss, w_mt_ratio_os, w_mt_ratio,
              nbins=None, xmin=None, xmax=None,
              cut='', weight='weight', embed=False, shift=None, replaceW=False,
              VVgroup = None, antiEleIsoForQCD = False):
    
    print 'making the plot:', var, 'cut', cut

    oscut = cut+' && diTau_charge==0'
    osign = H2TauTauDataMC(var, anaDir,
                           selComps, weights, nbins, xmin, xmax,
                           cut=oscut, weight=weight,
                           embed=embed, shift=shift, treeName = 'H2TauTauTreeProducerTauEle')
    osign.Hist(EWK).Scale( wJetScaleOS )

    #PG correct for the differnce in shape between SS and OS for the WJets MC
    #PG why should this be done only if the mt cut is present?
    if cut.find('mt<')!=-1:
        print 'correcting high->low mT extrapolation factor, OS', w_mt_ratio / w_mt_ratio_os
        osign.Hist(EWK).Scale( w_mt_ratio / w_mt_ratio_os )
#    replaceW = False
    if replaceW:
        osign = replaceShapeRelIso(osign, var, anaDir,
                                   selComps['WJets'], weights, 
                                   oscut, weight,
                                   embed, shift)
    if VVgroup != None:
         osign.Group('VV', VVgroup)
         
    sscut = cut+' && diTau_charge!=0'
    ssign = H2TauTauDataMC(var, anaDir,
                           selComps, weights, nbins, xmin, xmax,
                           cut=sscut, weight=weight,
                           embed=embed, shift=shift, treeName = 'H2TauTauTreeProducerTauEle')
    ssign.Hist(EWK).Scale( wJetScaleSS ) 

    #PG correct for the differnce in shape between SS and OS for the WJets MC
    #PG why should this be done only if the mt cut is present?
    if cut.find('mt<')!=-1:
        print 'correcting high->low mT extrapolation factor, SS', w_mt_ratio / w_mt_ratio_ss
        ssign.Hist(EWK).Scale( w_mt_ratio / w_mt_ratio_ss  ) 

    if replaceW:
        ssign = replaceShapeRelIso(ssign, var, anaDir,
                                   selComps['WJets'], weights, 
                                   sscut, weight,
                                   embed, shift)
    if VVgroup != None:
         ssign.Group('VV', VVgroup)
    # import pdb; pdb.set_trace()

    ssQCD, osQCD = getQCD( ssign, osign, 'Data', 1.06 ) #PG scale value according Jose, 18/10

    if antiEleIsoForQCD:
        print 'WARNING RELAXING ISO FOR QCD SHAPE'
        # replace QCD with a shape obtained from data in an anti-iso control region
        qcd_yield = osQCD.Hist('QCD').Integral()
        
        sscut_qcdshape = cut.replace('l2_relIso05<0.1', '(l2_relIso05<0.5 && l2_relIso05>0.2)').replace('l1_looseMvaIso>0.5', 'l1_rawMvaIso>0.7') + ' && diTau_charge!=0'
        ssign_qcdshape = H2TauTauDataMC(var, anaDir,
                                        selComps, weights, nbins, xmin, xmax,
                                        cut=sscut_qcdshape, weight=weight,
                                        embed=embed, treeName = 'H2TauTauTreeProducerTauEle')
        qcd_shape = copy.deepcopy( ssign_qcdshape.Hist('Data') )

        qcd_shape.Normalize()
        qcd_shape.Scale(qcd_yield)
        osQCD.Replace('QCD', qcd_shape)
        
    osQCD.Group('EWK', ['WJets', 'Ztt_ZJ','VV'])
    osQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])

    ssQCD.Group('EWK', ['WJets', 'Ztt_ZJ','VV'])
    ssQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])

    return ssign, osign, ssQCD, osQCD
コード例 #10
0
def makePlot(var,
             weights,
             wJetScaleSS,
             wJetScaleOS,
             nbins=None,
             xmin=None,
             xmax=None,
             weight='weight',
             embed=False):

    if nbins is None: nbins = NBINS
    if xmin is None: xmin = XMIN
    if xmax is None: xmax = XMAX

    oscut = str(inc_sig & Cut('l1_charge*l2_charge<0 && mt<40') & cat_VBF)
    print '[OS]', oscut
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           embed=embed)
    osign.Hist(EWK).Scale(wJetScaleOS)
    # import pdb; pdb.set_trace()
    osign = replaceWJets(osign, var, oscut, weight, embed)
    osign = replaceZtt(osign, var, oscut, weight, embed)

    ssantisocut = str(
        Cut(cat_Inc_AntiMuTauIsoJosh) & Cut('l1_charge*l2_charge>0 && mt<40')
        & cat_VBF)

    ssantiso = H2TauTauDataMC(var,
                              anaDir,
                              selComps,
                              weights,
                              nbins,
                              xmin,
                              xmax,
                              cut=ssantisocut,
                              weight=weight,
                              embed=embed)
    # here, would need to replace with the same dilep cut!
    # antiso = replaceWJets(antiso, var, antisocut, weight, embed)
    # antiso = replaceZtt(antiso, var, antisocut, weight, embed)
    # ssantisoQCD = addQCD( ssantiso, 'Data')

    import pdb
    pdb.set_trace()

    # now get the QCD yield:
    antisoForYield = H2TauTauDataMC(var,
                                    anaDir,
                                    selComps,
                                    weights,
                                    nbins,
                                    xmin,
                                    xmax,
                                    cut=antisocut,
                                    weight=fakeweight,
                                    embed=embed)
    # import pdb; pdb.set_trace()

    # hmmm shouldn't I use fakeweight here?
    # import pdb; pdb.set_trace()

    #WARNING!!! I HAD THAT IN TO GET MY NICE PLOTS JUNE12, 12:20, WORKS WHEN BOTH MU AND TAU ISO
    # ARE RELAXED
    antisoForYield = replaceWJets(antisoForYield, var, antisocut, fakeweight,
                                  embed)

    # antisoForYield = replaceZtt(antisoForYield, var, antisocut, fakeweight, embed)

    # antisoForYieldQCD = addQCD( antisoForYield, 'Data')

    # import pdb; pdb.set_trace()
    qcdyield = antisoForYield.Hist('Data').Integral()
    # ASSUMING ONLY QCD IN ANTI-ISO REGION
    qcd = copy.deepcopy(antisoQCD.Hist('Data'))
    qcd.weighted.SetFillStyle(1001)
    qcd.stack = True
    qcd.Normalize()
    qcd.Scale(qcdyield)

    osQCD = copy.deepcopy(osign)
    osQCD.AddHistogram('QCD', qcd.weighted, 1.5)

    # osQCD = osign
    groupEWK(osQCD)
    return antiso, osign, antisoQCD, osQCD
コード例 #11
0
def makePlot(var,
             nbins,
             xmin,
             xmax,
             anaDir,
             selComps,
             weights,
             wInfo,
             cut='',
             weight='weight',
             embed=False,
             shift=None,
             replaceW=False,
             VVgroup=None,
             TTgroup=None,
             antiEleIsoForQCD=False,
             antiEleRlxTauIsoForQCD=False,
             antiEleRlxTauIsoForQCDYield=False,
             subtractBGForQCDShape=False,
             embedForSS=False,
             relSelection={},
             osForWExtrapolation=True,
             incQCDYield=99999.,
             qcdYieldInclusiveExtrapolation=False,
             dataComps={},
             cutName='',
             isZeroB=False,
             isOneJet=False):

    print '\nMaking the plot:', var, 'cut', cut

    wJetScaleSS, wJetScaleOS, w_mt_ratio_ss, w_mt_ratio_os, w_mt_ratio = wInfo

    oscut = cut + ' && diTau_charge==0'
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           shift=shift,
                           embed=embed,
                           treeName='H2TauTauTreeProducerTauEle')
    osign.Hist(EWK).Scale(wJetScaleOS)

    print 'USING wJetScaleOS', wJetScaleOS

    # No OS requirement for MT extrapolation in 1-jet categories
    if cut.find('mt<') != -1 and not osForWExtrapolation:
        print 'correcting high->low mT extrapolation factor, OS', w_mt_ratio / w_mt_ratio_os
        osign.Hist(EWK).Scale(w_mt_ratio / w_mt_ratio_os)
    if replaceW:
        osign = replaceShapeInclusive(osign, var, anaDir, selComps['WJets'],
                                      weights, oscut, weight, embed, shift)

    print '\nINFO Replacing shapes'
    shapePlotInfo = var, anaDir, selComps, weights, nbins, xmin, xmax, weight, embed, shift
    for sample in relSelection:
        if sample != 'QCD':
            print 'Replace shape', sample
            print 'Tight cut', cut + ' && diTau_charge==0'
            print 'Relaxed cut', relSelection[sample] + ' && diTau_charge==0'
            replaceShape(sample, relSelection[sample] + ' && diTau_charge==0',
                         osign, shapePlotInfo)

    sscut = cut + ' && diTau_charge!=0'
    if not embedForSS and embed:
        print '\nINFO, as opposed to old default, not using embedded samples for SS region, but only for OS'

    ssign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=sscut,
                           weight=weight,
                           shift=shift,
                           embed=embedForSS,
                           treeName='H2TauTauTreeProducerTauEle')
    ssign.Hist(EWK).Scale(wJetScaleSS)

    # if cut.find('mt<')!=-1:
    #     if w_mt_ratio_ss > 0.:
    #         print 'correcting high->low mT extrapolation factor, SS', w_mt_ratio / w_mt_ratio_ss
    #         ssign.Hist(EWK).Scale( w_mt_ratio / w_mt_ratio_ss  )
    #     else:
    #         print 'WARNING! Not correcting W mT ratio from SS to OS region: No events in SS high mT'

    # if replaceW:
    #     ssign = replaceShapeInclusive(ssign, var, anaDir,
    #                                   selComps['WJets'], weights,
    #                                   sscut, weight,
    #                                   embed, shift)

    if VVgroup:
        ssign.Group('VV', VVgroup)
        osign.Group('VV', VVgroup)
    if TTgroup:
        ssign.Group('TTJets', TTgroup)
        osign.Group('TTJets', TTgroup)

    print '\nINFO, Estimating QCD'
    if subtractBGForQCDShape:
        print 'Subtracting BG for QCD shape'

    ssQCD, osQCD = getQCD(ssign,
                          osign,
                          'Data',
                          VVgroup,
                          subtractBGForShape=subtractBGForQCDShape)

    # Calculate QCD yield for VBF and 1 jet high med higgs
    if qcdYieldInclusiveExtrapolation:
        # QCD, Inclusive, SS, anti-isolation, for QCD efficiency
        inc_qcd_cut = ' && '.join([
            cat_Inc, 'mt<30', 'diTau_charge!=0'
        ])  # FIXME: fixed for now, make configurable? guess from cat string?
        cat_qcd_cut = sscut
        if antiEleIsoForQCD:
            print 'INFO: Inverting ele iso for QCD yield extrapolation'
            inc_qcd_cut = inc_qcd_cut.replace(
                'l2_relIso05<0.1', 'l2_relIso05>0.2 && l2_relIso05<0.5')
            cat_qcd_cut = cat_qcd_cut.replace(
                'l2_relIso05<0.1', 'l2_relIso05>0.2 && l2_relIso05<0.5')
        if antiEleRlxTauIsoForQCDYield:
            print 'INFO: Inverting ele and relaxing tau iso for QCD yield extrapolation'
            inc_qcd_cut = inc_qcd_cut.replace(
                'l2_relIso05<0.1',
                'l2_relIso05>0.2 && l2_relIso05<0.5').replace(
                    'l1_threeHitIso<1.5',
                    'l1_threeHitIso<10.') + ' && diTau_charge!=0'
            cat_qcd_cut = cat_qcd_cut.replace(
                'l2_relIso05<0.1',
                'l2_relIso05>0.2 && l2_relIso05<0.5').replace(
                    'l1_threeHitIso<1.5',
                    'l1_threeHitIso<10.') + ' && diTau_charge!=0'

        inc_qcd_plot = buildPlot(var,
                                 anaDir,
                                 dataComps,
                                 weights,
                                 nbins,
                                 xmin,
                                 xmax,
                                 inc_qcd_cut,
                                 weight,
                                 embed,
                                 treeName='H2TauTauTreeProducerTauEle')
        inc_qcd_yield = inc_qcd_plot.Hist('Data').Integral()

        cat_qcd_plot = buildPlot(options.hist,
                                 anaDir,
                                 dataComps,
                                 weights,
                                 NBINS,
                                 XMIN,
                                 XMAX,
                                 cat_qcd_cut,
                                 weight,
                                 options.embed,
                                 treeName='H2TauTauTreeProducerTauEle')
        cat_qcd_yield = cat_qcd_plot.Hist('Data').Integral()

        qcd_cat_eff = cat_qcd_yield / inc_qcd_yield
        print 'Extrapolation factor:', qcd_cat_eff

        print 'Correcting QCD yield'
        print 'Old yield', osQCD.Hist('QCD').Integral()

        osQCD.Hist('QCD').Scale(qcd_cat_eff * incQCDYield /
                                osQCD.Hist('QCD').Integral())
        print 'New yield', osQCD.Hist('QCD').Integral()

    if antiEleIsoForQCD or antiEleRlxTauIsoForQCD:
        qcdcut = cut
        if 'QCD' in relSelection:
            qcdcut = relSelection['QCD']
            print 'INFO, replacing QCD shape', qcdcut
        if antiEleIsoForQCD:
            print 'INFO: INVERTING ELE ISO FOR QCD SHAPE'
            sscut_qcdshape = qcdcut.replace(
                'l2_relIso05<0.1',
                'l2_relIso05>0.2 && l2_relIso05<0.5') + ' && diTau_charge!=0'
        if antiEleRlxTauIsoForQCD:
            print 'INFO: RELAXING TAU AND INVERTING ELE ISO FOR QCD SHAPE'
            sscut_qcdshape = qcdcut.replace(
                'l2_relIso05<0.1',
                'l2_relIso05>0.2 && l2_relIso05<0.5').replace(
                    'l1_threeHitIso<1.5',
                    'l1_threeHitIso<10.') + ' && diTau_charge!=0'

        qcd_yield = osQCD.Hist('QCD').Integral()

        ssign_qcdshape = H2TauTauDataMC(var,
                                        anaDir,
                                        dataComps,
                                        weights,
                                        nbins,
                                        xmin,
                                        xmax,
                                        cut=sscut_qcdshape,
                                        weight=weight,
                                        embed=embed,
                                        treeName='H2TauTauTreeProducerTauEle')
        print var, anaDir, dataComps, weights, nbins, xmin, xmax, sscut_qcdshape, weight, embed
        qcd_shape = copy.deepcopy(ssign_qcdshape.Hist('Data'))
        print ssign_qcdshape
        # import pdb; pdb.set_trace()
        qcd_shape.Normalize()
        qcd_shape.Scale(qcd_yield)
        # qcd_shape.Scale( qcd_yield )
        old_qcd_shape = osQCD.Hist('QCD')
        osQCD.old_qcd_shape = copy.deepcopy(old_qcd_shape)
        osQCD.Replace('QCD', qcd_shape)

    # Scale QCD yield for mtt < 50 by factor 1.1 in one-jet categories unless tau iso is relaxed
    if (isOneJet or isZeroB) and not antiEleRlxTauIsoForQCD:
        for iBin in range(1, osQCD.Hist('QCD').weighted.GetNbinsX()):
            if osQCD.Hist('QCD').weighted.GetBinCenter(iBin) < 50.:
                osQCD.Hist('QCD').weighted.SetBinContent(
                    iBin,
                    osQCD.Hist('QCD').weighted.GetBinContent(iBin) * 1.1)
                osQCD.Hist('QCD').weighted.SetBinError(
                    iBin,
                    osQCD.Hist('QCD').weighted.GetBinError(iBin) * 1.1)

    # # Extra sausage for ZL in VBF loose: Normalise yield to yield in 2 jet
    # # plus extrapolation to VBF loose
    # if cat_VBF_loose in cut:
    #     dycomp = selComps['Ztt']
    #     cut2Jet = cut.replace(cat_VBF_loose, cat_J2)
    #     dyplot2Jet = buildPlot(var, anaDir,
    #                    {dycomp.name:dycomp}, weights,
    #                    nbins, xmin, xmax,
    #                    cut2Jet, weight,
    #                    embed, shift, treeName = 'H2TauTauTreeProducerTauEle')
    #     dyplot = buildPlot(var, anaDir,
    #                    {dycomp.name:dycomp}, weights,
    #                    nbins, xmin, xmax,
    #                    cut, weight,
    #                    embed, shift, treeName = 'H2TauTauTreeProducerTauEle')

    #     zlYield2Jet = dyplot2Jet.Hist('Ztt_ZL').Integral()
    #     zttYield2Jet = dyplot2Jet.Hist('Ztt').Integral()
    #     zlYieldVBFloose = dyplot.Hist('Ztt_ZL').Integral()
    #     zttYieldVBFloose = dyplot.Hist('Ztt').Integral()

    #     print 'INFO: Estimating ZL yield in VBF loose'
    #     print '      Yield in 2 jet', zlYield2Jet
    #     print '      Yield in VBF l', zlYieldVBFloose
    #     print '      Yield in 2 jet', zttYield2Jet
    #     print '      Yield in VBF l', zttYieldVBFloose

    #     print '      Scaling by', zttYieldVBFloose/zttYield2Jet * zlYield2Jet/zlYieldVBFloose

    #     osQCD.Hist('Ztt_ZL').Scale(zttYieldVBFloose/zttYield2Jet * zlYield2Jet/zlYieldVBFloose)
    if cat_J1B in cut:
        print 'INFO: Subtracting 1.5% of the Ztt yield from the ttbar yield in the 1 b-tag category'
        scaleZtt = osQCD.Hist('Ztt').Integral()
        scaleTT = osQCD.Hist('TTJets').Integral()
        scaleTTNew = scaleTT - scaleZtt * 0.015
        osQCD.Hist('TTJets').Scale(scaleTTNew / scaleTT)

    # osQCD.Group('electroweak', ['WJets', 'Ztt_ZL', 'Ztt_ZJ','VV'])
    osQCD.Group('electroweak', ['WJets', 'Ztt_ZJ', 'VV', 'Ztt_TL'])
    osQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])
    return ssign, osign, ssQCD, osQCD
                                15,
                                60,
                                120,
                                cutwJ2,
                                weight=weight,
                                embed=options.embed)

    if vbf_eff is None:
        # QCD VBF, SS, anti-isolation, for QCD efficiency
        vbf_qcd_cut = '&&'.join([inc_qcd_cut, cat_VBF, 'diTau_charge!=0'])
        vbf_qcd_ssQCD = H2TauTauDataMC(options.hist,
                                       anaDir,
                                       selComps,
                                       weights,
                                       NBINS,
                                       XMIN,
                                       XMAX,
                                       cut=vbf_qcd_cut,
                                       weight=weight,
                                       embed=embed,
                                       treeName='H2TauTauTreeProducerTauEle')

        vbf_qcd_yield = vbf_qcd_ssQCD.Hist('Data').Integral()

        vbf_eff = vbf_qcd_yield / inc_qcd_yield

    print 'VBF Efficiency = ', vbf_eff

    osign, osQCD = makePlot(options.hist,
                            weights,
                            fwss,
コード例 #13
0
                                weights,
                                15,
                                60,
                                120,
                                cutwJ2,
                                weight=weight,
                                embed=options.embed)

    if vbf_eff is None:
        # QCD VBF, SS, anti-isolation, for QCD efficiency
        vbf_qcd_cut = '&&'.join([inc_qcd_cut, cat_VBF, 'diTau_charge!=0'])
        vbf_qcd_ssQCD = H2TauTauDataMC(options.hist,
                                       anaDir,
                                       selComps,
                                       weights,
                                       NBINS,
                                       XMIN,
                                       XMAX,
                                       cut=vbf_qcd_cut,
                                       weight=weight,
                                       embed=embed)

        vbf_qcd_yield = vbf_qcd_ssQCD.Hist('Data').Integral()

        vbf_eff = vbf_qcd_yield / inc_qcd_yield

    print 'VBF Efficiency = ', vbf_eff

    osign, osQCD = makePlot(options.hist,
                            weights,
                            fwss,
                            fwos,
コード例 #14
0
def makePlot( var, anaDir, selComps, weights, wJetScaleSS, wJetScaleOS,
              w_mt_ratio_ss, w_mt_ratio_os, w_mt_ratio,
              nbins=None, xmin=None, xmax=None,
              cut='', weight='weight', embed=False, shift=None, replaceW=False,
              VVgroup=None, antiEleIsoForQCD=False):
    
    print 'making the plot:', var, 'cut', cut

    oscut = cut+' && diTau_charge==0'
    osign = H2TauTauDataMC(var, anaDir,
                           selComps, weights, nbins, xmin, xmax,
                           cut=oscut, weight=weight, shift=shift,
                           embed=embed,
                           treeName = 'H2TauTauTreeProducerTauEle')
    osign.Hist(EWK).Scale( wJetScaleOS ) # * w_mt_ratio / w_mt_ratio_os )
    
    if cut.find('mt<')!=-1:
        print 'correcting high->low mT extrapolation factor, OS', w_mt_ratio / w_mt_ratio_os
        osign.Hist(EWK).Scale( w_mt_ratio / w_mt_ratio_os )

    replaceW = False
    if replaceW:
        osign = replaceShapeInclusive(osign, var, anaDir,
                                      selComps['WJets'], weights, 
                                      oscut, weight,
                                      embed, shift)
    sscut = cut+' && diTau_charge!=0'
    ssign = H2TauTauDataMC(var, anaDir,
                           selComps, weights, nbins, xmin, xmax,
                           cut=sscut, weight=weight, shift=shift,
                           embed=embed,
                           treeName = 'H2TauTauTreeProducerTauEle')
    ssign.Hist(EWK).Scale( wJetScaleSS )
    if cut.find('mt<')!=-1:
        print 'correcting high->low mT extrapolation factor, SS', w_mt_ratio / w_mt_ratio_ss
        ssign.Hist(EWK).Scale( w_mt_ratio / w_mt_ratio_ss  ) 
    if replaceW:
        ssign = replaceShapeInclusive(ssign, var, anaDir,
                                      selComps['WJets'], weights, 
                                      sscut, weight,
                                      embed, shift)
    if VVgroup:
        ssign.Group('VV',VVgroup)
        osign.Group('VV',VVgroup)
    
    ssQCD, osQCD = getQCD( ssign, osign, 'Data' )
    if antiEleIsoForQCD:
        print 'WARNING RELAXING ISO FOR QCD SHAPE'
        # replace QCD with a shape obtained from data in an anti-iso control region
        qcd_yield = osQCD.Hist('QCD').Integral()
        
        # sscut_qcdshape = cut.replace('l2_relIso05<0.1','l2_relIso05>0.2 && l2_relIso05<0.5') + ' && diTau_charge!=0' 
        sscut_qcdshape = cut.replace('l2_relIso05<0.1','l2_relIso05>0.2 && l2_relIso05<0.5').replace('l1_looseMvaIso>0.5', 'l1_rawMvaIso>0.7') + ' && diTau_charge!=0'
        ssign_qcdshape = H2TauTauDataMC(var, anaDir,
                                        selComps, weights, nbins, xmin, xmax,
                                        cut=sscut_qcdshape, weight=weight,
                                        embed=embed,
                                        treeName = 'H2TauTauTreeProducerTauEle')
        qcd_shape = copy.deepcopy( ssign_qcdshape.Hist('Data') )    
        qcd_shape.Normalize()
        qcd_shape.Scale(qcd_yield)
        # qcd_shape.Scale( qcd_yield )
        osQCD.Replace('QCD', qcd_shape)

    # osQCD.Group('VV', ['WW','WZ','ZZ'])
    osQCD.Group('electroweak', ['WJets', 'Ztt_ZJ','VV'])
    osQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])
    return ssign, osign, ssQCD, osQCD
コード例 #15
0
    #PG fw_ss = W normalization factor for the same sign plots
    #PG fw_os = W normalization factor for the opposite sign plots
    #PG ss   = mt plot with the scaled W, according to fw_ss
    #PG os   = mt plot with the scaled W, according to fw_os

    #PG (TEST) remake the WJets plots over the full range for SS
    #PG ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
    #PG with the binning I want

    cut_ss = '{cut} && diTau_charge!=0'.format(cut=cutw)
    FULL_mt_ss = H2TauTauDataMC(
        'mt',
        anaDir,
        selComps,
        weights,  #PG prepare the plot
        30,
        0,
        200,
        cut=cut_ss,
        weight=weight,
        embed=options.embed,
        treeName='H2TauTauTreeProducerTauEle')
    FULL_mt_ss.Hist('WJets').Scale(fw_ss)

    if cfg.VVgroup != None:
        FULL_mt_ss.Group('VV', cfg.VVgroup)

    # WJets_data = data - DY - TTbar
    FULL_mt_ss_wjet = copy.deepcopy(
        FULL_mt_ss.Hist(dataName))  #PG isolate data and subtract
    FULL_mt_ss_wjet.Add(FULL_mt_ss.Hist('Ztt'),
                        -1)  #PG non-WJets bkgs (but QCD)
コード例 #16
0
def makePlot(var,
             weights,
             wJetScaleSS,
             wJetScaleOS,
             vbf_qcd_yield,
             nbins,
             xmin,
             xmax,
             cut,
             weight='weight',
             embed=False,
             shift=None):

    if nbins is None: nbins = NBINS
    # if xmin is None: xmin = XMIN
    # if xmax is None: xmax = XMAX

    #PG prepare the final plot, that will be modified in the subsequent lines
    #PG ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

    oscut = '&&'.join([cat_Inc, cat_VBF, 'diTau_charge==0', cut])
    # oscut = str(inc_sig & Cut('l1_charge*l2_charge<0 && mt<40') & cat_VBF)
    print '[OS]', oscut
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           shift=shift,
                           embed=embed,
                           treeName='H2TauTauTreeProducerTauEle')
    osign.Hist(EWK).Scale(wJetScaleOS)

    #PG get the W+jets shape with loose VBF and loose isolation
    #PG ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

    wjshape = WJets_shape_VBF(var, anaDir, cutwJ2, selComps, zComps, weights,
                              nbins, xmin, xmax, weight, embed, shift)
    wjshape.Scale(osign.Hist('WJets').Integral())
    osign.Replace('WJets', wjshape)

    #PG get the QCD shape from SS with relaxed cuts
    #PG ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

    sscut = ' && '.join(
        [cat_Inc_AntiEleTauIsoCERNShape, 'diTau_charge!=0', cut, cat_VBF])
    print '[SS]', sscut
    ssign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=sscut,
                           weight=weight,
                           shift=shift,
                           embed=embed,
                           treeName='H2TauTauTreeProducerTauEle')

    ssQCD = addQCD(ssign, 'Data')

    qcd_shape = ssQCD.Hist('QCD')
    qcd_shape_before = copy.deepcopy(qcd_shape)
    qcd_shape.Scale(vbf_qcd_yield / qcd_shape.Integral())

    #PG prepare the final plot
    #PG ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

    osQCD = copy.deepcopy(osign)
    osQCD.AddHistogram('QCD', qcd_shape.weighted, 1.5)

    osQCD.Group('VV', ['WW', 'WZ', 'ZZ'])
    osQCD.Group('EWK', ['WJets', 'Ztt_ZL', 'Ztt_ZJ'])
    osQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])

    return qcd_shape_before, osign, osQCD
コード例 #17
0
def makePlot(var,
             weights,
             w_yield,
             vbf_qcd_yield,
             vbf_zl_yield,
             vbf_zj_yield,
             nbins,
             xmin,
             xmax,
             cut,
             weight='weight',
             embed=False,
             shift=None,
             VVgroup=None):

    oscut = '&&'.join([cat_Inc, cat_VBF, 'diTau_charge==0', cut])
    # oscut = str(inc_sig & Cut('l1_charge*l2_charge<0 && mt<40') & cat_VBF)
    print '[OS]', oscut
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           shift=shift,
                           embed=embed,
                           treeName='H2TauTauTreeProducerTauEle')

    # osign.Hist(EWK).Scale( wJetScaleOS )
    # import pdb; pdb.set_trace()
    # if cut.find('mt<')!=-1:
    #    print 'correcting high->low mT extrapolation factor, OS', w_mt_ratio / w_mt_ratio_os
    #    osign.Hist(EWK).Scale( w_mt_ratio / w_mt_ratio_os )
    osign.Hist('WJets').Normalize()
    osign.Hist('WJets').Scale(w_yield)

    cut_shape = ' && '.join([cut, cut_VBF_Rel_W])

    def replaceShape(compName):
        print compName, 'shape replaced', cut_shape
        nshape = shape(var,
                       anaDir,
                       selComps[compName],
                       weights,
                       nbins,
                       xmin,
                       xmax,
                       cut_shape,
                       weight,
                       embed,
                       shift,
                       treeName='H2TauTauTreeProducerTauEle')
        nshape.Scale(osign.Hist(compName).Integral())
        osign.Replace(compName, nshape)

    #  import pdb; pdb.set_trace()
    replaceShape('WJets')
    replaceShape('TTJets')
    for vvname in VVgroup:
        replaceShape(vvname)

    # ZL and ZJ shapes
    dycomp = selComps['Ztt']
    dyplot = buildPlot(var,
                       anaDir, {dycomp.name: dycomp},
                       weights,
                       nbins,
                       xmin,
                       xmax,
                       cut_shape,
                       weight,
                       embed,
                       shift,
                       treeName='H2TauTauTreeProducerTauEle')
    zlshape = dyplot.Hist('Ztt_ZL')
    zlshape.Scale(vbf_zl_yield / zlshape.Integral())
    osign.Replace('Ztt_ZL', zlshape)
    zjshape = dyplot.Hist('Ztt_ZJ')
    zjshape.Scale(vbf_zj_yield / zjshape.Integral())
    osign.Replace('Ztt_ZJ', zjshape)

    # Ztt shape
    # from embedded samples, with relaxed cut

    embComps = dict(
        (comp.name, comp) for comp in selComps.values() if comp.isEmbed)
    emb_plot = buildPlot(var,
                         anaDir,
                         embComps,
                         weights,
                         nbins,
                         xmin,
                         xmax,
                         cut_shape,
                         weight,
                         embed,
                         treeName='H2TauTauTreeProducerTauEle')
    names = []
    for h in emb_plot.histos:
        h.stack = True
        names.append(h.name)
    emb_plot.Group('Embed', names)
    zttshape = emb_plot.Hist('Embed')
    zttshape.Scale(osign.Hist('Ztt').Integral() / zttshape.Integral())
    osign.Replace('Ztt', zttshape)

    qcd_cut = '&&'.join(
        [cat_Inc_AntiEleTauIsoJosh, 'diTau_charge!=0', cat_VBF_Rel_20, cut])
    print 'QCD shape', qcd_cut
    qcd_plot = buildPlot(options.hist,
                         anaDir,
                         dataComps,
                         weights,
                         NBINS,
                         XMIN,
                         XMAX,
                         qcd_cut,
                         weight,
                         options.embed,
                         treeName='H2TauTauTreeProducerTauEle')
    qcd_shape = qcd_plot.Hist('Data')
    qcd_shape.Scale(vbf_qcd_yield / qcd_shape.Integral())

    osQCD = copy.deepcopy(osign)
    osQCD.AddHistogram('QCD', qcd_shape.weighted, 1.5)
    osQCD.Hist('QCD').stack = True
    osQCD.Hist('QCD').SetStyle(sHTT_QCD)

    osQCD.Group('VV', VVgroup)
    osQCD.Group('ZL', ['Ztt_ZJ', 'Ztt_ZL'])
    osQCD.Group('EWK', ['WJets', 'VV'])
    osQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])

    return osign, osQCD
def makePlot(var,
             weights,
             wJetScaleSS,
             wJetScaleOS,
             vbf_qcd_yield,
             nbins,
             xmin,
             xmax,
             cut,
             weight='weight',
             embed=False,
             shift=None):

    if nbins is None: nbins = NBINS
    # if xmin is None: xmin = XMIN
    # if xmax is None: xmax = XMAX

    oscut = '&&'.join([cat_Inc, cat_VBF, 'diTau_charge==0', cut])
    # oscut = str(inc_sig & Cut('l1_charge*l2_charge<0 && mt<40') & cat_VBF)
    print '[OS]', oscut
    osign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=oscut,
                           weight=weight,
                           shift=shift,
                           embed=embed,
                           treeName='H2TauTauTreeProducerTauEle')
    osign.Hist(EWK).Scale(wJetScaleOS)

    wjshape = WJets_shape_VBF(var, anaDir, cutwJ2, selComps, zComps, weights,
                              nbins, xmin, xmax, weight, embed, shift)
    wjshape.Scale(osign.Hist('WJets').Integral())
    osign.Replace('WJets', wjshape)

    sscut = ' && '.join(
        [cat_Inc_AntiMuTauIso_B, 'diTau_charge!=0', cut, cat_VBF])
    print '[SS]', sscut
    ssign = H2TauTauDataMC(var,
                           anaDir,
                           selComps,
                           weights,
                           nbins,
                           xmin,
                           xmax,
                           cut=sscut,
                           weight=weight,
                           shift=shift,
                           embed=embed,
                           treeName='H2TauTauTreeProducerTauEle')

    ssQCD = addQCD(ssign, 'Data')

    qcd_shape = ssQCD.Hist('QCD')
    qcd_shape.Scale(vbf_qcd_yield / qcd_shape.Integral())

    osQCD = copy.deepcopy(osign)
    osQCD.AddHistogram('QCD', qcd_shape.weighted, 1.5)

    osQCD.Group('VV', ['WW', 'WZ', 'ZZ'])
    osQCD.Group('EWK', ['WJets', 'Ztt_ZL', 'Ztt_ZJ'])
    osQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])

    return osign, osQCD
コード例 #19
0
def makePlot( var, anaDir, selComps, weights, wJetYieldSS, wJetYieldOS,
              nbins=None, xmin=None, xmax=None,
              cut='', weight='weight', embed=False):
    
    print 'making the plot:', var, 'cut', cut
    # if nbins is None: nbins = NBINS
    # if xmin is None: xmin = XMIN
    # if xmax is None: xmax = XMAX


    oscut = cut+' && diTau_charge==0'
    osign = H2TauTauDataMC(var, anaDir,
                           selComps, weights, nbins, xmin, xmax,
                           cut=oscut, weight=weight,
                           embed=embed)
    # osign.Hist(EWK).Scale( wJetScaleOS )
    osign.Hist(EWK).Normalize()
    osign.Hist(EWK).Scale(wJetYieldOS)    
    replaceWJets = True
    if replaceWJets:
        osign = replaceShapeInclusive(osign, var, anaDir,
                                      selComps['WJets'], weights, 
                                      oscut, weight,
                                      embed)
    
    sscut = cut+' && diTau_charge!=0'
    ssign = H2TauTauDataMC(var, anaDir,
                           selComps, weights, nbins, xmin, xmax,
                           cut=sscut, weight=weight,
                           embed=embed)
    # ssign.Hist(EWK).Scale( wJetScaleSS ) 
    # import pdb; pdb.set_trace()
    ssign.Hist(EWK).Normalize()
    ssign.Hist(EWK).Scale(wJetYieldSS)    
    if replaceWJets:
        ssign = replaceShapeInclusive(ssign, var, anaDir,
                                      selComps['WJets'], weights, 
                                      sscut, weight,
                                      embed)

    ssQCD, osQCD = getQCD( ssign, osign, 'Data' )

    
    qcd_yield = osQCD.Hist('QCD').Integral()

    # replace the QCD shape by the one obtained from the data in the isolation sideband
    sscut_qcdshape = cut.replace('l2_relIso05<0.1','l2_relIso05>0.2').replace('l1_looseMvaIso>0.5', 'l1_rawMvaIso>-0.75') + ' && diTau_charge!=0' 
    ssign_qcdshape = H2TauTauDataMC(var, anaDir,
                                    selComps, weights, nbins, xmin, xmax,
                                    cut=sscut_qcdshape, weight=weight,
                                    embed=embed)
    # import pdb; pdb.set_trace()
    # ssign.Hist(EWK).Scale( wJetScaleSS ) 
    qcd_shape = copy.deepcopy( ssign_qcdshape.Hist('Data') )    
    qcd_shape.Normalize()
    qcd_shape.Scale(qcd_yield)
    # qcd_shape.Scale( qcd_yield )
    osQCD.Replace('QCD', qcd_shape)
    # import pdb; pdb.set_trace()
    if var!='mt':
        osQCD.Hist('QCD').Scale( 1618. / 1860.)
    osQCD.Group('VV', ['WW','WZ','ZZ'])
    osQCD.Group('EWK', ['WJets', 'Ztt_ZL', 'Ztt_ZJ','VV'])
    osQCD.Group('Higgs 125', ['HiggsVBF125', 'HiggsGGH125', 'HiggsVH125'])
    
    return ssign, osign, ssQCD, osQCD
コード例 #20
0
def makePlot( var, weights, wJetScaleSS, wJetScaleOS,
              nbins=None, xmin=None, xmax=None,
              weight='weight', embed=False):
    
    if nbins is None: nbins = NBINS
    if xmin is None: xmin = XMIN
    if xmax is None: xmax = XMAX

    oscut = str(inc_sig & Cut('l1_charge*l2_charge<0 && mt<40') & cat_VBF)
    print '[OS]', oscut
    osign = H2TauTauDataMC(var, anaDir,
                           selComps, weights, nbins, xmin, xmax,
                           cut=oscut, weight=weight,
                           embed=embed)
    osign.Hist(EWK).Scale( wJetScaleOS ) 

    import pdb; pdb.set_trace()
    # osign = replaceWJets(osign, var, oscut, weight, embed)
    # osign = replaceZtt(osign, var, oscut, weight, embed)
    wjshape = WJets_shape_VBF(var, anaDir, cutw,
                              selComps, zComps, weights,
                              nbins, xmin, xmax, weight,
                              embed)
    wjshape.Scale( osign.Hist('WJets').Integral() )
    osign.Replace('WJets', wjshape )



    antisocut = str( Cut(cat_Inc_AntiMuTauIso) &  Cut('l1_charge*l2_charge<0 && mt<40') & cat_VBF )
    fakeweight = ' * '.join( [weight, colin_qcdTauIsoRatio, colin_qcdMuIsoRatio])

    antiso = H2TauTauDataMC(var, anaDir,
                            selComps, weights, nbins, xmin, xmax,
                            cut=antisocut, weight=weight,
                            embed=embed)
    # here, would need to replace with the same dilep cut!
    # antiso = replaceWJets(antiso, var, antisocut, weight, embed)
    # antiso = replaceZtt(antiso, var, antisocut, weight, embed)    
    antisoQCD = addQCD( antiso, 'Data')

    # now get the QCD yield:
    antisoForYield = H2TauTauDataMC(var, anaDir,
                                    selComps, weights, nbins, xmin, xmax,
                                    cut=antisocut, weight=fakeweight,
                                    embed=embed)

    # antisoForYield = replaceWJets(antisoForYield, var, antisocut, fakeweight, embed)


    # antisoForYield = replaceZtt(antisoForYield, var, antisocut, fakeweight, embed)

    # antisoForYieldQCD = addQCD( antisoForYield, 'Data')

    # import pdb; pdb.set_trace()
    qcdyield = antisoForYield.Hist('Data').Integral()
    # ASSUMING ONLY QCD IN ANTI-ISO REGION
    qcd = copy.deepcopy(antisoQCD.Hist('Data'))
    qcd.weighted.SetFillStyle(1001)
    qcd.stack = True
    qcd.Normalize()
    qcd.Scale(qcdyield)

    osQCD = copy.deepcopy( osign )
    osQCD.AddHistogram('QCD', qcd.weighted, 1.5 )
    
    # boxss = box.replace('OS','SS')
    # sscut = str(inc_sig & Cut('l1_charge*l2_charge>0') & cat_VBF)
##     sscut = ' && '.join( [cat_Inc_RlxMuIso, 'l1_charge*l2_charge>0', cat_VBF] )
##     print '[SS]', sscut
##     ssign = H2TauTauDataMC(var, anaDir,
##                            selComps, weights, nbins, xmin, xmax,
##                            cut=sscut, weight=weight,
##                            embed=embed)
##     ssign.Hist(EWK).Scale( wJetScaleSS ) 
##     ssign = replaceWJets(ssign, var, 'l1_charge*l2_charge>0 && mt<40' , weight, embed)
##     ssign = replaceZtt(ssign, var, 'l1_charge*l2_charge>0 && mt<40' , weight, embed)

##     ssQCD, osQCD = getQCD_VBF( ssign, osign, 'Data' )

    # osQCD = osign
    groupEWK( osQCD )
    return antiso, osign, antisoQCD, osQCD