Exemplo n.º 1
0
    def selectCandidates(self):
        candidate = {
            'z1': None,
            'z2': None,
            'z': None,
            'l1': None,
            'w': None,
            'met': self.pfmet,
            'cleanJets': [],
        }

        # get leptons
        leps = self.getPassingCands('Loose', self.electrons, self.muons)
        if len(leps) != 3: return candidate  # need 3 leptons

        # get invariant masses
        bestZ = ()
        bestMassdiff = 99999
        for zpair in itertools.permutations(leps, 3):
            # z pass medium
            if not self.passMedium(zpair[0]): continue
            if not self.passMedium(zpair[1]): continue
            if zpair[0].collName != zpair[1].collName: continue  # SF
            if zpair[0].charge() == zpair[1].charge(): continue  # OS
            z = [zpair[0], zpair[1], zpair[2]
                 ] if zpair[0].pt() > zpair[1].pt() else [
                     zpair[1], zpair[0], zpair[2]
                 ]
            if not bestZ: bestZ = z
            if z[0].pt() > bestZ[0].pt():
                bestZ = z
            if z[0].pt() == bestZ[0].pt() and z[1].pt() > bestZ[1].pt():
                bestZ = z

        if not bestZ: return candidate  # need a z candidate

        z = [bestZ[0], bestZ[1]
             ] if bestZ[0].pt() > bestZ[1].pt() else [bestZ[1], bestZ[0]]
        zCand = DiCandidate(z[0], z[1])
        if zCand.M() < 60 or zCand.M() > 120: return candidate

        l = bestZ[2]
        if deltaR(z[0].eta(), z[0].phi(), l.eta(), l.phi()) < 0.4 or deltaR(
                z[1].eta(), z[1].phi(), l.eta(), l.phi()) < 0.4:
            return candidate

        candidate['z1'] = z[0]
        candidate['z2'] = z[1]
        candidate['l1'] = l
        candidate['z'] = zCand
        candidate['w'] = MetCompositeCandidate(self.pfmet, l)

        medLeps = self.getPassingCands('Medium', self.electrons, self.muons)
        candidate['cleanJets'] = self.cleanCands(self.jets, medLeps, 0.4)

        return candidate
Exemplo n.º 2
0
    def selectCandidates(self):
        candidate = {
            'z1': None,
            'z2': None,
            'g1': None,
            'z': None,
            'zg': None,
            'met': self.pfmet,
            'cleanJets': [],
        }

        # get leptons
        medLeps = self.getPassingCands('Medium', self.muons)
        if len(medLeps) < 2: return candidate  # need at least 2 leptons
        #phos = self.getPassingCands('PhotonPreselectionNoElectronVeto',self.photons)
        phos = self.photons

        # get invariant masses
        bestZ = ()
        bestMassdiff = 99999
        for mm in itertools.combinations(medLeps, 2):
            m1, m2 = mm
            if m1.collName != m2.collName: continue  # SF
            if m1.charge() == m2.charge(): continue  # OS
            for g in phos:
                if deltaR(m1.eta(), m1.phi(), g.eta(), g.phi()) < 0.8:
                    if m2.pt() < 20: continue
                elif deltaR(m2.eta(), m2.phi(), g.eta(), g.phi()) < 0.8:
                    if m1.pt() < 20: continue
                else:
                    continue
                zg = CompositeCandidate(m1, m2, g)
                massdiff = abs(zg.M() - ZMASS)
                if massdiff < bestMassdiff:
                    bestZ = (m1, m2, g) if m1.pt() > m2.pt() else (m2, m1, g)
                    bestMassdiff = massdiff

        if not bestZ: return candidate  # need a z candidate

        m1, m2, g = bestZ
        candidate['z1'] = m1
        candidate['z2'] = m2
        candidate['z'] = DiCandidate(m1, m2)
        candidate['g1'] = g
        candidate['zg'] = CompositeCandidate(m1, m2, g)

        goodGs = self.getPassingCands('Photon', self.photons)
        candidate['cleanJets'] = self.cleanCands(
            self.jets, medLeps + goodGs + [m1, m2, g], 0.4)

        return candidate
    def selectCandidates(self):
        candidate = {
            'z1': None,
            'z2': None,
            'z' : None,
            'l1': None,
            'w' : None,
            'met': self.pfmet,
            'cleanJets': [],
        }

        # get leptons
        leps = self.getPassingCands('Loose',self.electrons,self.muons)
        if len(leps)!=3: return candidate # need 3 leptons

        # get invariant masses
        bestZ = ()
        bestMassdiff = 99999
        for zpair in itertools.permutations(leps,3):
            # z pass medium
            if not self.passMedium(zpair[0]): continue
            if not self.passMedium(zpair[1]): continue
            if zpair[0].collName!=zpair[1].collName: continue # SF
            if zpair[0].charge()==zpair[1].charge(): continue # OS
            z = [zpair[0],zpair[1],zpair[2]] if zpair[0].pt()>zpair[1].pt() else [zpair[1],zpair[0],zpair[2]]
            if not bestZ: bestZ = z
            if z[0].pt()>bestZ[0].pt():
                bestZ = z
            if z[0].pt()==bestZ[0].pt() and z[1].pt()>bestZ[1].pt():
                bestZ = z

        if not bestZ: return candidate # need a z candidate

        z = [bestZ[0],bestZ[1]] if bestZ[0].pt()>bestZ[1].pt() else [bestZ[1],bestZ[0]]
        zCand = DiCandidate(z[0],z[1])
        if zCand.M()<60 or zCand.M()>120: return candidate

        l = bestZ[2]
        if deltaR(z[0].eta(),z[0].phi(),l.eta(),l.phi())<0.4 or deltaR(z[1].eta(),z[1].phi(),l.eta(),l.phi())<0.4: return candidate

        candidate['z1'] = z[0]
        candidate['z2'] = z[1]
        candidate['l1'] = l
        candidate['z'] = zCand
        candidate['w'] = MetCompositeCandidate(self.pfmet,l)

        medLeps = self.getPassingCands('Medium',self.electrons,self.muons)
        candidate['cleanJets'] = self.cleanCands(self.jets,medLeps,0.4)

        return candidate
