ATLAS Offline Software
DerivationFrameworkCaloConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 #!/usr/bin/env python
3 
4 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
5 from AthenaConfiguration.ComponentFactory import CompFactory
6 
7 
8 def MaxCellDecoratorCfg(flags, **kwargs):
10  kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.Electrons)
11  kwargs.setdefault("SGKey_photons", flags.Egamma.Keys.Output.Photons)
12  acc.setPrivateTools(CompFactory.DerivationFramework.MaxCellDecorator(**kwargs))
13  from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
14 
15  acc.merge(LArOnOffIdMappingCfg(flags))
16  return acc
17 
18 
19 def GainDecoratorCfg(flags, **kwargs):
20  acc = ComponentAccumulator()
21  kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.Electrons)
22  kwargs.setdefault("SGKey_photons", flags.Egamma.Keys.Output.Photons)
23  kwargs.setdefault("name", "GainDecor")
24  acc.setPrivateTools(CompFactory.DerivationFramework.GainDecorator(**kwargs))
25  return acc
26 
27 
28 def EgammaCoreCellRecoveryCfg(flags, **kwargs):
29  acc = ComponentAccumulator()
30  acc.setPrivateTools(
31  CompFactory.DerivationFramework.EGammaClusterCoreCellRecovery(**kwargs)
32  )
33  return acc
34 
35 
36 def CaloFillRectangularClusterCfg(flags, **kwargs):
37  acc = ComponentAccumulator()
38  kwargs.setdefault("cells_name", flags.Egamma.Keys.Input.CaloCells)
39  kwargs.setdefault("fill_cluster", True)
40  acc.setPrivateTools(CompFactory.CaloFillRectangularCluster(**kwargs))
41  return acc
42 
43 
44 def ClusterEnergyPerLayerDecoratorCfg(flags, **kwargs):
45  acc = ComponentAccumulator()
46  kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.Electrons)
47  kwargs.setdefault("SGKey_photons", flags.Egamma.Keys.Output.Photons)
48  kwargs.setdefault("SGKey_caloCells", flags.Egamma.Keys.Input.CaloCells)
49  kwargs.setdefault("neta", 5)
50  kwargs.setdefault("nphi", 5)
51  toolArgs = {}
52  toolArgs.update({"eta_size": kwargs["neta"]})
53  toolArgs.update({"phi_size": kwargs["nphi"]})
54  kwargs.setdefault(
55  "CaloFillRectangularClusterTool",
56  acc.popToolsAndMerge(CaloFillRectangularClusterCfg(flags, **toolArgs)),
57  )
58  acc.setPrivateTools(
59  CompFactory.DerivationFramework.ClusterEnergyPerLayerDecorator(**kwargs)
60  )
61  return acc
62 
63 
64 def MaxCellDecoratorKernelCfg(flags, name="MaxCellDecoratorKernel", **kwargs):
65  acc = ComponentAccumulator()
66 
67  augmentationTools = [
68  acc.addPublicTool(acc.popToolsAndMerge(MaxCellDecoratorCfg(flags)))
69  ]
70 
71  kwargs.setdefault("AugmentationTools", augmentationTools)
72 
73  acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, **kwargs))
74  return acc
75 
76 
77 def CaloDecoratorKernelCfg(flags, name="CaloDecoratorKernel", **kwargs):
78  acc = MaxCellDecoratorKernelCfg(flags)
79 
80  augmentationTools = [
81  acc.addPublicTool(acc.popToolsAndMerge(GainDecoratorCfg(flags)))
82  ]
83 
84  # might need some modification if cell-level reweighting is implemented
85  cluster_sizes = (3, 7), (5, 5), (7, 11)
86  for neta, nphi in cluster_sizes:
87  cename = "ClusterEnergyPerLayerDecorator_%sx%s" % (neta, nphi)
88  ClusterEnergyPerLayerDecorator = acc.popToolsAndMerge(
89  ClusterEnergyPerLayerDecoratorCfg(flags, neta=neta, nphi=nphi, name=cename)
90  )
91  augmentationTools.append(acc.addPublicTool(ClusterEnergyPerLayerDecorator))
92 
93  kwargs.setdefault("AugmentationTools", augmentationTools)
94 
95  acc.addEventAlgo(CompFactory.DerivationFramework.DerivationKernel(name, **kwargs))
96  return acc
97 
98 
99 def CaloClusterThinningCfg(flags, **kwargs):
100  acc = ComponentAccumulator()
101  CaloClusterThinning = CompFactory.DerivationFramework.CaloClusterThinning
102  acc.addPublicTool(CaloClusterThinning(**kwargs), primary=True)
103  return acc
104 
105 
106 
109 
110 
112  """getGainLayerNames( tool ) -> return a list of names of the decorations added to the
113  egamma tool, given the GainDecorator tool"""
114  return [
115  tool.decoration_pattern.format(info=info, layer=layer, gain=gain)
116  for info in ["E", "nCells"]
117  for layer in tool.layers
118  for gain in tool.gain_names.values()
119  ]
120 
121 
123  acc,
124  flags,
125  kernel,
126  collections=None,
127  info=["E", "nCells"],
128 ):
129  """getGainDecorations( acc, kernel collections=["Electrons", "Photons"] ) ->
130  Return a list with the 'ExtraContent' to be added to the decorations to save the gain
131  information per layer"""
132 
133  if collections is None:
134  collections = [flags.Egamma.Keys.Output.Electrons, flags.Egamma.Keys.Output.Photons]
135 
136  GainDecoratorTool = None
137  for toolStr in acc.getEventAlgo(kernel).AugmentationTools:
138  toolStr = f"{toolStr}"
139  splitStr = toolStr.split("/")
140  tool = acc.getPublicTool(splitStr[1])
141  if splitStr[0] == "DerivationFramework::GainDecorator":
142  GainDecoratorTool = tool
143 
144  if GainDecoratorTool:
145  return [
146  "{part}.{info}".format(part=part, info=info)
147  for part in collections
148  for info in getGainLayerNames(GainDecoratorTool)
149  ]
150  else:
151  return ""
152 
153 
155  """getClusterEnergyPerLayerDecorationsLegacy( acc, kernel ) -> return a list of names of the
156  decorations added to the egamma object, given the ClusterEnergyPerLayerDecorations
157  object (e.g. Photons.E7x11_Lr0, ...)"""
158  properties = "SGKey_photons", "SGKey_electrons"
159  ClusterEnergyPerLayerDecorators = []
160  for toolStr in acc.getEventAlgo(kernel).AugmentationTools:
161  toolStr = f"{toolStr}"
162  splitStr = toolStr.split("/")
163  tool = acc.getPublicTool(splitStr[1])
164  if splitStr[0] == "DerivationFramework::ClusterEnergyPerLayerDecorator":
165  ClusterEnergyPerLayerDecorators.append(tool)
166 
167  decorations = []
168  for tool in ClusterEnergyPerLayerDecorators:
169  collections = filter(bool, (getattr(tool, x) for x in properties))
170  for part in collections:
171  for layer in tool.layers:
172  decorations.extend(
173  [
174  "{part}.E{neta}x{nphi}_Lr{layer}".format(
175  part=part,
176  neta=tool.neta,
177  nphi=tool.nphi,
178  layer=layer,
179  )
180  ]
181  )
182  return decorations
DerivationFrameworkCaloConfig.CaloClusterThinningCfg
def CaloClusterThinningCfg(flags, **kwargs)
Definition: DerivationFrameworkCaloConfig.py:99
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
vtune_athena.format
format
Definition: vtune_athena.py:14
DerivationFrameworkCaloConfig.MaxCellDecoratorCfg
def MaxCellDecoratorCfg(flags, **kwargs)
Definition: DerivationFrameworkCaloConfig.py:8
covarianceTool.filter
filter
Definition: covarianceTool.py:514
DerivationFrameworkCaloConfig.EgammaCoreCellRecoveryCfg
def EgammaCoreCellRecoveryCfg(flags, **kwargs)
Definition: DerivationFrameworkCaloConfig.py:28
DerivationFrameworkCaloConfig.GainDecoratorCfg
def GainDecoratorCfg(flags, **kwargs)
Definition: DerivationFrameworkCaloConfig.py:19
DerivationFrameworkCaloConfig.getGainLayerNames
def getGainLayerNames(tool)
additional utilities to return the list of decorations added by the tools
Definition: DerivationFrameworkCaloConfig.py:111
DerivationFrameworkCaloConfig.ClusterEnergyPerLayerDecoratorCfg
def ClusterEnergyPerLayerDecoratorCfg(flags, **kwargs)
Definition: DerivationFrameworkCaloConfig.py:44
DerivationFrameworkCaloConfig.MaxCellDecoratorKernelCfg
def MaxCellDecoratorKernelCfg(flags, name="MaxCellDecoratorKernel", **kwargs)
Definition: DerivationFrameworkCaloConfig.py:64
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
DerivationFrameworkCaloConfig.CaloDecoratorKernelCfg
def CaloDecoratorKernelCfg(flags, name="CaloDecoratorKernel", **kwargs)
Definition: DerivationFrameworkCaloConfig.py:77
DerivationFrameworkCaloConfig.getClusterEnergyPerLayerDecorations
def getClusterEnergyPerLayerDecorations(acc, kernel)
Definition: DerivationFrameworkCaloConfig.py:154
DerivationFrameworkCaloConfig.getGainDecorations
def getGainDecorations(acc, flags, kernel, collections=None, info=["E", "nCells"])
Definition: DerivationFrameworkCaloConfig.py:122
DerivationFrameworkCaloConfig.CaloFillRectangularClusterCfg
def CaloFillRectangularClusterCfg(flags, **kwargs)
Definition: DerivationFrameworkCaloConfig.py:36