ATLAS Offline Software
JetCommonConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 #==============================================================================
4 # Contains the configuration for common jet reconstruction + decorations
5 # used in analysis DAODs
6 #==============================================================================
7 
8 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9 from AthenaConfiguration.ComponentFactory import CompFactory
10 
11 def JetCommonCfg(ConfigFlags):
12  """Main config for jet reconstruction and decorations"""
13 
14  acc = ComponentAccumulator()
15 
16  acc.merge(StandardJetsInDerivCfg(ConfigFlags))
17  if "McEventCollection#GEN_EVENT" not in ConfigFlags.Input.TypedCollections:
18  acc.merge(AddBadBatmanCfg(ConfigFlags))
19  acc.merge(AddDistanceInTrainCfg(ConfigFlags))
20  acc.merge(AddSidebandEventShapeCfg(ConfigFlags))
21  acc.merge(AddEventCleanFlagsCfg(ConfigFlags))
22 
23  return acc
24 
25 
26 def StandardJetsInDerivCfg(ConfigFlags):
27  """Jet reconstruction needed for PHYS/PHYSLITE"""
28 
29  from JetRecConfig.StandardSmallRJets import AntiKt4EMTopo,AntiKt4EMPFlow,AntiKtVR30Rmax4Rmin02PV0Track
30  from JetRecConfig.StandardLargeRJets import AntiKt10LCTopoTrimmed,AntiKt10UFOCSSKSoftDrop
31  from JetRecConfig.JetRecConfig import JetRecCfg
32 
33  acc = ComponentAccumulator()
34 
35  AntiKt4EMTopo_deriv = AntiKt4EMTopo.clone(
36  modifiers = AntiKt4EMTopo.modifiers+("JetPtAssociation","QGTagging")
37  )
38 
39  AntiKt4EMPFlow_deriv = AntiKt4EMPFlow.clone(
40  modifiers = AntiKt4EMPFlow.modifiers+("JetPtAssociation","QGTagging","fJVT","NNJVT","CaloEnergiesClus","JetPileupLabel")
41  )
42 
43  jetList = [AntiKt4EMTopo_deriv, AntiKt4EMPFlow_deriv,
44  AntiKtVR30Rmax4Rmin02PV0Track,
45  AntiKt10LCTopoTrimmed,AntiKt10UFOCSSKSoftDrop]
46 
47 
48  for jd in jetList:
49  acc.merge(JetRecCfg(ConfigFlags,jd))
50 
51  return acc
52 
53 def AddBadBatmanCfg(ConfigFlags):
54  """Add bad batman decoration for events with large EMEC-IW noise"""
55 
56  acc = ComponentAccumulator()
57 
58  CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
59  from DerivationFrameworkJetEtMiss.JetToolConfig import BadBatmanToolCfg
60  badBatmanTool = acc.getPrimaryAndMerge(BadBatmanToolCfg(ConfigFlags))
61  acc.addEventAlgo(CommonAugmentation("BadBatmanAugmentation", AugmentationTools = [badBatmanTool]))
62 
63  return acc
64 
65 def AddDistanceInTrainCfg(ConfigFlags):
66  """Add distance in train information to EventInfo"""
67  from DerivationFrameworkJetEtMiss.JetToolConfig import DistanceInTrainToolCfg
68 
69  acc = ComponentAccumulator()
70 
71  CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
72  distanceInTrainTool = acc.getPrimaryAndMerge(DistanceInTrainToolCfg(ConfigFlags))
73  acc.addEventAlgo(CommonAugmentation("DistanceInTrainAugmentation", AugmentationTools = [distanceInTrainTool]))
74 
75  return acc
76 
77 def AddSidebandEventShapeCfg(ConfigFlags):
78  """Special rho definitions for PFlow jets"""
79  from JetRecConfig.JetRecConfig import getInputAlgs,getConstitPJGAlg,reOrderAlgs
80  from JetRecConfig.StandardJetConstits import stdConstitDic as cst
81  from JetRecConfig.JetInputConfig import buildEventShapeAlg
82 
83  acc = ComponentAccumulator()
84 
85  constit_algs = getInputAlgs(cst.GPFlow, flags=ConfigFlags)
86  constit_algs, ca = reOrderAlgs( [a for a in constit_algs if a is not None])
87 
88  acc.merge(ca)
89  for a in constit_algs:
90  acc.addEventAlgo(a)
91 
92  #Sideband definition
93  acc.addEventAlgo(getConstitPJGAlg(cst.GPFlow, suffix='PUSB'))
94  acc.addEventAlgo(buildEventShapeAlg(cst.GPFlow, '', suffix = 'PUSB' ))
95 
96  #New "sideband" definition when using CHS based on TTVA
97  acc.addEventAlgo(getConstitPJGAlg(cst.GPFlow, suffix='Neut'))
98  acc.addEventAlgo(buildEventShapeAlg(cst.GPFlow, '', suffix = 'Neut' ))
99 
100  return acc
101 
102 def AddJvtDecorationAlgCfg(ConfigFlags, algName = "JvtPassDecorAlg", jetContainer='AntiKt4EMTopo', **kwargs):
103  acc = ComponentAccumulator()
104  # Decorate if jet passed JVT criteria
105  from JetJvtEfficiency.JetJvtEfficiencyToolConfig import getJvtEffToolCfg
106 
107  passJvtTool = acc.popToolsAndMerge(getJvtEffToolCfg(ConfigFlags, jetContainer))
108  passJvtTool.PassJVTKey = "{}Jets.DFCommonJets_passJvt".format(jetContainer)
109  passJvtTool.SuppressOutputDependence = False
110  kwargs.setdefault("Decorators", [passJvtTool])
111  kwargs.setdefault("JetContainer", "{}Jets".format(jetContainer))
112  acc.addEventAlgo(CompFactory.JetDecorationAlg(algName, **kwargs), primary = True)
113  return acc
114 
115 def AddEventCleanFlagsCfg(ConfigFlags, workingPoints = ['Loose', 'Tight', 'LooseLLP']):
116  """Add event cleaning flags"""
117 
118  acc = ComponentAccumulator()
119  acc.merge(AddJvtDecorationAlgCfg(ConfigFlags, algName="JvtPassDecorAlg_EMTopo", jetContainer='AntiKt4EMTopo'))
120  acc.merge(AddJvtDecorationAlgCfg(ConfigFlags, algName="JvtPassDecorAlg", jetContainer='AntiKt4EMPFlow'))
121 
122  from DerivationFrameworkTau.TauCommonConfig import AddTauAugmentationCfg
123  acc.merge(AddTauAugmentationCfg(ConfigFlags, prefix="JetCommon", doLoose=True))
124 
125  # The overlap removal algorithm presents difficulties.
126  # It leaves decorations unlocked.
127  # Further, configurations may schedule multiple overlap removal algorithms,
128  # sometimes outside of this file, which then overwrite each other's
129  # results. So to get decoration locking to work properly, we need
130  # to first group all the event cleaning algorithms together,
131  # immediately followed by LockDecorations algorithms to lock the
132  # decorations produced by overlap. To accomplish this, we create
133  # two sequences, one for event cleaning and one for decoration locking
134  # and add the algorithms there. By default, these sequences will
135  # be scheduled at the current point in the global algorithm sequence,
136  # but if another fragment adds additional overlap removal, it may need
137  # to move the sequences later.
138  # All this is of course not MT-safe.
139  acc.addSequence(CompFactory.AthSequencer('EventCleanSeq', Sequential=True))
140  acc.addSequence(CompFactory.AthSequencer('EventCleanLockSeq', Sequential=True))
141 
142  # Overlap for EMTopo
143  from AssociationUtils.AssociationUtilsConfig import OverlapRemovalToolCfg
144  outputLabel_legacy = 'DFCommonJets_passOR'
145  bJetLabel = '' #default
146  tauLabel = 'DFTauLoose'
147  orTool_legacy = acc.popToolsAndMerge(OverlapRemovalToolCfg(ConfigFlags,outputLabel=outputLabel_legacy,bJetLabel=bJetLabel))
148  algOR_legacy = CompFactory.OverlapRemovalGenUseAlg('OverlapRemovalGenUseAlg_EMTopo',
149  JetKey="AntiKt4EMTopoJets",
150  OverlapLabel=outputLabel_legacy,
151  OverlapRemovalTool=orTool_legacy,
152  TauLabel=tauLabel,
153  BJetLabel=bJetLabel
154  )
155  acc.addEventAlgo(algOR_legacy, 'EventCleanSeq')
156 
157  # Overlap for EMPFlow
158  outputLabel = 'DFCommonJets_passOR'
159  orTool = acc.popToolsAndMerge(OverlapRemovalToolCfg(ConfigFlags,outputLabel=outputLabel,bJetLabel=bJetLabel))
160  algOR = CompFactory.OverlapRemovalGenUseAlg('OverlapRemovalGenUseAlg',
161  OverlapLabel=outputLabel,
162  OverlapRemovalTool=orTool,
163  TauLabel=tauLabel,
164  BJetLabel=bJetLabel)
165  acc.addEventAlgo(algOR, 'EventCleanSeq')
166 
167  # Explictly lock the decorations produced by overlap removal.
168  lockOR = CompFactory.DerivationFramework.LockDecorations \
169  ('OverlapRemovalLockDecorAlg',
170  Decorations = [
171  'Electrons.selected',
172  'Electrons.' + outputLabel,
173  'Muons.selected',
174  'Muons.' + outputLabel,
175  'Photons.selected',
176  'Photons.' + outputLabel,
177  'AntiKt4EMPFlowJets.selected',
178  'AntiKt4EMPFlowJets.' + outputLabel,
179  'AntiKt4EMTopoJets.selected',
180  'AntiKt4EMTopoJets.' + outputLabel,
181  'TauJets.selected',
182  'TauJets.' + outputLabel,
183  ])
184  acc.addEventAlgo(lockOR, 'EventCleanLockSeq')
185 
186  CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
187  from DerivationFrameworkMuons.MuonsToolsConfig import MuonJetDrToolCfg
188  muonJetDrTool = acc.getPrimaryAndMerge(MuonJetDrToolCfg(ConfigFlags, "MuonJetDrTool"))
189  acc.addEventAlgo(CommonAugmentation("DFCommonMuonsKernel2", AugmentationTools = [muonJetDrTool]), 'EventCleanSeq')
190 
191  from JetSelectorTools.JetSelectorToolsConfig import EventCleaningToolCfg,JetCleaningToolCfg
192 
193  supportedWPs = ['Loose', 'Tight', 'LooseLLP', 'VeryLooseLLP', 'SuperLooseLLP']
194  prefix = "DFCommonJets_"
195  evt_lvl_suppWPs_PFlow = ['LooseBad', 'TightBad']
196 
197  for wp in workingPoints:
198  if wp not in supportedWPs:
199  continue
200 
201  cleaningLevel = wp + 'Bad'
202  # LLP WPs have a slightly different name format
203  if 'LLP' in wp:
204  cleaningLevel = wp.replace('LLP', 'BadLLP')
205 
206  # Add support for TightBad event flag as well
207  doEvent_PFlow=False
208  for evt_swp in evt_lvl_suppWPs_PFlow:
209  if evt_swp == cleaningLevel:
210  doEvent_PFlow=True
211  break
212 
213  doEvent_EMTopo=False
214  if 'Loose' in cleaningLevel:
215  doEvent_EMTopo=True
216 
217 
218  if doEvent_EMTopo:
219  jetCleaningTool_legacy = acc.popToolsAndMerge(JetCleaningToolCfg(
220  ConfigFlags, 'JetCleaningTool_'+cleaningLevel+'_EMTopo',
221  'AntiKt4EMTopo', cleaningLevel, False))
222  acc.addPublicTool(jetCleaningTool_legacy)
223  ecTool_legacy = acc.popToolsAndMerge(EventCleaningToolCfg(
224  ConfigFlags,'EventCleaningTool_'+wp+'_EMTopo', cleaningLevel))
225  ecTool_legacy.JetCleanPrefix = prefix
226  ecTool_legacy.JetContainer = "AntiKt4EMTopoJets"
227  ecTool_legacy.JetCleaningTool = jetCleaningTool_legacy
228  acc.addPublicTool(ecTool_legacy)
229 
230  eventCleanAlg_legacy = CompFactory.EventCleaningTestAlg('EventCleaningTestAlg_'+wp+'_EMTopo',
231  EventCleaningTool=ecTool_legacy,
232  JetCollectionName="AntiKt4EMTopoJets",
233  EventCleanPrefix=prefix,
234  CleaningLevel=cleaningLevel,
235  doEvent=True) # Only store event-level flags for Loose and LooseLLP
236  acc.addEventAlgo(eventCleanAlg_legacy, 'EventCleanSeq')
237 
238 
239  if doEvent_PFlow:
240  jetCleaningTool = acc.popToolsAndMerge(JetCleaningToolCfg(
241  ConfigFlags, 'JetCleaningTool_'+cleaningLevel,
242  'AntiKt4EMPFlowJets', cleaningLevel, False))
243  acc.addPublicTool(jetCleaningTool)
244 
245  ecTool = acc.popToolsAndMerge(EventCleaningToolCfg(ConfigFlags,'EventCleaningTool_' + wp, cleaningLevel))
246  ecTool.JetCleanPrefix = prefix
247  ecTool.JetContainer = "AntiKt4EMPFlowJets"
248  ecTool.JetCleaningTool = jetCleaningTool
249  acc.addPublicTool(ecTool)
250 
251  eventCleanAlg = CompFactory.EventCleaningTestAlg('EventCleaningTestAlg_'+wp,
252  EventCleaningTool=ecTool,
253  JetCollectionName="AntiKt4EMPFlowJets",
254  EventCleanPrefix=prefix,
255  CleaningLevel=cleaningLevel,
256  doEvent=True) # for PFlow we use Loose and Tight
257  acc.addEventAlgo(eventCleanAlg, 'EventCleanSeq')
258 
259  return acc
260 
261 
262 def addJetsToSlimmingTool(slimhelper,contentlist,smartlist=[]):
263  for item in contentlist:
264  if item not in slimhelper.AppendToDictionary:
265  slimhelper.AppendToDictionary.update({item:'xAOD::JetContainer',
266  item+"Aux":'xAOD::JetAuxContainer'})
267  if item in smartlist:
268  slimhelper.SmartCollections.append(item)
269  else:
270  slimhelper.AllVariables.append(item)
271 
272 
273 
276 def addOriginCorrectedClustersToSlimmingTool(slimhelper,writeLC=False,writeEM=False):
277 
278  slimhelper.ExtraVariables.append('CaloCalTopoClusters.calE.calEta.calPhi.calM')
279 
280  if writeLC:
281  if "LCOriginTopoClusters" not in slimhelper.AppendToDictionary:
282  slimhelper.AppendToDictionary.update({"LCOriginTopoClusters":'xAOD::CaloClusterContainer',
283  "LCOriginTopoClustersAux":'xAOD::ShallowAuxContainer'})
284  slimhelper.ExtraVariables.append('LCOriginTopoClusters.calEta.calPhi.originalObjectLink')
285 
286  if writeEM:
287  if "EMOriginTopoClusters" not in slimhelper.AppendToDictionary:
288  slimhelper.AppendToDictionary.update({"EMOriginTopoClusters":'xAOD::CaloClusterContainer',
289  "EMOriginTopoClustersAux":'xAOD::ShallowAuxContainer'})
290  slimhelper.ExtraVariables.append('EMOriginTopoClusters.calE.calEta.calPhi.originalObjectLink')
AssociationUtilsConfig.OverlapRemovalToolCfg
def OverlapRemovalToolCfg(ConfigFlags, masterName='OverlapRemovalTool', inputLabel='selected', outputLabel='overlaps', bJetLabel='', maxElePtForBJetAwareOR=100. *1000, boostedLeptons=False, outputPassValue=False, linkOverlapObjects=False, doEleEleOR=False, doElectrons=True, doMuons=True, doJets=True, doTaus=True, doPhotons=True, doFatJets=False, **kwargs)
Definition: AssociationUtilsConfig.py:5
python.JetCommonConfig.JetCommonCfg
def JetCommonCfg(ConfigFlags)
Definition: JetCommonConfig.py:11
python.JetCommonConfig.AddSidebandEventShapeCfg
def AddSidebandEventShapeCfg(ConfigFlags)
Definition: JetCommonConfig.py:77
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
vtune_athena.format
format
Definition: vtune_athena.py:14
python.JetRecConfig.getInputAlgs
def getInputAlgs(jetOrConstitdef, flags, context="default", monTool=None)
Definition: JetRecConfig.py:279
python.JetSelectorToolsConfig.EventCleaningToolCfg
def EventCleaningToolCfg(ConfigFlags, name, cleaningLevel)
Definition: JetSelectorToolsConfig.py:14
python.JetCommonConfig.addOriginCorrectedClustersToSlimmingTool
def addOriginCorrectedClustersToSlimmingTool(slimhelper, writeLC=False, writeEM=False)
Helper to add origin corrected clusters to output.
Definition: JetCommonConfig.py:276
python.JetRecConfig.reOrderAlgs
def reOrderAlgs(algs)
Definition: JetRecConfig.py:796
python.MuonsToolsConfig.MuonJetDrToolCfg
def MuonJetDrToolCfg(ConfigFlags, name)
Definition: MuonsToolsConfig.py:6
python.JetInputConfig.buildEventShapeAlg
def buildEventShapeAlg(jetOrConstitdef, inputspec, voronoiRf=0.9, radius=0.4, suffix=None)
Definition: JetInputConfig.py:132
python.JetSelectorToolsConfig.JetCleaningToolCfg
def JetCleaningToolCfg(ConfigFlags, name, jetdef, cleaningLevel, useDecorations)
Definition: JetSelectorToolsConfig.py:6
python.TauCommonConfig.AddTauAugmentationCfg
def AddTauAugmentationCfg(flags, **kwargs)
Definition: TauCommonConfig.py:6
python.JetRecConfig.JetRecCfg
def JetRecCfg(flags, jetdef, returnConfiguredDef=False)
Top level functions returning ComponentAccumulator out of JetDefinition.
Definition: JetRecConfig.py:36
python.JetCommonConfig.addJetsToSlimmingTool
def addJetsToSlimmingTool(slimhelper, contentlist, smartlist=[])
Definition: JetCommonConfig.py:262
python.JetToolConfig.DistanceInTrainToolCfg
def DistanceInTrainToolCfg(ConfigFlags)
Definition: JetToolConfig.py:13
python.JetCommonConfig.AddJvtDecorationAlgCfg
def AddJvtDecorationAlgCfg(ConfigFlags, algName="JvtPassDecorAlg", jetContainer='AntiKt4EMTopo', **kwargs)
Definition: JetCommonConfig.py:102
python.JetRecConfig.getConstitPJGAlg
def getConstitPJGAlg(constitdef, suffix=None, flags=None, parent_jetdef=None)
Definition: JetRecConfig.py:350
python.JetCommonConfig.StandardJetsInDerivCfg
def StandardJetsInDerivCfg(ConfigFlags)
Definition: JetCommonConfig.py:26
python.JetCommonConfig.AddBadBatmanCfg
def AddBadBatmanCfg(ConfigFlags)
Definition: JetCommonConfig.py:53
python.JetJvtEfficiencyToolConfig.getJvtEffToolCfg
def getJvtEffToolCfg(flags, jetalg)
Definition: JetJvtEfficiencyToolConfig.py:17
python.JetCommonConfig.AddDistanceInTrainCfg
def AddDistanceInTrainCfg(ConfigFlags)
Definition: JetCommonConfig.py:65
python.JetToolConfig.BadBatmanToolCfg
def BadBatmanToolCfg(ConfigFlags)
Definition: JetToolConfig.py:6
python.JetCommonConfig.AddEventCleanFlagsCfg
def AddEventCleanFlagsCfg(ConfigFlags, workingPoints=['Loose', 'Tight', 'LooseLLP'])
Definition: JetCommonConfig.py:115