ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
PyAnalysis
PyAnalysisUtils
python
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
10
"""Dump out MC truth information.
11
12
This module contains the function dump_truth which will dump out the
13
truth information for the current event in a tabular format.
14
"""
15
16
from
PyAnalysisUtils
import
PDG
17
from
PyParticleTools
import
PyParticleTools
18
import
sys
19
20
def
do_decay
(t, n):
21
"""Return the unique ID number for decay N of truth particle T
22
as a string. Return an empty string if there's no such decay.
23
"""
24
if
t.nDecay() <= n:
25
return
''
26
bc = t.child(n).genParticle().id()
27
return
str(bc)
28
29
class
_Truthtmp
(object):
30
pass
31
def
dump_one_truth
(t, f=sys.stdout):
32
"""Dump truth information for truth particle T to file F."""
33
d = _Truthtmp()
34
d.bc = t.genParticle().id()
35
d.name = PDG.pdgid_to_name(t.pdgId())
36
d.da1 =
do_decay
(t, 0)
37
d.da2 =
do_decay
(t, 1)
38
d.da3 =
do_decay
(t, 2)
39
d.pt = t.pt()/1000
40
d.eta = t.eta()
41
d.phi = t.phi()
42
d.m = t.m()/1000
43
d.px = t.px()/1000
44
d.py = t.py()/1000
45
d.pz = t.pz()/1000
46
d.e = t.e()/1000
47
print
(
"%(id)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)
48
if
t.nDecay() > 3:
49
print
(
" (more than 3 decays)"
, file=f)
50
51
52
def
dump_truth
(f=sys.stdout, sgkey="SpclMC", maxn=None):
53
"""Dump out truth information for the current event.
54
F is the file to which the dump is sent.
55
SGKEY is the StoreGate key which is used to retrieve the truth information.
56
57
The first column in the dump is the particle unique ID number.
58
This is followed by the particle type, and then by the unique ID numbers
59
of any decay daughters (up to 3). This is followed by the four-momentum
60
in two versions: first as pt, eta, phi, m and then as px, py, pz, e.
61
"""
62
parts = [p
for
p
in
PyParticleTools.getTruthParticles (sgkey)]
63
if
maxn
is
not
None
:
64
parts = parts[:maxn]
65
for
t
in
parts:
66
dump_one_truth (t, f)
67
return
python.truth._Truthtmp
Definition
truth.py:29
python.truth.dump_truth
dump_truth(f=sys.stdout, sgkey="SpclMC", maxn=None)
Definition
truth.py:52
python.truth.dump_one_truth
dump_one_truth(t, f=sys.stdout)
Definition
truth.py:31
python.truth.do_decay
do_decay(t, n)
Definition
truth.py:20
Generated on
for ATLAS Offline Software by
1.17.0