Beispiel #1
0
def makePhoton( event, sample, level ):
    ''' Make a Photon vector to facilitate further calculations
    '''
    preTag = 'reco' if level == 'reco' else 'gen'

    if level == 'reco':
        photonList = ['pt', 'eta', 'phi', 'isolationVar', 'isolationVarRhoCorr', 'sumPtCharged', 'sumPtNeutral', 'sumPtChargedPU', 'sumPt', 'ehadOverEem', 'genIndex', 'minLeptonPt', 'minLeptonDR', 'minJetDR']
    else:
        photonList = ['pt', 'eta', 'phi', 'mass', 'motherPdgId', 'relIso04', 'minLeptonDR', 'minJetDR'] #'minLeptonPt'

    event.gammas = getCollection( event, '%sPhoton'%preTag, photonList, 'n%sPhoton'%preTag )

    event.gamma0 = event.gammas[0] if len(event.gammas)>0 else nanPhoton()
    event.gamma1 = event.gammas[1] if len(event.gammas)>1 else nanPhoton()
    event.gamma2 = event.gammas[2] if len(event.gammas)>2 else nanPhoton()

    if level == 'reco':
        for p in [event.gamma2, event.gamma1, event.gamma0]:
            addIDeltaBeta( p )

    event.gamma_unitVec2D = UnitVectorT2( event.gamma0['phi'] )
    event.gamma_vec4D     = ROOT.TLorentzVector()
    event.gamma_vec4D.SetPtEtaPhiM( event.gamma0['pt'], event.gamma0['eta'], event.gamma0['phi'], 0 )
    event.gamma_unitVec3D = event.gamma_vec4D.Vect().Unit()

    # Import additional functions/classes specified for the level of reconstruction
    if level == 'reco':      from TTXPheno.Tools.objectSelection      import isGoodRecoPhoton     as isGoodPhoton
    else:                    from TTXPheno.Tools.objectSelection      import isGoodGenPhoton      as isGoodPhoton

    event.foundGamma0    = isGoodPhoton( event.gamma0 )
    event.foundGamma1    = isGoodPhoton( event.gamma1 )
    event.foundGamma2    = isGoodPhoton( event.gamma2 )

    event.passing_photons =  event.foundGamma0
Beispiel #2
0
def makeJets( event, sample, level ):
    ''' Add a list of filtered jets to the event (full list is required for lepton cross cleaning)
    '''
    preTag = 'reco' if level == 'reco' else 'gen'
    tag    = 'reco' if level == 'reco' else 'genLep'

    # load jets
    btag = 'bTag' if level == 'reco' else 'matchBParton'
    event.jets = getCollection( event, '%sJet'%preTag, ['pt', 'eta', 'phi', btag ], 'n%sJet'%preTag )
    event.bjets = list( filter( lambda j: j[btag], event.jets ) )

    # get (second) hardest bjets
    event.bj0 = {'pt':getattr( event, '%sBj0_pt'%preTag ), 'phi':getattr( event, '%sBj0_phi'%preTag ), 'eta':getattr( event, '%sBj0_eta'%preTag )}
    event.bj1 = {'pt':getattr( event, '%sBj1_pt'%preTag ), 'phi':getattr( event, '%sBj1_phi'%preTag ), 'eta':getattr( event, '%sBj1_eta'%preTag )}

    # Define leptonic b-jets
    event.bj0lep = getObjDict( event, '%sJet_'%preTag, ['pt', 'eta', 'phi'], getattr( event, '%sBjLeadlep_index'%preTag ) ) if getattr( event, '%sBjLeadlep_index'%preTag ) >= 0 else nanJet()
