Esempio n. 1
0
def triggerMatched(object,
                   triggerObjects,
                   path,
                   filter,
                   dR2Max=0.089999,
                   dRMax=0.,
                   pdgIds=None,
                   index=False):
    '''The default dR2Max is 0.3^2'''
    eta = object.eta()
    phi = object.phi()
    # to speed up the code, could sort the triggerObjects by decreasing pT
    # when they are produced
    for i, trigObj in enumerate(triggerObjects):
        if trigObj.hasPath( path )        and \
           trigObj.hasSelection( filter ) and \
           dRMax == 0.                    and \
           deltaR2( eta, phi, trigObj.eta(), trigObj.phi() ) < dR2Max:
            if pdgIds is None or abs(trigObj.pdgId()) in pdgIds:
                if index: return True, i
                else: return True
        if trigObj.hasPath( path )        and \
           trigObj.hasSelection( filter ) and \
           dRMax > 0.                     and \
           math.sqrt(deltaR2( eta, phi, trigObj.eta(), trigObj.phi() )) < dRMax:
            if pdgIds is None or abs(trigObj.pdgId()) in pdgIds:
                if index: return True, i
                else: return True

    if index: return False, -99
    else: return False
Esempio n. 2
0
def triggerMatched(object, triggerObjects, path, filter, dR2Max=0.089999, dRMax=0.0, pdgIds=None, index=False):
    """The default dR2Max is 0.3^2"""
    eta = object.eta()
    phi = object.phi()
    # to speed up the code, could sort the triggerObjects by decreasing pT
    # when they are produced
    for i, trigObj in enumerate(triggerObjects):
        if (
            trigObj.hasPath(path)
            and trigObj.hasSelection(filter)
            and dRMax == 0.0
            and deltaR2(eta, phi, trigObj.eta(), trigObj.phi()) < dR2Max
        ):
            if pdgIds is None or abs(trigObj.pdgId()) in pdgIds:
                if index:
                    return True, i
                else:
                    return True
        if (
            trigObj.hasPath(path)
            and trigObj.hasSelection(filter)
            and dRMax > 0.0
            and math.sqrt(deltaR2(eta, phi, trigObj.eta(), trigObj.phi())) < dRMax
        ):
            if pdgIds is None or abs(trigObj.pdgId()) in pdgIds:
                if index:
                    return True, i
                else:
                    return True

    if index:
        return False, -99
    else:
        return False
Esempio n. 3
0
    def match(self, myPair, genParticles):

        dR2leg1Min = 999.
        dR2leg2Min = 999.
        dR2leg1 = 999.
        dR2leg2 = 999.
        index1 = -99
        index2 = -99

        for index, genPart in enumerate(genParticles):
            dR2leg1 = deltaR2(myPair.leg1().eta(),
                              myPair.leg1().phi(), genPart.eta(),
                              genPart.phi())
            dR2leg2 = deltaR2(myPair.leg2().eta(),
                              myPair.leg2().phi(), genPart.eta(),
                              genPart.phi())
            if dR2leg1 < dR2leg1Min:
                dR2leg1Min = dR2leg1
                index1 = index
            if dR2leg2 < dR2leg2Min:
                dR2leg2Min = dR2leg2
                index2 = index

        self.leg1DeltaR = math.sqrt(dR2leg1Min)
        self.leg2DeltaR = math.sqrt(dR2leg2Min)
        self.index1 = index1
        self.index2 = index2
        return (self.leg1DeltaR, self.leg2DeltaR, self.index1, self.index2)
Esempio n. 4
0
 def match(self, genParticles):
     #TODO review matching algorithm
     #TODO move matching stuff even higher?
     # print self
     genTaus = []
     ZorPhotonorHiggs = [22, 23, 25, 35, 36, 37]
     for gen in genParticles:
         # print '\t', gen
         if abs(gen.pdgId())==15 and gen.mother().pdgId() in ZorPhotonorHiggs:
             genTaus.append( gen )
     # print 'Gen taus: '
     # print '\n'.join( map( str, genTaus ) )
     if len(genTaus)!=2:
         #COLIN what about WW, ZZ? 
         return (-1, -1)
     else:
         dR2leg1Min, self.leg1Gen = ( float('inf'), None)
         dR2leg2Min, self.leg2Gen = ( float('inf'), None) 
         for genTau in genTaus:
             dR2leg1 = deltaR2(self.leg1().eta(), self.leg1().phi(), genTau.eta(), genTau.phi() )
             dR2leg2 = deltaR2(self.leg2().eta(), self.leg2().phi(), genTau.eta(), genTau.phi() )
             if dR2leg1 <  dR2leg1Min:
                 dR2leg1Min, self.leg1Gen = (dR2leg1, genTau)
             if dR2leg2 <  dR2leg2Min:
                 dR2leg2Min, self.leg2Gen = (dR2leg2, genTau)
         # print dR2leg1Min, dR2leg2Min
         # print self.leg1Gen
         # print self.leg2Gen
         self.leg1DeltaR = math.sqrt( dR2leg1Min )
         self.leg2DeltaR = math.sqrt( dR2leg2Min )
         return (self.leg1DeltaR, self.leg2DeltaR)        
Esempio n. 5
0
 def matchW(self, genParticles):
     # print self
     genTaus = []
     for gen in genParticles:
         # print '\t', gen
         if abs(gen.pdgId()) == 15 and gen.mother().pdgId(
         ) == 24:  # W -> tau nu_tau
             genTaus.append(gen)
     # print 'Gen taus: '
     # print '\n'.join( map( str, genTaus ) )
     if len(genTaus) != 1:
         #COLIN what about WW, ZZ?
         return (-1, -1)
     else:
         dR2leg1Min, self.leg1Gen = (float('inf'), None)
         dR2leg2Min, self.leg2Gen = (float('inf'), None)
         for genTau in genTaus:
             dR2leg1 = deltaR2(self.leg1().eta(),
                               self.leg1().phi(), genTau.eta(),
                               genTau.phi())
             dR2leg2 = deltaR2(self.leg2().eta(),
                               self.leg2().phi(), genTau.eta(),
                               genTau.phi())
             if dR2leg1 < dR2leg1Min:
                 dR2leg1Min, self.leg1Gen = (dR2leg1, genTau)
             if dR2leg2 < dR2leg2Min:
                 dR2leg2Min, self.leg2Gen = (dR2leg2, genTau)
         # print dR2leg1Min, dR2leg2Min
         # print self.leg1Gen
         # print self.leg2Gen
         self.leg1DeltaR = math.sqrt(dR2leg1Min)
         self.leg2DeltaR = math.sqrt(dR2leg2Min)
         return (self.leg1DeltaR, self.leg2DeltaR)
Esempio n. 6
0
 def matchW(self, genParticles):
     # print self
     genTaus = []
     for gen in genParticles:
         # print '\t', gen
         if abs(gen.pdgId())==15 and gen.mother().pdgId()==24: # W -> tau nu_tau
             genTaus.append( gen )
     # print 'Gen taus: '
     # print '\n'.join( map( str, genTaus ) )
     if len(genTaus)!=1:
         #COLIN what about WW, ZZ? 
         return (-1, -1)
     else:
         dR2leg1Min, self.leg1Gen = ( float('inf'), None)
         dR2leg2Min, self.leg2Gen = ( float('inf'), None) 
         for genTau in genTaus:
             dR2leg1 = deltaR2(self.leg1().eta(), self.leg1().phi(),
                               genTau.eta(), genTau.phi() )
             dR2leg2 = deltaR2(self.leg2().eta(), self.leg2().phi(),
                               genTau.eta(), genTau.phi() )
             if dR2leg1 <  dR2leg1Min:
                 dR2leg1Min, self.leg1Gen = (dR2leg1, genTau)
             if dR2leg2 <  dR2leg2Min:
                 dR2leg2Min, self.leg2Gen = (dR2leg2, genTau)
         # print dR2leg1Min, dR2leg2Min
         # print self.leg1Gen
         # print self.leg2Gen
         self.leg1DeltaR = math.sqrt( dR2leg1Min )
         self.leg2DeltaR = math.sqrt( dR2leg2Min )
         return (self.leg1DeltaR, self.leg2DeltaR)        
Esempio n. 7
0
def cleanNearestJetOnly(jets, leptons, deltaR):
    dr2 = deltaR**2
    good = [True for j in jets]
    for l in leptons:
        ibest, d2m = -1, dr2
        for i, j in enumerate(jets):
            d2i = deltaR2(l.eta(), l.phi(), j.eta(), j.phi())
            if d2i < d2m:
                ibest, d2m = i, d2i
        if ibest != -1: good[ibest] = False
    return [j for (i, j) in enumerate(jets) if good[i] == True]
Esempio n. 8
0
def cleanNearestJetOnly(jets,leptons,deltaR):
    dr2 = deltaR**2
    good = [ True for j in jets ]
    for l in leptons:
        ibest, d2m = -1, dr2
        for i,j in enumerate(jets):
            d2i = deltaR2(l.eta(),l.phi(), j.eta(),j.phi())
            if d2i < d2m:
                ibest, d2m = i, d2i
        if ibest != -1: good[ibest] = False
    return [ j for (i,j) in enumerate(jets) if good[i] == True ] 
Esempio n. 9
0
    def match(self, myPair, genParticles):
      
      dR2leg1Min = 999.
      dR2leg2Min = 999.
      dR2leg1 = 999.
      dR2leg2 = 999.
      index1  = -99
      index2  = -99
      
      for index, genPart in enumerate(genParticles) :
        dR2leg1 = deltaR2(myPair.leg1().eta(), myPair.leg1().phi(), genPart.eta(), genPart.phi() )
        dR2leg2 = deltaR2(myPair.leg2().eta(), myPair.leg2().phi(), genPart.eta(), genPart.phi() )
        if dR2leg1 <  dR2leg1Min: 
          dR2leg1Min = dR2leg1
          index1     = index
        if dR2leg2 <  dR2leg2Min: 
          dR2leg2Min = dR2leg2
          index2     = index

      self.leg1DeltaR = math.sqrt( dR2leg1Min )
      self.leg2DeltaR = math.sqrt( dR2leg2Min )
      self.index1     = index1
      self.index2     = index2
      return (self.leg1DeltaR, self.leg2DeltaR, self.index1, self.index2)        
