ATLAS Offline Software
TrigJetHypoToolConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentFactory import CompFactory
4 from AthenaCommon.SystemOfUnits import GeV
5 
6 from TriggerMenuMT.HLT.Config.ControlFlow.HLTCFTools import NoHypoToolCreated
7 from TrigHLTJetHypo.hypoConfigBuilder import hypotool_from_chaindict
8 from TrigHLTJetHypo.TrigJetHypoMonitoringConfig import TrigJetHypoToolMonitoring
9 from AthenaCommon.Logging import logging
10 logger = logging.getLogger(__name__)
11 import re
12 
13 import os
14 debug = 'JETHYPODEBUG' in os.environ
15 if debug:
16  from AthenaCommon.Constants import DEBUG
17  logger.setLevel(DEBUG)
18 
19 
20 def trigJetHypoToolFromDict(flags, chain_dict):
21 
22  from DecisionHandling.TrigCompositeUtils import isLegId, getLegIndexInt
23  chain_name = chain_dict['chainName']
24  chain_mg = chain_dict['monGroups']
25  jet_signature_identifiers = ['Jet', 'Bjet']
26 
27  if isLegId(chain_name):
28  # For multi-leg chains which include jet legs we have a -- SPECIAL BEHAVIOUR --
29  # We instantiate a HypoTool only for the *first* jet leg, whichever leg that happens to be in the chain
30  # This single HypoTool gets configured to perform the selection for _all_ of the jet legs, and to report
31  # the per-jet passing status for all of these legs.
32  #
33  # Here we determine if this is the 2nd+ jet leg of a multi-leg chain which has jet legs, and return no tool if it is
34 
35  # Can we fetch this from elsewhere?
36 
37  leg_id = getLegIndexInt(chain_name)
38  # CHECK: If we have called trigJetHypoToolFromDict, then the chain_dict['signatures'] list must contain at minimum one entry from the jet_signature_identifiers list.
39  if not any(signature in chain_dict['signatures'] for signature in jet_signature_identifiers):
40  raise Exception("[trigJetHypoToolFromDict] No {} in {} for chain {}. Please update this list of jet signatures.".format(tuple(jet_signature_identifiers),tuple(chain_dict['signatures']),chain_name))
41 
42  # CHECK: All Jet and Bjet legs (i.e. signatures from jet_signature_identifiers) must be contiguous
43  # (this check is probable best put somewhere else?)
44  status = 0
45  for entry in chain_dict['signatures']:
46  if status == 0 and entry in jet_signature_identifiers:
47  status = 1
48  elif status == 1 and entry not in jet_signature_identifiers:
49  status = 2
50  elif status == 2 and entry in jet_signature_identifiers:
51  raise Exception("[trigJetHypoToolFromDict] All {} legs should be contiguous in the signatures list, modify the ordering of the chain {}. Signatures:{}.".format(tuple(jet_signature_identifiers),chain_name, tuple(chain_dict['signatures'])))
52 
53  # CHECK: The leg_id must correspond to a Signature from jet_signature_identifiers. At the time of implementation, this is not guaranteed and can be affected by alignment.
54  # If this check fails for any chain, then we need to look again at how the legXXX ordering maps to the chain_dict['signatures'] ordering.
55  if not any(signature in chain_dict['signatures'][leg_id] for signature in jet_signature_identifiers):
56  raise Exception("[trigJetHypoToolFromDict] For this code to work for chain {}, the signature at index {} must be one of {}. But the signature list is: {}".format(chain_name,leg_id,tuple(jet_signature_identifiers),tuple(chain_dict['signatures'])))
57 
58  # Locate the first index within chain_dict['signatures'] which contains an signature listed in jet_signature_identifiers
59  first_leg_index = 999
60  for signature in jet_signature_identifiers:
61  if signature in chain_dict['signatures']:
62  first_leg_index = min(first_leg_index, chain_dict['signatures'].index(signature))
63 
64  if leg_id > first_leg_index:
65  logger.debug("Not returning a HypoTool for %s as this is not the first leg "
66  "with any of %s (leg signatures are %s)",
67  chain_name, tuple(jet_signature_identifiers), tuple(chain_dict['signatures']))
68  raise NoHypoToolCreated("No HypoTool created for %s" % chain_name)
69 
70  logger.debug("Returning a HypoTool for %s as this is the first leg with any of %s (leg signatures are %s)",
71  chain_name, tuple(jet_signature_identifiers), tuple(chain_dict['signatures']))
72 
73  hypo_tool = hypotool_from_chaindict(chain_dict, debug)
74 
75  #if menu has chain in an online monitoring group, unpack the recoalg(s) and hyposcenario(s) to configure monitoring
76  if any('jetMon:online' in group for group in chain_mg):
77  cpl = chain_dict["chainParts"]
78  histFlags = []
79  for cp in cpl:
80  histFlags += [ cp['recoAlg'] ] + [ cp['hypoScenario']]
81  hypo_tool.MonTool = TrigJetHypoToolMonitoring(flags, "HLTJetHypo/"+chain_name, histFlags)
82  return hypo_tool
83 
84 
86  return CompFactory.TrigJetTLAHypoTool(chain_dict['chainName'])
87 
89  if len(chain_dict['chainParts']) > 1:
90  raise Exception("misconfiguration of emerging jet chain")
91 
92  if len(chain_dict['chainParts'][0]['exotHypo']) > 0:
93  exot_hypo = chain_dict['chainParts'][0]['exotHypo'][0]
94  else:
95  raise Exception("Unable to extract exotHypo emerging jet configuration from chain dict")
96 
97  if 'emerging' in exot_hypo:
98  trackless = int(0)
99  ptf = float(exot_hypo.split('PTF')[1].split('dR')[0].replace('p', '.'))
100  dr = float(exot_hypo.split('dR')[1].split('_')[0].replace('p', '.'))
101  elif 'trackless' in exot_hypo:
102  trackless = int(1)
103  ptf = 0.0
104  dr = float(exot_hypo.split('dR')[1].split('_')[0].replace('p', '.'))
105  else:
106  raise Exception("misconfiguration of emerging jet chain")
107 
108  chain_name = chain_dict['chainName']
109 
110  hypo = CompFactory.TrigJetEJsHypoTool(chain_name)
111  hypo.PTF = ptf
112  hypo.dR = dr
113  hypo.Trackless = trackless
114 
115  return hypo
116 
118  chain_name = chain_dict['chainName']
119  doBIBrm = int(0)
120  doExoCal = int(0)
121  ExoCalCut = 220
122  if len(chain_dict['chainParts'][0]['exotHypo']) > 0:
123  exot_hypo = chain_dict['chainParts'][0]['exotHypo'][0]
124  calratioX_matched = re.match(r'.*calratiovar(?P<cut>\d{1,3}[\d\D]*)', chain_dict['chainParts'][0]['exotHypo'][0])
125  if calratioX_matched:
126  doExoCal= int(1)
127  ExoCalCut = calratioX_matched.groupdict()['cut']
128  else:
129  if len(chain_dict['chainParts'][1]['exotHypo']) > 0:
130  exot_hypo = chain_dict['chainParts'][1]['exotHypo'][0]
131  logger.warning(chain_dict)
132  calratioX_matched = re.match(r'.*calratiovar(?P<cut>\d{1,3}[\d\D]*)', chain_dict['chainParts'][1]['exotHypo'][0])
133  if calratioX_matched:
134  doExoCal= int(1)
135  ExoCalCut = calratioX_matched.groupdict()['cut']
136  else:
137  raise Exception("Unable to extract exotHypo calratio jet configuration from chain dict")
138  if 'calratiovar' in exot_hypo:
139  if 'calratiovarrmbib' in exot_hypo:
140  doBIBrm = int(1)
141  else:
142  raise Exception("misconfiguration of new calratio jet chain")
143 
144  presel_matched = re.match(r'.*emf(?P<cut>\d?\d?[\d\D]+)', chain_dict['chainParts'][0]['trkpresel'])
145  if presel_matched:
146  emf_cut = presel_matched.groupdict()['cut']
147  elif len(chain_dict['chainParts'])>1:
148  presel_matched = re.match(r'.*emf(?P<cut>\d?\d?[\d\D]+)', chain_dict['chainParts'][1]['trkpresel'])
149  if presel_matched:
150  emf_cut = presel_matched.groupdict()['cut']
151  elif len(chain_dict['chainParts'])>3:
152  presel_matched = re.match(r'.*emf(?P<cut>\d?\d?[\d\D]+)', chain_dict['chainParts'][3]['trkpresel'])
153  if presel_matched:
154  emf_cut = presel_matched.groupdict()['cut']
155  else:
156  raise Exception("misconfiguration of Exotic jet chain")
157  else:
158  raise Exception("misconfiguration of Exotic jet chain")
159 
160  import math
161  hypo = CompFactory.TrigJetCRVARHypoTool(chain_name)
162  hypo.MpufixLogRatio = math.log10(1./(float(emf_cut)*0.01) - 1.)
163  hypo.MinjetlogR = 1.2
164  if doExoCal:
165  hypo.MinjetlogR = (float(ExoCalCut)*0.01) - 1.
166  hypo.MintrackPt = 2*GeV
167  hypo.MindeltaR = 0.2
168  hypo.countBIBcells = 4
169  hypo.doBIBremoval = doBIBrm
170 
171  return hypo
172 
174  chain_name = chain_dict['chainName']
175 
176  doBIBrm = int(0)
177  if len(chain_dict['chainParts'][0]['exotHypo']) > 0:
178  exot_hypo = chain_dict['chainParts'][0]['exotHypo'][0]
179  else:
180  raise Exception("Unable to extract exotHypo calratio jet configuration from chain dict")
181  if 'calratio' in exot_hypo and ('calratiovar' not in exot_hypo):
182  if 'calratiormbib' in exot_hypo:
183  doBIBrm = int(1)
184  else:
185  raise Exception("misconfiguration of new calratio jet chain")
186 
187  hypo = CompFactory.TrigJetCRHypoTool(chain_name)
188  hypo.MinjetlogR = 1.2
189  hypo.MintrackPt = 2*GeV
190  hypo.MindeltaR = 0.2
191  hypo.countBIBcells = 4
192  hypo.doBIBremoval = doBIBrm
193 
194  return hypo
195 
196 import unittest
197 class TestStringMethods(unittest.TestCase):
198  def testValidConfigs(self):
199  from TriggerMenuMT.HLT.Config.Utility.DictFromChainName import (
200  dictFromChainName,)
201 
202  chain_names = (
203  'HLT_j0_FBDJNOSHARED10etXX20etXX34massXX50fbet_L1J20',)
204 
205  from AthenaConfiguration.AllConfigFlags import initConfigFlags
206  flags = initConfigFlags()
207  flags.Input.Files = []
208 
209  flags.lock()
210 
211  wid = max(len(c) for c in chain_names)
212  for chain_name in chain_names:
213  chain_dict = dictFromChainName(flags, chain_name)
214  tool = trigJetHypoToolFromDict(flags, chain_dict)
215  self.assertIsNotNone(tool)
216  logger.debug(chain_name.rjust(wid), str(tool))
217 
218 
219 
220 if __name__ == '__main__':
221  unittest.main()
222 
223  # other local tests have been moved to testChainDictMaker.py
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.TrigJetHypoMonitoringConfig.TrigJetHypoToolMonitoring
def TrigJetHypoToolMonitoring(flags, histPath, histFlags)
Definition: TrigJetHypoMonitoringConfig.py:5
SystemOfUnits
max
#define max(a, b)
Definition: cfImp.cxx:41
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
index
Definition: index.py:1
python.TrigCompositeUtils.isLegId
def isLegId(chainName)
Definition: DecisionHandling/python/TrigCompositeUtils.py:18
DictFromChainName.dictFromChainName
def dictFromChainName(flags, chainInfo)
Definition: DictFromChainName.py:626
python.TrigJetHypoToolConfig.trigJetEJsHypoToolFromDict
def trigJetEJsHypoToolFromDict(chain_dict)
Definition: TrigJetHypoToolConfig.py:88
python.TrigJetHypoToolConfig.trigJetCRVARHypoToolFromDict
def trigJetCRVARHypoToolFromDict(chain_dict)
Definition: TrigJetHypoToolConfig.py:117
Constants
some useful constants -------------------------------------------------—
python.TrigJetHypoToolConfig.trigJetTLAHypoToolFromDict
def trigJetTLAHypoToolFromDict(chain_dict)
Definition: TrigJetHypoToolConfig.py:85
python.hypoConfigBuilder.hypotool_from_chaindict
def hypotool_from_chaindict(chain_dict, visit_debug=False)
Definition: hypoConfigBuilder.py:377
min
#define min(a, b)
Definition: cfImp.cxx:40
python.TrigCompositeUtils.getLegIndexInt
def getLegIndexInt(chainName)
Definition: DecisionHandling/python/TrigCompositeUtils.py:21
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.TrigJetHypoToolConfig.trigJetHypoToolFromDict
def trigJetHypoToolFromDict(flags, chain_dict)
Definition: TrigJetHypoToolConfig.py:20
str
Definition: BTagTrackIpAccessor.cxx:11
python.TrigJetHypoToolConfig.TestStringMethods.testValidConfigs
def testValidConfigs(self)
Definition: TrigJetHypoToolConfig.py:198
python.TrigJetHypoToolConfig.TestStringMethods
Definition: TrigJetHypoToolConfig.py:197
python.TrigJetHypoToolConfig.trigJetCRHypoToolFromDict
def trigJetCRHypoToolFromDict(chain_dict)
Definition: TrigJetHypoToolConfig.py:173
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38