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