Esempio n. 10
0
 def match(self, genParticles):
     #TODO review matching algorithm
     #TODO move matching stuff even higher?
     # print self
     genTaus = []
     ZorPhotonorHiggs = [22, 23, 25, 35, 36, 37]
     for gen in genParticles:
         # print '\t', gen
         if abs(gen.pdgId()) == 15 and gen.mother().pdgId(
         ) in ZorPhotonorHiggs:
             genTaus.append(gen)
     # print 'Gen taus: '
     # print '\n'.join( map( str, genTaus ) )
     if len(genTaus) != 2:
         #COLIN what about WW, ZZ?
         return (-1, -1)
     else:
         dR2leg1Min, self.leg1Gen = (float('inf'), None)
         dR2leg2Min, self.leg2Gen = (float('inf'), None)
         for genTau in genTaus:
             dR2leg1 = deltaR2(self.leg1().eta(),
                               self.leg1().phi(), genTau.eta(),
                               genTau.phi())
             dR2leg2 = deltaR2(self.leg2().eta(),
                               self.leg2().phi(), genTau.eta(),
                               genTau.phi())
             if dR2leg1 < dR2leg1Min:
                 dR2leg1Min, self.leg1Gen = (dR2leg1, genTau)
             if dR2leg2 < dR2leg2Min:
                 dR2leg2Min, self.leg2Gen = (dR2leg2, genTau)
         # print dR2leg1Min, dR2leg2Min
         # print self.leg1Gen
         # print self.leg2Gen
         self.leg1DeltaR = math.sqrt(dR2leg1Min)
         self.leg2DeltaR = math.sqrt(dR2leg2Min)
         return (self.leg1DeltaR, self.leg2DeltaR)
Esempio n. 11
0
def triggerMatched( object, triggerObjects, path, filter,
                    dR2Max=0.089999, pdgIds=None):
    '''The default dR2Max is 0.3^2'''
    # import pdb; pdb.set_trace()
    eta = object.eta()
    phi = object.phi()
    # to speed up the code, could sort the triggerObjects by decreasing pT
    # when they are produced
    for trigObj in triggerObjects:
        if trigObj.hasPath( path ) and \
           trigObj.hasSelection( filter ) and \
           deltaR2( eta, phi, trigObj.eta(), trigObj.phi() ) < dR2Max:
            if pdgIds is None or \
                   abs(trigObj.pdgId()) in pdgIds:
                return True
    return False
Esempio n. 12
0
 def fillJet (self, jet) :
     # import pdb
     # pdb.set_trace ()
     self.fillFrac (jet)
     self.h_pt.Fill (jet.pt ())
     if jet.pt () > 10 : self.h_eta.Fill (jet.eta ())
     self.h_phi_eta.Fill (jet.eta (), jet.phi ()) 
     if hasattr (jet, 'gen') and jet.gen is not None:
         dR2 = deltaR2 (jet.gen.eta (), jet.gen.phi (), jet.eta (), jet.phi ())
         self.h_deltaJetMatch.Fill (dR2)
         self.h_dpt_dR2.Fill (dR2, jet.pt () / jet.gen.pt ())
         self.h_dR2_ptr.Fill (jet.gen.pt (), dR2)
         self.h_dR2_eta.Fill (jet.gen.eta (), dR2)
         if dR2 < 0.3 :
             self.h_genpt.Fill (jet.gen.pt ())
             self.h_geneta.Fill (jet.gen.pt ())
             self.h_dpt.Fill (jet.pt () / jet.gen.pt ())
             self.h_dpt_pt.Fill (jet.gen.pt (), jet.pt () / jet.gen.pt ()) 
             self.h_dpt_eta.Fill (jet.gen.eta (), jet.pt () / jet.gen.pt ()) 
             self.h_ptr_ptg.Fill (jet.gen.pt (), jet.pt ()) 
Esempio n. 13
0
def triggerMatched(object,
                   triggerObjects,
                   path,
                   filter,
                   dR2Max=0.089999,
                   pdgIds=None):
    '''The default dR2Max is 0.3^2'''
    # import pdb; pdb.set_trace()
    eta = object.eta()
    phi = object.phi()
    # to speed up the code, could sort the triggerObjects by decreasing pT
    # when they are produced
    for trigObj in triggerObjects:
        if trigObj.hasPath( path ) and \
           trigObj.hasSelection( filter ) and \
           deltaR2( eta, phi, trigObj.eta(), trigObj.phi() ) < dR2Max:
            if pdgIds is None or \
                   abs(trigObj.pdgId()) in pdgIds:
                return True
    return False
 def fillJet(self, jet):
     # import pdb
     # pdb.set_trace ()
     self.fillFrac(jet)
     self.h_pt.Fill(jet.pt())
     if jet.pt() > 10:
         self.h_eta.Fill(jet.eta())  # why cut on pt only here ?
     self.h_phi_eta.Fill(jet.eta(), jet.phi())
     if hasattr(jet, "gen") and jet.gen is not None:
         dR2 = deltaR2(jet.gen.eta(), jet.gen.phi(), jet.eta(), jet.phi())
         self.h_deltaJetMatch.Fill(dR2)
         self.h_dpt_dR2.Fill(dR2, jet.pt() / jet.gen.pt())
         self.h_dR2_ptr.Fill(jet.gen.pt(), dR2)
         self.h_dR2_eta.Fill(jet.gen.eta(), dR2)
         if dR2 < 0.3:
             self.h_genpt.Fill(jet.gen.pt())
             self.h_geneta.Fill(jet.gen.pt())
             self.h_dpt.Fill(jet.pt() / jet.gen.pt())
             self.h_dpt_pt.Fill(jet.gen.pt(), jet.pt() / jet.gen.pt())
             self.h_dpt_eta.Fill(jet.gen.eta(), jet.pt() / jet.gen.pt())
             self.h_ptr_ptg.Fill(jet.gen.pt(), jet.pt())
Esempio n. 15
0
    def process(self, iEvent, event):
        
        self.readCollections( iEvent )
        cmgJets = self.handles['jets'].product()

        allJets = []
        event.jets = []
        event.bJets = []
        event.cleanJets = []
        event.cleanBJets = []

        leptons = []
        if hasattr(event, 'selectedLeptons'):
            leptons = event.selectedLeptons


        genJets = None
        if self.cfg_comp.isMC:
            genJets = map( GenJet, self.mchandles['genJets'].product() ) 
            
        for cmgJet in cmgJets:
            jet = Jet( cmgJet )
            allJets.append( jet )
            if self.cfg_comp.isMC and hasattr( self.cfg_comp, 'jetScale'):
                scale = random.gauss( self.cfg_comp.jetScale,
                                      self.cfg_comp.jetSmear )
                jet.scaleEnergy( scale )
            if genJets:
                # Use DeltaR = 0.25 matching like JetMET
                pairs = matchObjectCollection( [jet], genJets, 0.25*0.25)
                if pairs[jet] is None:
                    pass
                else:
                    jet.matchedGenJet = pairs[jet] 

            #Add JER correction for MC jets. Requires gen-jet matching. 
            if self.cfg_comp.isMC and hasattr(self.cfg_ana, 'jerCorr') and self.cfg_ana.jerCorr:
                self.jerCorrection(jet)

            #Add JES correction for MC jets.
            if self.cfg_comp.isMC and hasattr(self.cfg_ana, 'jesCorr'):
                self.jesCorrection(jet, self.cfg_ana.jesCorr)
            if self.testJet( jet ):
                event.jets.append(jet)
            if self.testBJet(jet):
                event.bJets.append(jet)


                
        self.counters.counter('jets').inc('all events')

        event.cleanJets, dummy = cleanObjectCollection( event.jets,
                                                        masks = leptons,
                                                        deltaRMin = 0.5 )
        

        event.cleanBJets, dummy = cleanObjectCollection( event.bJets,
                                                         masks = leptons,
                                                         deltaRMin = 0.5 )        

        pairs = matchObjectCollection( leptons, allJets, 0.5*0.5)


        # associating a jet to each lepton
        for lepton in leptons:
            jet = pairs[lepton]
            if jet is None:
                lepton.jet = lepton
            else:
                lepton.jet = jet

        # associating a leg to each clean jet
        invpairs = matchObjectCollection( event.cleanJets, leptons, 99999. )
        for jet in event.cleanJets:
            leg = invpairs[jet]
            jet.leg = leg

        for jet in event.cleanJets:
            jet.matchGenParton=999.0

        if self.cfg_comp.isMC and "BB" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            for gen in genParticles:
                if abs(gen.pdgId())==5 and gen.mother() and abs(gen.mother().pdgId())==21:
                    for jet in event.cleanJets:
                        dR=deltaR2(jet.eta(), jet.phi(), gen.eta(), gen.phi() )
                        if dR<jet.matchGenParton:
                            jet.matchGenParton=dR

        event.jets30 = [jet for jet in event.jets if jet.pt()>30]
        event.cleanJets30 = [jet for jet in event.cleanJets if jet.pt()>30]
        
        if len( event.jets30 )>=2:
            self.counters.counter('jets').inc('at least 2 good jets')
               
        if len( event.cleanJets30 )>=2:
            self.counters.counter('jets').inc('at least 2 clean jets')

        if len(event.cleanJets)<2:
            return True

        return True