Exemplo n.º 4
0
 def genDeltaR(self,rtrow,cand):
     '''Get the gen level deltaR'''
     eta = self.getObjectVariable(rtrow,cand,'eta')
     genEta = self.getObjectVariable(rtrow,cand,'genEta')
     phi = self.getObjectVariable(rtrow,cand,'phi')
     genPhi = self.getObjectVariable(rtrow,cand,'genPhi')
     return deltaR(eta,phi,genEta,genPhi)
Exemplo n.º 5
0
    def selectCandidates(self):
        candidate = {
            'z1' : None,
            'z2' : None,
            'g' : None,
            'z' : None,
            'zg' : None,
            'met': self.pfmet,
        }

        # get leptons
        medLeps = self.getPassingCands('Medium',self.muons)
        if len(medLeps)<2: return candidate # need at least 2 leptons
        #phos = self.getPassingCands('PhotonPreselectionNoElectronVeto',self.photons)
        phos = self.photons

        # get invariant masses
        bestZ = ()
        bestMassdiff = 99999
        for mm in itertools.combinations(medLeps,2):
            m1, m2 = mm
            if m1.collName!=m2.collName: continue # SF
            if m1.charge()==m2.charge(): continue # OS
            for g in phos:
                if deltaR(m1.eta(),m1.phi(),g.eta(),g.phi())<0.8:
                    if m2.pt()<20: continue
                elif deltaR(m2.eta(),m2.phi(),g.eta(),g.phi())<0.8:
                    if m1.pt()<20: continue
                else:
                    continue
                zg = CompositeCandidate(m1,m2,g)
                massdiff = abs(zg.M()-ZMASS)
                if massdiff<bestMassdiff:
                    bestZ = (m1,m2,g) if m1.pt()>m2.pt() else (m2,m1,g)
                    bestMassdiff = massdiff

        if not bestZ: return candidate # need a z candidate

        m1,m2,g = bestZ
        candidate['z1'] = m1
        candidate['z2'] = m2
        candidate['z'] = DiCandidate(m1,m2)
        candidate['g'] = g
        candidate['zg'] = CompositeCandidate(m1,m2,g)

        return candidate
 def genJetDeltaR(self,cand):
     '''Get the gen level deltaR'''
     if cand.genJetMatch()==0: return 0.
     eta = cand.eta()
     genEta = cand.genJetEta()
     phi = cand.phi()
     genPhi = cand.genJetPhi()
     return deltaR(eta,phi,genEta,genPhi)
Exemplo n.º 7
0
    def selectCandidates(self):
        candidate = {
            'z1' : None,
            'z2' : None,
            'm' : None,
            'z' : None,
            'met': self.pfmet,
        }

        # get leptons
        muons = [m for m in self.muons if self.passMuon(m)]
        if len(muons)<2: return candidate


        # get the candidates
        zCand = []
        for mm in itertools.permutations(muons,2):
            m1 = mm[0]
            m2 = mm[1]
            # charge OS
            if m1.charge()==m2.charge(): continue
            # require lead m pt>25
            if m1.pt()<20: continue
            if m2.pt()<10: continue
            # iso
            if m1.relPFIsoDeltaBetaR04()>=0.25: continue
            if m2.relPFIsoDeltaBetaR04()>=0.25: continue
            # make composites
            z = DiCandidate(m1,m2)
            if not zCand: zCand = mm
            better = True
            if zCand[0].pt()>m1.pt():
                better = False
            elif zCand[1].pt()>m2.pt():
                better = False
            if better: zCand = mm
                
        if not zCand: return candidate

        m1 = zCand[0] if zCand[0].pt()>zCand[1].pt() else zCand[1]
        m2 = zCand[1] if zCand[0].pt()>zCand[1].pt() else zCand[0]

        # highest pt tau with DR>0.8 from selected muons
        goodMuons = [m for m in muons if deltaR(m.eta(),m.phi(),m1.eta(),m1.phi())>0.8 and deltaR(m.eta(),m.phi(),m2.eta(),m2.phi())>0.8]
        if len(goodMuons)==0: return candidate

        m = goodMuons[0]

        z = DiCandidate(m1,m2)
        if z.M()>120: return candidate
        if z.M()<60: return candidate

        candidate['z1'] = m1
        candidate['z2'] = m2
        candidate['m'] = m
        candidate['z'] = DiCandidate(m1,m2)

        return candidate
Exemplo n.º 8
0
 def matchToGenPhotons(self,pho):
     numMatch = 0
     for gen in self.gen:
         if gen.pdgId() != 22: continue
         if gen.status() != 1: continue
         #if abs(gen.mother_1()) not in [1,2,3,4,5,6,21,22,35,36]: continue # from quarks for gjet mc, 35/36 for signal
         if deltaR(gen.eta(),gen.phi(),pho.eta(),pho.phi())>0.1: continue
         numMatch += 1
     return numMatch
Exemplo n.º 9
0
 def matchToGenPhotons(self, pho):
     numMatch = 0
     for gen in self.gen:
         if gen.pdgId() != 22: continue
         if gen.status() != 1: continue
         #if abs(gen.mother_1()) not in [1,2,3,4,5,6,21,22,35,36]: continue # from quarks for gjet mc, 35/36 for signal
         if deltaR(gen.eta(), gen.phi(), pho.eta(), pho.phi()) > 0.1:
             continue
         numMatch += 1
     return numMatch
Exemplo n.º 10
0
 def cleanCands(self,src,other,dr):
     cleaned = []
     for s in src:
         keep = True
         for o in other:
             if deltaR(s.eta(),s.phi(),o.eta(),o.phi())<dr:
                 keep = False
                 break
         if keep:
             cleaned += [s]
     return cleaned
