예제 #1
0
def fillDiLepton(tree, diLepton):
    fill(tree, 'visMass', diLepton.mass())
    fill(tree, 'svfitMass', diLepton.massSVFit())
    fill(tree, 'pZetaMET', diLepton.pZetaMET())
    fill(tree, 'pZetaVis', diLepton.pZetaVis())
    fill(tree, 'pZetaDisc', diLepton.pZetaDisc())
    fill(tree, 'mt', diLepton.mTLeg2())
    fill(tree, 'mtleg1', diLepton.mTLeg1())
    fill(tree, 'met', diLepton.met().pt())
    fill(tree, 'metphi', diLepton.met().phi())

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

    l1eta = diLepton.leg1().eta()
    l2eta = diLepton.leg2().eta()
    l1phi = diLepton.leg1().phi()
    l2phi = diLepton.leg2().phi()
    metphi = diLepton.met().phi()
    fill(tree, 'deltaPhiL1L2', deltaPhi(l1phi, l2phi))
    fill(tree, 'deltaEtaL1L2', abs(l1eta - l2eta))
    fill(tree, 'deltaRL1L2', deltaR(l1eta, l1phi, l2eta, l2phi))
    fill(tree, 'deltaPhiL1MET', deltaPhi(l1phi, metphi))
    fill(tree, 'deltaPhiL2MET', deltaPhi(l2phi, metphi))
예제 #2
0
 def fHiggsVars( pName, particle, classifierValue ):
     fill('{pName}Mass'.format(pName=pName),particle.mass())
     fill('{pName}Pt'.format(pName=pName),particle.pt())
     fill('{pName}Energy'.format(pName=pName),particle.energy())
     fill('{pName}Eta'.format(pName=pName),particle.eta())
     fill('{pName}Phi'.format(pName=pName),particle.phi())
     fill('{pName}DeltaPtZ'.format(pName=pName),abs(particle.leg1().pt() - particle.leg2().pt()))
     fill('{pName}DeltaPhiZ'.format(pName=pName),deltaPhi(particle.leg1().phi(), particle.leg2().phi()))
     fill('{pName}DeltaPhiZJ1'.format(pName=pName),deltaPhi(particle.leg1().phi(), particle.leg2().leg1().phi()))
     fill('{pName}DeltaPhiZJ2'.format(pName=pName),deltaPhi(particle.leg1().phi(), particle.leg2().leg2().phi()))
     fill('{pName}SumAbsEtaJ1J2'.format(pName=pName),abs(particle.leg2().leg1().eta())+abs(particle.leg2().leg2().eta()))
     fill('{pName}costhetastar'.format(pName=pName),particle.costhetastar())
     fill('{pName}helphi'.format(pName=pName),particle.helphi())
     fill('{pName}helphiZl1'.format(pName=pName), particle.helphiZl1())
     fill('{pName}helphiZl2'.format(pName=pName), particle.helphiZl2())
     fill('{pName}helcosthetaZl1'.format(pName=pName), particle.helcosthetaZl1())
     fill('{pName}helcosthetaZl2'.format(pName=pName), particle.helcosthetaZl2())
     fill('{pName}phistarZl1'.format(pName=pName), particle.phistarZl1())
     fill('{pName}phistarZl2'.format(pName=pName), particle.phistarZl2())
     if particle.vbfptr().isNonnull():
       fill('{pName}detaVBF'.format(pName=pName), abs(particle.vbfptr().leg1().eta()-particle.vbfptr().leg2().eta()))
       fill('{pName}dphiVBF'.format(pName=pName), deltaPhi(particle.vbfptr().leg1().phi(), particle.vbfptr().leg2().phi()))
       fill('{pName}massVBF'.format(pName=pName), particle.vbfptr().mass())     
       #
     fill('{pName}Classifier'.format(pName=pName), classifierValue)
예제 #3
0
파일: VBF.py 프로젝트: aehart/cmssw
    def __init__(self, jets, diLepton, vbfMvaCalc, cjvPtCut):
        '''jets: jets cleaned from the diLepton legs.
        diLepton: the di-tau, for example. Necessary to compute input variables for MVA selection
        '''
        self.cjvPtCut = cjvPtCut
        self.vbfMvaCalc = vbfMvaCalc
        self.jets = jets
        # the MET is taken from the di-lepton, because it can depend on it
        # e.g. recoil corrections, mva met
        self.met = diLepton.met()
        self.leadJets = jets[:2] # taking first 2 jets (leading ones)
        self.otherJets = jets[2:]
        self.centralJets = self.findCentralJets( self.leadJets, self.otherJets )

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

        # below, the variables for the MVA selection
        # delta phi
        self.dphi = deltaPhi(self.leadJets[0].phi(), self.leadJets[1].phi())
        dijetp4 = self.leadJets[0].p4() + self.leadJets[1].p4()
        # mass of the di-jet system
        self.mjj = dijetp4.M()
        # pt of di-jet system
        self.dijetpt = dijetp4.pt()
        # phi of di-jet system
        self.dijetphi = dijetp4.phi()
        # higgs momentum (defined as the di-lepton momentum + the met momentum)
        # don't access longitudinal quantities!
        self.higgsp4 = diLepton.p4() + self.met.p4()
        # delta phi between dijet system and higgs system
        self.dphidijethiggs = deltaPhi( self.dijetphi, self.higgsp4.phi() )
        # ? 
        visDiLepton = diLepton.leg1 ().p4 () + diLepton.leg2 ().p4 ()
        self.visjeteta = min (
            abs (self.leadJets[0].eta () - visDiLepton.eta ()), 
            abs (self.leadJets[1].eta () - visDiLepton.eta ()))
        # visible higgs pt = di-lepton pt
        self.ptvis = visDiLepton.pt()
        ## self.ptvis = diLepton.pt()
        # new VBF MVA, based on 4 variables
        if self.vbfMvaCalc is not None:
            self.mva = self.vbfMvaCalc.val( self.mjj,
                                            abs(self.deta),
                                            self.visjeteta,
                                            self.ptvis )
        else:
            self.mva = -99.
예제 #4
0
    def calculateJetVars(self, fourLepton, jets, cleanDR=0.5):
        #Apply ID
        idJets = filter(lambda x: x.looseJetId() and x.passPuJetId('full', 2),
                        jets)

        #Cross clean from leptons
        cleanedJets = filter(lambda x: deltaR(x.eta(),x.phi(),fourLepton.leg1.leg1.eta(),fourLepton.leg1.leg1.phi())>cleanDR and \
                             deltaR(x.eta(),x.phi(),fourLepton.leg1.leg2.eta(),fourLepton.leg1.leg2.phi())>cleanDR and \
                             deltaR(x.eta(),x.phi(),fourLepton.leg2.leg1.eta(),fourLepton.leg2.leg1.phi())>cleanDR and \
                             deltaR(x.eta(),x.phi(),fourLepton.leg2.leg2.eta(),fourLepton.leg2.leg2.phi())>cleanDR,idJets)

        bJets = filter(
            lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags') >
            0.224, cleanedJets)
        jetVars = dict()
        jetVars['nJets'] = len(cleanedJets)

        jetVars['nBJets'] = len(bJets)
        jetVars['nBJetsTight'] = len(
            filter(
                lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags') >
                0.679, cleanedJets))
        ht = 0
        if len(bJets) >= 2:
            jetVars['Mbb'] = (bJets[0].p4() + bJets[1].p4()).M()
        else:
            jetVars['Mbb'] = -99

        for jet in cleanedJets:
            ht = ht + jet.pt()
        jetVars['HT'] = ht
        if len(cleanedJets) > 2:
            jetVars['Mjjj'] = (cleanedJets[0].p4() + cleanedJets[1].p4() +
                               cleanedJets[2].p4()).M()
        else:
            jetVars['Mjjj'] = -99.

        if len(cleanedJets) > 1:
            jetVars['dEta'] = cleanedJets[0].eta() - cleanedJets[1].eta()
            jetVars['dPhi'] = deltaPhi(cleanedJets[0].phi(),
                                       cleanedJets[1].phi())
            jetVars['Mjj'] = (cleanedJets[0].p4() + cleanedJets[1].p4()).M()
            jetVars['Ptjj'] = (cleanedJets[0].p4() + cleanedJets[1].p4()).Pt()
        else:
            jetVars['dEta'] = -99
            jetVars['dPhi'] = -99
            jetVars['Mjj'] = -99
            jetVars['Ptjj'] = -99

        if len(cleanedJets) > 0:
            #Add leading jet variables
            highestJet = max(cleanedJets, key=lambda x: x.pt())
            jetVars['leadingPt'] = highestJet.pt()
            jetVars['leadingEta'] = highestJet.eta()
        else:
            jetVars['leadingPt'] = -99.
            jetVars['leadingEta'] = -99.

        fourLepton.jets = jetVars
