ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFrameworkCaloConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4from AthenaConfiguration.ComponentFactory import CompFactory
5
6def CaloCellDecoratorCfg(flags, **kwargs):
7 acc = ComponentAccumulator()
8 kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.Electrons)
9 kwargs.setdefault("SGKey_photons", flags.Egamma.Keys.Output.Photons)
10 kwargs.setdefault("SGKey_CaloCells", flags.Egamma.Keys.Input.CaloCells)
11
12 from egammaCaloTools.egammaCaloToolsConfig import egammaLargeClusterCellRecoveryToolCfg
13 kwargs.setdefault("egammaLargeClusterCellRecoveryTool",
14 acc.popToolsAndMerge(egammaLargeClusterCellRecoveryToolCfg(flags)))
15
16 acc.setPrivateTools(CompFactory.DerivationFramework.CaloCellDecorator(**kwargs))
17 from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
18
19 acc.merge(LArOnOffIdMappingCfg(flags))
20 return acc
21
22
23def MaxCellDecoratorCfg(flags, name="MaxCellDecorator", **kwargs):
24 acc = ComponentAccumulator()
25 kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.Electrons)
26 baseDecorations =["maxEcell_time", "maxEcell_energy", "maxEcell_gain",
27 "maxEcell_onlId", "maxEcell_x", "maxEcell_y", "maxEcell_z"]
28 electronDecorations = baseDecorations
29 kwargs.setdefault("SGKey_egammaClusters", "")
30 if kwargs["SGKey_egammaClusters"] != '':
31 electronDecorations += ["dR"]
32 kwargs.setdefault("SGKey_electrons_decorations", electronDecorations)
33 kwargs.setdefault("SGKey_photons", flags.Egamma.Keys.Output.Photons)
34 acc.setPrivateTools(CompFactory.DerivationFramework.MaxCellDecorator(name, **kwargs))
35 from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
36
37 acc.merge(LArOnOffIdMappingCfg(flags))
38 return acc
39
40
41def GainDecoratorCfg(flags, **kwargs):
42 acc = ComponentAccumulator()
43 decorationPattern = kwargs.pop("decoration_pattern", "{}_Lr{}_{}G")
44 kwargs.setdefault("gain_names", { 0 : "Hi", 1 : "Med", 2 : "Low" })
45 kwargs.setdefault("layers", [0, 1, 2, 3])
46 decorNames = []
47 for x, gain in kwargs["gain_names"].items():
48 for layer in kwargs["layers"]:
49 decorNames += [decorationPattern.format("E", layer, gain)]
50 decorNames += [decorationPattern.format("rnoW", layer, gain)]
51 decorNames += [decorationPattern.format("nCells", layer, gain)]
52 kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.Electrons)
53 kwargs.setdefault("SGKey_electrons_decorations", decorNames)
54 kwargs.setdefault("SGKey_photons", flags.Egamma.Keys.Output.Photons)
55 kwargs.setdefault("SGKey_photons_decorations", decorNames)
56 kwargs.setdefault("name", "GainDecor")
57 acc.setPrivateTools(CompFactory.DerivationFramework.GainDecorator(**kwargs))
58 return acc
59
60
61def EgammaCoreCellRecoveryCfg(flags, **kwargs):
62 acc = ComponentAccumulator()
63 # needed for reading cells, do not rely on other config to do that
64 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
65 acc.merge(LArGMCfg(flags))
66 from TileGeoModel.TileGMConfig import TileGMCfg
67 acc.merge(TileGMCfg(flags))
68 #
69 acc.setPrivateTools(
70 CompFactory.DerivationFramework.EGammaClusterCoreCellRecovery(**kwargs)
71 )
72 return acc
73
74
75def CaloFillRectangularClusterCfg(flags, **kwargs):
76 acc = ComponentAccumulator()
77 kwargs.setdefault("cells_name", flags.Egamma.Keys.Input.CaloCells)
78 kwargs.setdefault("fill_cluster", True)
79 acc.setPrivateTools(CompFactory.CaloFillRectangularCluster(**kwargs))
80 return acc
81
82
84 acc = ComponentAccumulator()
85 kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.Electrons)
86 kwargs.setdefault("SGKey_photons", flags.Egamma.Keys.Output.Photons)
87 kwargs.setdefault("SGKey_caloCells", flags.Egamma.Keys.Input.CaloCells)
88 neta = kwargs.pop("neta", 5)
89 nphi = kwargs.pop("nphi", 5)
90 kwargs.setdefault("layers", [ 0, 1, 2, 3 ])
91 decorBase = "E{}x{}_Lr".format(neta, nphi)
92 kwargs.setdefault("SGKey_photons_decorations", [decorBase+str(layer) for layer in kwargs['layers']])
93 kwargs.setdefault("SGKey_electrons_decorations", [decorBase+str(layer) for layer in kwargs['layers']])
94 toolArgs = {}
95 toolArgs.update({"eta_size": neta})
96 toolArgs.update({"phi_size": nphi})
97 kwargs.setdefault(
98 "CaloFillRectangularClusterTool",
99 acc.popToolsAndMerge(CaloFillRectangularClusterCfg(flags, **toolArgs)),
100 )
101 acc.setPrivateTools(
102 CompFactory.DerivationFramework.ClusterEnergyPerLayerDecorator(**kwargs)
103 )
104 return acc
105
106
107def CaloCellDecoratorKernelCfg(flags, name="CaloCellDecoratorKernel", **kwargs):
108 acc = ComponentAccumulator()
109
110 augmentationTools = [
111 acc.addPublicTool(acc.popToolsAndMerge(CaloCellDecoratorCfg(flags)))
112 ]
113
114 kwargs.setdefault("AugmentationTools", augmentationTools)
115
116 acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, **kwargs))
117 return acc
118
119
120def MaxCellDecoratorKernelCfg(flags, name="MaxCellDecoratorKernel", **kwargs):
121 acc = ComponentAccumulator()
122
123 augmentationTools = [
124 acc.addPublicTool(acc.popToolsAndMerge(MaxCellDecoratorCfg(flags)))
125 ]
126
127 kwargs.setdefault("AugmentationTools", augmentationTools)
128
129 acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, **kwargs))
130 return acc
131
132
133def CaloDecoratorKernelCfg(flags, name="CaloDecoratorKernel", **kwargs):
134 acc = MaxCellDecoratorKernelCfg(flags)
135
136 augmentationTools = [
137 acc.addPublicTool(acc.popToolsAndMerge(GainDecoratorCfg(flags)))
138 ]
139
140 # might need some modification if cell-level reweighting is implemented
141 cluster_sizes = (3, 7), (5, 5), (7, 11)
142 for neta, nphi in cluster_sizes:
143 cename = "ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi)
144 ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge(
145 ClusterEnergyPerLayerDecoratorCfg(flags, neta=neta, nphi=nphi, name=cename)
146 )
147 augmentationTools.append(acc.addPublicTool(ClusterEnergyPerLayerDecorator))
148
149 kwargs.setdefault("AugmentationTools", augmentationTools)
150
151 acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, **kwargs))
152 return acc
153
154
155def CaloClusterThinningCfg(flags, **kwargs):
156 acc = ComponentAccumulator()
157 CaloClusterThinning = CompFactory.DerivationFramework.CaloClusterThinning
158 acc.addPublicTool(CaloClusterThinning(**kwargs), primary=True)
159 return acc
160
161def JetCaloClusterThinningCfg(flags, **kwargs):
162 acc = ComponentAccumulator()
163 JetCaloClusterThinning = CompFactory.DerivationFramework.JetCaloClusterThinning
164 acc.addPublicTool(JetCaloClusterThinning(**kwargs), primary=True)
165 return acc
166
167
170
171
173 """getGainLayerNames( tool ) -> return a list of names of the decorations added to the
174 egamma tool, given the GainDecorator tool"""
175 return [
176 tool.decoration_pattern.format(info=info, layer=layer, gain=gain)
177 for info in ["E", "nCells"]
178 for layer in tool.layers
179 for gain in tool.gain_names.values()
180 ]
181
182
184 acc,
185 flags,
186 kernel,
187 collections=None,
188 info=["E", "nCells"],
189):
190 """getGainDecorations( acc, kernel collections=["Electrons", "Photons"] ) ->
191 Return a list with the 'ExtraContent' to be added to the decorations to save the gain
192 information per layer"""
193
194 if collections is None:
195 collections = [flags.Egamma.Keys.Output.Electrons, flags.Egamma.Keys.Output.Photons]
196
197 GainDecoratorTool = None
198 for tool in acc.getEventAlgo(kernel).AugmentationTools:
199 if tool.getType() == "DerivationFramework::GainDecorator":
200 GainDecoratorTool = tool
201
202 if GainDecoratorTool:
203 return [
204 "{part}.{info}".format(part=part, info=info)
205 for part in collections
206 for info in getGainLayerNames(GainDecoratorTool)
207 ]
208 else:
209 return ""
210
211
212def getClusterEnergyPerLayerDecorations(acc, kernel):
213 """getClusterEnergyPerLayerDecorationsLegacy( acc, kernel ) -> return a list of names of the
214 decorations added to the egamma object, given the ClusterEnergyPerLayerDecorations
215 object (e.g. Photons.E7x11_Lr0, ...)"""
216 properties = "SGKey_photons", "SGKey_electrons"
217 ClusterEnergyPerLayerDecorators = []
218 for tool in acc.getEventAlgo(kernel).AugmentationTools:
219 if tool.getType() == "DerivationFramework::ClusterEnergyPerLayerDecorator":
220 ClusterEnergyPerLayerDecorators.append(tool)
221
222 decorations = []
223 for tool in ClusterEnergyPerLayerDecorators:
224 collections = filter(bool, (getattr(tool, x) for x in properties))
225 for part in collections:
226 key = "SGKey_{}_decorations".format(str(part).lower())
227 decorations.extend(getattr(tool, key))
228 return decorations
MaxCellDecoratorKernelCfg(flags, name="MaxCellDecoratorKernel", **kwargs)
MaxCellDecoratorCfg(flags, name="MaxCellDecorator", **kwargs)
getGainDecorations(acc, flags, kernel, collections=None, info=["E", "nCells"])
CaloCellDecoratorKernelCfg(flags, name="CaloCellDecoratorKernel", **kwargs)
getGainLayerNames(tool)
additional utilities to return the list of decorations added by the tools
CaloDecoratorKernelCfg(flags, name="CaloDecoratorKernel", **kwargs)