ATLAS Offline Software
Loading...
Searching...
No Matches
METRecoCfg.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4from AthenaConfiguration.ComponentFactory import CompFactory
5
6from AthenaCommon import Logging
7metlog = Logging.logging.getLogger('METConfig')
8
9
11
12defaultInputKey = {
13 'Ele' :'Electrons',
14 'Gamma' :'Photons',
15 'Tau' :'TauJets',
16 'Jet' :'AntiKt4EMTopoJets',
17 'Muon' :'Muons',
18 'SoftTrk' :'InDetTrackParticles',
19 'SoftClus' :'CaloCalTopoClusters',
20 'SoftPFlow':'JetETMissNeutralParticleFlowObjects',
21 'PrimaryVx':'PrimaryVertices',
22 'Truth' :'TruthEvents',
23 'Calo' :'AllCalo',
24 'LCOCSoftClus':'LCOriginTopoClusters',
25 'EMOCSoftClus':'EMOriginTopoClusters',
26 }
27
28defaultOutputKey = {
29 'Ele' :'RefEle',
30 'Gamma' :'RefGamma',
31 'Tau' :'RefTau',
32 'Jet' :'RefJet',
33 'Muon' :'Muons',
34 'SoftTrk' :'SoftTrk',
35 'SoftClus' :'SoftClus',
36 'SoftPFlow':'SoftPFlow',
37 'Total' :'Final',
38 'Truth' :'Truth',
39 'Calo' :'Calo'
40 }
41
42prefix = 'METRecoConfig: '
43
44
46
48 def __init__(self,objType='',outputKey='',inputKey=''):
49 self.objType = objType
50 self.outputKey = outputKey
51 self.inputKey = inputKey
52
53def getBuilder(config,suffix,doTracks,doCells,doTriggerMET,doOriginCorrClus):
54 tool = None
55 # Construct tool and set defaults for case-specific configuration
56 if config.objType == 'SoftTrk':
57 tool = CompFactory.getComp("met::METSoftTermsTool")('MET_SoftTrkTool_'+suffix)
58 tool.InputComposition = 'Tracks'
59 tool.TrackKey = defaultInputKey[config.objType]
60 config.inputKey = defaultInputKey[config.objType]
61 if config.objType.endswith('SoftClus'):
62 tool = CompFactory.getComp("met::METSoftTermsTool")('MET_SoftClusTool_'+suffix)
63 tool.InputComposition = 'Clusters'
64 tool.CaloClusterKey = defaultInputKey[config.objType]
65 config.inputKey = defaultInputKey[config.objType]
66 if config.objType == 'SoftPFlow':
67 tool = CompFactory.getComp("met::METSoftTermsTool")('MET_SoftPFlowTool_'+suffix)
68 tool.InputComposition = 'PFlow'
69 pfotool = CompFactory.RetrievePFOTool('MET_PFOTool_'+suffix)
70 tool.PFOTool = pfotool
71 if suffix == 'Truth':
72 tool = CompFactory.getComp("met::METTruthTool")('MET_TruthTool_'+config.objType)
73 tool.InputComposition = config.objType
74 tool.InputCollection = defaultInputKey['Truth']
75 config.inputKey = defaultInputKey['Truth']
76 config.outputKey = config.objType
77 if suffix == 'Calo':
78 tool = CompFactory.getComp("met::METCaloRegionsTool")('MET_CaloRegionsTool')
79 if doCells:
80 tool.UseCells = True
81 tool.DoTriggerMET = doTriggerMET
82 tool.CaloCellKey = defaultInputKey['Calo']
83 config.inputKey = defaultInputKey['Calo']
84 else:
85 tool.UseCells = False
86 tool.DoTriggerMET = False
87 tool.CaloClusterKey = defaultInputKey['SoftClus']
88 config.inputKey = defaultInputKey['SoftClus']
89 config.outputKey = config.objType
90
91 # set input/output key names
92 if config.inputKey == '':
93 tool.InputCollection = defaultInputKey[config.objType]
94 config.inputKey = tool.InputCollection
95 elif hasattr(tool, 'InputCollection'):
96 tool.InputCollection = config.inputKey
97 if not suffix=='Calo':
98 if config.outputKey == '':
99 tool.MissingETKey = defaultOutputKey[config.objType]
100 config.outputKey = tool.MissingETKey
101 else:
102 tool.MissingETKey = config.outputKey
103 return tool
104
105
107
109 def __init__(self,myType='',outputKey=''):
110 self.type = myType
111 self.outputKey = outputKey
112
113def getRefiner(flags,config,suffix,trkseltool=None,trkvxtool=None,trkisotool=None,caloisotool=None):
114 tool = None
115
116 if config.type == 'TrackFilter':
117 tool = CompFactory.getComp("met::METTrackFilterTool")('MET_TrackFilterTool_'+suffix)
118 tool.InputPVKey = defaultInputKey['PrimaryVx']
119 tool.TrackSelectorTool=trkseltool
120 tool.TrackVxAssocTool=trkvxtool
121 #
122 tool.UseIsolationTools = False #True
123 tool.TrackIsolationTool = trkisotool
124 tool.CaloIsolationTool = caloisotool
125 #
126 tool.DoPVSel = flags.MET.UseTracks
127 tool.DoVxSep = flags.MET.UseTracks
128 tool.MissingETKey = config.outputKey
129 return tool
130
131
133
134def getRegions(config,suffix):
135 if suffix == 'Truth':
136 config.outputKey = config.objType
137 tool = CompFactory.getComp("met::METRegionsTool")('MET_'+config.outputKey+'Regions_'+suffix)
138 tool.InputMETContainer = 'MET_'+suffix
139 tool.InputMETMap = 'METMap_'+suffix
140 tool.InputMETKey = config.outputKey
141 tool.RegionValues = [ 1.5, 3.2, 10 ]
142 return tool
143
144
146
149 return 'MET_'+self.suffix
150 #
151 def outputMap(self):
152 return 'METMap_'+self.suffix
153 #
154 def setupBuilders(self,buildconfigs):
155 metlog.info("{} Setting up builders for MET config {}".format(prefix,self.suffix))
156 for config in buildconfigs:
157 if config.objType in self.builders:
158 metlog.error("{} Config {} already contains a builder of type {}".format(prefix,self.suffix,config.objType))
159 raise LookupError
160 else:
161 builder = getBuilder(config,self.suffix,self.doTracks,self.doCells,
163 self.builders[config.objType] = builder
164 self.buildlist.append(builder)
165 metlog.info("{} Added {} tool named {}".format(prefix,config.objType,builder.name))
166 #
167 def setupRefiners(self,flags,refconfigs):
168 metlog.info("{} Setting up refiners for MET config {}".format(prefix,self.suffix))
169 for config in refconfigs:
170 # need to enforce this?
171 if config.type in self.refiners:
172 metlog.error("Config {} already contains a refiner of type {}".format(self.suffix,config.type))
173 raise LookupError
174 else:
175 refiner = getRefiner(flags, config=config,suffix=self.suffix,
176 trkseltool=self.trkseltool,trkvxtool=self.trkvxtool,
177 trkisotool=self.trkisotool,caloisotool=self.caloisotool)
178 self.refiners[config.type] = refiner
179 self.reflist.append(refiner)
180 metlog.info("{} Added {} tool named {}".format(prefix,config.type,refiner.name))
181 #
182 def setupRegions(self,buildconfigs):
183 metlog.info("{} Setting up regions for MET config {}".format(prefix,self.suffix))
184 for config in buildconfigs:
185 if config.objType in self.regions:
186 metlog.error("{} Config {} already contains a region tool of type {}".format(prefix,self.suffix,config.objType))
187 raise LookupError
188 else:
189 regions = getRegions(config,self.suffix)
190 self.regions[config.objType] = regions
191 self.reglist.append(regions)
192 metlog.info("{} Added {} region tool named {}".format(prefix,config.objType,regions.name))
193 #
194 def __init__(self,suffix,inputFlags,buildconfigs=[],refconfigs=[],
195 doTracks=False,doSum=False,doRegions=False,
196 doCells=False,doTriggerMET=True,duplicateWarning=True,
197 doOriginCorrClus=False):
198 metlog.info("{} Creating MET config {}".format(prefix,suffix))
199 self.accumulator = ComponentAccumulator()
200 self.suffix = suffix
201 self.doSum = doSum
202 self.doTracks = doTracks
203 self.doRegions = doRegions
204 self.doCells = doCells,
205 self.doOriginCorrClus = doOriginCorrClus
206 self.doTriggerMET = doTriggerMET
207 self.duplicateWarning = duplicateWarning
208 #
209 self.builders = {}
210 self.buildlist = [] # need an ordered list
211 #
212 self.refiners = {}
213 self.reflist = [] # need an ordered list
214 #
215 self.regions = {}
216 self.reglist = [] # need an ordered list
217 if doRegions:
218 self.setupRegions(buildconfigs)
219 #
220 if self.suffix != 'Truth':
221 # TODO: These Z0 and D0 cuts are left over from R21. The track vertex association can now use looser ones.
222 # To be investigated and possibly updated by the MET group.
223 self.trkseltool=CompFactory.getComp("InDet::InDetTrackSelectionTool")("IDTrkSel_MET",
224 CutLevel="TightPrimary",
225 maxZ0SinTheta=3,
226 maxD0=2,
227 minPt=500)
228 #
229 from TrackVertexAssociationTool.TrackVertexAssociationToolConfig import TTVAToolCfg
230 self.trkvxtool = self.accumulator.popToolsAndMerge(
231 TTVAToolCfg(inputFlags, "TrackVertexAssociationTool_MET", addDecoAlg=True,
232 WorkingPoint="Nonprompt_All_MaxWeight", HardScatterLinkDeco=""))
233 #
234 self.trkisotool = CompFactory.getComp("xAOD::TrackIsolationTool")("TrackIsolationTool_MET")
235 self.trkisotool.TrackSelectionTool = self.trkseltool # As configured above
236
237 from TrkConfig.AtlasExtrapolatorConfig import AtlasExtrapolatorCfg
238 extrapCfg = AtlasExtrapolatorCfg(inputFlags)
239 CaloExtensionTool= CompFactory.getComp("Trk::ParticleCaloExtensionTool")(Extrapolator = self.accumulator.popToolsAndMerge(extrapCfg))
240 CaloCellAssocTool = CompFactory.getComp("Rec::ParticleCaloCellAssociationTool")(ParticleCaloExtensionTool = CaloExtensionTool)
241 self.caloisotool = CompFactory.getComp("xAOD::CaloIsolationTool")("CaloIsolationTool_MET",
242 saveOnlyRequestedCorrections=True,
243 ParticleCaloExtensionTool = CaloExtensionTool,
244 ParticleCaloCellAssociationTool = CaloCellAssocTool)
245
246 self.setupBuilders(buildconfigs)
247 self.setupRefiners(inputFlags,refconfigs)
248
249# Set up a top-level tool with mostly defaults
250def getMETRecoTool(topconfig):
251 recoTool = CompFactory.getComp("met::METRecoTool")('MET_RecoTool_'+topconfig.suffix,
252 METBuilders = topconfig.buildlist,
253 METRefiners = topconfig.reflist,
254 METContainer = topconfig.outputCollection(),
255 METComponentMap = topconfig.outputMap(),
256 WarnIfDuplicate = topconfig.duplicateWarning)
257 if topconfig.doSum:
258 recoTool.METFinalName = defaultOutputKey['Total']
259
260 return recoTool
261
262# Set up a METRecoTool that builds MET regions
263def getRegionRecoTool(topconfig):
264 regTool = CompFactory.getComp("met::METRecoTool")('MET_RegionTool_'+topconfig.suffix,
265 METBuilders = [],
266 METRefiners = topconfig.reglist,
267 METContainer = topconfig.outputCollection()+'Regions',
268 METComponentMap = topconfig.outputMap()+'Regions',
269 WarnIfDuplicate = topconfig.duplicateWarning)
270 return regTool
271
272# Allow user to configure reco tools directly or get more default configurations
273def getMETRecoAlg(algName='METReconstruction',configs={}):
274 recoTools = []
275 for key,conf in configs.items():
276 metlog.info("{} Generate METRecoTool for MET_{}".format(prefix,key))
277 recotool = getMETRecoTool(conf)
278 recoTools.append(recotool)
279 if conf.doRegions:
280 regiontool = getRegionRecoTool(conf)
281 recoTools.append(regiontool)
282 for tool in recoTools:
283 metlog.info("{} Added METRecoTool {} to alg {}".format(prefix,tool.name,algName))
284 recoAlg = CompFactory.getComp("met::METRecoAlg")(name=algName,RecoTools=recoTools)
285 return recoAlg
Configuration of builders.
Definition METRecoCfg.py:47
__init__(self, objType='', outputKey='', inputKey='')
Definition METRecoCfg.py:48
Top level MET configuration.
setupRegions(self, buildconfigs)
setupBuilders(self, buildconfigs)
setupRefiners(self, flags, refconfigs)
__init__(self, suffix, inputFlags, buildconfigs=[], refconfigs=[], doTracks=False, doSum=False, doRegions=False, doCells=False, doTriggerMET=True, duplicateWarning=True, doOriginCorrClus=False)
Configuration of refiners.
__init__(self, myType='', outputKey='')
getMETRecoAlg(algName='METReconstruction', configs={})
getRefiner(flags, config, suffix, trkseltool=None, trkvxtool=None, trkisotool=None, caloisotool=None)
getMETRecoTool(topconfig)
getRegionRecoTool(topconfig)
getRegions(config, suffix)
Region tools are a special case of refiners.
getBuilder(config, suffix, doTracks, doCells, doTriggerMET, doOriginCorrClus)
Definition METRecoCfg.py:53