ATLAS Offline Software
Loading...
Searching...
No Matches
scenario_mult.py
Go to the documentation of this file.
1# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3from TrigHLTJetHypo.RepeatedConditionParams import RepeatedConditionParams
4from TrigHLTJetHypo.FilterParams import FilterParams
5from TrigHLTJetHypo.HelperConfigToolParams import HelperConfigToolParams
6from TrigHLTJetHypo.ConditionDefaults import defaults
7from TrigHLTJetHypo.make_treevec import make_treevec
8
9import re
10
11
12pattern_pt_threshold = r'^MULT(?P<multlo>\d+)mult(?P<multhi>\d+)'\
13 r'(XX(?P<ptlo>\d*)pt(?P<pthi>\d*))?'
14
15pattern_et_threshold = r'^MULT(?P<multlo>\d+)mult(?P<multhi>\d+)'\
16 r'(XX(?P<etlo>\d*)et(?P<ethi>\d*))?'
17
18pattern_common = r'(XX(?P<etalo>\d*)eta(?P<etahi>\d*))?'
19
20pattern_ptfull = pattern_pt_threshold + pattern_common
21rgx_pt = re.compile(pattern_ptfull)
22
23pattern_etfull = pattern_et_threshold + pattern_common
24rgx_et = re.compile(pattern_etfull)
25
26def get_conditionfilter_args_from_matchdict(groupdict, threshold_var):
27 """ Extract the arguments used by the filter of the MULT condition
28 from the dictionary greated during ghe regex matching to the sceanario
29 string. THESE CHAINS HAS DEFAULT CONDITION FILTERING"""
30
31 # care! if et no match, etlo and etahi are None.
32 # if et match, missing etlo, ethi = ''
33 # same for eta
34
35 if groupdict[threshold_var+'lo'] is None: # then default filtering for threshold_var
36 groupdict[threshold_var+'lo'] = ''
37 groupdict[threshold_var+'hi'] = '' # will be assigned default value
38
39 if groupdict['etalo'] is None: # then default filtering for eta
40 groupdict['etalo'] = '' # will be assigned default value
41 groupdict['etahi'] = ''
42
43 condargs = []
44 vals = defaults(threshold_var,
45 groupdict[threshold_var+'lo'],
46 groupdict[threshold_var+'hi'])
47 condargs.append((threshold_var, vals))
48
49 vals = defaults('eta',
50 groupdict['etalo'],
51 groupdict['etahi'])
52 condargs.append(('eta', vals))
53
54 return condargs
55
56
57def scenario_mult(scenario, chainPartInd):
58 """calculate the parameters needed to generate a hypo helper config AlgTool
59 starting from a the hypoScenario which appears in the chainname for
60 an MULT condition. The MULT condition is filtered"""
61
62 if not scenario.startswith('MULT'):
63 raise ValueError( f'routing error, module {__name__}: bad scenario {scenario}')
64
65 threshold_var = 'pt'
66 m = rgx_pt.match(scenario)
67 if m is None:
68 threshold_var = 'et'
69 m = rgx_et.match(scenario)
70 groupdict = m.groupdict()
71
72 condargs = []
73 vals = defaults('mult',
74 groupdict['multlo'],
75 groupdict['multhi'])
76
77 # find the constructor arguments for each elemental condition
78 condargs.append(('mult', vals))
79
80 # treeVec is [0, 0] handle non-root nodes here
81 repcondargs = [RepeatedConditionParams(tree_id = 1,
82 tree_pid=0,
83 chainPartInd=chainPartInd,
84 condargs=condargs)]
85
86 # get the arguments needed for the MULT condition filter
87 filterparams = None
88 condargs = get_conditionfilter_args_from_matchdict(groupdict,threshold_var)
89
90 if condargs: # has default filterinf, so always True
91
92 # make repeated conditions that filter the MULT condition
93 repfiltargs = [RepeatedConditionParams(tree_id=1,
94 tree_pid=0,
95 condargs=condargs)]
96 filterparams = [FilterParams(typename='ConditionFilter',
97 args=repfiltargs)]
98 filterparam_inds = [0]
99
100 else:
101 filterparams = []
102 filterparam_inds = [-1] # no condition filter
103
104 # parameters to initalise the AlgTool that initialises the helper AlgTool
105
106 # treevec[i] gives the tree_id of the parent of the
107 # node with tree_id = i
108 treevec = make_treevec(repcondargs)
109 assert treevec == [0, 0]
110
111 assert len(repcondargs) == len(filterparam_inds)
112
113
114 helper_params = HelperConfigToolParams(treevec=treevec,
115 repcondargs=repcondargs,
116 filterparams=filterparams,
117 filterparam_inds=filterparam_inds)
118
119 return [helper_params] # a list with one entry per FastReduction tree
120
get_conditionfilter_args_from_matchdict(groupdict, threshold_var)