#    event.bj0had = getObjDict( event, '%sJet_'%preTag, ['pt', 'eta', 'phi'], getattr( event, '%sBjLeadhad_index'%preTag ) ) if getattr( event, '%sBjLeadlep_index'%preTag ) >= 0 else nanJet()

    # Add extra vectors
    for p in [event.bj0, event.bj1, event.bj0lep]:
        addTransverseVector( p )
        addTLorentzVector( p )

    # Import additional functions/classes specified for the level of reconstruction
    if level == 'reco':      from TTXPheno.Tools.objectSelection      import isGoodRecoJet     as isGoodJet
    else:                    from TTXPheno.Tools.objectSelection      import isGoodGenJet      as isGoodJet

    # selection checks
    event.foundBj0 = isGoodJet( event.bj0 )
#    event.foundBj0lep    = getattr( event, '%sBjLeadlep_index'%preTag ) >= 0 and isGoodJet( event.bj0lep )

    # choose your selection on b-jets
    event.passing_bjets = event.foundBj0
Beispiel #3
0
def makeLeps( event, sample, level, flavorCheck ):
    ''' Add important leptons (no full list of leptons is required for now)
    '''
    preTag = 'reco' if level == 'reco' else 'gen'
    tag    = 'reco' if level == 'reco' else 'genLep'

    if level == 'reco':
        leptonList = ['pt', 'eta', 'phi', 'pdgId', 'isolationVar', 'isolationVarRhoCorr', 'sumPtCharged', 'sumPtNeutral', 'sumPtChargedPU', 'sumPt', 'ehadOverEem', 'genIndex']
    else:
        leptonList = ['pt', 'eta', 'phi', 'pdgId', 'motherPdgId']

    event.leps = getCollection( event, '%sLep'%preTag, leptonList, 'n%sLep'%preTag )

    # Define hardest leptons
    event.l0 = event.leps[0]
    addTransverseVector( event.l0 )
    addTLorentzVector( event.l0 )
    if level == 'reco': addIDeltaBeta( event.l0 )

    # Import additional functions/classes specified for the level of reconstruction
    if level == 'reco': from TTXPheno.Tools.objectSelection      import isGoodRecoLepton  as isGoodLepton
    else:               from TTXPheno.Tools.objectSelection      import isGoodGenLepton   as isGoodLepton

    # We may loose some events by cross-cleaning or by thresholds.
    event.found1lep    = isGoodLepton( event.l0 ) and len(event.leps) == 1
    if flavorCheck == 'e': event.found1lep = event.found1lep and abs(event.l0['pdgId'])==11
    elif flavorCheck == 'mu': event.found1lep = event.found1lep and abs(event.l0['pdgId'])==13
    
    # choose your selection on leptons
    event.passing_leptons = event.found1lep
Beispiel #4
0
def makeJets(event, sample):
    ''' Add a list of filtered jets to the event
    '''
    # load jets
    event.jets = getCollection(event, 'GenJet',
                               ['pt', 'eta', 'phi', 'matchBParton'], 'nGenJet')

    # filter, pre-selection requires 3 leptons (no default leptons necessary)
    event.jets = list(filter(lambda j: isGoodGenJet(j), event.jets))

    # sort
    event.jets = sorted(event.jets, key=lambda k: -k['pt'])

    # Add extra vectors
    for p in event.jets:
        addTransverseVector(p)
        addTLorentzVector(p)

    # True B's
    event.trueBjets = list(filter(lambda j: j['matchBParton'], event.jets))
    event.trueNonBjets = list(
        filter(lambda j: not j['matchBParton'], event.jets))

    # Mimick b reconstruction ( if the trailing b fails acceptance, we supplement with the leading non-b jet )
    event.bj0, event.bj1 = (event.trueBjets + event.trueNonBjets +
                            [NanJet(), NanJet()])[:2]
