ATLAS Offline Software
hypoToolTests.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 """Make chain dicts for testing jet hypo config modules"""
3 
4 from TriggerMenuMT.HLT.Menu.Physics_pp_run3_v1 import (
5  SingleJetGroup,
6  MultiJetGroup)
7 
8 from TriggerMenuMT.HLT.Config.Utility.ChainDefInMenu import ChainProp
9 from TriggerMenuMT.HLT.Config.Utility.DictFromChainName import dictFromChainName
10 
11 from TrigHLTJetHypo.hypoConfigBuilder import hypotool_from_chaindict
12 from TrigHLTJetHypo.HypoToolAnalyser import HypoToolAnalyser
13 
14 import unittest
15 
16 from AthenaCommon.Logging import logging
17 from AthenaCommon.Constants import DEBUG
18 logger = logging.getLogger( __name__)
19 
20 logger.setLevel(DEBUG)
21 
22 from AthenaConfiguration.AllConfigFlags import initConfigFlags
23 flags = initConfigFlags()
24 flags.Input.Files = []
25 
26 flags.lock()
27 
28 class HypoToolStructure(unittest.TestCase):
29  def test_structure(self):
30  testData = [
31  {'prop':
32  ChainProp(name='HLT_j420_subresjesgscIS_ftf_L1J100',
33  groups=SingleJetGroup),
34  'connections': dict(((0, [1]),
35  (1, [2]),
36  (2, [3, 5]),
37  (3, [4]),
38  (5, [6, 7]))),
39  'values': []
40  },
41 
42  {'prop':
43  ChainProp(name='HLT_j260f_L1J75_31ETA49',
44  groups=SingleJetGroup),
45  'connections': dict(((0, [1]),
46  (1, [2]),
47  (2, [3, 5]),
48  (3, [4]),
49  (5, [6, 7]))),
50  'values': []
51  },
52 
53 
54  {'prop':
55  ChainProp(name='HLT_j80_j60_L1J15',
56  l1SeedThresholds=['FSNOSEED']*2, groups=MultiJetGroup),
57  'connections': dict(((0, [1]),
58  (1, [2]),
59  (2, [3, 5, 8]),
60  (3, [4]),
61  (5, [6, 7]),
62  (8, [9, 10]))),
63  'values': []
64  },
65 
66  {
67  'prop': ChainProp(name='HLT_2j80_3j60_L1J15',
68  l1SeedThresholds=['FSNOSEED']*2, groups=MultiJetGroup),
69  'connections': dict(((0, [1]), (1, [2]),
70  (2, [3, 5, 8]),
71  (3, [4]),
72  (5, [6, 7]),
73  (8, [9,10]))),
74  'values': []
75  },
76 
77  {
78  'prop': ChainProp(name='HLT_j0_HT1000_L1J20',
79  groups=SingleJetGroup),
80 
81  'connections': dict(((0, [1]),
82  (1, [2]),
83  (2, [3, 5, 7]),
84  (3, [4]),
85  (5, [6]),
86  (7, [8]),
87  (8, [9, 10]))),
88  'values': []
89  },
90 
91  {
92  'prop': ChainProp(
93  name='HLT_j70_1j50a_j0_DIJET70j12etXX1000djmassXXdjdphi200XX400djdeta_L1MJJ-500-NFF',
94  l1SeedThresholds=['FSNOSEED']*3,
95  groups=MultiJetGroup),
96 
97  'connections': dict(((0, [1]),
98  (1, [2, 11]),
99  (2, [3, 5, 8]),
100  (3, [4]),
101  (5, [6, 7]),
102  (8, [9, 10]),
103  (11, [12, 14, 18]),
104  (12, [13]),
105  (14, [15, 16, 17]),
106  (18, [19, 20]),)),
107  'values': []
108  },
109 
110  {
111  'prop': ChainProp(name='HLT_10j40_L1J15',
112  l1SeedThresholds=['FSNOSEED'],
113  groups=MultiJetGroup),
114 
115  'connections': dict(((0, [1]),
116  (1, [2]),
117  (2, [3, 5]),
118  (3, [4]),
119  (5, [6, 7]))),
120  'values': [{'nodeid': 5,
121  'multiplicity': 10}]
122  },
123 
124  {
125  'prop': ChainProp(name='HLT_j0_FBDJSHARED_L1J20',
126  groups=SingleJetGroup),
127 
128  'connections': dict(((0, [1]),
129  (1, [2, 11]),
130  (2, [3, 5, 8]),
131  (3, [4]),
132  (5, [6, 7]),
133  (8, [9, 10]),
134  (11, [12, 14, 17, 20]),
135  (12, [13]),
136  (14, [15, 16]),
137  (17, [18, 19]),
138  (20, [21, 22]))),
139  'values': []
140  },
141 
142  {
143  'prop': ChainProp(name='HLT_j40_j0_HT50XX10etXX0eta320_L1J20',
144  l1SeedThresholds=['FSNOSEED']*2,
145  groups=MultiJetGroup),
146 
147  'connections': dict(((0, [1]),
148  (1, [2, 8]),
149  (2, [3, 5]),
150  (3, [4]),
151  (5, [6, 7]),
152  (8, [9, 11, 13]),
153  (9, [10]),
154  (11, [12]),
155  (13, [14]),
156  (14, [15, 16]))),
157  'values': []
158  },
159 
160  {
161  'prop': ChainProp(name='HLT_j0_FBDJNOSHARED10etXX20etXX34massXX50fbet_L1J20',
162  groups=SingleJetGroup),
163 
164  'connections': dict(((0, [1]),
165  (1, [2]),
166  (2, [3, 5, 8, 11, 14, 17]),
167  (3, [4]),
168  (5, [6, 7]),
169  (8, [9, 10]),
170  (11, [12, 13]),
171  (14, [15, 16]),
172  (17, [18, 19]))),
173  'values': []
174  },
175 
176 
177  {
178  'prop': ChainProp(name='HLT_j45_pf_ftf_preselj20_L1J15',
179  groups=SingleJetGroup),
180 
181  'connections': dict(((0, [1]),
182  (1, [2]),
183  (2, [3, 5]),
184  (3, [4]),
185  (5, [6, 7]))),
186  'values': []
187  },
188 
189  {
190  'prop': ChainProp(name='HLT_j85_ftf_MASK300ceta210XX300nphi10_L1J20',
191  groups=SingleJetGroup),
192 
193 
194  'connections': dict(((0, [1]),
195  (1, [2, 8]),
196  (2, [3, 5]),
197  (3, [4]),
198  (5, [6, 7]),
199  (8, [9]),
200  (9, [10, 11]))),
201  'values': []
202  },
203 
204 
205  {
206  'prop': ChainProp(name='HLT_j0_DIJET80j12etXX0j12eta240XX700djmass_L1J20',
207  groups=SingleJetGroup),
208 
209 
210 
211  'connections': dict(((0, [1]),
212  (1, [2]),
213  (2, [3, 5, 7]),
214  (3, [4]),
215  (5, [6]),
216  (7, [8, 9]))),
217 
218  'values': [{'nodeid': 6, 'min': '700000.0', 'max': 'inf'},
219 
220  {'nodeid': 7, 'multiplicity': 2},
221  {'nodeid': 8, 'min': '80000.0', 'max': 'inf'},
222  {'nodeid': 9, 'min': '0.0', 'max': '2.4'},
223  ]
224 
225  },
226 
227 
228  ]
229 
230  for td in testData:
231  chain_dict =chain_dict = dictFromChainName(flags, td['prop'])
232  # set chain part indices (kludge)
233  cpi = 0
234  for cp in chain_dict['chainParts']:
235  cp['chainPartIndex'] = cpi
236  cpi += 1
237  chain_name = chain_dict['chainName']
238  tool = hypotool_from_chaindict(chain_dict)
239 
240  analyser = HypoToolAnalyser(tool)
241 
242  node_table = []
243  for k in sorted(analyser.node_table.keys()):
244  node_table.append ('%d: %s' % (k, analyser.node_table[k]))
245 
246  node_table = '\n'.join(node_table)
247 
248  self.assertTrue(analyser.connections == td['connections'],
249  'fail for case %s expected %s; saw %s \n %s' %(
250  chain_name,
251  str(td['connections']),
252  str(analyser.connections),
253  node_table))
254 
255  # check selected attributes of inner (nested) tools.
256 
257  for ref_values in td['values']:
258 
259  # find the inner (nested) subtool
260  # from the tool list in the analyser
261 
262  nodeid = ref_values['nodeid']
263  del ref_values['nodeid']
264  subtool = analyser.node_table[nodeid]
265 
266  # check selected attributes of the subtool
267 
268  for attrname, testval in ref_values.items():
269  toolval = getattr(subtool, attrname)
270  self.assertEqual(toolval, testval,
271  msg='%s: node: %d expected %s saw %s' % (
272  chain_name,
273  nodeid,
274  str(testval),
275  str(toolval)))
276 
277 
278 if __name__ == '__main__':
279 
280  unittest.main()
281 
282 
283 
DictFromChainName.dictFromChainName
def dictFromChainName(flags, chainInfo)
Definition: DictFromChainName.py:626
Constants
some useful constants -------------------------------------------------—
python.hypoConfigBuilder.hypotool_from_chaindict
def hypotool_from_chaindict(chain_dict, visit_debug=False)
Definition: hypoConfigBuilder.py:377
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.hypoToolTests.HypoToolStructure
Definition: hypoToolTests.py:28
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
str
Definition: BTagTrackIpAccessor.cxx:11
python.hypoToolTests.HypoToolStructure.test_structure
def test_structure(self)
Definition: hypoToolTests.py:29