Ejemplo n.º 1
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     electrons = Collection(event, "Electron")
     muons = Collection(event, "Muon")
     jets = Collection(event, "Jet")
     njets = len(jets)
     mht = ROOT.TLorentzVector()
     for lep in filter(self.muSel, muons):
         mht += lep.p4()
     for lep in filter(self.elSel, electrons):
         mht += lep.p4()
     goodjet = [0 for i in xrange(njets)]
     for i, j in enumerate(jets):
         if not self.jetSel(j): continue
         if j.muonIdx1 != -1 and j.muonIdx1 < njets:
             if self.muSel(muons[j.muonIdx1]): continue  # prefer the muon
         if j.muonIdx2 != -1 and j.muonIdx2 < njets:
             if self.muSel(muons[j.muonIdx2]): continue  # prefer the muon
         if j.electronIdx1 != -1 and j.electronIdx1 < njets:
             if self.elSel(electrons[j.electronIdx1]):
                 continue  # prefer the electron
         if j.electronIdx2 != -1 and j.electronIdx2 < njets:
             if self.elSel(electrons[j.electronIdx2]):
                 continue  # prefer the electron
         goodjet[i] = 1
         mht += j.p4()
     self.out.fillBranch("MHT_pt", mht.Pt())
     self.out.fillBranch("MHT_phi", -mht.Phi())  # note the minus
     self.out.fillBranch("Jet_mhtCleaning", goodjet)
     return True
Ejemplo n.º 2
0
    def getVisibleV(self, event):
        """
        tries to reconstruct a Z from the selected leptons
        for a W only the leading lepton is returned
        """

        lepColl = Collection(event, "LepGood")
        leps = []
        zCand = None
        nl = len(lepColl)
        for i in xrange(0, nl):
            l = lepColl[i]
            leps.append(l.p4())

            #check if a Z candidate can be formed
            for j in xrange(0, i):
                if lepColl[i].pdgId != lepColl[j].pdgId: continue
                ll = leps[i] + leps[j]
                if abs(ll.M() - 91) > 15: continue
                zCand = (i, j)
                break

        #build the visible V from what has been found
        visibleV = VisibleVectorBoson(
            selLeptons=[leps[0]]) if len(leps) > 0 else None
        if zCand:
            visibleV = VisibleVectorBoson(
                selLeptons=[leps[zCand[0]], leps[zCand[1]]])

        return visibleV
Ejemplo n.º 3
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     leps = filter(self.lepSel, Collection(event, "LepGood"))
     jets = filter(self.jetSel, Collection(event, "Jet"))
     jets.sort(key = self.jetSort, reverse=True)
     ret = {}
     for V in self.vars: ret[V] = []
     for lep in leps: lep.awayJet = None
     for lep in leps:
         for jet in jets:
             if self.pairSel(lep,jet):
                 lep.awayJet = jet
                 break
         for V in self.vars: 
             ret[V].append(getattr(lep.awayJet,V) if lep.awayJet else 0)
     for V in self.vars:
         self.out.fillBranch("LepGood_awayJet_"+V,ret[V])
     return True
Ejemplo n.º 4
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     jets = Collection(event, "Jet")
     for u, branchname in self.uncerts:
         uworker = self.factorizedUncertainties[u]
         jetUn = []
         for j in jets:
             uworker.setJetEta(j.eta)
             uworker.setJetPt(j.pt)
             jetUn.append(uworker.getUncertainty(True))
         self.out.fillBranch(branchname, jetUn)
     return True
Ejemplo n.º 5
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     leps = Collection(event, "LepGood")
     sf = []
     for l in leps:
         if event.isData:
             sf.append(1.)
         else:
             worker = self._worker_el if abs(
                 l.pdgId) == 11 else self._worker_mu
             sf.append(worker.getSF(l.pdgId, l.pt, l.eta))
     self.out.fillBranch("LepGood_effSF", sf)
     return True
Ejemplo n.º 6
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     coll = [Collection(event,x) for x in self.input]
     objects = [(coll[j][i],j,i) for j in xrange(self.nInputs) for i in xrange(len(coll[j]))]
     if self.selector: objects=filter(lambda (obj,j,i) : self.selector[j](obj), objects)
     objects.sort(key = self.sortkey, reverse = self.reverse)
     if self.maxObjects: objects = objects[:self.maxObjects]
     for bridx,br in enumerate(self.brlist_all):
         out = []
         for obj,j,i in objects:
             out.append(getattr(obj,br) if self.is_there[bridx][j] else 0)
         self.out.fillBranch("%s_%s"%(self.output,br), out)
     return True
Ejemplo n.º 7
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     leps = Collection(event, "LepGood")
     sf = []
     for l in leps:
         if event.isData or abs(l.pdgId) != 11:
             sf.append(1.)
         else:
             if self.dim == 2:
                 wgt = self._worker.getWeight(l.pt, l.eta)
                 sf.append(wgt if wgt > 0 else 1.)
             else:
                 sf.append(self._worker.getWeight(getattr(l, sef.var)))
     self.out.fillBranch("LepGood_trgSF", sf)
     return True
Ejemplo n.º 8
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     leps = Collection(event, "LepGood")
     iso = []
     for l in leps:
         if abs(l.pdgId)!=11: # implemented only for electrons
             iso.append(-1000) 
         else:
             eA = self._worker.getEffectiveArea(abs(l.eta))
             rho = getattr(event,self.rho)
             # approximation, since we don't have the three components of the isolation
             # should be chad + max(0.0, nhad + pho - rho*eA)
             iso.append((l.relIso04*l.pt - rho*eA)/l.pt) 
             # print "eta=%f,pt=%f,eA=%f,rho=%f,reliso=%f,relisocorr=%f" % (l.eta,l.pt,eA,rho,l.relIso04,(l.relIso04*l.pt - rho*eA)/l.pt)
     self.out.fillBranch("LepGood_relIso04EA", iso)
     return True
Ejemplo n.º 9
0
 def analyze(self, event):
     """process event, return True (go to next module) or False (fail, go to next event)"""
     ret = {}
     jets = Collection(event, "Jet")
     for V in self.vars:
         branch = getattr(self, "Jet_" + V)
         ret["Jet" + self.label + "_" + V] = [getattr(j, V) for j in jets]
     if event._tree._ttreereaderversion > self._ttreereaderversion:  # do this check at every event, as other modules might have read further branches
         self.initReaders(event._tree)
     # do NOT access other branches in python between the check/call to initReaders and the call to C++ worker code
     ## Algo
     cleanJets = self._worker.run()
     ## Output
     self.out.fillBranch('nJet' + self.label, len(cleanJets))
     for V in self.vars:
         self.out.fillBranch(
             "Jet" + self.label + "_" + V,
             [ret["Jet" + self.label + "_" + V][j] for j in cleanJets])
     return True