Beispiel #5
0
def makeLeps(event, sample):
    ''' Add a list of filtered leptons to the event
    '''
    # load leps
    event.leps = getCollection(event, 'GenLep',
                               ['pt', 'eta', 'phi', 'pdgId', 'motherPdgId'],
                               'nGenLep')

    # filter, pre-selection requires 3 leptons (no default leptons necessary)
    event.leps = list(filter(lambda l: isGoodGenLepton(l), event.leps))

    # Cross-cleaning: remove leptons that overlap with a jet within 0.4
    event.leps = list(
        filter(lambda l: min([deltaR(l, j) for j in event.jets] + [999]) > 0.4,
               event.leps))

    # sort
    event.leps = sorted(event.leps, key=lambda l: -l['pt'])

    # Add extra vectors
    for p in event.leps:
        addTransverseVector(p)
        addTLorentzVector(p)

    # 2l
    event.l0, event.l1 = (event.leps + [NanLepton(), NanLepton()])[:2]

    # We may loose some events by cross-cleaning or by thresholds.
    event.passing_2lep = len(
        event.leps) >= 2 and event.l0['pdgId'] * event.l1['pdgId'] > 0.
Beispiel #6
0
def makeLeps( event, sample ):

    # Read leptons, do not yet filter
    event.leps = getCollection( event, 'GenLep', ['pt', 'eta', 'phi', 'pdgId', 'motherPdgId'], 'nGenLep' )
    # Add extra vectors
    for p in event.leps:
        addTransverseVector( p )
        addTLorentzVector( p )

    # Sort
    event.leps = sorted( event.leps, key=lambda k: -k['pt'] )

    # Cross-cleaning: remove leptons that overlap with a jet within 0.4
    # event.leps = list(filter( lambda l: min( [ deltaR(l, j) for j in event.jets ] + [999] ) > 0.4 , event.leps ))

    # find leptons from Z
    event.lepsFromZ = list( filter( lambda j: j['motherPdgId'] == 23 , event.leps ) )
    event.foundZ    = len( event.lepsFromZ )==2 and event.lepsFromZ[0]['pdgId'] * event.lepsFromZ[1]['pdgId'] < 0
    event.Z_deltaPhi_ll = deltaPhi( event.lepsFromZ[0]['phi'], event.lepsFromZ[1]['phi']) if event.foundZ else float('nan')
    event.Z_deltaR_ll   = deltaR( *event.lepsFromZ) if event.foundZ else float('nan')
 
    # convinience
    event.Z_unitVec2D = UnitVectorT2( event.Z_phi )
    event.Z_vec4D     = ROOT.TLorentzVector()
    event.Z_vec4D.SetPtEtaPhiM( event.Z_pt, event.Z_eta, event.Z_phi, event.Z_mass )
    event.Z_unitVec3D = event.Z_vec4D.Vect()
    #event.Z_unitVec3D /= event.Z_unitVec3D.Mag() 

    # find leptons that are NOT from Z 
    event.leptonsNotFromZ = [lepton for lepton in event.leps if lepton not in event.lepsFromZ] 

    # We may loose some events by cross-cleaning or by thresholds. Make a bool for that.
    event.passing_3lep    = event.foundZ and len(event.leptonsNotFromZ)==1
Beispiel #7
0
def makeJets( event, sample, level ):
    ''' Add a list of filtered jets to the event (full list is required for lepton cross cleaning)
    '''
    # load jets
    btag = 'bTag' if level == 'reco' else 'matchBParton'
    event.jets = getCollection( event, '%sJet'%preTag, ['pt', 'eta', 'phi', btag ], 'n%sJet'%preTag )
    event.bjets = list( filter( lambda j: j[btag], event.jets ) )
        
    # get (second) hardest bjets
    event.bj0 = {'pt':getattr( event, '%sBj0_pt'%preTag ), 'phi':getattr( event, '%sBj0_phi'%preTag ), 'eta':getattr( event, '%sBj0_eta'%preTag )}
    event.bj1 = {'pt':getattr( event, '%sBj1_pt'%preTag ), 'phi':getattr( event, '%sBj1_phi'%preTag ), 'eta':getattr( event, '%sBj1_eta'%preTag )}

    # Add extra vectors
    for p in [event.bj0, event.bj1]:
        addTransverseVector( p )
        addTLorentzVector( p )

    event.ht = sum( [ j["pt"] for j in event.jets ] )

    # Import additional functions/classes specified for the level of reconstruction
    if level == 'reco': from TTXPheno.Tools.objectSelection  import isGoodRecoJet       as isGoodJet
    else:               from TTXPheno.Tools.objectSelection  import isGoodGenJet        as isGoodJet

    # selection checks
    event.foundBj0 = isGoodJet( event.bj0 )
    if len(event.jets) > 1:
        event.foundBj1 = isGoodJet( event.bj1 )
    else: 
        event.foundBj1 = True

    # choose your selection on b-jets
    event.passing_bjets = event.foundBj0 and event.foundBj1
