CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions
python.ParticleDecayDrawer.ParticleDecayDrawer Class Reference
Inheritance diagram for python.ParticleDecayDrawer.ParticleDecayDrawer:

Public Member Functions

def __init__ (self)
 
def draw (self, particles)
 

Private Member Functions

def _accept (self, candidate, skipList)
 
def _decay (self, candidate, skipList)
 
def _hasValidDaughters (self, candidate)
 
def _printP4 (self, candidate)
 
def _select (self, candidate)
 

Detailed Description

Draws particle decay tree 

Definition at line 7 of file ParticleDecayDrawer.py.

Constructor & Destructor Documentation

def python.ParticleDecayDrawer.ParticleDecayDrawer.__init__ (   self)

Definition at line 10 of file ParticleDecayDrawer.py.

10  def __init__(self):
11  print "Init particleDecayDrawer"
12  # booleans: printP4 printPtEtaPhi printVertex
13 

Member Function Documentation

def python.ParticleDecayDrawer.ParticleDecayDrawer._accept (   self,
  candidate,
  skipList 
)
private

Definition at line 14 of file ParticleDecayDrawer.py.

References python.ParticleDecayDrawer.ParticleDecayDrawer._select().

Referenced by python.ParticleDecayDrawer.ParticleDecayDrawer._decay().

14  def _accept(self, candidate, skipList):
15  if candidate in skipList: return False;
16  return self._select(candidate)
17 
def python.ParticleDecayDrawer.ParticleDecayDrawer._decay (   self,
  candidate,
  skipList 
)
private

Definition at line 30 of file ParticleDecayDrawer.py.

References python.ParticleDecayDrawer.ParticleDecayDrawer._accept(), python.ParticleDecayDrawer.ParticleDecayDrawer._decay(), python.ParticleDecayDrawer.ParticleDecayDrawer._printP4(), and str.

Referenced by python.ParticleDecayDrawer.ParticleDecayDrawer._decay(), and python.ParticleDecayDrawer.ParticleDecayDrawer.draw().

30  def _decay(self, candidate, skipList):
31 
32  out = str()
33  if candidate in skipList:
34  return ""
35  skipList.append(candidate)
36 
37  id = candidate.pdg_id()
38  # here the part about the names :-(
39  out += str(id) + self._printP4(candidate)
40 
41  validDau = 0
42  nOfDaughters = candidate.numChildren()
43  for i in xrange(nOfDaughters):
44  if self._accept(candidate.listChildren()[i], skipList): validDau+=1
45  if validDau == 0: return out
46 
47  out += " ->"
48 
49  for i in xrange(nOfDaughters):
50  d = candidate.listChildren()[i]
51  if self._accept(d, skipList):
52  decString = self._decay(d, skipList)
53  if ("->" in decString): out += " ( %s ) " %decString
54  else: out += " %s" %decString
55  return out
56 
#define str(s)
def python.ParticleDecayDrawer.ParticleDecayDrawer._hasValidDaughters (   self,
  candidate 
)
private

Definition at line 21 of file ParticleDecayDrawer.py.

References python.ParticleDecayDrawer.ParticleDecayDrawer._select().

21  def _hasValidDaughters(self, candidate):
22  nDaughters = candidate.numChildren()
23  for i in xrange(nDaughters):
24  if self._select(candidate.listChildren()[i]): return True
25  return False
26 
def python.ParticleDecayDrawer.ParticleDecayDrawer._printP4 (   self,
  candidate 
)
private

Definition at line 27 of file ParticleDecayDrawer.py.

Referenced by python.ParticleDecayDrawer.ParticleDecayDrawer._decay().

27  def _printP4(self, candidate):
28  return " "
29 
def python.ParticleDecayDrawer.ParticleDecayDrawer._select (   self,
  candidate 
)
private
def python.ParticleDecayDrawer.ParticleDecayDrawer.draw (   self,
  particles 
)
draw decay tree from list(HepMC.GenParticles)

Definition at line 57 of file ParticleDecayDrawer.py.

References python.ParticleDecayDrawer.ParticleDecayDrawer._decay(), and python.ParticleDecayDrawer.ParticleDecayDrawer._select().

57  def draw(self, particles):
58  """ draw decay tree from list(HepMC.GenParticles)"""
59  skipList = []
60  nodesList = []
61  momsList = []
62  for particle in particles:
63  if particle.numParents() > 1:
64  if self._select(particle):
65  skipList.append(particle)
66  nodesList.append(particle)
67  for j in xrange(particle.numParents()):
68  mom = particle.listParents()[j]
69  while (mom.mother()):# != None ):
70  mom = mom.mother()
71  if self._select(mom):
72  momsList.append(mom)
73 
74  print "-- decay --"
75  if len(momsList) > 0:
76  if len(momsList) > 1:
77  for m in xrange(len(momsList)):
78  decString = self._decay( momsList[m], skipList)
79  if len(decString) > 0:
80  print "{ %s } " %decString
81  else:
82  print self._decay(momsList[0], skipList)
83 
84  if len(nodesList) > 0:
85  print "-> "
86  if len(nodesList) > 1:
87  for node in nodesList:
88  skipList.remove(node)
89  decString = self._decay(node, skipList)
90  if len(decString) > 0:
91  if "->" in decString: print " ( %s ) " %decString
92  else: print " " + decString
93  else:
94  skipList.remove(nodesList[0])
95  print self._decay(nodesList[0], skipList)
96 
97  print
98