ATLAS Offline Software
Loading...
Searching...
No Matches
AlgConfigs.py
Go to the documentation of this file.
2# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3#
4
5from __future__ import annotations
6
7import copy
8import errno
9import json
10from typing import Any
11import os
12
13from .ConfigHelpers import AlgConfig, stringToMETRecoDict
14from .METRecoSequencesConfig import (
15 cellInputCfg,
16 clusterInputCfg,
17 jetInputCfg,
18 jetRecoDictForMET,
19 trackingInputCfg,
20 pfoInputCfg,
21 mergedPFOInputCfg,
22 cvfClusterInputCfg,
23)
24from .StepOutput import StepOutput
25from ..Menu.SignatureDicts import METChainParts
26import GaudiKernel.SystemOfUnits as Units
27import TrigEFMissingET.PUClassification as PUClassification
28from AthenaConfiguration.ComponentFactory import CompFactory
29from AthenaCommon.Utils.unixtools import find_datafile
30
31
32from AthenaCommon.Logging import logging
33
34log = logging.getLogger(__name__)
35
36
38 """Make sure that all algorithms defined in the METChainParts have
39 configurations
40
41 Really, this is mainly to have something sensible to call in the
42 ConfigHelpers file to succeed the ctest :(
43 """
44 unknown_algs = []
45 for alg in METChainParts["EFrecoAlg"]:
46 for subcls in AlgConfig._get_subclasses():
47 if subcls.algType() == alg:
48 break
49 else:
50 unknown_algs.append(alg)
51 assert (
52 len(unknown_algs) == 0
53 ), "The following EFrecoAlgs do not have AlgConfig classes: " "{}".format(
54 unknown_algs
55 )
56
57
59 @classmethod
60 def algType(cls):
61 return "cell"
62
63 def __init__(self, **recoDict):
64 super(CellConfig, self).__init__(**recoDict)
65
66 def make_reco_algs(self, flags, **recoDict) -> StepOutput:
67 cells = cellInputCfg(flags, **recoDict)
68
69 return self._append_fex(
70 flags,
71 CompFactory.HLT.MET.CellFex(self.fexName, CellName=cells["Cells"]),
72 cells,
73 )
74
75
77 @classmethod
78 def algType(cls):
79 return "tc"
80
81 def __init__(self, calib, **recoDict):
82 super(TCConfig, self).__init__(calib=calib, **recoDict)
83
84 def make_reco_algs(self, flags, **recoDict):
85 clusters = clusterInputCfg(flags, **recoDict)
86 return self._append_fex(
87 flags,
88 CompFactory.HLT.MET.TCFex(self.fexName, ClusterName=clusters["Clusters"]),
89 clusters,
90 )
91
92
94 @classmethod
95 def algType(cls):
96 return "tcpufit"
97
98 def __init__(self, nSigma, **recoDict):
99 super(TCPufitConfig, self).__init__(nSigma=nSigma, **recoDict)
100 if nSigma == "default":
101 nSigma = "sig50"
102 # Strip off the 'sig' part of the string, convert the end to a float, then divide by 10
103 self.n_sigma = float(nSigma[3:]) / 10.0
104
105 def make_reco_algs(self, flags, **recoDict):
106 clusters = clusterInputCfg(flags, **recoDict)
107 return self._append_fex(
108 flags,
109 CompFactory.HLT.MET.TCPufitFex(
110 self.fexName, ClusterName=clusters["Clusters"], NSigma=self.n_sigma
111 ),
112 clusters,
113 )
114
115
117 @classmethod
118 def algType(cls):
119 return "mht"
120
121 def interpret_reco_dict(self) -> dict[str, Any]:
122 # Force the cluster calibration to EM
123 return self.recoDict | {"calib": "em"}
124
125 def make_reco_algs(self, flags, **recoDict):
126 jets = jetInputCfg(flags, **recoDict)
127 return self._append_fex(
128 flags, CompFactory.HLT.MET.MHTFex(self.fexName, JetName=jets["Jets"]), jets
129 )
130
131
132# NB: TrkMHT isn't ready to run with PF jets yet - for that we need to add an
133# option for cPFOs
135 @classmethod
136 def algType(cls):
137 return "trkmht"
138
139 def __init__(self, **recoDict):
140 super(TrkMHTConfig, self).__init__(
141 forceTracks=True,
142 **recoDict,
143 )
144
145 def make_reco_algs(self, flags, **recoDict):
146 inputs = StepOutput.merge(
147 trackingInputCfg(flags, **recoDict),
148 jetInputCfg(flags, force_tracks=True, **recoDict),
149 )
150 return self._append_fex(
151 flags,
152 CompFactory.HLT.MET.TrkMHTFex(
154 JetName=inputs["Jets"],
155 TrackName=inputs["Tracks"],
156 VertexName=inputs["Vertices"],
157 TVAName=inputs["TVA"],
158 TrackLinkName=inputs["GhostTracksLabel"],
159 TrackSelTool=CompFactory.InDet.InDetTrackSelectionTool(
160 CutLevel="Loose",
161 maxZ0SinTheta=1.5,
162 maxD0overSigmaD0=3,
163 minPt=1 * Units.GeV,
164 ),
165 ),
166 inputs,
167 )
168
169
171 @classmethod
172 def algType(cls):
173 return "pfsum"
174
175 def make_reco_algs(self, flags, **recoDict):
176 pfos = pfoInputCfg(flags, **recoDict)
177 return self._append_fex(
178 flags,
179 CompFactory.HLT.MET.PFSumFex(
180 self.fexName, NeutralPFOName=pfos["nPFOs"], ChargedPFOName=pfos["cPFOs"]
181 ),
182 pfos,
183 )
184
185
187 @classmethod
188 def algType(cls):
189 return "pfopufit"
190
191 def __init__(self, nSigma, **recoDict):
192 super(PFOPufitConfig, self).__init__(nSigma=nSigma, **recoDict)
193 if nSigma == "default":
194 nSigma = "sig50"
195 # Strip off the 'sig' part of the string, convert the end to a float, then divide by 10
196 self.n_sigma = float(nSigma[3:]) / 10.0
197
198 def make_reco_algs(self, flags, **recoDict):
199 pfos = mergedPFOInputCfg(flags, **recoDict)
200 return self._append_fex(
201 flags,
202 CompFactory.HLT.MET.PUSplitPufitFex(
204 InputName=pfos["MergedPFOs"],
205 InputCategoryName=pfos["PUCategory"],
206 NeutralThresholdMode=PUClassification.NeutralForward,
207 NSigma=self.n_sigma,
208 ),
209 pfos,
210 )
211
212
214 @classmethod
215 def algType(cls):
216 return "cvfpufit"
217
218 def __init__(self, nSigma, **recoDict):
219 super(CVFPufitConfig, self).__init__(nSigma=nSigma, **recoDict)
220 if nSigma == "default":
221 nSigma = "sig50"
222 # Strip off the 'sig' part of the string, convert the end to and int, then divide by 10
223 self.n_sigma = int(nSigma[3:]) / 10.0
224
225 def make_reco_algs(self, flags, **recoDict):
226 clusters = cvfClusterInputCfg(flags, **recoDict)
227 return self._append_fex(
228 flags,
229 CompFactory.HLT.MET.PUSplitPufitFex(
231 InputName=clusters["Clusters"],
232 InputCategoryName=clusters["PUCategory"],
233 NeutralThresholdMode=PUClassification.NeutralForward,
234 NSigma=self.n_sigma,
235 ),
236 clusters,
237 )
238
239
241 @classmethod
242 def algType(cls):
243 return "mhtpufit"
244
245 def __init__(self, nSigma, **recoDict):
246 super(MHTPufitConfig, self).__init__(nSigma=nSigma, **recoDict)
247 if nSigma == "default":
248 nSigma = "sig50"
249 # Strip off the 'sig' part of the string, convert the end to and int, then divide by 10
250 self.n_sigma = int(nSigma[3:]) / 10.0
251
252 def interpret_reco_dict(self) -> dict[str, Any]:
253 # Set the jet calibration
254 dct = copy.copy(self.recoDict)
255 if dct["jetCalib"] == "default":
256 dct["jetCalib"] = "subjesgscIS"
257 return dct
258
259 def make_reco_algs(self, flags, **recoDict):
260 inputs = StepOutput.merge(jetInputCfg(flags, **recoDict))
261 jrd = jetRecoDictForMET(**recoDict)
262 calibHasAreaSub = "sub" in jrd["jetCalib"]
263 calibHasAreaSub = False # TODO: Fix this - there was a bug in the old implementation
264 if calibHasAreaSub:
265 from JetRecConfig.JetRecConfig import instantiateAliases
266 from JetRecConfig.JetInputConfig import getEventShapeName
267
268 instantiateAliases(inputs["JetDef"])
269 rhoKey = getEventShapeName(inputs["JetDef"], "HLT_")
270 else:
271 rhoKey = ""
272 if recoDict["constitType"] == "pf":
273 inputs.merge_other(mergedPFOInputCfg(flags, **recoDict))
274 input_key = "MergedPFOs"
275 else:
276 inputs.merge_other(clusterInputCfg(flags, **recoDict))
277 input_key = "Clusters"
278 return self._append_fex(
279 flags,
280 CompFactory.HLT.MET.MHTPufitFex(
282 InputJetsName=inputs["Jets"],
283 InputName=inputs[input_key],
284 JetCalibIncludesAreaSub=calibHasAreaSub,
285 JetEventShapeName=rhoKey,
286 NSigma=self.n_sigma,
287 ),
288 inputs,
289 )
290
291
293 @classmethod
294 def algType(cls):
295 return "nn"
296
297 def __init__(self, **recoDict):
298 self.file_name = "TrigEFMissingET/20220429/NNsingleLayerRed.json"
299 # Locate the file on the calib path
300 full_name = find_datafile(
301 self.file_name, os.environ["CALIBPATH"].split(os.pathsep)
302 )
303 if full_name is None:
304 raise FileNotFoundError(
305 errno.ENOENT, "File not found on CALIBPATH", self.file_name
306 )
307 with open(full_name, "r") as fp:
308 network = json.load(fp)
309 # Read the names of the algorithms used from the network file. The network file contains
310 # the container+aux read from it, e.g. HLT_MET_cell.met so we strip off the HLT_MET_ prefix
311 # and the .XX suffix
312 # The variables containers can appear multiple times (e.g. met and sumet) therefore we have
313 # to make sure to only add each once
314 self.input_mets = []
315 for dct in network["inputs"]:
316 for dct2 in dct["variables"]:
317 met = dct2["name"].removeprefix("HLT_MET_").partition(".")[0]
318 if met not in self.input_mets:
319 self.input_mets.append(met)
320
321 super().__init__(**recoDict)
322
323 def make_reco_algs(self, flags, **recoDict) -> StepOutput:
324 inputs = StepOutput()
325 met_names: list[str] = []
326 for alg in self.input_mets:
327 cfg = AlgConfig.fromRecoDict(**stringToMETRecoDict(alg, onlyRecoKeys = True))
328 met_names.append(cfg.outputKey)
329 output = cfg.make_reco_algs(flags, **cfg.interpret_reco_dict())
330 output.add_output_prefix(f"{alg}.")
331 inputs.merge_other(output)
332 return self._append_fex(
333 flags,
334 CompFactory.HLT.MET.NNHLTFex(
335 self.fexName, TriggerMETs=met_names, InputFileName=self.file_name
336 ),
337 inputs,
338 )
__init__(self, nSigma, **recoDict)
make_reco_algs(self, flags, **recoDict)
StepOutput make_reco_algs(self, flags, **recoDict)
Definition AlgConfigs.py:66
make_reco_algs(self, flags, **recoDict)
dict[str, Any] interpret_reco_dict(self)
make_reco_algs(self, flags, **recoDict)
__init__(self, nSigma, **recoDict)
StepOutput make_reco_algs(self, flags, **recoDict)
make_reco_algs(self, flags, **recoDict)
__init__(self, nSigma, **recoDict)
make_reco_algs(self, flags, **recoDict)
make_reco_algs(self, flags, **recoDict)
Definition AlgConfigs.py:84
__init__(self, calib, **recoDict)
Definition AlgConfigs.py:81
__init__(self, nSigma, **recoDict)
Definition AlgConfigs.py:98
make_reco_algs(self, flags, **recoDict)
make_reco_algs(self, flags, **recoDict)
None _append_fex(self, flags, fex, Optional[StepOutput] inputs=None)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177