def analyze(self,event): event.deltaRL12 = deltaR(event.etaL1[0],event.phiL1[0],event.etaL2[0],event.phiL2[0]) event.deltaRL13 = deltaR(event.etaL1[0],event.phiL1[0],event.etaL3[0],event.phiL3[0]) #event.deltaRL14 = deltaR(event.etaL1[0],event.phiL1[0],event.etaL4[0],event.phiL4[0]) event.deltaRL23 = deltaR(event.etaL2[0],event.phiL2[0],event.etaL3[0],event.phiL3[0]) #event.deltaRL24 = deltaR(event.etaL2[0],event.phiL2[0],event.etaL4[0],event.phiL4[0]) #event.deltaRL34 = deltaR(event.etaL3[0],event.phiL3[0],event.etaL4[0],event.phiL4[0]) event.minDeltaRL = min([event.deltaRL12, event.deltaRL13, #event.deltaRL14, event.deltaRL23, #event.deltaRL24, #event.deltaRL34, ]) #event.deltaRL3bjet if event.minDeltaRL <= 0.02: return False #if event.minDeltaRL < 0.6: return False return True
def analyze(self, event): # same as skim tree selection, redundant if running on skim tree if len(event.tightLeps) == 0: return False if event.tightLeps[0].pt < 25: return False if len(event.selPhotons) == 0: return False if len(event.tightLeps) != 1: return False event.firstLep = event.tightLeps[0] deltaRList = [ deltaR(event.tightLeps[0].eta, event.tightLeps[0].phi, pho.eta, pho.phi) for pho in event.selPhotons ] if min(deltaRList) < 0.3: return False return True
def recleanTaus(self, taucollcleaned, taucolldiscarded, lepcoll, postfix, ret, tauret, event): ### Define taus alltaus = taucollcleaned + taucolldiscarded # 0. mark each tau as clean for t in alltaus: t._clean = True # 1. check for every tau if it is too close to a loose lepton for t in alltaus: for lep in lepcoll: dr = deltaR(lep, t) if self.cleanTau(lep, t, dr): t._clean = False # 2. compute the tau list ret["iTauSel" + postfix] = [] for itc, t in enumerate(taucollcleaned): if not t._clean: continue if not self.looseTau(t): continue setattr(t, "reclTauId", 1 + self.tightTau(t)) ret["iTauSel" + postfix].append(itc) for itd, t in enumerate(taucolldiscarded): if not t._clean: continue if not self.looseTau(t): continue setattr(t, "reclTauId", 1 + self.tightTau(t)) ret["iTauSel" + postfix].append(-1 - itd) # 3. sort the taus by pt ret["iTauSel" + postfix].sort( key=lambda idx: taucollcleaned[idx].pt if idx >= 0 else taucolldiscarded[-1 - idx].pt, reverse=True) goodtaus = [ (taucollcleaned[idx] if idx >= 0 else taucolldiscarded[-1 - idx]) for idx in ret["iTauSel" + postfix] ] ret["nTauSel" + postfix] = len(goodtaus) ret["nTightTauSel" + postfix] = sum( [1 for g in goodtaus if g.reclTauId == 2]) # 4. store the tau 4-vectors if postfix == self.label: for tfloat in "pt eta phi mass reclTauId pdgId".split(): tauret[tfloat] = [] for g in goodtaus: tauret[tfloat].append(getattr(g, tfloat)) for tfloat in "mcMatchId".split(): tauret[tfloat] = [] for g in goodtaus: tauret[tfloat].append( getattr(g, tfloat) if hasattr(event, "TauGood_" + tfloat) else -99) return goodtaus
def analyze(self, event): event.deltaRL12 = deltaR(event.etaL1[0], event.phiL1[0], event.etaL2[0], event.phiL2[0]) event.vecL1 = ROOT.TLorentzVector() event.vecL1.SetPtEtaPhiM(event.pTL1[0], event.etaL1[0], event.phiL1[0], muonMass) event.vecL2 = ROOT.TLorentzVector() event.vecL2.SetPtEtaPhiM(event.pTL2[0], event.etaL2[0], event.phiL2[0], muonMass) event.vecL3 = ROOT.TLorentzVector() event.vecL3.SetPtEtaPhiM(event.pTL3[0], event.etaL3[0], event.phiL3[0], muonMass) event.vecL4 = ROOT.TLorentzVector() event.vecL4.SetPtEtaPhiM(event.pTL4[0], event.etaL4[0], event.phiL4[0], muonMass) event.vecZ1 = event.vecL1 + event.vecL2 event.vecZ2 = event.vecL3 + event.vecL4 event.phiL21 = deltaPhi(event.phiL2[0], event.phiL1[0]) event.phiL31 = deltaPhi(event.phiL3[0], event.phiL1[0]) event.phiL41 = deltaPhi(event.phiL4[0], event.phiL1[0]) event.cosThetaStar = ROOT.Double(0.) event.cosTheta1 = ROOT.Double(0.) event.cosTheta2 = ROOT.Double(0.) event.phi = ROOT.Double(0.) event.phi1 = ROOT.Double(0.) ROOT.computeAngles( event.vecL1, event.idL1[0], event.vecL2, event.idL2[0], event.vecL3, event.idL3[0], event.vecL4, event.idL4[0], event.cosThetaStar, event.cosTheta1, event.cosTheta2, event.phi, event.phi1, ) return True
def analyze(self, event): event.deltaRL12 = deltaR(event.etaL1[0], event.phiL1[0], event.etaL2[0], event.phiL2[0]) event.deltaRL13 = deltaR(event.etaL1[0], event.phiL1[0], event.etaL3[0], event.phiL3[0]) event.deltaRL14 = deltaR(event.etaL1[0], event.phiL1[0], event.etaL4[0], event.phiL4[0]) event.deltaRL23 = deltaR(event.etaL2[0], event.phiL2[0], event.etaL3[0], event.phiL3[0]) event.deltaRL24 = deltaR(event.etaL2[0], event.phiL2[0], event.etaL4[0], event.phiL4[0]) event.deltaRL34 = deltaR(event.etaL3[0], event.phiL3[0], event.etaL4[0], event.phiL4[0]) event.minDeltaRL = min([ event.deltaRL12, event.deltaRL13, event.deltaRL14, event.deltaRL23, event.deltaRL24, event.deltaRL34, ]) event.etaL21 = event.etaL2[0] - event.etaL1[0] event.etaL31 = event.etaL3[0] - event.etaL1[0] event.etaL41 = event.etaL4[0] - event.etaL1[0] event.phiL21 = deltaPhi(event.phiL2[0], event.phiL1[0]) event.phiL31 = deltaPhi(event.phiL3[0], event.phiL1[0]) event.phiL41 = deltaPhi(event.phiL4[0], event.phiL1[0]) event.vecL1 = ROOT.TLorentzVector() event.vecL1.SetPtEtaPhiM(event.pTL1[0], event.etaL1[0], event.phiL1[0], self.get_mass(event.idL1[0])) event.vecL2 = ROOT.TLorentzVector() event.vecL2.SetPtEtaPhiM(event.pTL2[0], event.etaL2[0], event.phiL2[0], self.get_mass(event.idL2[0])) event.vecL3 = ROOT.TLorentzVector() event.vecL3.SetPtEtaPhiM(event.pTL3[0], event.etaL3[0], event.phiL3[0], self.get_mass(event.idL3[0])) event.vecL4 = ROOT.TLorentzVector() event.vecL4.SetPtEtaPhiM(event.pTL4[0], event.etaL4[0], event.phiL4[0], self.get_mass(event.idL4[0])) #if event.minDeltaRL < 0.3: return False #if event.minDeltaRL < 0.6: return False return True
def analyze(self, event): event.muons = [p for p in event.MediumMuons if p.pt > 40] event.muons.sort(key=lambda x: x.pt, reverse=True) event.eles = [p for p in event.MediumElectrons if p.pt > 40] event.eles.sort(key=lambda x: x.pt, reverse=True) event.leps = event.muons + event.eles event.leps.sort(key=lambda x: x.pt, reverse=True) event.nLep40 = len(event.leps) event.jets = [p for p in event.LooseJets if p.pt > 40] event.jets.sort(key=lambda x: x.pt, reverse=True) event.nJet40 = len(event.jets) event.ht40 = 0. for ps in [event.jets, event.leps]: for p in ps: event.ht40 += p.pt if event.nLep40 >= 2: vecSum = event.leps[0].p4() + event.leps[1].p4() event.mll = vecSum.M() else: event.mll = None if len(event.jets) >= 2 and len(event.leps) >= 2: event.m_ct = [ numpy.sqrt( numpy.square( numpy.sqrt( numpy.square(event.jets[0].pt) + numpy.square(event.jets[0].mass)) + numpy.sqrt( numpy.square(event.jets[1].pt) + numpy.square(event.jets[1].mass))) - numpy.square(event.jets[0].pt - event.jets[1].pt)) ] vecsum1 = event.leps[0].p4() + event.jets[0].p4() l1 = vecsum1.M() vecsum2 = event.leps[1].p4() + event.jets[1].p4() l2 = vecsum2.M() vecsum3 = event.leps[1].p4() + event.jets[0].p4() l3 = vecsum3.M() vecsum4 = event.leps[0].p4() + event.jets[1].p4() l4 = vecsum4.M() if l1 >= l2 and l3 >= l4: event.m0_bl = [l1, l3] event.m1_bl = [l2, l4] elif l1 >= l2 and l3 < l4: event.m0_bl = [l1, l4] event.m1_bl = [l2, l3] elif l1 < l2 and l3 >= l4: event.m0_bl = [l2, l3] event.m1_bl = [l1, l4] elif l1 < l2 and l3 < l4: event.m0_bl = [l2, l4] event.m1_bl = [l1, l3] temp1 = (event.m0_bl[0] - event.m1_bl[0]) / (event.m0_bl[0] + event.m1_bl[0]) temp2 = (event.m0_bl[1] - event.m1_bl[1]) / (event.m0_bl[1] + event.m1_bl[1]) if temp1 < temp2: event.m_asym_bl = [temp1] event.m0_bl = [event.m0_bl[0]] event.m1_bl = [event.m1_bl[0]] else: event.m_asym_bl = [temp2] event.m0_bl = [event.m0_bl[1]] event.m1_bl = [event.m1_bl[1]] else: event.m_ct = -1 event.m0_b1 = -1 event.m1_b1 = -1 for j in event.jets: muEnergy = event.Muon_pt[j.muonIdx1] + event.Muon_pt[j.muonIdx2] j.muEF = muEnergy / (j.pt * (1 - j.rawFactor)) #dphi = [abs(event.jets[0].phi- event.leps[0].phi), abs(event.jets[0].phi- event.leps[1].phi), abs(event.jets[1].phi- event.leps[0].phi), abs(event.jets[1].phi- event.leps[1].phi)] #deta = [abs(event.jets[0].eta- event.leps[0].eta), abs(event.jets[0].eta- event.leps[1].eta), abs(event.jets[1].eta- event.leps[0].eta), abs(event.jets[1].eta- event.leps[1].eta)] #dR = [0,0,0,0] event.dR_min_jets_leps = 0 for i in event.jets: for j in event.leps: temp = deltaR(i.eta, i.phi, j.eta, j.phi) if event.dR_min_jets_leps == 0 or event.dR_min_jets_leps > temp: event.dR_min_jets_leps = temp return True
index2], lep_id[ev][index3] ot.pTL1[0], ot.pTL2[0], ot.pTL3[0] = lep1.Pt(), lep2.Pt(), lep3.Pt() ot.etaL1[0], ot.etaL2[0], ot.etaL3[0] = lep1.Eta(), lep2.Eta(), lep3.Eta() ot.phiL1[0], ot.phiL2[0], ot.phiL3[0] = lep1.Phi(), lep2.Phi(), lep3.Phi() ot.IsoL1[0], ot.IsoL2[0], ot.IsoL3[0] = lep_iso[ev][index1], lep_iso[ev][ index2], lep_iso[ev][index3] ot.ip3dL1[0], ot.ip3dL2[0], ot.ip3dL3[0] = lep_ip[ev][index1], lep_ip[ev][ index2], lep_ip[ev][index3] ot.sip3dL1[0], ot.sip3dL2[0], ot.sip3dL3[0] = lep_sip[ev][index1], lep_sip[ ev][index2], lep_sip[ev][index3] ot.massL1[0], ot.massL2[0], ot.massL3[0] = lep1.M(), lep2.M(), lep3.M() ot.tightIdL1[0], ot.tightIdL2[0], ot.tightIdL3[0] = lep_tight[ev][ index1], lep_tight[ev][index2], lep_tight[ev][index3] ot.medIdL1[0], ot.medIdL2[0], ot.medIdL3[0] = lep_med[ev][index1], lep_med[ ev][index2], lep_med[ev][index3] ot.dR12[0] = deltaR(lep1.Eta(), lep1.Phi(), lep2.Eta(), lep2.Phi()) ot.dR13[0] = deltaR(lep1.Eta(), lep1.Phi(), lep3.Eta(), lep3.Phi()) ot.dR23[0] = deltaR(lep2.Eta(), lep2.Phi(), lep3.Eta(), lep3.Phi()) ot.met[0], ot.met_phi[0] = MET[ev], MET_phi[ev] #ot.nLep[0] = nLep #ot.nElectrons[0] = t.nElectron ot.nMuons[0] = nMuon[ev] #ot.trueL3[0] = trueL3 ot.m3l[0] = threeleps.M() ot.mt[0] = (threeleps + Met).M() ot.Run[0] = Run[ev] ot.Event[0] = Event[ev] ot.LumiSect[0] = LumiSect[ev]
def recleanJets(self, jetcollcleaned, jetcolldiscarded, lepcoll, postfix, ret, jetret, discjetret): ### Define jets ret["iJSel" + postfix] = [] ret["iDiscJSel" + postfix] = [] # 0. mark each jet as clean for j in jetcollcleaned + jetcolldiscarded: j._clean = True # 1. associate to each lepton passing the cleaning selection its nearest jet for lep in lepcoll: best = None bestdr = 0.4 for j in jetcollcleaned + jetcolldiscarded: dr = deltaR(lep, j) if dr < bestdr: best = j bestdr = dr if best is not None and self.cleanJet(lep, best, bestdr): best._clean = False # 2. compute the jet list for ijc, j in enumerate(jetcollcleaned): if not self.selectJet(j): continue elif not j._clean: ret["iDiscJSel" + postfix].append(ijc) else: ret["iJSel" + postfix].append(ijc) for ijd, j in enumerate(jetcolldiscarded): if not self.selectJet(j): continue elif not j._clean: ret["iDiscJSel" + postfix].append(-1 - ijd) else: ret["iJSel" + postfix].append(-1 - ijd) # 3. sort the jets by pt ret["iJSel" + postfix].sort( key=lambda idx: jetcollcleaned[idx].pt if idx >= 0 else jetcolldiscarded[-1 - idx].pt, reverse=True) ret["iDiscJSel" + postfix].sort( key=lambda idx: jetcollcleaned[idx].pt if idx >= 0 else jetcolldiscarded[-1 - idx].pt, reverse=True) ret["nJetSel" + postfix] = len(ret["iJSel" + postfix]) ret["nDiscJetSel" + postfix] = len(ret["iDiscJSel" + postfix]) # 4. if needed, store the jet 4-vectors if self.storeJetVariables: #print postfix, self.label if postfix == self.label: for jfloat in self.jetVarToStore.split(): jetret[jfloat] = [] discjetret[jfloat] = [] for idx in ret["iJSel" + postfix]: jet = jetcollcleaned[ idx] if idx >= 0 else jetcolldiscarded[-1 - idx] for jfloat in self.jetVarToStore.split(): if "Flavour" in jfloat: valueToStore = getattr(jet, jfloat, -99.) else: valueToStore = getattr(jet, jfloat) jetret[jfloat].append(valueToStore) for idx in ret["iDiscJSel" + postfix]: jet = jetcollcleaned[ idx] if idx >= 0 else jetcolldiscarded[-1 - idx] for jfloat in self.jetVarToStore.split(): if "Flavour" in jfloat: valueToStore = getattr(jet, jfloat, -99.) else: valueToStore = getattr(jet, jfloat) discjetret[jfloat].append(valueToStore) # 5. compute the sums ret["nJet" + self.strBJetPt + postfix] = 0 ret["htJet" + self.strBJetPt + "j" + postfix] = 0 ret["mhtJet" + self.strBJetPt + postfix] = 0 ret["nBJetLoose" + self.strBJetPt + postfix] = 0 ret["nBJetMedium" + self.strBJetPt + postfix] = 0 ret["nJet" + self.strJetPt + postfix] = 0 ret["htJet" + self.strJetPt + "j" + postfix] = 0 ret["mhtJet" + self.strJetPt + postfix] = 0 ret["nBJetLoose" + self.strJetPt + postfix] = 0 ret["nBJetMedium" + self.strJetPt + postfix] = 0 cleanjets = [] mhtBJetPtvec = ROOT.TLorentzVector(0, 0, 0, 0) mhtJetPtvec = ROOT.TLorentzVector(0, 0, 0, 0) for x in lepcoll: mhtBJetPtvec = mhtBJetPtvec - x.p4() for x in lepcoll: mhtJetPtvec = mhtJetPtvec - x.p4() for j in jetcollcleaned + jetcolldiscarded: if not (j._clean and self.selectJet(j)): continue cleanjets.append(j) if j.pt > float(self.bJetPt): ret["nJet" + self.strBJetPt + postfix] += 1 ret["htJet" + self.strBJetPt + "j" + postfix] += j.pt if j.btagCSV > self.btagCSVLoose: ret["nBJetLoose" + self.strBJetPt + postfix] += 1 if j.btagCSV > self.btagCSVMedium: ret["nBJetMedium" + self.strBJetPt + postfix] += 1 mhtBJetPtvec = mhtBJetPtvec - j.p4() if j.pt > float(self.jetPt): ret["nJet" + self.strJetPt + postfix] += 1 ret["htJet" + self.strJetPt + "j" + postfix] += j.pt if j.btagCSV > self.btagCSVLoose: ret["nBJetLoose" + self.strJetPt + postfix] += 1 if j.btagCSV > self.btagCSVMedium: ret["nBJetMedium" + self.strJetPt + postfix] += 1 mhtJetPtvec = mhtJetPtvec - j.p4() ret["mhtJet" + self.strBJetPt + postfix] = mhtBJetPtvec.Pt() ret["mhtJet" + self.strJetPt + postfix] = mhtJetPtvec.Pt() return cleanjets