Пример #1
0
    def addJetVariables(self, event):
        for i, j in enumerate(
                event.xcleanJets
        ):  #+event.xcleanJetsJERUp+event.xcleanJetsJERDown:
            j.deltaPhi_met = abs(deltaPhi(j.phi(), event.fakemet.phi()))
            j.deltaPhi_jet1 = abs(deltaPhi(j.phi(), event.xcleanJets[0].phi()))
            j.deltaR_lep1 = deltaR(
                event.xcleanLeptons[0].eta(), event.xcleanLeptons[0].phi(),
                j.eta(), j.phi()) if hasattr(event, "xcleanLeptons") and len(
                    event.xcleanLeptons) > 0 else 9.
            if j.deltaPhi_met < event.minDeltaPhi:
                event.minDeltaPhi = j.deltaPhi_met
            self.addJECUnc(event, j)

        for i, j in enumerate(event.xcleanJetsNoAK8):
            if j.deltaPhi_met < event.minDeltaPhiNoAK8:
                event.minDeltaPhiNoAK8 = j.deltaPhi_met
            if j.deltaR_lep1 < event.minDeltaR: event.minDeltaR = j.deltaR_lep1

        for i, j in enumerate(
                event.xcleanJetsAK8
        ):  #+event.xcleanJetsAK8JERUp+event.xcleanJetsAK8JERDown):
            j.deltaPhi_met = abs(deltaPhi(j.phi(), event.fakemet.phi()))
            j.deltaPhi_jet1 = abs(
                deltaPhi(j.phi(), event.xcleanJetsAK8[0].phi()))
            j.dR_subjets = -1.
            if len(j.subjets('SoftDrop')) >= 2:
                j.dR_subjets = deltaR(
                    j.subjets('SoftDrop')[0].eta(),
                    j.subjets('SoftDrop')[0].phi(),
                    j.subjets('SoftDrop')[1].eta(),
                    j.subjets('SoftDrop')[1].phi())
            self.addCorrectedJetMass(event, j)
            self.addJECUnc(event, j)
Пример #2
0
    def selectZ(self, event):
        event.isZtoEE = False
        event.isZtoMM = False

        if hasattr(event, "muon1") and hasattr(event, "muon2"):
            event.isZtoMM = True
            event.Leptons.append(event.muon1)
            event.Leptons.append(event.muon2)
        elif hasattr(event, "electron1") and hasattr(event, "electron2"):
            event.isZtoEE = True
            event.Leptons.append(event.electron1)
            event.Leptons.append(event.electron2)
        else:
            return False

        theZ = event.Leptons[0].p4() + event.Leptons[1].p4()
        if theZ.mass() < self.cfg_ana.mass_low or theZ.mass(
        ) > self.cfg_ana.mass_high:
            return False
        theZ.charge = event.Leptons[0].charge() + event.Leptons[1].charge()
        theZ.deltaR = deltaR(event.Leptons[0].eta(), event.Leptons[0].phi(),
                             event.Leptons[1].eta(), event.Leptons[1].phi())
        theZ.deltaEta = abs(event.Leptons[0].eta() - event.Leptons[1].eta())
        theZ.deltaPhi = deltaPhi(event.Leptons[0].phi(),
                                 event.Leptons[1].phi())
        theZ.deltaPhi_met = deltaPhi(theZ.phi(), event.met.phi())
        theZ.deltaPhi_jet1 = deltaPhi(theZ.phi(), event.Jets[0].phi())
        event.Z = theZ

        return True
Пример #3
0
 def selectZ(self, event):
     event.isZtoEE = False
     event.isZtoMM = False
     
     if hasattr(event, "muon1") and hasattr(event, "muon2"):
         event.isZtoMM = True
         event.Leptons.append(event.muon1)
         event.Leptons.append(event.muon2)
     elif hasattr(event, "electron1") and hasattr(event, "electron2"):
         event.isZtoEE = True
         event.Leptons.append(event.electron1)
         event.Leptons.append(event.electron2)
     else:
         return False
         
     theZ = event.Leptons[0].p4() + event.Leptons[1].p4()
     if theZ.mass() < self.cfg_ana.mass_low or theZ.mass() > self.cfg_ana.mass_high:
         return False
     theZ.charge = event.Leptons[0].charge() + event.Leptons[1].charge()
     theZ.deltaR = deltaR(event.Leptons[0].eta(), event.Leptons[0].phi(), event.Leptons[1].eta(), event.Leptons[1].phi())
     theZ.deltaEta = abs(event.Leptons[0].eta() - event.Leptons[1].eta())
     theZ.deltaPhi = deltaPhi(event.Leptons[0].phi(), event.Leptons[1].phi())
     theZ.deltaPhi_met = deltaPhi(theZ.phi(), event.met.phi())
     theZ.deltaPhi_jet1 = deltaPhi(theZ.phi(), event.Jets[0].phi())
     event.Z = theZ
     
     return True
Пример #4
0
 def selectFatJet(self, event):
     if not len(event.cleanJetsAK8) >= 1:
         return False
     if not event.cleanJetsAK8[0].pt() > self.cfg_ana.fatjet_pt: 
         return False
     
     # FatJet selections
     if not event.cleanJetsAK8[0].nSubJetTags >= 2:
         return False
     if not event.cleanJetsAK8[0].userFloat(self.cfg_ana.fatjet_mass_algo) > self.cfg_ana.fatjet_mass:
         return False
     if not hasattr(event.cleanJetsAK8[0], "tau21") or not event.cleanJetsAK8[0].tau21 > self.cfg_ana.fatjet_tau21:
         return False
     
     # Add subjets to the event
     event.SubJets = event.cleanJetsAK8[0].subjets('SoftDrop')
     
     # Higgs candidate
     theV = event.cleanJetsAK8[0].p4()
     theV.charge = event.cleanJetsAK8[0].charge()
     theV.deltaR = deltaR(event.SubJets[0].eta(), event.SubJets[0].phi(), event.SubJets[1].eta(), event.SubJets[1].phi())
     theV.deltaEta = abs(event.SubJets[0].eta() - event.SubJets[1].eta())
     theV.deltaPhi = deltaPhi(event.SubJets[0].phi(), event.SubJets[1].phi())
     theV.deltaPhi_met = deltaPhi(theV.phi(), event.met.phi())
     theV.deltaPhi_jet1 = deltaPhi(theV.phi(), event.cleanJetsAK8[0].phi())
     event.V = theV
     
     return True
Пример #5
0
    def fillDiLepton(self, tree, diLepton):
        self.fill(tree, 'visMass', diLepton.mass())
        self.fill(tree, 'svfitMass', diLepton.svfitMass())
        self.fill(tree, 'pZetaMET', diLepton.pZetaMET())
        self.fill(tree, 'pZetaVis', diLepton.pZetaVis())
        self.fill(tree, 'pZetaDisc', diLepton.pZetaDisc())
        self.fill(tree, 'mt', diLepton.mTLeg2())
        self.fill(tree, 'mtleg2', diLepton.mTLeg2()
                  )  # RIC: handy for tt, redundant but non destructive
        self.fill(tree, 'mtleg1', diLepton.mTLeg1())
        # RIC: can't find cov matrix... will look it up later
        #self.fill(tree, 'metcov00', diLepton.metSig().significance()(0,0))
        #self.fill(tree, 'metcov01', diLepton.metSig().significance()(0,1))
        #self.fill(tree, 'metcov10', diLepton.metSig().significance()(1,0))
        #self.fill(tree, 'metcov11', diLepton.metSig().significance()(1,1))
        self.fill(tree, 'metphi', diLepton.met().phi())
        self.fill(tree, 'mex', diLepton.met().px())
        self.fill(tree, 'mey', diLepton.met().py())
        self.fill(tree, 'met', diLepton.met().pt())

        pthiggs = (diLepton.leg1().p4() + diLepton.leg2().p4() +
                   diLepton.met().p4()).pt()
        self.fill(tree, 'pthiggs', pthiggs)

        l1eta = diLepton.leg1().eta()
        l2eta = diLepton.leg2().eta()
        l1phi = diLepton.leg1().phi()
        l2phi = diLepton.leg2().phi()
        metphi = diLepton.met().phi()
        self.fill(tree, 'deltaPhiL1L2', deltaPhi(l1phi, l2phi))
        self.fill(tree, 'deltaEtaL1L2', abs(l1eta - l2eta))
        self.fill(tree, 'deltaRL1L2', deltaR(l1eta, l1phi, l2eta, l2phi))
        self.fill(tree, 'deltaPhiL1MET', deltaPhi(l1phi, metphi))
        self.fill(tree, 'deltaPhiL2MET', deltaPhi(l2phi, metphi))
Пример #6
0
    def process(self, event):
        self.readCollections( event.input )
        pf = map( PhysicsObject, self.handles['pf'].product() )
        leptons = getattr(event,self.leptonTag)
        self.IsolationComputer.setPackedCandidates(self.handles['pf'].product())


        #first trim the photons that are only near leptons
        direct=[]
        forIso=[]


        for p in pf:
            if p.pdgId() != 22 or not( p.pt() > 2.0 and abs(p.eta()) < 2.4 ):
                continue
            scVetoed = False
            for l in leptons:
                if abs(l.pdgId())==11 and self.electronID(l):
                    #print "Testing photon pt %5.1f eta %+7.4f phi %+7.4f vs ele pt %.1f eta %+7.4f  phi %+7.4f sc  eta %+7.4f  phi %+7.4f" % ( p.pt(), p.eta(), p.phi(), l.pt(), l.eta(), l.phi(), l.superCluster().eta(), l.superCluster().phi() )
                    #print "Testing                                                       deta %+7.4f dphi %+7.4f sc deta %+7.4f dphi %+7.4f" % ( abs(p.eta()-l.eta()), deltaPhi(p.phi(),l.phi()), abs(p.eta()-l.superCluster().eta()), deltaPhi(p.phi(),l.superCluster().phi()))
                    if self.cfg_ana.electronVeto == "superclusterEta":
                        if (abs(p.eta()-l.superCluster().eta())<0.05 and abs(deltaPhi(p.phi(),l.superCluster().phi()))<2) or deltaR(p.eta(),p.phi(),l.superCluster().eta(),l.superCluster().phi())<0.15: 
                            scVetoed = True; break
                    elif self.cfg_ana.electronVeto == "electronEta":
                        if (abs(p.eta()-l.eta())<0.05 and abs(deltaPhi(p.phi(),l.phi()))<2) or deltaR(p.eta(),p.phi(),l.eta(),l.phi())<0.15: 
                            scVetoed = True; break
                    else: 
                        raise RuntimeError, "electronVeto option %r not implemented" % self.cfg_ana.electronVeto
            if scVetoed: continue
            okNoIso = False; okIfIso = False
            for l in leptons:
                DR =deltaR(l.eta(),l.phi(),p.eta(),p.phi())     
                if DR<0.07 and p.pt()>2.0:
                    direct.append(p)
                    okNoIso = True
                    break;
                elif  DR<0.5 and p.pt()>4.0:   
                    okIfIso = True
            if okIfIso and not okNoIso:
                forIso.append(p)
        isolatedPhotons=[]        
        for g in forIso:
            g.absIsoCH = self.IsolationComputer.chargedAbsIso(g.physObj,0.3,0.0001,0.2)
            g.absIsoPU = self.IsolationComputer.puAbsIso(g.physObj,0.3,0.0001,0.2)
            g.absIsoNH = self.IsolationComputer.neutralHadAbsIsoRaw(g.physObj,0.3,0.01,0.5)
            g.absIsoPH = self.IsolationComputer.photonAbsIsoRaw(g.physObj,0.3,0.01,0.5)
            g.relIso   = (g.absIsoCH+g.absIsoPU+g.absIsoNH+g.absIsoPH)/g.pt()
            if g.relIso<1.0:
                isolatedPhotons.append(g)

        event.fsrPhotons = isolatedPhotons+direct
                    
        # save all, for debugging
        event.fsrPhotonsNoIso = forIso + direct
        for fsr in event.fsrPhotonsNoIso:
            closest = min(leptons, key = lambda l : deltaR(fsr.eta(),fsr.phi(),l.eta(),l.phi()))
            fsr.globalClosestLepton = closest

        return True
Пример #7
0
    def calculateSUSYVars(self, event):
        met = ROOT.pat.MET(self.handles['met'].product()[0])
        mva_met = event.diLepton.met()

        event.minDphiMETJets = min(
            deltaPhi(met.phi(), jet.phi())
            for jet in event.cleanJets30) if event.cleanJets30 else -999.
        event.minDphiMVAMETJets = min(
            deltaPhi(mva_met.phi(), jet.phi())
            for jet in event.cleanJets30) if event.cleanJets30 else -999.
Пример #8
0
    def selectFatJet(self, event):
        if not len(event.cleanFatJets) >= 1:
            return False
        if not event.cleanFatJets[0].pt() > self.cfg_ana.fatjet_pt: 
            return False
        
        # Add n-subjettiness
        for i, j in enumerate(event.cleanFatJets):
            j.tau21 = j.userFloat("NjettinessAK8:tau2")/j.userFloat("NjettinessAK8:tau1")
        
        #########
        # FIXME dirty hack: count the number of ak4 b-tagged jet close instead
        # Count number of b-tagged subjets
        nSubJetTags = 0
        for f in event.cleanFatJets:
            subJets = []
            for j in event.cleanJets:
                if deltaR(f.eta(), f.phi(), j.eta(), j.phi())<0.8:
                    subJets.append(j)
            subJets.sort(key = lambda x : x.btag('combinedInclusiveSecondaryVertexV2BJetTags'), reverse = True)
            f.nSubJets = len(subJets)
            if len(subJets) >= 1:
                f.subJet1 = subJets[0]
            if len(subJets) >= 2:
                f.subJet2 = subJets[1]
        #########
        
        # FatJet selections
        if not event.cleanFatJets[0].nSubJets >= 1 or not event.cleanFatJets[0].subJet1.btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatjet_tag1:
            return False
#        if not event.cleanFatJets[0].nSubJets >= 2 or not event.cleanFatJets[0].subJet2.btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatjet_tag2:
#            return False
        if not event.cleanFatJets[0].userFloat("ak8PFJetsCHSPrunedLinks") > self.cfg_ana.fatjet_mass:
            return False
        if not hasattr(event.cleanFatJets[0], "tau21") or not event.cleanFatJets[0].tau21 > self.cfg_ana.fatjet_tau21:
            return False
        
        
        # Higgs candidate
        #prunedJet = copy.deepcopy(event.cleanFatJets[0]) # Copy fatJet...
        #prunedJet.setMass(prunedJet.userFloat("ak8PFJetsCHSPrunedLinks")) # ... and set the mass to the pruned mass
        theH = event.cleanFatJets[0].p4()
        theH.charge = event.cleanFatJets[0].charge()
        theH.deltaR = deltaR(event.cleanFatJets[0].subJet1.eta(), event.cleanFatJets[0].subJet1.phi(), event.cleanFatJets[0].subJet2.eta(), event.cleanFatJets[0].subJet2.phi()) if hasattr(event.cleanFatJets[0], "subJet2") else -1.
        theH.deltaEta = abs(event.cleanFatJets[0].subJet1.eta() - event.cleanFatJets[0].subJet2.eta()) if hasattr(event.cleanFatJets[0], "subJet2") else -9.
        theH.deltaPhi = deltaPhi(event.cleanFatJets[0].subJet1.phi(), event.cleanFatJets[0].subJet2.phi()) if hasattr(event.cleanFatJets[0], "subJet2") else -9.
        theH.deltaPhi_met = deltaPhi(theH.phi(), event.met.phi())
        theH.deltaPhi_jet1 = deltaPhi(theH.phi(), event.cleanFatJets[0].phi())
        event.H = theH
        
        return True
Пример #9
0
    def selectFatJet(self, event):
        if not len(event.cleanFatJets) >= 1:
            return False
        if not event.cleanFatJets[0].pt() > self.cfg_ana.fatjet_pt: 
            return False
        
        # Add n-subjettiness
        for i, j in enumerate(event.cleanFatJets):
            j.tau21 = j.userFloat("NjettinessAK8:tau2")/j.userFloat("NjettinessAK8:tau1")
        
        #########
        # FIXME dirty hack: count the number of ak4 b-tagged jet close instead
        # Count number of b-tagged subjets
        nSubJetTags = 0
        for f in event.cleanFatJets:
            subJets = []
            for j in event.cleanJets:
                if deltaR(f.eta(), f.phi(), j.eta(), j.phi())<0.8:
                    subJets.append(j)
            subJets.sort(key = lambda x : x.btag('combinedInclusiveSecondaryVertexV2BJetTags'), reverse = True)
            f.nSubJets = len(subJets)
            if len(subJets) >= 1:
                f.subJet1 = subJets[0]
            if len(subJets) >= 2:
                f.subJet2 = subJets[1]
        #########
        
        # FatJet selections
        if not event.cleanFatJets[0].nSubJets >= 1 or not event.cleanFatJets[0].subJet1.btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatjet_tag1:
            return False