Beispiel #8
0
def makeJets( event, sample, level ):
    ''' Add a list of filtered jets to the event (full list is required for lepton cross cleaning)
    '''
    preTag = 'reco' if level == 'reco' else 'gen'
    tag    = 'reco' if level == 'reco' else 'genLep'

    # Import additional functions/classes specified for the level of reconstruction
    if level == 'reco': from TTXPheno.Tools.objectSelection      import isGoodRecoJet     as isGoodJet
    else:               from TTXPheno.Tools.objectSelection      import isGoodGenJet      as isGoodJet

    # load jets
    btag = 'bTag_medium' if level == 'reco' else 'matchBParton'
    event.jets = getCollection( event, '%sJet'%preTag, ['pt', 'eta', 'phi', btag, 'nNeutrals', 'nCharged' ], 'n%sJet'%preTag )
#    event.jets = list( filter( lambda j: isGoodJet(j), event.jets ) )

    # Define leptonic b-jets
    event.bj0lep = getObjDict( event, '%sJet_'%preTag, ['pt', 'eta', 'phi', 'nNeutrals', 'nCharged'], getattr( event, '%sBjLeadlep_index'%preTag ) ) if getattr( event, '%sBjLeadlep_index'%preTag ) >= 0 else nanJet()
    event.bj0had = getObjDict( event, '%sJet_'%preTag, ['pt', 'eta', 'phi', 'nNeutrals', 'nCharged'], getattr( event, '%sBjLeadhad_index'%preTag ) ) if getattr( event, '%sBjLeadhad_index'%preTag ) >= 0 else nanJet()

    # Define non-Z b-jets
    event.bjNonZlep = getObjDict( event, '%sJet_'%preTag, ['pt', 'eta', 'phi', 'nNeutrals', 'nCharged'], getattr( event, '%sBjNonZlep_index'%preTag ) ) if getattr( event, '%sBjNonZlep_index'%preTag ) >= 0 else nanJet()
    event.bjNonZhad = getObjDict( event, '%sJet_'%preTag, ['pt', 'eta', 'phi', 'nNeutrals', 'nCharged'], getattr( event, '%sBjNonZhad_index'%preTag ) ) if getattr( event, '%sBjNonZhad_index'%preTag ) >= 0 else nanJet()

    # get (second) hardest bjets
    event.bj0 = {'pt':getattr( event, '%sBj0_pt'%preTag ), 'phi':getattr( event, '%sBj0_phi'%preTag ), 'eta':getattr( event, '%sBj0_eta'%preTag ), 'nNeutrals':getattr( event, '%sBj0_nNeutrals'%preTag ), 'nCharged':getattr( event, '%sBj0_nCharged'%preTag )}
    event.bj1 = {'pt':getattr( event, '%sBj1_pt'%preTag ), 'phi':getattr( event, '%sBj1_phi'%preTag ), 'eta':getattr( event, '%sBj1_eta'%preTag ),  'nNeutrals':getattr( event, '%sBj0_nNeutrals'%preTag ), 'nCharged':getattr( event, '%sBj0_nCharged'%preTag )}

    # Add extra vectors
    for p in [event.bj0, event.bj1, event.bj0lep, event.bj0had, event.bjNonZlep, event.bjNonZhad]:
        addTransverseVector( p )
        addTLorentzVector( p )
