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:Jet', 'Bjet:Bjet', 'Tau:Ditau']
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  chain_sig_w_sub_sig = [f'{sig}:{subsig}' for sig, subsigs in chain_dict['sigDicts'].items() for subsig in subsigs]
39  # CHECK: If we have called trigJetHypoToolFromDict, then the chain_sig_w_sub_sig list must contain at minimum one entry from the jet_signature_identifiers list.
40  if not any(signature in chain_sig_w_sub_sig for signature in jet_signature_identifiers):
41  raise Exception("[trigJetHypoToolFromDict] No {} in {} for chain {}. Please update this list of jet signatures.".format(tuple(jet_signature_identifiers),tuple(chain_sig_w_sub_sig),chain_name))
42 
43  # CHECK: All Jet and Bjet legs (i.e. signatures from jet_signature_identifiers) must be contiguous
44  # (this check is probable best put somewhere else?)
45  status = 0
46  for entry in chain_sig_w_sub_sig:
47  if status == 0 and entry in jet_signature_identifiers:
48  status = 1
49  elif status == 1 and entry not in jet_signature_identifiers:
50  status = 2
51  elif status == 2 and entry in jet_signature_identifiers:
52  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_sig_w_sub_sig)))
53 
54  # 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.
55  # If this check fails for any chain, then we need to look again at how the legXXX ordering maps to the chain_sig_w_sub_sig ordering.
56  if not any(signature in chain_sig_w_sub_sig[leg_id] for signature in jet_signature_identifiers):
57  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_sig_w_sub_sig)))
58 
59  # Locate the first index within chain_sig_w_sub_sig which contains an signature listed in jet_signature_identifiers
60  first_leg_index = 999
61  for signature in jet_signature_identifiers:
62  if signature in chain_sig_w_sub_sig:
63  first_leg_index = min(first_leg_index, chain_sig_w_sub_sig.index(signature))
64 
65  if leg_id > first_leg_index:
66  logger.debug("Not returning a HypoTool for %s as this is not the first leg "
67  "with any of %s (leg signatures are %s)",
68  chain_name, tuple(jet_signature_identifiers), tuple(chain_sig_w_sub_sig))
69  raise NoHypoToolCreated("No HypoTool created for %s" % chain_name)
70 
71  logger.debug("Returning a HypoTool for %s as this is the first leg with any of %s (leg signatures are %s)",
72  chain_name, tuple(jet_signature_identifiers), tuple(chain_dict['signatures']))
73 
74  hypo_tool = hypotool_from_chaindict(chain_dict, debug)
75 
76  #if menu has chain in an online monitoring group, unpack the recoalg(s) and hyposcenario(s) to configure monitoring
77  if any('jetMon:online' in group for group in chain_mg):
78  cpl = chain_dict["chainParts"]
79  histFlags = []
80  for cp in cpl:
81  histFlags += [ cp['recoAlg'] ] + [ cp['hypoScenario']]
82  hypo_tool.MonTool = TrigJetHypoToolMonitoring(flags, "HLTJetHypo/"+chain_name, histFlags)
83  return hypo_tool
84 
85 
86 def trigJetTLAHypoToolFromDict(flags, chain_dict):
87  return CompFactory.TrigJetTLAHypoTool(chain_dict['chainName'])
88 
89 def trigJetEJsHypoToolFromDict(flags, chain_dict):
90  if len(chain_dict['chainParts']) > 1:
91  raise Exception("misconfiguration of emerging jet chain")
92 
93  if len(chain_dict['chainParts'][0]['exotHypo']) > 0:
94  exot_hypo = chain_dict['chainParts'][0]['exotHypo'][0]
95  else:
96  raise Exception("Unable to extract exotHypo emerging jet configuration from chain dict")
97 
98  if 'emerging' in exot_hypo:
99  trackless = int(0)
100  ptf = float(exot_hypo.split('PTF')[1].split('dR')[0].replace('p', '.'))
101  dr = float(exot_hypo.split('dR')[1].split('_')[0].replace('p', '.'))
102  elif 'trackless' in exot_hypo:
103  trackless = int(1)
104  ptf = 0.0
105  dr = float(exot_hypo.split('dR')[1].split('_')[0].replace('p', '.'))
106  else:
107  raise Exception("misconfiguration of emerging jet chain")
108 
109  chain_name = chain_dict['chainName']
110 
111  hypo = CompFactory.TrigJetEJsHypoTool(chain_name)
112  hypo.PTF = ptf
113  hypo.dR = dr
114  hypo.Trackless = trackless
115 
116  return hypo
117 
118 def trigJetCRVARHypoToolFromDict(flags, chain_dict):
119  chain_name = chain_dict['chainName']
120  doBIBrm = int(0)
121  doExoCal = int(0)
122  ExoCalCut = 220
123  if len(chain_dict['chainParts'][0]['exotHypo']) > 0:
124  exot_hypo = chain_dict['chainParts'][0]['exotHypo'][0]
125  calratioX_matched = re.match(r'.*calratiovar(?P<cut>\d{1,3}[\d\D]*)', chain_dict['chainParts'][0]['exotHypo'][0])
126  if calratioX_matched:
127  doExoCal= int(1)
128  ExoCalCut = calratioX_matched.groupdict()['cut']
129  else:
130  if len(chain_dict['chainParts'][1]['exotHypo']) > 0:
131  exot_hypo = chain_dict['chainParts'][1]['exotHypo'][0]
132  logger.warning(chain_dict)
133  calratioX_matched = re.match(r'.*calratiovar(?P<cut>\d{1,3}[\d\D]*)', chain_dict['chainParts'][1]['exotHypo'][0])
134  if calratioX_matched:
135  doExoCal= int(1)
136  ExoCalCut = calratioX_matched.groupdict()['cut']
137  else:
138  raise Exception("Unable to extract exotHypo calratio jet configuration from chain dict")
139  if 'calratiovar' in exot_hypo:
140  if 'calratiovarrmbib' in exot_hypo:
141  doBIBrm = int(1)
142  else:
143  raise Exception("misconfiguration of new calratio jet chain")
144 
145  presel_matched = re.match(r'.*emf(?P<cut>\d?\d?[\d\D]+)', chain_dict['chainParts'][0]['trkpresel'])
146  if presel_matched:
147  emf_cut = presel_matched.groupdict()['cut']
148  elif len(chain_dict['chainParts'])>1:
149  presel_matched = re.match(r'.*emf(?P<cut>\d?\d?[\d\D]+)', chain_dict['chainParts'][1]['trkpresel'])
150  if presel_matched:
151  emf_cut = presel_matched.groupdict()['cut']
152  elif len(chain_dict['chainParts'])>3:
153  presel_matched = re.match(r'.*emf(?P<cut>\d?\d?[\d\D]+)', chain_dict['chainParts'][3]['trkpresel'])
154  if presel_matched:
155  emf_cut = presel_matched.groupdict()['cut']
156  else:
157  raise Exception("misconfiguration of Exotic jet chain")
158  else:
159  raise Exception("misconfiguration of Exotic jet chain")
160 
161  import math
162  hypo = CompFactory.TrigJetCRVARHypoTool(chain_name)
163  hypo.MpufixLogRatio = math.log10(1./(float(emf_cut)*0.01) - 1.)
164  hypo.MinjetlogR = 1.2
165  if doExoCal:
166  hypo.MinjetlogR = (float(ExoCalCut)*0.01) - 1.
167  hypo.MintrackPt = 2*GeV
168  hypo.MindeltaR = 0.2
169  hypo.countBIBcells = 4
170  hypo.doBIBremoval = doBIBrm
171 
172  return hypo
173 
174 def trigJetCRHypoToolFromDict(flags, chain_dict):
175  chain_name = chain_dict['chainName']
176 
177  doBIBrm = int(0)
178  if len(chain_dict['chainParts'][0]['exotHypo']) > 0:
179  exot_hypo = chain_dict['chainParts'][0]['exotHypo'][0]
180  else:
181  raise Exception("Unable to extract exotHypo calratio jet configuration from chain dict")
182  if 'calratio' in exot_hypo and ('calratiovar' not in exot_hypo):
183  if 'calratiormbib' in exot_hypo:
184  doBIBrm = int(1)
185  else:
186  raise Exception("misconfiguration of new calratio jet chain")
187 
188  hypo = CompFactory.TrigJetCRHypoTool(chain_name)
189  hypo.MinjetlogR = 1.2
190  hypo.MintrackPt = 2*GeV
191  hypo.MindeltaR = 0.2
192  hypo.countBIBcells = 4
193  hypo.doBIBremoval = doBIBrm
194 
195  return hypo
196 
197 import unittest
198 class TestStringMethods(unittest.TestCase):
199  def testValidConfigs(self):
200  from TriggerMenuMT.HLT.Config.Utility.DictFromChainName import (
201  dictFromChainName,)
202 
203  chain_names = (
204  'HLT_j0_FBDJNOSHARED10etXX20etXX34massXX50fbet_L1J20',)
205 
206  from AthenaConfiguration.AllConfigFlags import initConfigFlags
207  flags = initConfigFlags()
208  flags.Input.Files = []
209 
210  flags.lock()
211 
212  wid = max(len(c) for c in chain_names)
213  for chain_name in chain_names:
214  chain_dict = dictFromChainName(flags, chain_name)
215  tool = trigJetHypoToolFromDict(flags, chain_dict)
216  self.assertIsNotNone(tool)
217  logger.debug(chain_name.rjust(wid), str(tool))
218 
219 
220 
221 if __name__ == '__main__':
222  unittest.main()
223 
224  # 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
vtune_athena.format
format
Definition: vtune_athena.py:14
python.TrigJetHypoToolConfig.trigJetCRHypoToolFromDict
def trigJetCRHypoToolFromDict(flags, chain_dict)
Definition: TrigJetHypoToolConfig.py:174
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.TrigCompositeUtils.isLegId
def isLegId(chainName)
Definition: DecisionHandling/python/TrigCompositeUtils.py:18
DictFromChainName.dictFromChainName
def dictFromChainName(flags, chainInfo)
Definition: DictFromChainName.py:652
python.TrigJetHypoToolConfig.trigJetCRVARHypoToolFromDict
def trigJetCRVARHypoToolFromDict(flags, chain_dict)
Definition: TrigJetHypoToolConfig.py:118
Constants
some useful constants -------------------------------------------------—
python.hypoConfigBuilder.hypotool_from_chaindict
def hypotool_from_chaindict(chain_dict, visit_debug=False)
Definition: hypoConfigBuilder.py:395
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
python.TrigCompositeUtils.getLegIndexInt
def getLegIndexInt(chainName)
Definition: DecisionHandling/python/TrigCompositeUtils.py:21
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
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:199
python.TrigJetHypoToolConfig.trigJetEJsHypoToolFromDict
def trigJetEJsHypoToolFromDict(flags, chain_dict)
Definition: TrigJetHypoToolConfig.py:89
python.TrigJetHypoToolConfig.TestStringMethods
Definition: TrigJetHypoToolConfig.py:198
python.TrigJetHypoToolConfig.trigJetTLAHypoToolFromDict
def trigJetTLAHypoToolFromDict(flags, chain_dict)
Definition: TrigJetHypoToolConfig.py:86
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65