#        if not event.cleanFatJets[0].nSubJets >= 2 or not event.cleanFatJets[0].subJet2.btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatjet_tag2:
#            return False
        if not event.cleanFatJets[0].userFloat("ak8PFJetsCHSPrunedLinks") > self.cfg_ana.fatjet_mass:
            return False
        if not hasattr(event.cleanFatJets[0], "tau21") or not event.cleanFatJets[0].tau21 > self.cfg_ana.fatjet_tau21:
            return False
        
        
        # Higgs candidate
        prunedJet = copy.deepcopy(event.cleanFatJets[0]) # Copy fatJet...
        prunedJet.setMass(prunedJet.userFloat("ak8PFJetsCHSPrunedLinks")) # ... and set the mass to the pruned mass
        theH = prunedJet.p4()
        theH.charge = event.cleanFatJets[0].charge()
        theH.deltaR = deltaR(event.cleanFatJets[0].subJet1.eta(), event.cleanFatJets[0].subJet1.phi(), event.cleanFatJets[0].subJet2.eta(), event.cleanFatJets[0].subJet2.phi()) if hasattr(event.cleanFatJets[0], "subJet2") else -1.
        theH.deltaEta = abs(event.cleanFatJets[0].subJet1.eta() - event.cleanFatJets[0].subJet2.eta()) if hasattr(event.cleanFatJets[0], "subJet2") else -9.
        theH.deltaPhi = deltaPhi(event.cleanFatJets[0].subJet1.phi(), event.cleanFatJets[0].subJet2.phi()) if hasattr(event.cleanFatJets[0], "subJet2") else -9.
        theH.deltaPhi_met = deltaPhi(theH.phi(), event.met.phi())
        theH.deltaPhi_jet1 = deltaPhi(theH.phi(), event.cleanFatJets[0].phi())
        event.H = theH
        
        return True
Пример #10
0
 def selectW(self, event):
     if not hasattr(event, "muon1"):
         return False
     theW = event.selectedMuons[0].p4() + event.met.p4()
     theW.deltaPhi_met = deltaPhi(event.selectedMuons[0].phi(), event.met.phi())
     theW.mT = math.sqrt( 2.*event.selectedMuons[0].et()*event.met.pt()*(1.-math.cos(theW.deltaPhi_met)) )        
     if theW.mT < self.cfg_ana.mt_low or theW.mT > self.cfg_ana.mt_high:
         return False
     theW.charge = event.selectedMuons[0].charge()
     theW.deltaEta = abs(event.selectedMuons[0].eta())
     theW.deltaPhi = deltaPhi(event.selectedMuons[0].phi(), event.met.phi())
     theW.deltaR = deltaR(event.selectedMuons[0].eta(), event.selectedMuons[0].phi(), 0, event.met.phi())
     event.W = theW
     return True
Пример #11
0
 def selectW(self, event):
     if not hasattr(event, "muon1"):
         return False
     theW = event.selectedMuons[0].p4() + event.met.p4()
     theW.deltaPhi_met = deltaPhi(event.selectedMuons[0].phi(), event.met.phi())
     theW.mT = math.sqrt( 2.*event.selectedMuons[0].et()*event.met.pt()*(1.-math.cos(theW.deltaPhi_met)) )        
     if theW.mT < self.cfg_ana.mt_low or theW.mT > self.cfg_ana.mt_high:
         return False
     theW.charge = event.selectedMuons[0].charge()
     theW.deltaEta = abs(event.selectedMuons[0].eta())
     theW.deltaPhi = deltaPhi(event.selectedMuons[0].phi(), event.met.phi())
     theW.deltaR = deltaR(event.selectedMuons[0].eta(), event.selectedMuons[0].phi(), 0, event.met.phi())
     event.W = theW
     return True
Пример #12
0
    def __init__(self, jets, diLepton, vbfMvaCalc, cjvPtCut):
        '''jets: jets cleaned from the diLepton legs.
        diLepton: the di-tau, for example. Necessary to compute input variables for MVA selection
        '''
        self.cjvPtCut = cjvPtCut
        self.vbfMvaCalc = vbfMvaCalc
        self.jets = jets
        # the MET is taken from the di-lepton, because it can depend on it
        # e.g. recoil corrections, mva met
        self.met = diLepton.met()
        self.leadJets = jets[:2] # taking first 2 jets (leading ones)
        self.otherJets = jets[2:]
        self.centralJets = self.findCentralJets( self.leadJets, self.otherJets )

        # delta eta
        self.deta = self.leadJets[0].eta() - self.leadJets[1].eta()

        # below, the variables for the MVA selection
        # delta phi
        self.dphi = deltaPhi(self.leadJets[0].phi(), self.leadJets[1].phi())
        dijetp4 = self.leadJets[0].p4() + self.leadJets[1].p4()
        # mass of the di-jet system
        self.mjj = dijetp4.M()
        # pt of di-jet system
        self.dijetpt = dijetp4.pt()
        # phi of di-jet system
        self.dijetphi = dijetp4.phi()
        # higgs momentum (defined as the di-lepton momentum + the met momentum)
        # don't access longitudinal quantities!
        self.higgsp4 = diLepton.p4() + self.met.p4()
        # delta phi between dijet system and higgs system
        self.dphidijethiggs = deltaPhi( self.dijetphi, self.higgsp4.phi() )
        # ? 
        visDiLepton = diLepton.leg1 ().p4 () + diLepton.leg2 ().p4 ()
        self.visjeteta = min (
            abs (self.leadJets[0].eta () - visDiLepton.eta ()), 
            abs (self.leadJets[1].eta () - visDiLepton.eta ()))
        # visible higgs pt = di-lepton pt
        self.ptvis = visDiLepton.pt()
        ## self.ptvis = diLepton.pt()
        # new VBF MVA, based on 4 variables
        if self.vbfMvaCalc is not None:
            self.mva = self.vbfMvaCalc.val( self.mjj,
                                            abs(self.deta),
                                            self.visjeteta,
                                            self.ptvis )
        else:
            self.mva = -99.
Пример #13
0
    def __init__(self, jets, diLepton, vbfMvaCalc, cjvPtCut):
        '''jets: jets cleaned from the diLepton legs.
        diLepton: the di-tau, for example. Necessary to compute input variables for MVA selection
        '''
        self.cjvPtCut = cjvPtCut
        self.vbfMvaCalc = vbfMvaCalc
        self.jets = jets
        # the MET is taken from the di-lepton, because it can depend on it
        # e.g. recoil corrections, mva met
        self.met = diLepton.met()
        self.leadJets = jets[:2] # taking first 2 jets (leading ones)
        self.otherJets = jets[2:]
        self.centralJets = self.findCentralJets( self.leadJets, self.otherJets )

        # delta eta
        self.deta = self.leadJets[0].eta() - self.leadJets[1].eta()

        # below, the variables for the MVA selection
        # delta phi
        self.dphi = deltaPhi(self.leadJets[0].phi(), self.leadJets[1].phi())
        dijetp4 = self.leadJets[0].p4() + self.leadJets[1].p4()
        # mass of the di-jet system
        self.mjj = dijetp4.M()
        # pt of di-jet system
        self.dijetpt = dijetp4.pt()
        # phi of di-jet system
        self.dijetphi = dijetp4.phi()
        # higgs momentum (defined as the di-lepton momentum + the met momentum)
        # don't access longitudinal quantities!
        self.higgsp4 = diLepton.p4() + self.met.p4()
        # delta phi between dijet system and higgs system
        self.dphidijethiggs = deltaPhi( self.dijetphi, self.higgsp4.phi() )
        # ? 
        visDiLepton = diLepton.leg1 ().p4 () + diLepton.leg2 ().p4 ()
        self.visjeteta = min (
            abs (self.leadJets[0].eta () - visDiLepton.eta ()), 
            abs (self.leadJets[1].eta () - visDiLepton.eta ()))
        # visible higgs pt = di-lepton pt
        self.ptvis = visDiLepton.pt()
        ## self.ptvis = diLepton.pt()
        # new VBF MVA, based on 4 variables
        if self.vbfMvaCalc is not None:
            self.mva = self.vbfMvaCalc.val( self.mjj,
                                            abs(self.deta),
                                            self.visjeteta,
                                            self.ptvis )
        else:
            self.mva = -99.
Пример #14
0
    def process(self, event):
        self.readCollections(event.input)
        self.counters.counter('events').inc('all events')

        if len(event.cleanJets) >= 0:
            self.counters.counter('events').inc('one jet')

        event.lightJets = [
            j for j in event.cleanJets if not j.btagWP("CSVv2IVFL")
        ]
        event.lightJets.sort(key=lambda j: j.pt(), reverse=True)
        event.ISRJet = event.lightJets[0] if len(event.lightJets) else None

        event.iBs = [i for (i, j) in enumerate(event.cleanJets)]
        event.iBs.sort(key=lambda i: event.cleanJets[i].btag(
            'pfCombinedInclusiveSecondaryVertexV2BJetTags'),
                       reverse=True)

        def mT(b, m):
            return sqrt(2 * b.pt() * m.pt() * (1 - cos(b.phi() - m.phi())))

        event.mtB1 = mT(event.cleanJets[event.iBs[0]],
                        event.met) if len(event.iBs) >= 1 else -99.0
        event.mtB2 = mT(event.cleanJets[event.iBs[1]],
                        event.met) if len(event.iBs) >= 2 else -99.0

        for i in xrange(6):
            setattr(
                event, 'dphiJet%dMet' % (i + 1),
                abs(deltaPhi(event.cleanJets[i].phi(), event.met.phi()))
                if len(event.cleanJets) > i else -99)

        self.counters.counter('events').inc('accepted events')
        return True
Пример #15
0
 def searchISRforVH(self,event):
     p4VH=event.HCSV+event.V
     if p4VH.pt() > 30 :
           phi=pi+p4VH.phi()
           matchedJets=[x for x in event.cleanJetsAll if abs(deltaPhi(phi,x.phi())) < 0.4 and  x.puJetId() > 0 and x.jetID('POG_PFID_Loose') and x not in event.hJetsCSV and x not in event.hJetsaddJetsdR08] 
           if len(matchedJets) > 0 :
               event.isrJetVH=event.cleanJetsAll.index(sorted(matchedJets, key=lambda x:x.pt(),reverse=True)[0])
Пример #16
0
    def computeQGvars(self, jet):

        jet.mult = 0
        sum_weight = 0.
        sum_pt = 0.
        sum_deta = 0.
        sum_dphi = 0.
        sum_deta2 = 0.
        sum_detadphi = 0.
        sum_dphi2 = 0.

        for ii in range(0, jet.numberOfDaughters()):

            part = jet.daughter(ii)

            if part.charge() == 0:  # neutral particles

                if part.pt() < 1.: continue

            else:  # charged particles

                if part.trackHighPurity() == False: continue
                if part.fromPV() <= 1: continue

            jet.mult += 1

            deta = part.eta() - jet.eta()
            dphi = deltaPhi(part.phi(), jet.phi())
            partPt = part.pt()
            weight = partPt * partPt
            sum_weight += weight
            sum_pt += partPt
            sum_deta += deta * weight
            sum_dphi += dphi * weight
            sum_deta2 += deta * deta * weight
            sum_detadphi += deta * dphi * weight
            sum_dphi2 += dphi * dphi * weight

        a = 0.
        b = 0.
        c = 0.

        if sum_weight > 0:
            jet.ptd = math.sqrt(sum_weight) / sum_pt
            ave_deta = sum_deta / sum_weight
            ave_dphi = sum_dphi / sum_weight
            ave_deta2 = sum_deta2 / sum_weight
            ave_dphi2 = sum_dphi2 / sum_weight
            a = ave_deta2 - ave_deta * ave_deta
            b = ave_dphi2 - ave_dphi * ave_dphi
            c = -(sum_detadphi / sum_weight - ave_deta * ave_dphi)
        else:
            jet.ptd = 0.

        delta = math.sqrt(math.fabs((a - b) * (a - b) + 4. * c * c))

        if a + b - delta > 0:
            jet.axis2 = -math.log(math.sqrt(0.5 * (a + b - delta)))
        else:
            jet.axis2 = -1.
Пример #17
0
 def process(self, event):
     self.Sync.GetXaxis().SetBinLabel(1, "All events")
     self.Sync.Fill(0)
     if len(event.cleanJets) >= 1 and event.cleanJets[0].pt()>110. and event.cleanJets[0].chargedHadronEnergyFraction()>0.2 and event.cleanJets[0].neutralHadronEnergyFraction()<0.7 and event.cleanJets[0].neutralEmEnergyFraction()<0.7:
         self.Sync.GetXaxis().SetBinLabel(2, "Jet pT > 110")
         self.Sync.Fill(1)
         # print
         print "* %5d * %5d * %5d * %10.3f * %10.3f * %10.3f * %10.3f * %10.3f * %10.3f * %10.3f * %5d * %5d * %5d * %5d *" % ( event.input.eventAuxiliary().id().run(), event.input.eventAuxiliary().id().luminosityBlock(), event.input.eventAuxiliary().id().event(),  event.cleanJets[0].pt(), event.cleanJets[0].eta(), event.cleanJets[0].phi(), event.cleanJets[1].pt() if len(event.cleanJets)>1 else 0., event.cleanJets[1].eta() if len(event.cleanJets)>1 else 0., event.cleanJets[1].phi() if len(event.cleanJets)>1 else 0., event.met.pt(), len(event.cleanJets), len(event.inclusiveLeptons), len(event.selectedTaus), len(event.selectedPhotons))
         
         if event.input.eventAuxiliary().id().event()==458: print "@@@@@@@@@@@@@@@@@@", abs(deltaPhi(event.cleanJets[0].phi(), event.cleanJets[1].phi())), event.cleanJets[1].neutralHadronEnergyFraction(), event.cleanJets[1].neutralEmEnergyFraction()
         
         
         if len(event.cleanJets) < 2 or ( abs(deltaPhi(event.cleanJets[0].phi(), event.cleanJets[1].phi())) < 2.5 and event.cleanJets[1].neutralHadronEnergyFraction()<0.7 and event.cleanJets[1].neutralEmEnergyFraction()<0.9 ):
             self.Sync.GetXaxis().SetBinLabel(3, "dPhi(j1,j2)<2.5")
             self.Sync.Fill(2)
             if event.met.pt()>200.:
                 self.Sync.GetXaxis().SetBinLabel(4, "MET > 200")
                 self.Sync.Fill(3)
                 if len(event.cleanJets)<3:
                     self.Sync.GetXaxis().SetBinLabel(5, "Jets < 3")
                     self.Sync.Fill(4)
                     if len(event.inclusiveLeptons) == 0:
                         self.Sync.GetXaxis().SetBinLabel(6, "Lepton veto")
                         self.Sync.Fill(5)
                         if len(event.selectedTaus) == 0:
                             self.Sync.GetXaxis().SetBinLabel(7, "Tau veto")
                             self.Sync.Fill(6)
                             if len(event.selectedPhotons) == 0:
                                 self.Sync.GetXaxis().SetBinLabel(8, "Photon veto")
                                 self.Sync.Fill(7)
                             
     
     return True
Пример #18
0
    def makeZllObjects(self, event):

        import ROOT

        vetoLeptons = [
            l for l in event.selectedLeptons
            if l.pt() > 10 and abs(l.eta()) < 2.5
        ]

        # MET + zll
        event.zll_ht = -999.
        event.zll_deltaPhiMin = -999.
        event.zll_met_pt = -999.
        event.zll_met_phi = -999.
        event.zll_diffMetMht = -999.
        event.zll_mhtJet40j = -999.
        event.zll_mhtPhiJet40j = -999.
        event.zll_p4 = ROOT.reco.Particle.LorentzVector(0, 0, 0, 0)

        if len(vetoLeptons) == 2:
            event.zll_met = ROOT.reco.Particle.LorentzVector(
                event.met.px(), event.met.py(), 0, 0)
            for l in vetoLeptons:
                event.zll_met = ROOT.reco.Particle.LorentzVector(
                    event.zll_met.px() + l.px(),
                    event.zll_met.py() + l.py(), 0, 0)

            event.zll_met_pt = event.zll_met.pt()
            event.zll_met_phi = event.zll_met.phi()

            # defining mht as hadronic mht
            event.zll_mhtJet40j = event.mhtJet40j
            event.zll_mhtPhiJet40j = event.mhtPhiJet40j

            # look for minimal deltaPhi between MET and four leading jets with pt>40 and |eta|<2.4
            event.zll_deltaPhiMin = 999.
            objects40jc = [
                j for j in event.cleanJets
                if j.pt() > 40 and abs(j.eta()) < 2.5
            ]
            objects40ja = [j for j in event.cleanJets if j.pt() > 40]
            event.zll_ht = sum([x.pt() for x in objects40jc])
            for n, j in enumerate(objects40ja):
                if n > 3: break
                thisDeltaPhi = abs(deltaPhi(j.phi(), event.zll_met.phi()))
                if thisDeltaPhi < event.zll_deltaPhiMin:
                    event.zll_deltaPhiMin = thisDeltaPhi

            # absolute value of the vectorial difference between met and mht
            zll_diffMetMht_vec = ROOT.reco.Particle.LorentzVector(
                event.mhtJet40jvec.px() - event.zll_met.px(),
                event.mhtJet40jvec.py() - event.zll_met.py(), 0, 0)
            event.zll_diffMetMht = sqrt(
                zll_diffMetMht_vec.px() * zll_diffMetMht_vec.px() +
                zll_diffMetMht_vec.py() * zll_diffMetMht_vec.py())

            # di-lepton invariant mass
            for l in vetoLeptons:
                event.zll_p4 += l.p4()