Exemplo n.º 11
0
    def tauGenMatch(self,candidate,label):
        if self.event.isData(): return -1
        t = candidate[label]
        gtaus = [g for g in self.gen if abs(g.pdgId())==15]
        gelectrons = [g for g in self.gen if abs(g.pdgId())==11]
        gmuons = [g for g in self.gen if abs(g.pdgId())==13]
        bestG = None
        bestDR = 999.
        for g in self.gen:
            if not g.isPrompt(): continue
            if g.pt()<8: continue
            dr = deltaR(t.eta(),t.phi(),g.eta(),g.phi())
            if dr<bestDR:
                bestG = g
                bestDR = dr
        bestTauG = None
        bestTauDR = 999
        for g in gtaus:
            dr = deltaR(t.eta(),t.phi(),g.eta(),g.phi())
            if dr<bestTauDR:
                bestTauG = g
                bestTauDR = dr
        #if bestDR<0.2:
        #    dr = deltaR(t.eta(),t.phi(),bestG.eta(),bestG.phi())
        #    print bestG.pdgId(), bestG.numberOfDaughters(), bestG.daughter_1(), bestG.daughter_2(), bestG.mother_1(), dr
        #else:
        #    print 'No prompt'
        #if bestTauDR<0.2:
        #    dr = deltaR(t.eta(),t.phi(),bestTauG.eta(),bestTauG.phi())
        #    print bestTauG.pdgId(), bestTauG.numberOfDaughters(), bestTauG.daughter_1(), bestTauG.daughter_2(), bestTauG.mother_1(), dr
        #else:
        #    print 'No gen tau'
        if bestDR<0.2 and bestDR<bestTauDR:
            if abs(bestG.pdgId()) == 11: return 1
            elif abs(bestG.pdgId()) == 13: return 2
        elif bestTauDR<0.2 and bestTauDR<bestDR:
            if abs(bestTauG.pdgId()) == 15  and 11 in [abs(bestTauG.daughter_1()), abs(bestTauG.daughter_2())]: return 3
            elif abs(bestTauG.pdgId()) == 15  and 13 in [abs(bestTauG.daughter_1()), abs(bestTauG.daughter_2())]: return 4
            elif abs(bestTauG.pdgId()) == 15: return 5

        return 6
Exemplo n.º 12
0
    def getCompositeVariable(self,rtrow,var,*cands):
        '''Create a composite candidate'''

        key = '_'.join(['{0}_{1}'.format(*cand) for cand in cands] + [var])
        if key in self.cache: return self.cache[key]

        vec = ROOT.TLorentzVector()
        for cand in cands:
            vec += self.getObjectVariable(rtrow,cand,'p4')

        if var=='p4':
            val = vec
        elif var in ['mass','Mass','m','M']:
            val = vec.M()
        elif var in ['pt','Pt']:
            val = vec.Pt()
        elif var in ['eta','Eta']:
            val = vec.Eta()
        elif var in ['phi','Phi']:
            val = vec.Phi()
        elif var in ['energy','Energy']:
            val = vec.Energy()
        elif len(cands)==2:
            if var in ['deltaR','dR','dr','DR']:
                eta1 = self.getObjectVariable(rtrow,cands[0],'eta')
                phi1 = self.getObjectVariable(rtrow,cands[0],'phi')
                eta2 = self.getObjectVariable(rtrow,cands[1],'eta')
                phi2 = self.getObjectVariable(rtrow,cands[1],'phi')
                val = deltaR(eta1,phi1,eta2,phi2)
            elif var in ['deltaPhi','dPhi','dphi','DPhi']:
                phi1 = self.getObjectVariable(rtrow,cands[0],'phi')
                phi2 = self.getObjectVariable(rtrow,cands[1],'phi')
                val = deltaPhi(phi1,phi2)
            elif var in ['deltaEta','dEta','deta','DEta']:
                eta1 = self.getObjectVariable(rtrow,cands[0],'eta')
                eta2 = self.getObjectVariable(rtrow,cands[1],'eta')
                val = abs(eta1-eta2)
            else:
                val = 0
        else:
            val = 0

        self.cache[key] = val
        return val
Exemplo n.º 13
0
    def selectCandidates(self):
        candidate = {
            'e': None,
            'g': None,
            'eg': None,
            'met': self.pfmet,
            'cleanJets': [],
            #'leadJet': Candidate(None),
            #'subleadJet': Candidate(None),
            #'dijet': DiCandidate(Candidate(None),Candidate(None)),
        }

        gs = self.photons
        es = self.getPassingCands('Medium', self.electrons)

        if not es or not gs: return candidate

        best = ()
        for e in es:
            if e.pt() < 30: continue
            for g in gs:
                if deltaR(e.eta(), e.phi(), g.eta(), g.phi()) < 0.4: continue
                if self.passElectronVeto(g): continue
                eg = DiCandidate(e, g)
                if eg.M() < 60 or eg.M() > 120: continue
                if not best: best = (e, g)
                if e.pt() > best[0].pt():
                    best = (e, g)
                elif g.pt() > best[1].pt():
                    best = (e, g)

        if not best: return candidate
        e, g = best

        candidate['e'] = e
        candidate['g'] = g
        candidate['eg'] = DiCandidate(e, g)

        goodGs = self.getPassingCands('Photon', self.photons)
        candidate['cleanJets'] = self.cleanCands(self.jets, es + goodGs + [g],
                                                 0.4)

        return candidate