Beispiel #9
0
def addZCut(event, sample):
    recoLep = getCollection(
        event, 'recoLep',
        ["pt", "eta", "phi", "pdgId", "sumPt", "isolationVar"], 'nrecoLep')
    recoLep = list(filter(lambda l: isGoodRecoLepton(l), recoLep))
    #    recoLep = list( filter( lambda l: (l["sumPt"]-l["pt"])/l["pt"] < 0.2, recoLep ) )
    recoLep = list(filter(lambda l: l["isolationVar"] < 0.2, recoLep))
    event.nrecoLep = len(recoLep)

    event.recoZ_mass = -999  #float("nan")
    event.recoZ_pt = -999  #float("nan")
    event.recoZ_phi = -999  #float("nan")
    event.recoZ_eta = -999  #float("nan")
    event.recoZ_lldPhi = -999  #float("nan")
    event.recoZ_lldR = -999  #float("nan")

    if event.nrecoLep < 2:
        event.lumiweight1fb = 0
        return

    if event.nrecoLep > 1:
        event.recoZ_mass, event.recoZ_l1_index, event.recoZ_l2_index = closestOSDLMassToMZ(
            recoLep)

        l1 = recoLep[event.recoZ_l1_index]
        l2 = recoLep[event.recoZ_l2_index]
        #        print deltaR(l1,l2), l1["pt"], l2["pt"], event.recoZ_l1_index, event.recoZ_l2_index, event.recoZ_mass
        if event.recoZ_mass:
            Z_l1 = ROOT.TLorentzVector()
            Z_l1.SetPtEtaPhiM(recoLep[event.recoZ_l1_index]['pt'],
                              recoLep[event.recoZ_l1_index]['eta'],
                              recoLep[event.recoZ_l1_index]['phi'], 0)
            Z_l2 = ROOT.TLorentzVector()
            Z_l2.SetPtEtaPhiM(recoLep[event.recoZ_l2_index]['pt'],
                              recoLep[event.recoZ_l2_index]['eta'],
                              recoLep[event.recoZ_l2_index]['phi'], 0)
            Z = Z_l1 + Z_l2
            event.recoZ_pt = Z.Pt()
            event.recoZ_eta = Z.Eta()
            event.recoZ_phi = Z.Phi()
            event.recoZ_lldPhi = deltaPhi(recoLep[event.recoZ_l1_index]['phi'],
                                          recoLep[event.recoZ_l2_index]['phi'])
            event.recoZ_lldR = deltaR(recoLep[event.recoZ_l1_index],
                                      recoLep[event.recoZ_l2_index])
            lm_index = event.recoZ_l1_index if recoLep[
                event.recoZ_l1_index]['pdgId'] > 0 else event.recoZ_l2_index
            event.recoZ_cosThetaStar = cosThetaStar(
                event.recoZ_mass, event.recoZ_pt, event.recoZ_eta,
                event.recoZ_phi, recoLep[lm_index]['pt'],
                recoLep[lm_index]['eta'], recoLep[lm_index]['phi'])

            if abs(event.recoZ_mass - 91) > 15:
                event.lumiweight1fb = 0
                return

        else:
            event.lumiweight1fb = 0
