ATLAS Offline Software
Loading...
Searching...
No Matches
EGammaToolsConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3# ==============================================================================
4# Provides configs for the tools used for e-gamma decorations used in DAOD
5# building
6# ==============================================================================
7
8from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9from AthenaConfiguration.ComponentFactory import CompFactory
10
11
12# PhotonsDirectionTool
13def PhotonsDirectionToolCfg(flags, name, **kwargs):
14 """Configure the PhotonsDirectionTool"""
15 acc = ComponentAccumulator()
16 acc.setPrivateTools(CompFactory.DerivationFramework.PhotonsDirectionTool(name, **kwargs))
17 return acc
18
19
20# E-gamma selection tool wrapper
21def EGSelectionToolWrapperCfg(flags, name, **kwargs):
22 """Configure the E-gamma selection tool wrapper"""
23 acc = ComponentAccumulator()
24 sgName = kwargs.pop("StoreGateEntryName", "")
25 if not sgName:
26 raise AttributeError("StoreGateEntryName not set")
27 kwargs.setdefault("decoratorPass", sgName)
28 kwargs.setdefault("decoratorIsEM", sgName + "IsEMValue")
29 acc.setPrivateTools(CompFactory.DerivationFramework.EGSelectionToolWrapper(name, **kwargs))
30 return acc
31
32
33# Electron likelihood tool wrapper
34def EGElectronLikelihoodToolWrapperCfg(flags, name, **kwargs):
35 """Configure the electron likelihood tool wrapper"""
36 acc = ComponentAccumulator()
37 sgName = kwargs.pop("StoreGateEntryName", "")
38 containerName = kwargs.setdefault("ContainerName", "")
39 if not sgName:
40 raise AttributeError("StoreGateEntryName not set")
41 if not containerName:
42 raise AttributeError("ContainerName empty string")
43 storeTResult = kwargs.setdefault("StoreTResult", False)
44 storeMultipleOutputs = kwargs.setdefault("StoreMultipleOutputs", False)
45 sgMultipleNames = kwargs.pop("StoreGateEntryMultipleNames", [])
46 # Write decoration handle keys
47 kwargs.setdefault("decoratorPass", sgName)
48 kwargs.setdefault("decoratorIsEM", sgName + "IsEMValue")
49 kwargs.setdefault("decoratorResult", sgName + "Result" if storeTResult else "")
50 kwargs.setdefault("decoratorMultipleOutputs", sgMultipleNames if storeMultipleOutputs else [])
51 acc.setPrivateTools(CompFactory.DerivationFramework.EGElectronLikelihoodToolWrapper(name, **kwargs))
52 return acc
53
54
55# Photon cleaning tool wrapper
56def EGPhotonCleaningWrapperCfg(flags, name, **kwargs):
57 """Configure the photon cleaning tool wrapper"""
58 acc = ComponentAccumulator()
59 sgName = kwargs.pop("StoreGateEntryName", "DFCommonPhotonsCleaning")
60 # Write decoration handle keys
61 kwargs.setdefault("decoratorPass", sgName)
62 kwargs.setdefault("decoratorPassDelayed", sgName + "NoTime")
63 acc.setPrivateTools(CompFactory.DerivationFramework.EGPhotonCleaningWrapper(name, **kwargs))
64 return acc
65
66
67# Electron ambiguity tool
68def EGElectronAmbiguityToolCfg(flags, name, **kwargs):
69 """Configure the electron ambiguity tool"""
70 acc = ComponentAccumulator()
71 EGElectronAmbiguityTool = CompFactory.DerivationFramework.EGElectronAmbiguityTool
72 acc.setPrivateTools(EGElectronAmbiguityTool(name, **kwargs))
73 return acc
74
75
76# Background electron classification tool
77def BkgElectronClassificationCfg(flags, name, **kwargs):
78 """Configure the background electron classification tool"""
79 acc = ComponentAccumulator()
80 from MCTruthClassifier.MCTruthClassifierConfig import DFCommonMCTruthClassifierCfg
81 kwargs.setdefault("MCTruthClassifierTool", acc.popToolsAndMerge(
82 DFCommonMCTruthClassifierCfg(flags)))
83 acc.setPrivateTools(CompFactory.DerivationFramework.BkgElectronClassification(name, **kwargs))
84 return acc
85
86
87# Standard + LRT electron collection merger
88def ElectronMergerCfg(flags, name, **kwargs): # TODO Remove as, no clients??
89 """Configure the track particle merger tool"""
90 acc = ComponentAccumulator()
91 ElectronMerger = CompFactory.DerivationFramework.ElectronMergerTool
92 acc.setPrivateTools(ElectronMerger(name, **kwargs))
93 return acc
94
95
96def PhotonVertexSelectionWrapperCfg(
97 flags, name="PhotonVertexSelectionWrapper", **kwargs):
98 acc = ComponentAccumulator()
99 prefix = kwargs.pop("DecorationPrefix", "")
100 if prefix: prefix += "_"
101 kwargs.setdefault("pt", prefix + "pt")
102 kwargs.setdefault("eta", prefix + "eta")
103 kwargs.setdefault("phi", prefix + "phi")
104 kwargs.setdefault("sumPt", prefix + "sumPt")
105 kwargs.setdefault("sumPt2", prefix + "sumPt2")
106
107 if "PhotonPointingTool" not in kwargs:
108 from PhotonVertexSelection.PhotonVertexSelectionConfig import (
109 PhotonPointingToolCfg)
110 kwargs.setdefault("PhotonPointingTool", acc.popToolsAndMerge(
111 PhotonPointingToolCfg(flags)))
112
113 acc.setPrivateTools(
114 CompFactory.DerivationFramework.PhotonVertexSelectionWrapper(
115 name, **kwargs))
116 return acc
117
118
119def PhotonVertexSelectionWrapperKernelCfg(
120 flags, name="PhotonVertexSelectionWrapperKernel", **kwargs):
121 acc = ComponentAccumulator()
122
123 augmentationTools = [
124 acc.addPublicTool(acc.popToolsAndMerge(PhotonVertexSelectionWrapperCfg(flags)))
125 ]
126 kwargs.setdefault("AugmentationTools", augmentationTools)
127
128 acc.addEventAlgo(
129 CompFactory.DerivationFramework.DerivationKernel(name, **kwargs))
130 return acc
131
132
133def EGammaCookieCutClusterToolCfg(flags, name = 'EGCookieCutTool', **kwargs):
134 acc = ComponentAccumulator()
135 # needed for reading cells, do not rely on other config to do that
136 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
137 acc.merge(LArGMCfg(flags))
138 from TileGeoModel.TileGMConfig import TileGMCfg
139 acc.merge(TileGMCfg(flags))
140
141 clusterKey = kwargs.setdefault("ClusterContainerName", "ForwardElectronCookieCutClusters")
142 kwargs.setdefault("ClusterContainerLinksName", clusterKey + "_links")
143 #These two properties need to be in sync
144 if kwargs["ClusterContainerLinksName"] != (clusterKey + "_links"):
145 raise AttributeError("ClusterContainerLinksName ({}) is not syncrhonised with ClusterContainerName ({})".format(kwargs["ClusterContainerLinksName"], clusterKey))
146 kwargs.setdefault('StoreCookedMoments', False)
147 kwargs.setdefault('StoreInputMoments', False)
148 kwargs.setdefault("SGKey_electrons", flags.Egamma.Keys.Output.ForwardElectrons)
149 momentNames = [
150 "CENTER_X", "CENTER_Y", "CENTER_Z",
151 "SECOND_LAMBDA", "LATERAL", "LONGITUDINAL", "ENG_FRAC_MAX",
152 "SECOND_R", "CENTER_LAMBDA", "SECOND_ENG_DENS", "SIGNIFICANCE" ]
153 import ROOT
154 moments = [
155 ROOT.xAOD.CaloCluster.CENTER_X, ROOT.xAOD.CaloCluster.CENTER_Y, ROOT.xAOD.CaloCluster.CENTER_Z,
156 ROOT.xAOD.CaloCluster.SECOND_LAMBDA, ROOT.xAOD.CaloCluster.LATERAL, ROOT.xAOD.CaloCluster.LONGITUDINAL, ROOT.xAOD.CaloCluster.ENG_FRAC_MAX,
157 ROOT.xAOD.CaloCluster.SECOND_R, ROOT.xAOD.CaloCluster.CENTER_LAMBDA, ROOT.xAOD.CaloCluster.SECOND_ENG_DENS, ROOT.xAOD.CaloCluster.SIGNIFICANCE ]
158 kwargs.setdefault("MomentNames", momentNames)
159 kwargs.setdefault("Moments", moments)
160 cookedMoments = [ "cookiecut" + moment for moment in momentNames] if kwargs['StoreCookedMoments'] else []
161 originalMoments = [ "original" + moment for moment in momentNames] if kwargs['StoreInputMoments'] else []
162 electronDecorations = [i for sublist in zip(cookedMoments, originalMoments) for i in sublist]
163 electronDecorations += ["cookiecutClusterLink"]
164 kwargs.setdefault("SGKey_electrons_decorations", electronDecorations)
165
166 from CaloTools.CaloNoiseCondAlgConfig import CaloNoiseCondAlgCfg
167 acc.merge(CaloNoiseCondAlgCfg(flags,"totalNoise"))
168 from CaloRec.CaloTopoClusterConfig import getTopoMoments
169 momentsMaker = acc.popToolsAndMerge(getTopoMoments(flags))
170 kwargs.setdefault("ClusterMomentMaker",[momentsMaker])
171
172 acc.setPrivateTools(
173 CompFactory.DerivationFramework.EGammaCookieCutClusterTool(
174 name, **kwargs))
175 return acc
EGSelectionToolWrapperCfg(flags, name, **kwargs)
PhotonsDirectionToolCfg(flags, name, **kwargs)