Exemplo n.º 14
0
    def selectCandidates(self):
        candidate = {
            'm': None,
            't': None,
            'z': None,
            'wm': None,
            'wt': None,
            'met': self.pfmet,
        }

        # get leptons
        muons = self.getCands(self.muons, self.passTight)
        #loosemuons = self.getCands(self.muons,self.passLoose)
        taus = self.getCands(self.taus, self.passLooseNew)
        if len(muons) != 1: return candidate  # need 1 tight muon
        #if len(loosemuons)>1: return candidate # dont allow another loose muon
        # require tau to be 0.8 away from muon
        taus = [
            t for t in taus
            if deltaR(t.eta(), t.phi(), muons[0].eta(), muons[0].phi()) > 0.8
        ]
        if len(taus) < 1: return candidate  # need at least 1 tau

        # quality
        if muons[0].pt() < 25: return candidate
        if taus[0].pt() < 20: return candidate
        if muons[0].charge() != taus[0].charge(): return candidate
        z = DiCandidate(muons[0], taus[0])
        if z.deltaR() < 0.5: return candidate

        candidate['m'] = muons[0]
        candidate['t'] = taus[0]
        candidate['z'] = z
        candidate['wm'] = MetCompositeCandidate(self.pfmet, muons[0])
        candidate['wt'] = MetCompositeCandidate(self.pfmet, taus[0])

        return candidate
Exemplo n.º 15
0
    def selectCandidates(self):
        candidate = {
            'e' : None,
            'g' : None,
            'eg': None,
            'met': self.pfmet,
        }

        gs = self.photons
        es = self.getPassingCands('Medium',self.electrons)

        if not es or not gs: return candidate

        best = ()
        for e in es:
            if e.pt()<30: continue
            if abs(e.eta())>2.17: continue
            for g in gs:
                if deltaR(e.eta(),e.phi(),g.eta(),g.phi())<0.4: continue
                #if self.passElectronVeto(g): continue
                if not best: best = (e,g)
                if e.pt()>best[0].pt():
                    best = (e,g)
                elif g.pt()>best[1].pt():
                    best = (e,g)

        if not best: return candidate
        e,g = best
        eg = DiCandidate(e,g)
        if eg.M()<60 or eg.M()>120: return candidate

        candidate['e'] = e
        candidate['g'] = g
        candidate['eg'] = eg

        return candidate
Exemplo n.º 16
0
    def selectCandidates(self):
        candidate = {
            'e': None,
            'g': None,
            'eg': None,
            'met': self.pfmet,
        }

        gs = self.photons
        es = self.getPassingCands('Medium', self.electrons)

        if not es or not gs: return candidate

        best = ()
        for e in es:
            if e.pt() < 30: continue
            if abs(e.eta()) > 2.17: continue
            for g in gs:
                if deltaR(e.eta(), e.phi(), g.eta(), g.phi()) < 0.4: continue
                #if self.passElectronVeto(g): continue
                if not best: best = (e, g)
                if e.pt() > best[0].pt():
                    best = (e, g)
                elif g.pt() > best[1].pt():
                    best = (e, g)

        if not best: return candidate
        e, g = best
        eg = DiCandidate(e, g)
        if eg.M() < 60 or eg.M() > 120: return candidate

        candidate['e'] = e
        candidate['g'] = g
        candidate['eg'] = eg

        return candidate
    def selectCandidates(self):
        candidate = {
            'm' : None,
            't' : None,
            'z' : None,
            'wm': None,
            'wt': None,
            'met': self.pfmet,
        }

        # get leptons
        muons = self.getCands(self.muons,self.passTight)
        #loosemuons = self.getCands(self.muons,self.passLoose)
        taus = self.getCands(self.taus,self.passLooseNew)
        if len(muons)!=1: return candidate # need 1 tight muon
        #if len(loosemuons)>1: return candidate # dont allow another loose muon
        # require tau to be 0.8 away from muon
        taus = [t for t in taus if deltaR(t.eta(),t.phi(),muons[0].eta(),muons[0].phi())>0.8]
        if len(taus)<1: return candidate # need at least 1 tau 


        # quality
        if muons[0].pt()<25: return candidate
        if taus[0].pt()<20: return candidate
        if muons[0].charge()!=taus[0].charge(): return candidate
        z = DiCandidate(muons[0],taus[0])
        if z.deltaR()<0.5: return candidate

        candidate['m'] = muons[0]
        candidate['t'] = taus[0]
        candidate['z'] = z
        candidate['wm'] = MetCompositeCandidate(self.pfmet,muons[0])
        candidate['wt'] = MetCompositeCandidate(self.pfmet,taus[0])


        return candidate
Exemplo n.º 18
0
    def selectCandidates(self):
        candidate = {
            'z1': None,
            'z2': None,
            'z': None,
            't': None,
            'w': None,
            'met': self.pfmet,
            'cleanJets': [],
        }

        # get leptons
        leps = self.getPassingCands('Medium', self.electrons, self.muons)
        tleps = self.getPassingCands('LooseNew', self.taus)
        if len(leps) != 2: return candidate  # need 3 leptons
        if len(tleps) < 1: return candidate  # need 3 leptons

        # get invariant masses
        bestZ = ()
        bestMassdiff = 99999
        for zpair in itertools.permutations(leps, 2):
            # z pass medium
            if not self.passMedium(zpair[0]): continue
            if not self.passMedium(zpair[1]): continue
            if zpair[0].collName != zpair[1].collName: continue  # SF
            if zpair[0].charge() == zpair[1].charge(): continue  # OS
            z = [zpair[0], zpair[1]
                 ] if zpair[0].pt() > zpair[1].pt() else [zpair[1], zpair[0]]
            if not bestZ: bestZ = z
            if z[0].pt() > bestZ[0].pt():
                bestZ = z
            if z[0].pt() == bestZ[0].pt() and z[1].pt() > bestZ[1].pt():
                bestZ = z
            #z = DiCandidate(*zpair[:2])
            #massdiff = abs(z.M()-ZMASS)
            #if massdiff<bestMassdiff:
            #    bestZ = zpair
            #    bestMassdiff = massdiff

        if not bestZ: return candidate  # need a z candidate
        zcand = DiCandidate(*bestZ)
        if zcand.M() < 60 or zcand.M() > 120: return candidate

        tleps = [
            t for t in tleps
            if deltaR(t.eta(), t.phi(), zcand[0].eta(), zcand[0].phi()) > 0.8
            and deltaR(t.eta(), t.phi(), zcand[1].eta(), zcand[1].phi()) > 0.8
        ]
        if len(tleps) < 1: return candidate

        # and sort pt of Z
        z = [bestZ[0], bestZ[1]
             ] if bestZ[0].pt() > bestZ[1].pt() else [bestZ[1], bestZ[0]]
        candidate['z1'] = z[0]
        candidate['z2'] = z[1]
        candidate['t'] = tleps[0]
        candidate['z'] = DiCandidate(z[0], z[1])
        candidate['w'] = MetCompositeCandidate(self.pfmet, tleps[0])

        medLeps = self.getPassingCands('Medium', self.electrons, self.muons,
                                       self.taus)
        candidate['cleanJets'] = self.cleanCands(self.jets, medLeps, 0.4)

        return candidate
