CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
genutils.py
Go to the documentation of this file.
1 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import printOut
2 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import GenParticle
3 
4 def findStatus1Leptons(particle):
5  '''Returns status 1 e and mu among the particle daughters'''
6  leptons = []
7  for i in range( particle.numberOfDaughters() ):
8  dau = particle.daughter(i)
9  if dau.status() == 1:
10  if abs(dau.pdgId())==11 or abs(dau.pdgId())==13:
11  leptons.append( dau )
12  else:
13  continue
14  else:
15  leptons = findStatus1Leptons( dau, leptons )
16  return leptons
17 
18 
19 def allDaughters(particle, daughters, rank ):
20  '''Fills daughters with all the daughters of particle.
21  Recursive function.'''
22  rank += 1
23  for i in range( particle.numberOfDaughters() ):
24  dau = GenParticle(particle.daughter(i))
25  dau.rank = rank
26  daughters.append( dau )
27  daughters = allDaughters( dau, daughters, rank )
28  return daughters
29 
30 
31 def bosonToX(particles, bosonType, xType):
32  bosons = filter(lambda x: x.status()==3 and x.pdgId()==bosonType, particles)
33  daughters = []
34  if len(bosons)==0:
35  return [], False
36  boson = bosons[0]
37  daus = []
38  allDaughters( boson, daus, 0)
39  xDaus = filter(lambda x: x.status()==3 and abs(x.pdgId())==xType, daus)
40  # print printOut(xDaus)
41  return xDaus, True
42 
43 def isNotHadronicId(pdgId,includeSMLeptons=True):
44  if abs(pdgId) in [11,12,13,14,15,16]:
45  return includeSMLeptons
46  i = (abs(pdgId) % 1000)
47  return i > 10 and i != 21 and i < 100
48 
49 def isPromptLepton(lepton, beforeFSR, includeMotherless=True, includeTauDecays=False):
50  if abs(lepton.pdgId()) not in [11,13,15]:
51  return False
52  if lepton.numberOfMothers() == 0:
53  return includeMotherless;
54  mom = lepton.mother()
55  if mom.pdgId() == lepton.pdgId():
56  if beforeFSR: return False
57  return isPromptLepton(mom, beforeFSR, includeMotherless, includeTauDecays)
58  elif abs(mom.pdgId()) == 15:
59  if not includeTauDecays: return False
60  return isPromptLepton(mom, beforeFSR, includeMotherless, includeTauDecays)
61  else:
62  return isNotHadronicId(mom.pdgId(), includeSMLeptons=False)
63 
64 
66  for x in xrange(l.numberOfMothers()):
67  mom = l.mother(x)
68  if mom.status() > 2: return True
69  id = abs(mom.pdgId())
70  if id > 100: return False
71  if id < 6: return False
72  if id == 21: return False
73  if id in [11,13,15]: return isNotFromHadronicShower(mom)
74  if id >= 22 and id <= 39: return True
75  return True
76 
77 def realGenDaughters(gp,excludeRadiation=True):
78  """Get the daughters of a particle, going through radiative X -> X' + a
79  decays, either including or excluding the radiation among the daughters
80  e.g. for
81  X -> X' + a, X' -> b c
82  realGenDaughters(X, excludeRadiation=True) = { b, c }
83  realGenDaughters(X, excludeRadiation=False) = { a, b, c }"""
84  ret = []
85  for i in xrange(gp.numberOfDaughters()):
86  dau = gp.daughter(i)
87  if dau.pdgId() == gp.pdgId():
88  if excludeRadiation:
89  return realGenDaughters(dau)
90  else:
91  ret += realGenDaughters(dau)
92  else:
93  ret.append(dau)
94  return ret
95 
97  """Get the mothers of a particle X going through intermediate X -> X' chains.
98  e.g. if Y -> X, X -> X' realGenMothers(X') = Y"""
99  ret = []
100  for i in xrange(gp.numberOfMothers()):
101  mom = gp.mother(i)
102  if mom.pdgId() == gp.pdgId():
103  ret += realGenMothers(mom)
104  else:
105  ret.append(mom)
106  return ret
107 
108 
109 
def realGenMothers
Definition: genutils.py:96
def allDaughters
Definition: genutils.py:19
def isNotFromHadronicShower
Definition: genutils.py:65
def realGenDaughters
Definition: genutils.py:77
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def isNotHadronicId
Definition: genutils.py:43
def findStatus1Leptons
Definition: genutils.py:4
def bosonToX
Definition: genutils.py:31
def isPromptLepton
Definition: genutils.py:49