Skip to content

Commit

Permalink
Merge pull request cms-sw#142 from mariadalfonso/fixesListAndGen
Browse files Browse the repository at this point in the history
Fixes list and gen
  • Loading branch information
gpetruc committed Nov 23, 2014
2 parents 3cc7a25 + 4682b69 commit eb9c8a1
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def __init__(self, cfg_ana, cfg_comp, looperName):
})
self.collections.update({
# put more here
"gennus" : NTupleCollection("genNu", genParticleWithSourceType, 10, help="Generated neutrinos (nue/numu/nutau) from W/Z decays"),
"selectedLeptons" : NTupleCollection("lep", leptonTypeSusy, 50, help="Leptons after the preselection", filter=lambda l : l.pt()>10 ),
"selectedTaus" : NTupleCollection("tau", tauTypeSusy, 50, help="Taus after the preselection"),
"cleanJetsAll" : NTupleCollection("jet", jetTypeSusy, 100, help="all jets (w/ x-cleaning, w/ ID applied w/o PUID applied pt>10 |eta|<5.2) , sorted by pt", filter=lambda l : l.pt()>10 ),
Expand Down
30 changes: 29 additions & 1 deletion CMGTools/TTHAnalysis/python/analyzers/ttHGenLevelAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ttHGenLevelAnalyzer( Analyzer ):
event.genleps = [ gen electrons and muons from hard scattering not from tau decays ]
event.genbquarks = [ gen b quarks from top quark decays ]
event.genwzquarks = [ gen quarks from hadronic W,Z decays ]
event.gennus = [ gen nus from from Z,W ]
If filterHiggsDecays is set to a list of Higgs decay modes,
it will filter events that have those decay modes.
Expand Down Expand Up @@ -71,7 +72,9 @@ def fillGenLeptons(self, event, particle, isTau=False, sourceId=25):
dau.sourceId = sourceId
dau.isTau = isTau
id = abs(dau.pdgId())
moid = abs(dau.mother().pdgId())
moid = 0;
if dau.numberOfMothers() > 0:
moid = abs(dau.mother().pdgId())
if id in [11,13]:
if isTau: event.gentauleps.append(dau)
else: event.genleps.append(dau)
Expand All @@ -81,6 +84,8 @@ def fillGenLeptons(self, event, particle, isTau=False, sourceId=25):
self.fillGenLeptons(event, dau, True, sourceId)
elif id in [22,23,24]:
self.fillGenLeptons(event, dau, False, sourceId)
elif id in [12,14,16]:
event.gennus.append(dau)

def fillWZQuarks(self, event, particle, isWZ=False, sourceId=25):
"""Descend daughters of 'particle', and add quarks from W,Z to event.genwzquarks
Expand Down Expand Up @@ -130,6 +135,8 @@ def makeMCInfo(self, event):
print ""

event.genHiggsBoson = None
event.genVBosons = []
event.gennus = []
event.genleps = []
event.gentauleps = []
event.gentaus = []
Expand Down Expand Up @@ -162,11 +169,31 @@ def hasDescendent(particle, filter):
return False

bosons = [ gp for gp in event.genParticles if gp.status() > 2 and abs(gp.pdgId()) in [22,23,24] ]

if self.cfg_ana.verbose:
print "\n =============="
for i,p in enumerate(bosons):
print " %5d: pdgId %+5d status %3d pt %6.1f " % (i, p.pdgId(),p.status(),p.pt()),
if p.numberOfMothers() > 0:
imom, mom = p.motherRef().key(), p.mother()
print " | mother %5d pdgId %+5d status %3d pt %6.1f " % (imom, mom.pdgId(),mom.status(),mom.pt()),
else:
print " | no mother particle ",

for j in xrange(min(3, p.numberOfDaughters())):
idau, dau = p.daughterRef(j).key(), p.daughter(j)
print " | dau[%d] %5d pdgId %+5d status %3d pt %6.1f " % (j,idau,dau.pdgId(),dau.status(),dau.pt()),
print ""

for b in bosons:
b.sourceId = -1
if hasAncestor(b, lambda gp : abs(gp.pdgId()) == 6): continue
if hasDescendent(b, lambda gp : abs(gp.pdgId()) in [22,23,24] and gp.status() > 2): continue
self.fillGenLeptons(event, b, sourceId=abs(b.pdgId()))
self.fillWZQuarks(event, b, isWZ=True, sourceId=abs(b.pdgId()))
#print " ===> %5d: pdgId %+5d status %3d pt %6.1f " % (i, b.pdgId(),b.status(),b.pt()),
#event.genVBosons.append(b)

else:
if len(higgsBosons) > 1:
print "More than one higgs? \n%s\n" % higgsBosons
Expand All @@ -179,6 +206,7 @@ def hasDescendent(particle, filter):
self.fillGenLeptons( event, event.genHiggsBoson, sourceId=25 )
if self.cfg_ana.verbose:
print "Higgs boson decay mode: ", event.genHiggsDecayMode
print "Generator level prompt nus:\n", "\n".join(["\t%s" % p for p in event.gennus])
print "Generator level prompt light leptons:\n", "\n".join(["\t%s" % p for p in event.genleps])
print "Generator level light leptons from taus:\n", "\n".join(["\t%s" % p for p in event.gentauleps])
print "Generator level prompt tau leptons:\n", "\n".join(["\t%s" % p for p in event.gentaus])
Expand Down
Loading

0 comments on commit eb9c8a1

Please sign in to comment.