예제 #5
0
    def __init__(self, jets, diLepton, vbfMvaCalc, cjvPtCut):
        '''jets: jets cleaned from the diLepton legs.
        diLepton: the di-tau, for example. Necessary to compute input variables for MVA selection
        '''
        self.cjvPtCut = cjvPtCut
        self.vbfMvaCalc = vbfMvaCalc
        self.jets = jets
        # the MET is taken from the di-lepton, because it can depend on it
        # e.g. recoil corrections, mva met
        self.met = diLepton.met()
        self.leadJets = jets[:2]  # taking first 2 jets (leading ones)
        self.otherJets = jets[2:]
        self.centralJets = self.findCentralJets(self.leadJets, self.otherJets)

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

        # below, the variables for the MVA selection
        # delta phi
        self.dphi = deltaPhi(self.leadJets[0].phi(), self.leadJets[1].phi())
        dijetp4 = self.leadJets[0].p4() + self.leadJets[1].p4()
        # mass of the di-jet system
        self.mjj = dijetp4.M()
        # pt of di-jet system
        self.dijetpt = dijetp4.pt()
        # phi of di-jet system
        self.dijetphi = dijetp4.phi()
        # higgs momentum (defined as the di-lepton momentum + the met momentum)
        # don't access longitudinal quantities!
        self.higgsp4 = diLepton.p4() + self.met.p4()
        # delta phi between dijet system and higgs system
        self.dphidijethiggs = deltaPhi(self.dijetphi, self.higgsp4.phi())
        # ?
        visDiLepton = diLepton.leg1().p4() + diLepton.leg2().p4()
        self.visjeteta = min(abs(self.leadJets[0].eta() - visDiLepton.eta()),
                             abs(self.leadJets[1].eta() - visDiLepton.eta()))
        # visible higgs pt = di-lepton pt
        self.ptvis = visDiLepton.pt()
        ## self.ptvis = diLepton.pt()
        # new VBF MVA, based on 4 variables
        if self.vbfMvaCalc is not None:
            self.mva = self.vbfMvaCalc.val(self.mjj, abs(self.deta),
                                           self.visjeteta, self.ptvis)
        else:
            self.mva = -99.