Exemplo n.º 19
0
 def deltaR(self):
     return deltaR(self.objects[0].eta(),
                   self.objects[0].phi(),
                   self.objects[1].eta(),
                   self.objects[1].phi())
Exemplo n.º 20
0
 def deltaR(self):
     return deltaR(self.objects[0].eta(), self.objects[0].phi(),
                   self.objects[1].eta(), self.objects[1].phi())
Exemplo n.º 21
0
    def selectCandidates(self):
        candidate = {
            'z1' : None,
            'z2' : None,
            't' : None,
            'tjet' : Candidate(None),
            'z' : None,
            'm': None,
            'mt': None,
            'met': self.pfmet,
        }

        # get leptons
        muons = [m for m in self.muons if self.passMuon(m)]
        taus = [t for t in self.taus if self.passTau(t)]
        leps = muons+taus
        if len(muons)<2: return candidate
        if len(taus)<1: return candidate


        # get the candidates
        zCand = []
        for mm in itertools.permutations(muons,2):
            m1 = mm[0]
            m2 = mm[1]
            # charge OS
            if m1.charge()==m2.charge(): continue
            # require lead m pt>25
            if m1.pt()<26: continue
            if m2.pt()<10: continue
            # iso
            if m1.relPFIsoDeltaBetaR04()>=0.25: continue
            if m2.relPFIsoDeltaBetaR04()>=0.25: continue
            # make composites
            z = DiCandidate(m1,m2)
            if not zCand: zCand = mm
            better = True
            if zCand[0].pt()>m1.pt():
                better = False
            elif zCand[1].pt()>m2.pt():
                better = False
            if better: zCand = mm
                
        if not zCand: return candidate

        m1 = zCand[0] if zCand[0].pt()>zCand[1].pt() else zCand[1]
        m2 = zCand[1] if zCand[0].pt()>zCand[1].pt() else zCand[0]

        z = DiCandidate(m1,m2)
        if z.M()>120: return candidate
        if z.M()<60: return candidate

        # highest pt tau with DR>0.8 from selected muons
        goodTaus = [t for t in taus if deltaR(t.eta(),t.phi(),m1.eta(),m1.phi())>0.8 and deltaR(t.eta(),t.phi(),m2.eta(),m2.phi())>0.8]
        if len(goodTaus)==0: return candidate

        t = goodTaus[0]

        # find if there is a muon nearby
        otherMuons = [m for m in muons if m!=m1 and m!=m2 and deltaR(m.eta(),m.phi(),t.eta(),t.phi())<0.8]
        otherMuonsByDR = sorted(otherMuons, key=lambda m: deltaR(m.eta(),m.phi(),t.eta(),t.phi()))
        nearM = otherMuonsByDR[0] if otherMuonsByDR else Candidate(None)

        candidate['z1'] = m1
        candidate['z2'] = m2
        candidate['t'] = t
        candidate['z'] = DiCandidate(m1,m2)
        candidate['m'] = nearM
        candidate['mt'] = DiCandidate(nearM,t) if len(otherMuonsByDR) else DiCandidate(Candidate(None),Candidate(None))

        result = self.tauGenMatch(candidate,'t')

        # match jet to tau
        dr = 999
        j = None
        for jet in self.jets:
            jt = DiCandidate(jet,t)
            if jt.deltaR()<dr:
                j = jet
                dr = jt.deltaR()
        if j:
            candidate['tjet'] = j

        return candidate