Beispiel #10
0
def makeLeps(event, sample):
    ''' Add a list of filtered leptons to the event
    '''
    # load leps
    event.leps = getCollection(event, 'GenLep',
                               ['pt', 'eta', 'phi', 'pdgId', 'motherPdgId'],
                               'nGenLep')

    # filter, pre-selection requires 3 leptons (no default leptons necessary)
    event.leps = list(filter(lambda l: isGoodGenLepton(l), event.leps))

    # Cross-cleaning: remove leptons that overlap with a jet within 0.4
    event.leps = list(
        filter(lambda l: min([deltaR(l, j) for j in event.jets] + [999]) > 0.4,
               event.leps))

    # sort
    event.leps = sorted(event.leps, key=lambda l: -l['pt'])

    # Add extra vectors
    for p in event.leps:
        addTransverseVector(p)
        addTLorentzVector(p)

    # find leptons from Z
    event.lepsFromZ = list(filter(lambda j: j['motherPdgId'] == 23,
                                  event.leps))
    event.foundZ = len(event.lepsFromZ) == 2 and event.lepsFromZ[0][
        'pdgId'] * event.lepsFromZ[1]['pdgId'] < 0 and abs(
            event.lepsFromZ[0]['pdgId']) == abs(event.lepsFromZ[1]['pdgId'])
    event.Z_deltaPhi_ll = deltaPhi(
        event.lepsFromZ[0]['phi'],
        event.lepsFromZ[1]['phi']) if event.foundZ else float('nan')
    event.Z_deltaR_ll = deltaR(
        *event.lepsFromZ) if event.foundZ else float('nan')

    # find leptons that are NOT from Z
    event.lepsNotFromZ = list(
        filter(lambda j: j['motherPdgId'] != 23, event.leps))

    # We may loose some events by cross-cleaning or by thresholds.
    event.passing_4lep = event.foundZ and len(
        event.lepsNotFromZ) >= 2 and event.lepsNotFromZ[0][
            'pdgId'] * event.lepsNotFromZ[1]['pdgId'] < 0.

    # Add default lepton if leptons got filtered
    event.lepsNotFromZ += [NanLepton(), NanLepton()]

    # Define non-Z leptons
    event.l0, event.l1 = event.lepsNotFromZ[:2]
Beispiel #11
0
def makeSpinCorrelationObservables( event, sample, level ):

    if level != 'gen': return
    event.tops = getCollection( event, 'genTop', ['pt', 'eta', 'phi'], 'ngenTop' )

    # We now match leptons and tops by charge
    # Once I have the gen-top pdgId, this code will be replaced by a gen-level based
    # matching which ensures that top_pos/lep_pos and top_neg/lep_neg are the top-parton/lepton pair with 'p'lus and 'm'inus charge.
    if len(event.tops)>=2 and event.l0['pdgId']*event.l1['pdgId']<0:
        if event.l0['pdgId']<0:
            event.lep_pos, event.lep_neg = event.l0, event.l1
            event.top_pos, event.top_neg = event.tops[:2]     # <- arbitrary for now! FIXME
        else:
            event.lep_pos, event.lep_neg = event.l1, event.l0
            event.top_pos, event.top_neg = event.tops[:2]     # <- arbitrary for now! FIXME

        # Alexander, here are the leptons (plus and minus): event.lep_pos, event.lep_neg 
        # Here are the tops (plus and minus): event.tp, event.tm

        # Store numbers, objects, etc. in the 'event' like this:
        # dPhi (repeated below, just a proof of principle, remove, FIXME)
        event.lldPhi = deltaPhi( event.lep_neg['phi'], event.lep_pos['phi'] )
Beispiel #12
0
def addBTag(event, sample):
    event.jets = getCollection(event, 'recoJet', ["bTag"], 'nrecoJet')
    event.nBTag = len(filter(lambda j: j["bTag"], event.jets))