Пример #19
0
    def process(self, event):
        self.readCollections(event.input)
        self.counters.counter('events').inc('all events')

        if self.eMu in ("require", "veto"):
            has = True
            if len(event.selectedLeptons) < 2: has = False
            lep1, lep2 = event.selectedLeptons[:2]
            if abs(lep1.pdgId() + lep2.pdgId()) != 2: has = False
            if lep1.pt() < 25 or lep2.pt() < 20: has = False
            if self.eMu == "require" and not has: return False
            elif self.eMu == "veto" and has: return False
        if self.llNoZ in ("require", "veto"):
            has = True
            if len(event.selectedLeptons) < 2: has = False
            lep1, lep2 = event.selectedLeptons[:2]
            if lep1.pdgId() + lep2.pdgId() != 0: has = False
            if lep1.pt() < 25 or lep2.pt() < 20: has = False
            if abs((lep1.p4() + lep2.p4()).M() - 91.2) < 15: has = False
            if self.llNoZ == "require" and not has: return False
            elif self.llNoZ == "veto" and has: return False
        if self.bJet == "require":
            if len(event.cleanJets) < 1: return False
            if not sum((j.pt() > 30 and j.btagWP("CSVv2IVFM"))
                       for j in event.cleanJets):
                return False
        if len(event.cleanJets) >= 0:
            self.counters.counter('events').inc('one jet')

        event.lightJets = [
            j for j in event.cleanJets if not j.btagWP("CSVv2IVFL")
        ]
        event.lightJets.sort(key=lambda j: j.pt(), reverse=True)
        event.ISRJet = event.lightJets[0] if len(event.lightJets) else None

        event.iBs = [i for (i, j) in enumerate(event.cleanJets)]
        event.iBs.sort(key=lambda i: event.cleanJets[i].btag(
            'pfCombinedInclusiveSecondaryVertexV2BJetTags'),
                       reverse=True)

        def mT(b, m):
            return sqrt(2 * b.pt() * m.pt() * (1 - cos(b.phi() - m.phi())))

        event.mtB1 = mT(event.cleanJets[event.iBs[0]],
                        event.met) if len(event.iBs) >= 1 else -99.0
        event.mtB2 = mT(event.cleanJets[event.iBs[1]],
                        event.met) if len(event.iBs) >= 2 else -99.0

        for i in xrange(6):
            setattr(
                event, 'dphiJet%dMet' % (i + 1),
                abs(deltaPhi(event.cleanJets[i].phi(), event.met.phi()))
                if len(event.cleanJets) > i else -99)

        self.counters.counter('events').inc('accepted events')
        return True
Пример #20
0
 def addLeptonVariables(self, event):
     v = event.goodVertices[0].position()
     for i, l in enumerate(event.inclusiveLeptons):
         l.isHEEP = self.isHEEP(l, v)
         l.isCustomTracker = self.isCustomTracker(l, v)
         l.deltaPhi_met = abs(deltaPhi(l.phi(), event.met.phi()))
         l.dxyPV = l.gsfTrack().dxy(
             v) if l.isElectron() else l.bestTrack().dxy(v)
         l.dzPV = l.gsfTrack().dz(
             v) if l.isElectron() else l.bestTrack().dz(v)
         l.trkIso = l.trackIso() / l.pt() if l.isMuon() else -1.
Пример #21
0
    def createW(self, event, lepton):
        theW = lepton.p4() + event.met.p4()
        theW.charge = lepton.charge()
        theW.deltaR = deltaR(lepton.eta(), lepton.phi(), 0, event.met.phi())
        theW.deltaEta = abs(lepton.eta())
        theW.deltaPhi = abs(deltaPhi(lepton.phi(), event.met.phi()))
        theW.deltaPhi_met = abs(deltaPhi(lepton.phi(), event.met.phi()))
        theW.mT = math.sqrt(
            2. * lepton.et() * event.met.pt() *
            (1. - math.cos(deltaPhi(lepton.phi(), event.met.phi()))))
        event.theW = theW
        # Recoil correction variables
        recoilX = -event.met.px() - lepton.px()
        recoilY = -event.met.py() - lepton.py()
        event.Upara = (recoilX * lepton.px() +
                       recoilY * lepton.py()) / lepton.pt()
        event.Uperp = (recoilX * lepton.py() -
                       recoilY * lepton.px()) / lepton.pt()

        return True
Пример #22
0
    def process(self, event):
        self.readCollections(event.input)
        pf = map(PhysicsObject, self.handles['pf'].product())
        leptons = getattr(event, self.leptonTag)
        self.IsolationComputer.setPackedCandidates(
            self.handles['pf'].product())

        #first trim the photons that are only near leptons
        direct = []
        forIso = []

        for p in pf:
            if p.pdgId() != 22 or not (p.pt() > 2.0 and abs(p.eta()) < 2.4):
                continue
            for l in leptons:
                if abs(l.pdgId()) == 11 and self.electronID(l):
                    if (abs(p.eta() - l.eta()) < 0.05
                            and deltaPhi(p.phi(), l.phi()) < 2) or deltaR(
                                p.eta(), p.phi(), l.eta(), l.phi()) < 0.15:
                        continue
                DR = deltaR(l.eta(), l.phi(), p.eta(), p.phi())
                if DR < 0.07 and p.pt() > 2.0:
                    direct.append(p)
                    break
                elif DR < 0.5 and p.pt() > 4.0:
                    forIso.append(p)
                    break
        isolatedPhotons = []
        for g in forIso:
            g.absIsoCH = self.IsolationComputer.chargedAbsIso(
                g.physObj, 0.3, 0.0001, 0.2)
            g.absIsoPU = self.IsolationComputer.puAbsIso(
                g.physObj, 0.3, 0.0001, 0.2)
            g.absIsoNH = self.IsolationComputer.neutralHadAbsIsoRaw(
                g.physObj, 0.3, 0.01, 0.5)
            g.absIsoPH = self.IsolationComputer.photonAbsIsoRaw(
                g.physObj, 0.3, 0.01, 0.5)
            g.relIso = (g.absIsoCH + g.absIsoPU + g.absIsoNH +
                        g.absIsoPH) / g.pt()
            if g.relIso < 1.0:
                isolatedPhotons.append(g)

        event.fsrPhotons = isolatedPhotons + direct

        # save all, for debugging
        event.fsrPhotonsNoIso = forIso + direct
        for fsr in event.fsrPhotonsNoIso:
            closest = min(
                leptons,
                key=lambda l: deltaR(fsr.eta(), fsr.phi(), l.eta(), l.phi()))
            fsr.globalClosestLepton = closest

        return True
Пример #23
0
 def searchISRforVH(self, event):
     p4VH = event.HCSV + event.V
     if p4VH.pt() > 30:
         phi = pi + p4VH.phi()
         matchedJets = [
             x for x in event.cleanJetsAll
             if abs(deltaPhi(phi, x.phi())) < 0.4 and x.puJetId() > 0
             and x.jetID('POG_PFID_Loose') and x not in event.hJetsCSV
             and x not in event.hJetsaddJetsdR08
         ]
         if len(matchedJets) > 0:
             event.isrJetVH = event.cleanJetsAll.index(
                 sorted(matchedJets, key=lambda x: x.pt(), reverse=True)[0])
Пример #24
0
    def selectResolvedJet(self, event):
        if not len(event.cleanJets) >= 2:
            return False
        if not event.cleanJets[0].pt() > self.cfg_ana.jet1_pt: 
            return False
#        if not event.cleanJets[0].btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.jet1_tag: 
#            return False
        if not event.cleanJets[1].pt() > self.cfg_ana.jet2_pt: 
            return False
#        if not event.cleanJets[1].btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.jet2_tag: 
#            return False
        
        # Higgs candidate
        theH = event.cleanJets[0].p4() + event.cleanJets[1].p4()
        theH.charge = event.cleanJets[0].charge() + event.cleanJets[1].charge()
        theH.deltaR = deltaR(event.cleanJets[0].eta(), event.cleanJets[0].phi(), event.cleanJets[1].eta(), event.cleanJets[1].phi())
        theH.deltaEta = abs(event.cleanJets[0].eta() - event.cleanJets[1].eta())
        theH.deltaPhi = deltaPhi(event.cleanJets[0].phi(), event.cleanJets[1].phi())
        theH.deltaPhi_met = deltaPhi(theH.phi(), event.met.phi())
        theH.deltaPhi_jet1 = deltaPhi(theH.phi(), event.cleanJets[0].phi())
        event.H = theH
        
        return True
Пример #25
0
    def selectResolvedJet(self, event):
        if not len(event.cleanJets) >= 2:
            return False
        if not event.cleanJets[0].pt() > self.cfg_ana.jet1_pt: 
            return False
#        if not event.cleanJets[0].btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.jet1_tag: 
#            return False
        if not event.cleanJets[1].pt() > self.cfg_ana.jet2_pt: 
            return False
#        if not event.cleanJets[1].btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.jet2_tag: 
#            return False
        
        # Higgs candidate
        theH = event.cleanJets[0].p4() + event.cleanJets[1].p4()
        theH.charge = event.cleanJets[0].charge() + event.cleanJets[1].charge()
        theH.deltaR = deltaR(event.cleanJets[0].eta(), event.cleanJets[0].phi(), event.cleanJets[1].eta(), event.cleanJets[1].phi())
        theH.deltaEta = abs(event.cleanJets[0].eta() - event.cleanJets[1].eta())
        theH.deltaPhi = deltaPhi(event.cleanJets[0].phi(), event.cleanJets[1].phi())
        theH.deltaPhi_met = deltaPhi(theH.phi(), event.met.phi())
        theH.deltaPhi_jet1 = deltaPhi(theH.phi(), event.cleanJets[0].phi())
        event.H = theH
        
        return True
Пример #26
0
 def createZ(self, event, leptons):
     theZ = leptons[0].p4() + leptons[1].p4()
     theZ.charge = leptons[0].charge() + leptons[1].charge()
     theZ.deltaR = deltaR(leptons[0].eta(), leptons[0].phi(),
                          leptons[1].eta(), leptons[1].phi())
     theZ.deltaEta = abs(leptons[0].eta() - leptons[1].eta())
     theZ.deltaPhi = abs(deltaPhi(leptons[0].phi(), leptons[1].phi()))
     #theZ.deltaPhi_met = abs(deltaPhi(theZ.phi(), event.met.phi()))
     event.theZ = theZ
     # Recoil correction variables
     recoilX = -event.met.px() - event.theZ.px()
     recoilY = -event.met.py() - event.theZ.py()
     event.Upara = (recoilX * event.theZ.px() +
                    recoilY * event.theZ.py()) / event.theZ.pt()
     event.Uperp = (recoilX * event.theZ.py() -
                    recoilY * event.theZ.px()) / event.theZ.pt()
     return True
Пример #27
0
 def syncSR(self, event):
     self.SR.Fill(0)
     if len(event.cleanJets) >= 1 and event.cleanJets[0].pt()>110. and event.cleanJets[0].chargedHadronEnergyFraction()>0.2 and event.cleanJets[0].neutralHadronEnergyFraction()<0.7 and event.cleanJets[0].neutralEmEnergyFraction()<0.7:
         self.SR.Fill(1)                               
         if len(event.cleanJets) < 2 or ( abs(deltaPhi(event.cleanJets[0].phi(), event.cleanJets[1].phi())) < 2.5 and event.cleanJets[1].neutralHadronEnergyFraction()<0.7 and event.cleanJets[1].neutralEmEnergyFraction()<0.9 ):
             self.SR.Fill(2)
             if event.met.pt()>200.:
                 self.SR.Fill(3)
                 if len(event.cleanJets) < 3:
                     self.SR.Fill(4)
                     if len(event.selectedLeptons) == 0:
                         self.SR.Fill(5)
                         if len(event.selectedTaus) == 0:
                             self.SR.Fill(6)
                             if len(event.selectedPhotons) == 0:
                                 self.SR.Fill(7)
                                 if self.cfg_ana.verbose: print "%d:%d:%d" % ( event.input.eventAuxiliary().id().run(), event.input.eventAuxiliary().id().luminosityBlock(), event.input.eventAuxiliary().id().event() )
Пример #28
0
    def process(self, event):
        self.readCollections(event.input)

        puppi = self.handles['puppi'].product()

        for tau in self.getter(event):
            puppi_iso_cands = []
            puppi_iso_cands_04 = []
            puppi_iso_cands_03 = []
            isoPtSumOld = 0.
            tau_eta = tau.eta()
            tau_phi = tau.phi()
            # Normal loop crashes for some reason...
            for i_iso in range(len(tau.isolationCands())):
                isoPtSumOld += tau.isolationCands()[i_iso].pt()
                eta = tau.isolationCands()[i_iso].eta()
                phi = tau.isolationCands()[i_iso].phi()
                n_p = 0
                for c_p in puppi:
                    if abs(eta - c_p.eta()) < 0.00001 and \
                       abs(deltaPhi(phi, c_p.phi())) < 0.00001:
                        pdgId = c_p.pdgId()
                        if abs(pdgId) not in [22, 211]:
                            print 'Found puppi particle with pdgID', pdgId, 'ignoring...'
                            continue

                        puppi_iso_cands.append(c_p)
                        n_p += 1
                        dr = deltaR(c_p.eta(), c_p.phi(), tau_eta, tau_phi)
                        if dr < 0.4:
                            puppi_iso_cands_04.append(c_p)
                        if dr < 0.3:
                            puppi_iso_cands_03.append(c_p)
                if n_p > 1:
                    print 'WARNING, found more than 2 matching puppi particles'

            tau.puppi_iso_pt = sum(c_p.pt() for c_p in puppi_iso_cands)
            tau.puppi_iso04_pt = sum(c_p.pt() for c_p in puppi_iso_cands_04)
            tau.puppi_iso03_pt = sum(c_p.pt() for c_p in puppi_iso_cands_03)
            # Add puppi isolation

        return True
    def process(self, event):
        self.readCollections(event.input)

        puppi = self.handles['puppi'].product()

        for tau in self.getter(event):
            puppi_iso_cands = []
            puppi_iso_cands_04 = []
            puppi_iso_cands_03 = []
            isoPtSumOld = 0.
            tau_eta = tau.eta()
            tau_phi = tau.phi()
            # Normal loop crashes for some reason...
            for i_iso in range(len(tau.isolationCands())):
                    isoPtSumOld += tau.isolationCands()[i_iso].pt()
                    eta = tau.isolationCands()[i_iso].eta()
                    phi = tau.isolationCands()[i_iso].phi()
                    n_p = 0
                    for c_p in puppi:
                        if abs(eta - c_p.eta()) < 0.00001 and \
                           abs(deltaPhi(phi, c_p.phi())) < 0.00001:
                            pdgId = c_p.pdgId()
                            if abs(pdgId) not in [22, 211]:
                                print 'Found puppi particle with pdgID', pdgId, 'ignoring...'
                                continue
                                
                            puppi_iso_cands.append(c_p)
                            n_p += 1
                            dr = deltaR(c_p.eta(), c_p.phi(), tau_eta, tau_phi)
                            if dr < 0.4:
                                puppi_iso_cands_04.append(c_p)
                            if dr < 0.3:
                                puppi_iso_cands_03.append(c_p)
                    if n_p > 1:
                        print 'WARNING, found more than 2 matching puppi particles'

            tau.puppi_iso_pt = sum(c_p.pt() for c_p in puppi_iso_cands)
            tau.puppi_iso04_pt = sum(c_p.pt() for c_p in puppi_iso_cands_04)
            tau.puppi_iso03_pt = sum(c_p.pt() for c_p in puppi_iso_cands_03)
            # Add puppi isolation

        return True
