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