Beispiel #13
0
def cleanLeptons(event, sample):
    recoLep = getCollection(
        event, 'recoLep',
        ["pt", "eta", "phi", "pdgId", "sumPt", "isolationVar"], 'nrecoLep')
    recoLep = list(filter(lambda l: isGoodRecoLepton(l), recoLep))
    #    recoLep = list( filter( lambda l: (l["sumPt"]-l["pt"])/l["pt"] < 0.2, recoLep ) )
    recoLep = list(filter(lambda l: l["isolationVar"] < 0.2, recoLep))

    #    recoLep.sort( key=lambda l: -l["pt"] )
    #    goodLeps = []
    #    for i_l, l1 in enumerate(recoLep):
    #        clean = True
    #        for j_l, l2 in enumerate(recoLep[:i_l]):
    #            if deltaR2(l1, l2)<0.4**2:
    #                clean = False
    #                break
    #        if clean: goodLeps.append(l1)

    goodLeps = recoLep
    event.recoLep = goodLeps
    event.nrecoLep = len(goodLeps)
    #    event.recoLep_pt = []
    #    event.recoLep_pt.append(goodLeps[0]["pt"])
    #    event.recoLep_pt.append(goodLeps[1]["pt"])
    #    event.recoLep_eta = []
    #    event.recoLep_eta.append(goodLeps[0]["eta"])
    #    event.recoLep_eta.append(goodLeps[1]["eta"])
    #    event.recoLep_phi = []
    #    event.recoLep_phi.append(goodLeps[0]["phi"])
    #    event.recoLep_phi.append(goodLeps[1]["phi"])

    event.recoZ_mass = -999  #float("nan")
    event.recoZ_pt = -999  #float("nan")
    event.recoZ_phi = -999  #float("nan")
    event.recoZ_eta = -999  #float("nan")
    event.recoZ_lldPhi = -999  #float("nan")
    event.recoZ_lldR = -999  #float("nan")

    if event.nrecoLep != 1:
        event.lumiweight1fb = 0
        return

    if event.nrecoLep > 1:
        event.recoZ_mass, event.recoZ_l1_index, event.recoZ_l2_index = closestOSDLMassToMZ(
            goodLeps)

        l1 = goodLeps[event.recoZ_l1_index]
        l2 = goodLeps[event.recoZ_l2_index]
        #        print deltaR(l1,l2), l1["pt"], l2["pt"], event.recoZ_l1_index, event.recoZ_l2_index, event.recoZ_mass
        if event.recoZ_mass:
            Z_l1 = ROOT.TLorentzVector()
            Z_l1.SetPtEtaPhiM(goodLeps[event.recoZ_l1_index]['pt'],
                              goodLeps[event.recoZ_l1_index]['eta'],
                              goodLeps[event.recoZ_l1_index]['phi'], 0)
            Z_l2 = ROOT.TLorentzVector()
            Z_l2.SetPtEtaPhiM(goodLeps[event.recoZ_l2_index]['pt'],
                              goodLeps[event.recoZ_l2_index]['eta'],
                              goodLeps[event.recoZ_l2_index]['phi'], 0)
            Z = Z_l1 + Z_l2
            event.recoZ_pt = Z.Pt()
            event.recoZ_eta = Z.Eta()
            event.recoZ_phi = Z.Phi()
            event.recoZ_lldPhi = deltaPhi(
                goodLeps[event.recoZ_l1_index]['phi'],
                goodLeps[event.recoZ_l2_index]['phi'])
            event.recoZ_lldR = deltaR(goodLeps[event.recoZ_l1_index],
                                      goodLeps[event.recoZ_l2_index])
            lm_index = event.recoZ_l1_index if goodLeps[
                event.recoZ_l1_index]['pdgId'] > 0 else event.recoZ_l2_index
            event.recoZ_cosThetaStar = cosThetaStar(
                event.recoZ_mass, event.recoZ_pt, event.recoZ_eta,
                event.recoZ_phi, goodLeps[lm_index]['pt'],
                goodLeps[lm_index]['eta'], goodLeps[lm_index]['phi'])

            if event.recoZ_lldPhi < 0.1 or event.recoZ_lldR < 0.1:
                event.lumiweight1fb = 0
                return

    event.recoJet = getCollection(
        event, 'recoJet',
        ["pt", "eta", "phi", "nCharged", "nNeutrals", "bTag"], 'nrecoJet')
    event.recoJet = list(filter(lambda l: isGoodRecoJet(l), event.recoJet))
    event.recoJet.sort(key=lambda l: -l["pt"])
    event.recoJet = list(
        filter(
            lambda j: min([999] + [deltaR2(j, p)
                                   for p in event.recoLep]) > 0.4**2,
            event.recoJet))
    event.nrecoJet = len(event.recoJet)

    event.nBTag = len(filter(lambda j: j["bTag"], event.recoJet))