Пример #30
0
    def makeMT(self, event):
        for lepton in event.inclusiveLeptons:
            event.mtw = mtw(lepton, event.met)
            event.mtw1 = 1 - (80 * 80) / (2 * event.met.pt() * lepton.pt())
            event.mtw2 = cos(deltaPhi(event.met.phi(), lepton.phi()))
            lepton.cosLMet = cos(lepton.phi() - event.met.phi())
            lepton.mt = mtw(lepton, event.met)
            lepton.Q80 = 1 - 80**2 / (2 * lepton.pt() * event.met.pt())

        for tau in event.selectedTaus:
            tau.cosLMet = cos(tau.phi() - event.met.phi())
            tau.mt = mtw(tau, event.met)
            tau.Q80 = 1 - 80**2 / (2 * tau.pt() * event.met.pt())

        for track in event.selectedIsoTrack:
            track.cosLMet = cos(track.phi() - event.met.phi())
            track.mt = mtw(track, event.met)
            track.Q80 = 1 - 80**2 / (2 * track.pt() * event.met.pt())

        return
    def makeBiasedDPhi(self, event):

        jets = getattr(event,self.jetForBiasedDPhi)
        if len(jets) == 0:
            event.biasedDPhi = 0
            return 
        mht = getattr(event,self.mhtForBiasedDPhi)

	biasedDPhi = 10;
        for jet in jets:
	    newPhi = atan2(mht.py()+jet.py(), mht.px()+jet.px())
	    biasedDPhiTemp = abs(deltaPhi(newPhi,jet.phi()))
	    if biasedDPhiTemp < biasedDPhi:
		biasedDPhi = biasedDPhiTemp
		biasedDPhiJet = jet
            pass

        event.biasedDPhi = biasedDPhi
        event.biasedDPhiJet = biasedDPhiJet

        return
Пример #32
0
    def makeBiasedDPhi(self, event):

        jets = getattr(event,self.jetForBiasedDPhi)
        if len(jets) == 0:
            event.biasedDPhi = 0
            return 
        mht = getattr(event,self.mhtForBiasedDPhi)

	biasedDPhi = 10;
        for jet in jets:
	    newPhi = atan2(mht.py()+jet.py(), mht.px()+jet.px())
	    biasedDPhiTemp = abs(deltaPhi(newPhi,jet.phi()))
	    if biasedDPhiTemp < biasedDPhi:
		biasedDPhi = biasedDPhiTemp
		biasedDPhiJet = jet
            pass

        event.biasedDPhi = biasedDPhi
        event.biasedDPhiJet = biasedDPhiJet

        return
Пример #33
0
    def makeBiasedDPhi(self, event):

        if len(event.cleanJets) == 0:
            event.biasedDPhi = 0
            return 
	mhtPx = event.mhtJet50jvec.px()
	mhtPy = event.mhtJet50jvec.py()

	biasedDPhi = 10;
        for jet in event.cleanJets:
	    newPhi = atan2(mhtPy+jet.py(),mhtPx+jet.px())
	    biasedDPhiTemp = abs(deltaPhi(newPhi,jet.phi()))
	    if biasedDPhiTemp < biasedDPhi:
		biasedDPhi = biasedDPhiTemp
		biasedDPhiJet = jet
            pass

        event.biasedDPhi = biasedDPhi
        event.biasedDPhiJet = biasedDPhiJet

        return
Пример #34
0
 def syncWCR(self, event):
     self.WCR.Fill(0)
     if len(event.selectedMuons) == 1 and event.selectedMuons[0].pt() > 20 and event.selectedMuons[0].muonID('POG_ID_Tight') and event.selectedMuons[0].relIso04 < 0.12:
         self.WCR.Fill(1)
         if len(event.xcleanJets) > 0 and event.xcleanJets[0].pt()>110. and event.xcleanJets[0].chargedHadronEnergyFraction()>0.2 and event.xcleanJets[0].neutralHadronEnergyFraction()<0.7 and event.xcleanJets[0].neutralEmEnergyFraction()<0.7:
             self.WCR.Fill(2)
             if len(event.xcleanJets) == 1 or ( abs(deltaPhi(event.xcleanJets[0].phi(), event.xcleanJets[1].phi())) < 2.5 and event.xcleanJets[1].neutralHadronEnergyFraction()<0.7 and event.xcleanJets[1].neutralEmEnergyFraction()<0.9 ):
                 self.WCR.Fill(3)
                 if len(event.xcleanJets) < 3:
                     self.WCR.Fill(4)
                     if len(event.selectedElectrons) == 0:
                         self.WCR.Fill(5)
                         if len(event.xcleanTaus) == 0:
                             self.WCR.Fill(6)
                             if len(event.selectedPhotons) == 0:
                                 self.WCR.Fill(7)
                                 if event.theW.mT > 50:
                                     self.WCR.Fill(8)
                                     if event.fakemet.pt() > 200:
                                         self.WCR.Fill(9)
                                         if self.cfg_ana.verbose: print "WCR %d:%d:%d" % ( event.input.eventAuxiliary().id().run(), event.input.eventAuxiliary().id().luminosityBlock(), event.input.eventAuxiliary().id().event() )
Пример #35
0
def pt_weighted_dx(tau, mode=0, var=0, decaymode=-1):
    sum_pt = 0.
    sum_dx_pt = 0.
    signalrad = max(0.05, min(0.1, 3. / max(1., tau.pt())))
    cands = getGammas(tau, mode < 2)
    for cand in cands:
        if cand.pt() < 0.5:
            continue
        dr = deltaR(cand, tau)
        deta = abs(cand.eta() - tau.eta())
        dphi = abs(deltaPhi(cand.phi(), tau.phi()))
        pt = cand.pt()
        flag = isInside(pt, deta, dphi)
        if decaymode != 10:
            if mode == 2 or (mode == 0
                             and dr < signalrad) or (mode == 1
                                                     and dr > signalrad):
                sum_pt += pt
                if var == 0:
                    sum_dx_pt += pt * dr
                elif var == 1:
                    sum_dx_pt += pt * deta
                elif var == 2:
                    sum_dx_pt += pt * dphi
        else:
            if (mode == 2
                    and flag == False) or (mode == 1
                                           and flag == True) or mode == 0:
                sum_pt += pt
                if var == 0:
                    sum_dx_pt += pt * dr
                elif var == 1:
                    sum_dx_pt += pt * deta
                elif var == 2:
                    sum_dx_pt += pt * dphi
    if sum_pt > 0.:
        return sum_dx_pt / sum_pt
    return 0.
Пример #36
0
    def process(self, event):
        event.genDPhiZZ = -999
        event.genDPhiZZWeight = 1
        event.genDPhiZZSameFlavour = -1

        if not self.cfg_comp.isMC: return True
        self.readCollections(event.input)

        zs = [
            gp for gp in self.mchandles['genParticles'].product() if
            abs(gp.pdgId()) == 23 and 20 <= gp.status() and gp.status() <= 30
        ]
        if len(zs) == 2:
            event.genDPhiZZ = abs(deltaPhi(zs[0].phi(), zs[1].phi()))
            dau = zs[:]
            for i in 0, 1:
                while abs(dau[i].pdgId()) == 23:
                    found = False
                    for idau in xrange(dau[i].numberOfDaughters()):
                        ddau = dau[i].daughter(idau)
                        if abs(ddau.pdgId()) in (11, 13, 15):
                            dau[i] = ddau
                            found = True
                            break
                    if not found:
                        for idau in xrange(dau[i].numberOfDaughters()):
                            ddau = dau[i].daughter(idau)
                            if abs(ddau.pdgId()) == 23:
                                dau[i] = ddau
                                found = True
                                break
                    if not found: break
            if abs(dau[0].pdgId()) in (11, 13, 15) and abs(
                    dau[1].pdgId()) in (11, 13, 15):
                event.genDPhiZZSameFlavour = (1 if abs(dau[0].pdgId()) == abs(
                    dau[1].pdgId()) else 0)
        return True
Пример #37
0
    NTupleVariable("neHEF", lambda x : x.neutralHadronEnergyFraction(), float, mcOnly = False,help="neutralHadronEnergyFraction (relative to uncorrected jet energy)"),
    NTupleVariable("chEmEF", lambda x : x.chargedEmEnergyFraction(), float, mcOnly = False,help="chargedEmEnergyFraction (relative to uncorrected jet energy)"),
    NTupleVariable("neEmEF", lambda x : x.neutralEmEnergyFraction(), float, mcOnly = False,help="neutralEmEnergyFraction (relative to uncorrected jet energy)"),
    NTupleVariable("muEF", lambda x : x.muonEnergyFraction(), float, mcOnly = False,help="muonEnergyFraction (relative to uncorrected jet energy)"),
    NTupleVariable("chMult", lambda x : x.chargedMultiplicity(), int, mcOnly = False,help="chargedMultiplicity from PFJet.h"),
    NTupleVariable("neMult", lambda x : x.neutralMultiplicity(), int, mcOnly = False,help="neutralMultiplicity from PFJet.h"),
    NTupleVariable("leadTrackPt", lambda x : x.leadTrackPt() , float, mcOnly = False, help="pt of the leading track in the jet"), 
    NTupleVariable("mcEta",   lambda x : x.mcJet.eta() if getattr(x,"mcJet",None) else 0., mcOnly=True, help="eta of associated gen jet"),
    NTupleVariable("mcPhi",   lambda x : x.mcJet.phi() if getattr(x,"mcJet",None) else 0., mcOnly=True, help="phi of associated gen jet"),
    NTupleVariable("mcM",   lambda x : x.mcJet.p4().M() if getattr(x,"mcJet",None) else 0., mcOnly=True, help="mass of associated gen jet"),
    NTupleVariable("leptonPdgId",   lambda x : x.leptons[0].pdgId() if len(x.leptons) > 0 else -99, mcOnly=False, help="pdg id of the first associated lepton"),
    NTupleVariable("leptonPt",   lambda x : x.leptons[0].pt() if len(x.leptons) > 0 else -99, mcOnly=False, help="pt of the first associated lepton"),
    NTupleVariable("leptonPtRel",   lambda x : ptRel(x.leptons[0].p4(),x.p4()) if len(x.leptons) > 0 else -99, mcOnly=False, help="ptrel of the first associated lepton"),
    NTupleVariable("leptonPtRelInv",   lambda x : ptRel(x.p4(),x.leptons[0].p4()) if len(x.leptons) > 0 else -99, mcOnly=False, help="ptrel Run1 definition of the first associated lepton"),
    NTupleVariable("leptonDeltaR",   lambda x : deltaR(x.leptons[0].p4().eta(),x.leptons[0].p4().phi(),x.p4().eta(),x.p4().phi()) if len(x.leptons) > 0 else -99, mcOnly=False, help="deltaR of the first associated lepton"),
    NTupleVariable("leptonDeltaPhi",   lambda x : deltaPhi(x.leptons[0].p4().phi(),x.p4().phi()) if len(x.leptons) > 0 else 0, mcOnly=False, help="deltaPhi of the first associated lepton"),
    NTupleVariable("leptonDeltaEta",   lambda x : x.leptons[0].p4().eta()-x.p4().eta() if len(x.leptons) > 0 else 0, mcOnly=False, help="deltaEta of the first associated lepton"),
    NTupleVariable("vtxMass",   lambda x : x.userFloat("vtxMass"), mcOnly=False, help="vtxMass from btag"),
    NTupleVariable("vtxNtracks",   lambda x : x.userFloat("vtxNtracks"), mcOnly=False, help="number of tracks at vertex from btag"),
    NTupleVariable("vtxPt",   lambda x : sqrt(x.userFloat("vtxPx")**2 + x.userFloat("vtxPy")**2), mcOnly=False, help="pt of vertex from btag"),
    NTupleVariable("vtx3DSig",   lambda x : x.userFloat("vtx3DSig"), mcOnly=False, help="decay len significance of vertex from btag"),
    NTupleVariable("vtx3DVal",   lambda x : x.userFloat("vtx3DVal"), mcOnly=False, help="decay len of vertex from btag"),
    NTupleVariable("vtxPosX",   lambda x : x.userFloat("vtxPosX"), mcOnly=False, help="X coord of vertex from btag"),
    NTupleVariable("vtxPosY",   lambda x : x.userFloat("vtxPosY"), mcOnly=False, help="Y coord of vertex from btag"), 
    NTupleVariable("vtxPosZ",   lambda x : x.userFloat("vtxPosZ"), mcOnly=False, help="Z coord of vertex from btag"),
    NTupleVariable("pullVectorPhi", lambda x : getattr(x,"pullVectorPhi",-99), mcOnly=False, help="pull angle phi in the phi eta plane"),
    NTupleVariable("pullVectorMag", lambda x : getattr(x,"pullVectorMag",-99), mcOnly=False, help="pull angle magnitude"),
   # QG variables:
# this computes for all
#    NTupleVariable("qgl",   lambda x :x.qgl() , float, mcOnly=False,help="QG Likelihood"),
#    NTupleVariable("ptd",   lambda x : getattr(x.computeQGvars(),'ptd', 0), float, mcOnly=False,help="QG input variable: ptD"),
Пример #38
0
    def analyze(self, event):
        """process event, return True (go to next module) or False (fail, go to next event)"""

        if event._tree._ttreereaderversion > self._ttreereaderversion:
            self.initReaders(event._tree)

        #MC truth
        gen_visibleV, gen_V, gen_h, gen_ht = self.getMCTruth(event)

        #selected leptons at reco level
        visibleV = self.getVisibleV(event)
        if not visibleV: return False

        #leading PF candidates
        self.out.fillBranch('leadch_pt', event.leadCharged_pt)
        self.out.fillBranch('leadch_phi', event.leadCharged_phi)
        self.out.fillBranch('leadneut_pt', event.leadNeutral_pt)
        self.out.fillBranch('leadneut_phi', event.leadNeutral_phi)

        #met estimators
        metEstimators = {
            'met':
            self.summarizeMetEstimator(event, ['met'], [1]),
            'puppimet':
            self.summarizeMetEstimator(event, ['puppimet'], [1]),
            'ntmet':
            self.summarizeMetEstimator(event, ['ntMet'], [1]),
            'ntcentralmet':
            self.summarizeMetEstimator(event, ['ntCentralMet'], [1]),
            'tkmet':
            self.summarizeMetEstimator(event, ['tkMetPVLoose'], [1]),
            'chsmet':
            self.summarizeMetEstimator(event, ['tkMetPVchs'], [1]),
            'npvmet':
            self.summarizeMetEstimator(event, ['tkMetPUPVLoose'], [1]),
            'ntnpv':
            self.summarizeMetEstimator(event, ['ntMet', 'tkMetPUPVLoose'],
                                       [1, 1]),
            'centralntnpv':
            self.summarizeMetEstimator(event,
                                       ['ntCentralMet', 'tkMetPUPVLoose'],
                                       [1, 1]),
            'centralmetdbeta':
            self.summarizeMetEstimator(
                event, ['tkMetPVLoose', 'ntCentralMet', 'tkMetPUPVLoose'],
                [1, 1, 0.5]),
        }

        #recoil estimators
        for metType in metEstimators.keys() + ["truth", "gen"]:

            #some may need to be specified
            if metType == "truth":
                vis = gen_visibleV.VectorT()
                metP4 = gen_V
                h = ROOT.TVector3(-gen_V.Px(), -gen_V.Py(), 0)
                ht = gen_V.Pt()
                m = gen_V.M()
                count = 0
            elif metType == 'gen':
                vis = gen_visibleV.VectorT()
                metP4 = ROOT.TLorentzVector(0, 0, 0, 0)
                metP4.SetPtEtaPhiM(event.tkGenMet_pt, 0, event.tkGenMet_phi,
                                   0.)
                h = gen_h
                ht = gen_ht
                m = 0
                count = 0
            else:
                vis = visibleV.VectorT()
                metP4, sumEt, count = metEstimators[metType]
                h, ht, m = self.getRecoRecoil(event=event,
                                              metP4=metP4,
                                              sumEt=sumEt,
                                              visibleV=visibleV)

            #save information to tree
            pt = h.Pt()
            phi = h.Phi()
            metphi = metP4.Phi()
            sphericity = pt / ht if ht > 0 else -1
            e1 = gen_V.Pt() / h.Pt() if h.Pt() > 0 else -1
            e2 = deltaPhi(gen_V.Phi() + np.pi, h.Phi())
            mt2 = 2 * vis.Pt() * ((vis + h).Pt()) + vis.Pt()**2 + vis.Dot(h)
            mt = np.sqrt(mt2) if mt2 >= 0. else -np.sqrt(-mt2)

            self.out.fillBranch('%s_recoil_pt' % metType, pt)
            self.out.fillBranch('%s_recoil_phi' % metType, phi)
            self.out.fillBranch('%s_m' % metType, m)
            self.out.fillBranch('%s_recoil_sphericity' % metType, sphericity)
            self.out.fillBranch('%s_n' % metType, count)
            self.out.fillBranch('%s_recoil_e1' % metType, e1)
            self.out.fillBranch('%s_recoil_e2' % metType, e2)
            self.out.fillBranch('%s_mt' % metType, mt)
            self.out.fillBranch(
                '%s_dphi2met' % metType,
                deltaPhi(metEstimators['met'][0].Phi(), metphi))
            self.out.fillBranch(
                '%s_dphi2puppimet' % metType,
                deltaPhi(metEstimators['puppimet'][0].Phi(), metphi))
            self.out.fillBranch(
                '%s_dphi2ntnpv' % metType,
                deltaPhi(metEstimators['ntnpv'][0].Phi(), metphi))
            self.out.fillBranch(
                '%s_dphi2centralntnpv' % metType,
                deltaPhi(metEstimators['centralntnpv'][0].Phi(), metphi))
            self.out.fillBranch(
                '%s_dphi2centralmetdbeta' % metType,
                deltaPhi(metEstimators['centralmetdbeta'][0].Phi(), metphi))
            self.out.fillBranch('%s_dphi2leadch' % metType,
                                deltaPhi(event.leadCharged_phi, metphi))
            self.out.fillBranch('%s_dphi2leadneut' % metType,
                                deltaPhi(event.leadNeutral_phi, metphi))

        return True