Esempio n. 16
0
    def process(self, iEvent, event):
        
        self.readCollections( iEvent )
        cmgJets = self.handles['jets'].product()

        allJets = []
        event.jets = []
        event.bJets = []
        event.cleanJets = []
        event.cleanBJets = []

        leg1 = event.diLepton.leg1()
        leg2 = event.diLepton.leg2()

        genJets = None
        if self.cfg_comp.isMC:
            genJets = map( GenJet, self.mchandles['genJets'].product() ) 
     
        for cmgJet in cmgJets:
            jet = Jet( cmgJet )
            allJets.append( jet )
            if self.cfg_comp.isMC and hasattr( self.cfg_comp, 'jetScale'):
                scale = random.gauss( self.cfg_comp.jetScale,
                                      self.cfg_comp.jetSmear )
                jet.scaleEnergy( scale )

            if self.testJet( jet ):
                event.jets.append(jet)
            if self.testBJet(jet):
                event.bJets.append(jet)
            if genJets:
                # Use DeltaR = 0.25 matching like JetMET
                pairs = matchObjectCollection( [jet], genJets, 0.25*0.25)
                if pairs[jet] is None:
                    pass
                    #jet.genJet = None
                else:
                    jet.genJet = pairs[jet] 

            #Add JER correction for MC jets. Requires gen-jet matching
            if self.cfg_comp.isMC and hasattr(self.cfg_ana, 'jerCorr') and self.cfg_ana.jerCorr:
                self.jerCorrection(jet)

        self.counters.counter('VBF').inc('all events')

        event.cleanJets, dummy = cleanObjectCollection( event.jets,
                                                        masks = [leg1,
                                                                 leg2 ],
                                                        deltaRMin = 0.5 )
        

        event.cleanBJets, dummy = cleanObjectCollection( event.bJets,
                                                         masks = [leg1,
                                                                  leg2 ],
                                                         deltaRMin = 0.5 )        

        pairs = matchObjectCollection( [ leg1,
                                         leg2 ], allJets, 0.5*0.5)

        # associating a jet to each leg
        leg1.jet = pairs[leg1]
        leg2.jet = pairs[leg2]
        if leg1.jet is None: #COLIN: I don't understand the code below...
            leg1.jet = leg1
        if leg2.jet is None:
            leg2.jet = leg2        

        # associating a leg to each clean jet
        invpairs = matchObjectCollection( event.cleanJets, [ leg1,leg2 ], 99999. )
        for jet in event.cleanJets:
            leg = invpairs[jet]
            jet.leg = leg

        for jet in event.cleanJets:
            jet.matchGenParton=999.0

        if self.cfg_comp.isMC and "BB" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            for gen in genParticles:
                if abs(gen.pdgId())==5 and gen.mother() and abs(gen.mother().pdgId())==21:
                    for jet in event.cleanJets:
                        dR=deltaR2(jet.eta(), jet.phi(), gen.eta(), gen.phi() )
                        if dR<jet.matchGenParton:
                            jet.matchGenParton=dR

        event.jets30 = [jet for jet in event.jets if jet.pt()>30]
        event.cleanJets30 = [jet for jet in event.cleanJets if jet.pt()>30]
        
        if len( event.jets30 )>=2:
            self.counters.counter('VBF').inc('at least 2 good jets')
               
        if len( event.cleanJets30 )>=2:
            self.counters.counter('VBF').inc('at least 2 clean jets')

        if len(event.cleanJets)<2:
            return True

        event.vbf = VBF( event.cleanJets, event.diLepton,
                         None, self.cfg_ana.cjvPtCut )
        if event.vbf.mjj > self.cfg_ana.Mjj:
            self.counters.counter('VBF').inc('M_jj > {cut:3.1f}'.format(cut=self.cfg_ana.Mjj) )
        else:
            return True 
        if abs(event.vbf.deta) > self.cfg_ana.deltaEta:
            self.counters.counter('VBF').inc('delta Eta > {cut:3.1f}'.format(cut=self.cfg_ana.deltaEta) )
        else:
            return True 
        if len(event.vbf.centralJets)==0:
            self.counters.counter('VBF').inc('no central jets')
        else:
            return True
        
        return True
Esempio n. 17
0
    def process(self, iEvent, event):
        
        self.readCollections( iEvent )
        cmgJets = self.handles['jets'].product()

        allJets = []
        event.jets = []
        event.bJets = []
        event.cleanJets = []
        event.cleanBJets = []

        leptons = event.selectedLeptons

        genJets = None
        if self.cfg_comp.isMC:
            genJets = map( GenJet, self.mchandles['genJets'].product() ) 
            
        for cmgJet in cmgJets:
            jet = Jet( cmgJet )
            allJets.append( jet )
            if self.cfg_comp.isMC and hasattr( self.cfg_comp, 'jetScale'):
                scale = random.gauss( self.cfg_comp.jetScale,
                                      self.cfg_comp.jetSmear )
                jet.scaleEnergy( scale )
            if genJets:
                # Use DeltaR = 0.25 matching like JetMET
                pairs = matchObjectCollection( [jet], genJets, 0.25*0.25)
                if pairs[jet] is None:
                    pass
                    #jet.genJet = None
                else:
                    jet.genJet = pairs[jet] 
                # print jet, jet.genJet

            #Add JER correction for MC jets. Requires gen-jet matching. 
            if self.cfg_comp.isMC and hasattr(self.cfg_ana, 'jerCorr') and self.cfg_ana.jerCorr:
                self.jerCorrection(jet)

            #Add JES correction for MC jets.
            if self.cfg_comp.isMC and hasattr(self.cfg_ana, 'jesCorr'):
                self.jesCorrection(jet, self.cfg_ana.jesCorr)
            if self.testJet( jet ):
                event.jets.append(jet)
            if self.testBJet(jet):
                event.bJets.append(jet)


                
        self.counters.counter('jets').inc('all events')

        event.cleanJets, dummy = cleanObjectCollection( event.jets,
                                                        masks = leptons,
                                                        deltaRMin = 0.5 )
        

        event.cleanBJets, dummy = cleanObjectCollection( event.bJets,
                                                         masks = leptons,
                                                         deltaRMin = 0.5 )        

        pairs = matchObjectCollection( leptons, allJets, 0.5*0.5)


        # associating a jet to each lepton
        for lepton in leptons:
            jet = pairs[lepton]
            if jet is None:
                lepton.jet = lepton
            else:
                lepton.jet = jet

        # associating a leg to each clean jet
        invpairs = matchObjectCollection( event.cleanJets, leptons, 99999. )
        for jet in event.cleanJets:
            leg = invpairs[jet]
            jet.leg = leg

        for jet in event.cleanJets:
            jet.matchGenParton=999.0

        if self.cfg_comp.isMC and "BB" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            for gen in genParticles:
                if abs(gen.pdgId())==5 and gen.mother() and abs(gen.mother().pdgId())==21:
                    for jet in event.cleanJets:
                        dR=deltaR2(jet.eta(), jet.phi(), gen.eta(), gen.phi() )
                        if dR<jet.matchGenParton:
                            jet.matchGenParton=dR

        event.jets30 = [jet for jet in event.jets if jet.pt()>30]
        event.cleanJets30 = [jet for jet in event.cleanJets if jet.pt()>30]
        
        if len( event.jets30 )>=2:
            self.counters.counter('jets').inc('at least 2 good jets')
               
        if len( event.cleanJets30 )>=2:
            self.counters.counter('jets').inc('at least 2 clean jets')

        if len(event.cleanJets)<2:
            return True

        return True
Esempio n. 18
0
    def process(self, iEvent, event):
        # select signal dileptons with all cuts on both legs
        
        if 'TTJets_emb' in self.cfg_comp.name :
          self.cfg_comp.isEmbed = True
        self.readCollections( iEvent )
        # trigger stuff could be put in a separate analyzer
        # event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]
        
        event.diLeptons = self.buildDiLeptons( self.handles['diLeptons'].product(), event )

        #event.leptons = self.buildLeptons( self.handles['leptons'].product(), event )
        event.leptons = []
	for diLepton in event.diLeptons:
          if not diLepton.leg1() in event.leptons:
            event.leptons += [diLepton.leg1()]
          if not diLepton.leg2() in event.leptons:
            event.leptons += [diLepton.leg2()]
        self.shiftEnergyScale(event)
        
	event.rawMET = self.handles['rawMET'].product()
        
	triggerResults = self.handles['triggerResults'].product()
        triggerNames = iEvent._event.triggerNames(triggerResults)
	#event.hltPath = []
	for trig in self.triggers:
	    index = triggerNames.triggerIndex(trig)
	    if index >= triggerNames.size():
                trigres = -1
	    else:
	        trigres = triggerResults.accept(index)
                #event.hltPath.append(trig) 
	    setattr(event,trig,trigres)
 
	result = self.selectionSequence(event, fillCounter=True)

        # select non signal dileptons with loose cuts
        if result is False:
	  selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
                           self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
	                   self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
	                  (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]

          if len(selDiLeptons)==0:
              selDiLeptons = [ diL for diL in event.diLeptons if \
                               self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
	                       self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
			       (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
          if len(selDiLeptons)==0:
            return False
          event.diLepton = self.bestDiLepton( selDiLeptons )
          event.leg1 = event.diLepton.leg1()
          event.leg2 = event.diLepton.leg2()
          event.isSignal = False
        else:
          event.isSignal = True

        #if event.eventId in notPassed :
        #  print 'diLeptons built, is Signal?', result
        #  import pdb ; pdb.set_trace()

        #if len([event.diLepton])>1 :
          #import pdb ; pdb.set_trace()
        event.leg1.NewLooseAntiEleMVA3 = self.passAntiEMVA(iCat = event.diLepton.leg1().tauID("againstElectronMVA3category"), raw = event.diLepton.leg1().tauID("againstElectronMVA3raw"), WP = 0 )
        event.leg2.NewLooseAntiEleMVA3 = self.passAntiEMVA(iCat = event.diLepton.leg2().tauID("againstElectronMVA3category"), raw = event.diLepton.leg2().tauID("againstElectronMVA3raw"), WP = 0 )
        
        # count muons
        event.muons = [lep for lep in self.buildMuons(self.handles['muons'].product(),event)
                       if self.testLegKine(lep, ptcut=10, etacut=2.4) and 
                          self.testLeg2ID(lep)                        and
                          self.testLeg2Iso(lep, 0.3) ]
        # count electrons
        event.electrons = [electron for electron in self.buildElectrons(self.handles['electrons'].product(),event)
                           if self.testLegKine(electron, ptcut=10, etacut=2.5) and
                              electron.looseIdForTriLeptonVeto()               and
                              self.testVertex( electron )                      and
                              electron.relIsoAllChargedDB05() < 0.3]
        ####### what ID for veto means
        ####### http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/CMG/CMGTools/RootTools/python/physicsobjects/HTauTauElectron.py?revision=1.10&view=markup
        #import pdb ; pdb.set_trace()

        if self.cfg_comp.isEmbed or "TTJets_emb" in self.cfg_comp.name :
            genParticles = self.embhandles['genParticlesEmb'].product()
            self.splitDYJets( event, genParticles, event.diLepton, require_status=False)

        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name or "W" in self.cfg_comp.name and not "WW" in self.cfg_comp.name and not "WZ" in self.cfg_comp.name and not "_new" in self.cfg_comp.name) :
          event.NUP = self.mchandles['source'].product().hepeup().NUP
	else:
          event.NUP = -1

        event.genMatched = None
        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name or "Higgs" in self.cfg_comp.name):
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            
            # useless now
            leg1DeltaR, leg2DeltaR = event.diLepton.match( event.genParticles ) 
	    event.leg1DeltaR = leg1DeltaR
            event.leg2DeltaR = leg2DeltaR
            if leg1DeltaR>-1 and leg1DeltaR < 0.3 and \
               leg2DeltaR>-1 and leg2DeltaR < 0.3 :
                event.genMatched = True
            else:
                event.genMatched = False
          
            self.splitDYJets( event, genParticles, event.diLepton)
                        
            event.isPhoton=False
            event.isElectron=False
	    for gen in genParticles:
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==23 and (gen.mother().mass()<80 or gen.mother().mass()>100):
                    event.isPhoton=True
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==23:
                    event.isMuon=True
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==23:
                    event.isElectron=True
        
        #import pdb ; pdb.set_trace()

        if self.cfg_comp.isMC and "W"      in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            genTaus = []
            event.genMatched = False
            event.genMatchedElectron = False
            event.genMatchedMuon = False
            for gen in genParticles:
                if abs(gen.pdgId()) in [11,13,15] and abs(gen.mother().pdgId())==24: # W -> tau nu
                    genTaus.append( gen )
            if len(genTaus)>=1:
                dR2leg1Min, event.diLepton.leg1Gen = ( float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = ( float('inf'), None) 
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(), event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi() )
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(), event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi() )
                    if dR2leg1 <  dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 <  dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt( dR2leg1Min )
                    leg2DeltaR = math.sqrt( dR2leg2Min )
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==11:
                         event.genMatchedElectron = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==13:
                         event.genMatchedMuon = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==15:
                         event.genMatched = True
            event.isElectron=False
            event.isMuon=False
            event.isTau=False
	    for gen in genParticles:
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==24:
                    event.isElectron=True
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==24:
                    event.isMuon=True
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==24:
                    event.isTau=True
        #import pdb ; pdb.set_trace()
        if self.cfg_comp.isMC and "TTJets_emb" not in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            genTaus = []
            event.genMatched = 0
            event.genMatchedElectron = 0
            event.genMatchedMuon = 0
            for gen in genParticles:
                if abs(gen.pdgId()) in [11,13,15] and abs(gen.mother().pdgId())==24: # W -> tau nu
                    genTaus.append( gen )
            if len(genTaus)>=1:
                dR2leg1Min, event.diLepton.leg1Gen = ( float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = ( float('inf'), None) 
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(), event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi() )
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(), event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi() )
                    if dR2leg1 <  dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 <  dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt( dR2leg1Min )
                    leg2DeltaR = math.sqrt( dR2leg2Min )
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron+=1
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon+=1
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==15:
                        event.genMatched+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==15:
                        event.genMatched+=1
            event.isElectron=0
            event.isMuon=0
            event.isTau=0
	    for gen in genParticles:
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==24:
                    event.isElectron+=1
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==24:
                    event.isMuon+=1
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==24:
                    event.isTau+=1
        if self.cfg_comp.isMC and "QCD"    in self.cfg_comp.name:
            generator = self.mchandles['generator'].product()
            event.generatorWeight = generator.weight()
            event.eventWeight *= event.generatorWeight
        #import pdb ; pdb.set_trace()
		
        if self.cfg_comp.isMC and "HiggsGGH" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
	    higgsPt=-1
	    for gen in genParticles:
                if abs(gen.pdgId())==25:
		    higgsPt = gen.pt()
		    break
	    event.higgsPtWeightNom  = self.higgsPtWeightHistogramNom.GetBinContent(self.higgsPtWeightHistogramNom.FindBin(higgsPt))
	    event.higgsPtWeightUp   = self.higgsPtWeightHistogramUp.GetBinContent(self.higgsPtWeightHistogramUp.FindBin(higgsPt))
	    event.higgsPtWeightDown = self.higgsPtWeightHistogramDown.GetBinContent(self.higgsPtWeightHistogramDown.FindBin(higgsPt))
	else :
	  event.higgsPtWeightNom  = 1.
          event.higgsPtWeightUp   = 1.
          event.higgsPtWeightDown = 1.


        ## third lepton veto
        if len(event.muons)+len(event.electrons)> 0: 
          return False

        if ("DY" in self.cfg_comp.name and event.isZtt) or "Higgs" in self.cfg_comp.name or (self.cfg_comp.isEmbed and event.isZtt):
          event.isRealTau = 1
        else :
          event.isRealTau = 0  
        
        if not hasattr(event,'NJetWeight') :
          event.NJetWeight = 1.
        #import pdb ; pdb.set_trace()


        if ("DY" in self.cfg_comp.name and event.isZtt) or "Higgs" in self.cfg_comp.name or (self.cfg_comp.isEmbed and event.isZtt):
          if event.leg1.decayMode() == 0 :
            event.leg1.prongWeight = 0.88
          else :
            event.leg1.prongWeight = 1.
          if event.leg2.decayMode() == 0 :
            event.leg2.prongWeight = 0.88
          else :
            event.leg2.prongWeight = 1.
        #import pdb ; pdb.set_trace()

        #event.name = self.cfg_comp.name
        #import pdb ; pdb.set_trace()
        event.metsig    = self.handles['metSig'].product()

   
        event.ntot = 1.