Beispiel #14
0
def makeLeps( event, sample, level ):
    ''' Add important leptons (no full list of leptons is required for now)
    '''
    event.leps = getCollection( event, '%sLep'%preTag, ['pt', 'eta', 'phi', 'pdgId'], 'n%sLep'%preTag )     

    # Define hardest leptons
    event.l0 = event.leps[0]
    event.l1 = event.leps[1]
#    event.l2 = event.leps[2]

    # Add extra vectors
    for p in [ event.l0, event.l1]:
        addTransverseVector( p )
        addTLorentzVector( p )

    # Import additional functions/classes specified for the level of reconstruction
    if level == 'reco': from TTXPheno.Tools.objectSelection  import isGoodRecoLepton    as isGoodLepton
    else:               from TTXPheno.Tools.objectSelection  import isGoodGenLepton     as isGoodLepton

    # We may loose some events by cross-cleaning or by thresholds
    event.foundLep0    = isGoodLepton( event.l0 )
    event.foundLep1    = isGoodLepton( event.l1 ) 
    event.found2Leps   = len(event.leps) == 2
    event.mll          = (get4DVec(event.l0) + get4DVec(event.l1)).M()
    
    if( event.l0['pdgId'] * event.l1['pdgId'] > 0 ):
        event.sign = 1
    else:
        event.sign = -1

    if( event.l0['pdgId'] == -13 and event.l1['pdgId'] == -13 ):    
        event.index = 0
    elif( event.l0['pdgId'] == -11 and event.l1['pdgId'] == -11 ):
        event.index = 2
    elif( event.l0['pdgId'] == 13 and event.l1['pdgId'] == 13 ):
        event.index = 3
    elif( event.l0['pdgId'] == 11 and event.l1['pdgId'] == 11 ):
        event.index = 5
    elif( (event.l0['pdgId'] == -11 and event.l1['pdgId'] == -13) or (event.l0['pdgId'] == -13 and event.l1['pdgId'] == -11) ):
        event.index = 1
    elif( (event.l0['pdgId'] == 11 and event.l1['pdgId'] == 13) or (event.l0['pdgId'] == 13 and event.l1['pdgId'] == 11) ):
        event.index = 4


#    event.mll          = (get4DVec(event.l0) + get4DVec(event.l1) + get4DVec(event.l2)).M()
#    event.found3Leps   = len(event.leps) == 3
#    event.foundLep2    = isGoodLepton( event.l2 )
    
#    if( event.l0['pdgId']*event.l1['pdgId'] < 0 and abs(event.l0['pdgId']) == abs(event.l1['pdgId']) and abs((get4DVec(event.l0)+get4DVec(event.l1)).M() - 91.2) < 10 ):
#        event.OSSF = True
#    elif( event.l0['pdgId']*event.l2['pdgId'] < 0 and abs(event.l0['pdgId']) == abs(event.l2['pdgId']) and abs((get4DVec(event.l0)+get4DVec(event.l2)).M() - 91.2) < 10 ):
#        event.OSSF = True
#    elif( event.l1['pdgId']*event.l2['pdgId'] < 0 and abs(event.l1['pdgId']) == abs(event.l2['pdgId']) and abs((get4DVec(event.l1)+get4DVec(event.l2)).M() - 91.2) < 10):
#        event.OSSF = True
#    else:
#        event.OSSF = False

    #event.sameSign = event.l0['pdgId']*event.l1['pdgId'] > 0
    #event.oppositeSign = event.l0['pdgId']*event.l1['pdgId'] <0
    #event.sameFlavor   = abs(event.l0['pdgId']) == abs(event.l1['pdgId'])

    # choose your selection on leptons
    event.passing_leptons = event.foundLep0 and event.foundLep1 and event.mll > 12 and abs(event.mll-91.2) > 15 and event.found2Leps