Пример #39
0
    def computeQGvars(self, jet):

       jet.mult = 0
       sum_weight = 0.
       sum_pt = 0.
       sum_deta = 0.
       sum_dphi = 0.
       sum_deta2 = 0.
       sum_detadphi = 0.
       sum_dphi2 = 0.



       for ii in range(0, jet.numberOfDaughters()) :

         part = jet.daughter(ii)

         if part.charge() == 0 : # neutral particles 

           if part.pt() < 1.: continue

         else : # charged particles

           if part.trackHighPurity()==False: continue
           if part.fromPV()<=1: continue


         jet.mult += 1

         deta = part.eta() - jet.eta()
         dphi = deltaPhi(part.phi(), jet.phi())
         partPt = part.pt()
         weight = partPt*partPt
         sum_weight += weight
         sum_pt += partPt
         sum_deta += deta*weight
         sum_dphi += dphi*weight
         sum_deta2 += deta*deta*weight
         sum_detadphi += deta*dphi*weight
         sum_dphi2 += dphi*dphi*weight




       a = 0.
       b = 0.
       c = 0.

       if sum_weight > 0 :
         jet.ptd = math.sqrt(sum_weight)/sum_pt
         ave_deta = sum_deta/sum_weight
         ave_dphi = sum_dphi/sum_weight
         ave_deta2 = sum_deta2/sum_weight
         ave_dphi2 = sum_dphi2/sum_weight
         a = ave_deta2 - ave_deta*ave_deta
         b = ave_dphi2 - ave_dphi*ave_dphi
         c = -(sum_detadphi/sum_weight - ave_deta*ave_dphi)
       else: jet.ptd = 0.

       delta = math.sqrt(math.fabs((a-b)*(a-b)+4.*c*c))

       if a+b-delta > 0: jet.axis2 = -math.log(math.sqrt(0.5*(a+b-delta)))
       else: jet.axis2 = -1.
  def evaluateBlikelihood(self, event) :
    nJet=len(event.cleanJetsAll)
    for index,j in enumerate(event.cleanJetsAll,start=0) :
      j.blike_VBF=-2
    if (nJet>=4):
      if ((event.cleanJetsAll[0].pt()>92.) and (event.cleanJetsAll[1].pt()>76.) and (event.cleanJetsAll[2].pt()>64) and (event.cleanJetsAll[3].pt()>30)):
    #    jetsForHiggs4=[jet for index,jet in enumerate(event.cleanJetsAll)  if (jet.jetID("POG_PFID_Loose")) and (index<4)] #uncomment if jet_id is working properly
        jetsForHiggs4=[jet for index,jet in enumerate(event.cleanJetsAll)  if (index<4)]
    #    jetsForHiggs4btag=[jet.btag("pfCombinedInclusiveSecondaryVertexV2BJetTags") for index,jet in enumerate(event.cleanJetsAll) if (jet.jetID("POG_PFID_Loose")) and (index<4) ]
        jetsForHiggs4btag=[jet.btag("pfCombinedInclusiveSecondaryVertexV2BJetTags") for index,jet in enumerate(event.cleanJetsAll) if (index<4) ]
        btag_max1=max(jetsForHiggs4btag)
        btag_max1_idx=jetsForHiggs4btag.index(btag_max1)

        if btag_max1>0.0:
          bjet1=jetsForHiggs4[btag_max1_idx]
          other3jets=[jet for index,jet in enumerate(jetsForHiggs4) if index!= btag_max1_idx]
          if len(other3jets)==3 :
            maxEta1, maxEta2 = None, None
            maxDeltaEta = -1

            for i in range(len(other3jets)):
              for j in range(i + 1, len(other3jets)):
                d = abs(other3jets[i].eta() - other3jets[j].eta())
                if d > maxDeltaEta:
                  maxEta1, maxEta2, maxDeltaEta = i, j, d
            if (maxEta1>=0) and (maxEta2>=0) :
              qjets=[]
              qjets.append(other3jets[maxEta1])
              qjets.append(other3jets[maxEta2])
              leftBjets=[jet for index,jet in enumerate(other3jets) if (index!=maxEta1) and (index!=maxEta2)]
              bjet2=leftBjets[0]

              Mqq=(qjets[0].p4()+qjets[1].p4()).M()
              bbDeltaPhi=abs(deltaPhi(bjet1.phi(),bjet2.phi()))
              qqDeltaEta=abs(qjets[0].eta()-qjets[1].eta())
           
              if (Mqq>460) :
                if (qqDeltaEta>4.1) : 
                  if (bbDeltaPhi<1.6) :
                    if (event.HLT_BIT_HLT_QuadPFJet_SingleBTagCSV_VBF_Mqq460_v) : 
                      loopMaxJet=7
                      if nJet<7 : loopMaxJet=nJet  
                   #   jetsForHiggsMax=[jet for index,jet in enumerate(event.cleanJetsAll) if (jet.jetID("POG_PFID_Loose")) and (index<loopMaxJet) and (jet.pt()>20)]
                      jetsForHiggsMax=[jet for index,jet in enumerate(event.cleanJetsAll) if (index<loopMaxJet) and (jet.pt()>20)]
                      jetsForHiggsMaxEta=[abs(jet.eta()) for jet in jetsForHiggsMax]
                      jetsForHiggsMaxEtaSorted=sorted(range(len(jetsForHiggsMaxEta)),key=lambda x:jetsForHiggsMaxEta[x])
                      jetsEtaIdx=sorted(range(len(jetsForHiggsMaxEta)),key=lambda x:jetsForHiggsMaxEtaSorted[x])
                      jetsForHiggsMaxBtag=[jet.btag("pfCombinedInclusiveSecondaryVertexV2BJetTags") for jet in jetsForHiggsMax]
                      for jet_btag in jetsForHiggsMaxBtag :
                        if jet_btag > 1 : jet_btag = 1
                        if jet_btag < 0 : jet_btag = 0
                      jetsForHiggsMaxBtagSorted=sorted(range(len(jetsForHiggsMaxBtag)),key=lambda x:jetsForHiggsMaxBtag[x], reverse=True)
                      jetsBtagIdx=sorted(range(len(jetsForHiggsMaxBtag)),key=lambda x:jetsForHiggsMaxBtagSorted[x])
                    
                      for i  in range(len(jetsForHiggsMax)) :
                        j=jetsForHiggsMax[i]
                        self.Jet_pt[0]=j.pt()
                        self.Jet_eta[0]=jetsForHiggsMaxEta[i]
                        self.Jet_btagCSV[0]=jetsForHiggsMaxBtag[i]
                        self.Jet_pt_idx[0]=i
                        self.Jet_eta_idx[0]=jetsEtaIdx[i]
                        self.Jet_btagCSV_idx[0]=jetsBtagIdx[i]
                        j.blike_VBF=self.reader.EvaluateMVA(self.name)
