ATLAS Offline Software
Loading...
Searching...
No Matches
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
8import re
9
10_slot_separator = "+"
11_candidate_sep = "|"
12_decay_arrow = "->"
13_wild_card = "*"
14
15def 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
35def 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
42if __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
STL class.