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