def getBoson(event): """Calculate Z/W/H boson full and visible pT and mass, for recoil corrections.""" #print '-'*80 particles = Collection(event, 'GenPart') #boson_real = TLorentzVector() boson_full = TLorentzVector() boson_vis = TLorentzVector() for id in range(event.nGenPart): particle = particles[id] PID = abs(particle.pdgId) neutrino = PID in [12, 14, 16] #if PID in [23,24,25] and particle.status==62: # boson_real = particle.p4() # print "%3d: PID=%3d, mass=%3.1f, pt=%3.1f, status=%2d"%(id,particle.pdgId,particle.mass,particle.pt,particle.status) if ((PID == 11 or PID == 13 or neutrino) and particle.status == 1 and hasBit(particle.statusFlags, 8)) or hasBit( particle.statusFlags, 10): boson_full += particle.p4() if not neutrino: boson_vis += particle.p4() #print "%3d: PID=%3d, mass=%3.1f, pt=%4.1f, status=%2d, statusFlags=%5d (%16s), fromHardProcess=%1d, isHardProcessTauDecayProduct=%1d, isDirectHardProcessTauDecayProduct=%1d"%\ #(id,particle.pdgId,particle.mass,particle.pt,particle.status,particle.statusFlags,bin(particle.statusFlags),hasBit(particle.statusFlags,8),hasBit(particle.statusFlags,9),hasBit(particle.statusFlags,10)) #print "real: mass=%3.1f, pt=%3.1f"%(boson_real.M(),boson_real.Pt()) #print "full: mass=%3.1f, pt=%3.1f"%(boson_full.M(),boson_full.Pt()) #print "vis: mass=%3.1f, pt=%3.1f"%(boson_vis.M(),boson_vis.Pt()) return boson_full, boson_vis
def getZBoson(event): """Calculate Z boson pT and mass.""" #print '-'*80 particles = Collection(event, 'GenPart') zboson = TLorentzVector() for id in range(event.nGenPart): particle = particles[id] PID = abs(particle.pdgId) if ((PID==11 or PID==13) and particle.status==1 and hasBit(particle.statusFlags,8)) or\ (PID==15 and particle.status==2 and hasBit(particle.statusFlags,8)): zboson += particle.p4() #print "%3d: PID=%3d, mass=%3.1f, pt=%4.1f, status=%2d, statusFlags=%5d (%16s), fromHardProcess=%1d, isHardProcessTauDecayProduct=%1d, isDirectHardProcessTauDecayProduct=%1d"%\ #(id,particle.pdgId,particle.mass,particle.pt,particle.status,particle.statusFlags,bin(particle.statusFlags),hasBit(particle.statusFlags,8),hasBit(particle.statusFlags,9),hasBit(particle.statusFlags,10)) #print "tlv: mass=%3.1f, pt=%3.1f"%(zboson.M(),zboson.Pt()) return zboson
def hasTop(event): """Return True if a top quark is found. (Used for LQ signal samples, with inclusive decays containing a b or top quark.)""" for id in range(event.nGenPart): if abs(event.GenPart_pdgId[id]) == 6 and hasBit( event.GenPart_statusFlags[id], 13): return True return False
def countTops(event): """Count number of tops in a given event. (Used for LQ signal samples, with inclusive decays containing a b or top quark.)""" ntops = 0 for id in range(event.nGenPart): if abs(event.GenPart_pdgId[id]) == 6 and hasBit( event.GenPart_statusFlags[id], 13): ntops += 1 return ntops
def genmatch(event, index, out=None): """Match reco tau to gen particles, as there is a bug in the nanoAOD matching for lepton to tau fakes of taus reconstructed as DM1.""" genmatch = 0 dR_min = 0.2 particles = Collection(event, 'GenPart') eta_reco = event.Tau_eta[index] phi_reco = event.Tau_phi[index] # lepton -> tau fakes for id in range(event.nGenPart): particle = particles[id] PID = abs(particle.pdgId) if (particle.status != 1 and PID != 13) or particle.pt < 8: continue dR = deltaR(eta_reco, phi_reco, particle.eta, particle.phi) if dR < dR_min: if hasBit(particle.statusFlags, 0): # isPrompt if PID == 11: genmatch = 1 dR_min = dR elif PID == 13: genmatch = 2 dR_min = dR elif hasBit(particle.statusFlags, 5): # isDirectPromptTauDecayProduct if PID == 11: genmatch = 3 dR_min = dR elif PID == 13: genmatch = 4 dR_min = dR # real tau leptons for id in range(event.nGenVisTau): dR = deltaR(eta_reco, phi_reco, event.GenVisTau_eta[id], event.GenVisTau_phi[id]) if dR < dR_min: dR_min = dR genmatch = 5 return genmatch