Exemplo n.º 22
0
 def addCompositeGenParticle(self, label, d1, d2):
     self.addGenParticle(label)
     self.tree.add(
         lambda cands: deltaR(cands[d1].eta(), cands[d1].phi(), cands[d2].
                              eta(), cands[d2].phi())
         if label in cands else 0, '{0}_deltaR'.format(label), 'F')
    def selectCandidates(self):
        # reset kinfit
        self._kinfit = None

        candidate = {
            'am1' : None,
            'am1met' : None,
            'am2' : None,
            'am2met' : None,
            'atm' : None,
            'atmmet' : None,
            'ath' : None,
            'athmet' : None,
            'amm' : None,
            'ammmet' : None,
            'att' : None,
            'attmet' : None,
            'mmm' : None,
            'mmmmet' : None,
            'mmt' : None,
            'mmtmet' : None,
            'h' : None,
            'hmet' : None,
            'mmm' : None,
            'mmmmet' : None,
            'met': self.pfmet,
            'athjet': Candidate(None),
            'cleanJets' : [],
            'cleanJetsNoTau' : [],
        }

        # get leptons
        muons = [m for m in self.muons if self.passMuon(m)]
        taus = [t for t in self.taus if self.passTau(t)]
        leps = muons+taus
        if len(muons)<3:
            self.report_failure('fails 3 muon requirement')
            return self.fallback()
        if len(taus)<1: 
            self.report_failure('fails 1 tau requirement')
            return self.fallback()


        # get the candidates
        hCand = []
        mmDeltaR = 999
        ttDeltaR = 999
        m1pt = 0
        furthest = 0
        nperms = 0
        nvalid = 0
        for quad in itertools.permutations(leps,4):
            nperms += 1
            # require mmmt
            if not quad[0].__class__.__name__=='Muon': continue
            if not quad[1].__class__.__name__=='Muon': continue
            if not quad[2].__class__.__name__=='Muon': continue
            if not quad[3].__class__.__name__=='Tau': continue
            # trigger match
            matchTrigger = quad[0].matches_IsoMu24() or quad[0].matches_IsoTkMu24()
            if not matchTrigger: continue
            furthest = max([1,furthest])
            # charge OS
            if quad[0].charge()==quad[1].charge(): continue
            if quad[2].charge()==quad[3].charge(): continue
            furthest = max([2,furthest])
            nvalid += 1
            # require lead m pt>25
            if quad[0].pt()<25: continue
            furthest = max([3,furthest])
            # make composites
            amm = DiCandidate(quad[0],quad[1])
            att = DiCandidate(quad[2],quad[3])
            # reject events with mu1/mu2 near tm/th
            m1tm = DiCandidate(quad[0],quad[2])
            m1th = DiCandidate(quad[0],quad[3])
            m2tm = DiCandidate(quad[1],quad[2])
            m2th = DiCandidate(quad[1],quad[3])
            if m1tm.deltaR()<0.4: continue
            if m1th.deltaR()<0.8: continue
            if m2tm.deltaR()<0.4: continue
            if m2th.deltaR()<0.8: continue
            furthest = max([4,furthest])
            # choose best
            if not hCand: hCand = quad
            better = True
            if amm.deltaR()>mmDeltaR:
                better = False
            elif amm.deltaR()==mmDeltaR and att.deltaR()>ttDeltaR:
                better = False
            elif amm.deltaR()==mmDeltaR and att.deltaR()==ttDeltaR and quad[0].pt()<m1pt:
                better = False
            if better:
                hCand = quad
                mmDeltaR = amm.deltaR()
                ttDeltaR = att.deltaR()
                m1pt = quad[0].pt()

        #print 'number perms: {}, number valid: {}'.format(nperms,nvalid)

        furthestMap = {
            0: 'topology',
            1: 'trigger',
            2: 'OS',
            3: 'lead pt',
            4: 'deltaR',
        }
                
        if not hCand:
            self.report_failure('no higgs candidate, furthest {}'.format(furthestMap[furthest]))
            return candidate

        am1 = hCand[0] #if hCand[0].pt()>hCand[1].pt() else hCand[1]
        am2 = hCand[1] #if hCand[0].pt()>hCand[1].pt() else hCand[0]
        atm = hCand[2]
        ath = hCand[3]

        amm = DiCandidate(am1,am2)
        if amm.M()>30:
            self.report_failure('selected higgs amm M>30')
            return candidate
        att = DiCandidate(atm,ath)
        if att.deltaR()>0.8:
            self.report_failure('selected higgs att DR>0.8')
            return candidate

        candidate['am1'] = am1
        candidate['am1met'] = MetCompositeCandidate(self.pfmet,am1)
        candidate['am2'] = am2
        candidate['am2met'] = MetCompositeCandidate(self.pfmet,am2)
        candidate['atm'] = atm
        candidate['atmmet'] = MetCompositeCandidate(self.pfmet,atm)
        candidate['ath'] = ath
        candidate['athmet'] = MetCompositeCandidate(self.pfmet,ath)
        candidate['amm'] = DiCandidate(am1,am2)
        candidate['ammmet'] = MetCompositeCandidate(self.pfmet,am1,am2)
        candidate['att'] = DiCandidate(atm,ath)
        candidate['attmet'] = MetCompositeCandidate(self.pfmet,atm,ath)
        candidate['h'] = CompositeCandidate(am1,am2,atm,ath)
        candidate['hmet'] = MetCompositeCandidate(self.pfmet,am1,am2,atm,ath)
        candidate['mmm'] = CompositeCandidate(am1,am2,atm)
        candidate['mmmmet'] = MetCompositeCandidate(self.pfmet,am1,am2,atm)
        candidate['mmt'] = CompositeCandidate(am1,am2,ath)
        candidate['mmtmet'] = MetCompositeCandidate(self.pfmet,am1,am2,ath)

        if doPacked:
            candidate['ch1'] = Candidate(None)
            candidate['ch2'] = Candidate(None)
            candidate['mmch'] = CompositeCandidate()
            candidate['ttch'] = CompositeCandidate()

            def passPacked(ch):
                if ch.dz()>0.5: return False
                return True


            packed = [p for p in self.packed if passPacked(p)]

            ch1 = None
            ch2 = None
            for ch in packed:
                if not ch1: ch1 = ch
                if not ch2: ch2 = ch
                drmm = deltaR(ch.eta(), ch.phi(), candidate['amm'].eta(), candidate['amm'].phi())
                drm1 = deltaR(ch.eta(), ch.phi(), candidate['am1'].eta(), candidate['am1'].phi())
                drm2 = deltaR(ch.eta(), ch.phi(), candidate['am2'].eta(), candidate['am2'].phi())
                drtt = deltaR(ch.eta(), ch.phi(), candidate['att'].eta(), candidate['att'].phi())
                drtm = deltaR(ch.eta(), ch.phi(), candidate['atm'].eta(), candidate['atm'].phi())
                drth = deltaR(ch.eta(), ch.phi(), candidate['ath'].eta(), candidate['ath'].phi())
                if drmm < deltaR(ch1.eta(), ch1.phi(), candidate['amm'].eta(), candidate['amm'].phi()) and drm1>0.02 and drm2>0.02:
                    ch1 = ch
                if drtt < deltaR(ch2.eta(), ch2.phi(), candidate['att'].eta(), candidate['att'].phi()) and drtm>0.02 and drth>0.02:
                    ch2 = ch
            if ch1:
                candidate['ch1'] = ch1
                candidate['mmch'] = CompositeCandidate(am1,am2,ch1)
            if ch2:
                candidate['ch2'] = ch2
                candidate['ttch'] = CompositeCandidate(atm,ath,ch2)

        # clean the jets
        candidate['cleanJets'] = self.cleanCands(self.jets,[am1,am2,atm,ath],0.4)
        candidate['cleanJetsDR08'] = self.cleanCands(candidate['cleanJets'],[ath],0.8)

        # match jet to tau
        dr = 999
        j = None
        for jet in self.jets:
            jt = DiCandidate(jet,ath)
            if jt.deltaR()<dr:
                j = jet
                dr = jt.deltaR()
        if j:
            candidate['athjet'] = j

        candidate.update(self.getGenCandidates())

        return candidate
 def addGenDeltaR(self,label,gen):
     self.tree.add(lambda cands: deltaR(cands[label].eta(),cands[label].phi(),cands[gen].eta(),cands[gen].phi()) if gen in cands else 9, '{0}_genTruthDeltaR'.format(label), 'F')
 def addCompositeGenParticle(self,label,d1,d2):
     self.addGenParticle(label)
     self.tree.add(lambda cands: deltaR(cands[d1].eta(),cands[d1].phi(),cands[d2].eta(),cands[d2].phi()) if label in cands else 0, '{0}_deltaR'.format(label), 'F')
