def analyze(self, event): all_leps = [l for l in Collection(event,"LepGood")] nFO = getattr(event,"nLepFO"+self.inputlabel) chosen = getattr(event,"iLepFO"+self.inputlabel) leps = [all_leps[chosen[i]] for i in xrange(nFO)] if len(leps) < 2: return True ret = {} for var in self.systsJEC: ret['highestHjTagger%s'%self.systsJEC[var]] = -99 _var = var if not hasattr(event,"nJet25"+self.systsJEC[var]+self.inputlabel): _var = 0; jets = [j for j in Collection(event,"JetSel"+self.inputlabel)] jetptcut = 25 jets = filter(lambda x : getattr(x,'pt%s'%self.systsJEC[_var]) > jetptcut, jets) allVars = [] for j in jets: pseudoevent = emptyclass() setattr(pseudoevent, 'v1', min( deltaR(j, leps[0]), deltaR(j, leps[1]))) setattr(pseudoevent, 'v2', max( 0, j.btagDeepFlavB)) setattr(pseudoevent, 'v3', max( 0, j.qgl )) setattr(pseudoevent, 'v4', max( deltaR(j, leps[0]), deltaR(j, leps[1]) )) setattr(pseudoevent, 'v5', getattr(j,'pt%s'%self.systsJEC[_var])) allVars.append( self._MVA( pseudoevent ) ) del pseudoevent if len(allVars): ret['highestHjTagger%s'%self.systsJEC[var]] = max(allVars) writeOutput(self, ret) return True
def matchSVToSubjets(self, event, fj): assert (len(fj.subjets) == 2) drcut = min(0.4, 0.5 * deltaR(*fj.subjets)) for sj in fj.subjets: sj.sv_list = [] for sv in event.secondary_vertices: if deltaR(sv, sj) < drcut: sj.sv_list.append(sv)
def run(self,event,Collection,metName): allret = {} all_leps = [l for l in Collection(event,"LepGood")] nFO = getattr(event,"nLepFO"+self.inputlabel) chosen = getattr(event,"iLepFO"+self.inputlabel) leps = [all_leps[chosen[i]] for i in xrange(nFO)] for var in self.systsJEC: _var = var if not hasattr(event,"nJet25"+self.systsJEC[var]+self.inputlabel): _var = 0 jets = [j for j in Collection(event,"JetSel"+self.inputlabel)] jetptcut = 25 if (_var==0): jets = filter(lambda x : x.pt>jetptcut, jets) elif (_var==1): jets = filter(lambda x : x.pt*x.corr_JECUp/x.corr>jetptcut, jets) elif (_var==-1): jets = filter(lambda x : x.pt*x.corr_JECDown/x.corr>jetptcut, jets) ### USE ONLY ANGULAR JET VARIABLES IN THE FOLLOWING!!! met = getattr(event,metName+self.systsJEC[_var]+"_pt") metphi = getattr(event,metName+self.systsJEC[_var]+"_phi") njet = len(jets); nlep = len(leps) # prepare output ret = dict([(name,0.0) for name in self.namebranches]) # fill output if njet >= 1: ret["mindr_lep1_jet"] = min([deltaR(j,leps[0]) for j in jets]) if nlep >= 1 else 0; ret["mindr_lep2_jet"] = min([deltaR(j,leps[1]) for j in jets]) if nlep >= 2 else 0; if njet >= 2: sumdr, ndr = 0, 0 for i,j in enumerate(jets): for i2,j2 in enumerate(jets[i+1:]): ndr += 1 sumdr += deltaR(j,j2) ret["avg_dr_jet"] = sumdr/ndr if ndr else 0; if nlep > 0: ret["MT_met_lep1"] = sqrt( 2*leps[0].conePt*met*(1-cos(leps[0].phi-metphi)) ) # if nlep > 1: # px = leps[0].conePt*cos(leps[0].phi) + leps[1].conePt*cos(leps[1].phi) + met*cos(metphi) # py = leps[0].conePt*sin(leps[0].phi) + leps[1].conePt*sin(leps[1].phi) + met*sin(metphi) # ht = leps[0].conePt + leps[1].conePt + met # ret["MT_met_leplep"] = sqrt(max(0,ht**2 - px**2 - py**2)) # if nlep >= 1: # sumapz, sumspz = 0,0 # for o in leps[:2] + jets: # pz = o.conePt*sinh(o.eta) if o in leps else o.pt*sinh(o.eta) # sumspz += pz # sumapz += abs(pz); # ret["sum_abspz"] = sumapz # ret["sum_sgnpz"] = sumspz for br in self.namebranches: allret[br+self.label+self.systsJEC[var]] = ret[br] return allret
def analyze(self, event): subjets = Collection(event, self.subJetBranchName) genquarks_filtered = [] for genquark_branchName in self.genQuarkBranchNames: genquarks = Collection(event, genquark_branchName) for genquark in genquarks: if not (0 < abs(genquark.pdgId) < 6): continue has_match = False for genquark_filtered in genquarks_filtered: if deltaR(genquark.eta, genquark.phi, genquark_filtered.eta, genquark_filtered.phi) < 1e-2: has_match = True break if not has_match: genquarks_filtered.append(genquark) genquarks_sorted = list(sorted(genquarks_filtered, key = lambda genquark: genquark.pt, reverse = True)) genquarks_matched = [] for subjet in subjets: if not (subjet.pt > self.btag_minPt and abs(subjet.eta) < self.btag_maxAbsEta): continue subjet_flavor = 0 # assume light flavor if no match min_dr = 1e3 match_idx = -1 for genquark_idx, genquark in enumerate(genquarks_sorted): if genquark_idx in genquarks_matched: # genquark already matched continue dr = deltaR(subjet.eta, subjet.phi, genquark.eta, genquark.phi) if dr < self.match_dR and dr < min_dr: min_dr = dr match_idx = genquark_idx if match_idx >= 0: genquarks_matched.append(match_idx) subjet_flavor = abs(genquarks_sorted[match_idx].pdgId) if subjet_flavor < 4: subjet_flavor = 0 assert(subjet_flavor in self.flavors) subjet_pt = subjet.pt subjet_absEta = abs(subjet.eta) subjet_btag = subjet.btagDeepB for binning in self.binning: histKey_total = self.getHistKey(binning, subjet_flavor) self.hists[histKey_total].Fill(subjet_pt, subjet_absEta) for btagWP in self.btagWP: if subjet_btag >= self.btagWP[btagWP]: histKey = self.getHistKey(binning, subjet_flavor, btagWP) self.hists[histKey].Fill(subjet_pt, subjet_absEta) return True
def _fillCommonInfo(self, event, i_parton, parton, daughters): self.out.fillBranch("i_evt", int(event.event)) self.out.fillBranch("npv", event.PV_npvs) self.out.fillBranch("genweight", event.genWeight) pdgid2type = { 24: 1, 6: 2, 23: 3, 25: 4, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 21: 0 } self.out.fillBranch("i_parton", i_parton) self.out.fillBranch("type", pdgid2type[abs(parton.pdgId)]) self.out.fillBranch("gen_pt", parton.pt) self.out.fillBranch("gen_eta", parton.eta) self.out.fillBranch("gen_phi", parton.phi) self.out.fillBranch("gen_pdgid", parton.pdgId) self.out.fillBranch( "gen_size", max([deltaR(parton, dau) for dau in daughters]) if len(daughters) else 0) c = Counter([abs(dau.pdgId) for dau in daughters]) self.out.fillBranch("gen_n_b_daus", c[5]) self.out.fillBranch("gen_n_c_daus", c[4]) if abs(parton.pdgId) == 6: self.out.fillBranch("gentop_b_pt", parton.genB.pt) self.out.fillBranch("gentop_b_eta", parton.genB.eta) self.out.fillBranch("gentop_b_phi", parton.genB.phi) self.out.fillBranch("gentop_w_pt", parton.genW.pt) self.out.fillBranch("gentop_w_eta", parton.genW.eta) self.out.fillBranch("gentop_w_phi", parton.genW.phi) self.out.fillBranch( "gentop_w_size", max([deltaR(parton.genW, dau) for dau in daughters[1:]]) if len(daughters) == 3 else 0) else: self.out.fillBranch("gentop_b_pt", 0) self.out.fillBranch("gentop_b_eta", 0) self.out.fillBranch("gentop_b_phi", 0) self.out.fillBranch("gentop_w_pt", 0) self.out.fillBranch("gentop_w_eta", 0) self.out.fillBranch("gentop_w_phi", 0) self.out.fillBranch("gentop_w_size", 0)
def drmatch(event, jet): dr_b, dr_wq1, dr_wq2 = 999, 999, 999 if jet: top, _ = closest(jet, event.hadGenTops) if top: dr_b = deltaR(jet, top.genB) dr_wq1 = deltaR(jet, event.genparts[top.genW.dauIdx[0]]) dr_wq2 = deltaR(jet, event.genparts[top.genW.dauIdx[1]]) else: w, _ = closest(jet, event.hadGenWs) if w: dr_wq1 = deltaR(jet, event.genparts[w.dauIdx[0]]) dr_wq2 = deltaR(jet, event.genparts[w.dauIdx[1]]) return dr_b, max(dr_wq1, dr_wq2), min(dr_wq1, dr_wq2)
def analyze(self, event): taus = Collection(event, "PFcand") jet = Collection(event, "Jet") mva = {} mva_ = [] for tau in taus: jetmatch = tau.contJetIndex > -1 and jet[ tau.contJetIndex].pt > 30.0 and math.fabs( jet[tau.contJetIndex].eta) < 2.4 contjetdr = deltaR(tau, jet[tau.contJetIndex]) if jetmatch else -1.0 contjetcsv = jet[tau.contJetIndex].btagDeepB if jetmatch else -1.0 mva = { "Pfcand_pt": tau.pt, "Pfcand_eta": tau.eta, "Pfcand_dz": tau.dz, "Pfcand_chiso0p1": tau.chiso0p1, "Pfcand_chiso0p2": tau.chiso0p2, "Pfcand_chiso0p3": tau.chiso0p3, "Pfcand_chiso0p4": tau.chiso0p4, "Pfcand_totiso0p1": tau.totiso0p1, "Pfcand_totiso0p2": tau.totiso0p2, "Pfcand_totiso0p3": tau.totiso0p3, "Pfcand_totiso0p4": tau.totiso0p4, "Pfcand_nearestTrkDR": tau.nearestTrkDR, "Pfcand_contjetdr": contjetdr, "Pfcand_contjetcsv": contjetcsv } mva_.append(self.xgb.eval(mva)) #print "mva output: ", mva_ self.out.fillBranch("kinBDT", mva_) #self.out.fillBranch("TauMVA_Stop0l", True if mva_ > self.tauMVADisc else False) return True
def cleanJetFromMuons(jet, muons, dR): clean = (jet.jetId == 7) for mu in muons: if deltaR(mu.eta, mu.phi, jet.eta, jet.phi) <= dR: clean = False break return clean
def overlaps_any(self, obj, refcollection, coneSize): has_overlap = False for refobj in refcollection: if deltaR(obj.eta, obj.phi, refobj.eta, refobj.phi) < coneSize: has_overlap = True break return has_overlap
def _fillAK8(self, parton, daughters, jet): self.out.fillBranch("dR_gen_ak8", deltaR(parton, jet) if jet else 999) fillBranch = self._get_filler(jet) fillBranch("ak8_pt", jet.pt, -1) fillBranch("ak8_eta", jet.eta) fillBranch("ak8_phi", jet.phi) fillBranch("ak8_sdmass", jet.msoftdrop) fillBranch("ak8_corr_sdmass", jet.corr_sdmass) fillBranch("ak8_tau21", jet.tau2 / jet.tau1 if jet.tau1 > 0 else 99, 99) fillBranch("ak8_tau32", jet.tau3 / jet.tau2 if jet.tau2 > 0 else 99, 99) fillBranch( "ak8_maxsubjetcsv", max([sj.btagCSVV2 for sj in jet.subjets]) if jet and len(jet.subjets) else -99, -99) fillBranch("ak8_doubleb", jet.btagHbb, -99) fillBranch("ak8_DeepAK8_TvsQCD", jet.deepTag_TvsQCD) fillBranch("ak8_DeepAK8_WvsQCD", jet.deepTag_WvsQCD) fillBranch("ak8_DeepAK8_ZvsQCD", jet.deepTag_ZvsQCD) fillBranch("ak8_DeepAK8MD_TvsQCD", jet.deepTagMD_TvsQCD) fillBranch("ak8_DeepAK8MD_WvsQCD", jet.deepTagMD_WvsQCD) fillBranch("ak8_DeepAK8MD_ZvsQCD", jet.deepTagMD_ZvsQCD) fillBranch("ak8_DeepAK8MD_ZHbbvsQCD", jet.deepTagMD_ZHbbvsQCD) fillBranch("ak8_DeepAK8MD_ZHccvsQCD", jet.deepTagMD_ZHccvsQCD) fillBranch("ak8_ecfN2", jet.n2b1, 99) fillBranch("ak8_ecfN2DDT", jet.n2b1ddt, 99)
def _matchSVToFatjet(self, event, fj): if 'sv_list' in fj.__dict__: return fj.sv_list = [] for sv in event.secondary_vertices: if deltaR(sv, fj) < self._jetConeSize: fj.sv_list.append(sv)
def mapGenToPF(self, GenColl, PFColl, selGen=lambda x: True, selPF=lambda x: True): # map charged for gp in GenColl: if not selGen(gp): continue dRmin = 999.0 matchedIndex = -999 for ip in xrange(len(PFColl)): p = PFColl[ip] if not selPF(p): continue dR = deltaR(gp.eta, gp.phi, p.eta, p.phi) if dR < dRmin: dRmin = dR matchedIndex = ip if matchedIndex >= 0: p = PFColl[matchedIndex] gp.toPFIndex = p.index gp.toPFselectedIndex = matchedIndex gp.toPFdR = dRmin p.toGenN += 1 p.toGen_sumpt += gp.p4() if dRmin < p.toGen_mindR: p.toGen_mindR = dRmin p.toGen_mindRIndex = gp.index
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Code for ISR jet cal from Scarlet ~~~~~ # Looks like room for speed up jets = Collection(event, "Jet") genParts = Collection(event, "GenPart") electrons = Collection(event, "Electron") muons = Collection(event, "Muon") # Follow babymaker code to produce nisr in the event, following the ICHEP recommendation # https://github.com/manuelfs/babymaker/blob/0136340602ee28caab14e3f6b064d1db81544a0a/bmaker/plugins/bmaker_full.cc#L1268-L1295 jetidx = self.GetBabyJetList(jets, muons, electrons) nisr = 0 for j in jetidx: jet = jets[j] matched = False for genPart in genParts: if genPart.statusFlags != 23 or abs(genPart.pdgId) > 5: continue if self.RecursiveMother(genPart): dR = deltaR(jet,genPart) if dR<0.3: matched = True break if not matched: nisr+=1 nbin = bisect.bisect(self.nISRbins, nisr) -1 self.out.fillBranch("nISRJets", nisr) self.out.fillBranch("ISRWeight", self.ISRcentral[nbin]) self.out.fillBranch("ISRWeight_Up", self.ISRUp[nbin]) self.out.fillBranch("ISRWeight_Down", self.ISRDown[nbin]) return True
def analyze(self, event): jetsCA15 = Collection(event, self.jetCollectionCA15) jetsHTTv2 = Collection(event, self.jetCollectionHTTv2) #print "<jetSubstructureObservablesProducerHTTv2::analyze>: #%s jets = %i, #%s jets = %i" % (self.jetCollectionHTTv2, len(jetsHTTv2), self.jetCollectionCA15, len(jetsCA15)) tau1Val = [] tau2Val = [] tau3Val = [] for jetHTTv2_idx, jetHTTv2 in enumerate(jetsHTTv2): #print "%s jet #%i: pT = %1.2f, eta = %1.2f, phi = %1.2f, mass = %1.2f" % \ # (self.jetCollectionHTTv2, jetHTTv2_idx, jetHTTv2.pt, jetHTTv2.eta, jetHTTv2.phi, jetHTTv2.mass) tau1 = -1. tau2 = -1. tau3 = -1. dRmin = 1.e+3 for jetCA15_idx, jetCA15 in enumerate(jetsCA15): dR = deltaR(jetHTTv2, jetCA15) if dR < 0.75 and dR < dRmin: tau1 = jetCA15.tau1 tau2 = jetCA15.tau2 tau3 = jetCA15.tau3 dRmin = dR #print "matched to %s jet #%i: pT = %1.2f, eta = %1.2f, phi = %1.2f, mass = %1.2f (dR = %1.2f)" % \ # (self.jetCollectionCA15, jetCA15_idx, jetCA15.pt, jetCA15.eta, jetCA15.phi, jetCA15.mass, dR) #print " setting tau1 = %1.2f, tau2 = %1.2f, tau3 = %1.2f" % (tau1, tau2, tau3) tau1Val.append(tau1) tau2Val.append(tau2) tau3Val.append(tau3) self.out.fillBranch(self.jetCollectionHTTv2 + "_tau1", tau1Val) self.out.fillBranch(self.jetCollectionHTTv2 + "_tau2", tau2Val) self.out.fillBranch(self.jetCollectionHTTv2 + "_tau3", tau3Val) return True
def _fillCommonInfo(self, event, i_parton, parton, daughters): self.out.fillBranch("i_evt", int(event.event)) self.out.fillBranch("npv", event.PV_npvs) self.out.fillBranch("genweight", event.genWeight) pdgid2type = { 24: 1, 6: 2, 23: 3, 25: 4, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 21: 0 } self.out.fillBranch("i_parton", i_parton) self.out.fillBranch("type", pdgid2type[abs(parton.pdgId)]) self.out.fillBranch("gen_pt", parton.pt) self.out.fillBranch("gen_eta", parton.eta) self.out.fillBranch("gen_phi", parton.phi) self.out.fillBranch("gen_pdgid", parton.pdgId) self.out.fillBranch( "gen_size", max([deltaR(parton, dau) for dau in daughters]) if len(daughters) else 0)
def analyze(self, event): """process event, return True (go to next module) or False (fail, go to next event)""" taus = Collection(event, "Tau") jets = Collection(event, "Jet") JetProducer_nJet = 0 JetProducer_nBJetL = JetProducer_nBJetM = JetProducer_nBJetT = 0 for jet in jets: if jet.pt>20 and abs(jet.eta)<2.5 and (4&jet.jetId): mindr = 9. for tau in taus: if (128&tau.idDeepTau2017v2p1VSjet): mindr_ = deltaR(jet.eta, jet.phi, tau.eta, tau.phi) if mindr_<mindr: mindr = mindr_ if mindr>=0.4: JetProducer_nJet = JetProducer_nJet + 1 if jet.btagDeepB>=0.1241: JetProducer_nBJetL = JetProducer_nBJetL + 1 if jet.btagDeepB>=0.4184: JetProducer_nBJetM = JetProducer_nBJetM + 1 if jet.btagDeepB>=0.7527: JetProducer_nBJetT = JetProducer_nBJetT + 1 self.out.fillBranch("JetProducer_nBJetL", JetProducer_nBJetL) self.out.fillBranch("JetProducer_nBJetM", JetProducer_nBJetM) self.out.fillBranch("JetProducer_nBJetT", JetProducer_nBJetT) self.out.fillBranch("JetProducer_nJet", JetProducer_nJet) return True
def vetoCandidate(self, pcand, vetoCands): """ given input pcand and vetoCands, decide if the pcand should be vetoed or not. Currently only apply DeltaR cut """ for vc in vetoCands: if deltaR(pcand.eta, pcand.phi, vc.eta, vc.phi) < 0.01: return True return False
def SelTau(self, genpart, pfc): for g in genpart: genPartMom = g.genPartIdxMother if self.isA(self.p_tauminus, g.pdgId) and deltaR( g.eta, g.phi, pfc.eta, pfc.phi ) < 0.2: # and (self.isA(self.p_Z0, genPartMom) or self.isA(self.p_Wplus, genPartMom)): return True return False
def analyze(self, event): #Can only be performed on MC #if not isMC: return True if not self.isMC: return True leps = [x for x in Collection(event, "Electron") ] + [x for x in Collection(event, "Muon")] jets = [x for x in Collection(event, "Jet")] gens = [x for x in Collection(event, "GenPart")] #jets = filter(self.jetSel, Collection(event, 'Jet')) #gens = Collection(event, 'GenPart') jets = filter(lambda x: x.pt > 35 and abs(x.eta) < 2.4, jets) nIsr = 0 for jet in jets: matched = False skip = False for lep in leps: if deltaR(jet, lep) < 0.4: skip = True break if skip: continue for gen in gens: if abs(gen.pdgId) > 5 or gen.status != 23: continue if gen.genPartIdxMother < 0: continue # mom = gens[gen.genPartIdxMother] # momid = abs(mom.pdgId) # if momid not in [6,23,24,25] and momid < 1e6: continue # for gen2 in gens: # if isInDecayOf(gen2, gen, gens): # if deltaR(gen2,jet) < 0.3: # matched = True # break # if matched: break # if not matched: # nIsr+=1 if deltaR(jet, gen) > 0.3: continue if not getRightParentage(gen, gens): continue matched = True break if not matched: nIsr += 1 self.wrappedOutputTree.fillBranch("nIsr", nIsr) return True
def getmindr(event, jet, genParticles, pickGenW=False): dr = 999 if jet: gp, _ = closest(jet, genParticles) if gp: if pickGenW: gp = gp.genW dr = deltaR(jet, gp) return dr
def SelSoftb(self, isv, jets): ## Select soft bs ## SV is not associate with selected jets for j in jets: if j.pt >= 20 and math.fabs(j.eta) <= 2.4 and deltaR(j.eta, j.phi, isv.eta, isv.phi) <= 0.4 : return False if isv.ntracks < 3 or math.fabs(isv.dxy)>3. or isv.dlenSig <4: return False if isv.DdotP < 0.98 : return False return True
def analyze1(self, event): jets = Collection(event, "Jet") genjets = Collection(event, "GenJet") met = Object(event, self.metBranchName) for gJ in genjets: #print 'pt of genjets',gJ.pt self.h1.Fill(gJ.pt) for rJ in jets: if (deltaR(gJ.eta, gJ.phi, rJ.eta, rJ.phi) < 0.2): #print 'pt of recojets',rJ.pt self.h2.Fill(rJ.pt) return True
def analyze(self, event): leps = [l for l in Collection(event, 'LepGood') ] ret = [ 0 for l in leps ] if len(leps) == 2: for i,l1 in enumerate(leps): l2 = leps[1-i] if abs(l2.genPartFlav) not in (1,15): continue if l2.mvaTTH < 0.9: continue if deltaR(l1.eta, l1.phi, l2.eta, l2.phi) < 0.8: continue ret[i] = 1 self.out.fillBranch("LepGood_otherLeptonSelection", ret) return True
def mapPFNVPToGenNVP(self): for ieta, iphi in zip(*np.where(self.neuTowers_PF[:, :] > 0)): neuPF = self.neuTowers_PF[ieta, iphi] dRmin = 999 matchedGenNVP = None for ieta, iphi in zip(*np.where(self.neuTowers_Gen[:, :] > 0)): neuGen = self.neuTowers_Gen[ieta, iphi] # skip the gen towers with pt smaller than 0.5 # (to remove more pileup) #if neuGen.pt() < 0.5: # continue dR = deltaR(neuGen.eta, neuGen.phi, neuPF.eta, neuPF.phi) if dR < dRmin: dRmin = dR matchedGenNVP = neuGen if dRmin < 1e-5: break if matchedGenNVP: neuPF.toGenIndex = matchedGenNVP.index neuPF.toGendR = dRmin # calculate hypot(ieta, iphi) dIR = self.segment.deltaIR(matchedGenNVP.eta, matchedGenNVP.phi, neuPF.eta, neuPF.phi) neuPF.toGendIR = dIR if dRmin < matchedGenNVP.toPFmindR: matchedGenNVP.toPFmindRIndex = neuPF.index matchedGenNVP.toPFmindR = dRmin matchedGenNVP.toPFmindRdIR = dIR NVP_PF_toGenIndex = [] NVP_PF_toGendR = [] NVP_PF_toGendIR = [] for ieta, iphi in zip(*np.where(self.neuTowers_PF[:, :] > 0)): NVP_PF_toGenIndex.append(self.neuTowers_PF[ieta, iphi].toGenIndex) NVP_PF_toGendR.append(self.neuTowers_PF[ieta, iphi].toGendR) NVP_PF_toGendIR.append(self.neuTowers_PF[ieta, iphi].toGendIR) NVP_Gen_toPFmindRIndex = [] NVP_Gen_toPFmindR = [] NVP_Gen_toPFmindRdIR = [] for ieta, iphi in zip(*np.where(self.neuTowers_Gen[:, :] > 0)): NVP_Gen_toPFmindRIndex.append( self.neuTowers_Gen[ieta, iphi].toPFmindRIndex) NVP_Gen_toPFmindR.append(self.neuTowers_Gen[ieta, iphi].toPFmindR) NVP_Gen_toPFmindRdIR.append(self.neuTowers_Gen[ieta, iphi].toPFmindRdIR) return NVP_PF_toGenIndex, NVP_PF_toGendR, NVP_PF_toGendIR, NVP_Gen_toPFmindRIndex, NVP_Gen_toPFmindR, NVP_Gen_toPFmindRdIR
def prepareEvent(self, event): logging.debug('processing event %d' % event.event) # # ht selection event.ak4jets = [] for j in event._allJets: if not (j.pt > 25 and abs(j.eta) < 2.4 and (j.jetId & 2)): continue event.ak4jets.append(j) event.ht = sum([j.pt for j in event.ak4jets]) if event.ht < 900.: return False ## selection on AK8 jets / drop if overlaps with a photon event.ak8jets = [] for fj in event._allAK8jets: if not (fj.pt > 200 and abs(fj.eta) < 2.4 and (fj.jetId & 2)): continue event.ak8jets.append(fj) if len(event.ak8jets) < 1: return False ## selection on CA15 jets / drop if overlaps with a photon event.ca15jets = [] for fj in event._allCA15jets: if not (fj.pt > 200 and abs(fj.eta) < 2.4 and (fj.jetId & 2)): continue event.ca15jets.append(fj) if len(event.ca15jets) < 1: return False ## require the leading ak8 & ca15 jets overlap if deltaR(event.ak8jets[0], event.ca15jets[0]) > 0.8: return False # # selection on HOTVR jets event.hotvrjets = [] for fj in event._allHOTVRjets: if not (fj.pt > 200 and abs(fj.eta) < 2.4): continue event.hotvrjets.append(fj) ## return True if passes selection return True
def makeDRMapGenPF(self, GenColl, PFColl): """ save the deltaR values betwee Gen and PF into numpy arrays """ self.AdrGenPF = np.full((len(GenColl), len(PFColl)), np.inf) # map from Gen to PF of the same type (chg to chg, neu to neu, and pho to pho) self.AdrGenPFST = np.full((len(GenColl), len(PFColl)), np.inf) for igp in xrange(len(GenColl)): for ip in xrange(len(PFColl)): dR = deltaR(GenColl[igp].eta, GenColl[igp].phi, PFColl[ip].eta, PFColl[ip].phi) ## only save dR<0.1 values now, to save time in changing np array values #if dR<0.1: self.AdrGenPF[igp, ip] = dR if GenColl[igp].ptype == PFColl[ip].ptype: self.AdrGenPFST[igp, ip] = dR
def match(jet, genjets, resolution, coneSize=0.4): # Try to find a gen jet matching # dR < m_dR_max # dPt < m_dPt_max_factor * resolution minDR = 1e99 matched = None for genj in genjets: dR = deltaR(genj, jet) if dR > minDR: continue if dR < 0.5 * coneSize: dPT = abs(genj.pt - jet.pt) if dPT > 3. * resolution: continue minDR = dR matched = genj return matched
def cleanFromleptonSS(InList, leptonList, dR=0.4): #cross clean leptonList cleplist = [] for lepton in leptonList: for jet in InList: if deltaR(jet, lepton) < dR: #Muons if lepton._prefix.split('_')[0] == "Muon": if lepton.mediumId == 1: #if jet.chHEF>0.1 or (jet.chHEF<0.1 and jet.neHEF>0.2): if jet.chHEF > 0.1 or jet.neHEF > 0.2: #distinct jet leptonList.remove(lepton) break else: #good distinct lepton InList.remove(jet) continue elif lepton.mediumId == 0: #bad distinct lepton InList.remove(jet) #Electrons elif lepton._prefix.split('_')[0] == "Electron": if lepton.cutBased > 0: #if jet.chHEF>0.1 or (jet.chHEF<0.1 and jet.neHEF>0.2): if jet.chHEF > 0.1 or jet.neHEF > 0.2: #distinct jet leptonList.remove(lepton) break else: #good distinct lepton InList.remove(jet) continue elif lepton.cutBased == 0: #bad distinct lepton InList.remove(jet) leptonList.sort(key=getPt, reverse=True) InList.sort(key=getPt, reverse=True)
def mapPFToGen(self, GenColl, PFColl, selGen=lambda x: True, selPF=lambda x:True): # map charged for p in PFColl: if not selPF(p): continue dRmin = p.toGendR matchedIndex = -999 for igp in xrange(len(GenColl)): gp = GenColl[igp] if not selGen(gp): continue dR = deltaR(gp.eta, gp.phi, p.eta, p.phi) if dR < dRmin: dRmin = dR matchedIndex = igp if matchedIndex>=0: gp = GenColl[matchedIndex] p.toGenIndex = gp.index p.toGendR = dRmin gp.toPFN += 1 if dRmin < gp.toPF_mindR: gp.toPF_mindR = dRmin gp.toPF_mindRIndex = p.index
def getIsolations(self, particleColl): """ calculate isolatios for particles in particleColl """ for ip1 in xrange(len(particleColl)): vchg1 = ROOT.TLorentzVector() vneu1 = ROOT.TLorentzVector() vpho1 = ROOT.TLorentzVector() for ip2 in xrange(len(particleColl)): if ip2 == ip1: continue dR = deltaR(particleColl[ip1].eta, particleColl[ip1].phi, particleColl[ip2].eta, particleColl[ip2].phi) if dR < 0.1: p2 = particleColl[ip2] plorenz = p2.p4() vchg1 += plorenz * (p2.ptype == 1) vneu1 += plorenz * (p2.ptype == 2) vpho1 += plorenz * (p2.ptype == 3) p1 = particleColl[ip1] p1.chgIso1 = vchg1.Pt() p1.neuIso1 = vneu1.Pt() p1.phoIso1 = vpho1.Pt()