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