ATLAS Offline Software
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 from __future__ import print_function
8 
9 import re
10 
11 _slot_separator = "+"
12 _candidate_sep = "|"
13 _decay_arrow = "->"
14 _wild_card = "*"
15 
16 def py_parse (cmd):
17  # remove all spaces to ease further parsing
18  cmd = re.sub(pattern=" ",
19  repl="",
20  string=cmd)
21 
22 
23  if cmd == _decay_arrow:
24  # special case of a single arrow without any parent nor child:
25  # this decay pattern will select every single vertex
26  return (0, None, None)
27  buf = cmd.split (_decay_arrow)
28  assert (len(buf)==2)
29 
30 
31  parents = process_block (buf[0])
32  children= process_block (buf[1])
33 
34  return (0, parents, children)
35 
36 def process_block (cmd):
37  if cmd == "":
38  return None
39  candidates = cmd.split (_slot_separator)
40  return [list(set(c.split(_candidate_sep))) for c in candidates]
41 
42 
43 if __name__ == "__main__":
44  print (":"*80)
45  print ("::: tests...")
46  for cmd in ("-1|-2|-3|-4|-5|-6|21 + 1|2|3|4|5|6|21 -> ",
47  "-> 91|92|94"
48  ):
49  print ("::: testing [%s]..." % cmd)
50  print ("::: result:",py_parse (cmd))
51 
52  print ("::: bye.")
53  print (":"*80)
54 
python.DecayParser.py_parse
def py_parse(cmd)
Definition: DecayParser.py:16
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.DecayParser.process_block
def process_block(cmd)
Definition: DecayParser.py:36
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