ATLAS Offline Software
truth.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 #
4 # File: truth.py
5 # Created: sss, March 2005.
6 # Purpose: Dump out MC truth information.
7 #
8 
9 from __future__ import print_function
10 
11 """Dump out MC truth information.
12 
13 This module contains the function dump_truth which will dump out the
14 truth information for the current event in a tabular format.
15 """
16 
17 from PyAnalysisUtils import PDG
18 from PyParticleTools import PyParticleTools
19 import sys
20 
21 def do_decay (t, n):
22  """Return the barcode number for decay N of truth particle T
23 as a string. Return an empty string if there's no such decay.
24 """
25  if t.nDecay() <= n:
26  return ''
27  bc = t.child(n).genParticle().barcode()
28  return str(bc)
29 
31  pass
32 def dump_one_truth (t, f=sys.stdout):
33  """Dump truth information for truth particle T to file F."""
34  d = _Truthtmp()
35  d.bc = t.genParticle().barcode()
36  d.name = PDG.pdgid_to_name(t.pdgId())
37  d.da1 = do_decay(t, 0)
38  d.da2 = do_decay(t, 1)
39  d.da3 = do_decay(t, 2)
40  d.pt = t.pt()/1000
41  d.eta = t.eta()
42  d.phi = t.phi()
43  d.m = t.m()/1000
44  d.px = t.px()/1000
45  d.py = t.py()/1000
46  d.pz = t.pz()/1000
47  d.e = t.e()/1000
48  print ("%(bc)3d %(name)-4s %(da1)4s %(da2)4s %(da3)4s %(pt)6.1f %(eta)5.2f %(phi)5.2f %(m)5.1f %(px)6.1f %(py)6.1f %(pz)6.1f %(e)6.1f" % d.__dict__, file=f)
49  if t.nDecay() > 3:
50  print (" (more than 3 decays)", file=f)
51 
52 
53 def dump_truth(f=sys.stdout, sgkey="SpclMC", maxn=None):
54  """Dump out truth information for the current event.
55 F is the file to which the dump is sent.
56 SGKEY is the StoreGate key which is used to retrieve the truth information.
57 
58 The first column in the dump is the particle barcode number.
59 This is followed by the particle type, and then by the barcode numbers
60 of any decay daughters (up to 3). This is followed by the four-momentum
61 in two versions: first as pt, eta, phi, m and then as px, py, pz, e.
62 """
63  parts = [p for p in PyParticleTools.getTruthParticles (sgkey)]
64  if maxn is not None:
65  parts = parts[:maxn]
66  for t in parts:
67  dump_one_truth (t, f)
68  return
python.truth.do_decay
def do_decay(t, n)
Definition: truth.py:21
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
python.truth.dump_truth
def dump_truth(f=sys.stdout, sgkey="SpclMC", maxn=None)
Definition: truth.py:53
python.truth.dump_one_truth
def dump_one_truth(t, f=sys.stdout)
Definition: truth.py:32
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
python.truth._Truthtmp
Definition: truth.py:30