ATLAS Offline Software
AlgConfigs.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 from __future__ import annotations
6 
7 import copy
8 import errno
9 import json
10 from typing import Any
11 import os
12 
13 from .ConfigHelpers import AlgConfig, stringToMETRecoDict
14 from .METRecoSequencesConfig import (
15  cellInputCfg,
16  clusterInputCfg,
17  jetInputCfg,
18  jetRecoDictForMET,
19  trackingInputCfg,
20  pfoInputCfg,
21  mergedPFOInputCfg,
22  cvfClusterInputCfg,
23 )
24 from .StepOutput import StepOutput
25 from ..Menu.SignatureDicts import METChainParts
26 import GaudiKernel.SystemOfUnits as Units
27 import TrigEFMissingET.PUClassification as PUClassification
28 from AthenaConfiguration.ComponentFactory import CompFactory
29 from AthenaCommon.Utils.unixtools import find_datafile
30 
31 
32 from AthenaCommon.Logging import logging
33 
34 log = 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(
153  self.fexName,
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(
203  self.fexName,
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(
230  self.fexName,
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(
281  self.fexName,
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  )
python.HLT.MET.ConfigHelpers.AlgConfig._append_fex
None _append_fex(self, flags, fex, Optional[StepOutput] inputs=None)
Definition: ConfigHelpers.py:168
python.HLT.MET.AlgConfigs.TCPufitConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:105
python.HLT.MET.AlgConfigs.MHTPufitConfig.interpret_reco_dict
dict[str, Any] interpret_reco_dict(self)
Definition: AlgConfigs.py:252
python.HLT.MET.AlgConfigs.PFSumConfig
Definition: AlgConfigs.py:170
python.HLT.MET.AlgConfigs.NNHLTConfig.input_mets
input_mets
Definition: AlgConfigs.py:314
vtune_athena.format
format
Definition: vtune_athena.py:14
python.HLT.MET.AlgConfigs.TrkMHTConfig.__init__
def __init__(self, **recoDict)
Definition: AlgConfigs.py:139
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.HLT.MET.AlgConfigs.NNHLTConfig
Definition: AlgConfigs.py:292
python.HLT.MET.AlgConfigs.MHTPufitConfig.algType
def algType(cls)
Definition: AlgConfigs.py:242
python.HLT.MET.AlgConfigs.NNHLTConfig.__init__
def __init__(self, **recoDict)
Definition: AlgConfigs.py:297
python.HLT.MET.AlgConfigs.NNHLTConfig.make_reco_algs
StepOutput make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:323
python.HLT.MET.AlgConfigs.CellConfig
Definition: AlgConfigs.py:58
python.HLT.MET.AlgConfigs.MHTPufitConfig.__init__
def __init__(self, nSigma, **recoDict)
Definition: AlgConfigs.py:245
python.HLT.MET.AlgConfigs.NNHLTConfig.algType
def algType(cls)
Definition: AlgConfigs.py:294
python.HLT.MET.AlgConfigs.TCPufitConfig.n_sigma
n_sigma
Definition: AlgConfigs.py:103
python.HLT.MET.AlgConfigs.PFOPufitConfig
Definition: AlgConfigs.py:186
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.HLT.MET.AlgConfigs.TCConfig.algType
def algType(cls)
Definition: AlgConfigs.py:78
python.HLT.MET.AlgConfigs.CellConfig.algType
def algType(cls)
Definition: AlgConfigs.py:60
python.HLT.MET.METRecoSequencesConfig.pfoInputCfg
StepOutput pfoInputCfg(flags, **recoDict)
Definition: METRecoSequencesConfig.py:104
python.HLT.MET.AlgConfigs.TCPufitConfig.algType
def algType(cls)
Definition: AlgConfigs.py:95
python.HLT.MET.AlgConfigs.CVFPufitConfig.algType
def algType(cls)
Definition: AlgConfigs.py:215
python.HLT.MET.AlgConfigs.MHTConfig.algType
def algType(cls)
Definition: AlgConfigs.py:118
python.HLT.MET.AlgConfigs.TCConfig
Definition: AlgConfigs.py:76
python.HLT.MET.AlgConfigs.TrkMHTConfig.algType
def algType(cls)
Definition: AlgConfigs.py:136
python.HLT.MET.AlgConfigs.PFSumConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:175
EventDensityConfig.getEventShapeName
def getEventShapeName(defOrLabel, nameprefix="", suffix=None, radius=0.4)
Definition: EventDensityConfig.py:7
python.HLT.MET.StepOutput.StepOutput
Definition: StepOutput.py:19
python.HLT.MET.AlgConfigs.test_configs
def test_configs()
Definition: AlgConfigs.py:37
python.HLT.MET.AlgConfigs.PFOPufitConfig.n_sigma
n_sigma
Definition: AlgConfigs.py:196
python.HLT.MET.ConfigHelpers.AlgConfig
Definition: ConfigHelpers.py:94
python.HLT.MET.AlgConfigs.TrkMHTConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:145
python.HLT.MET.ConfigHelpers.AlgConfig.recoDict
recoDict
Definition: ConfigHelpers.py:135
python.HLT.MET.AlgConfigs.CVFPufitConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:225
python.HLT.MET.AlgConfigs.TCConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:84
python.HLT.MET.METRecoSequencesConfig.jetInputCfg
StepOutput jetInputCfg(flags, bool force_tracks=False, **recoDict)
Definition: METRecoSequencesConfig.py:201
python.HLT.MET.AlgConfigs.NNHLTConfig.file_name
file_name
Definition: AlgConfigs.py:298
python.HLT.MET.AlgConfigs.PFSumConfig.algType
def algType(cls)
Definition: AlgConfigs.py:172
python.HLT.MET.AlgConfigs.PFOPufitConfig.__init__
def __init__(self, nSigma, **recoDict)
Definition: AlgConfigs.py:191
python.HLT.MET.AlgConfigs.PFOPufitConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:198
python.HLT.MET.AlgConfigs.CVFPufitConfig
Definition: AlgConfigs.py:213
python.HLT.MET.AlgConfigs.MHTPufitConfig
Definition: AlgConfigs.py:240
python.HLT.MET.AlgConfigs.MHTConfig
Definition: AlgConfigs.py:116
python.HLT.MET.AlgConfigs.MHTPufitConfig.n_sigma
n_sigma
Definition: AlgConfigs.py:250
python.HLT.MET.AlgConfigs.TCPufitConfig
Definition: AlgConfigs.py:93
Trk::open
@ open
Definition: BinningType.h:40
python.HLT.MET.AlgConfigs.TrkMHTConfig
Definition: AlgConfigs.py:134
python.HLT.MET.AlgConfigs.MHTPufitConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:259
python.HLT.MET.METRecoSequencesConfig.clusterInputCfg
StepOutput clusterInputCfg(flags, **recoDict)
Definition: METRecoSequencesConfig.py:68
python.HLT.MET.ConfigHelpers.AlgConfig.fexName
str fexName(self)
Definition: ConfigHelpers.py:146
python.HLT.MET.AlgConfigs.MHTConfig.interpret_reco_dict
dict[str, Any] interpret_reco_dict(self)
Definition: AlgConfigs.py:121
python.HLT.MET.METRecoSequencesConfig.trackingInputCfg
StepOutput trackingInputCfg(flags, **recoDict)
Definition: METRecoSequencesConfig.py:94
python.HLT.MET.AlgConfigs.CVFPufitConfig.n_sigma
n_sigma
Definition: AlgConfigs.py:223
python.HLT.MET.AlgConfigs.TCConfig.__init__
def __init__(self, calib, **recoDict)
Definition: AlgConfigs.py:81
StateLessPT_NewConfig.partition
partition
Definition: StateLessPT_NewConfig.py:49
python.HLT.MET.METRecoSequencesConfig.cellInputCfg
StepOutput cellInputCfg(flags, **recoDict)
Definition: METRecoSequencesConfig.py:61
python.HLT.MET.AlgConfigs.TCPufitConfig.__init__
def __init__(self, nSigma, **recoDict)
Definition: AlgConfigs.py:98
python.HLT.MET.AlgConfigs.MHTConfig.make_reco_algs
def make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:125
python.HLT.MET.ConfigHelpers.stringToMETRecoDict
dict[str, Any] stringToMETRecoDict(str string, bool onlyRecoKeys=False)
Definition: ConfigHelpers.py:74
python.Utils.unixtools.find_datafile
def find_datafile(fname, pathlist=None, access=os.R_OK)
pathresolver-like helper function --------------------------------------—
Definition: unixtools.py:67
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.HLT.MET.AlgConfigs.CellConfig.__init__
def __init__(self, **recoDict)
Definition: AlgConfigs.py:63
python.HLT.MET.AlgConfigs.CellConfig.make_reco_algs
StepOutput make_reco_algs(self, flags, **recoDict)
Definition: AlgConfigs.py:66
python.HLT.MET.METRecoSequencesConfig.mergedPFOInputCfg
StepOutput mergedPFOInputCfg(flags, **recoDict)
Definition: METRecoSequencesConfig.py:144
python.HLT.MET.AlgConfigs.CVFPufitConfig.__init__
def __init__(self, nSigma, **recoDict)
Definition: AlgConfigs.py:218
python.HLT.MET.AlgConfigs.PFOPufitConfig.algType
def algType(cls)
Definition: AlgConfigs.py:188
python.HLT.MET.METRecoSequencesConfig.cvfClusterInputCfg
StepOutput cvfClusterInputCfg(flags, **recoDict)
Definition: METRecoSequencesConfig.py:162
python.HLT.MET.METRecoSequencesConfig.jetRecoDictForMET
dict[str, Any] jetRecoDictForMET(**recoDict)
Definition: METRecoSequencesConfig.py:34