Example #1
0
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
Example #2
0
def fillFlagHistogram(hist,particle):
  """Fill histograms with status flags for genPartFlav check."""
  if hasBit(particle.statusFlags, 0): hist.Fill( 0) # isPrompt
  if hasBit(particle.statusFlags, 5): hist.Fill( 1) # isDirectPromptTauDecayProduct
  if hasBit(particle.statusFlags, 7): hist.Fill( 2) # isHardProcess
  if hasBit(particle.statusFlags, 8): hist.Fill( 3) # fromHardProcess
  if hasBit(particle.statusFlags,10): hist.Fill( 4) # isDirectHardProcessTauDecayProduct
  if hasBit(particle.statusFlags,11): hist.Fill( 5) # fromHardProcessBeforeFSR
  if hasBit(particle.statusFlags,12): hist.Fill( 6) # isFirstCopy
  if hasBit(particle.statusFlags,13): hist.Fill( 7) # isLastCop
  if hasBit(particle.statusFlags,14): hist.Fill( 8) # isLastCopyBeforeFSR
  if   particle.status==1:            hist.Fill( 9) # status==1
  elif particle.status==23:           hist.Fill(10) # status==23
  elif particle.status==44:           hist.Fill(11) # status==44
  elif particle.status==51:           hist.Fill(12) # status==51
  elif particle.status==52:           hist.Fill(13) # status==52
  else:                               hist.Fill(14) # other status
Example #3
0
def genmatchCheck(event,index,out):
    """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."""
    #print '-'*80
    genmatch  = 0
    #partmatch_s1 = None
    #partmatch_sn1 = None # status != 1
    dR_min    = 1.0
    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 or particle.pt<8: continue
      #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
            #if particle.status==1: partmatch_s1 = particle
            #else:                  partmatch_sn1 = particle
          elif PID==13:
            genmatch = 2; dR_min = dR
            #if particle.status==1: partmatch_s1 = particle
            #else:                  partmatch_sn1 = particle
        elif hasBit(particle.statusFlags,5): # isDirectPromptTauDecayProduct
          if   PID==11:
            genmatch = 3; dR_min = dR
            #if particle.status==1: partmatch_s1 = particle
            #else:                  partmatch_sn1 = particle
          elif PID==13:
            genmatch = 4; dR_min = dR
            #if particle.status==1: partmatch_s1 = particle
            #else:                  partmatch_sn1 = particle
        #if particle.status!=1 and particle.status!=23:
        # mother = abs(particles[particle.genPartIdxMother].pdgId) if hasattr(particle,'genPartIdxMother') and particle.genPartIdxMother>0 else 0
        # print "%3d: PID=%3d, mass=%3.1f, pt=%4.1f, status=%2d, mother=%2d, statusFlags=%5d (%16s), isPrompt=%d, isDirectPromptTauDecayProduct=%d, fromHardProcess=%1d, isHardProcessTauDecayProduct=%1d, isDirectHardProcessTauDecayProduct=%1d"%\
        # (id,particle.pdgId,particle.mass,particle.pt,particle.status,mother,particle.statusFlags,bin(particle.statusFlags),hasBit(particle.statusFlags,0),hasBit(particle.statusFlags,5),hasBit(particle.statusFlags,8),hasBit(particle.statusFlags,9),hasBit(particle.statusFlags,10))
    
    # 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
    
    ## CHECKS
    #if genmatch!=ord(event.Tau_genPartFlav[index]):
    # #mother = abs(particles[partmatch_s1.genPartIdxMother].pdgId) if hasattr(partmatch_s1,'genPartIdxMother') else 0
    # #print "gen mismatch: Tau_genPartFlav = %s, genmatch = %s, Tau_decayMode = %2s, mother = %s"%(ord(event.Tau_genPartFlav[index]),genmatch,event.Tau_decayMode[index],mother)
    # if genmatch>0 and genmatch<5 and event.Tau_decayMode[index]==1:
    #   if partmatch_s1:
    #     fillFlagHistogram(out.flags_LTF_mis,partmatch_s1)
    #   elif partmatch_sn1:
    #     fillFlagHistogram(out.flags_LTF_mis_sn1,partmatch_sn1)
    #
    ## CHECK status and flags
    #if genmatch>0 and genmatch<5:
    # if event.Tau_decayMode[index]==0:
    #   if partmatch_s1:
    #     fillFlagHistogram(out.flags_LTF_DM0,partmatch_s1)       
    #   elif partmatch_sn1:
    #     fillFlagHistogram(out.flags_LTF_DM0_sn1,partmatch_sn1)
    # elif event.Tau_decayMode[index]==1:
    #   if partmatch_s1:
    #     fillFlagHistogram(out.flags_LTF_DM1,partmatch_s1)
    #   elif partmatch_sn1:
    #     fillFlagHistogram(out.flags_LTF_DM1_sn1,partmatch_sn1)
    #     #if partmatch_sn1.status not in [23,44,52]:
    #     #  print partmatch_sn1.status
    #
    ## CHECK correlation
    #out.genmatch_corr.Fill(ord(event.Tau_genPartFlav[index]),genmatch)
    #if event.Tau_decayMode[index]==0:
    # out.genmatch_corr_DM0.Fill(ord(event.Tau_genPartFlav[index]),genmatch)
    #if event.Tau_decayMode[index]==1:
    # out.genmatch_corr_DM1.Fill(ord(event.Tau_genPartFlav[index]),genmatch)
    
    return genmatch