ATLAS Offline Software
PhysicsAnalysis
TruthParticleID
McParticleUtils
python
DecayParser.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2
3
# @file: McParticleUtils/python/DecayParser.py
4
# @purpose: implement the parsing/tokenization of decay-patterns' strings
5
# @author: Sebastien Binet <binet@cern.ch>
6
7
8
import
re
9
10
_slot_separator =
"+"
11
_candidate_sep =
"|"
12
_decay_arrow =
"->"
13
_wild_card =
"*"
14
15
def
py_parse
(cmd):
16
# remove all spaces to ease further parsing
17
cmd = re.sub(pattern=
" "
,
18
repl=
""
,
19
string=cmd)
20
21
22
if
cmd == _decay_arrow:
23
# special case of a single arrow without any parent nor child:
24
# this decay pattern will select every single vertex
25
return
(0,
None
,
None
)
26
buf = cmd.split (_decay_arrow)
27
assert
(len(buf)==2)
28
29
30
parents = process_block (buf[0])
31
children= process_block (buf[1])
32
33
return
(0, parents, children)
34
35
def
process_block
(cmd):
36
if
cmd ==
""
:
37
return
None
38
candidates = cmd.split (_slot_separator)
39
return
[
list
(
set
(c.split(_candidate_sep)))
for
c
in
candidates]
40
41
42
if
__name__ ==
"__main__"
:
43
print
(
":"
*80)
44
print
(
"::: tests..."
)
45
for
cmd
in
(
"-1|-2|-3|-4|-5|-6|21 + 1|2|3|4|5|6|21 -> "
,
46
"-> 91|92|94"
47
):
48
print
(
"::: testing [%s]..."
% cmd)
49
print
(
"::: result:"
,py_parse (cmd))
50
51
print
(
"::: bye."
)
52
print
(
":"
*80)
53
python.DecayParser.py_parse
def py_parse(cmd)
Definition:
DecayParser.py:15
histSizes.list
def list(name, path='/')
Definition:
histSizes.py:38
python.DecayParser.process_block
def process_block(cmd)
Definition:
DecayParser.py:35
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition:
bitmask.h:232
Generated on Sun Oct 26 2025 21:08:48 for ATLAS Offline Software by
1.8.18