CMS 3D CMS Logo

ParticleDecayDrawer.py
Go to the documentation of this file.
1 from __future__ import print_function
2 # Benedikt Hegner, DESY
3 # benedikt.hegner@cern.ch
4 #
5 # this tool is based on Luca Lista's tree drawer module
6 
7 
8 from builtins import range
10  """Draws particle decay tree """
11 
12  def __init__(self):
13  print("Init particleDecayDrawer")
14  # booleans: printP4 printPtEtaPhi printVertex
15 
16  def _accept(self, candidate, skipList):
17  if candidate in skipList: return False;
18  return self._select(candidate)
19 
20  def _select(self, candidate):
21  return candidate.status() == 3
22 
23  def _hasValidDaughters(self, candidate):
24  nDaughters = candidate.numChildren()
25  for i in range(nDaughters):
26  if self._select(candidate.listChildren()[i]): return True
27  return False
28 
29  def _printP4(self, candidate):
30  return " "
31 
32  def _decay(self, candidate, skipList):
33 
34  out = str()
35  if candidate in skipList:
36  return ""
37  skipList.append(candidate)
38 
39  id = candidate.pdg_id()
40  # here the part about the names :-(
41  out += str(id) + self._printP4(candidate)
42 
43  validDau = 0
44  nOfDaughters = candidate.numChildren()
45  for i in range(nOfDaughters):
46  if self._accept(candidate.listChildren()[i], skipList): validDau+=1
47  if validDau == 0: return out
48 
49  out += " ->"
50 
51  for i in range(nOfDaughters):
52  d = candidate.listChildren()[i]
53  if self._accept(d, skipList):
54  decString = self._decay(d, skipList)
55  if ("->" in decString): out += " ( %s ) " %decString
56  else: out += " %s" %decString
57  return out
58 
59  def draw(self, particles):
60  """ draw decay tree from list(HepMC.GenParticles)"""
61  skipList = []
62  nodesList = []
63  momsList = []
64  for particle in particles:
65  if particle.numParents() > 1:
66  if self._select(particle):
67  skipList.append(particle)
68  nodesList.append(particle)
69  for j in range(particle.numParents()):
70  mom = particle.listParents()[j]
71  while (mom.mother()):# != None ):
72  mom = mom.mother()
73  if self._select(mom):
74  momsList.append(mom)
75 
76  print("-- decay --")
77  if len(momsList) > 0:
78  if len(momsList) > 1:
79  for m in range(len(momsList)):
80  decString = self._decay( momsList[m], skipList)
81  if len(decString) > 0:
82  print("{ %s } " %decString)
83  else:
84  print(self._decay(momsList[0], skipList))
85 
86  if len(nodesList) > 0:
87  print("-> ")
88  if len(nodesList) > 1:
89  for node in nodesList:
90  skipList.remove(node)
91  decString = self._decay(node, skipList)
92  if len(decString) > 0:
93  if "->" in decString: print(" ( %s ) " %decString)
94  else: print(" " + decString)
95  else:
96  skipList.remove(nodesList[0])
97  print(self._decay(nodesList[0], skipList))
98 
99  print()
100 
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
python.ParticleDecayDrawer.ParticleDecayDrawer._hasValidDaughters
def _hasValidDaughters(self, candidate)
Definition: ParticleDecayDrawer.py:23
python.ParticleDecayDrawer.ParticleDecayDrawer._accept
def _accept(self, candidate, skipList)
Definition: ParticleDecayDrawer.py:16
str
#define str(s)
Definition: TestProcessor.cc:52
python.ParticleDecayDrawer.ParticleDecayDrawer.draw
def draw(self, particles)
Definition: ParticleDecayDrawer.py:59
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
python.ParticleDecayDrawer.ParticleDecayDrawer.__init__
def __init__(self)
Definition: ParticleDecayDrawer.py:12
python.ParticleDecayDrawer.ParticleDecayDrawer
Definition: ParticleDecayDrawer.py:9
python.ParticleDecayDrawer.ParticleDecayDrawer._printP4
def _printP4(self, candidate)
Definition: ParticleDecayDrawer.py:29
python.ParticleDecayDrawer.ParticleDecayDrawer._decay
def _decay(self, candidate, skipList)
Definition: ParticleDecayDrawer.py:32
python.ParticleDecayDrawer.ParticleDecayDrawer._select
def _select(self, candidate)
Definition: ParticleDecayDrawer.py:20