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