예제 #6
0
    def calculateJetVars(self,fourLepton,jets,cleanDR = 0.5):
        #Apply ID
        idJets = filter(lambda x:x.looseJetId() and  x.passPuJetId('full', 2),jets) 

        #Cross clean from leptons
        cleanedJets = filter(lambda x: deltaR(x.eta(),x.phi(),fourLepton.leg1.leg1.eta(),fourLepton.leg1.leg1.phi())>cleanDR and \
                             deltaR(x.eta(),x.phi(),fourLepton.leg1.leg2.eta(),fourLepton.leg1.leg2.phi())>cleanDR and \
                             deltaR(x.eta(),x.phi(),fourLepton.leg2.leg1.eta(),fourLepton.leg2.leg1.phi())>cleanDR and \
                             deltaR(x.eta(),x.phi(),fourLepton.leg2.leg2.eta(),fourLepton.leg2.leg2.phi())>cleanDR,idJets)


        bJets = filter(lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags')>0.224,cleanedJets)
        jetVars=dict()
        jetVars['nJets']=len(cleanedJets)

        jetVars['nBJets']=len(bJets)
        jetVars['nBJetsTight']=len(filter(lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags')>0.679,cleanedJets))
        ht=0
        if len(bJets) >=2:
            jetVars['Mbb'] = (bJets[0].p4()+bJets[1].p4()).M()
        else:
            jetVars['Mbb']=-99
            
        for jet in cleanedJets:
            ht = ht + jet.pt()
        jetVars['HT'] = ht
        if len(cleanedJets)>2:
            jetVars['Mjjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()+cleanedJets[2].p4()).M()
        else:    
            jetVars['Mjjj'] = -99.

        if len(cleanedJets)>1:
            jetVars['dEta'] = cleanedJets[0].eta()-cleanedJets[1].eta()
            jetVars['dPhi'] = deltaPhi(cleanedJets[0].phi(),cleanedJets[1].phi())
            jetVars['Mjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()).M()
            jetVars['Ptjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()).Pt()
        else:
            jetVars['dEta'] = -99
            jetVars['dPhi'] = -99
            jetVars['Mjj'] = -99
            jetVars['Ptjj'] = -99

        if  len(cleanedJets)>0:
            #Add leading jet variables    
            highestJet = max(cleanedJets,key=lambda x:x.pt())
            jetVars['leadingPt']=highestJet.pt()
            jetVars['leadingEta']=highestJet.eta()
        else:
            jetVars['leadingPt']=-99.
            jetVars['leadingEta']=-99.
            
            
            
            
        fourLepton.jets = jetVars
예제 #7
0
def fillDiLepton(tree, diLepton):
    fill(tree, 'visMass', diLepton.mass())
    fill(tree, 'svfitMass', diLepton.massSVFit())
    fill(tree, 'pZetaMET', diLepton.pZetaMET())
    fill(tree, 'pZetaVis', diLepton.pZetaVis())
    fill(tree, 'pZetaDisc', diLepton.pZetaDisc())
    fill(tree, 'mt', diLepton.mTLeg2())
    fill(tree, 'met', diLepton.met().pt())

    pthiggs = (diLepton.leg1().p4()+diLepton.leg2().p4()+diLepton.met().p4()).pt()
    fill(tree, 'pthiggs', pthiggs)
    
    l1eta = diLepton.leg1().eta()
    l2eta = diLepton.leg2().eta()
    l1phi = diLepton.leg1().phi()
    l2phi = diLepton.leg2().phi()
    metphi = diLepton.met().phi()
    fill(tree, 'deltaPhiL1L2', deltaPhi(l1phi, l2phi))
    fill(tree, 'deltaEtaL1L2', abs(l1eta-l2eta))
    fill(tree, 'deltaRL1L2', deltaR(l1eta, l1phi, l2eta, l2phi))
    fill(tree, 'deltaPhiL1MET', deltaPhi(l1phi, metphi))
    fill(tree, 'deltaPhiL2MET', deltaPhi(l2phi, metphi))
 def fParticleVars( pName, particle ):
     fill('{pName}Mass'.format(pName=pName), particle.mass() )
     fill('{pName}Pt'.format(pName=pName), particle.pt() )
     fill('{pName}Energy'.format(pName=pName), particle.energy() )
     fill('{pName}Eta'.format(pName=pName), particle.eta() )
     fill('{pName}Phi'.format(pName=pName), particle.phi() )
     #fill('{pName}Charge'.format(pName=pName), particle.charge() )
     if particle.numberOfDaughters() > 1:
       fill('{pName}deltaEtaDecay'.format(pName=pName), abs(particle.daughter(0).eta() - particle.daughter(1).eta() ))
       fill('{pName}deltaPhiDecay'.format(pName=pName), deltaPhi(particle.daughter(0).phi(), particle.daughter(1).phi() ))
       fill('{pName}deltaRDecay'.format(pName=pName), deltaR(particle.daughter(0).eta(), 
                                                             particle.daughter(0).phi(), 
                                                             particle.daughter(1).eta(), 
                                                             particle.daughter(1).phi() ))
       if (pName == 'jj'):                                                      
         fill('{pName}btag1'.format(pName=pName), particle.daughter(0).btag(7)) 
         fill('{pName}btag2'.format(pName=pName), particle.daughter(1).btag(7))                                                       
예제 #9
0
    def photonPreFilter(self, photon):
        '''Generic cross cleaning of photons'''
        if self.verbose:
            print 'prefilter gamma', photon.pt(), photon.eta(), photon.phi()

        for leg in self.leptons:
            DR = deltaR(photon.eta(), photon.phi(), leg.eta(), leg.phi())
            Deta = abs(photon.eta() - leg.eta())
            Dphi = abs(deltaPhi(photon.phi(), leg.phi()))
            if self.verbose:
                print '---->vs leg', leg.pdgId(), self.electronID(
                    leg), leg.pt(), leg.eta(), leg.phi(), '|', DR, Deta, Dphi

            if abs(leg.pdgId()) == 11 and self.electronID(leg):
                if DR < self.cfg.vetoElectronDR:
                    return False
                if Deta < self.cfg.vetoElectronDEta and Dphi < self.cfg.vetoElectronDPhi:
                    return False

        return True
예제 #10
0
파일: FSRRecovery.py 프로젝트: anantoni/CMG
    def photonPreFilter(self,photon):
        '''Generic cross cleaning of photons''' 
        if self.verbose:
            print 'prefilter gamma',photon.pt(),photon.eta(),photon.phi()

        for leg in self.leptons:
            DR = deltaR(photon.eta(),photon.phi(),leg.eta(),leg.phi())
            Deta = abs(photon.eta()-leg.eta())
            Dphi = abs(deltaPhi(photon.phi(),leg.phi()))
            if self.verbose:
                print '---->vs leg',leg.pdgId(),self.electronID(leg),leg.pt(),leg.eta(),leg.phi(),'|',DR,Deta,Dphi
                
                
            if  abs(leg.pdgId())==11 and self.electronID(leg):
                if DR<self.cfg.vetoElectronDR:
                    return False
                if Deta <self.cfg.vetoElectronDEta and  Dphi<self.cfg.vetoElectronDPhi:
                    return False
                

        return True
예제 #11
0
def dPhi(x,y):
    return deltaPhi(x.phi() if hasattr(x,'phi') else x, 
                     y.phi() if hasattr(y,'phi') else y)
예제 #12
0
    def process(self, iEvent, event):
        self.readCollections( iEvent )

        self.buildMCinfo(iEvent)

        eventNumber = iEvent.eventAuxiliary().id().event()
        myEvent = Event(event.iEv)
        setattr(event, self.name, myEvent)
        event = myEvent
        event.genVBFdeltaPhi = -99.
        #if len(self.vbfjets) != 2:
        #  print "Warning: ",len(self.vbfjets)," VBF partons"
        #if len(self.vbfjets) > 2:
        #  event.genVBFdeltaPhi = deltaPhi(self.vbfjets[0].phi(), self.vbfjets[1].phi())
        event.step=0  
        
        event.alljets = []
        event.leadingmuons = []
        event.leadingelectrons = []
        event.dimuonmass = -1
        event.dielectronmass = -1
        event.deltaeta = -1;
        event.deltaphi = -99;
        event.mjj = -1;
        event.truezhad = []
        if not self.handles['electrons'].isValid():
          #print "invalid collection!"
          return
       
        #iEvent is of type ChainEvent
        #trignames = iEvent.object().triggerNames(self.handles['trigger'].product())
        #for i in range(self.handles['trigger'].product().size()):
        #    print trignames.triggerName(i)
        trigger = iEvent.object().triggerResultsByName('HLT') #self.handles['trigger'].product()
        event.dimuonTrigger = 1 if trigger.accept('HLT_Mu13_Mu8_v17') else 0
        #print "dimuon: %d" %event.dimuonTrigger
        event.dielectronTrigger = 1 if trigger.accept('HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v17')  else 0
        #print "dielectron: %d" %event.dielectronTrigger
        
        event.hmumujj_mcmatch = []
        event.hjj_mcmatch = []
        event.hmumu_mcmatch = []
        event.hmumujj_nomcmatch = []
        event.hjj_nomcmatch = []
        event.hmumu_nomcmatch = []
        

        for electron in self.handles['electrons'].product():
          event.leadingelectrons.append(Electron(electron))

        event.leadingelectrons.sort(key=lambda a: a.pt(), reverse = True)
        while(len(event.leadingelectrons)>2):
          event.leadingelectrons.pop()

        for muon in self.handles['muons'].product():
          event.leadingmuons.append(Electron(muon))
            
        event.leadingmuons.sort(key=lambda a: a.pt(), reverse = True)
        while(len(event.leadingmuons)>2):
          event.leadingmuons.pop()   
        
        if len(event.leadingmuons) == 2 or len(event.leadingelectrons) == 2 :
          event.step+=1   

        if len(event.leadingmuons) == 2:
          event.dimuonmass = ( event.leadingmuons[0].p4() + event.leadingmuons[1].p4() ).mass()
          if event.dimuonmass < 70.:
            event.step+=1

        if len(event.leadingelectrons) == 2:
          event.dielectronmass = ( event.leadingelectrons[0].p4() + event.leadingelectrons[1].p4() ).mass()
          if event.dielectronmass < 70.:
            event.step+=1

        if not self.handles['jets'].isValid():
          print "invalid collection!"
          return
        for jet in self.handles['jets'].product():
          if jet.pt() > 0.:
            event.alljets.append(Jet(jet))

        event.alljets.sort(key=lambda a: a.pt(), reverse = True)
        if len(event.alljets)>=2:
          event.step+=1

        triggerjets = []
        for jet in event.alljets:
          if jet.pt() > 35.:
            triggerjets.append(Jet(jet))

        #sort triggerjets in rapidity
        triggerjets.sort(key=lambda a: a.rapidity(), reverse = True )
        if ( len(triggerjets)>=2 ):
          event.step+=1
          event.deltaeta = triggerjets[0].rapidity() - triggerjets[len(triggerjets)-1].rapidity()
          event.deltaphi = deltaPhi(triggerjets[0].phi(), triggerjets[len(triggerjets)-1].phi())
          event.mjj = ( triggerjets[0].p4() + triggerjets[len(triggerjets)-1].p4() ).mass()    

        #higgs candidates
        event.hmumujj = []
        event.heejj = []
        event.mumu = []
        event.ee = []
        event.jj = []
        
#        if self.handles['hmumujj'].isValid():
            #print "cristo."  
            #return
        if self.handles['hmumujj'].isValid() and len(self.handles['hmumujj'].product()) > 0:
          #if len(self.handles['hmumujj'].product()) != 1:
            #print "WARNING! more than one hmumujj candidates"
          hmumujj = self.handles['hmumujj'].product()[0]
          event.hmumujj.append(hmumujj)
          event.mumu.append(hmumujj.leg1())
          event.jj.append(hmumujj.leg2())

        if self.handles['heejj'].isValid() and len(self.handles['heejj'].product()) > 0:
          if len(event.hmumujj) != 0:
            print "WARNING! found and heejj when and hmumujj is already present"
          #if len(self.handles['heejj'].product()) != 1:
            #print "WARNING! more than one heejj candidates"
          heejj = self.handles['heejj'].product()[0]
          event.heejj.append(heejj)
          event.ee.append(heejj.leg1())
          event.jj.append(heejj.leg2())

        #refit the candidates
        #refit is not needed anymore, the first candidate is taken instead.   
        ## hrefit = []
##         event.truezhad = self.zhad
##         if self.handles['hmumujjnofit'].isValid() and len(self.handles['hmumujjnofit'].product()) > 0:
            
##             for candidate in self.handles['hmumujjnofit'].product():
##                 jjnofit = candidate.leg2()
##                 jet1 = jjnofit.leg1().p4()
##                 jet2 = jjnofit.leg2().p4()
##           #if len(self.zhad):
##           #  kinfitter = DiJetKinFitter("GiulioFitter", "GiulioFitter", self.zhad[0].mass())
##           #else:  

##                 kinfitter = DiJetKinFitter("GiulioFitter", "GiulioFitter", 91.1876, 5.)
##                 result = kinfitter.fit(jet1, jet2)
##                 chi2 = kinfitter.getChi2()
##                 hfit = copy.deepcopy(candidate)
##                 hfit.leg2().leg1().setP4(result.first)
##                 hfit.leg2().leg2().setP4(result.second)
##                 hfit.leg2().setP4(result.first+result.second)
##                 hfit.setP4(hfit.leg1().p4()+result.first+result.second)
##                 t = hfit, chi2
##                 hrefit.append(t)

##         hrefit.sort(key=lambda a: a[1])
        event.hbest = []
        event.deltaPhiLJ = []
        event.deltaPhiJJ  = -1
        event.deltaPhiZJ1 = -1
        event.deltaPhiZJ2 = -1
        event.deltaPhiZJ = []
                                
        if len(event.hmumujj):
          #event.hbest.append((hrefit[0])[0])
          event.hbest.append(hmumujj)  
          event.deltaPhiLJ.append( abs( deltaPhi(event.hbest[0].leg1().leg1().phi(), event.hbest[0].leg2().leg1().phi()) ) ) 
          event.deltaPhiLJ.append( abs( deltaPhi(event.hbest[0].leg1().leg1().phi(), event.hbest[0].leg2().leg2().phi()) ) ) 
          event.deltaPhiLJ.append( abs( deltaPhi(event.hbest[0].leg1().leg2().phi(), event.hbest[0].leg2().leg1().phi()) ) ) 
          event.deltaPhiLJ.append( abs( deltaPhi(event.hbest[0].leg1().leg2().phi(), event.hbest[0].leg2().leg2().phi()) ) )
          event.deltaPhiZJ.append( abs( deltaPhi(event.hbest[0].leg1().phi(), event.hbest[0].leg2().leg1().phi()) ) )
          event.deltaPhiZJ.append( abs( deltaPhi(event.hbest[0].leg1().phi(), event.hbest[0].leg2().leg2().phi()) ) )
          if event.hbest[0].leg2().leg1().pt() > event.hbest[0].leg2().leg2().pt():
              event.deltaPhiZJ1 = abs( deltaPhi(event.hbest[0].leg1().phi(), event.hbest[0].leg2().leg1().phi()) )
              event.deltaPhiZJ2= abs( deltaPhi(event.hbest[0].leg1().phi(), event.hbest[0].leg2().leg2().phi()) )
          else:
              event.deltaPhiZJ1= abs( deltaPhi(event.hbest[0].leg1().phi(), event.hbest[0].leg2().leg2().phi()) )
              event.deltaPhiZJ2= abs( deltaPhi(event.hbest[0].leg1().phi(), event.hbest[0].leg2().leg1().phi()) )
              
                                                                                    
        event.deltaPhiLJ.sort() 
        event.deltaPhiZJ.sort()
예제 #13
0
def dPhi(x, y):
    return deltaPhi(x.phi() if hasattr(x, 'phi') else x,
                    y.phi() if hasattr(y, 'phi') else y)
예제 #14
0
    def process(self, iEvent, event):
        self.readCollections( iEvent )

        if self.domcmatching:
          self.buildMCinfo(iEvent)
        #print self.handles['genVBF'].product().size()
        #if self.handles['vbfpairs'].isValid():
        #  print "valid"
        #  if self.handles['vbfpairs'].product().size() > 0:
        #    print "size of VBF pairs",self.handles['vbfpairs'].product().size()
        #else:
        #  print "invalid vbfpairs"

        eventNumber = iEvent.eventAuxiliary().id().event()
        myEvent = Event(event.iEv)
        setattr(event, self.name, myEvent)
        event = myEvent
        event.genVBFdeltaPhi = -99.
        #if len(self.vbfjets) != 2:
        #  print "Warning: ",len(self.vbfjets)," VBF partons"
        #if len(self.vbfjets) > 2:
        #  event.genVBFdeltaPhi = deltaPhi(self.vbfjets[0].phi(), self.vbfjets[1].phi())
        event.step=0  
        event.alljets = []
        event.leadingmuons = []
        event.highptmuons = []
        event.highptelectrons = []
        event.leadingelectrons = []
        event.dimuonmass = -1
        event.dielectronmass = -1
        event.deltaeta = -1;
        event.deltaphi = -99;
        event.mjj = -1;
        event.ht = -1
        event.iszmumu = False
        event.iszee = False
        event.mmumu = -99
        event.mee = -99
        event.myweight = 1.
        event.nvertices = -1
        event.vertices = []
        event.rho = -99
        event.truezlepmass= -1
        event.truezlep = []
        event.truezhad = []
        event.dielectronTrigger  = -1
        event.dielectronHtTrigger  = -1
        event.dimuonTrigger = -1
        event.dimuonHtTrigger = -1
        #higgs candidates
        event.hmumujj = []
        event.heejj = []
        event.mumu = []
        event.ee = []
        event.jj = []
        event.hbest = []
        event.deltaPhiLJ = []
        event.deltaPhiJJ  = -1
        event.deltaPhiZJ1 = -1
        event.deltaPhiZJ2 = -1
        event.deltaPhiZJ = [] 
        event.dimuons = []
        event.highptjets = []
        event.dijets = []
        event.dielectrons = []
        event.hmumujj_withmatchinfo = []
        event.heejj_withmatchinfo = []
        event.sortedCandidatesE = []
        event.sortedCandidatesMu = []

        #event.hmumujj_nomcmatch = []


        #if not self.handles['electrons'].isValid():
          #print "invalid collection!"
        #  return
     
        if not self.handles['PUweight'].isValid():
          return
        puw = self.handles['PUweight'].product()
        event.myweight = event.myweight*puw[0] 
        if not self.handles['vertices'].isValid():
          return
        event.nvertices=self.handles['vertices'].product().size()  
        for vertex in self.handles['vertices'].product():
            if vertex.isValid() and vertex.ndof()>4:
              event.vertices.append(vertex)
        def getSumPt(v):
          sumpt = 0
          #TODO NON RIESCO a loopare sugli iteratori del c++  
          #for t in v.tracks_:
          #  print t.pt()
          #  sumpt += t.pt()
          return sumpt
        event.vertices.sort(key=lambda a: getSumPt(a), reverse=True)       
 
        if not self.handles['rho'].isValid():
          return
        event.rho = self.handles['rho'].product()[0]  
          
########################BEGIN SELECTION PART        
        if self.cfg_ana.replicatepreselection:

          if (self.domcmatching):
          #if (True):
            if len(self.zlep) != 1:
              print "problem with true zlep, number of daughters is",len(self.zlep)
              return
            if abs(self.zlep[0].daughter(0).pdgId())==11:
              event.iszee = True
            elif abs(self.zlep[0].daughter(0).pdgId())==13:
              event.iszmumu = True

            event.truezlep = self.zlep
            event.truezhad = self.zhad
          
            event.truezlepmass = self.zlep[0].p4().mass()

          self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
          #self.counters.counter('countall').inc('All events', event.myweight)
          #self.counters.counter('countall_lowmass').inc('All events', event.myweight)
          #self.counters.counter('countall_highmass').inc('All events', event.myweight)
          if (event.iszmumu):
            self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
          if (event.iszee):
            self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          #self.counters.counter('countelectron').inc('All events', event.myweight)
          #self.counters.counter('countelectron_lowmass').inc('All events', event.myweight)
          #self.counters.counter('countelectron_highmass').inc('All events', event.myweight)
          #self.counters.counter('countmuon').inc('All events', event.myweight)
          #self.counters.counter('countmuon_lowmass').inc('All events', event.myweight)
          #self.counters.counter('countmuon_highmass').inc('All events', event.myweight) 

          #iEvent is of type ChainEvent
          trigger = iEvent.object().triggerResultsByName('HLT') #self.handles['trigger'].product()
          event.dimuonTrigger = 1 if trigger.accept('HLT_Mu13_Mu8_v17') else 0
          event.dimuonHtTrigger = 1 if trigger.accept('HLT_DoubleMu8_Mass8_PFHT175_v6') else 0
          event.dielectronTrigger = 1 if trigger.accept('HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v17')  else 0
          event.dielectronHtTrigger = 1 if trigger.accept('HLT_DoubleEle8_CaloIdT_TrkIdVL_Mass8_PFHT175_v6') else 0

          # 2 leptons, pt1>10., pt2 > 5
          for electron in self.handles['allelectrons'].product():
            event.leadingelectrons.append(Electron(electron))
            if electron.pt()>10.:
              event.highptelectrons.append(Electron(electron))

          event.leadingelectrons.sort(key=lambda a: a.pt(), reverse = True)
          event.highptelectrons.sort(key=lambda a: a.pt(), reverse = True)

          for muon in self.handles['allmuons'].product():
            event.leadingmuons.append(Muon(muon))
            if muon.pt()>10.:
              event.highptmuons.append(Muon(muon))
              
          event.leadingmuons.sort(key=lambda a: a.pt(), reverse = True)
          event.highptmuons.sort(key=lambda a: a.pt(), reverse = True)

          if ( (len(event.highptmuons)>1 and not (event.highptmuons[0].pt()<10)) and 
              self.isMuMCmatched(event.highptmuons[0]) and self.isMuMCmatched(event.highptmuons[1])) :
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)

          elif ( (len(event.highptelectrons)>1 and not (event.highptelectrons[0].pt()<10)) and
                self.isEMCmatched(event.highptelectrons[0]) and self.isEMCmatched(event.highptelectrons[1]) ):
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return  
            

          # 2 leptons, pt1>10., pt2 > 5 with id
               #(electron.getSelection("cuts_cutBasedLoose_eidEE") or \
               # electron.getSelection("cuts_cutBasedLoose_eidEB") ) and \
          event.leadingelectrons_id = []
          for electron in event.leadingelectrons:
            if (electron.getSelection("cuts_kinematics") and 
                #electron.getSelection("cuts_loosemvaid") and  
                (electron.sourcePtr().electronID("mvaNonTrigV0")>0.7) and  
                electron.getSelection("cuts_HLTPatch") ):
              event.leadingelectrons_id.append(Electron(electron))
          
          event.leadingmuons_id = []
          for muon in event.leadingmuons:
            if muon.getSelection("cuts_kinematics") and muon.getSelection("cuts_tightPFmuon"):
              event.leadingmuons_id.append(Muon(muon))

          if (len(event.leadingmuons_id)>1 and not event.leadingmuons_id[0].pt < 10 and
              self.isMuMCmatched(event.leadingmuons_id[0]) and self.isMuMCmatched(event.leadingmuons_id[1]) ):
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)

          elif  (len(event.leadingelectrons_id)>1 and not event.leadingelectrons_id[0].pt < 10 and
                self.isEMCmatched(event.leadingelectrons_id[0]) and self.isEMCmatched(event.leadingelectrons_id[1])):
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return
          
          # 2 leptons, pt1>10., pt2 > 5 with id and iso
          # N.B. now access muonPresel and electronPresel
          event.preselElectrons = []
          for electron in self.handles['electrons'].product():
            if electron.pt()>10.:
              event.preselElectrons.append(Electron(electron))

          event.preselMuons = []
          for muon in self.handles['muons'].product():
            if muon.pt() > 10:
              event.preselMuons.append(Muon(muon))
              

  #        if (len(event.preselMuons)>1 and not event.preselMuons[0].pt < 10 and 
  #            self.isMuMCmatched(event.preselMuons[0]) and self.isMuMCmatched(event.preselMuons[1])):
  #          event.step += 1
  #          self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
  #          self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
  #
  #        elif  (len(event.preselElectrons)>1 and not event.preselElectrons[0].pt < 10 and 
  #              self.isEMCmatched(event.preselElectrons[0]) and self.isEMCmatched(event.preselElectrons[1])):
  #          event.step += 1
  #          self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
  #          self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
  #        else:
  #          return
   
  #        # now dilepton mass requirement
          for mu1 in range(len(event.leadingmuons_id)):
            for mu2 in range(mu1+1,len(event.leadingmuons_id)):
               dimu = event.leadingmuons_id[mu1].p4() + event.leadingmuons_id[mu2].p4() 
  #             if dimu.mass()>12. and dimu.mass()<75. and event.preselMuons[mu1].pt() > 10.:
               event.dimuons.append(dimu)

          for e1 in range(len(event.leadingelectrons_id)):
            for e2 in range(e1+1,len(event.leadingelectrons_id)):
               die = event.leadingelectrons_id[e1].p4() + event.leadingelectrons_id[e2].p4()       
  #             if die.mass()>12. and die.mass()<75. and event.preselElectrons[e1].pt() > 10.:
               event.dielectrons.append(die) 

          #2 jets with pt > 15
          if not self.handles['jets'].isValid():
            return
          for jet in self.handles['jets'].product():
            if jet.pt()>self.cfg_ana.jetptmin and abs(jet.eta())<2.4:
              isisolated=True 
              for mu in event.leadingmuons_id:
                if deltaR(mu.p4().eta(), mu.p4().phi(), jet.p4().eta(), jet.p4().phi()) < 0.5 :
                  #print "found matching muon ", mu 
                  #print "with jet ", jet.pt(), jet.eta(), jet.phi() 
                  isisolated = False
                  break
              if isisolated:
                for e in event.leadingelectrons_id:
                  if deltaR(e.p4().eta(), e.p4().phi(), jet.p4().eta(), jet.p4().phi()) < 0.5 :
                    #print "found matching electron ", e 
                    #print "with jet ", jet.pt(), jet.eta(), jet.phi()
                    isisolated = False
                    break 
              if isisolated:
                event.highptjets.append(Jet(jet))

          #if len(event.highptjets)>1:
          if len(event.highptjets)>=self.cfg_ana.minjets:
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            if (len(event.leadingmuons_id)>1):
            #if (len(event.preselMuons)>1):
              self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
            else:
              self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return

          # 2 jets with id
          event.highptjets_id = []
          for jet in event.highptjets:
            if jet.getSelection("cuts_jetKinematics") and jet.getSelection("cuts_looseJetId"):
              event.highptjets_id.append(Jet(jet))
         
          if len(event.highptjets_id)>=self.cfg_ana.minjetsiwithid:
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            #if (len(event.preselMuons)>1):
            if (len(event.leadingmuons_id)>1):
              self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
            else:
              self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return

          # 2 jets with id and invariant mass
          passmass = False
          for jet1 in range(len(event.highptjets_id)):
            for jet2 in range(jet1+1, len(event.highptjets_id)):
              dijet = event.highptjets_id[jet1].p4() +event.highptjets_id[jet2].p4()
              if dijet.mass() > 50 and dijet.mass()<140:
                passmass = True
              event.dijets.append(dijet)

          #if len(event.dijets):
          if passmass:
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            #if (len(event.preselMuons)>1):
            if (len(event.leadingmuons_id)>1):
              self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
            else:
              self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)        
          else:   
            return
################END SELECTION PART
        
        triggerjets = []
        for jet in event.highptjets:
          if jet.pt() > 20.:
            triggerjets.append(Jet(jet))

        for jet in triggerjets:
            event.ht = event.ht + jet.pt()

        #sort triggerjets in rapidity
        triggerjets.sort(key=lambda a: a.rapidity(), reverse = True )
        if ( len(triggerjets)>=2 ):
          event.deltaeta = triggerjets[0].rapidity() - triggerjets[len(triggerjets)-1].rapidity()
          event.deltaphi = deltaPhi(triggerjets[0].phi(), triggerjets[len(triggerjets)-1].phi())
          event.mjj = ( triggerjets[0].p4() + triggerjets[len(triggerjets)-1].p4() ).mass()

        
             
 
        #do MC matching for muons
        def matchAndSort(inputCollection, outputCollection):
          for cand in inputCollection:
            decaymatched = False
            vbfmatched=False
            if self.domcmatching:
              decaymatched = cand.leg2().leg1().getSelection('cuts_genParton') and cand.leg2().leg2().getSelection('cuts_genParton')
              if cand.vbfptr().isNonnull():
               if self.cfg_ana.matchvbfgen:  
                vbfjets = self.handles['genVBF'].product()
                if (len(vbfjets))>1:
                  phileg1 = cand.vbfptr().leg1().phi()
                  etaleg1 = cand.vbfptr().leg1().eta()
                  phileg2 = cand.vbfptr().leg2().phi()
                  etaleg2 = cand.vbfptr().leg2().eta()


                  phigen1 = vbfjets[0].phi() 
                  etagen1 = vbfjets[0].eta()
                  phigen2 = vbfjets[1].phi()
                  etagen2 = vbfjets[1].eta()
##                   vbfmatched = ((deltaR(phileg1, etaleg1, phigen1, etagen1)<1 or deltaR(phileg1, etaleg1, phigen2, etagen2)<1) or
##                                (deltaR(phileg2, etaleg2, phigen1, etagen1)<1 or deltaR(phileg2, etaleg2, phigen2, etagen2)<1))

                  vbfmatched = ((deltaR(phileg1, etaleg1, phigen1, etagen1)<0.5 or deltaR(phileg1, etaleg1, phigen2, etagen2)<0.5) or
                               (deltaR(phileg2, etaleg2, phigen1, etagen1)<0.5 or deltaR(phileg2, etaleg2, phigen2, etagen2)<0.5))
                  
            if ( cand.leg2().leg1().pt()>self.cfg_ana.jetptmin and
                 cand.leg2().leg2().pt()>self.cfg_ana.jetptmin ):
              if cand.vbfptr().isNonnull():
                if ( cand.vbfptr().leg1().pt()>self.cfg_ana.jetptmin and
                     cand.vbfptr().leg2().pt()>self.cfg_ana.jetptmin ):
                  varnames = vector("string") ()
                  varnames.push_back("ZJJMass")
                  varnames.push_back("J1Pt")
                  varnames.push_back("J2Pt")
                  varnames.push_back("ZJJdeltaEtaDecay")
                  varnames.push_back("HMMJJMass>0?abs(HMMJJDeltaPhiZ):abs(HEEJJDeltaPhiZ)")
                  varnames.push_back("HMMJJMass>0?abs(HMMJJSumAbsEtaJ1J2):abs(HEEJJSumAbsEtaJ1J2)")
                  varnames.push_back("HMMJJMass>0?HMMJJcosthetastar:HEEJJcosthetastar")
                  varnames.push_back("HMMJJMass>0?HMMJJhelphi:HEEJJhelphi")
                  varnames.push_back("HMMJJMass>0?HMMJJhelphiZl1:HEEJJhelphiZl1")
                  varnames.push_back("HMMJJMass>0?HMMJJhelphiZl2:HEEJJhelphiZl2")
                  varnames.push_back("HMMJJMass>0?HMMJJphistarZl1:HEEJJphistarZl1")
                  varnames.push_back("HMMJJMass>0?HMMJJphistarZl2:HEEJJphistarZl2")
                  varnames.push_back("HMMJJMass>0?HMMJJhelcosthetaZl1:HEEJJhelcosthetaZl1")
                  varnames.push_back("HMMJJMass>0?HMMJJhelcosthetaZl2:HEEJJhelcosthetaZl2")
                  vars = vector("double") ()
                  vars.push_back(cand.leg2().mass())
                  vars.push_back(cand.leg2().leg1().pt())
                  vars.push_back(cand.leg2().leg2().pt())
                  vars.push_back(abs(cand.leg2().leg1().eta() - cand.leg2().leg2().eta()))
                  vars.push_back(abs(deltaPhi(cand.leg1().eta(), cand.leg2().eta())))
                  vars.push_back(abs(cand.leg2().leg1().eta())+abs(cand.leg2().leg2().eta()))
                  vars.push_back(cand.costhetastar())
                  vars.push_back(cand.helphi())
                  vars.push_back(cand.helphiZl1())
                  vars.push_back(cand.helphiZl2())
                  vars.push_back(cand.phistarZl1())
                  vars.push_back(cand.phistarZl2())
                  vars.push_back(cand.helcosthetaZl1())
                  vars.push_back(cand.helcosthetaZl2())
                  if self.cfg_ana.computeClassifier:         
                    classifier = ReadBDT(varnames)
                    value = classifier.GetMvaValue(vars)  
                  else: 
                    value = -1.
                  outputCollection.append([cand, decaymatched, vbfmatched,value])
          outputCollection.sort(key=lambda a: a[0].vbfptr().mass(), reverse=True)       
          if self.cfg_ana.computeClassifier:
            outputCollection.sort(key=lambda a: a[3], reverse=True)  
          #print "initial size", len(outputCollection)  
          leadingmass = outputCollection[0][0].vbfptr().mass()  
          #print "maxvbfmass is ",leadingmass  
          outputCollection = [x for x in outputCollection if x[0].vbfptr().mass() >= leadingmass]
          #print "final size",len(outputCollection)




        if self.handles['hmumujj'].isValid() and len(self.handles['hmumujj'].product()) > 0:
          matchAndSort(self.handles['hmumujj'].product(), event.hmumujj_withmatchinfo)
          #for item in event.hmumujj_withmatchinfo:
          #  if item[1] and item[2]:
          #    print "Muon match"
          #    break

        if self.handles['heejj'].isValid() and len(self.handles['heejj'].product()) > 0:

          matchAndSort(self.handles['heejj'].product(), event.heejj_withmatchinfo)
예제 #15
0
    def calculateJetObservables(self,object,jets,prefix = 'jets',cleanDR = 0.5):
        #Apply ID
        leptons = object.daughterLeptons()+object.daughterPhotons()

        cleanedJets=[]

        for jet in jets:
            if jet.pt()>30: ###Apply the real cut here to do proper systs on jet counting
#            if (jet.pt()>30 and abs(jet.eta())<4.7) or (jet.pt()>20 and abs(jet.eta())<2.1): ###Apply the real cut here to do proper systs on jet counting
                overlap=False
                for lepton in leptons:
                    if deltaR(jet.eta(),jet.phi(),lepton.eta(),lepton.phi())<cleanDR:
                        overlap=True
                        break
                if not overlap:
                    cleanedJets.append(jet)
                

        jetVars=dict()

        
        jetVars['nJets']=len(cleanedJets)

        #B tagging
        bJets = filter(lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags')>0.224,cleanedJets)
        jetVars['nBJets']=len(bJets)
        jetVars['nBJetsTight']=len(filter(lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags')>0.679,cleanedJets))

        #HT
        ht=0
        for jet in cleanedJets:
            ht = ht + jet.pt()
        jetVars['HT'] = ht



        #M bb
        if len(bJets) >=2:
            jetVars['Mbb'] = (bJets[0].p4()+bJets[1].p4()).M()
        else:
            jetVars['Mbb']=-99

        #Mjjj    
        if len(cleanedJets)>2:
            jetVars['Mjjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()+cleanedJets[2].p4()).M()
        else:    
            jetVars['Mjjj'] = -99.

        #VBF     
        if len(cleanedJets)>1:
            jetVars['dEta'] = cleanedJets[0].eta()-cleanedJets[1].eta()
            jetVars['dPhi'] = deltaPhi(cleanedJets[0].phi(),cleanedJets[1].phi())
            jetVars['Mjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()).M()
            jetVars['Ptjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()).Pt()
            jetVars['subleadingPt']=cleanedJets[1].pt()
            jetVars['subleadingEta']=cleanedJets[1].eta()
            jetVars['Fisher']=0.18*fabs(jetVars['dEta'])  +1.92e-4*jetVars['Mjj']
        
        else:
            jetVars['dEta'] = -99
            jetVars['dPhi'] = -99
            jetVars['Mjj'] = -99
            jetVars['Ptjj'] = -99
            jetVars['subleadingPt']=-99.
            jetVars['subleadingEta']=-99.
            jetVars['Fisher']=-99.

        #highest Jet    
        if  len(cleanedJets)>0:
            #Add leading jet variables    
            highestJet = max(cleanedJets,key=lambda x:x.pt())
            jetVars['leadingPt']=highestJet.pt()
            jetVars['leadingEta']=highestJet.eta()
        else:
            jetVars['leadingPt']=-99.
            jetVars['leadingEta']=-99.



        setattr(object,prefix,jetVars)    



       

                                                                                                           



                                                                                                       
예제 #16
0
    def calculateJetObservables(self,object,jets,prefix = 'jets',cleanDR = 0.5):
        #Apply ID
        leptons = object.daughterLeptons()+object.daughterPhotons()

        cleanedJets=[]

        for jet in jets:
            if jet.pt()>30: ###Apply the real cut here to do proper systs on jet counting
#            if (jet.pt()>30 and abs(jet.eta())<4.7) or (jet.pt()>20 and abs(jet.eta())<2.1): ###Apply the real cut here to do proper systs on jet counting
                overlap=False
                for lepton in leptons:
                    if deltaR(jet.eta(),jet.phi(),lepton.eta(),lepton.phi())<cleanDR:
                        overlap=True
                        break
                if not overlap:
                    cleanedJets.append(jet)
                

        jetVars=dict()

        
        jetVars['nJets']=len(cleanedJets)

        #B tagging
        bJets = filter(lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags')>0.224,cleanedJets)
        jetVars['nBJets']=len(bJets)
        jetVars['nBJetsTight']=len(filter(lambda x: x.bDiscriminator('combinedSecondaryVertexBJetTags')>0.679,cleanedJets))

        #HT
        ht=0
        for jet in cleanedJets:
            ht = ht + jet.pt()
        jetVars['HT'] = ht



        #M bb
        if len(bJets) >=2:
            jetVars['Mbb'] = (bJets[0].p4()+bJets[1].p4()).M()
        else:
            jetVars['Mbb']=-99

        #Mjjj    
        if len(cleanedJets)>2:
            jetVars['Mjjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()+cleanedJets[2].p4()).M()
        else:    
            jetVars['Mjjj'] = -99.

        #VBF     
        if len(cleanedJets)>1:
            jetVars['dEta'] = cleanedJets[0].eta()-cleanedJets[1].eta()
            jetVars['dPhi'] = deltaPhi(cleanedJets[0].phi(),cleanedJets[1].phi())
            jetVars['Mjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()).M()
            jetVars['Ptjj'] = (cleanedJets[0].p4()+cleanedJets[1].p4()).Pt()
            jetVars['subleadingPt']=cleanedJets[1].pt()
            jetVars['subleadingEta']=cleanedJets[1].eta()
            jetVars['Fisher']=0.18*fabs(jetVars['dEta'])  +1.92e-4*jetVars['Mjj']
        
        else:
            jetVars['dEta'] = -99
            jetVars['dPhi'] = -99
            jetVars['Mjj'] = -99
            jetVars['Ptjj'] = -99
            jetVars['subleadingPt']=-99.
            jetVars['subleadingEta']=-99.
            jetVars['Fisher']=-99.

        #highest Jet    
        if  len(cleanedJets)>0:
            #Add leading jet variables    
            highestJet = max(cleanedJets,key=lambda x:x.pt())
            jetVars['leadingPt']=highestJet.pt()
            jetVars['leadingEta']=highestJet.eta()
        else:
            jetVars['leadingPt']=-99.
            jetVars['leadingEta']=-99.



        setattr(object,prefix,jetVars)    
    def process(self, iEvent, event):
        self.readCollections( iEvent )

        if self.domcmatching:
          self.buildMCinfo(iEvent)
        #print self.handles['genVBF'].product().size()
        #if self.handles['vbfpairs'].isValid():
        #  print "valid"
        #  if self.handles['vbfpairs'].product().size() > 0:
        #    print "size of VBF pairs",self.handles['vbfpairs'].product().size()
        #else:
        #  print "invalid vbfpairs"

        eventNumber = iEvent.eventAuxiliary().id().event()
        if eventNumber == self.lastevent:
          return False
        self.lastevent = eventNumber  
        myEvent = Event(event.iEv)
        setattr(event, self.name, myEvent)
        event = myEvent
        event.genVBFdeltaPhi = -99.
        #if len(self.vbfjets) != 2:
        #  print "Warning: ",len(self.vbfjets)," VBF partons"
        #if len(self.vbfjets) > 2:
        #  event.genVBFdeltaPhi = deltaPhi(self.vbfjets[0].phi(), self.vbfjets[1].phi())
        event.step=0  
        event.alljets = []
        event.leadingmuons = []
        event.highptmuons = []
        event.highptelectrons = []
        event.leadingelectrons = []
        event.dimuonmass = -1
        event.dielectronmass = -1
        event.deltaeta = -1;
        event.deltaphi = -99;
        event.mjj = -1;
        event.ht = -1
        event.iszmumu = False
        event.iszee = False
        event.mmumu = -99
        event.mee = -99
        event.myweight = 1.
        event.nvertices = -1
        event.vertices = []
        event.rho = -99
        event.truezlepmass= -1
        event.truezlep = []
        event.truezhad = []
        event.dielectronTrigger  = -1
        event.dielectronHtTrigger  = -1
        event.dimuonTrigger = -1
        event.dimuonHtTrigger = -1
        #higgs candidates
        event.hmumujj = []
        event.heejj = []
        event.mumu = []
        event.ee = []
        event.jj = []
        event.hbest = []
        event.deltaPhiLJ = []
        event.deltaPhiJJ  = -1
        event.deltaPhiZJ1 = -1
        event.deltaPhiZJ2 = -1
        event.deltaPhiZJ = [] 
        event.dimuons = []
        event.highptjets = []
        event.dijets = []
        event.dielectrons = []
        event.hmumujj_withmatchinfo = []
        event.heejj_withmatchinfo = []
        event.sortedCandidatesE = []
        event.sortedCandidatesMu = []

        #event.hmumujj_nomcmatch = []


        #if not self.handles['electrons'].isValid():
          #print "invalid collection!"
        #  return
     
        if not self.handles['PUweight'].isValid():
          return
        puw = self.handles['PUweight'].product()
        event.myweight = event.myweight*puw[0] 
        if not self.handles['vertices'].isValid():
          return
        event.nvertices=self.handles['vertices'].product().size()  
        for vertex in self.handles['vertices'].product():
            if vertex.isValid() and vertex.ndof()>4:
              event.vertices.append(vertex)
        def getSumPt(v):
          sumpt = 0
          #TODO NON RIESCO a loopare sugli iteratori del c++  
          #for t in v.tracks_:
          #  print t.pt()
          #  sumpt += t.pt()
          return sumpt
        event.vertices.sort(key=lambda a: getSumPt(a), reverse=True)       
 
        if not self.handles['rho'].isValid():
          return
        event.rho = self.handles['rho'].product()[0]  
          
########################BEGIN SELECTION PART        
        if self.cfg_ana.replicatepreselection:

          if (self.domcmatching):
          #if (True):
            if len(self.zlep) != 1:
              print "problem with true zlep, number of daughters is",len(self.zlep)
              return
            if abs(self.zlep[0].daughter(0).pdgId())==11:
              event.iszee = True
            elif abs(self.zlep[0].daughter(0).pdgId())==13:
              event.iszmumu = True

            event.truezlep = self.zlep
            event.truezhad = self.zhad
          
            event.truezlepmass = self.zlep[0].p4().mass()

          self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
          #self.counters.counter('countall').inc('All events', event.myweight)
          #self.counters.counter('countall_lowmass').inc('All events', event.myweight)
          #self.counters.counter('countall_highmass').inc('All events', event.myweight)
          if (event.iszmumu):
            self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
          if (event.iszee):
            self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          #self.counters.counter('countelectron').inc('All events', event.myweight)
          #self.counters.counter('countelectron_lowmass').inc('All events', event.myweight)
          #self.counters.counter('countelectron_highmass').inc('All events', event.myweight)
          #self.counters.counter('countmuon').inc('All events', event.myweight)
          #self.counters.counter('countmuon_lowmass').inc('All events', event.myweight)
          #self.counters.counter('countmuon_highmass').inc('All events', event.myweight) 

          #iEvent is of type ChainEvent
          trigger = iEvent.object().triggerResultsByName('HLT') #self.handles['trigger'].product()
          event.dimuonTrigger = 1 if trigger.accept('HLT_Mu13_Mu8_v17') else 0
          event.dimuonHtTrigger = 1 if trigger.accept('HLT_DoubleMu8_Mass8_PFHT175_v6') else 0
          event.dielectronTrigger = 1 if trigger.accept('HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v17')  else 0
          event.dielectronHtTrigger = 1 if trigger.accept('HLT_DoubleEle8_CaloIdT_TrkIdVL_Mass8_PFHT175_v6') else 0

          # 2 leptons, pt1>10., pt2 > 5
          for electron in self.handles['allelectrons'].product():
            event.leadingelectrons.append(Electron(electron))
            if electron.pt()>10.:
              event.highptelectrons.append(Electron(electron))

          event.leadingelectrons.sort(key=lambda a: a.pt(), reverse = True)
          event.highptelectrons.sort(key=lambda a: a.pt(), reverse = True)

          for muon in self.handles['allmuons'].product():
            event.leadingmuons.append(Muon(muon))
            if muon.pt()>10.:
              event.highptmuons.append(Muon(muon))
              
          event.leadingmuons.sort(key=lambda a: a.pt(), reverse = True)
          event.highptmuons.sort(key=lambda a: a.pt(), reverse = True)

          if ( (len(event.highptmuons)>1 and not (event.highptmuons[0].pt()<10)) and 
              self.isMuMCmatched(event.highptmuons[0]) and self.isMuMCmatched(event.highptmuons[1])) :
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)

          elif ( (len(event.highptelectrons)>1 and not (event.highptelectrons[0].pt()<10)) and
                self.isEMCmatched(event.highptelectrons[0]) and self.isEMCmatched(event.highptelectrons[1]) ):
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return  
            

          # 2 leptons, pt1>10., pt2 > 5 with id
               #(electron.getSelection("cuts_cutBasedLoose_eidEE") or \
               # electron.getSelection("cuts_cutBasedLoose_eidEB") ) and \
          event.leadingelectrons_id = []
          for electron in event.leadingelectrons:
            if (electron.getSelection("cuts_kinematics") and 
                #electron.getSelection("cuts_loosemvaid") and  
                (electron.sourcePtr().electronID("mvaNonTrigV0")>0.7) and  
                electron.getSelection("cuts_HLTPatch") ):
              event.leadingelectrons_id.append(Electron(electron))
          
          event.leadingmuons_id = []
          for muon in event.leadingmuons:
            if muon.getSelection("cuts_kinematics") and muon.getSelection("cuts_tightPFmuon"):
              event.leadingmuons_id.append(Muon(muon))

          if (len(event.leadingmuons_id)>1 and not event.leadingmuons_id[0].pt < 10 and
              self.isMuMCmatched(event.leadingmuons_id[0]) and self.isMuMCmatched(event.leadingmuons_id[1]) ):
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)

          elif  (len(event.leadingelectrons_id)>1 and not event.leadingelectrons_id[0].pt < 10 and
                self.isEMCmatched(event.leadingelectrons_id[0]) and self.isEMCmatched(event.leadingelectrons_id[1])):
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return
          
          # 2 leptons, pt1>10., pt2 > 5 with id and iso
          # N.B. now access muonPresel and electronPresel
          event.preselElectrons = []
          for electron in self.handles['electrons'].product():
            if electron.pt()>10.:
              event.preselElectrons.append(Electron(electron))

          event.preselMuons = []
          for muon in self.handles['muons'].product():
            if muon.pt() > 10:
              event.preselMuons.append(Muon(muon))
              

  #        if (len(event.preselMuons)>1 and not event.preselMuons[0].pt < 10 and 
  #            self.isMuMCmatched(event.preselMuons[0]) and self.isMuMCmatched(event.preselMuons[1])):
  #          event.step += 1
  #          self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
  #          self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
  #
  #        elif  (len(event.preselElectrons)>1 and not event.preselElectrons[0].pt < 10 and 
  #              self.isEMCmatched(event.preselElectrons[0]) and self.isEMCmatched(event.preselElectrons[1])):
  #          event.step += 1
  #          self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
  #          self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
  #        else:
  #          return
   
  #        # now dilepton mass requirement
          for mu1 in range(len(event.leadingmuons_id)):
            for mu2 in range(mu1+1,len(event.leadingmuons_id)):
               dimu = event.leadingmuons_id[mu1].p4() + event.leadingmuons_id[mu2].p4() 
  #             if dimu.mass()>12. and dimu.mass()<75. and event.preselMuons[mu1].pt() > 10.:
               event.dimuons.append(dimu)

          for e1 in range(len(event.leadingelectrons_id)):
            for e2 in range(e1+1,len(event.leadingelectrons_id)):
               die = event.leadingelectrons_id[e1].p4() + event.leadingelectrons_id[e2].p4()       
  #             if die.mass()>12. and die.mass()<75. and event.preselElectrons[e1].pt() > 10.:
               event.dielectrons.append(die) 

          #2 jets with pt > 15
          if not self.handles['jets'].isValid():
            return
          for jet in self.handles['jets'].product():
            if jet.pt()>self.cfg_ana.jetptmin and abs(jet.eta())<2.4:
              isisolated=True 
              for mu in event.leadingmuons_id:
                if deltaR(mu.p4().eta(), mu.p4().phi(), jet.p4().eta(), jet.p4().phi()) < 0.5 :
                  #print "found matching muon ", mu 
                  #print "with jet ", jet.pt(), jet.eta(), jet.phi() 
                  isisolated = False
                  break
              if isisolated:
                for e in event.leadingelectrons_id:
                  if deltaR(e.p4().eta(), e.p4().phi(), jet.p4().eta(), jet.p4().phi()) < 0.5 :
                    #print "found matching electron ", e 
                    #print "with jet ", jet.pt(), jet.eta(), jet.phi()
                    isisolated = False
                    break 
              if isisolated:
                event.highptjets.append(Jet(jet))

          #if len(event.highptjets)>1:
          if len(event.highptjets)>=self.cfg_ana.minjets:
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            if (len(event.leadingmuons_id)>1):
            #if (len(event.preselMuons)>1):
              self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
            else:
              self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return

          # 2 jets with id
          event.highptjets_id = []
          for jet in event.highptjets:
            if jet.getSelection("cuts_jetKinematics") and jet.getSelection("cuts_looseJetId"):
              event.highptjets_id.append(Jet(jet))
         
          if len(event.highptjets_id)>=self.cfg_ana.minjetsiwithid:
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            #if (len(event.preselMuons)>1):
            if (len(event.leadingmuons_id)>1):
              self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
            else:
              self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)
          else:
            return

          # 2 jets with id and invariant mass
          passmass = False
          for jet1 in range(len(event.highptjets_id)):
            for jet2 in range(jet1+1, len(event.highptjets_id)):
              dijet = event.highptjets_id[jet1].p4() +event.highptjets_id[jet2].p4()
              if dijet.mass() > 50 and dijet.mass()<140:
                passmass = True
              event.dijets.append(dijet)

          #if len(event.dijets):
          if passmass:
            event.step += 1
            self.fillStandardStep('countall',event.step, event.truezlepmass, event.myweight)
            #if (len(event.preselMuons)>1):
            if (len(event.leadingmuons_id)>1):
              self.fillStandardStep('countmuon',event.step, event.truezlepmass, event.myweight)
            else:
              self.fillStandardStep('countelectron',event.step, event.truezlepmass, event.myweight)        
          else:   
            return
################END SELECTION PART
        
        triggerjets = []
        for jet in event.highptjets:
          if jet.pt() > 20.:
            triggerjets.append(Jet(jet))

        for jet in triggerjets:
            event.ht = event.ht + jet.pt()

        #sort triggerjets in rapidity
        triggerjets.sort(key=lambda a: a.rapidity(), reverse = True )
        if ( len(triggerjets)>=2 ):
          event.deltaeta = triggerjets[0].rapidity() - triggerjets[len(triggerjets)-1].rapidity()
          event.deltaphi = deltaPhi(triggerjets[0].phi(), triggerjets[len(triggerjets)-1].phi())
          event.mjj = ( triggerjets[0].p4() + triggerjets[len(triggerjets)-1].p4() ).mass()

        
               
 
        #do MC matching for muons
        def matchAndSort(inputCollection,inputLD, outputCollection):
          for i in range(len(inputCollection)):
            cand = inputCollection[i]
            cand.LD = inputLD.get(i)
            outputCollection.append( cand )
          #sort according to the VBF mass
          outputCollection.sort(key=lambda a: a.vbfptr().mass(), reverse=True)      
          #remove the non leading vbf mass
          if (len(outputCollection)):
            leadingmass = outputCollection[0].vbfptr().mass()  
            outputCollection = [x for x in outputCollection if x.vbfptr().mass() >= leadingmass]
          #sort according to the leptonic mass-91.2
          outputCollection.sort(key=lambda a: a.leg1().mass()-91.2)
          if (len(outputCollection)):
            massdiff = outputCollection[0].leg1().mass() - 91.2
            outputCollection = [x for x in outputCollection if x.leg1().mass() <= massdiff]
          #sort according to the hadronic mass
          outputCollection.sort(key=lambda a: a.leg2().mass()-91.2)
          if (len(outputCollection)):
            massdiff = outputCollection[0].leg2().mass() - 91.2
            outputCollection = [x for x in outputCollection if x.leg2().mass() <= massdiff]
            




        if self.handles['hmumujj'].isValid() and len(self.handles['hmumujj'].product()) > 0:
          matchAndSort(self.handles['hmumujj'].product(), self.handles['LDmu'].product(), event.hmumujj_withmatchinfo)
          #for item in event.hmumujj_withmatchinfo:
          #  if item[1] and item[2]:
          #    print "Muon match"
          #    break
          return True

        if self.handles['heejj'].isValid() and len(self.handles['heejj'].product()) > 0:
          matchAndSort(self.handles['heejj'].product(), self.handles['LDe'].product(), event.heejj_withmatchinfo)
          #for item in event.heejj_withmatchinfo:
          #  if item[1] and item[2]:
          #    print "Electron match"
          #    break
          return True

          print "No valid candidate found" 

        return False  
예제 #18
0
        def matchAndSort(inputCollection, outputCollection):
          for cand in inputCollection:
            decaymatched = False
            vbfmatched=False
            if self.domcmatching:
              decaymatched = cand.leg2().leg1().getSelection('cuts_genParton') and cand.leg2().leg2().getSelection('cuts_genParton')
              if cand.vbfptr().isNonnull():
               if self.cfg_ana.matchvbfgen:  
                vbfjets = self.handles['genVBF'].product()
                if (len(vbfjets))>1:
                  phileg1 = cand.vbfptr().leg1().phi()
                  etaleg1 = cand.vbfptr().leg1().eta()
                  phileg2 = cand.vbfptr().leg2().phi()
                  etaleg2 = cand.vbfptr().leg2().eta()


                  phigen1 = vbfjets[0].phi() 
                  etagen1 = vbfjets[0].eta()
                  phigen2 = vbfjets[1].phi()
                  etagen2 = vbfjets[1].eta()
##                   vbfmatched = ((deltaR(phileg1, etaleg1, phigen1, etagen1)<1 or deltaR(phileg1, etaleg1, phigen2, etagen2)<1) or
##                                (deltaR(phileg2, etaleg2, phigen1, etagen1)<1 or deltaR(phileg2, etaleg2, phigen2, etagen2)<1))

                  vbfmatched = ((deltaR(phileg1, etaleg1, phigen1, etagen1)<0.5 or deltaR(phileg1, etaleg1, phigen2, etagen2)<0.5) or
                               (deltaR(phileg2, etaleg2, phigen1, etagen1)<0.5 or deltaR(phileg2, etaleg2, phigen2, etagen2)<0.5))
                  
            if ( cand.leg2().leg1().pt()>self.cfg_ana.jetptmin and
                 cand.leg2().leg2().pt()>self.cfg_ana.jetptmin ):
              if cand.vbfptr().isNonnull():
                if ( cand.vbfptr().leg1().pt()>self.cfg_ana.jetptmin and
                     cand.vbfptr().leg2().pt()>self.cfg_ana.jetptmin ):
                  varnames = vector("string") ()
                  varnames.push_back("ZJJMass")
                  varnames.push_back("J1Pt")
                  varnames.push_back("J2Pt")
                  varnames.push_back("ZJJdeltaEtaDecay")
                  varnames.push_back("HMMJJMass>0?abs(HMMJJDeltaPhiZ):abs(HEEJJDeltaPhiZ)")
                  varnames.push_back("HMMJJMass>0?abs(HMMJJSumAbsEtaJ1J2):abs(HEEJJSumAbsEtaJ1J2)")
                  varnames.push_back("HMMJJMass>0?HMMJJcosthetastar:HEEJJcosthetastar")
                  varnames.push_back("HMMJJMass>0?HMMJJhelphi:HEEJJhelphi")
                  varnames.push_back("HMMJJMass>0?HMMJJhelphiZl1:HEEJJhelphiZl1")
                  varnames.push_back("HMMJJMass>0?HMMJJhelphiZl2:HEEJJhelphiZl2")
                  varnames.push_back("HMMJJMass>0?HMMJJphistarZl1:HEEJJphistarZl1")
                  varnames.push_back("HMMJJMass>0?HMMJJphistarZl2:HEEJJphistarZl2")
                  varnames.push_back("HMMJJMass>0?HMMJJhelcosthetaZl1:HEEJJhelcosthetaZl1")
                  varnames.push_back("HMMJJMass>0?HMMJJhelcosthetaZl2:HEEJJhelcosthetaZl2")
                  vars = vector("double") ()
                  vars.push_back(cand.leg2().mass())
                  vars.push_back(cand.leg2().leg1().pt())
                  vars.push_back(cand.leg2().leg2().pt())
                  vars.push_back(abs(cand.leg2().leg1().eta() - cand.leg2().leg2().eta()))
                  vars.push_back(abs(deltaPhi(cand.leg1().eta(), cand.leg2().eta())))
                  vars.push_back(abs(cand.leg2().leg1().eta())+abs(cand.leg2().leg2().eta()))
                  vars.push_back(cand.costhetastar())
                  vars.push_back(cand.helphi())
                  vars.push_back(cand.helphiZl1())
                  vars.push_back(cand.helphiZl2())
                  vars.push_back(cand.phistarZl1())
                  vars.push_back(cand.phistarZl2())
                  vars.push_back(cand.helcosthetaZl1())
                  vars.push_back(cand.helcosthetaZl2())
                  if self.cfg_ana.computeClassifier:         
                    classifier = ReadBDT(varnames)
                    value = classifier.GetMvaValue(vars)  
                  else: 
                    value = -1.
                  outputCollection.append([cand, decaymatched, vbfmatched,value])
          outputCollection.sort(key=lambda a: a[0].vbfptr().mass(), reverse=True)       
          if self.cfg_ana.computeClassifier:
            outputCollection.sort(key=lambda a: a[3], reverse=True)  
          #print "initial size", len(outputCollection)  
          leadingmass = outputCollection[0][0].vbfptr().mass()  
          #print "maxvbfmass is ",leadingmass  
          outputCollection = [x for x in outputCollection if x[0].vbfptr().mass() >= leadingmass]