Ejemplo n.º 1
0
def isCleanFromLeptons(chain, index):
    for l in xrange(chain._nL):
        if not isTightLepton(chain, l): continue
        if deltaR(chain._lEta[l], chain._jetEta[index], chain._lPhi[l],
                  chain._jetPhi[index]) < 0.4:
            return False
    return True
Ejemplo n.º 2
0
def calculateGeneralVariables(chain, new_chain, is_reco_level=True):
    if is_reco_level:
        #ptCone
        new_chain.pt_cone = []
        new_chain.dr_closestJet = []
        for il, l in enumerate(new_chain.l_indices):
            if chain.l_flavor[il] < 2:
                new_chain.pt_cone.append(chain._lPtCorr[l] *
                                         coneCorrection(chain, l))
            else:
                new_chain.pt_cone.append(chain._lPt[l] *
                                         coneCorrection(chain, l))

            closest_jet = findClosestJet(chain, il)
            if closest_jet is None:
                new_chain.dr_closestJet.append(-1.)
            else:
                new_chain.dr_closestJet.append(
                    deltaR(chain.l_eta[il], chain._jetEta[closest_jet],
                           chain.l_phi[il], chain._jetPhi[closest_jet]))

        #calculate #jets and #bjets
        new_chain.njets = len(selectJets(chain))
        new_chain.nbjets = nBjets(chain, 'loose')
        new_chain.HT = calcHT(chain, new_chain)
        selectFirstTwoJets(chain, new_chain)

    new_chain.hasOSSF = containsOSSF(new_chain)

    new_chain.LT = calcLT(chain, new_chain)
Ejemplo n.º 3
0
def isCleanFromMuons(chain, index, mu_algo='leptonMVAtZq'):

    for mu in xrange(chain._nMu):
        if not isLooseMuon(chain, mu, mu_algo): continue
        if deltaR(chain._lEta[mu], chain._lEta[index], chain._lPhi[mu],
                  chain._lPhi[index]) < 0.05:
            return False
    return True
Ejemplo n.º 4
0
def isCleanFromMuons(chain, index):

    for mu in xrange(chain._nMu):
        if not isGoodMuon(chain, mu, workingpoint='loose'): continue
        if deltaR(chain._lEta[mu], chain._lEta[index], chain._lPhi[mu],
                  chain._lPhi[index]) < 0.05:
            return False
    return True
Ejemplo n.º 5
0
def isCleanFromLightLeptons(chain, index):
    for l in xrange(chain._nLight):
        if chain._lFlavor == 1 and not isLooseMuon(chain, l): continue
        if chain._lFlavor == 0 and not isLooseElectron(chain, l): continue
        if deltaR(chain._lEta[l], chain._lEta[index], chain._lPhi[l],
                  chain._lPhi[index]) < 0.4:
            return False
    return True
Ejemplo n.º 6
0
def findClosestJet(chain, lepton_index):
    mindr = 1000.
    mindr_jet = None
    for jet in selectJets(chain):
        dr = deltaR(chain.l_eta[lepton_index], chain._jetEta[jet],
                    chain.l_phi[lepton_index], chain._jetPhi[jet])
        if dr < mindr:
            mindr = dr
            mindr_jet = jet
    return mindr_jet
Ejemplo n.º 7
0
def isCleanFromLightLeptons(chain, index):
    for l in xrange(chain._nLight):
        if chain._lFlavor[l] == 1 and not isGoodMuon(
                chain, l, workingpoint='loose'):
            continue
        if chain._lFlavor[l] == 0 and not isGoodElectron(
                chain, l, workingpoint='loose'):
            continue
        if deltaR(chain._lEta[l], chain._lEta[index], chain._lPhi[l],
                  chain._lPhi[index]) < 0.4:
            return False
    return True
Ejemplo n.º 8
0
def matchGenToReco(chain, l):

    min_dr = 0.3
    matched_l = None
    for lepton in xrange(chain._nLight, chain._nL):
        if chain._tauGenStatus[lepton] != 5: continue
        dr = deltaR(chain._gen_lEta[l], chain._lEta[lepton],
                    chain._gen_lPhi[l], chain._lPhi[lepton])
        if dr < min_dr:
            matched_l = lepton
            min_dr = dr

    return matched_l
