ATLAS Offline Software
Loading...
Searching...
No Matches
METRecoSequencesConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3"""Configuration sequences for the MET input reconstruction
4
5By convention all of these functions return two values: first a defaultdict mapping from
6reco step to the component accumulators containing the reconstruction sequences and
7second the name(s) of the key outputs created. The names can either be a single string
8if there is only one output or a tuple otherwise. Which outputs are returned and their
9order should be clearly documented in the method documentation
10"""
11
12from typing import Any
13
14from AthenaConfiguration.AccumulatorCache import AccumulatorCache
15from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
16from AthenaConfiguration.ComponentFactory import CompFactory
17from eflowRec.PFHLTConfig import PFCfg
18from JetRecConfig.JetRecConfig import getConstitModAlg_nojetdef
19from TrigCaloRec.TrigCaloRecConfig import (
20 hltCaloCellMakerCfg,
21 jetmetTopoClusteringCfg,
22 jetmetTopoClusteringCfg_LC,
23)
24from ..CommonSequences.FullScanDefs import em_clusters, lc_clusters, trkFSRoI
25from ..Jet.JetRecoCommon import (
26 defineJetConstit,
27)
28from ..Jet.JetRecoSequencesConfig import JetRecoDataDeps, JetRecoCfg
29from ..Jet.JetTrackingConfig import JetFSTrackingCfg
30from .StepOutput import StepOutput
31from TrackVertexAssociationTool.TrackVertexAssociationToolConfig import CVF_TTVAToolCfg
32import contextlib
33
34
35def jetRecoDictForMET(**recoDict) -> dict[str, Any]:
36 """Get a jet reco dict that's usable for the MET slice"""
37 from ..Jet.JetRecoCommon import getJetCalibDefaultString, jetRecoDictToString
38 from ..Jet.JetRecoCommon import recoKeys as jetRecoKeys
39 from ..Menu.SignatureDicts import JetChainParts_Default
40
41 jrd = {k: recoDict.get(k, JetChainParts_Default[k]) for k in jetRecoKeys}
42 # Rename the cluster calibration
43 with contextlib.suppress(KeyError):
44 jrd["clusterCalib"] = recoDict["calib"]
45 # Fill constitMod
46 jrd["constitMod"] = recoDict.get("constitmod", "")
47 # We only use em calibration for PFOs
48 if jrd["constitType"] == "pf":
49 jrd["clusterCalib"] = "em"
50 # Interpret jet calibration
51 if jrd["jetCalib"] == "default":
52 jrd["jetCalib"] = getJetCalibDefaultString(jrd['recoAlg'],jrd['constitType'],jrd['trkopt'])
53 if jrd["constitType"] != "tc" or "gsc" in jrd["jetCalib"]:
54 jrd["trkopt"] = "ftf"
55 jrd["jetDefStr"] = jetRecoDictToString(jrd)
56 return jrd
57
58
59@AccumulatorCache
60def cellInputCfg(flags, **recoDict) -> StepOutput:
61 """Create the cell inputs"""
62 acc = hltCaloCellMakerCfg(flags, name="HLTCaloCellMakerFS", roisKey="")
63 return StepOutput.create(acc, Cells=acc.getPrimary().CellsName)
64
65
66@AccumulatorCache
67def clusterInputCfg(flags, **recoDict) -> StepOutput:
68 """Create the cluster inputs"""
69 if recoDict["calib"] == "em":
70 acc = jetmetTopoClusteringCfg(flags, RoIs="")
71 clusters = em_clusters
72 elif recoDict["calib"] == "lcw":
73 acc = jetmetTopoClusteringCfg_LC(flags, RoIs="")
74 clusters = lc_clusters
75 else:
76 raise ValueError(f"Invalid cluster calibration '{recoDict['calib']}'")
77
78 if recoDict.get("constitmod"):
79 # Force the constituent type to topoclusters
80 jetRecoDict = jetRecoDictForMET(**(recoDict | {"constitType": "tc"}))
81 constit = defineJetConstit(jetRecoDict, clustersKey=clusters)
82 acc.addEventAlgo(
83 getConstitModAlg_nojetdef(
84 constit, flags, context=jetRecoDict.get("trkopt", "default"),
85 )
86 )
87 clusters = constit.containername
88
89 return StepOutput.create(acc, Clusters=clusters)
90
91
92@AccumulatorCache
93def trackingInputCfg(flags, **recoDict) -> StepOutput:
94 """Get the tracking inputs"""
95 return StepOutput.create(
96 JetFSTrackingCfg(flags, "ftf", RoIs=trkFSRoI),
97 step_idx=2,
98 **flags.Jet.Context.ftf,
99 )
100
101
102@AccumulatorCache
103def pfoInputCfg(flags, **recoDict) -> StepOutput:
104 """Get the PFO inputs"""
105 inputs = StepOutput.merge(
106 cellInputCfg(flags),
107 clusterInputCfg(flags, calib="em"),
108 trackingInputCfg(flags),
109 )
110 acc = PFCfg(
111 flags,
112 tracktype="ftf",
113 clustersin=inputs["Clusters"],
114 calclustersin="",
115 tracksin=inputs["Tracks"],
116 verticesin=inputs["Vertices"],
117 cellsin=inputs["Cells"],
118 )
119
120 # The jet constituent modifier sequence here is to apply the correct weights and
121 # decorate the PV matching decoration. If we've specified constituent modifiers
122 # those are also applied.
123 jetRecoDict = jetRecoDictForMET(
124 **(recoDict | {"trkopt": "ftf", "constitType": "pf"})
125 )
126 constit = defineJetConstit(jetRecoDict, pfoPrefix="HLT_ftf")
127 acc.addEventAlgo(
128 getConstitModAlg_nojetdef(constit, flags, context=jetRecoDict.get("trkopt", "default"))
129 )
130 pfoPrefix = constit.containername
131 if pfoPrefix.endswith("ParticleFlowObjects"):
132 pfoPrefix = pfoPrefix[:-19]
133 return StepOutput.create(
134 acc,
135 inputs,
136 PFOPrefix=pfoPrefix,
137 cPFOs=pfoPrefix + "ChargedParticleFlowObjects",
138 nPFOs=pfoPrefix + "NeutralParticleFlowObjects",
139 )
140
141
142@AccumulatorCache
143def mergedPFOInputCfg(flags, **recoDict) -> StepOutput:
144 """Create the merged PFO inputs"""
145 pfos = pfoInputCfg(flags, **recoDict)
146 alg = CompFactory.HLT.MET.FlowElementPrepAlg(
147 f"{pfos['PFOPrefix']}METTrigPFOPrepAlg",
148 InputNeutralKey=pfos["nPFOs"],
149 InputChargedKey=pfos["cPFOs"],
150 OutputKey=f"{pfos['PFOPrefix']}METTrigCombinedParticleFlowObjects",
151 OutputCategoryKey="PUClassification",
152 )
153 acc = ComponentAccumulator()
154 acc.addEventAlgo(alg, primary=True)
155 return StepOutput.create(
156 acc, pfos, MergedPFOs=alg.OutputKey, PUCategory=alg.OutputCategoryKey
157 )
158
159
160@AccumulatorCache
161def cvfClusterInputCfg(flags, **recoDict) -> StepOutput:
162 """Create the clusters with CVF decorated"""
163 inputs = StepOutput.merge(
164 clusterInputCfg(flags, **recoDict),
165 trackingInputCfg(flags),
166 )
167 acc = ComponentAccumulator()
168 acc.addEventAlgo(
169 CompFactory.HLT.MET.CVFAlg(
170 f"{recoDict['calib']}ftfClusterCVFAlg",
171 InputClusterKey=inputs["Clusters"],
172 InputTrackKey=inputs["Tracks"],
173 InputVertexKey=inputs["Vertices"],
174 OutputCVFKey="CVF",
175 TrackSelectionTool=CompFactory.InDet.InDetTrackSelectionTool(
176 CutLevel="TightPrimary"
177 ),
178 TVATool=acc.popToolsAndMerge(
179 CVF_TTVAToolCfg(
180 flags,
181 TrackContName=inputs["Tracks"],
182 VertexContName=inputs["Vertices"]
183 )
184 ),
185 ExtensionTool=CompFactory.ApproximateTrackToLayerTool(),
186 )
187 )
188 acc.addEventAlgo(
189 CompFactory.HLT.MET.CVFPrepAlg(
190 f"{recoDict['calib']}ftfClusterCVFPrepAlg",
191 InputClusterKey=inputs["Clusters"],
192 InputCVFKey="CVF",
193 OutputCategoryKey="PUClassification",
194 )
195 )
196 return StepOutput.create(acc, inputs, CVF="CVF", PUCategory="PUClassification")
197
198
199@AccumulatorCache
200def jetInputCfg(flags, force_tracks: bool = False, **recoDict) -> StepOutput:
201 """Create the input jets
202
203 Set force_tracks to True to require tracks and ensure that they are ghost-associated
204 to the jets.
205
206 Returns the accumulators and (jets, jetDef)
207 """
208 if force_tracks:
209 recoDict["trkopt"] = "ftf"
210 # hard code to em (for now) - there are no LC jets in EDM
211 jrd = jetRecoDictForMET(
212 **(
213 recoDict
214 | {"calib": "em"}
215 )
216 )
217
218 inputs = StepOutput()
219 if jrd["trkopt"] == "ftf":
220 inputs.merge_other(trackingInputCfg(flags))
221 if jrd["constitType"] == "pf":
222 inputs.merge_other(pfoInputCfg(flags))
223 else:
224 # Always use EM clusters for jets
225 inputs.merge_other(clusterInputCfg(flags, calib="em"))
226
227 acc = ComponentAccumulator()
228 jetDefDict = JetRecoDataDeps(flags, **jrd)
229 jetName, jetDef = jetDefDict['final']
230 jet_acc = JetRecoCfg(flags, **jetDefDict)
231 acc.merge(jet_acc)
232 return StepOutput.create(
233 acc, inputs, Jets=jetName, JetDef=jetDef, **jetDef._contextDic
234 )
Definition PFCfg.py:1
StepOutput cellInputCfg(flags, **recoDict)
StepOutput cvfClusterInputCfg(flags, **recoDict)
StepOutput jetInputCfg(flags, bool force_tracks=False, **recoDict)
StepOutput trackingInputCfg(flags, **recoDict)
StepOutput clusterInputCfg(flags, **recoDict)
StepOutput mergedPFOInputCfg(flags, **recoDict)
StepOutput pfoInputCfg(flags, **recoDict)