#         ngenevts = { 'W1Jets'         : 23141598.* 1.0           ,
#                      'W2Jets'         : 34044921.* 1.0           ,
#                      'W3Jets'         : 15539503.* 0.997191011236,
#                      'W4Jets'         : 13382803.* 0.996168582375,
#                      #'WJets'         : 18393090 * 1.0           ,
#                      'WJets'          : 57709905.* 1.0           ,
#                      'HiggsGGH125'    : 968134.  * 1.0           ,
#                      'HiggsVBF125'    : 998836.  * 1.0           ,
#                      'TTJetsFullLept' : 12011428 * 1.0           ,
#                      'TTJetsHadronic' : 31223821 * 1.0           ,
#                      'TTJetsSemiLept' : 24953451 * 1.0           ,
#                      'DYJets'         : 30459503 * 1.0           ,
#                      'HiggsSUSYBB'    : 999976   * 1.0           ,
#                      'HiggsSUSYGluGlu': 981688   * 1.0           ,
#                      'HiggsSUSYBB'    : 996960   * 1.0           ,
#                      'HiggsSUSYGluGlu': 985800   * 1.0           ,
#                    }
        
        ngenevts = { 
                     'HiggsSUSYGluGlu110': 1000348 * 0.990003 ,
                   }
        
        #import pdb ; pdb.set_trace()
        for name in ngenevts.keys() :
          if name in self.cfg_comp.name :   
            event.ntot = ngenevts[name]

        return True
