ATLAS Offline Software
Loading...
Searching...
No Matches
hypoConfigBuilder.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3from TrigHLTJetHypo.FastReductionAlgToolFactory import toolfactory
4
5# import modules concerned with extracting scenario paramters
6# from a scenario string
7from TrigHLTJetHypo.scenario_ht import scenario_ht
8from TrigHLTJetHypo.scenario_dipz import scenario_dipz
9from TrigHLTJetHypo.scenario_hitz import scenario_hitz
10from TrigHLTJetHypo.scenario_htdipz import scenario_htdipz
11from TrigHLTJetHypo.scenario_mult import scenario_mult
12from TrigHLTJetHypo.scenario_dijet import scenario_dijet
13from TrigHLTJetHypo.scenario_fbdjnoshared import scenario_fbdjnoshared
14from TrigHLTJetHypo.scenario_fbdjshared import scenario_fbdjshared
15from TrigHLTJetHypo.scenario_simple import scenario_simple
16
17from TrigHLTJetHypo.prefilter_mask import prefilter_mask
18from TrigHLTJetHypo.prefilter_ptrange import prefilter_ptrange
19from TrigHLTJetHypo.prefilter_maxmult import prefilter_maxmult
20from TrigHLTJetHypo.prefilter_clean import prefilter_clean
21
22from TrigHLTJetHypo.hypoToolDisplay import hypoToolDisplay
23
24
25
26from TrigHLTJetHypo.makeConditionFilterConfigurer import (
27 makeConditionFilterConfigurer,
28)
29
30from TrigHLTJetHypo.make_repeatedCondConfigurer import (
31 make_repeatedCond,
32 make_repeatedCondCfgFromParams,
33)
34
35from DecisionHandling.TrigCompositeUtils import isLegId, getLegIndexInt
36
37from AthenaCommon.Logging import logging
38from AthenaCommon.Constants import DEBUG
39
40import re
41
42logger = logging.getLogger( __name__)
43logger.setLevel(DEBUG)
44
45# Dictionary to interpret / map scenario aliases into actual scenario strings that can be understood by scenario_XX.py
46aliasesDict = {
47 'DJMASS200j20' : 'DIJET20j12ptXX200djmass',
48 'DJMASS350j20' : 'DIJET20j12ptXX350djmass',
49 'DJMASS300j35' : 'DIJET35j12ptXX300djmass',
50 'DJMASS500j35' : 'DIJET35j12ptXX500djmass',
51 'DJMASS700j35' : 'DIJET35j12ptXX700djmass',
52 'DJMASS1000j35' : 'DIJET35j12ptXX1000djmass',
53 'DJMASS700j40' : 'DIJET40j12ptXX700djmass',
54 'DJMASS700j50x0eta240' : 'DIJET50j12ptXX0j12eta240XX700djmass',
55 'DJMASS700j80x0eta240' : 'DIJET80j12ptXX0j12eta240XX700djmass',
56 'DJMASS900j50' : 'DIJET50j12ptXX900djmass',
57 'DJMASS1000j50' : 'DIJET50j12ptXX1000djmass',
58 'DJMASS1000j50dphi240' : 'DIJET50j12ptXX1000djmassXXdjdphi240',
59 'DJMASS900j50dphi240' : 'DIJET50j12ptXX900djmassXXdjdphi240',
60 'DJMASS1000j50dphi200x400deta' : 'DIJET50j12ptXX1000djmassXXdjdphi200XX400djdeta',
61 'DJMASS900j50dphi200x400deta' : 'DIJET50j12ptXX900djmassXXdjdphi200XX400djdeta',
62 'DJMASS1000j50dphi260x200deta' : 'DIJET50j12ptXX1000djmassXXdjdphi260XX200djdeta',
63 'DJMASS900j50dphi260x200deta' : 'DIJET50j12ptXX900djmassXXdjdphi260XX200djdeta',
64 'DJMASS1000j30dphi260x200deta' : 'DIJET30j12ptXX1000djmassXXdjdphi260XX200djdeta',
65 'DJMASS900j30dphi260x200deta' : 'DIJET30j12ptXX900djmassXXdjdphi260XX200djdeta',
66 'DJMASS1000j50x200deta' : 'DIJET50j12ptXX1000djmassXX200djdeta',
67 'DJMASS900j50x200deta' : 'DIJET50j12ptXX900djmassXX200djdeta',
68
69 'DJMASS1000j50dphi260' : 'DIJET50j12ptXX1000djmassXXdjdphi260',
70 'DJMASS900j50dphi260' : 'DIJET50j12ptXX900djmassXXdjdphi260',
71
72}
73
75 """make a repeated condition configurer for the fast reduction
76 root node. This will will have a single accapt all internal node."""
77
78 toolclass, name = toolfactory('all')
79 args = {'name': name}
80 conditionMakers = [toolclass(**args)]
81
82 configurer = make_repeatedCond(tree_id=0,
83 tree_pid=0,
84 clique=-1,
85 conditionMakers=conditionMakers)
86
87 return configurer
88
90 """the parameter object passed in is built in the modules handling
91 scenarios. It contains the information needed to build the
92 configuration AlgTool that intialiases a hypo helper AlgTool"""
93
94 # check that each Condition has a Filter index.
95 # the index is -1 for no Condition filtering.
96 assert len(params.repcondargs) == len(params.filterparam_inds)
97 assert len(params.filterparam_inds) >= len(params.filterparams)
98
99 # FastReducer root node
100 repcondobjs = [make_root_repcondconfig()]
101 for ra in params.repcondargs:
102 repcondobjs.append(make_repeatedCondCfgFromParams(ra))
103
104
105 # filter for FastReducer root node (use position 0)
106 filtConditionMakers = []
107 filtConditionMakerInds = [-1] # no condition filtering for root
108
109 for ra_ind in params.filterparam_inds:
110 if ra_ind != -1:
111 ra = params.filterparams[ra_ind]
112 filtConditionMakers.append(makeConditionFilterConfigurer(ra))
113 filtConditionMakerInds.append(len(filtConditionMakers)-1)
114 else:
115 filtConditionMakerInds.append(-1)
116
117 toolclass, name = toolfactory('HelperToolConfigTool')
118
119 vals = {'name': name,
120 'conditionMakers': repcondobjs,
121 'filterMakers': filtConditionMakers,
122 'filterMakerInds': filtConditionMakerInds,
123 'treeVector': params.treevec,
124 'leafVector': params.leafvec,
125 }
126
127 return toolclass(**vals)
128
129
130def process_simple(chain_parts):
131 """Obtain the paramters needed to build an AlgTool
132 to initialise a jet hypo HelperAlgTool"""
133
134 # obtain a list of parameter objects that will be used
135 # to build a helper config AlgTools
136 helper_params = scenario_simple(chain_parts)
137
138 # build the helper config AlgTools
139 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
140 helper_params]
141
142 return helperconfigobjs
143
144
145def process_dipz(scenario, chainPartInd):
146 """Obtain the paramters needed to build an AlgTool
147 to initialise a jet hypo HelperAlgTool"""
148
149 # obtain a list of parameter objects that will be used
150 # to build a helper config AlgTools
151 helper_params = scenario_dipz(scenario, chainPartInd)
152
153 # build the helper config AlgTools
154 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
155 helper_params]
156
157 return helperconfigobjs
158
159
160def process_hitz(scenario, chainPartInd):
161 """Obtain the paramters needed to build an AlgTool
162 to initialise a jet hypo HelperAlgTool"""
163
164 # obtain a list of parameter objects that will be used
165 # to build a helper config AlgTools
166 helper_params = scenario_hitz(scenario, chainPartInd)
167
168 # build the helper config AlgTools
169 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
170 helper_params]
171
172 return helperconfigobjs
173
174def process_ht(scenario, chainPartInd):
175 """Obtain the paramters needed to build an AlgTool
176 to initialise a jet hypo HelperAlgTool"""
177
178 # obtain a list of parameter objects that will be used
179 # to build a helper config AlgTools
180 helper_params = scenario_ht(scenario, chainPartInd)
181
182 # build the helper config AlgTools
183 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
184 helper_params]
185
186 return helperconfigobjs
187
188def process_htdipz(scenario, chainPartInd):
189 """Obtain the paramters needed to build an AlgTool
190 to initialise a jet hypo HelperAlgTool"""
191
192 # obtain a list of parameter objects that will be used
193 # to build a helper config AlgTools
194 helper_params = scenario_htdipz(scenario, chainPartInd)
195
196 # build the helper config AlgTools
197 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
198 helper_params]
199
200 return helperconfigobjs
201
202
203def process_mult(scenario, chainPartInd):
204 """Obtain the paramters needed to build an AlgTool
205 to initialise a jet hypo HelperAlgTool"""
206
207 # obtain a list of parameter objects that will be used
208 # to build a helper config AlgTools
209 helper_params = scenario_mult(scenario, chainPartInd)
210
211 # build the helper config AlgTools
212 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
213 helper_params]
214
215 return helperconfigobjs
216
217
218def process_dijet(scenario, chainPartInd):
219 """Obtain the paramters needed to build an AlgTool
220 to initialise a jet hypo HelperAlgTool"""
221
222 # obtain a list of parameter objects that will be used
223 # to build a helper config AlgTools
224 helper_params = scenario_dijet(scenario, chainPartInd)
225
226 # build the helper config AlgTools
227 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
228 helper_params]
229
230 return helperconfigobjs
231
232
233def process_fbdjshared(scenario, chainPartInd):
234 """Obtain the paramters needed to build an AlgTool
235 to initialise a jet hypo HelperAlgTool"""
236
237 # obtain a list of parameter objects that will be used
238 # to build a helper config AlgTools
239 helper_params = scenario_fbdjshared(scenario, chainPartInd)
240
241 # build the helper config AlgTools
242 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
243 helper_params]
244
245 return helperconfigobjs
246
247
248def process_fbdjnoshared(scenario, chainPartInd):
249 """Obtain the paramters needed to build an AlgTool
250 to initialise a jet hypo HelperAlgTool"""
251
252 # obtain a list of parameter objects that will be used
253 # to build a helper config AlgTools
254 helper_params = scenario_fbdjnoshared(scenario, chainPartInd)
255
256 # build the helper config AlgTools
257 helperconfigobjs = [buildHypoHelperConfigTool(params) for params in
258 helper_params]
259
260 return helperconfigobjs
261
262
263def process_nonsimple(scenario, chainPartInd):
264 """Maker a list of helper tool config tool for a non-simple scenario.
265 Note: a non-simple scenario will produce more than HelperToolConfigTool
266 if jet sharing among Conditions is required."""
267
268 # interpret scenario aliases
269 if scenario in aliasesDict.keys(): scenario = aliasesDict[scenario]
270
271 router = {
272 'Z': process_dipz,
273 'HZ': process_hitz,
274 'HTZ': process_htdipz,
275 'HT': process_ht,
276 'MULT': process_mult,
277 'DIJET': process_dijet,
278 'FBDJSHARED': process_fbdjshared,
279 'FBDJNOSHARED': process_fbdjnoshared,
280 }
281
282 # get scenario stub and make sure is correct
283 pattern = r'^(?P<stub>[A-Z]+)'
284 rgx = re.compile(pattern)
285 m = rgx.match(scenario)
286 assert m is not None,'No scenario stub was found'
287 groupdict = m.groupdict()
288 assert groupdict['stub'] in router,'scenario stub ({}) not recognized'.format(groupdict['stub'])
289
290 return router[groupdict['stub']](scenario, chainPartInd) # list of HelperToolConfigTool
291
292
294 """Create HelperToolConfigTool instances. Each instance
295 configures a FastReduction tree. Chain parts with the 'simple' scenario
296 are used to form a single HelperToolConfigTool. The information
297 may be spread over a number of chain parts.
298
299 There is at most one chain part with a non-simple scenario.
300 This may give rise to > 1 HelperToolConfigTool instance - as this
301 is how jet sharing among Conditions is handled.
302
303 If there are both simple and non-simple scenarios, there will be
304 n HelperToolConfigTool instances, where n >=2: one for the simple
305 scenario chain parts, and n-1 for the non-simple scenario.
306 """
307
308 chain_parts = chain_dict['chainParts']
309
310 simple_chainparts = [
311 cp for cp in chain_parts if cp['hypoScenario'] == 'simple']
312 simple_cpis = [cp['chainPartIndex'] for cp in simple_chainparts]
313 # check that all the simple scenario parts occur before
314 # non-simple scenario chain parts
315
316 if simple_cpis:
317 assert simple_cpis == sorted(simple_cpis), "disordered chain parts"
318 assert simple_cpis[-1] - simple_cpis[0] == len(simple_cpis) - 1, "nonsequential chainParts"
319 helperToolConfigTools = []
320
321 # check for SHARED markers (chainPart['tboundary'] = 'SHARED')
322 # in the list of simple chain parts.
323 # Get a tree configuration each time SHARED == 1 is encountered.
324 if simple_chainparts:
325
326 assert simple_chainparts[-1]['tboundary'] == ''
327
328 tree_cps = []
329 for cp in simple_chainparts:
330 tree_cps.append(cp)
331 if cp['tboundary'] == 'SHARED':
332 helperToolConfigTools.extend(process_simple(tree_cps))
333 tree_cps = []
334
335 # tree_cps cannot be empty here
336 assert tree_cps
337 helperToolConfigTools.extend(process_simple(tree_cps))
338
339 scenario_chainparts =[
340 cp for cp in chain_parts if cp['hypoScenario'] != 'simple']
341
342 if scenario_chainparts:
343 for scenario_chainpart in scenario_chainparts:
344 # scenario_chainpart = scenario_chainparts[0]
345
346 # We only allow threshold != 0 for the simple scenario.
347 assert scenario_chainpart['threshold'] == '0'
348
349 scenario = scenario_chainpart['hypoScenario']
350 # find the chain part index for a non-simple scenario.
351 # assume simple is processed before non-simple, and that
352 # there is at most one non-simple chainpart.
353 # chainPartInd is needed to report passing jets to the
354 # trigger framework.
355 chainPartInd = scenario_chainpart['chainPartIndex']
356
357 helperToolConfigTools.extend(process_nonsimple(scenario,
358 chainPartInd))
359
360 return helperToolConfigTools
361
362
364 """Set up the prefilters fo the chain."""
365
366 pf_strings = []
367 chain_parts = [cp for cp in chain_dict['chainParts'] if
368 cp['signature'] == 'Jet' and 'prefilters' in cp]
369
370 [pf_strings.extend(cp['prefilters']) for cp in chain_parts]
371
372 # if not pre filter strings (pf_strings) are found in the chainDict,
373 # a PassThroughFilter configurer is made.
374
375 if not pf_strings:
376 return []
377
378 # route the prefilter strings to the appropriate handler
379 prefilter_router = {
380 'MASK': prefilter_mask,
381 'PTRANGE': prefilter_ptrange,
382 'MAXMULT': prefilter_maxmult,
383 'CLEAN': prefilter_clean,
384 }
385
386 pattern = r'(?P<stub>[A-Z]*)'
387 rgx = re.compile(pattern)
388
389 filters = []
390 for pf_string in pf_strings:
391 # get prefilter stub and make sure is correct
392 m = rgx.match(pf_string)
393 assert m is not None,'No prefilter stub was found'
394 groupdict = m.groupdict()
395 assert groupdict['stub'] in prefilter_router,'prefilter stub ({}) not recognized'.format(groupdict['stub'])
396 filters.append(prefilter_router[groupdict['stub']](pf_string))
397
398 return filters
399
400
401def getLabelIndices(chain_dict):
402
403 start_index = 0
404 if isLegId(chain_dict['chainName']):
405 start_index = getLegIndexInt(chain_dict['chainName'])
406
407 end_index = start_index + len(chain_dict['chainParts'])
408
409 return start_index, end_index
410
411
412def hypotool_from_chaindict(chain_dict, visit_debug=False):
413
414 toolfactory.reset()
415
416 if visit_debug:
417 fn = chain_dict['chainName'] + '_chaindict.log'
418 from pprint import pprint
419 with open(fn, 'w') as fh:
420 pprint(chain_dict, fh)
421
422
423 helperToolConfigTools = make_fastreduction_configurers(chain_dict)
424
425 prefilterMakers = make_prefilter_configurers(chain_dict)
426
427 toolclass, name = toolfactory('helper_tool')
428 args = {'name': name,
429 'HypoConfigurers': helperToolConfigTools,
430 'prefilterMakers': prefilterMakers
431 }
432
433 helper_tool = toolclass(**args)
434
435 toolclass, name = toolfactory('hypo_tool')
436
437 startLabelIndex, endLabelIndex = getLabelIndices(chain_dict)
438
439 args = {'name': chain_dict['chainName'],
440 # for reporting passing jets:
441 'visit_debug': visit_debug,
442 'helper_tool': helper_tool,
443 'chain_name': chain_dict['chainName'],
444 'startLabelIndex': startLabelIndex,
445 'endLabelIndex': endLabelIndex,
446 }
447
448 hypo_tool = toolclass(**args)
449 hypo_tool.visit_debug = visit_debug
450
451 if (visit_debug):
452 hypoToolDisplay(hypo_tool,
453 do_dot=True)
454
455 return hypo_tool
456
457if __name__ == '__main__':
458 cd = {'EBstep': '',
459 'L1item': 'L1_EM22VHI',
460 'alignmentGroups': ['Egamma', 'JetMET', 'JetMET'],
461 'chainCounter': 1451,
462 'chainMultiplicities': [1, 2, 2],
463 'chainName': 'leg001_HLT_g25_medium_2j35_pf_ftf_0eta490_bdl1r77_2j35_pf_ftf_0eta490_L1EM22VHI',
464 'chainNameHash': 4053501929,
465 'chainParts': [{'L1threshold': 'FSNOSEED',
466 'addInfo': [],
467 'alignmentGroup': 'JetMET',
468 'bConfig': [],
469 'bMatching': [],
470 'bTag': 'bdl1r77',
471 'bTracking': '',
472 'bsel': '',
473 'tausel': '',
474 'chainPartIndex': 1,
475 'chainPartName': '2j35_pf_ftf_0eta490_bdl1r77',
476 'clusterCalib': 'em',
477 'constitMod': '',
478 'constitType': 'pf',
479 'etaRange': '0eta490',
480 'exotHypo': [],
481 'extra': '',
482 'hypoScenario': 'simple',
483 'ionopt': 'noion',
484 'jetCalib': 'default',
485 'jvt': '',
486 'momCuts': '',
487 'multiplicity': '2',
488 'prefilters': [],
489 'recoAlg': 'a4',
490 'scan': 'FS',
491 'sigFolder': ['Bjet'],
492 'signature': 'Bjet',
493 'smc': 'nosmc',
494 'subSigs': ['Bjet'],
495 'tboundary': '',
496 'threshold': '35',
497 'topo': [],
498 'trigType': 'j',
499 'trkopt': 'ftf',
500 'trkpresel': 'nopresel'},
501 {'L1threshold': 'FSNOSEED',
502 'addInfo': [],
503 'alignmentGroup': 'JetMET',
504 'bConfig': [],
505 'bMatching': [],
506 'bTag': '',
507 'bTracking': '',
508 'bsel': '',
509 'tausel': '',
510 'chainPartIndex': 2,
511 'chainPartName': '2j35_pf_ftf_0eta490',
512 'clusterCalib': 'em',
513 'constitMod': '',
514 'constitType': 'pf',
515 'etaRange': '0eta490',
516 'exotHypo': [],
517 'extra': '',
518 'hypoScenario': 'simple',
519 'ionopt': 'noion',
520 'jetCalib': 'default',
521 'jvt': '',
522 'momCuts': '',
523 'multiplicity': '2',
524 'prefilters': [],
525 'recoAlg': 'a4',
526 'scan': 'FS',
527 'sigFolder': ['Jet'],
528 'signature': 'Jet',
529 'smc': 'nosmc',
530 'subSigs': ['Jet'],
531 'tboundary': '',
532 'threshold': '35',
533 'topo': [],
534 'trigType': 'j',
535 'trkopt': 'ftf',
536 'trkpresel': 'nopresel'}],
537 'eventBuildType': '',
538 'extraComboHypos': [],
539 'groups': ['Support:Legacy', 'RATE:EgammaBjet', 'BW:BJet'],
540 'mergingOffset': -1,
541 'mergingOrder': [],
542 'mergingStrategy': 'auto',
543 'monGroups': [],
544 'prescale': 1,
545 'sigDicts': {'Bjet': ['Bjet'], 'Egamma': ['Photon'], 'Jet': ['Jet']},
546 'sigFolder': [],
547 'signature': 'Bjet',
548 'signatures': ['Photon', 'Bjet', 'Jet'],
549 'stream': ['Main'],
550 'subSigs': [],
551 'topo': []}
552
554
555
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.
process_fbdjshared(scenario, chainPartInd)
process_dipz(scenario, chainPartInd)
process_mult(scenario, chainPartInd)
process_dijet(scenario, chainPartInd)
process_ht(scenario, chainPartInd)
hypotool_from_chaindict(chain_dict, visit_debug=False)
process_htdipz(scenario, chainPartInd)
process_nonsimple(scenario, chainPartInd)
make_fastreduction_configurers(chain_dict)
process_hitz(scenario, chainPartInd)
process_fbdjnoshared(scenario, chainPartInd)