ATLAS Offline Software
HIGG1D1CustomJetsConfig.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 customs jet reconstruction + decorations
5 # used in analysis DAODs
6 #==============================================================================
7 
8 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9 from AthenaConfiguration.ComponentFactory import CompFactory
10 from AthenaConfiguration.Enums import LHCPeriod
11 
12 def addJetContextFlags(flags):
13  jetContextName = 'CustomVtx'
14  PrefixForHggCollection = "Hgg"
15  HggVertexContainerName = PrefixForHggCollection+"PrimaryVertices"
16  def customVtxContext(prevflags):
17  context = prevflags.Jet.Context.default.clone(
18  Vertices = HggVertexContainerName,
19  GhostTracks = "PseudoJetGhostTrack",
20  GhostTracksLabel = "GhostTrack",
21  TVA = "JetTrackVtxAssoc"+jetContextName,
22  JetTracks = "JetSelectedTracks"+jetContextName,
23  JetTracksQualityCuts = "JetSelectedTracks"+jetContextName+"_trackSelOpt"
24  )
25  return context
26  flags.addFlag(f"Jet.Context.{jetContextName}", customVtxContext)
27 
28 def HIGG1D1CustomJetsCfg(ConfigFlags):
29  """Jet reconstruction needed for HIGG1D1"""
30 
31  acc = ComponentAccumulator()
32 
33  # Ideally there would be a nice way to configure the PFlowCustomVtx jets but at the moment
34  # all tools need to be configured manually to ensure that the track to vertex association is done correctly.
35  PrefixForHggCollection = "Hgg"
36  HggVertexContainerName = PrefixForHggCollection+"PrimaryVertices"
37  CustomPFJetContainerName = "AntiKt4EMPFlowCustomVtxJets"
38 
39  from JetRecConfig.StandardJetConstits import stdInputExtDic, JetInputExternal,JetInputConstit, JetInputConstitSeq, JetConstitModifier, xAODType
40  from JetRecConfig.StandardSmallRJets import AntiKt4EMPFlow
41  from JetRecConfig.JetDefinition import JetDefinition
42  from JetRecTools import JetRecToolsConfig as jrtcfg
43  from JetMomentTools import JetMomentToolsConfig
44  from JetRecConfig.StandardJetConstits import stdConstitDic, stdContitModifDic
45  from JetRecConfig.StandardJetContext import propFromContext, inputsFromContext
46  from JetRecConfig.JetInputConfig import buildEventShapeAlg
47 
48  # Get custom jet context
49  jetContextName = 'CustomVtx'
50  context = ConfigFlags.Jet.Context[jetContextName]
51 
52  def replaceItems(tup,orgName,newName):
53  newList = list(tup)
54  for i, item in enumerate(newList):
55  if orgName in item:
56  newList[i] = item.replace(orgName,newName)
57  print( "Updated ", orgName, " to ", newName )
58  return tuple(newList)
59  print( "Failed to update ", orgName, " to ", newName )
60  return tuple(newList)
61 
62  def updateCalibSequence(tup):
63  newList = list(tup)
64  if ConfigFlags.GeoModel.Run is LHCPeriod.Run3:
65  rhoname = "Kt4EMPFlowNeutEventShape"
66  else:
67  rhoname = "Kt4EMPFlowCustomVtxEventShape"
68 
69  for i, item in enumerate(newList):
70  if "Calib" in item:
71  calibspecs = item.split(":")
72  calib, calibcontext, data_type = calibspecs[:3]
73  calibseq=""
74  if len(calibspecs)>3:
75  calibseq = calibspecs[3]
76  pvname = HggVertexContainerName
77  finalCalibString = f"CalibCustomVtx:{calibcontext}:{data_type}:{calibseq}:{rhoname}:{pvname}"
78  if len(calibspecs)>6: finalCalibString = f"{finalCalibString}:{calibspecs[6]}"
79  newList[i] = finalCalibString
80  print(finalCalibString)
81  return tuple(newList)
82  print( "Failed to update calib sequence" )
83  return tuple(newList)
84 
85 
86  # Create modifier list and JetDefinition
87  modsCustomVtx = AntiKt4EMPFlow.modifiers
88  modsCustomVtx = updateCalibSequence(modsCustomVtx)
89  modsCustomVtx = replaceItems(modsCustomVtx,"TrackMoments","TrackMomentsCustomVtx")
90  modsCustomVtx = replaceItems(modsCustomVtx,"TrackSumMoments","TrackSumMomentsCustomVtx")
91  modsCustomVtx = replaceItems(modsCustomVtx,"JVF","JVFCustomVtx")
92  modsCustomVtx = replaceItems(modsCustomVtx,"JVT","JVTCustomVtx")
93  modsCustomVtx = replaceItems(modsCustomVtx,"Charge","ChargeCustomVtx")
94 
95  ghostCustomVtx = AntiKt4EMPFlow.ghostdefs
96 
97  # GPFlow are the same than EMPFlow except they have pflow linked to elec or muons filtered out.
98  stdConstitDic["TrackCustomVtx"] = JetInputConstit("TrackCustomVtx", xAODType.TrackParticle,"JetSelectedTracksCustomVtx" )
99 
100 
101  stdConstitDic["GPFlowCustomVtx"] = JetInputConstitSeq("GPFlowCustomVtx", xAODType.FlowElement,["CorrectPFOCustomVtx", "CHSCustomVtx"] , 'GlobalParticleFlowObjects', 'CHSGCustomVtxParticleFlowObjects',
102  label='EMPFlow')
103 
104  stdContitModifDic["CorrectPFOCustomVtx"] = JetConstitModifier("CorrectPFOCustomVtx", "CorrectPFOTool",
105  prereqs=[inputsFromContext("Vertices")],
106  properties=dict(VertexContainerKey=propFromContext("Vertices"),
107  WeightPFOTool= CompFactory.getComp("CP::WeightPFOTool")("weightPFO") )
108  )
109 
110  stdContitModifDic["CHSCustomVtx"] = JetConstitModifier("CHSCustomVtx", "ChargedHadronSubtractionTool",
111  prereqs= [inputsFromContext("Vertices"),inputsFromContext("TVA")],
112  properties=dict(VertexContainerKey=propFromContext("Vertices"),
113  TrackVertexAssociation=propFromContext("TVA"),
114  UseTrackToVertexTool=True,
115  ))
116 
117 
118 
119  AntiKt4EMPFlowCustomVtx = JetDefinition("AntiKt",0.4,stdConstitDic.GPFlowCustomVtx,
120  infix = "CustomVtx",
121  context = jetContextName,
122  ghostdefs = ghostCustomVtx,
123  modifiers = modsCustomVtx+("JetPtAssociation","QGTaggingCustomVtx","fJVTCustomVtx","NNJVTCustomVtx","CaloEnergiesClus","JetPileupLabel"),
124  ptmin = 10000,
125  )
126 
127  def getUsedInVertexFitTrackDecoratorAlgCustomVtx(jetdef, jetmod):
128  """ Create the alg to decorate the used-in-fit information for AMVF """
129  context = jetdef._contextDic
130 
131  from InDetUsedInFitTrackDecoratorTool.UsedInVertexFitTrackDecoratorConfig import getUsedInVertexFitTrackDecoratorAlg
132  alg = getUsedInVertexFitTrackDecoratorAlg(context['Tracks'], context['Vertices'],
133  vertexDeco='TTVA_AMVFVertices_forHiggs',
134  weightDeco='TTVA_AMVFWeights_forHiggs')
135  return alg
136 
137 
138  # Define new input variables for jet configuration
139  stdInputExtDic[context['Vertices']] = JetInputExternal( context['Vertices'], xAODType.Vertex )
140 
141  stdInputExtDic["JetSelectedTracksCustomVtx"] = JetInputExternal("JetSelectedTracksCustomVtx", xAODType.TrackParticle,
142  prereqs= [ f"input:{context['Tracks']}" ], # in std context, this is InDetTrackParticles (see StandardJetContext)
143  algoBuilder = lambda jdef,_ : jrtcfg.getTrackSelAlg(jdef, trackSelOpt=False,
144  DecorDeps=["TTVA_AMVFWeights_forHiggs", "TTVA_AMVFVertices_forHiggs"] )
145  )
146 
147  stdInputExtDic["JetTrackUsedInFitDecoCustomVtx"] = JetInputExternal("JetTrackUsedInFitDecoCustomVtx", xAODType.TrackParticle,
148  prereqs= [ f"input:{context['Tracks']}" , # in std context, this is InDetTrackParticles (see StandardJetContext)
149  f"input:{context['Vertices']}"],
150  algoBuilder = getUsedInVertexFitTrackDecoratorAlgCustomVtx
151  )
152 
153  stdInputExtDic["JetTrackVtxAssocCustomVtx"] = JetInputExternal("JetTrackVtxAssocCustomVtx", xAODType.TrackParticle,
154  algoBuilder = lambda jdef,_ : jrtcfg.getJetTrackVtxAlg(jdef._contextDic, algname="jetTVACustomVtx",
155  WorkingPoint="Nonprompt_All_MaxWeight",
156  AMVFVerticesDeco='TTVA_AMVFVertices_forHiggs',
157  AMVFWeightsDeco='TTVA_AMVFWeights_forHiggs'),
158  prereqs = [ "input:JetTrackUsedInFitDecoCustomVtx", f"input:{context['Vertices']}" ] )
159 
160  stdInputExtDic["EventDensityCustomVtx"] = JetInputExternal("EventDensityCustomVtx", "EventShape", algoBuilder = buildEventShapeAlg,
161  containername = lambda jetdef, _ : "Kt4"+jetdef.inputdef.label+"CustomVtxEventShape",
162  prereqs = lambda jetdef : ["input:"+jetdef.inputdef.name] )
163 
164  from JetRecConfig.StandardJetMods import stdJetModifiers
165  from JetRecConfig.JetDefinition import JetModifier
166  from JetCalibTools import JetCalibToolsConfig
167 
168  stdJetModifiers.update(
169 
170  CalibCustomVtx = JetModifier("JetCalibrationTool","jetcalib_jetcoll_calibseqCustomVtx",
171  createfn=JetCalibToolsConfig.getJetCalibToolFromString,
172  prereqs=lambda mod,jetdef : JetCalibToolsConfig.getJetCalibToolPrereqs(mod,jetdef)+[f"input:{context['Vertices']}"]),
173 
174 
175  JVFCustomVtx = JetModifier("JetVertexFractionTool", "jvfCustomVtx",
176  createfn= lambda jdef,_ : JetMomentToolsConfig.getJVFTool(jdef,"CustomVtx"),
177  modspec = "CustomVtx",
178  prereqs = ["input:JetTrackVtxAssocCustomVtx", "mod:TrackMomentsCustomVtx", f"input:{context['Vertices']}"] ,
179  JetContainer = CustomPFJetContainerName),
180 
181  JVTCustomVtx = JetModifier("JetVertexTaggerTool", "jvtCustomVtx",
182  createfn= lambda jdef,_ : JetMomentToolsConfig.getJVTTool(jdef,"CustomVtx"),
183  modspec = "CustomVtx",
184  prereqs = [ "mod:JVFCustomVtx" ],JetContainer = CustomPFJetContainerName),
185 
186  NNJVTCustomVtx = JetModifier("JetVertexNNTagger", "nnjvtCustomVtx",
187  createfn=lambda jdef,_ :JetMomentToolsConfig.getNNJvtTool(jdef,"CustomVtx"),
188  prereqs = [ "mod:JVFCustomVtx" ],JetContainer = CustomPFJetContainerName),
189 
190  OriginSetPVCustomVtx = JetModifier("JetOriginCorrectionTool", "origin_setpvCustomVtx",
191  modspec = "CustomVtx",
192  prereqs = [ "mod:JVFCustomVtx" ],JetContainer = CustomPFJetContainerName, OnlyAssignPV=True),
193 
194  TrackMomentsCustomVtx = JetModifier("JetTrackMomentsTool", "trkmomsCustomVtx",
195  createfn= lambda jdef,_ : JetMomentToolsConfig.getTrackMomentsTool(jdef,"CustomVtx"),
196  modspec = "CustomVtx",
197  prereqs = [ "input:JetTrackVtxAssocCustomVtx","ghost:Track" ],JetContainer = CustomPFJetContainerName),
198 
199  TrackSumMomentsCustomVtx = JetModifier("JetTrackSumMomentsTool", "trksummomsCustomVtx",
200  createfn=lambda jdef,_ :JetMomentToolsConfig.getTrackSumMomentsTool(jdef,"CustomVtx"),
201  modspec = "CustomVtx",
202  prereqs = [ "input:JetTrackVtxAssocCustomVtx","ghost:Track" ],JetContainer = CustomPFJetContainerName),
203 
204  ChargeCustomVtx = JetModifier("JetChargeTool", "jetchargeCustomVtx",
205  prereqs = [ "ghost:Track" ]),
206 
207 
208  QGTaggingCustomVtx = JetModifier("JetQGTaggerVariableTool", "qgtaggingCustomVtx",
209  createfn=lambda jdef,_ :JetMomentToolsConfig.getQGTaggingTool(jdef,"CustomVtx"),
210  modspec = "CustomVtx",
211  prereqs = lambda _,jdef :
212  ["input:JetTrackVtxAssocCustomVtx","mod:TrackMomentsCustomVtx"] +
213  (["mod:JetPtAssociation"] if not jdef._cflags.Input.isMC else []),
214  JetContainer = CustomPFJetContainerName),
215 
216  fJVTCustomVtx = JetModifier("JetForwardPFlowJvtTool", "fJVTCustomVtx",
217  createfn=lambda jdef,_ :JetMomentToolsConfig.getPFlowfJVTTool(jdef,"CustomVtx"),
218  modspec = "CustomVtx",
219  prereqs = ["input:JetTrackVtxAssocCustomVtx","input:EventDensityCustomVtx",f"input:{context['Vertices']}","mod:NNJVTCustomVtx"],
220  JetContainer = CustomPFJetContainerName),
221  )
222 
223  from JetRecConfig.JetRecConfig import JetRecCfg
224 
225  acc.merge(JetRecCfg(ConfigFlags,AntiKt4EMPFlowCustomVtx))
226 
227  return acc
228 
230  """Event cleaning and jet cleaning for HIGG1D1"""
231 
232  acc = ComponentAccumulator()
233 
234  from DerivationFrameworkJetEtMiss.JetCommonConfig import AddJvtDecorationAlgCfg
235  acc.merge(AddJvtDecorationAlgCfg(ConfigFlags, algName = "JvtPassDecorCustomVtxAlg", jetContainer='AntiKt4EMPFlowCustomVtx'))
236 
237  from DerivationFrameworkTau.TauCommonConfig import AddTauAugmentationCfg
238  acc.merge(AddTauAugmentationCfg(ConfigFlags, prefix="JetCommon", doLoose=True))
239 
240  # Decorate if jet passes OR and save decoration DFCommonJets_passOR
241  # Use modified OR that does not check overlaps with tauls
242  from AssociationUtils.AssociationUtilsConfig import OverlapRemovalToolCfg
243 
244  # Sequences for event cleaning and decorator locking.
245  # See comments in JetCommonConfig.AddEventCleanFlagsCfg.
246  acc.addSequence(CompFactory.AthSequencer('EventCleanSeq', Sequential=True))
247  acc.addSequence(CompFactory.AthSequencer('EventCleanLockSeq', Sequential=True))
248 
249  outputLabel = 'DFCommonJets_passOR'
250  bJetLabel = '' #default
251  tauLabel = 'DFTauLoose'
252  orTool = acc.popToolsAndMerge(OverlapRemovalToolCfg(ConfigFlags, outputLabel=outputLabel, bJetLabel=bJetLabel))
253  algOR = CompFactory.OverlapRemovalGenUseAlg('OverlapRemovalGenUseAlg_CustomVtx',
254  JetKey="AntiKt4EMPFlowCustomVtxJets",
255  OverlapLabel=outputLabel,
256  OverlapRemovalTool=orTool,
257  TauLabel=tauLabel,
258  BJetLabel=bJetLabel)
259  acc.addEventAlgo(algOR, 'EventCleanSeq')
260 
261  # Explictly lock the decorations produced by overlap removal.
262  lockOR = CompFactory.DerivationFramework.LockDecorations \
263  ('OverlapRemovalLockDecorAlg_CustomVtx',
264  Decorations = [
265  'Electrons.selected',
266  'Electrons.' + outputLabel,
267  'Muons.selected',
268  'Muons.' + outputLabel,
269  'Photons.selected',
270  'Photons.' + outputLabel,
271  'AntiKt4EMPFlowCustomVtxJets.selected',
272  'AntiKt4EMPFlowCustomVtxJets.' + outputLabel,
273  ])
274  acc.addEventAlgo(lockOR, 'EventCleanLockSeq')
275 
276  from JetSelectorTools.JetSelectorToolsConfig import EventCleaningToolCfg, JetCleaningToolCfg
277  workingPoints = ['Loose', 'Tight']
278 
279  for wp in workingPoints:
280  cleaningLevel = wp + "Bad"
281 
282  jetCleaningTool = acc.popToolsAndMerge(
284  ConfigFlags,
285  name="JetCleaningCustomVtxTool_" + cleaningLevel,
286  jetdef="AntiKt4EMPFlowCustomVtxJets",
287  cleaningLevel=cleaningLevel,
288  useDecorations=False,
289  )
290  )
291  acc.addPublicTool(jetCleaningTool)
292 
293  ecTool = acc.popToolsAndMerge(
294  EventCleaningToolCfg(ConfigFlags, "EventCleaningCustomVtxTool_" + wp, cleaningLevel)
295  )
296  ecTool.JetCleanPrefix = "DFCommonJets_"
297  ecTool.JetContainer = "AntiKt4EMPFlowCustomVtxJets"
298  ecTool.JetCleaningTool = jetCleaningTool
299  acc.addPublicTool(ecTool)
300 
301  # Alg to calculate event-level and jet-level cleaning variables
302  # Only store event-level flags for Loose* WPs
303  eventCleanAlg = CompFactory.EventCleaningTestAlg(
304  "EventCleaningCustomVtxTestAlg_" + wp,
305  EventCleaningTool=ecTool,
306  JetCollectionName="AntiKt4EMPFlowCustomVtxJets",
307  EventCleanPrefix="DFCommonJetsCustomVtx_",
308  CleaningLevel=cleaningLevel,
309  doEvent=True,
310  )
311  acc.addEventAlgo(eventCleanAlg, 'EventCleanSeq')
312 
313  return acc
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.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.JetSelectorToolsConfig.EventCleaningToolCfg
def EventCleaningToolCfg(ConfigFlags, name, cleaningLevel)
Definition: JetSelectorToolsConfig.py:14
python.HIGG1D1CustomJetsConfig.HIGG1D1CustomJetsCleaningCfg
def HIGG1D1CustomJetsCleaningCfg(ConfigFlags)
Definition: HIGG1D1CustomJetsConfig.py:229
python.JetSelectorToolsConfig.JetCleaningToolCfg
def JetCleaningToolCfg(ConfigFlags, name, jetdef, cleaningLevel, useDecorations)
Definition: JetSelectorToolsConfig.py:6
JetCalibToolsConfig.getJetCalibToolPrereqs
def getJetCalibToolPrereqs(modspec, jetdef)
Definition: JetCalibToolsConfig.py:202
python.HIGG1D1CustomJetsConfig.HIGG1D1CustomJetsCfg
def HIGG1D1CustomJetsCfg(ConfigFlags)
Definition: HIGG1D1CustomJetsConfig.py:28
python.TauCommonConfig.AddTauAugmentationCfg
def AddTauAugmentationCfg(flags, **kwargs)
Definition: TauCommonConfig.py:6
python.StandardJetContext.inputsFromContext
def inputsFromContext(inputKey, prefix="", suffix="")
Definition: StandardJetContext.py:106
python.JetRecConfig.JetRecCfg
def JetRecCfg(flags, jetdef, returnConfiguredDef=False)
Top level functions returning ComponentAccumulator out of JetDefinition.
Definition: JetRecConfig.py:36
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.HIGG1D1CustomJetsConfig.addJetContextFlags
def addJetContextFlags(flags)
Definition: HIGG1D1CustomJetsConfig.py:12
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
UsedInVertexFitTrackDecoratorConfig.getUsedInVertexFitTrackDecoratorAlg
def getUsedInVertexFitTrackDecoratorAlg(trackCont="InDetTrackParticles", vtxCont="PrimaryVertices", vertexDeco="TTVA_AMVFVertices_forReco", weightDeco="TTVA_AMVFWeights_forReco")
Definition: UsedInVertexFitTrackDecoratorConfig.py:16
JetMomentToolsConfig.getNNJvtTool
def getNNJvtTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:117
python.JetCommonConfig.AddJvtDecorationAlgCfg
def AddJvtDecorationAlgCfg(ConfigFlags, algName="JvtPassDecorAlg", jetContainer='AntiKt4EMTopo', **kwargs)
Definition: JetCommonConfig.py:102
python.StandardJetContext.propFromContext
def propFromContext(propName)
Definition: StandardJetContext.py:94
JetMomentToolsConfig.getPFlowfJVTTool
def getPFlowfJVTTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:195
JetMomentToolsConfig.getJVFTool
def getJVFTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:90
JetMomentToolsConfig.getTrackMomentsTool
def getTrackMomentsTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:126
JetMomentToolsConfig.getJVTTool
def getJVTTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:107
JetMomentToolsConfig.getQGTaggingTool
def getQGTaggingTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:182
JetMomentToolsConfig.getTrackSumMomentsTool
def getTrackSumMomentsTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:142