Esempio n. 19
0
    def process(self, iEvent, event):
        # select signal dileptons with all cuts on both legs

        if 'TTJets_emb' in self.cfg_comp.name:
            self.cfg_comp.isEmbed = True
        self.readCollections(iEvent)
        # trigger stuff could be put in a separate analyzer
        # event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]

        event.diLeptons = self.buildDiLeptons(
            self.handles['diLeptons'].product(), event)

        #event.leptons = self.buildLeptons( self.handles['leptons'].product(), event )
        event.leptons = []
        for diLepton in event.diLeptons:
            if not diLepton.leg1() in event.leptons:
                event.leptons += [diLepton.leg1()]
            if not diLepton.leg2() in event.leptons:
                event.leptons += [diLepton.leg2()]
        self.shiftEnergyScale(event)

        event.rawMET = self.handles['rawMET'].product()

        triggerResults = self.handles['triggerResults'].product()
        triggerNames = iEvent._event.triggerNames(triggerResults)
        #event.hltPath = []
        for trig in self.triggers:
            index = triggerNames.triggerIndex(trig)
            if index >= triggerNames.size():
                trigres = -1
            else:
                trigres = triggerResults.accept(index)
        #event.hltPath.append(trig)
            setattr(event, trig, trigres)

        result = self.selectionSequence(event, fillCounter=True)

        # select non signal dileptons with loose cuts
        if result is False:
            selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
                                    self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
                             self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
                            (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]

            if len(selDiLeptons) == 0:
                selDiLeptons = [ diL for diL in event.diLeptons if \
                                 self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
                          self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
            (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
            if len(selDiLeptons) == 0:
                return False
            event.diLepton = self.bestDiLepton(selDiLeptons)
            event.leg1 = event.diLepton.leg1()
            event.leg2 = event.diLepton.leg2()
            event.isSignal = False
        else:
            event.isSignal = True

        #if event.eventId in notPassed :
        #  print 'diLeptons built, is Signal?', result
        #  import pdb ; pdb.set_trace()

        #if len([event.diLepton])>1 :
        #import pdb ; pdb.set_trace()
        event.leg1.NewLooseAntiEleMVA3 = self.passAntiEMVA(
            iCat=event.diLepton.leg1().tauID("againstElectronMVA3category"),
            raw=event.diLepton.leg1().tauID("againstElectronMVA3raw"),
            WP=0)
        event.leg2.NewLooseAntiEleMVA3 = self.passAntiEMVA(
            iCat=event.diLepton.leg2().tauID("againstElectronMVA3category"),
            raw=event.diLepton.leg2().tauID("againstElectronMVA3raw"),
            WP=0)

        # count muons
        event.muons = [
            lep
            for lep in self.buildMuons(self.handles['muons'].product(), event)
            if self.testLegKine(lep, ptcut=10, etacut=2.4)
            and self.testLeg2ID(lep) and self.testLeg2Iso(lep, 0.3)
        ]
        # count electrons
        event.electrons = [
            electron for electron in self.buildElectrons(
                self.handles['electrons'].product(), event)
            if self.testLegKine(electron, ptcut=10, etacut=2.5)
            and electron.looseIdForTriLeptonVeto() and self.testVertex(
                electron) and electron.relIsoAllChargedDB05() < 0.3
        ]
        ####### what ID for veto means
        ####### http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/CMG/CMGTools/RootTools/python/physicsobjects/HTauTauElectron.py?revision=1.10&view=markup
        #import pdb ; pdb.set_trace()

        if self.cfg_comp.isEmbed or "TTJets_emb" in self.cfg_comp.name:
            genParticles = self.embhandles['genParticlesEmb'].product()
            self.splitDYJets(event,
                             genParticles,
                             event.diLepton,
                             require_status=False)

        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name
                                   or "W" in self.cfg_comp.name
                                   and not "WW" in self.cfg_comp.name
                                   and not "WZ" in self.cfg_comp.name
                                   and not "_new" in self.cfg_comp.name):
            event.NUP = self.mchandles['source'].product().hepeup().NUP
        else:
            event.NUP = -1

        event.genMatched = None
        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name
                                   or "Higgs" in self.cfg_comp.name):
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)

            # useless now
            leg1DeltaR, leg2DeltaR = event.diLepton.match(event.genParticles)
            event.leg1DeltaR = leg1DeltaR
            event.leg2DeltaR = leg2DeltaR
            if leg1DeltaR>-1 and leg1DeltaR < 0.3 and \
               leg2DeltaR>-1 and leg2DeltaR < 0.3 :
                event.genMatched = True
            else:
                event.genMatched = False

            self.splitDYJets(event, genParticles, event.diLepton)

            event.isPhoton = False
            event.isElectron = False
            for gen in genParticles:
                if abs(gen.pdgId()) == 15 and abs(
                        gen.mother().pdgId()) == 23 and (
                            gen.mother().mass() < 80
                            or gen.mother().mass() > 100):
                    event.isPhoton = True
                if abs(gen.pdgId()) == 13 and abs(gen.mother().pdgId()) == 23:
                    event.isMuon = True
                if abs(gen.pdgId()) == 11 and abs(gen.mother().pdgId()) == 23:
                    event.isElectron = True

        #import pdb ; pdb.set_trace()

        if self.cfg_comp.isMC and "W" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)
            genTaus = []
            event.genMatched = False
            event.genMatchedElectron = False
            event.genMatchedMuon = False
            for gen in genParticles:
                if abs(gen.pdgId()) in [11, 13, 15] and abs(
                        gen.mother().pdgId()) == 24:  # W -> tau nu
                    genTaus.append(gen)
            if len(genTaus) >= 1:
                dR2leg1Min, event.diLepton.leg1Gen = (float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = (float('inf'), None)
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(),
                                      event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi())
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(),
                                      event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi())
                    if dR2leg1 < dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 < dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt(dR2leg1Min)
                    leg2DeltaR = math.sqrt(dR2leg2Min)
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==15:
                        event.genMatched = True
            event.isElectron = False
            event.isMuon = False
            event.isTau = False
            for gen in genParticles:
                if abs(gen.pdgId()) == 11 and abs(gen.mother().pdgId()) == 24:
                    event.isElectron = True
                if abs(gen.pdgId()) == 13 and abs(gen.mother().pdgId()) == 24:
                    event.isMuon = True
                if abs(gen.pdgId()) == 15 and abs(gen.mother().pdgId()) == 24:
                    event.isTau = True
        #import pdb ; pdb.set_trace()
        if self.cfg_comp.isMC and "TTJets_emb" not in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)
            genTaus = []
            event.genMatched = 0
            event.genMatchedElectron = 0
            event.genMatchedMuon = 0
            for gen in genParticles:
                if abs(gen.pdgId()) in [11, 13, 15] and abs(
                        gen.mother().pdgId()) == 24:  # W -> tau nu
                    genTaus.append(gen)
            if len(genTaus) >= 1:
                dR2leg1Min, event.diLepton.leg1Gen = (float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = (float('inf'), None)
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(),
                                      event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi())
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(),
                                      event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi())
                    if dR2leg1 < dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 < dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt(dR2leg1Min)
                    leg2DeltaR = math.sqrt(dR2leg2Min)
                    if (leg1DeltaR > -1 and leg1DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 11:
                        event.genMatchedElectron += 1
                    if (leg1DeltaR > -1 and leg1DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 13:
                        event.genMatchedMuon += 1
                    if (leg1DeltaR > -1 and leg1DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 15:
                        event.genMatched += 1
                    if (leg2DeltaR > -1 and leg2DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 11:
                        event.genMatchedElectron += 1
                    if (leg2DeltaR > -1 and leg2DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 13:
                        event.genMatchedMuon += 1
                    if (leg2DeltaR > -1 and leg2DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 15:
                        event.genMatched += 1
            event.isElectron = 0
            event.isMuon = 0
            event.isTau = 0
            for gen in genParticles:
                if abs(gen.pdgId()) == 11 and abs(gen.mother().pdgId()) == 24:
                    event.isElectron += 1
                if abs(gen.pdgId()) == 13 and abs(gen.mother().pdgId()) == 24:
                    event.isMuon += 1
                if abs(gen.pdgId()) == 15 and abs(gen.mother().pdgId()) == 24:
                    event.isTau += 1
        if self.cfg_comp.isMC and "QCD" in self.cfg_comp.name:
            generator = self.mchandles['generator'].product()
            event.generatorWeight = generator.weight()
            event.eventWeight *= event.generatorWeight
        #import pdb ; pdb.set_trace()

        if self.cfg_comp.isMC and "HiggsGGH" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)
            higgsPt = -1
            for gen in genParticles:
                if abs(gen.pdgId()) == 25:
                    higgsPt = gen.pt()
                    break
            event.higgsPtWeightNom = self.higgsPtWeightHistogramNom.GetBinContent(
                self.higgsPtWeightHistogramNom.FindBin(higgsPt))
            event.higgsPtWeightUp = self.higgsPtWeightHistogramUp.GetBinContent(
                self.higgsPtWeightHistogramUp.FindBin(higgsPt))
            event.higgsPtWeightDown = self.higgsPtWeightHistogramDown.GetBinContent(
                self.higgsPtWeightHistogramDown.FindBin(higgsPt))
        else:
            event.higgsPtWeightNom = 1.
            event.higgsPtWeightUp = 1.
            event.higgsPtWeightDown = 1.

        ## third lepton veto
        if len(event.muons) + len(event.electrons) > 0:
            return False

        if ("DY" in self.cfg_comp.name
                and event.isZtt) or "Higgs" in self.cfg_comp.name or (
                    self.cfg_comp.isEmbed and event.isZtt):
            event.isRealTau = 1
        else:
            event.isRealTau = 0

        if not hasattr(event, 'NJetWeight'):
            event.NJetWeight = 1.
        #import pdb ; pdb.set_trace()

        if ("DY" in self.cfg_comp.name
                and event.isZtt) or "Higgs" in self.cfg_comp.name or (
                    self.cfg_comp.isEmbed and event.isZtt):
            if event.leg1.decayMode() == 0:
                event.leg1.prongWeight = 0.88
            else:
                event.leg1.prongWeight = 1.
            if event.leg2.decayMode() == 0:
                event.leg2.prongWeight = 0.88
            else:
                event.leg2.prongWeight = 1.
        #import pdb ; pdb.set_trace()

        #event.name = self.cfg_comp.name
        #import pdb ; pdb.set_trace()
        event.metsig = self.handles['metSig'].product()

        event.ntot = 1.
        #         ngenevts = { 'W1Jets'         : 23141598.* 1.0           ,
        #                      'W2Jets'         : 34044921.* 1.0           ,
        #                      'W3Jets'         : 15539503.* 0.997191011236,
        #                      'W4Jets'         : 13382803.* 0.996168582375,
        #                      #'WJets'         : 18393090 * 1.0           ,
        #                      'WJets'          : 57709905.* 1.0           ,
        #                      'HiggsGGH125'    : 968134.  * 1.0           ,
        #                      'HiggsVBF125'    : 998836.  * 1.0           ,
        #                      'TTJetsFullLept' : 12011428 * 1.0           ,
        #                      'TTJetsHadronic' : 31223821 * 1.0           ,
        #                      'TTJetsSemiLept' : 24953451 * 1.0           ,
        #                      'DYJets'         : 30459503 * 1.0           ,
        #                      'HiggsSUSYBB'    : 999976   * 1.0           ,
        #                      'HiggsSUSYGluGlu': 981688   * 1.0           ,
        #                      'HiggsSUSYBB'    : 996960   * 1.0           ,
        #                      'HiggsSUSYGluGlu': 985800   * 1.0           ,
        #                    }

        ngenevts = {
            'HiggsSUSYGluGlu110': 1000348 * 0.990003,
        }

        #import pdb ; pdb.set_trace()
        for name in ngenevts.keys():
            if name in self.cfg_comp.name:
                event.ntot = ngenevts[name]

        return True
    def process(self, iEvent, event):
        # select signal dileptons with all cuts on both legs

        self.readCollections( iEvent )
        # trigger stuff could be put in a separate analyzer
        # event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]

        event.diLeptons = self.buildDiLeptons( self.handles['diLeptons'].product(), event )

        #event.leptons = self.buildLeptons( self.handles['leptons'].product(), event )
        event.leptons = []
	for diLepton in event.diLeptons:
          if not diLepton.leg1() in event.leptons:
            event.leptons += [diLepton.leg1()]
          if not diLepton.leg2() in event.leptons:
            event.leptons += [diLepton.leg2()]
        self.shiftEnergyScale(event)

        if hasattr(self.cfg_ana,'HCP_matching'):
            event.triggerObjects=[]
 
	result = self.selectionSequence(event, fillCounter=True)

	#if event.eventId in [212391570,227704571,254997006,34410222]:
	#    print "found event"
	#    print eventId,result
        
	event.rawMET=self.handles['rawMET'].product()
        
	triggerResults=self.handles['triggerResults'].product()
        triggerNames = iEvent._event.triggerNames(triggerResults)
	for trig in self.triggers:
	    index=triggerNames.triggerIndex(trig)
	    if index>=triggerNames.size():
                trigres=-1
	    else:
	        trigres=triggerResults.accept(index)
	    setattr(event,trig,trigres)

        if hasattr(self.cfg_ana,'HCP_matching'):
            event.l1TrigMatched=True
            event.l2TrigMatched=True
	
        # select non signal dileptons with loose cuts
        if result is False:
            # Post-Preapproval version
            if hasattr(self.cfg_ana,'HCP_matching'):
                selDiLeptons = [ diL for diL in event.diLeptons if \
                             self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
			     self.testNonLeg( diL.leg1() ) and self.testNonLeg( diL.leg2() ) and \
			     (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
	    else:
	        selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
                             self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
			     self.testNonLeg( diL.leg1() ) and self.testNonLeg( diL.leg2() ) and \
			     (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
                if len(selDiLeptons)==0:
                    selDiLeptons = [ diL for diL in event.diLeptons if \
                             self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
			     self.testNonLeg( diL.leg1() ) and self.testNonLeg( diL.leg2() ) and \
			     (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
            # loose reference version
            #selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
            #                 self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
		#	     self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
		#	     (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
            # std. medium iso version
            #selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
            #                 self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
		#	     self.testNonLeg( diL.leg1() ) and self.testNonLeg( diL.leg2() ) and \
		#	     (self.testStdMediumLeg( diL.leg1() ) or self.testStdMediumLeg( diL.leg2() )) ]
            # std. tight iso version
            #selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
            #                 self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
		#	     self.testLooseStdLeg( diL.leg1() ) and self.testLooseStdLeg( diL.leg2() ) and \
		#	     (self.testStdTightLeg( diL.leg1() ) or self.testStdTightLeg( diL.leg2() )) ]
            # relax cuts completely
	    #if len(selDiLeptons)==0:
	    #    selDiLeptons=event.diLeptons
            if len(selDiLeptons)==0:
                return False
            event.diLepton = self.bestDiLepton( selDiLeptons )
            event.leg1 = event.diLepton.leg1()
            event.leg2 = event.diLepton.leg2()
            event.isSignal = False
        else:
            event.isSignal = True


        # count muons
        event.muons = [lep for lep in self.buildMuons(self.handles['muons'].product(),event)
                       if self.testLegKine(lep, ptcut=10, etacut=2.4) and 
                       self.testLeg2ID(lep) and
                       self.testLeg2Iso(lep, 0.3) ]
        # count electrons
        event.electrons = [electron for electron in self.buildElectrons(self.handles['electrons'].product(),event)
                if self.testLegKine(electron, ptcut=10, etacut=2.5) and \
                   electron.looseIdForTriLeptonVeto()           and \
                   self.testVertex( electron )           and \
                   electron.relIsoAllChargedDB05() < 0.3]

        # if len(event.muons)+len(event.electrons) > 0:
        #    return False

        if self.cfg_comp.isMC and ("WJets" in self.cfg_comp.name or "W0Jets" in self.cfg_comp.name or "W1Jets" in self.cfg_comp.name or "W2Jets" in self.cfg_comp.name or "W3Jets" in self.cfg_comp.name or "W4Jets" in self.cfg_comp.name
	                        or "DYJets" in self.cfg_comp.name or "DY0Jets" in self.cfg_comp.name or "DY1Jets" in self.cfg_comp.name or "DY2Jets" in self.cfg_comp.name or "DY3Jets" in self.cfg_comp.name or "DY4Jets" in self.cfg_comp.name):
          event.NUP = self.mchandles['source'].product().hepeup().NUP
	else:
          event.NUP = -1

        event.genMatched = None
        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name or "Higgs" in self.cfg_comp.name):
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            leg1DeltaR, leg2DeltaR = event.diLepton.match( event.genParticles ) 
	    event.leg1DeltaR=leg1DeltaR
            event.leg2DeltaR=leg2DeltaR
            if leg1DeltaR>-1 and leg1DeltaR < 0.1 and \
               leg2DeltaR>-1 and leg2DeltaR < 0.1:
                event.genMatched = True
            else:
                event.genMatched = False
            event.isPhoton=False
            event.isElectron=False
	    for gen in genParticles:
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==23 and (gen.mother().mass()<80 or gen.mother().mass()>100):
                    event.isPhoton=True
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==23:
                    event.isMuon=True
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==23:
                    event.isElectron=True
                if abs(gen.pdgId()) in [23, 25, 35, 36, 37]:
                    event.genMass=gen.mass()
                if abs(gen.pdgId()) in [23]:
                    event.hasW=True
                if abs(gen.pdgId()) in [24]:
                    event.hasZ=True
        if self.cfg_comp.isMC and "W" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            genTaus = []
            event.genMatched = False
            event.genMatchedElectron = False
            event.genMatchedMuon = False
            for gen in genParticles:
                if abs(gen.pdgId()) in [11,13,15] and abs(gen.mother().pdgId())==24: # W -> tau nu
                    genTaus.append( gen )
            if len(genTaus)>=1:
                dR2leg1Min, event.diLepton.leg1Gen = ( float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = ( float('inf'), None) 
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(), event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi() )
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(), event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi() )
                    if dR2leg1 <  dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 <  dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt( dR2leg1Min )
                    leg2DeltaR = math.sqrt( dR2leg2Min )
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==11:
                         event.genMatchedElectron = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==13:
                         event.genMatchedMuon = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==15:
                         event.genMatched = True
            event.isElectron=False
            event.isMuon=False
            event.isTau=False
	    for gen in genParticles:
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==24:
                    event.isElectron=True
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==24:
                    event.isMuon=True
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==24:
                    event.isTau=True
        if self.cfg_comp.isMC and "TTJets" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            genTaus = []
            event.genMatched = 0
            event.genMatchedElectron = 0
            event.genMatchedMuon = 0
            for gen in genParticles:
                if abs(gen.pdgId()) in [11,13,15] and abs(gen.mother().pdgId())==24: # W -> tau nu
                    genTaus.append( gen )
            if len(genTaus)>=1:
                dR2leg1Min, event.diLepton.leg1Gen = ( float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = ( float('inf'), None) 
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(), event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi() )
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(), event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi() )
                    if dR2leg1 <  dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 <  dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt( dR2leg1Min )
                    leg2DeltaR = math.sqrt( dR2leg2Min )
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron+=1
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon+=1
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==15:
                        event.genMatched+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==15:
                        event.genMatched+=1
            event.isElectron=0
            event.isMuon=0
            event.isTau=0
	    for gen in genParticles:
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==24:
                    event.isElectron+=1
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==24:
                    event.isMuon+=1
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==24:
                    event.isTau+=1
		
        if self.cfg_comp.isMC and "Higgsgg" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
	    higgsPt=-1
	    for gen in genParticles:
                if abs(gen.pdgId())==25:
		    higgsPt = gen.pt()
		    break
	    event.higgsPtWeight = self.higgsPtWeightHistogram.GetBinContent(self.higgsPtWeightHistogram.FindBin(higgsPt))
            #event.eventWeight *= event.higgsPtWeight
		
        if self.cfg_comp.isMC and "QCD" in self.cfg_comp.name:
            generator = self.mchandles['generator'].product()
            event.generatorWeight = generator.weight()
            event.eventWeight *= event.generatorWeight

#COLIN: no genParticle collection present in embedded samples diTau files...
##         if self.cfg_comp.isEmbed:
##             genParticles = self.handles['genParticles'].product()
##             event.genParticles = map( GenParticle, genParticles)
## 	    for gen in genParticles:
##                 if abs(gen.pdgId()) in [23]:
##                     event.genMass=gen.mass()
	
        return True
Esempio n. 21
0
    def process(self, iEvent, event):
        # select signal dileptons with all cuts on both legs

        self.readCollections( iEvent )
        # trigger stuff could be put in a separate analyzer
        # event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]

        #if event.eventId in notPassed :
        #  print 'before anything'
        #  import pdb ; pdb.set_trace()
          
        event.diLeptons = self.buildDiLeptons( self.handles['diLeptons'].product(), event )

        #event.leptons = self.buildLeptons( self.handles['leptons'].product(), event )
        event.leptons = []
	for diLepton in event.diLeptons:
          if not diLepton.leg1() in event.leptons:
            event.leptons += [diLepton.leg1()]
          if not diLepton.leg2() in event.leptons:
            event.leptons += [diLepton.leg2()]
        self.shiftEnergyScale(event)
 
	result = self.selectionSequence(event, fillCounter=True)
        
	event.rawMET = self.handles['rawMET'].product()
        
	triggerResults = self.handles['triggerResults'].product()
        triggerNames = iEvent._event.triggerNames(triggerResults)
	for trig in self.triggers:
	    index = triggerNames.triggerIndex(trig)
	    if index >= triggerNames.size():
                trigres = -1
	    else:
	        trigres = triggerResults.accept(index)
	    setattr(event,trig,trigres)

	  	  
        # select non signal dileptons with loose cuts
        if result is False:
	  selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
                           self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
	                   self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
	                  (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]

          if len(selDiLeptons)==0:
              selDiLeptons = [ diL for diL in event.diLeptons if \
                               self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
	                       self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
			       (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
          if len(selDiLeptons)==0:
            return False
          event.diLepton = self.bestDiLepton( selDiLeptons )
          event.leg1 = event.diLepton.leg1()
          event.leg2 = event.diLepton.leg2()
          event.isSignal = False
        else:
          event.isSignal = True

        #if event.eventId in notPassed :
        #  print 'diLeptons built, is Signal?', result
        #  import pdb ; pdb.set_trace()

        #if len([event.diLepton])>1 :
          #import pdb ; pdb.set_trace()
        event.leg1.NewLooseAntiEleMVA3 = self.passAntiEMVA(iCat = event.diLepton.leg1().tauID("againstElectronMVA3category"), raw = event.diLepton.leg1().tauID("againstElectronMVA3raw"), WP = 0 )
        event.leg2.NewLooseAntiEleMVA3 = self.passAntiEMVA(iCat = event.diLepton.leg2().tauID("againstElectronMVA3category"), raw = event.diLepton.leg2().tauID("againstElectronMVA3raw"), WP = 0 )
        
        # count muons
        event.muons = [lep for lep in self.buildMuons(self.handles['muons'].product(),event)
                       if self.testLegKine(lep, ptcut=10, etacut=2.4) and 
                          self.testLeg2ID(lep)                        and
                          self.testLeg2Iso(lep, 0.3) ]
        # count electrons
        event.electrons = [electron for electron in self.buildElectrons(self.handles['electrons'].product(),event)
                           if self.testLegKine(electron, ptcut=10, etacut=2.5) and
                              electron.looseIdForTriLeptonVeto()               and
                              self.testVertex( electron )                      and
                              electron.relIsoAllChargedDB05() < 0.3]
        ####### what ID for veto means
        ####### http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/CMG/CMGTools/RootTools/python/physicsobjects/HTauTauElectron.py?revision=1.10&view=markup

        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name or "W" in self.cfg_comp.name and not "WW" in self.cfg_comp.name and not "WZ" in self.cfg_comp.name) :
          event.NUP = self.mchandles['source'].product().hepeup().NUP
	else:
          event.NUP = -1

        event.genMatched = None
        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name or "Higgs" in self.cfg_comp.name):
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            leg1DeltaR, leg2DeltaR = event.diLepton.match( event.genParticles ) 
	    event.leg1DeltaR=leg1DeltaR
            event.leg2DeltaR=leg2DeltaR
            if leg1DeltaR>-1 and leg1DeltaR < 0.1 and \
               leg2DeltaR>-1 and leg2DeltaR < 0.1:
                event.genMatched = True
            else:
                event.genMatched = False
            event.isPhoton=False
            event.isElectron=False
	    for gen in genParticles:
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==23 and (gen.mother().mass()<80 or gen.mother().mass()>100):
                    event.isPhoton=True
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==23:
                    event.isMuon=True
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==23:
                    event.isElectron=True
                if abs(gen.pdgId()) in [23, 25, 35, 36, 37]:
                    event.genMass=gen.mass()
                if abs(gen.pdgId()) in [23]:
                    event.hasW=True
                if abs(gen.pdgId()) in [24]:
                    event.hasZ=True
        if self.cfg_comp.isMC and "W"      in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            genTaus = []
            event.genMatched = False
            event.genMatchedElectron = False
            event.genMatchedMuon = False
            for gen in genParticles:
                if abs(gen.pdgId()) in [11,13,15] and abs(gen.mother().pdgId())==24: # W -> tau nu
                    genTaus.append( gen )
            if len(genTaus)>=1:
                dR2leg1Min, event.diLepton.leg1Gen = ( float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = ( float('inf'), None) 
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(), event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi() )
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(), event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi() )
                    if dR2leg1 <  dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 <  dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt( dR2leg1Min )
                    leg2DeltaR = math.sqrt( dR2leg2Min )
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==11:
                         event.genMatchedElectron = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==13:
                         event.genMatchedMuon = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==15:
                         event.genMatched = True
            event.isElectron=False
            event.isMuon=False
            event.isTau=False
	    for gen in genParticles:
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==24:
                    event.isElectron=True
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==24:
                    event.isMuon=True
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==24:
                    event.isTau=True
        if self.cfg_comp.isMC and "TTJets" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            genTaus = []
            event.genMatched = 0
            event.genMatchedElectron = 0
            event.genMatchedMuon = 0
            for gen in genParticles:
                if abs(gen.pdgId()) in [11,13,15] and abs(gen.mother().pdgId())==24: # W -> tau nu
                    genTaus.append( gen )
            if len(genTaus)>=1:
                dR2leg1Min, event.diLepton.leg1Gen = ( float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = ( float('inf'), None) 
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(), event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi() )
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(), event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi() )
                    if dR2leg1 <  dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 <  dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt( dR2leg1Min )
                    leg2DeltaR = math.sqrt( dR2leg2Min )
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron+=1
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon+=1
                    if (leg1DeltaR>-1 and leg1DeltaR < 0.1) and abs(genTau.pdgId())==15:
                        event.genMatched+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon+=1
                    if (leg2DeltaR>-1 and leg2DeltaR < 0.1) and abs(genTau.pdgId())==15:
                        event.genMatched+=1
            event.isElectron=0
            event.isMuon=0
            event.isTau=0
	    for gen in genParticles:
                if abs(gen.pdgId())==11 and abs(gen.mother().pdgId())==24:
                    event.isElectron+=1
                if abs(gen.pdgId())==13 and abs(gen.mother().pdgId())==24:
                    event.isMuon+=1
                if abs(gen.pdgId())==15 and abs(gen.mother().pdgId())==24:
                    event.isTau+=1
        if self.cfg_comp.isMC and "QCD"    in self.cfg_comp.name:
            generator = self.mchandles['generator'].product()
            event.generatorWeight = generator.weight()
            event.eventWeight *= event.generatorWeight
		
        if self.cfg_comp.isMC and "HiggsGGH" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
	    higgsPt=-1
	    for gen in genParticles:
                if abs(gen.pdgId())==25:
		    higgsPt = gen.pt()
		    break
	    event.higgsPtWeightNom  = self.higgsPtWeightHistogramNom.GetBinContent(self.higgsPtWeightHistogramNom.FindBin(higgsPt))
	    event.higgsPtWeightUp   = self.higgsPtWeightHistogramUp.GetBinContent(self.higgsPtWeightHistogramUp.FindBin(higgsPt))
	    event.higgsPtWeightDown = self.higgsPtWeightHistogramDown.GetBinContent(self.higgsPtWeightHistogramDown.FindBin(higgsPt))
	else :
	  event.higgsPtWeightNom  = 1.
          event.higgsPtWeightUp   = 1.
          event.higgsPtWeightDown = 1.


        ## third lepton veto
        if len(event.muons)>0+len(event.electrons) > 0: ## FOR SYNCHING!!!
          return False

        if "DY" in self.cfg_comp.name or "Higgs" in self.cfg_comp.name or self.cfg_comp.isEmbed:
          event.isRealTau = 1
        else :
          event.isRealTau = 0  
        
        if not hasattr(event,'NJetWeight') :
          event.NJetWeight = 1.
        
        #event.name = self.cfg_comp.name
        #import pdb ; pdb.set_trace()
        event.metsig    = self.handles['metSig'].product()

        return True
Esempio n. 22
0
    def process(self, iEvent, event):
        # select signal dileptons with all cuts on both legs

        self.readCollections(iEvent)
        # trigger stuff could be put in a separate analyzer
        # event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]

        #if event.eventId in notPassed :
        #  print 'before anything'
        #  import pdb ; pdb.set_trace()

        event.diLeptons = self.buildDiLeptons(
            self.handles['diLeptons'].product(), event)

        #event.leptons = self.buildLeptons( self.handles['leptons'].product(), event )
        event.leptons = []
        for diLepton in event.diLeptons:
            if not diLepton.leg1() in event.leptons:
                event.leptons += [diLepton.leg1()]
            if not diLepton.leg2() in event.leptons:
                event.leptons += [diLepton.leg2()]
        self.shiftEnergyScale(event)

        result = self.selectionSequence(event, fillCounter=True)

        event.rawMET = self.handles['rawMET'].product()

        triggerResults = self.handles['triggerResults'].product()
        triggerNames = iEvent._event.triggerNames(triggerResults)
        for trig in self.triggers:
            index = triggerNames.triggerIndex(trig)
            if index >= triggerNames.size():
                trigres = -1
            else:
                trigres = triggerResults.accept(index)
            setattr(event, trig, trigres)

        # select non signal dileptons with loose cuts
        if result is False:
            selDiLeptons = [ diL for diL in event.diLeptonsTrigMatched if \
                                    self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
                             self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
                            (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]

            if len(selDiLeptons) == 0:
                selDiLeptons = [ diL for diL in event.diLeptons if \
                                 self.cfg_ana.m_min < diL.mass() and diL.mass() < self.cfg_ana.m_max and \
                          self.testLooseLeg( diL.leg1() ) and self.testLooseLeg( diL.leg2() ) and \
            (self.testLeg( diL.leg1() ) or self.testLeg( diL.leg2() )) ]
            if len(selDiLeptons) == 0:
                return False
            event.diLepton = self.bestDiLepton(selDiLeptons)
            event.leg1 = event.diLepton.leg1()
            event.leg2 = event.diLepton.leg2()
            event.isSignal = False
        else:
            event.isSignal = True

        #if event.eventId in notPassed :
        #  print 'diLeptons built, is Signal?', result
        #  import pdb ; pdb.set_trace()

        #if len([event.diLepton])>1 :
        #import pdb ; pdb.set_trace()
        event.leg1.NewLooseAntiEleMVA3 = self.passAntiEMVA(
            iCat=event.diLepton.leg1().tauID("againstElectronMVA3category"),
            raw=event.diLepton.leg1().tauID("againstElectronMVA3raw"),
            WP=0)
        event.leg2.NewLooseAntiEleMVA3 = self.passAntiEMVA(
            iCat=event.diLepton.leg2().tauID("againstElectronMVA3category"),
            raw=event.diLepton.leg2().tauID("againstElectronMVA3raw"),
            WP=0)

        # count muons
        event.muons = [
            lep
            for lep in self.buildMuons(self.handles['muons'].product(), event)
            if self.testLegKine(lep, ptcut=10, etacut=2.4)
            and self.testLeg2ID(lep) and self.testLeg2Iso(lep, 0.3)
        ]
        # count electrons
        event.electrons = [
            electron for electron in self.buildElectrons(
                self.handles['electrons'].product(), event)
            if self.testLegKine(electron, ptcut=10, etacut=2.5)
            and electron.looseIdForTriLeptonVeto() and self.testVertex(
                electron) and electron.relIsoAllChargedDB05() < 0.3
        ]
        ####### what ID for veto means
        ####### http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/CMG/CMGTools/RootTools/python/physicsobjects/HTauTauElectron.py?revision=1.10&view=markup

        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name
                                   or "W" in self.cfg_comp.name
                                   and not "WW" in self.cfg_comp.name
                                   and not "WZ" in self.cfg_comp.name):
            event.NUP = self.mchandles['source'].product().hepeup().NUP
        else:
            event.NUP = -1

        event.genMatched = None
        if self.cfg_comp.isMC and ("DY" in self.cfg_comp.name
                                   or "Higgs" in self.cfg_comp.name):
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)
            leg1DeltaR, leg2DeltaR = event.diLepton.match(event.genParticles)
            event.leg1DeltaR = leg1DeltaR
            event.leg2DeltaR = leg2DeltaR
            if leg1DeltaR>-1 and leg1DeltaR < 0.1 and \
               leg2DeltaR>-1 and leg2DeltaR < 0.1:
                event.genMatched = True
            else:
                event.genMatched = False
            event.isPhoton = False
            event.isElectron = False
            for gen in genParticles:
                if abs(gen.pdgId()) == 15 and abs(
                        gen.mother().pdgId()) == 23 and (
                            gen.mother().mass() < 80
                            or gen.mother().mass() > 100):
                    event.isPhoton = True
                if abs(gen.pdgId()) == 13 and abs(gen.mother().pdgId()) == 23:
                    event.isMuon = True
                if abs(gen.pdgId()) == 11 and abs(gen.mother().pdgId()) == 23:
                    event.isElectron = True
                if abs(gen.pdgId()) in [23, 25, 35, 36, 37]:
                    event.genMass = gen.mass()
                if abs(gen.pdgId()) in [23]:
                    event.hasW = True
                if abs(gen.pdgId()) in [24]:
                    event.hasZ = True
        if self.cfg_comp.isMC and "W" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)
            genTaus = []
            event.genMatched = False
            event.genMatchedElectron = False
            event.genMatchedMuon = False
            for gen in genParticles:
                if abs(gen.pdgId()) in [11, 13, 15] and abs(
                        gen.mother().pdgId()) == 24:  # W -> tau nu
                    genTaus.append(gen)
            if len(genTaus) >= 1:
                dR2leg1Min, event.diLepton.leg1Gen = (float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = (float('inf'), None)
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(),
                                      event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi())
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(),
                                      event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi())
                    if dR2leg1 < dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 < dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt(dR2leg1Min)
                    leg2DeltaR = math.sqrt(dR2leg2Min)
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==11:
                        event.genMatchedElectron = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==13:
                        event.genMatchedMuon = True
                    if ((leg1DeltaR>-1 and leg1DeltaR < 0.1) or \
                        (leg2DeltaR>-1 and leg2DeltaR < 0.1)) and abs(genTau.pdgId())==15:
                        event.genMatched = True
            event.isElectron = False
            event.isMuon = False
            event.isTau = False
            for gen in genParticles:
                if abs(gen.pdgId()) == 11 and abs(gen.mother().pdgId()) == 24:
                    event.isElectron = True
                if abs(gen.pdgId()) == 13 and abs(gen.mother().pdgId()) == 24:
                    event.isMuon = True
                if abs(gen.pdgId()) == 15 and abs(gen.mother().pdgId()) == 24:
                    event.isTau = True
        if self.cfg_comp.isMC and "TTJets" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)
            genTaus = []
            event.genMatched = 0
            event.genMatchedElectron = 0
            event.genMatchedMuon = 0
            for gen in genParticles:
                if abs(gen.pdgId()) in [11, 13, 15] and abs(
                        gen.mother().pdgId()) == 24:  # W -> tau nu
                    genTaus.append(gen)
            if len(genTaus) >= 1:
                dR2leg1Min, event.diLepton.leg1Gen = (float('inf'), None)
                dR2leg2Min, event.diLepton.leg2Gen = (float('inf'), None)
                for genTau in genTaus:
                    dR2leg1 = deltaR2(event.diLepton.leg1().eta(),
                                      event.diLepton.leg1().phi(),
                                      genTau.eta(), genTau.phi())
                    dR2leg2 = deltaR2(event.diLepton.leg2().eta(),
                                      event.diLepton.leg2().phi(),
                                      genTau.eta(), genTau.phi())
                    if dR2leg1 < dR2leg1Min:
                        dR2leg1Min, event.diLepton.leg1Gen = (dR2leg1, genTau)
                    if dR2leg2 < dR2leg2Min:
                        dR2leg2Min, event.diLepton.leg2Gen = (dR2leg2, genTau)
                    leg1DeltaR = math.sqrt(dR2leg1Min)
                    leg2DeltaR = math.sqrt(dR2leg2Min)
                    if (leg1DeltaR > -1 and leg1DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 11:
                        event.genMatchedElectron += 1
                    if (leg1DeltaR > -1 and leg1DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 13:
                        event.genMatchedMuon += 1
                    if (leg1DeltaR > -1 and leg1DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 15:
                        event.genMatched += 1
                    if (leg2DeltaR > -1 and leg2DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 11:
                        event.genMatchedElectron += 1
                    if (leg2DeltaR > -1 and leg2DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 13:
                        event.genMatchedMuon += 1
                    if (leg2DeltaR > -1 and leg2DeltaR < 0.1) and abs(
                            genTau.pdgId()) == 15:
                        event.genMatched += 1
            event.isElectron = 0
            event.isMuon = 0
            event.isTau = 0
            for gen in genParticles:
                if abs(gen.pdgId()) == 11 and abs(gen.mother().pdgId()) == 24:
                    event.isElectron += 1
                if abs(gen.pdgId()) == 13 and abs(gen.mother().pdgId()) == 24:
                    event.isMuon += 1
                if abs(gen.pdgId()) == 15 and abs(gen.mother().pdgId()) == 24:
                    event.isTau += 1
        if self.cfg_comp.isMC and "QCD" in self.cfg_comp.name:
            generator = self.mchandles['generator'].product()
            event.generatorWeight = generator.weight()
            event.eventWeight *= event.generatorWeight

        if self.cfg_comp.isMC and "HiggsGGH" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map(GenParticle, genParticles)
            higgsPt = -1
            for gen in genParticles:
                if abs(gen.pdgId()) == 25:
                    higgsPt = gen.pt()
                    break
            event.higgsPtWeightNom = self.higgsPtWeightHistogramNom.GetBinContent(
                self.higgsPtWeightHistogramNom.FindBin(higgsPt))
            event.higgsPtWeightUp = self.higgsPtWeightHistogramUp.GetBinContent(
                self.higgsPtWeightHistogramUp.FindBin(higgsPt))
            event.higgsPtWeightDown = self.higgsPtWeightHistogramDown.GetBinContent(
                self.higgsPtWeightHistogramDown.FindBin(higgsPt))
        else:
            event.higgsPtWeightNom = 1.
            event.higgsPtWeightUp = 1.
            event.higgsPtWeightDown = 1.

        ## third lepton veto
        if len(event.muons) > 0 + len(event.electrons) > 0:  ## FOR SYNCHING!!!
            return False

        if "DY" in self.cfg_comp.name or "Higgs" in self.cfg_comp.name or self.cfg_comp.isEmbed:
            event.isRealTau = 1
        else:
            event.isRealTau = 0

        if not hasattr(event, 'NJetWeight'):
            event.NJetWeight = 1.

        #event.name = self.cfg_comp.name
        #import pdb ; pdb.set_trace()
        event.metsig = self.handles['metSig'].product()

        return True
Esempio n. 23
0
    def process(self, iEvent, event):
        
        self.readCollections( iEvent )
        cmgJets = self.handles['jets'].product()

        print 'cmgJets = ', len(cmgJets)

        allJets = []
        event.jets = []
        event.bJets = []
        event.cleanJets = []
        event.cleanBJets = []

#        import pdb; pdb.set_trace();

        leptons = []
        if hasattr(event, 'selectedLeptons'):
            leptons = event.selectedLeptons
#        elif hasattr(event, 'muoncand'):
##            leptons = event.muoncand + event.electroncand + event.taucand
#            leptons = event.muon + event.electron + event.tau
#            print '# of leptons = ', len(leptons)

        genJets = None
        if self.cfg_comp.isMC:
            genJets = map( GenJet, self.mchandles['genJets'].product() ) 
            
        for cmgJet in cmgJets:
            jet = Jet( cmgJet )
            allJets.append( jet )
            if self.cfg_comp.isMC and hasattr( self.cfg_comp, 'jetScale'):
                scale = random.gauss( self.cfg_comp.jetScale,
                                      self.cfg_comp.jetSmear )
                jet.scaleEnergy( scale )
            if genJets:
                # Use DeltaR = 0.25 matching like JetMET
                pairs = matchObjectCollection( [jet], genJets, 0.25*0.25)
                if pairs[jet] is None:
                    pass
                    #jet.genJet = None
                else:
                    jet.genJet = pairs[jet] 
                # print jet, jet.genJet

            #Add JER correction for MC jets. Requires gen-jet matching. 
            if self.cfg_comp.isMC and hasattr(self.cfg_ana, 'jerCorr') and self.cfg_ana.jerCorr:
                self.jerCorrection(jet)

            #Add JES correction for MC jets.
            if self.cfg_comp.isMC and hasattr(self.cfg_ana, 'jesCorr'):
                self.jesCorrection(jet, self.cfg_ana.jesCorr)
            if self.testJet( jet ):
                event.jets.append(jet)
            if self.testBJet(jet):
                event.bJets.append(jet)


                
        self.counters.counter('jets').inc('all events')

#        print 'check =', len(event.muon), len(event,electron), len(event.tau)


#        if isinstance(event.muoncand, list):
#            event.cleanBJets, dummy = cleanObjectCollection( event.bJets,
#                                                             masks = event.muoncand,
#                                                             deltaRMin = 0.4 )
#
#            event.cleanJets, dummy = cleanObjectCollection( event.jets,
#                                                            masks = event.muoncand,
#                                                            deltaRMin = 0.4 )
#
#        else:
#            event.cleanBJets, dummy = cleanObjectCollection( event.bJets,
#                                                             masks = [event.muoncand],
#                                                             deltaRMin = 0.4 )
#            
#            event.cleanJets, dummy = cleanObjectCollection( event.jets,
#                                                            masks = [event.muoncand],
#                                                            deltaRMin = 0.4 )
#
#        if isinstance(event.electroncand, list):
#            event.cleanBJets, dummy = cleanObjectCollection( event.cleanBJets,
#                                                             masks = event.electroncand,
#                                                             deltaRMin = 0.4 )
#
#            event.cleanJets, dummy = cleanObjectCollection( event.cleanJets,
#                                                            masks = event.electroncand,
#                                                            deltaRMin = 0.4 )
#
#        else:
#            event.cleanBJets, dummy = cleanObjectCollection( event.cleanBJets,
#                                                             masks = [event.electroncand],
#                                                             deltaRMin = 0.4 )
#            
#            
#            event.cleanJets, dummy = cleanObjectCollection( event.cleanJets,
#                                                            masks = [event.electroncand],
#                                                            deltaRMin = 0.4 )
#
#
#        if isinstance(event.taucand, list):
#            event.cleanBJets, dummy = cleanObjectCollection( event.cleanBJets,
#                                                             masks = event.taucand,
#                                                             deltaRMin = 0.4 )
#
#            event.cleanJets, dummy = cleanObjectCollection( event.cleanJets,
#                                                            masks = event.taucand,
#                                                            deltaRMin = 0.4 )
#
#        else:
#            event.cleanBJets, dummy = cleanObjectCollection( event.cleanBJets,
#                                                             masks = [event.taucand],
#                                                             deltaRMin = 0.4 )
#            
#            
#            event.cleanJets, dummy = cleanObjectCollection( event.cleanJets,
#                                                            masks = [event.taucand],
#                                                            deltaRMin = 0.4 )


        
        pairs = matchObjectCollection( leptons, allJets, 0.5*0.5)


        # associating a jet to each lepton
        for lepton in leptons:
            jet = pairs[lepton]
            if jet is None:
                lepton.jet = lepton
            else:
                lepton.jet = jet

        # associating a leg to each clean jet
        invpairs = matchObjectCollection( event.cleanJets, leptons, 99999. )
        for jet in event.cleanJets:
            leg = invpairs[jet]
            jet.leg = leg

        for jet in event.cleanJets:
            jet.matchGenParton=999.0

        if self.cfg_comp.isMC and "BB" in self.cfg_comp.name:
            genParticles = self.mchandles['genParticles'].product()
            event.genParticles = map( GenParticle, genParticles)
            for gen in genParticles:
                if abs(gen.pdgId())==5 and gen.mother() and abs(gen.mother().pdgId())==21:
                    for jet in event.cleanJets:
                        dR=deltaR2(jet.eta(), jet.phi(), gen.eta(), gen.phi() )
                        if dR<jet.matchGenParton:
                            jet.matchGenParton=dR

        event.jets30 = [jet for jet in event.jets if jet.pt()>30]
        event.cleanJets30 = [jet for jet in event.cleanJets if jet.pt()>30]
        
#        if len( event.jets30 )>=2:
#            self.counters.counter('jets').inc('at least 2 good jets')
               
#        if len( event.cleanJets30 )>=2:
#            self.counters.counter('jets').inc('at least 2 clean jets')

        event.cleanJets = event.jets
        event.cleanBJets = event.bJets

#        print 'cleanJets = ', len(event.jets)
#        print 'clean_bJets = ', len(event.bJets)

#        if len(event.bJets)>0:
#        if len(event.cleanBJets)>0:
#            import pdb; pdb.set_trace()
#            return False

        self.counters.counter('jets').inc('No b jets')
        return True