Exemplo n.º 26
0
 def addGenDeltaR(self, label, gen):
     self.tree.add(
         lambda cands: deltaR(cands[label].eta(), cands[label].phi(), cands[
             gen].eta(), cands[gen].phi())
         if gen in cands else 9, '{0}_genTruthDeltaR'.format(label), 'F')
    def selectCandidates(self):
        candidate = {
            'z1': None,
            'z2': None,
            'z' : None,
            't': None,
            'tjet': Candidate(None),
            'w' : None,
            'met': self.pfmet,
            'cleanJets': [],
        }

        # get leptons
        leps = self.getPassingCands('Medium',self.electrons,self.muons)
        tleps = self.getPassingCands('LooseNew',self.taus)
        if len(leps)!=2: return candidate # need 3 leptons
        if len(tleps)<1: return candidate # need 3 leptons

        # get invariant masses
        bestZ = ()
        bestMassdiff = 99999
        for zpair in itertools.permutations(leps,2):
            # z pass medium
            if not self.passMedium(zpair[0]): continue
            if not self.passMedium(zpair[1]): continue
            if zpair[0].collName!=zpair[1].collName: continue # SF
            if zpair[0].charge()==zpair[1].charge(): continue # OS
            z = [zpair[0],zpair[1]] if zpair[0].pt()>zpair[1].pt() else [zpair[1],zpair[0]]
            if not bestZ: bestZ = z
            if z[0].pt()>bestZ[0].pt():
                bestZ = z
            if z[0].pt()==bestZ[0].pt() and z[1].pt()>bestZ[1].pt():
                bestZ = z
            #z = DiCandidate(*zpair[:2])
            #massdiff = abs(z.M()-ZMASS)
            #if massdiff<bestMassdiff:
            #    bestZ = zpair
            #    bestMassdiff = massdiff

        if not bestZ: return candidate # need a z candidate
        zcand = DiCandidate(*bestZ)
        if zcand.M()<60 or zcand.M()>120: return candidate

        tleps = [t for t in tleps if deltaR(t.eta(),t.phi(),zcand[0].eta(),zcand[0].phi())>0.8 and deltaR(t.eta(),t.phi(),zcand[1].eta(),zcand[1].phi())>0.8]
        if len(tleps)<1: return candidate

        # and sort pt of Z
        z = [bestZ[0],bestZ[1]] if bestZ[0].pt()>bestZ[1].pt() else [bestZ[1],bestZ[0]]
        candidate['z1'] = z[0]
        candidate['z2'] = z[1]
        candidate['t'] = tleps[0]
        candidate['z'] = DiCandidate(z[0],z[1])
        candidate['w'] = MetCompositeCandidate(self.pfmet,tleps[0])

        medLeps = self.getPassingCands('Medium',self.electrons,self.muons,self.taus)
        candidate['cleanJets'] = self.cleanCands(self.jets,medLeps,0.4)

        # match jet to obj
        for c in ['t']:
            dr = 999
            j = None
            for jet in self.jets:
                jt = DiCandidate(jet,candidate[c])
                if jt.deltaR()<dr:
                    j = jet
                    dr = jt.deltaR()
            if j:
                candidate['{}jet'.format(c)] = j

        return candidate