Ejemplo n.º 9
0
def matchGenToReco(chain, l):

    min_dr = 0.3
    matched_l = None
    for lepton in xrange(chain._nLight):
        if not chain._lIsPrompt[lepton]: continue
        if chain._gen_lFlavor[l] != chain._lFlavor[lepton]: continue
        dr = deltaR(chain._gen_lEta[l], chain._lEta[lepton],
                    chain._gen_lPhi[l], chain._lPhi[lepton])
        if dr < min_dr:
            matched_l = lepton
            min_dr = dr

    return matched_l
Ejemplo n.º 10
0
def matchGenToReco(in_chain, l):

    min_dr = 0.3
    matched_lepton = None
    for lepton_index in xrange(in_chain._nLight):
        if not in_chain._lIsPrompt[lepton_index]: continue
        if in_chain._gen_lFlavor[l] != in_chain._lFlavor[lepton_index]:
            continue
        dr = deltaR(in_chain._gen_lEta[l], in_chain._lEta[lepton_index],
                    in_chain._gen_lPhi[l], in_chain._lPhi[lepton_index])
        if dr < min_dr:
            matched_lepton = lepton_index
            min_dr = dr

    return matched_lepton
Ejemplo n.º 11
0
    def passedFilter(self,
                     cutter,
                     only_muons=False,
                     only_electrons=False,
                     require_jets=False):
        if not cutter.cut(self.chain._passMETFilters, 'pass met filters'):
            return False

        #Select exactly one lepton and veto a second loose lepton
        if not self.initEvent(cutter): return False
        if not cutter.cut(
                isGoodLightLepton(self.chain, self.chain.l_indices[0], 'FO'),
                'is FO lepton'):
            return False

        #Select correct lepton flavor
        if only_muons and only_electrons:
            raise RuntimeError(
                "passedFilter in LightLeptonFakeRateMeasurementRegion can not have both only muons and only electrons at the same time"
            )
        if only_muons and not cutter.cut(self.chain.l_flavor[0] == 1,
                                         'is muon'):
            return False
        if only_electrons and not cutter.cut(self.chain.l_flavor[0] == 0,
                                             'is electron'):
            return False

        #Require the presence of at least one good jet if option is set to True
        if require_jets:
            jet_indices = selectJets(self.chain, cleaned='loose')
            if len(jet_indices) < 1: return False

            max_delta_r = 0
            for jet in jet_indices:
                delta_r = deltaR(self.chain._jetEta[jet], self.chain.l_eta[0],
                                 self.chain._jetPhi[jet], self.chain.l_phi[0])
                if delta_r > max_delta_r:
                    max_delta_r = delta_r
            if not cutter.cut(max_delta_r > 0.7, 'contains jet'): return False

        applyConeCorrection(self.chain, self.new_chain)

        return True
Ejemplo n.º 12
0
    def matchLheParticle(self, l):
        tmp_match = None
        min_dr = 0.3
        for i in xrange(self.c._nLheParticles):
            #Avoid double matching
            if i in self.used_lheparticles: continue

            #Check if the flavor of the gen lepton corresponds to the pdg id of the lhe particle that we checking as potential match
            if abs(self.c._lhePdgId[i]) != PDG_DICT[self.c._gen_lFlavor[l]]:
                continue

            #Check for geometric match
            dr = deltaR(self.c._gen_lEta[l], self.c._lheEta[i],
                        self.c._gen_lPhi[l], self.c._lhePhi[i])
            if dr < min_dr:
                tmp_match = i
                min_dr = dr

        self.used_lheparticles.append(tmp_match)
        return tmp_match
Ejemplo n.º 13
0
                    break

            if not cutter.cut(keep_event, "Third loose light lepton veto"):
                continue

            #
            # Select tau candidates
            #
            tau_candidates = []
            for tau in xrange(chain._nLight, chain._nL):
                if not isGeneralTau(chain, tau, 'deeptauVSjets', 'tight',
                                    'deeptauVSe', 'vvloose', 'deeptauVSmu',
                                    'vloose'):
                    continue
                if chain._dz[tau] > 0.2: continue
                if deltaR(chain._lEta[muon_index], chain._lEta[tau],
                          chain._lPhi[muon_index], chain._lPhi[tau]) < 0.5:
                    continue
                tau_candidates.append(tau)

            if not cutter.cut(len(tau_candidates) != 0, "Has tau candidates"):
                continue

            #
            # Select most isolated tau candidate
            #
            tau_index = tau_candidates[0]
            for tau in tau_candidates[1:]:
                if chain._tauDeepTauVsJetsRaw[
                        tau] > chain._tauDeepTauVsJetsRaw[tau_index]:
                    tau_index = tau