ATLAS Offline Software
Loading...
Searching...
No Matches
METAssocCfg.py
Go to the documentation of this file.
1# Copyright (C) 2002-2023 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
9from GaudiKernel.Constants import INFO
10
11
13
14
15defaultInputKey = {
16 'Ele' :'Electrons',
17 'LRTEle' :'LRTElectrons',
18 'Gamma' :'Photons',
19 'Tau' :'TauJets',
20 'LCJet' :'AntiKt4LCTopoJets',
21 'EMJet' :'AntiKt4EMTopoJets',
22 'PFlowJet' :'AntiKt4EMPFlowJets',
23 'HadronicRecoil':'',
24 'Muon' :'Muons',
25 'MuonLRT' :'MuonsLRT',
26 'Soft' :'',
27 'Clusters' :'CaloCalTopoClusters',
28 'Tracks' :'InDetTrackParticles',
29 'PFlowObj' :'CHSGParticleFlowObjects',
30 'PFlowObjHR' :'CHSGParticleFlowObjects',
31 'PrimVxColl' :'PrimaryVertices',
32 'Truth' :'TruthEvents',
33 }
34
35prefix = 'METAssocConfig: '
36
37
39
41 def __init__(self,objType='',inputKey=''):
42 self.objType = objType
43 self.inputKey = inputKey
44
45def getAssociator(configFlags, config,suffix,doPFlow=False,doRecoil=False,
46 trkseltool=None,
47 trkisotool=None,caloisotool=None,
48 useFELinks=False,
49 modConstKey="",
50 modClusColls={}):
51 tool = None
52 doModClus = (modConstKey!="" and not doPFlow)
53 if doModClus:
54 modLCClus = modClusColls['LC{0}Clusters'.format(modConstKey)]
55 modEMClus = modClusColls['EM{0}Clusters'.format(modConstKey)]
56
57 # Construct tool and set defaults for case-specific configuration
58 if config.objType == 'Ele':
59 tool = CompFactory.getComp("met::METElectronAssociator")('MET_ElectronAssociator_'+suffix,TCMatchMethod=1)
60 if config.objType == 'LRTEle':
61 tool = CompFactory.getComp("met::METElectronAssociator")('MET_LRTElectronAssociator_'+suffix,TCMatchMethod=1)
62 if config.objType == 'Gamma':
63 tool = CompFactory.getComp("met::METPhotonAssociator")('MET_PhotonAssociator_'+suffix,TCMatchMethod=1)
64 if config.objType == 'Tau':
65 tool = CompFactory.getComp("met::METTauAssociator")('MET_TauAssociator_'+suffix)
66 if config.objType == 'LCJet':
67 tool = CompFactory.getComp("met::METJetAssocTool")('MET_LCJetAssocTool_'+suffix)
68 if config.objType == 'EMJet':
69 tool = CompFactory.getComp("met::METJetAssocTool")('MET_EMJetAssocTool_'+suffix)
70 if config.objType == 'PFlowJet':
71 tool = CompFactory.getComp("met::METJetAssocTool")('MET_PFlowJetAssocTool_'+suffix)
72 if config.objType == 'HadronicRecoil':
73 tool = CompFactory.getComp("met::METJetAssocTool")('MET_PFlowJetAssocTool_HR_'+suffix)
74 if config.objType == 'CustomJet':
75 tool = CompFactory.getComp("met::METJetAssocTool")('MET_CustomJetAssocTool_'+suffix)
76 if config.objType == 'Muon':
77 tool = CompFactory.getComp("met::METMuonAssociator")('MET_MuonAssociator_'+suffix)
78 if config.objType == 'MuonLRT':
79 tool = CompFactory.getComp("met::METMuonAssociator")('MET_MuonLRTAssociator_'+suffix)
80 if config.objType == 'Soft':
81 tool = CompFactory.getComp("met::METSoftAssociator")('MET_SoftAssociator_'+suffix)
82 tool.DecorateSoftConst = True
83 if doModClus:
84 tool.LCModClusterKey = modLCClus
85 tool.EMModClusterKey = modEMClus
86 if config.objType == 'Truth':
87 tool = CompFactory.getComp("met::METTruthAssociator")('MET_TruthAssociator_'+suffix)
88 tool.RecoJetKey = config.inputKey
89 if doPFlow:
90 tool.PFlow = True
91 if doRecoil:
92 tool.FlowElementCollection = modConstKey if modConstKey!="" else defaultInputKey["PFlowObjHR"]
93 else:
94 tool.FlowElementCollection = modConstKey if modConstKey!="" else defaultInputKey["PFlowObj"]
95 else:
96 tool.UseModifiedClus = doModClus
97 if doRecoil and (config.objType == 'Muon' or config.objType == 'Ele'): #we only need the recoil implementation for e and mu
98 tool.HRecoil = True
99 tool.UseFELinks = False if config.objType == 'MuonLRT' or config.objType == 'LRTEle' else useFELinks
100 # set input/output key names
101 if config.inputKey == '' and defaultInputKey[config.objType] != '':
102 tool.InputCollection = defaultInputKey[config.objType]
103 config.inputKey = tool.InputCollection
104 elif hasattr(tool, 'InputCollection'):
105 tool.InputCollection = config.inputKey
106 if doModClus:
107 tool.ClusColl = modLCClus
108 if 'EMTopo' in suffix: tool.ClusColl = modEMClus
109 tool.TrkColl = defaultInputKey['Tracks']
110 tool.UseTracks = configFlags.MET.UseTracks
111 tool.TrackSelectorTool = trkseltool
112 tool.TrackIsolationTool = trkisotool
113 tool.CaloIsolationTool = caloisotool
114
115 return tool
116
117
119
122 if self.doTruth: return 'MET_Core_'+self.suffix
123 else: return 'MET_Core_'+self.suffix,'MET_Reference_'+self.suffix
124 #
125 def outputMap(self):
126 return 'METAssoc_'+self.suffix
127 #
128 def setupAssociators(self, configFlags, buildconfigs):
129 metlog.info("{} Setting up associators for MET config {}".format(prefix,self.suffix))
130 for config in buildconfigs:
131 if config.objType in self.associators:
132 metlog.error("{} Config {} already contains a associator of type {}".format(prefix,self.suffix,config.objType))
133 raise LookupError
134 else:
135 associator = getAssociator(configFlags, config=config,suffix=self.suffix,
136 doPFlow=self.doPFlow,
137 doRecoil=self.doRecoil,
138 useFELinks=self.useFELinks,
139 trkseltool=self.trkseltool,
140 trkisotool=self.trkisotool,
141 caloisotool=self.caloisotool,
142 modConstKey=self.modConstKey,
143 modClusColls=self.modClusColls)
144 self.associators[config.objType] = associator
145 self.assoclist.append(associator)
146 metlog.info("{} Added {} tool named {}".format(prefix,config.objType,associator.name))
147 #
148 def __init__(self,suffix,inputFlags,buildconfigs=[],
149 doPFlow=False, doRecoil=False, doTruth=False,
150 usePFOLinks=False,
151 trksel=None,
152 modConstKey="",
153 modClusColls={}
154 ):
155 self.accumulator = ComponentAccumulator()
156 # Set some sensible defaults
157 modConstKey_tmp = modConstKey
158 modClusColls_tmp = modClusColls
159 if doPFlow:
160 # Ideally this should not be hardcoded but linked to the JetDefinition with which this MET is built
161 # TODO : in new config, if possible use something like: jetdef.inputdef.containername
162 if modConstKey_tmp == "": modConstKey_tmp = "CHSGParticleFlowObjects"
163 else:
164 if modConstKey_tmp == "": modConstKey_tmp = "OriginCorr"
165 if modClusColls_tmp == {}: modClusColls_tmp = {'LCOriginCorrClusters':'LCOriginTopoClusters',
166 'EMOriginCorrClusters':'EMOriginTopoClusters'}
167 if doTruth:
168 metlog.info("{} Creating MET TruthAssoc config {}".format(prefix,suffix))
169 else:
170 metlog.info("{} Creating MET Assoc config {}".format(prefix,suffix))
171 self.suffix = suffix
172 self.doPFlow = doPFlow
173 self.doRecoil = doRecoil
174 self.useFELinks = usePFOLinks
175 self.modConstKey=modConstKey_tmp
176 self.modClusColls=modClusColls_tmp
177 self.doTruth = doTruth
178 if trksel:
179 self.trkseltool = trksel
180 else:
181 # TODO: These Z0 and D0 cuts are left over from R21. The track vertex association can now use looser ones.
182 # To be investigated and possibly updated by the MET group.
183 self.trkseltool=CompFactory.getComp("InDet::InDetTrackSelectionTool")("IDTrkSel_METAssoc",
184 CutLevel="TightPrimary",
185 maxZ0SinTheta=3,
186 maxD0=2,
187 minPt=500)
188
189 self.trkisotool = CompFactory.getComp("xAOD::TrackIsolationTool")("TrackIsolationTool_MET")
190 self.trkisotool.TrackSelectionTool = self.trkseltool # As configured above
191 from TrkConfig.AtlasExtrapolatorConfig import AtlasExtrapolatorCfg
192 extrapCfg = AtlasExtrapolatorCfg(inputFlags)
193 CaloExtensionTool= CompFactory.getComp("Trk::ParticleCaloExtensionTool")(Extrapolator = self.accumulator.popToolsAndMerge(extrapCfg))
194 CaloCellAssocTool = CompFactory.getComp("Rec::ParticleCaloCellAssociationTool")(ParticleCaloExtensionTool = CaloExtensionTool)
195 self.caloisotool = CompFactory.getComp("xAOD::CaloIsolationTool")("CaloIsolationTool_MET",
196 saveOnlyRequestedCorrections=True,
197 ParticleCaloExtensionTool = CaloExtensionTool,
198 ParticleCaloCellAssociationTool = CaloCellAssocTool)
199 self.associators = {}
200 self.assoclist = [] # need an ordered list
201 #
202 self.setupAssociators(inputFlags, buildconfigs)
203
204# Set up a top-level tool with mostly defaults
205def getMETAssocTool(topconfig,msglvl=INFO):
206 assocTool = None
207 if topconfig.doTruth:
208 assocTool = CompFactory.getComp("met::METAssociationTool")('MET_TruthAssociationTool_'+topconfig.suffix,
209 METAssociators = topconfig.assoclist,
210 METSuffix = topconfig.suffix)
211 else:
212 assocTool = CompFactory.getComp("met::METAssociationTool")('MET_AssociationTool_'+topconfig.suffix,
213 METAssociators = topconfig.assoclist,
214 METSuffix = topconfig.suffix,
215 OutputLevel=msglvl)
216 return assocTool
217
218# Convert the provided METAssocConfigs into a concrete algorithm
219def getMETAssocAlg(algName='METAssociation',configs={},tools=[],msglvl=INFO):
220
221 assocTools = []
222 assocTools += tools
223
224 if configs=={} and tools==[]:
225 metlog.info("{} Empty list of MET association configs provided. None will be reconstructed.".format(prefix))
226 for key,conf in configs.items():
227 metlog.info("{} Generate METAssocTool for MET_{}".format(prefix,key))
228 assoctool = getMETAssocTool(conf,msglvl)
229 assocTools.append(assoctool)
230
231 for tool in assocTools:
232 metlog.info("{} Added METAssocTool {} to alg {}".format(prefix,tool.name,algName))
233 assocAlg = CompFactory.getComp("met::METRecoAlg")(name=algName,
234 RecoTools=assocTools)
235 return assocAlg
Configuration of builders.
__init__(self, objType='', inputKey='')
Top level MET configuration.
setupAssociators(self, configFlags, buildconfigs)
__init__(self, suffix, inputFlags, buildconfigs=[], doPFlow=False, doRecoil=False, doTruth=False, usePFOLinks=False, trksel=None, modConstKey="", modClusColls={})
return+self.suffix doTruth
getAssociator(configFlags, config, suffix, doPFlow=False, doRecoil=False, trkseltool=None, trkisotool=None, caloisotool=None, useFELinks=False, modConstKey="", modClusColls={})
getMETAssocTool(topconfig, msglvl=INFO)
getMETAssocAlg(algName='METAssociation', configs={}, tools=[], msglvl=INFO)