ATLAS Offline Software
FtagDerivationConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 
6 from BTagging.BTagConfig import BTagAlgsCfg, GetTaggerTrainingMap
7 from BTagging.BTagTrackAugmenterAlgConfig import BTagTrackAugmenterAlgCfg
8 
9 from JetTagCalibration.JetTagCalibConfig import JetTagCalibCfg
10 from FlavorTagDiscriminants.FoldDecoratorConfig import FoldDecoratorCfg
11 from ElectronPhotonSelectorTools.AsgElectronLikelihoodToolsConfig import AsgElectronLikelihoodToolCfg
12 from ElectronPhotonSelectorTools.LikelihoodEnums import LikeEnum
13 from MuonSelectorTools.MuonSelectorToolsConfig import MuonSelectionToolCfg
14 
15 PFLOW_JETS = 'AntiKt4EMPFlowJets'
16 
17 def FtagJetCollectionsCfg(cfgFlags, jet_cols, pv_cols=None,
18  trackAugmenterPrefix=None):
19  """
20  Run flavour tagging in derivations.
21  Configures several jet collections at once.
22  """
23 
24  if pv_cols is None:
25  pv_cols = ['PrimaryVertices'] * len(jet_cols)
26  if len(pv_cols) != len(jet_cols):
27  raise ValueError('PV collection length is not the same as Jets')
28 
29  acc = ComponentAccumulator()
30 
31  acc.merge(JetTagCalibCfg(cfgFlags))
32 
33  if 'AntiKt4EMTopoJets' in jet_cols:
34  acc.merge(
35  RenameInputContainerEmTopoHacksCfg('oldAODVersion')
36  )
37 
38  if PFLOW_JETS in jet_cols and cfgFlags.BTagging.Trackless:
39  acc.merge(
40  RenameInputContainerEmPflowHacksCfg('tracklessAODVersion')
41  )
42 
43  # decorate tracks with detailed truth info and reco lepton info
44  acc.merge(trackTruthDecorator(cfgFlags))
45  acc.merge(trackLeptonDecorator(cfgFlags))
46 
47  # Treat large-R jets as a special case
48  largeRJetCollection = 'AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets'
49  if largeRJetCollection in jet_cols:
50  acc.merge(BTagLargeRDecoration(cfgFlags, largeRJetCollection))
51  jet_cols.remove(largeRJetCollection)
52 
53  # Run flavour tagging on each jet collection
54  for jet_col, pv_col in zip(jet_cols, pv_cols):
55 
56  # pflow jets need the jet fold hash to run GN2v01
57  if jet_col == PFLOW_JETS:
58  acc.merge(FoldDecoratorCfg(cfgFlags, jetCollection=jet_col))
59 
60  # Run flavour tagging on this jet collection
61  acc.merge(
63  cfgFlags, jet_col, pv_col,
64  trackAugmenterPrefix=trackAugmenterPrefix
65  )
66  )
67 
68  if cfgFlags.BTagging.GNNVertexFitter:
69  from GNNVertexFitter.GNNVertexFitterConfig import GNNVertexFitterAlgCfg
70  acc.merge(GNNVertexFitterAlgCfg(cfgFlags))
71  acc.merge(GNNVertexFitterAlgCfg(cfgFlags, inclusive=True))
72 
73  return acc
74 
76  from ParticleJetTools.ParticleJetToolsConfig import getJetDeltaRFlavorLabelTool
77 
78  acc = ComponentAccumulator()
79 
80  jetDec = CompFactory.JetDecorationAlg(
81  name='hltJetLabelingAlg',
82  JetContainer='HLT_AntiKt4EMPFlowJets_subresjesgscIS_ftf',
83  Decorators=[getJetDeltaRFlavorLabelTool()])
84 
85  acc.addEventAlgo(jetDec)
86 
87  return acc
88 
89 def BTagLargeRDecoration(cfgFlags, jet_col):
90 
91  jet_col_name_without_Jets = jet_col.replace('Jets', '')
92  nnFiles = GetTaggerTrainingMap(cfgFlags, jet_col_name_without_Jets)
93 
94  # Doesn't need to be configurable at the moment
95  trackContainer = 'GhostTrack'
96  primaryVertexContainer = 'PrimaryVertices'
97  variableRemapping = {'BTagTrackToJetAssociator': trackContainer}
98 
99  acc = ComponentAccumulator()
100  acc.merge(BTagTrackAugmenterAlgCfg(
101  cfgFlags,
102  TrackCollection='InDetTrackParticles',
103  PrimaryVertexCollectionName=primaryVertexContainer,
104  ))
105 
106  for nnFile in nnFiles:
107  # ugly string parsing to get the tagger name
108  tagger_name = nnFile.split('/')[-3]
109 
110  acc.addEventAlgo(
111  CompFactory.FlavorTagDiscriminants.JetTagDecoratorAlg(
112  f'{jet_col}{tagger_name}JetTagAlg',
113  container=jet_col,
114  constituentContainer=trackContainer,
115  decorator=CompFactory.FlavorTagDiscriminants.GNNTool(
116  tagger_name,
117  nnFile=nnFile,
118  variableRemapping=variableRemapping,
119  trackLinkType='IPARTICLE'
120  ),
121  )
122  )
123 
124  return acc
125 
126 
127 def tagSingleJetCollection(cfgFlags, jet_col, pv_col,
128  trackAugmenterPrefix=None):
129  """
130  Return a component accumulator which runs tagging on a single jet collection.
131  """
132 
133  jet_col_name_without_Jets = jet_col.replace('Jets','')
134  track_collection = _getTrackCollection(cfgFlags)
135  input_muons = 'Muons'
136  if cfgFlags.BTagging.Pseudotrack:
137  input_muons = None
138 
139  acc = ComponentAccumulator()
140  acc.merge(BTagTrackAugmenterAlgCfg(
141  cfgFlags,
142  TrackCollection=track_collection,
143  PrimaryVertexCollectionName=pv_col,
144  prefix=trackAugmenterPrefix
145  ))
146 
147  # schedule tagging algorithms for this jet collection
148  acc.merge(BTagAlgsCfg(
149  inputFlags=cfgFlags,
150  JetCollection=jet_col_name_without_Jets,
151  nnList=GetTaggerTrainingMap(cfgFlags, jet_col_name_without_Jets),
152  trackCollection=track_collection,
153  primaryVertices=pv_col,
154  muons=input_muons,
155  renameTrackJets=True,
156  AddedJetSuffix='Jets',
157  ))
158 
159  return acc
160 
161 
162 def trackLeptonDecorator(cfgFlags) -> ComponentAccumulator:
163  """Decorate tracks with information about reconstructed leptons"""
164  acc = ComponentAccumulator()
165 
166  electronID_tool = acc.popToolsAndMerge(
167  AsgElectronLikelihoodToolCfg(cfgFlags, name="ftagElectronID", quality=LikeEnum.VeryLoose)
168  )
169  muonID_tool = acc.popToolsAndMerge( # loose quality selection
170  MuonSelectionToolCfg(cfgFlags, name="ftagMuonID", MuQuality=2, MaxEta=2.5)
171  )
172  acc.addEventAlgo(CompFactory.FlavorTagDiscriminants.TrackLeptonDecoratorAlg(
173  'TrackLeptonDecoratorAlg',
174  trackContainer=_getTrackCollection(cfgFlags),
175  electronSelectionTool=electronID_tool,
176  muonSelectionTool=muonID_tool,
177  ))
178 
179  return acc
180 
181 
182 def trackTruthDecorator(cfgFlags) -> ComponentAccumulator:
183  """Decorate tracks with detailed truth information."""
184  acc = ComponentAccumulator()
185  if not cfgFlags.Input.isMC:
186  return acc
187 
188  from InDetTrackSystematicsTools.InDetTrackSystematicsToolsConfig import (
189  InDetTrackTruthOriginToolCfg,
190  )
191  trackTruthOriginTool = acc.popToolsAndMerge(InDetTrackTruthOriginToolCfg(cfgFlags))
192  acc.addEventAlgo(CompFactory.FlavorTagDiscriminants.TruthParticleDecoratorAlg(
193  'TruthParticleDecoratorAlg',
194  trackTruthOriginTool=trackTruthOriginTool
195  ))
196  acc.addEventAlgo(CompFactory.FlavorTagDiscriminants.TrackTruthDecoratorAlg(
197  'TrackTruthDecoratorAlg',
198  trackContainer=_getTrackCollection(cfgFlags),
199  trackTruthOriginTool=trackTruthOriginTool,
200  truthLeptonTool=CompFactory.TruthClassificationTool("TruthClassificationTool")
201  ))
202 
203  return acc
204 
205 
206 def _getTrackCollection(cfgFlags):
207  if cfgFlags.BTagging.Pseudotrack:
208  return 'InDetPseudoTrackParticles'
209  return 'InDetTrackParticles'
210 
211 
212 # Valerio's magic hacks for emtopo
214  acc = ComponentAccumulator()
215 
216  #Delete BTagging container read from input ESD
217  AddressRemappingSvc, ProxyProviderSvc=CompFactory.getComps("AddressRemappingSvc","ProxyProviderSvc",)
218  AddressRemappingSvc = AddressRemappingSvc("AddressRemappingSvc")
219  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMTopoJets.BTagTrackToJetAssociator->AntiKt4EMTopoJets.BTagTrackToJetAssociator_' + suffix]
220  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMTopoJets.JFVtx->AntiKt4EMTopoJets.JFVtx_' + suffix]
221  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMTopoJets.SecVtx->AntiKt4EMTopoJets.SecVtx_' + suffix]
222 
223  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMTopoJets.btaggingLink->AntiKt4EMTopoJets.btaggingLink_' + suffix]
224  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTaggingContainer#BTagging_AntiKt4EMTopo->BTagging_AntiKt4EMTopo_' + suffix]
225  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTaggingAuxContainer#BTagging_AntiKt4EMTopoAux.->BTagging_AntiKt4EMTopo_' + suffix+"Aux."]
226  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::VertexContainer#BTagging_AntiKt4EMTopoSecVtx->BTagging_AntiKt4EMTopoSecVtx_' + suffix]
227  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::VertexAuxContainer#BTagging_AntiKt4EMTopoSecVtxAux.->BTagging_AntiKt4EMTopoSecVtx_' + suffix+"Aux."]
228  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTagVertexContainer#BTagging_AntiKt4EMTopoJFVtx->BTagging_AntiKt4EMTopoJFVtx_' + suffix]
229  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTagVertexAuxContainer#BTagging_AntiKt4EMTopoJFVtxAux.->BTagging_AntiKt4EMTopoJFVtx_' + suffix+"Aux."]
230  acc.addService(AddressRemappingSvc)
231  acc.addService(ProxyProviderSvc(ProviderNames = [ "AddressRemappingSvc" ]))
232  return acc
233 
234 # Valerio's magic hacks for pflow
236  acc = ComponentAccumulator()
237 
238  AddressRemappingSvc, ProxyProviderSvc=CompFactory.getComps("AddressRemappingSvc","ProxyProviderSvc",)
239  AddressRemappingSvc = AddressRemappingSvc("AddressRemappingSvc")
240  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMPFlowJets.BTagTrackToJetAssociator->AntiKt4EMPFlowJets.BTagTrackToJetAssociator_' + suffix]
241  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMPFlowJets.JFVtx->AntiKt4EMPFlowJets.JFVtx_' + suffix]
242  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMPFlowJets.SecVtx->AntiKt4EMPFlowJets.SecVtx_' + suffix]
243 
244  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::JetAuxContainer#AntiKt4EMPFlowJets.btaggingLink->AntiKt4EMPFlowJets.btaggingLink_' + suffix]
245  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTaggingContainer#BTagging_AntiKt4EMPFlow->BTagging_AntiKt4EMPFlow_' + suffix]
246  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTaggingAuxContainer#BTagging_AntiKt4EMPFlowAux.->BTagging_AntiKt4EMPFlow_' + suffix+"Aux."]
247  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::VertexContainer#BTagging_AntiKt4EMPFlowSecVtx->BTagging_AntiKt4EMPFlowSecVtx_' + suffix]
248  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::VertexAuxContainer#BTagging_AntiKt4EMPFlowSecVtxAux.->BTagging_AntiKt4EMPFlowSecVtx_' + suffix+"Aux."]
249  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTagVertexContainer#BTagging_AntiKt4EMPFlowJFVtx->BTagging_AntiKt4EMPFlowJFVtx_' + suffix]
250  AddressRemappingSvc.TypeKeyRenameMaps += ['xAOD::BTagVertexAuxContainer#BTagging_AntiKt4EMPFlowJFVtxAux.->BTagging_AntiKt4EMPFlowJFVtx_' + suffix+"Aux."]
251  acc.addService(AddressRemappingSvc)
252  acc.addService(ProxyProviderSvc(ProviderNames = [ "AddressRemappingSvc" ]))
253  return acc
python.FtagDerivationConfig.RenameInputContainerEmTopoHacksCfg
def RenameInputContainerEmTopoHacksCfg(suffix)
Definition: FtagDerivationConfig.py:213
python.FtagDerivationConfig.HLTJetFTagDecorationCfg
def HLTJetFTagDecorationCfg(cfgFlags)
Definition: FtagDerivationConfig.py:75
AddressRemappingSvc
This class provides the interface to the LCG POOL persistency software.
Definition: AddressRemappingSvc.h:41
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
GNNVertexFitterConfig.GNNVertexFitterAlgCfg
def GNNVertexFitterAlgCfg(flags, jetcol="AntiKt4EMPFlowJets", inclusive=False, **kwargs)
Definition: GNNVertexFitterConfig.py:32
python.FtagDerivationConfig.FtagJetCollectionsCfg
def FtagJetCollectionsCfg(cfgFlags, jet_cols, pv_cols=None, trackAugmenterPrefix=None)
Definition: FtagDerivationConfig.py:17
python.FtagDerivationConfig.trackLeptonDecorator
ComponentAccumulator trackLeptonDecorator(cfgFlags)
Definition: FtagDerivationConfig.py:162
python.FtagDerivationConfig._getTrackCollection
def _getTrackCollection(cfgFlags)
Definition: FtagDerivationConfig.py:206
python.FtagDerivationConfig.RenameInputContainerEmPflowHacksCfg
def RenameInputContainerEmPflowHacksCfg(suffix)
Definition: FtagDerivationConfig.py:235
python.BTagConfig.BTagAlgsCfg
def BTagAlgsCfg(inputFlags, JetCollection, nnList=[], TaggerList=None, SecVertexers=None, trackCollection='InDetTrackParticles', primaryVertices='PrimaryVertices', muons='Muons', BTagCollection=None, renameTrackJets=False, AddedJetSuffix='')
Definition: BTagConfig.py:200
python.FtagDerivationConfig.trackTruthDecorator
ComponentAccumulator trackTruthDecorator(cfgFlags)
Definition: FtagDerivationConfig.py:182
python.AsgElectronLikelihoodToolsConfig.AsgElectronLikelihoodToolCfg
def AsgElectronLikelihoodToolCfg(flag, name, quality, menu=electronLHmenu.offlineMC21)
Definition: AsgElectronLikelihoodToolsConfig.py:13
ParticleJetToolsConfig.getJetDeltaRFlavorLabelTool
def getJetDeltaRFlavorLabelTool(name='jetdrlabeler', jet_pt_min=5000)
Definition: ParticleJetToolsConfig.py:127
python.BTagTrackAugmenterAlgConfig.BTagTrackAugmenterAlgCfg
def BTagTrackAugmenterAlgCfg(flags, TrackCollection='InDetTrackParticles', PrimaryVertexCollectionName='PrimaryVertices', prefix=None)
Definition: BTagTrackAugmenterAlgConfig.py:9
ProxyProviderSvc
manages the address providers and add proxies on demand to the store
Definition: ProxyProviderSvc.h:43
python.FtagDerivationConfig.tagSingleJetCollection
def tagSingleJetCollection(cfgFlags, jet_col, pv_col, trackAugmenterPrefix=None)
Definition: FtagDerivationConfig.py:127
python.MuonSelectorToolsConfig.MuonSelectionToolCfg
def MuonSelectionToolCfg(flags, name="MuonSelectionTool", **kwargs)
Standard configuration of the MuonSelectionTool used in reconstruction & validation jobs The snippet ...
Definition: MuonSelectorToolsConfig.py:16
python.FtagDerivationConfig.BTagLargeRDecoration
def BTagLargeRDecoration(cfgFlags, jet_col)
Definition: FtagDerivationConfig.py:89
python.FoldDecoratorConfig.FoldDecoratorCfg
def FoldDecoratorCfg(flags, jetCollection='AntiKt4EMPFlowJets', prefix='')
Definition: FoldDecoratorConfig.py:7
python.BTagConfig.GetTaggerTrainingMap
def GetTaggerTrainingMap(inputFlags, jet_col)
Definition: BTagConfig.py:30
InDetTrackSystematicsToolsConfig.InDetTrackTruthOriginToolCfg
def InDetTrackTruthOriginToolCfg(flags, name="InDetTrackTruthOriginTool", **kwargs)
Definition: InDetTrackSystematicsToolsConfig.py:6