test
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 > 1000000: return True
71  if id > 100: return False
72  if id < 6: return False
73  if id == 21: return False
74  if id in [11,12,13,14,15,16]:
75  if l.status() > 2: return True
76  return isNotFromHadronicShower(mom)
77  if id >= 22 and id <= 39: return True
78  return True
79 
80 def realGenDaughters(gp,excludeRadiation=True):
81  """Get the daughters of a particle, going through radiative X -> X' + a
82  decays, either including or excluding the radiation among the daughters
83  e.g. for
84  X -> X' + a, X' -> b c
85  realGenDaughters(X, excludeRadiation=True) = { b, c }
86  realGenDaughters(X, excludeRadiation=False) = { a, b, c }"""
87  ret = []
88  for i in xrange(gp.numberOfDaughters()):
89  dau = gp.daughter(i)
90  if dau.pdgId() == gp.pdgId():
91  if excludeRadiation:
92  return realGenDaughters(dau)
93  else:
94  ret += realGenDaughters(dau)
95  else:
96  ret.append(dau)
97  return ret
98 
100  """Get the mothers of a particle X going through intermediate X -> X' chains.
101  e.g. if Y -> X, X -> X' realGenMothers(X') = Y"""
102  ret = []
103  for i in xrange(gp.numberOfMothers()):
104  mom = gp.mother(i)
105  if mom.pdgId() == gp.pdgId():
106  ret += realGenMothers(mom)
107  else:
108  ret.append(mom)
109  return ret
110 
111 def lastGenCopy(gp):
112  me = gp.pdgId();
113  for i in xrange(gp.numberOfDaughters()):
114  if gp.daughter(i).pdgId() == me:
115  return False
116  return True
117 
118 
def lastGenCopy
Definition: genutils.py:111
def realGenMothers
Definition: genutils.py:99
def allDaughters
Definition: genutils.py:19
def isNotFromHadronicShower
Definition: genutils.py:65
def realGenDaughters
Definition: genutils.py:80
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