Пример #41
0
    def process(self, event):
        self.readCollections( event.input )
        self.counters.counter('events').inc('all events')

        event.bjetsLoose  = [ j for j in event.cleanJets if j.btagWP("CSVv2IVFL") ]
        event.bjetsMedium = [ j for j in event.cleanJets if j.btagWP("CSVv2IVFM") ]

        import ROOT

        ## with Central Jets
        objects25 = [ j for j in event.cleanJets if j.pt() > 25 ] + event.selectedLeptons
        objects30 = [ j for j in event.cleanJets if j.pt() > 30 ] + event.selectedLeptons
        objects40 = [ j for j in event.cleanJets if j.pt() > 40 ] + event.selectedLeptons
        objectsX  = [ j for j in event.cleanJets if j.pt() > self.jetPt ] + event.selectedLeptons
        objects25j = [ j for j in event.cleanJets if j.pt() > 25 ] 
        objects40j = [ j for j in event.cleanJets if j.pt() > 40 ] 
        objects50j = [ j for j in event.cleanJets if j.pt() > 50 ] 
        objectsXj = [ j for j in event.cleanJets if j.pt() > self.jetPt ]
        objects40j10l = [ j for j in event.cleanJets if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] 
        objects40j10l.sort(key = lambda obj : obj.pt(), reverse = True)
        objectsXj10l = [ j for j in event.cleanJets if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] 
        objectsXj10l.sort(key = lambda obj : obj.pt(), reverse = True)

        objects40j10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objects40j10l5t = [ j for j in event.cleanJets if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objects40j10l5t.sort(key = lambda obj : obj.pt(), reverse = True)

        objectsXj10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objectsXj10l5t = [ j for j in event.cleanJets if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objectsXj10l5t.sort(key = lambda obj : obj.pt(), reverse = True)
            
        event.htJet25 = sum([x.pt() for x in objects25])
        event.mhtJet25vec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects25])) , -1.*(sum([x.py() for x in objects25])), 0, 0 )     
        event.mhtPhiJet25 = event.mhtJet25vec.phi()
        event.mhtJet25 = event.mhtJet25vec.pt()

        event.htJet30 = sum([x.pt() for x in objects30])
        event.mhtJet30vec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects30])) , -1.*(sum([x.py() for x in objects30])), 0, 0 )             
        event.mhtJet30 = event.mhtJet30vec.pt()
        event.mhtPhiJet30 = event.mhtJet30vec.phi()

        event.htJet40 = sum([x.pt() for x in objects40])
        event.mhtJet40vec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40])) , -1.*(sum([x.py() for x in objects40])), 0, 0 )             
        event.mhtJet40 = event.mhtJet40vec.pt()
        event.mhtPhiJet40 = event.mhtJet40vec.phi()

        event.htJetX = sum([x.pt() for x in objectsX])
        event.mhtJetXvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsX])) , -1.*(sum([x.py() for x in objectsX])), 0, 0 )             
        event.mhtJetX = event.mhtJetXvec.pt()
        event.mhtPhiJetX = event.mhtJetXvec.phi()

        event.htJet25j = sum([x.pt() for x in objects25j])
        event.htJet40j = sum([x.pt() for x in objects40j])
        event.mhtJet40jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40j])) , -1.*(sum([x.py() for x in objects40j])), 0, 0 )               
        event.mhtJet40j = event.mhtJet40jvec.pt()
        event.mhtPhiJet40j = event.mhtJet40jvec.phi()        

        event.htJet50j = sum([x.pt() for x in objects50j])
        event.mhtJet50jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects50j])) , -1.*(sum([x.py() for x in objects50j])), 0, 0 )               
        event.mhtJet50j = event.mhtJet50jvec.pt()
        event.mhtPhiJet50j = event.mhtJet50jvec.phi()        
        
        event.htJetXj = sum([x.pt() for x in objectsXj])
        event.mhtJetXjvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXj])) , -1.*(sum([x.py() for x in objectsXj])), 0, 0 )
        event.mhtJetXj = event.mhtJetXjvec.pt()
        event.mhtPhiJetXj = event.mhtJetXjvec.phi()


        #Make 40 and 50 GeV HTs from cleanGenJets
        if self.cfg_comp.isMC:
            
            genObjects40j = [j for j in event.cleanGenJets if j.pt()>40]
            genObjects50j = [j for j in event.cleanGenJets if j.pt()>50]
            genObjectsXj = [j for j in event.cleanGenJets if j.pt()>self.jetPt]

            event.htGenJet40j = sum([x.pt() for x in genObjects40j])
            event.mhtGenJet40jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in genObjects40j])) , -1.*(sum([x.py() for x in genObjects40j])), 0, 0 )               
            event.mhtGenJet40j = event.mhtGenJet40jvec.pt()
            event.mhtPhiGenJet40j = event.mhtGenJet40jvec.phi()        

            event.htGenJet50j = sum([x.pt() for x in genObjects50j])
            event.mhtGenJet50jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in genObjects50j])) , -1.*(sum([x.py() for x in genObjects50j])), 0, 0 )               
            event.mhtGenJet50j = event.mhtGenJet50jvec.pt()
            event.mhtPhiGenJet50j = event.mhtGenJet50jvec.phi()        

            event.htGenJetXj = sum([x.pt() for x in genObjectsXj])
            event.mhtGenJetXjvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in genObjectsXj])) , -1.*(sum([x.py() for x in genObjectsXj])), 0, 0 )               
            event.mhtGenJetXj = event.mhtGenJetXjvec.pt()
            event.mhtPhiGenJetXj = event.mhtGenJetXjvec.phi()        

        event.htJet40j10l = sum([x.pt() for x in objects40j10l])
        event.mhtJet40j10lvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40j10l])) , -1.*(sum([x.py() for x in objects40j10l])), 0, 0 )               
        event.mhtJet40j10l = event.mhtJet40j10lvec.pt()
        event.mhtPhiJet40j10l = event.mhtJet40j10lvec.phi()        

        event.htJetXj10l = sum([x.pt() for x in objectsXj10l])
        event.mhtJetXj10lvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXj10l])) , -1.*(sum([x.py() for x in objectsXj10l])), 0, 0 )               
        event.mhtJetXj10l = event.mhtJetXj10lvec.pt()
        event.mhtPhiJetXj10l = event.mhtJetXj10lvec.phi()        

        event.htJet40j10l5t = sum([x.pt() for x in objects40j10l5t])
        event.mhtJet40j10l5tvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40j10l5t])) , -1.*(sum([x.py() for x in objects40j10l5t])), 0, 0 )               
        event.mhtJet40j10l5t = event.mhtJet40j10l5tvec.pt()
        event.mhtPhiJet40j10l5t = event.mhtJet40j10l5tvec.phi()        
        
        event.htJetXj10l5t = sum([x.pt() for x in objectsXj10l5t])
        event.mhtJetXj10l5tvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXj10l5t])) , -1.*(sum([x.py() for x in objectsXj10l5t])), 0, 0 )
        event.mhtJetXj10l5t = event.mhtJetXj10l5tvec.pt()
        event.mhtPhiJetXj10l5t = event.mhtJetXj10l5tvec.phi()

        ## same but with all eta range
        objects25a  = [ j for j in event.cleanJetsAll if j.pt() > 25 ] + event.selectedLeptons
        objects30a  = [ j for j in event.cleanJetsAll if j.pt() > 30 ] + event.selectedLeptons
        objects40a  = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + event.selectedLeptons
        objectsXa  = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ] + event.selectedLeptons
        objects40ja = [ j for j in event.cleanJetsAll if j.pt() > 40 ] 
        objectsXja = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ]

        objects40ja10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objects40ja10l5t = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objects40ja10l5t.sort(key = lambda obj : obj.pt(), reverse = True)

        objects40ja10l = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ]
        objects40ja10l.sort(key = lambda obj : obj.pt(), reverse = True)

        objectsXja10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objectsXja10l5t = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objectsXja10l5t.sort(key = lambda obj : obj.pt(), reverse = True)

        objects40ja10l = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ]
        objects40ja10l.sort(key = lambda obj : obj.pt(), reverse = True)

        objectsXja10l = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ]
        objectsXja10l.sort(key = lambda obj : obj.pt(), reverse = True)

        event.htJet25a = sum([x.pt() for x in objects25a])
        event.mhtJet25veca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects25a])) , -1.*(sum([x.py() for x in objects25a])), 0, 0 )     
        event.mhtPhiJet25a = event.mhtJet25veca.phi()
        event.mhtJet25a = event.mhtJet25veca.pt()

        event.htJet30a = sum([x.pt() for x in objects30a])
        event.mhtJet30veca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects30a])) , -1.*(sum([x.py() for x in objects30a])), 0, 0 )             
        event.mhtJet30a = event.mhtJet30veca.pt()
        event.mhtPhiJet30a = event.mhtJet30veca.phi()

        event.htJet40a = sum([x.pt() for x in objects40a])
        event.mhtJet40veca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40a])) , -1.*(sum([x.py() for x in objects40a])), 0, 0 )             
        event.mhtJet40a = event.mhtJet40veca.pt()
        event.mhtPhiJet40a = event.mhtJet40veca.phi()

        event.htJetXa = sum([x.pt() for x in objectsXa])
        event.mhtJetXveca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXa])) , -1.*(sum([x.py() for x in objectsXa])), 0, 0 )             
        event.mhtJetXa = event.mhtJetXveca.pt()
        event.mhtPhiJetXa = event.mhtJetXveca.phi()

        event.htJet40ja = sum([x.pt() for x in objects40ja])
        event.mhtJet40jveca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40ja])) , -1.*(sum([x.py() for x in objects40ja])), 0, 0 )                     
        event.mhtJet40ja = event.mhtJet40jveca.pt()
        event.mhtPhiJet40ja = event.mhtJet40jveca.phi()

        event.htJetXja = sum([x.pt() for x in objectsXja])
        event.mhtJetXjveca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXja])) , -1.*(sum([x.py() for x in objectsXja])), 0, 0 )
        event.mhtJetXja = event.mhtJetXjveca.pt()
        event.mhtPhiJetXja = event.mhtJetXjveca.phi()

        #For the vertex related variables 
        #A = selectedLeptons[0], B = selectedLeptons[1], C = selectedLeptons[2], D = selectedLeptons[3] 
        nlep = len(event.selectedLeptons)
        
        ##Variables related to IP
        #Of one lepton w.r.t. the PV of the event
        event.absIP3DA = absIP3D(event.selectedLeptons[0],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 0 else (-1,-1)  
        event.absIP3DB = absIP3D(event.selectedLeptons[1],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 1 else (-1,-1)    
        event.absIP3DC = absIP3D(event.selectedLeptons[2],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 2 else (-1,-1)
        event.absIP3DD = absIP3D(event.selectedLeptons[3],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 3 else (-1,-1)

        #Of one lepton w.r.t. the PV of the PV of the other leptons only
        event.absIP3DApvBC = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3,0) if nlep > 2 else (-1,-1)
        event.absIP3DBpvAC = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3,1) if nlep > 2 else (-1,-1)
        event.absIP3DCpvAB = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3,2) if nlep > 2 else (-1,-1)
 
        event.absIP3DApvBCD = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,0) if nlep > 3 else (-1,-1)
        event.absIP3DBpvACD = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,1) if nlep > 3 else (-1,-1)
        event.absIP3DCpvABD = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,2) if nlep > 3 else (-1,-1)
        event.absIP3DDpvABC = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,3) if nlep > 3 else (-1,-1)
        
        ##Variables related to chi2
        #Chi2 of all the good leptons of the event but one lepton
        event.chi2pvtrksBCbutA = chi2pvtrks(event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[1],event.selectedLeptons[1],2) if nlep > 2 else (-1,-1)
        event.chi2pvtrksACbutB = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[2],event.selectedLeptons[0],event.selectedLeptons[0],2) if nlep > 2 else (-1,-1)
        event.chi2pvtrksABbutC = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[0],event.selectedLeptons[0],2) if nlep > 2 else (-1,-1)

        event.chi2pvtrksBCDbutA = chi2pvtrks(event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],event.selectedLeptons[1],3) if nlep > 3 else (-1,-1)
        event.chi2pvtrksACDbutB = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[2],event.selectedLeptons[3],event.selectedLeptons[0],3) if nlep > 3 else (-1,-1)
        event.chi2pvtrksABDbutC = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[3],event.selectedLeptons[0],3) if nlep > 3 else (-1,-1)
        event.chi2pvtrksABCbutD = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3) if nlep > 3 else (-1,-1)

        self.makeZs(event, self.maxLeps)
        self.makeMlls(event, self.maxLeps)
        self.makeLepPtRel(event)

        # look for minimal deltaPhi between MET and four leading jets with pt>40 and eta<2.4
        event.deltaPhiMin_had = 999.
        for n,j in enumerate(objects40ja):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin_had : event.deltaPhiMin_had = thisDeltaPhi

        event.deltaPhiMin = 999.
        for n,j in enumerate(objects40ja10l5t):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin : event.deltaPhiMin = thisDeltaPhi

        event.deltaPhiMin_Xj_had = 999.
        for n,j in enumerate(objectsXja):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin_Xj_had : event.deltaPhiMin_Xj_had = thisDeltaPhi

        event.deltaPhiMin_Xj = 999.
        for n,j in enumerate(objectsXja10l5t):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin_Xj : event.deltaPhiMin_Xj = thisDeltaPhi


        for lep in event.selectedLeptons:
            if hasattr(lep,'miniAbsIsoCharged'):
                lep.mvaValueTTH     = self.leptonMVATTH(lep)
                lep.mvaValueSUSY     = self.leptonMVASUSY(lep)
                if self.doLeptonMVASoft:
                    if not (hasattr(lep,'AbsIsoMIVCharged04') and hasattr(lep,'isoSumRawP4Charged04')):
                        raise RuntimeError, 'Soft lepton MVA needs AbsIsoMIVCharged04 and isoSumRawP4Charged04 calculated for leptons'
                    lep.mvaValueSoftT2tt     = self.leptonMVASoftT2tt(lep)
                    lep.mvaValueSoftEWK     = self.leptonMVASoftEWK(lep)
        for lep in event.inclusiveLeptons:
            if lep not in event.selectedLeptons:
                if hasattr(lep,'miniAbsIsoCharged'):
                    lep.mvaValueTTH     = self.leptonMVATTH(lep)
                    lep.mvaValueSUSY     = self.leptonMVASUSY(lep)
                    if self.doLeptonMVASoft:
                        if not (hasattr(lep,'AbsIsoMIVCharged04') and hasattr(lep,'isoSumRawP4Charged04')):
                            raise RuntimeError, 'Soft lepton MVA needs AbsIsoMIVCharged04 and isoSumRawP4Charged04 calculated for leptons'
                        lep.mvaValueSoftT2tt     = self.leptonMVASoftT2tt(lep)
                        lep.mvaValueSoftEWK     = self.leptonMVASoftEWK(lep)


        # absolute value of the vectorial difference between met and mht
        diffMetMht_had_vec = ROOT.reco.Particle.LorentzVector(event.mhtJet40jvec.px()-event.met.px(), event.mhtJet40jvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht_had = sqrt( diffMetMht_had_vec.px()*diffMetMht_had_vec.px() + diffMetMht_had_vec.py()*diffMetMht_had_vec.py() )

        diffMetMht_vec = ROOT.reco.Particle.LorentzVector(event.mhtJet40j10l5tvec.px()-event.met.px(), event.mhtJet40j10l5tvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht = sqrt( diffMetMht_vec.px()*diffMetMht_vec.px() + diffMetMht_vec.py()*diffMetMht_vec.py() )
        
        diffMetMht_Xj_had_vec = ROOT.reco.Particle.LorentzVector(event.mhtJetXjvec.px()-event.met.px(), event.mhtJetXjvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht_Xj_had = sqrt( diffMetMht_Xj_had_vec.px()*diffMetMht_Xj_had_vec.px() + diffMetMht_Xj_had_vec.py()*diffMetMht_Xj_had_vec.py() )

        diffMetMht_Xj_vec = ROOT.reco.Particle.LorentzVector(event.mhtJetXj10l5tvec.px()-event.met.px(), event.mhtJetXj10l5tvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht_Xj = sqrt( diffMetMht_Xj_vec.px()*diffMetMht_Xj_vec.px() + diffMetMht_Xj_vec.py()*diffMetMht_Xj_vec.py() )
        ###

        #Make Biased DPhi
        event.biasedDPhi = -999
        self.makeBiasedDPhi(event)

        return True
Пример #42
0
 def process(self, event):
     
     if not hasattr(event, "genParticles"):
         return False
     # Mediator
     event.genPhi = None
     event.genChi = []
     
     for g in event.genParticles:
         if g.pdgId() == 9100000 or g.pdgId() == 9900032 or g.pdgId() == 1023:
             event.genPhi = g
         if abs(g.pdgId()) == 9100022 or g.pdgId() == 9100012:
             event.genChi.append(g)
     if event.genPhi:
         self.GenPhi1mass.Fill(event.genPhi.mass())
         self.GenPhi1pt.Fill(event.genPhi.pt())
         self.GenPhi1eta.Fill(event.genPhi.eta())
     if len(event.genChi) == 2:
         i1, i2 = [0, 1] if event.genChi[0].pt() > event.genChi[1].pt() else [1, 0]
         self.GenChi1mass.Fill(event.genChi[i1].mass())
         self.GenChi1pt.Fill(event.genChi[i1].pt())
         self.GenChi1eta.Fill(event.genChi[i1].eta())
         self.GenChi2mass.Fill(event.genChi[i1].mass())
         self.GenChi2pt.Fill(event.genChi[i1].pt())
         self.GenChi2eta.Fill(event.genChi[i1].eta())
         self.GenChi12dR.Fill(deltaR(event.genChi[0].eta(), event.genChi[0].phi(), event.genChi[1].eta(), event.genChi[1].phi()))
     # Z
     if hasattr(event, "genVBosons"):
         if len(event.genVBosons) > 0:
             self.GenZmass.Fill(event.genVBosons[0].mass())
             self.GenZpt.Fill(event.genVBosons[0].pt())
             self.GenZeta.Fill(event.genVBosons[0].eta())
     # Higgs
     if hasattr(event, "genHiggsBosons"):
         if len(event.genHiggsBosons) > 0:
             self.GenHmass.Fill(event.genHiggsBosons[0].mass())
             self.GenHpt.Fill(event.genHiggsBosons[0].pt())
             self.GenHeta.Fill(event.genHiggsBosons[0].eta())
     # Leptons from Z
     if hasattr(event, "genleps"):
         if len(event.genleps) >= 2:
             self.GenZdecay.Fill(abs(event.genleps[0].pdgId()))
             self.GenZdR.Fill(deltaR(event.genleps[0].eta(), event.genleps[0].phi(), event.genleps[1].eta(), event.genleps[1].phi()))
             i1, i2 = [0, 1] if event.genleps[0].pt() > event.genleps[1].pt() else [1, 0]
             self.GenLepton1pt.Fill(event.genleps[i1].pt())
             self.GenLepton1eta.Fill(event.genleps[i1].eta())
             self.GenLepton2pt.Fill(event.genleps[i2].pt())
             self.GenLepton2eta.Fill(event.genleps[i2].eta())
     # b-quarks from Higgs
     if hasattr(event, "genbquarks"):
         if len(event.genbquarks) == 1:
             self.GenBquark1pt.Fill(event.genbquarks[0].pt())
             self.GenBquark1eta.Fill(event.genbquarks[0].eta())
         elif len(event.genbquarks) >= 2:
             self.GenHdecay.Fill(abs(event.genbquarks[0].pdgId()))
             self.GenHdR.Fill(deltaR(event.genbquarks[0].eta(), event.genbquarks[0].phi(), event.genbquarks[1].eta(), event.genbquarks[1].phi()))
             self.GenHdPhi.Fill(deltaPhi(event.genbquarks[0].phi(), event.genbquarks[1].phi()))
             i1, i2 = [0, 1] if event.genbquarks[0].pt() > event.genbquarks[1].pt() else [1, 0]
             self.GenBquark1pt.Fill(event.genbquarks[i1].pt())
             self.GenBquark1eta.Fill(event.genbquarks[i1].eta())
             self.GenBquark2pt.Fill(event.genbquarks[i2].pt())
             self.GenBquark2eta.Fill(event.genbquarks[i2].eta())
         
     return True
Пример #43
0
    def process(self, event):
        event.isZZh = False
        
        self.ZZhCounter.Fill(0) # All
        self.ZZhCounter.Fill(1) # Trigger
        # Leptons >= 2
        if not len(event.inclusiveLeptons)>=2:
            return True
        self.ZZhCounter.Fill(2) # Lep > 2
        # Select first lepton
        if not hasattr(event, "Z"):
            return True
        self.ZZhCounter.Fill(3) # Z cand
        if event.Z.pt() < self.cfg_ana.Z_pt:
            return True
        self.ZZhCounter.Fill(4) # Z pT
        if len(event.cleanFatJets)<1 or event.cleanFatJets[0].pt() < self.cfg_ana.fatjet_pt:
            return True
        self.ZZhCounter.Fill(5) # Jet pT
        # Fill tree
        event.isZZh = True
        
        
        # Build candidates
        # Higgs candidate
        prunedJet = copy.deepcopy(event.cleanFatJets[0]) # Copy fatJet...
        prunedJet.setMass(prunedJet.userFloat("ak8PFJetsCHSPrunedLinks")) # ... and set the mass to the pruned mass
        theH = prunedJet.p4()
        theH.charge = event.cleanFatJets[0].charge()
        theH.deltaR = deltaR(event.cleanFatJets[0].subJet1.eta(), event.cleanFatJets[0].subJet1.phi(), event.cleanFatJets[0].subJet2.eta(), event.cleanFatJets[0].subJet2.phi()) if hasattr(event.cleanFatJets[0], "subJet2") else -1.
        theH.deltaEta = abs(event.cleanFatJets[0].subJet1.eta() - event.cleanFatJets[0].subJet2.eta()) if hasattr(event.cleanFatJets[0], "subJet2") else -9.
        theH.deltaPhi = deltaPhi(event.cleanFatJets[0].subJet1.phi(), event.cleanFatJets[0].subJet2.phi()) if hasattr(event.cleanFatJets[0], "subJet2") else -9.
        theH.deltaPhi_met = deltaPhi(theH.phi(), event.met.phi())
        theH.deltaPhi_jet1 = deltaPhi(theH.phi(), event.cleanFatJets[0].phi())
        event.h = theH
        # Zprime candidate
        theA = event.Z + event.h
        theA.charge = event.Z.charge + event.h.charge
        theA.deltaR = deltaR(event.Z.eta(), event.Z.phi(), event.h.eta(), event.h.phi())
        theA.deltaEta = abs(event.Z.eta() - event.h.eta())
        theA.deltaPhi = deltaPhi(event.Z.phi(), event.h.phi())
        theA.deltaPhi_met = deltaPhi(theA.phi(), event.met.phi())
        theA.deltaPhi_jet1 = deltaPhi(theA.phi(), event.h.phi())
        event.A = theA
        
#        for j in event.cleanFatJets:
#            j.deltaPhi_met = deltaPhi(j.phi(), event.met.phi())
#            j.deltaPhi_jet1 = deltaPhi(j.phi(), event.cleanFatJets[0].phi())
        
        # Estimate cuts
        if event.Z.mass() > self.cfg_ana.Zmass_low and event.Z.mass() < self.cfg_ana.Zmass_high:
            self.ZZhCounter.Fill(6) # Z mass
            #if event.cleanFatJets[0].btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatJet_btag:
            if event.cleanFatJets[0].nSubJets >= 1 and event.cleanFatJets[0].subJet1.btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatJet_btag_1:
                self.ZZhCounter.Fill(7) # b-Jet1
                if event.cleanFatJets[0].nSubJets >= 2 and event.cleanFatJets[0].subJet2.btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatJet_btag_2: 
                    self.ZZhCounter.Fill(8) # b-Jet2
                    if event.cleanFatJets[0].userFloat("ak8PFJetsCHSPrunedLinks") > self.cfg_ana.fatJetMass_low and event.cleanFatJets[0].userFloat("ak8PFJetsCHSPrunedLinks") < self.cfg_ana.fatJetMass_high:
                        self.ZZhCounter.Fill(9) # h mass
                        if event.met.pt() < self.cfg_ana.met_pt:
                            self.ZZhCounter.Fill(10) # MET

        return True
Пример #44
0
    def computeQGvars(self):
        #return immediately if qgvars already computed or if qgl is disabled
        if not hasattr(self,"qgl_rho") or getattr(self,"hasQGVvars",False) :
            return self
        self.hasQGvars = True

        jet = self
        jet.mult = 0
        sum_weight = 0.
        sum_pt = 0.    
        sum_deta = 0.  
        sum_dphi = 0.  
        sum_deta2 = 0. 
        sum_detadphi = 0.
        sum_dphi2 = 0.   



        for ii in range(0, jet.numberOfDaughters()) :

            part = jet.daughter(ii)

            if part.charge() == 0 : # neutral particles 

                if part.pt() < 1.: continue

            else : # charged particles

                if part.trackHighPurity()==False: continue
                if part.fromPV()<=1: continue             


            jet.mult += 1

            deta = part.eta() - jet.eta()
            dphi = deltaPhi(part.phi(), jet.phi())
            partPt = part.pt()                    
            weight = partPt*partPt                
            sum_weight += weight                  
            sum_pt += partPt                      
            sum_deta += deta*weight               
            sum_dphi += dphi*weight               
            sum_deta2 += deta*deta*weight         
            sum_detadphi += deta*dphi*weight      
            sum_dphi2 += dphi*dphi*weight         




        a = 0.
        b = 0.
        c = 0.

        if sum_weight > 0 :
            jet.ptd = math.sqrt(sum_weight)/sum_pt
            ave_deta = sum_deta/sum_weight        
            ave_dphi = sum_dphi/sum_weight        
            ave_deta2 = sum_deta2/sum_weight      
            ave_dphi2 = sum_dphi2/sum_weight      
            a = ave_deta2 - ave_deta*ave_deta     
            b = ave_dphi2 - ave_dphi*ave_dphi     
            c = -(sum_detadphi/sum_weight - ave_deta*ave_dphi)
        else: jet.ptd = 0.                                  

        delta = math.sqrt(math.fabs((a-b)*(a-b)+4.*c*c))

        if a+b-delta > 0: jet.axis2 = -math.log(math.sqrt(0.5*(a+b-delta)))
        else: jet.axis2 = -1.                                              
        return jet	
Пример #45
0
treeProducer= cfg.Analyzer(
	class_object=AutoFillTreeProducer, 
	defaultFloatType = "F",
	verbose=False, 
	vectorTree = True,
        globalVariables	= [
                 NTupleVariable("puWeightUp", lambda ev : getattr(ev,"puWeightPlus",1.), help="Pileup up variation",mcOnly=True),
                 NTupleVariable("puWeightDown", lambda ev : getattr(ev,"puWeightMinus",1.), help="Pileup down variation",mcOnly=True),
                 NTupleVariable("json", lambda ev : getattr(ev,"json",True), help="Passing json selection"),
                 NTupleVariable("json_silver", lambda ev : getattr(ev,"json_silver",True), help="Passing silver json selection"),
                 NTupleVariable("nPU0", lambda ev : [bx.nPU() for bx in  ev.pileUpInfo if bx.getBunchCrossing()==0][0], help="nPU in BX=0",mcOnly=True),
                 NTupleVariable("nPVs", lambda ev : len(ev.goodVertices), help="total number of good PVs"),
		 NTupleVariable("Vtype", lambda ev : ev.Vtype, help="Event classification"),
		 NTupleVariable("VtypeSim", lambda ev : ev.VtypeSim, help="Event classification",mcOnly=True),
		 NTupleVariable("VMt", lambda ev : ev.V.goodMt, help="Transverse mass of the vector boson"),
		 NTupleVariable("HVdPhi", lambda ev : deltaPhi(ev.V.phi(),ev.H.phi()), help="Delta phi between Higgs and Z/W"),
		 NTupleVariable("fakeMET_sumet", lambda ev : ev.fakeMET.sumet, help="Fake SumET from Zmumu events removing muons"),
    	         NTupleVariable("bx",  lambda ev: ev.input.eventAuxiliary().bunchCrossing(), int, help="bunch crossing number"),
		 NTupleVariable("caloMetPt",  lambda ev: ev.met.caloMETPt(), float, help="calo met pt "),
		 NTupleVariable("caloMetPhi",  lambda ev: ev.met.caloMETPhi(), float, help="calo met phi"),
		 NTupleVariable("rho",  lambda ev: ev.rho, float, help="kt6PFJets rho"),
		 NTupleVariable("rhoN",  lambda ev: ev.rhoN, float, help="rho with neutrals only"),
		 NTupleVariable("rhoCHPU",  lambda ev: ev.rhoCHPU, float, help="rho with charged pileup particles"),
		 NTupleVariable("rhoCentral",  lambda ev: ev.rho, float, help="rho central"),
          
		 NTupleVariable("deltaR_jj",  lambda ev: deltaR(ev.hJets[0].eta(),ev.hJets[0].phi(),ev.hJets[1].eta(),ev.hJets[1].phi()) if len(ev.hJets) > 1 else -1, float, help="deltaR higgsJets"),
		 NTupleVariable("lheNj",  lambda ev: ev.lheNj, float,mcOnly=True, help="number of jets at LHE level"),
                 NTupleVariable("lheNb",  lambda ev: ev.lheNb, float,mcOnly=True, help="number of b-jets at LHE level"),
                 NTupleVariable("lheNc",  lambda ev: ev.lheNc, float,mcOnly=True, help="number of c-jets at LHE level"),
                 NTupleVariable("lheNg",  lambda ev: ev.lheNg, float,mcOnly=True, help="number of gluon jets at LHE level"),
                 NTupleVariable("lheNl",  lambda ev: ev.lheNl, float,mcOnly=True, help="number of light(uds) jets at LHE level"),
Пример #46
0
 def deltaPhi(self):
     return abs(deltaPhi(self.leg1.phi(),self.leg2.phi()))
Пример #47
0
 def fillJetVariables(self, event):
     for j in event.Jets + event.cleanJets + event.cleanFatJets:
         j.deltaPhi_met = deltaPhi(j.phi(), event.met.phi())
         j.deltaPhi_jet1 = deltaPhi(j.phi(), event.Jets[0].phi())
    def process(self, event):
        self.readCollections( event.input )
        self.counters.counter('events').inc('all events')

        event.bjetsLoose  = [ j for j in event.cleanJets if j.btagWP("CSVv2IVFL") ]
        event.bjetsMedium = [ j for j in event.cleanJets if j.btagWP("CSVv2IVFM") ]

        import ROOT

        ## with Central Jets
        objects25 = [ j for j in event.cleanJets if j.pt() > 25 ] + event.selectedLeptons
        objects30 = [ j for j in event.cleanJets if j.pt() > 30 ] + event.selectedLeptons
        objects40 = [ j for j in event.cleanJets if j.pt() > 40 ] + event.selectedLeptons
        objectsX  = [ j for j in event.cleanJets if j.pt() > self.jetPt ] + event.selectedLeptons
        objects30j = [ j for j in event.cleanJets if j.pt() > 30 ] 
        objects40j = [ j for j in event.cleanJets if j.pt() > 40 ] 
        objects50j = [ j for j in event.cleanJets if j.pt() > 50 ] 
        objectsXj = [ j for j in event.cleanJets if j.pt() > self.jetPt ]
        objects40j10l = [ j for j in event.cleanJets if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] 
        objects40j10l.sort(key = lambda obj : obj.pt(), reverse = True)
        objectsXj10l = [ j for j in event.cleanJets if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] 
        objectsXj10l.sort(key = lambda obj : obj.pt(), reverse = True)

        objects40j10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objects40j10l5t = [ j for j in event.cleanJets if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objects40j10l5t.sort(key = lambda obj : obj.pt(), reverse = True)

        objectsXj10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objectsXj10l5t = [ j for j in event.cleanJets if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objectsXj10l5t.sort(key = lambda obj : obj.pt(), reverse = True)
            
        event.htJet25 = sum([x.pt() for x in objects25])
        event.mhtJet25vec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects25])) , -1.*(sum([x.py() for x in objects25])), 0, 0 )     
        event.mhtPhiJet25 = event.mhtJet25vec.phi()
        event.mhtJet25 = event.mhtJet25vec.pt()

        event.htJet30 = sum([x.pt() for x in objects30])
        event.mhtJet30vec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects30])) , -1.*(sum([x.py() for x in objects30])), 0, 0 )             
        event.mhtJet30 = event.mhtJet30vec.pt()
        event.mhtPhiJet30 = event.mhtJet30vec.phi()

        event.htJet40 = sum([x.pt() for x in objects40])
        event.mhtJet40vec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40])) , -1.*(sum([x.py() for x in objects40])), 0, 0 )             
        event.mhtJet40 = event.mhtJet40vec.pt()
        event.mhtPhiJet40 = event.mhtJet40vec.phi()

        event.htJetX = sum([x.pt() for x in objectsX])
        event.mhtJetXvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsX])) , -1.*(sum([x.py() for x in objectsX])), 0, 0 )             
        event.mhtJetX = event.mhtJetXvec.pt()
        event.mhtPhiJetX = event.mhtJetXvec.phi()

        event.htJet30j = sum([x.pt() for x in objects30j])
        event.htJet40j = sum([x.pt() for x in objects40j])
        event.mhtJet40jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40j])) , -1.*(sum([x.py() for x in objects40j])), 0, 0 )               
        event.mhtJet40j = event.mhtJet40jvec.pt()
        event.mhtPhiJet40j = event.mhtJet40jvec.phi()        

        event.htJet50j = sum([x.pt() for x in objects50j])
        event.mhtJet50jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects50j])) , -1.*(sum([x.py() for x in objects50j])), 0, 0 )               
        event.mhtJet50j = event.mhtJet50jvec.pt()
        event.mhtPhiJet50j = event.mhtJet50jvec.phi()        
        
        event.htJetXj = sum([x.pt() for x in objectsXj])
        event.mhtJetXjvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXj])) , -1.*(sum([x.py() for x in objectsXj])), 0, 0 )
        event.mhtJetXj = event.mhtJetXjvec.pt()
        event.mhtPhiJetXj = event.mhtJetXjvec.phi()


        #Make 40 and 50 GeV HTs from cleanGenJets
        if self.cfg_comp.isMC:
            
            genObjects40j = [j for j in event.cleanGenJets if j.pt()>40]
            genObjects50j = [j for j in event.cleanGenJets if j.pt()>50]
            genObjectsXj = [j for j in event.cleanGenJets if j.pt()>self.jetPt]

            event.htGenJet40j = sum([x.pt() for x in genObjects40j])
            event.mhtGenJet40jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in genObjects40j])) , -1.*(sum([x.py() for x in genObjects40j])), 0, 0 )               
            event.mhtGenJet40j = event.mhtGenJet40jvec.pt()
            event.mhtPhiGenJet40j = event.mhtGenJet40jvec.phi()        

            event.htGenJet50j = sum([x.pt() for x in genObjects50j])
            event.mhtGenJet50jvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in genObjects50j])) , -1.*(sum([x.py() for x in genObjects50j])), 0, 0 )               
            event.mhtGenJet50j = event.mhtGenJet50jvec.pt()
            event.mhtPhiGenJet50j = event.mhtGenJet50jvec.phi()        

            event.htGenJetXj = sum([x.pt() for x in genObjectsXj])
            event.mhtGenJetXjvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in genObjectsXj])) , -1.*(sum([x.py() for x in genObjectsXj])), 0, 0 )               
            event.mhtGenJetXj = event.mhtGenJetXjvec.pt()
            event.mhtPhiGenJetXj = event.mhtGenJetXjvec.phi()        

        event.htJet40j10l = sum([x.pt() for x in objects40j10l])
        event.mhtJet40j10lvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40j10l])) , -1.*(sum([x.py() for x in objects40j10l])), 0, 0 )               
        event.mhtJet40j10l = event.mhtJet40j10lvec.pt()
        event.mhtPhiJet40j10l = event.mhtJet40j10lvec.phi()        

        event.htJetXj10l = sum([x.pt() for x in objectsXj10l])
        event.mhtJetXj10lvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXj10l])) , -1.*(sum([x.py() for x in objectsXj10l])), 0, 0 )               
        event.mhtJetXj10l = event.mhtJetXj10lvec.pt()
        event.mhtPhiJetXj10l = event.mhtJetXj10lvec.phi()        

        event.htJet40j10l5t = sum([x.pt() for x in objects40j10l5t])
        event.mhtJet40j10l5tvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40j10l5t])) , -1.*(sum([x.py() for x in objects40j10l5t])), 0, 0 )               
        event.mhtJet40j10l5t = event.mhtJet40j10l5tvec.pt()
        event.mhtPhiJet40j10l5t = event.mhtJet40j10l5tvec.phi()        
        
        event.htJetXj10l5t = sum([x.pt() for x in objectsXj10l5t])
        event.mhtJetXj10l5tvec = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXj10l5t])) , -1.*(sum([x.py() for x in objectsXj10l5t])), 0, 0 )
        event.mhtJetXj10l5t = event.mhtJetXj10l5tvec.pt()
        event.mhtPhiJetXj10l5t = event.mhtJetXj10l5tvec.phi()

        ## same but with all eta range
        objects25a  = [ j for j in event.cleanJetsAll if j.pt() > 25 ] + event.selectedLeptons
        objects30a  = [ j for j in event.cleanJetsAll if j.pt() > 30 ] + event.selectedLeptons
        objects40a  = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + event.selectedLeptons
        objectsXa  = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ] + event.selectedLeptons
        objects40ja = [ j for j in event.cleanJetsAll if j.pt() > 40 ] 
        objectsXja = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ]

        objects40ja10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objects40ja10l5t = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objects40ja10l5t.sort(key = lambda obj : obj.pt(), reverse = True)

        objects40ja10l = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ]
        objects40ja10l.sort(key = lambda obj : obj.pt(), reverse = True)

        objectsXja10l5t = []
        if hasattr(event, 'selectedIsoCleanTrack'):
            objectsXja10l5t = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ] + [ t for t in event.selectedIsoCleanTrack ]
            objectsXja10l5t.sort(key = lambda obj : obj.pt(), reverse = True)

        objects40ja10l = [ j for j in event.cleanJetsAll if j.pt() > 40 ] + [ l for l in event.selectedLeptons if l.pt() > 10 ]
        objects40ja10l.sort(key = lambda obj : obj.pt(), reverse = True)

        objectsXja10l = [ j for j in event.cleanJetsAll if j.pt() > self.jetPt ] + [ l for l in event.selectedLeptons if l.pt() > 10 ]
        objectsXja10l.sort(key = lambda obj : obj.pt(), reverse = True)

        event.htJet25a = sum([x.pt() for x in objects25a])
        event.mhtJet25veca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects25a])) , -1.*(sum([x.py() for x in objects25a])), 0, 0 )     
        event.mhtPhiJet25a = event.mhtJet25veca.phi()
        event.mhtJet25a = event.mhtJet25veca.pt()

        event.htJet30a = sum([x.pt() for x in objects30a])
        event.mhtJet30veca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects30a])) , -1.*(sum([x.py() for x in objects30a])), 0, 0 )             
        event.mhtJet30a = event.mhtJet30veca.pt()
        event.mhtPhiJet30a = event.mhtJet30veca.phi()

        event.htJet40a = sum([x.pt() for x in objects40a])
        event.mhtJet40veca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40a])) , -1.*(sum([x.py() for x in objects40a])), 0, 0 )             
        event.mhtJet40a = event.mhtJet40veca.pt()
        event.mhtPhiJet40a = event.mhtJet40veca.phi()

        event.htJetXa = sum([x.pt() for x in objectsXa])
        event.mhtJetXveca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXa])) , -1.*(sum([x.py() for x in objectsXa])), 0, 0 )             
        event.mhtJetXa = event.mhtJetXveca.pt()
        event.mhtPhiJetXa = event.mhtJetXveca.phi()

        event.htJet40ja = sum([x.pt() for x in objects40ja])
        event.mhtJet40jveca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objects40ja])) , -1.*(sum([x.py() for x in objects40ja])), 0, 0 )                     
        event.mhtJet40ja = event.mhtJet40jveca.pt()
        event.mhtPhiJet40ja = event.mhtJet40jveca.phi()

        event.htJetXja = sum([x.pt() for x in objectsXja])
        event.mhtJetXjveca = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in objectsXja])) , -1.*(sum([x.py() for x in objectsXja])), 0, 0 )
        event.mhtJetXja = event.mhtJetXjveca.pt()
        event.mhtPhiJetXja = event.mhtJetXjveca.phi()

        #For the vertex related variables 
        #A = selectedLeptons[0], B = selectedLeptons[1], C = selectedLeptons[2], D = selectedLeptons[3] 
        nlep = len(event.selectedLeptons)
        
        ##Variables related to IP
        #Of one lepton w.r.t. the PV of the event
        event.absIP3DA = absIP3D(event.selectedLeptons[0],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 0 else (-1,-1)  
        event.absIP3DB = absIP3D(event.selectedLeptons[1],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 1 else (-1,-1)    
        event.absIP3DC = absIP3D(event.selectedLeptons[2],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 2 else (-1,-1)
        event.absIP3DD = absIP3D(event.selectedLeptons[3],event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]) if nlep > 3 else (-1,-1)

        #Of one lepton w.r.t. the PV of the PV of the other leptons only
        event.absIP3DApvBC = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3,0) if nlep > 2 else (-1,-1)
        event.absIP3DBpvAC = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3,1) if nlep > 2 else (-1,-1)
        event.absIP3DCpvAB = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3,2) if nlep > 2 else (-1,-1)
 
        event.absIP3DApvBCD = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,0) if nlep > 3 else (-1,-1)
        event.absIP3DBpvACD = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,1) if nlep > 3 else (-1,-1)
        event.absIP3DCpvABD = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,2) if nlep > 3 else (-1,-1)
        event.absIP3DDpvABC = absIP3Dtrkpvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],4,3) if nlep > 3 else (-1,-1)
        
        ##Variables related to chi2
        #Chi2 of all the good leptons of the event but one lepton
        event.chi2pvtrksBCbutA = chi2pvtrks(event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[1],event.selectedLeptons[1],2) if nlep > 2 else (-1,-1)
        event.chi2pvtrksACbutB = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[2],event.selectedLeptons[0],event.selectedLeptons[0],2) if nlep > 2 else (-1,-1)
        event.chi2pvtrksABbutC = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[0],event.selectedLeptons[0],2) if nlep > 2 else (-1,-1)

        event.chi2pvtrksBCDbutA = chi2pvtrks(event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[3],event.selectedLeptons[1],3) if nlep > 3 else (-1,-1)
        event.chi2pvtrksACDbutB = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[2],event.selectedLeptons[3],event.selectedLeptons[0],3) if nlep > 3 else (-1,-1)
        event.chi2pvtrksABDbutC = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[3],event.selectedLeptons[0],3) if nlep > 3 else (-1,-1)
        event.chi2pvtrksABCbutD = chi2pvtrks(event.selectedLeptons[0],event.selectedLeptons[1],event.selectedLeptons[2],event.selectedLeptons[0],3) if nlep > 3 else (-1,-1)

        self.makeZs(event, self.maxLeps)
        self.makeMlls(event, self.maxLeps)
        self.makeLepPtRel(event)

        # look for minimal deltaPhi between MET and four leading jets with pt>40 and eta<2.4
        event.deltaPhiMin_had = 999.
        for n,j in enumerate(objects40ja):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin_had : event.deltaPhiMin_had = thisDeltaPhi

        event.deltaPhiMin = 999.
        for n,j in enumerate(objects40ja10l5t):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin : event.deltaPhiMin = thisDeltaPhi

        event.deltaPhiMin_Xj_had = 999.
        for n,j in enumerate(objectsXja):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin_Xj_had : event.deltaPhiMin_Xj_had = thisDeltaPhi

        event.deltaPhiMin_Xj = 999.
        for n,j in enumerate(objectsXja10l5t):
            if n>3:  break
            thisDeltaPhi = abs( deltaPhi( j.phi(), event.met.phi() ) )
            if thisDeltaPhi < event.deltaPhiMin_Xj : event.deltaPhiMin_Xj = thisDeltaPhi


        for lep in event.selectedLeptons:
            lep.mvaValueTTH     = self.leptonMVATTH(lep)
        for lep in event.inclusiveLeptons:
            if lep not in event.selectedLeptons:
                lep.mvaValueTTH     = self.leptonMVATTH(lep)


        # absolute value of the vectorial difference between met and mht
        diffMetMht_had_vec = ROOT.reco.Particle.LorentzVector(event.mhtJet40jvec.px()-event.met.px(), event.mhtJet40jvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht_had = sqrt( diffMetMht_had_vec.px()*diffMetMht_had_vec.px() + diffMetMht_had_vec.py()*diffMetMht_had_vec.py() )

        diffMetMht_vec = ROOT.reco.Particle.LorentzVector(event.mhtJet40j10l5tvec.px()-event.met.px(), event.mhtJet40j10l5tvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht = sqrt( diffMetMht_vec.px()*diffMetMht_vec.px() + diffMetMht_vec.py()*diffMetMht_vec.py() )
        
        diffMetMht_Xj_had_vec = ROOT.reco.Particle.LorentzVector(event.mhtJetXjvec.px()-event.met.px(), event.mhtJetXjvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht_Xj_had = sqrt( diffMetMht_Xj_had_vec.px()*diffMetMht_Xj_had_vec.px() + diffMetMht_Xj_had_vec.py()*diffMetMht_Xj_had_vec.py() )

        diffMetMht_Xj_vec = ROOT.reco.Particle.LorentzVector(event.mhtJetXj10l5tvec.px()-event.met.px(), event.mhtJetXj10l5tvec.py()-event.met.py(), 0, 0 )
        event.diffMetMht_Xj = sqrt( diffMetMht_Xj_vec.px()*diffMetMht_Xj_vec.px() + diffMetMht_Xj_vec.py()*diffMetMht_Xj_vec.py() )
        ###

        #Make Biased DPhi
        event.biasedDPhi = -999
        self.makeBiasedDPhi(event)

        return True
Пример #49
0
    Variable('pzeta_met', lambda dil : dil.pZetaMET()),
    Variable('pzeta_vis', lambda dil : dil.pZetaVis()),
    Variable('pzeta_disc', lambda dil : dil.pZetaDisc()),
    Variable('mt', lambda dil : dil.mTLeg1()),
    Variable('mt_leg2', lambda dil : dil.mTLeg2()),
    Variable('mt_leg1', lambda dil : dil.mTLeg1()),
    Variable('met_cov00', lambda dil : dil.mvaMetSig(0, 0) if dil.mvaMetSig else 0.),
    Variable('met_cov01', lambda dil : dil.mvaMetSig(0, 1) if dil.mvaMetSig else 0.),
    Variable('met_cov10', lambda dil : dil.mvaMetSig(1, 0) if dil.mvaMetSig else 0.),
    Variable('met_cov11', lambda dil : dil.mvaMetSig(1, 1) if dil.mvaMetSig else 0.),
    Variable('met_phi', lambda dil : dil.met().phi()),
    Variable('met_px', lambda dil : dil.met().px()),
    Variable('met_py', lambda dil : dil.met().py()),
    Variable('met_pt', lambda dil : dil.met().pt()),
    Variable('pthiggs', lambda dil : (dil.leg1().p4() + dil.leg2().p4() + dil.met().p4()).pt()),
    Variable('delta_phi_l1_l2', lambda dil : deltaPhi(dil.leg1().phi(), dil.leg2().phi())),
    Variable('delta_eta_l1_l2', lambda dil : abs(dil.leg1().eta() - dil.leg2().eta())),
    Variable('delta_r_l1_l2', lambda dil : deltaR(dil.leg1().eta(), dil.leg1().phi(), dil.leg2().eta(), dil.leg2().phi())),
    Variable('delta_phi_l1_met', lambda dil : deltaPhi(dil.leg2().phi(), dil.met().phi())),
    Variable('delta_phi_l2_met', lambda dil : deltaPhi(dil.leg1().phi(), dil.met().phi())),
]

# generic particle
particle_vars = [
    Variable('pt', lambda p: p.pt()),
    Variable('eta', lambda p: p.eta()),
    Variable('phi', lambda p: p.phi()),
    Variable('charge', lambda p: p.charge() if hasattr(p, 'charge') else 0), # charge may be non-integer for gen particles
    Variable('mass', lambda p: p.mass()),
]
Пример #50
0
     mcOnly=True),
 NTupleVariable("nPVs",
                lambda ev: len(ev.goodVertices),
                help="total number of good PVs"),
 NTupleVariable("Vtype",
                lambda ev: ev.Vtype,
                help="Event classification"),
 NTupleVariable("VtypeSim",
                lambda ev: ev.VtypeSim,
                help="Event classification",
                mcOnly=True),
 NTupleVariable("VMt",
                lambda ev: ev.V.goodMt,
                help="Transverse mass of the vector boson"),
 NTupleVariable("HVdPhi",
                lambda ev: deltaPhi(ev.V.phi(), ev.H.phi()),
                help="Delta phi between Higgs and Z/W"),
 NTupleVariable("fakeMET_sumet",
                lambda ev: ev.fakeMET.sumet,
                help="Fake SumET from Zmumu events removing muons"),
 NTupleVariable("bx",
                lambda ev: ev.input.eventAuxiliary().bunchCrossing(),
                int,
                help="bunch crossing number"),
 NTupleVariable("caloMetPt",
                lambda ev: ev.met.caloMETPt(),
                float,
                help="calo met pt "),
 NTupleVariable("caloMetPhi",
                lambda ev: ev.met.caloMETPhi(),
                float,
Пример #51
0
    def process(self, event):
        event.isZZh = False
        
#        self.genAnalysis(event)
        
        self.ZZhCounter.Fill(-1) # All
        self.ZZhCounter.Fill(0) # Trigger
        # Leptons >= 2
        if not len(event.inclusiveLeptons)>=2:
            return True
        self.ZZhCounter.Fill(1) # Lep > 2
        # Select first lepton
        if not hasattr(event, "Z"):
            return True
        self.ZZhCounter.Fill(2) # Z cand
        if len(event.cleanJetsAK8)<1 or event.cleanJetsAK8[0].pt() < self.cfg_ana.fatjet_pt or len(event.cleanJetsAK8[0].subjets('SoftDrop')) < 2:
            return True
        self.ZZhCounter.Fill(3) # Jet pT
        if event.Z.pt() < self.cfg_ana.Z_pt:
            return True
        self.ZZhCounter.Fill(4) # Z pT
        # Fill tree
        event.isZZh = True
        
        
        # Build candidates
        if not hasattr(event, "SubJets"): event.SubJets = event.cleanJetsAK8[0].subjets('SoftDrop')
        
        # Higgs candidate
        theH = event.cleanJetsAK8[0].p4()
        theH.charge = event.cleanJetsAK8[0].charge()
        theH.deltaR = deltaR(event.SubJets[0].eta(), event.SubJets[0].phi(), event.SubJets[1].eta(), event.SubJets[1].phi())
        theH.deltaEta = abs(event.SubJets[0].eta() - event.SubJets[1].eta())
        theH.deltaPhi = deltaPhi(event.SubJets[0].phi(), event.SubJets[1].phi())
        theH.deltaPhi_met = deltaPhi(theH.phi(), event.met.phi())
        theH.deltaPhi_jet1 = deltaPhi(theH.phi(), event.cleanJetsAK8[0].phi())
        event.H = theH
        
        # Zprime candidate
        theA = event.Z + event.H
        theA.charge = event.Z.charge + event.H.charge
        theA.deltaR = deltaR(event.Z.eta(), event.Z.phi(), event.H.eta(), event.H.phi())
        theA.deltaEta = abs(event.Z.eta() - event.H.eta())
        theA.deltaPhi = deltaPhi(event.Z.phi(), event.H.phi())
        theA.deltaPhi_met = deltaPhi(theA.phi(), event.met.phi())
        theA.deltaPhi_jet1 = deltaPhi(theA.phi(), event.H.phi())
        event.A = theA
        
        for j in event.cleanJetsAK8:
            j.deltaPhi_met = deltaPhi(j.phi(), event.met.phi())
            j.deltaPhi_jet1 = deltaPhi(j.phi(), event.cleanJetsAK8[0].phi())
        
        # Estimate cuts
        if event.Z.mass() > self.cfg_ana.Zmass_low and event.Z.mass() < self.cfg_ana.Zmass_high:
            self.ZZhCounter.Fill(5) # Z mass
            if event.cleanJetsAK8[0].userFloat(self.cfg_ana.fatjet_mass_algo) > self.cfg_ana.fatjet_mass_low and event.cleanJetsAK8[0].userFloat(self.cfg_ana.fatjet_mass_algo) < self.cfg_ana.fatjet_mass_high:
                self.ZZhCounter.Fill(6) # h mass
                if event.met.pt() < self.cfg_ana.met_pt:
                    self.ZZhCounter.Fill(7) # MET
                    #if event.cleanJetsAK8[0].btag('combinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatJet_btag:
                    if event.cleanJetsAK8[0].subjets('SoftDrop')[0].bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatjet_btag_1:
                        self.ZZhCounter.Fill(8) # b-Jet1
                        if event.cleanJetsAK8[0].subjets('SoftDrop')[1].bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags') > self.cfg_ana.fatjet_btag_2: 
                            self.ZZhCounter.Fill(9) # b-Jet2

        return True
Пример #52
0
    def computeQGvars(self):
        #return immediately if qgvars already computed or if qgl is disabled
        if not hasattr(self, "qgl_rho") or getattr(self, "hasQGVvars", False):
            return self
        self.hasQGvars = True

        jet = self
        jet.mult = 0
        sum_weight = 0.
        sum_pt = 0.
        sum_deta = 0.
        sum_dphi = 0.
        sum_deta2 = 0.
        sum_detadphi = 0.
        sum_dphi2 = 0.

        for ii in range(0, jet.numberOfDaughters()):

            part = jet.daughter(ii)

            if part.charge() == 0:  # neutral particles

                if part.pt() < 1.: continue

            else:  # charged particles

                if part.trackHighPurity() == False: continue
                if part.fromPV() <= 1: continue

            jet.mult += 1

            deta = part.eta() - jet.eta()
            dphi = deltaPhi(part.phi(), jet.phi())
            partPt = part.pt()
            weight = partPt * partPt
            sum_weight += weight
            sum_pt += partPt
            sum_deta += deta * weight
            sum_dphi += dphi * weight
            sum_deta2 += deta * deta * weight
            sum_detadphi += deta * dphi * weight
            sum_dphi2 += dphi * dphi * weight

        a = 0.
        b = 0.
        c = 0.

        if sum_weight > 0:
            jet.ptd = math.sqrt(sum_weight) / sum_pt
            ave_deta = sum_deta / sum_weight
            ave_dphi = sum_dphi / sum_weight
            ave_deta2 = sum_deta2 / sum_weight
            ave_dphi2 = sum_dphi2 / sum_weight
            a = ave_deta2 - ave_deta * ave_deta
            b = ave_dphi2 - ave_dphi * ave_dphi
            c = -(sum_detadphi / sum_weight - ave_deta * ave_dphi)
        else:
            jet.ptd = 0.

        delta = math.sqrt(math.fabs((a - b) * (a - b) + 4. * c * c))

        if a + b - delta > 0:
            jet.axis2 = -math.log(math.sqrt(0.5 * (a + b - delta)))
        else:
            jet.axis2 = -1.
        return jet
Пример #53
0
    def makeZllObjects(self, event):

        import ROOT

        vetoLeptons = [ l for l in event.selectedLeptons if l.pt() > 10 and abs(l.eta()) < 2.5 ]

        # MET + zll                                                                                                                                                                                                               
        event.zll_ht = -999.
        event.zll_deltaPhiMin = -999.
        event.zll_met_pt = -999.
        event.zll_met_phi = -999.
        event.zll_diffMetMht = -999.
        event.zll_mhtJet40j = -999.
        event.zll_mhtPhiJet40j = -999.
        event.zll_p4 = ROOT.reco.Particle.LorentzVector( 0, 0, 0, 0 )
                      
        event.zll_ht_Xj = -999.
        event.zll_deltaPhiMin_Xj = -999.
        event.zll_diffMetMht_Xj = -999.
        event.zll_mhtJetXj = -999.
        event.zll_mhtPhiJetXj = -999.

        if len(vetoLeptons)==2:
            event.zll_met = ROOT.reco.Particle.LorentzVector( event.met.px(), event.met.py(), 0, 0 )
            for l in vetoLeptons:
                event.zll_met = ROOT.reco.Particle.LorentzVector( event.zll_met.px() + l.px(), event.zll_met.py() + l.py() , 0, 0 )

            event.zll_met_pt = event.zll_met.pt()
            event.zll_met_phi = event.zll_met.phi()

            # defining mht as hadronic mht                                                                                                                                                                                        
            event.zll_mhtJet40j = event.mhtJet40j
            event.zll_mhtPhiJet40j = event.mhtPhiJet40j

            event.zll_mhtJetXj = event.mhtJetXj
            event.zll_mhtPhiJetXj = event.mhtPhiJetXj

            # look for minimal deltaPhi between MET and four leading jets with pt>40 and |eta|<2.4                                                                                                                                
            event.zll_deltaPhiMin = 999.
            objects40jc = [ j for j in event.cleanJets if j.pt() > 40 and abs(j.eta())<2.5 ]
            objects40ja = [ j for j in event.cleanJets if j.pt() > 40]
            event.zll_ht = sum([x.pt() for x in objects40jc])
            for n,j in enumerate(objects40ja):
                if n>3:  break
                thisDeltaPhi = abs( deltaPhi( j.phi(), event.zll_met.phi() ) )
                if thisDeltaPhi < event.zll_deltaPhiMin : event.zll_deltaPhiMin = thisDeltaPhi

            event.zll_deltaPhiMin_Xj = 999.
            objectsXjc = [ j for j in event.cleanJets if j.pt() > self.jetPt and abs(j.eta())<2.5 ]
            objectsXja = [ j for j in event.cleanJets if j.pt() > self.jetPt]
            event.zll_ht_Xj = sum([x.pt() for x in objectsXjc])
            for n,j in enumerate(objectsXja):
                if n>3:  break
                thisDeltaPhi = abs( deltaPhi( j.phi(), event.zll_met.phi() ) )
                if thisDeltaPhi < event.zll_deltaPhiMin_Xj : event.zll_deltaPhiMin_Xj = thisDeltaPhi

            # absolute value of the vectorial difference between met and mht                                                                                                                                                      
            zll_diffMetMht_vec = ROOT.reco.Particle.LorentzVector(event.mhtJet40jvec.px()-event.zll_met.px(), event.mhtJet40jvec.py()-event.zll_met.py(), 0, 0 )
            event.zll_diffMetMht = sqrt( zll_diffMetMht_vec.px()*zll_diffMetMht_vec.px() + zll_diffMetMht_vec.py()*zll_diffMetMht_vec.py() )

            zll_diffMetMht_Xj_vec = ROOT.reco.Particle.LorentzVector(event.mhtJetXjvec.px()-event.zll_met.px(), event.mhtJetXjvec.py()-event.zll_met.py(), 0, 0 )
            event.zll_diffMetMht_Xj = sqrt( zll_diffMetMht_Xj_vec.px()*zll_diffMetMht_Xj_vec.px() + zll_diffMetMht_Xj_vec.py()*zll_diffMetMht_Xj_vec.py() )

            # di-lepton invariant mass                                                                                                                                                                                            
            for l in vetoLeptons:
                event.zll_p4 += l.p4()