Exemplo n.º 28
0
    def selectCandidates(self):
        # reset kinfit
        self._kinfit = None

        candidate = {
            'am1': None,
            'am1met': None,
            'am2': None,
            'am2met': None,
            'atm': None,
            'atmmet': None,
            'ath': None,
            'athmet': None,
            'amm': None,
            'ammmet': None,
            'att': None,
            'attmet': None,
            'mmm': None,
            'mmmmet': None,
            'mmt': None,
            'mmtmet': None,
            'h': None,
            'hmet': None,
            'mmm': None,
            'mmmmet': None,
            'met': self.pfmet,
            'athjet': Candidate(None),
            'cleanJets': [],
            'cleanJetsNoTau': [],
        }

        # get leptons
        muons = [m for m in self.muons if self.passMuon(m)]
        taus = [t for t in self.taus if self.passTau(t)]
        leps = muons + taus
        if len(muons) < 3:
            self.report_failure('fails 3 muon requirement')
            return candidate
        if len(taus) < 1:
            self.report_failure('fails 1 tau requirement')
            return candidate

        # get the candidates
        hCand = []
        mmDeltaR = 999
        ttDeltaR = 999
        furthest = 0
        nperms = 0
        nvalid = 0
        for quad in itertools.permutations(leps, 4):
            nperms += 1
            # require mmmt
            if not quad[0].__class__.__name__ == 'Muon': continue
            if not quad[1].__class__.__name__ == 'Muon': continue
            if not quad[2].__class__.__name__ == 'Muon': continue
            if not quad[3].__class__.__name__ == 'Tau': continue
            # trigger match
            matchTrigger = quad[0].matches_IsoMu24(
            ) or quad[0].matches_IsoTkMu24()
            if not matchTrigger: continue
            furthest = max([1, furthest])
            # charge OS
            if quad[0].charge() == quad[1].charge(): continue
            if quad[2].charge() == quad[3].charge(): continue
            furthest = max([2, furthest])
            nvalid += 1
            # require lead m pt>25
            if quad[0].pt() < 25: continue
            furthest = max([3, furthest])
            # make composites
            amm = DiCandidate(quad[0], quad[1])
            att = DiCandidate(quad[2], quad[3])
            # reject events with mu1/mu2 near tm/th
            m1tm = DiCandidate(quad[0], quad[2])
            m1th = DiCandidate(quad[0], quad[3])
            m2tm = DiCandidate(quad[1], quad[2])
            m2th = DiCandidate(quad[1], quad[3])
            if m1tm.deltaR() < 0.4: continue
            if m1th.deltaR() < 0.8: continue
            if m2tm.deltaR() < 0.4: continue
            if m2th.deltaR() < 0.8: continue
            furthest = max([4, furthest])
            # choose best
            if not hCand: hCand = quad
            better = True
            if amm.deltaR() > mmDeltaR:
                better = False
            elif amm.deltaR() == mmDeltaR and att.deltaR() > ttDeltaR:
                better = False
            if better:
                hCand = quad
                mmDeltaR = amm.deltaR()
                ttDeltaR = att.deltaR()

        #print 'number perms: {}, number valid: {}'.format(nperms,nvalid)

        furthestMap = {
            0: 'topology',
            1: 'trigger',
            2: 'OS',
            3: 'lead pt',
            4: 'deltaR',
        }

        if not hCand:
            self.report_failure('no higgs candidate, furthest {}'.format(
                furthestMap[furthest]))
            return candidate

        am1 = hCand[0] if hCand[0].pt() > hCand[1].pt() else hCand[1]
        am2 = hCand[1] if hCand[0].pt() > hCand[1].pt() else hCand[0]
        atm = hCand[2]
        ath = hCand[3]

        amm = DiCandidate(am1, am2)
        if amm.M() > 30:
            self.report_failure('selected higgs amm M>30')
            return candidate
        att = DiCandidate(atm, ath)
        if att.deltaR() > 0.8:
            self.report_failure('selected higgs att DR>0.8')
            return candidate

        candidate['am1'] = am1
        candidate['am1met'] = MetCompositeCandidate(self.pfmet, am1)
        candidate['am2'] = am2
        candidate['am2met'] = MetCompositeCandidate(self.pfmet, am2)
        candidate['atm'] = atm
        candidate['atmmet'] = MetCompositeCandidate(self.pfmet, atm)
        candidate['ath'] = ath
        candidate['athmet'] = MetCompositeCandidate(self.pfmet, ath)
        candidate['amm'] = DiCandidate(am1, am2)
        candidate['ammmet'] = MetCompositeCandidate(self.pfmet, am1, am2)
        candidate['att'] = DiCandidate(atm, ath)
        candidate['attmet'] = MetCompositeCandidate(self.pfmet, atm, ath)
        candidate['h'] = CompositeCandidate(am1, am2, atm, ath)
        candidate['hmet'] = MetCompositeCandidate(self.pfmet, am1, am2, atm,
                                                  ath)
        candidate['mmm'] = CompositeCandidate(am1, am2, atm)
        candidate['mmmmet'] = MetCompositeCandidate(self.pfmet, am1, am2, atm)
        candidate['mmt'] = CompositeCandidate(am1, am2, ath)
        candidate['mmtmet'] = MetCompositeCandidate(self.pfmet, am1, am2, ath)

        if doPacked:
            candidate['ch1'] = Candidate(None)
            candidate['ch2'] = Candidate(None)
            candidate['mmch'] = CompositeCandidate()
            candidate['ttch'] = CompositeCandidate()

            def passPacked(ch):
                if ch.dz() > 0.5: return False
                return True

            packed = [p for p in self.packed if passPacked(p)]

            ch1 = None
            ch2 = None
            for ch in packed:
                if not ch1: ch1 = ch
                if not ch2: ch2 = ch
                drmm = deltaR(ch.eta(), ch.phi(), candidate['amm'].eta(),
                              candidate['amm'].phi())
                drm1 = deltaR(ch.eta(), ch.phi(), candidate['am1'].eta(),
                              candidate['am1'].phi())
                drm2 = deltaR(ch.eta(), ch.phi(), candidate['am2'].eta(),
                              candidate['am2'].phi())
                drtt = deltaR(ch.eta(), ch.phi(), candidate['att'].eta(),
                              candidate['att'].phi())
                drtm = deltaR(ch.eta(), ch.phi(), candidate['atm'].eta(),
                              candidate['atm'].phi())
                drth = deltaR(ch.eta(), ch.phi(), candidate['ath'].eta(),
                              candidate['ath'].phi())
                if drmm < deltaR(ch1.eta(), ch1.phi(), candidate['amm'].eta(
                ), candidate['amm'].phi()) and drm1 > 0.02 and drm2 > 0.02:
                    ch1 = ch
                if drtt < deltaR(ch2.eta(), ch2.phi(), candidate['att'].eta(
                ), candidate['att'].phi()) and drtm > 0.02 and drth > 0.02:
                    ch2 = ch
            if ch1:
                candidate['ch1'] = ch1
                candidate['mmch'] = CompositeCandidate(am1, am2, ch1)
            if ch2:
                candidate['ch2'] = ch2
                candidate['ttch'] = CompositeCandidate(atm, ath, ch2)

        # clean the jets
        candidate['cleanJets'] = self.cleanCands(self.jets,
                                                 [am1, am2, atm, ath], 0.4)
        candidate['cleanJetsDR08'] = self.cleanCands(candidate['cleanJets'],
                                                     [ath], 0.8)

        # match jet to tau
        dr = 999
        j = None
        for jet in self.jets:
            jt = DiCandidate(jet, ath)
            if jt.deltaR() < dr:
                j = jet
                dr = jt.deltaR()
        if j:
            candidate['athjet'] = j

        candidate.update(self.getGenCandidates())

        return candidate