ATLAS Offline Software
METAssocCfg.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 
6 from AthenaCommon import Logging
7 metlog = Logging.logging.getLogger('METConfig')
8 
9 from GaudiKernel.Constants import INFO
10 
11 
13 
14 
15 defaultInputKey = {
16  'Ele' :'Electrons',
17  'LRTEle' :'LRTElectrons',
18  'Gamma' :'Photons',
19  'Tau' :'TauJets',
20  'LCJet' :'AntiKt4LCTopoJets',
21  'EMJet' :'AntiKt4EMTopoJets',
22  'PFlowJet' :'AntiKt4EMPFlowJets',
23  'PFlowJetHR':'AntiKt4EMPFlowJets',
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 
35 prefix = 'METAssocConfig: '
36 
37 
39 
41  def __init__(self,objType='',inputKey=''):
42  self.objType = objType
43  self.inputKey = inputKey
44 
45 def 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 == 'PFlowJetHR':
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 
121  def outputCollections(self):
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  ):
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
205 def 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
219 def 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
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
METAssocCfg.METAssocConfig.doRecoil
doRecoil
Definition: METAssocCfg.py:167
vtune_athena.format
format
Definition: vtune_athena.py:14
METAssocCfg.METAssocConfig.modClusColls
modClusColls
Definition: METAssocCfg.py:170
METAssocCfg.METAssocConfig.setupAssociators
def setupAssociators(self, configFlags, buildconfigs)
Definition: METAssocCfg.py:128
METAssocCfg.getMETAssocTool
def getMETAssocTool(topconfig, msglvl=INFO)
Definition: METAssocCfg.py:205
METAssocCfg.METAssocConfig.trkseltool
trkseltool
Definition: METAssocCfg.py:173
METAssocCfg.getAssociator
def getAssociator(configFlags, config, suffix, doPFlow=False, doRecoil=False, trkseltool=None, trkisotool=None, caloisotool=None, useFELinks=False, modConstKey="", modClusColls={})
Definition: METAssocCfg.py:45
METAssocCfg.METAssocConfig.caloisotool
caloisotool
Definition: METAssocCfg.py:189
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
METAssocCfg.METAssocConfig.accumulator
accumulator
Definition: METAssocCfg.py:149
python.AtlasExtrapolatorConfig.AtlasExtrapolatorCfg
def AtlasExtrapolatorCfg(flags, name='AtlasExtrapolator')
Definition: AtlasExtrapolatorConfig.py:63
METAssocCfg.METAssocConfig.associators
associators
Definition: METAssocCfg.py:193
METAssocCfg.AssocConfig
Configuration of builders.
Definition: METAssocCfg.py:40
METAssocCfg.AssocConfig.__init__
def __init__(self, objType='', inputKey='')
Definition: METAssocCfg.py:41
METAssocCfg.METAssocConfig.modConstKey
modConstKey
Definition: METAssocCfg.py:169
METAssocCfg.METAssocConfig.useFELinks
useFELinks
Definition: METAssocCfg.py:168
METAssocCfg.METAssocConfig.doPFlow
doPFlow
Definition: METAssocCfg.py:166
METAssocCfg.AssocConfig.objType
objType
Definition: METAssocCfg.py:42
METAssocCfg.AssocConfig.inputKey
inputKey
Definition: METAssocCfg.py:43
METAssocCfg.getMETAssocAlg
def getMETAssocAlg(algName='METAssociation', configs={}, tools=[], msglvl=INFO)
Definition: METAssocCfg.py:219
METAssocCfg.METAssocConfig.assoclist
assoclist
Definition: METAssocCfg.py:194
METAssocCfg.METAssocConfig.__init__
def __init__(self, suffix, inputFlags, buildconfigs=[], doPFlow=False, doRecoil=False, doTruth=False, usePFOLinks=False, trksel=None, modConstKey="", modClusColls={})
Definition: METAssocCfg.py:148
METAssocCfg.METAssocConfig.suffix
suffix
Definition: METAssocCfg.py:165
METAssocCfg.METAssocConfig
Top level MET configuration.
Definition: METAssocCfg.py:120
METAssocCfg.METAssocConfig.doTruth
doTruth
Definition: METAssocCfg.py:171
METAssocCfg.METAssocConfig.trkisotool
trkisotool
Definition: METAssocCfg.py:183
METAssocCfg.METAssocConfig.outputMap
def outputMap(self)
Definition: METAssocCfg.py:125
METAssocCfg.METAssocConfig.outputCollections
def outputCollections(self)
Definition: METAssocCfg.py:121