ATLAS Offline Software
JetMomentToolsConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 """
4 
5  JetMomentToolsConfig: A helper module for configuring jet moment
6  tools, in support of JetRecConfig.JetModConfig.
7  Author: TJ Khoo
8 
9 
10 IMPORTANT : all the getXYZTool(jetdef, modspec) functions are meant to be used as callback from the main JetRecConfig module
11 when we need to convert definitions of tools into the actual tools. At this point the functions are invoked as
12  func(jetdef, modspec)
13 Hence they have jetdef and modspec arguments even if not needed in every case.
14 """
15 
16 from AthenaCommon import Logging
17 jetmomentlog = Logging.logging.getLogger('JetMomentToolsConfig')
18 
19 from AthenaConfiguration.ComponentFactory import CompFactory
20 from AthenaConfiguration.Enums import LHCPeriod
21 
22 from xAODBase.xAODType import xAODType
23 
24 
25 def idTrackSelToolFromJetCtx(trkOpt,trkProperties):
26  """returns a InDetTrackSelectionTool configured with the jet context corresponding to trkOpt
27  """
28  from JetRecTools.JetRecToolsConfig import getIDTrackSelectionTool #
29  return getIDTrackSelectionTool(f"trackSel{trkOpt}", **trkProperties["trackSelOptions"])
30 
31 
32 def getEMScaleMomTool(jetdef, modspec=""):
33  # This may need updating e.g. for evolving trigger cluster container names
34  # We do the non-trivial summation over constituents unless the jets were
35  # built directly from EM-scale topoclusters, in which case we can just
36  # copy the constituent scale
37  useUncalibConstits = False
38  if jetdef.inputdef.basetype==xAODType.CaloCluster:
39  builtFromEMClusters = jetdef.inputdef.inputname in ["CaloCalTopoClusters","HLT_CaloTopoClustersFS"] and jetdef.inputdef.modifiers==["EM"]
40  useUncalibConstits = not builtFromEMClusters
41  elif (jetdef.inputdef.basetype==xAODType.ParticleFlow or jetdef.inputdef.basetype==xAODType.FlowElement):
42  useUncalibConstits = True
43  else:
44  raise ValueError("EM scale momentum not defined for input type {}".format(jetdef.inputdef.basetype))
45 
46  emscalemom = CompFactory.JetEMScaleMomTool(
47  "emscalemom_{}".format(jetdef.basename),
48  UseUncalibConstits = useUncalibConstits,
49  JetContainer = jetdef.fullname(),
50  )
51 
52  return emscalemom
53 
54 def getConstitFourMomTool(jetdef, modspec=""):
55 
59  CaloClusterStates = {
60  "UNKNOWN" : -1,
61  "UNCALIBRATED" : 0,
62  "CALIBRATED" : 1,
63  "ALTCALIBRATED" : 2,
64  "NSTATES" : 3
65  }
66 
67  cfourmom = CompFactory.JetConstitFourMomTool("constitfourmom_{0}".format(jetdef.basename))
68  if "LCTopo" in jetdef.basename or "EMTopo" in jetdef.basename:
69  cfourmom.JetScaleNames = ["DetectorEtaPhi"]
70  if "HLT_" in jetdef.fullname():
71  cfourmom.AltConstitColls = [""]
72  cfourmom.AltConstitScales = [0]
73  cfourmom.AltJetScales = ["JetConstitScaleMomentum"]
74  else:
75  clstate = "CALIBRATED" if "LCTopo" in jetdef.basename else "UNCALIBRATED"
76  cfourmom.AltConstitColls = [jetdef.inputdef.inputname]
77  cfourmom.AltConstitScales = [CaloClusterStates[clstate]]
78  cfourmom.AltJetScales = [""]
79  # Drop the LC-calibrated four-mom for EMTopo jets as we only wanted it as a possibility
80  # in MET CST calculations but never used it
81  elif "PFlow" in jetdef.basename or "UFO" in jetdef.basename:
82  cfourmom.JetScaleNames = ["DetectorEtaPhi"]
83  cfourmom.AltConstitColls = [""]
84  cfourmom.AltConstitScales = [0]
85  cfourmom.AltJetScales = ["JetConstitScaleMomentum"]
86 
87  return cfourmom
88 
89 # Jet vertex fraction with selection.
90 def getJVFTool(jetdef, modspec):
91  trkopt = modspec or jetdef.context # allow to overide jetdef.context if modspec is specified
92  trackingKeys = jetdef._cflags.Jet.Context[trkopt]
93  jvf = CompFactory.JetVertexFractionTool(
94  "jvf",
95  VertexContainer = trackingKeys["Vertices"],
96  AssociatedTracks = trackingKeys["GhostTracksLabel"],
97  TrackVertexAssociation = trackingKeys["TVA"],
98  TrackParticleContainer = trackingKeys["Tracks"],
99  TrackSelector = idTrackSelToolFromJetCtx(trkopt, trackingKeys),
100  SuppressInputDependence = True,
101  UseOriginVertex = jetdef.byVertex
102  )
103  return jvf
104 
105 
106 # Jet vertex tagger with selection.
107 def getJVTTool(jetdef, modspec):
108  jvt = CompFactory.JetVertexTaggerTool(
109  "jvt",
110  VertexContainer = jetdef._cflags.Jet.Context[modspec or jetdef.context]["Vertices"],
111  SuppressInputDependence = True,
112  UseOriginVertex = jetdef.byVertex
113  )
114  return jvt
115 
116 # Jet vertex tagger with neural network.
117 def getNNJvtTool(jetdef, modspec):
118  nnjvt = CompFactory.getComp("JetPileupTag::JetVertexNNTagger")(
119  "nnjvt",
120  VertexContainer = jetdef._cflags.Jet.Context[modspec or jetdef.context]["Vertices"],
121  SuppressInputDependence = True
122  )
123  return nnjvt
124 
125 
126 def getTrackMomentsTool(jetdef, modspec):
127  # retrieve the tracking keys to be used with modspec :
128  trkopt = modspec or jetdef.context # allow to overide jetdef.context if modspec is specified
129  trackingKeys = jetdef._cflags.Jet.Context[trkopt]
130 
131  trackmoments = CompFactory.JetTrackMomentsTool(
132  "trkmoms",
133  VertexContainer = trackingKeys["Vertices"],
134  AssociatedTracks = trackingKeys["GhostTracksLabel"],
135  TrackVertexAssociation = trackingKeys["TVA"],
136  TrackMinPtCuts = [500, 1000],
137  TrackSelector = idTrackSelToolFromJetCtx(trkopt,trackingKeys),
138  DoPFlowMoments = 'PFlow' in jetdef.fullname() or 'UFO' in jetdef.fullname() ,
139  )
140  return trackmoments
141 
142 def getTrackSumMomentsTool(jetdef, modspec):
143  trkopt = modspec or jetdef.context # allow to overide jetdef.context if modspec is specified
144  trackingKeys = jetdef._cflags.Jet.Context[trkopt]
145  jettrackselloose = idTrackSelToolFromJetCtx(trkopt,trackingKeys)
146  # retrieve the tracking keys to be used with modspec :
147  tracksummoments = CompFactory.JetTrackSumMomentsTool(
148  "trksummoms",
149  VertexContainer = trackingKeys["Vertices"],
150  AssociatedTracks = trackingKeys["GhostTracksLabel"],
151  TrackVertexAssociation = trackingKeys["TVA"],
152  RequireTrackPV = True,
153  TrackSelector = jettrackselloose
154  )
155  return tracksummoments
156 
157 # This tool sets a decoration saying which the nominal HS PV was.
158 # Historically it did the origin correction, but now we do this to constituents
159 def getOriginCorrVxTool(jetdef, modspec):
160  origin_setpv = CompFactory.JetOriginCorrectionTool(
161  "jetorigin_setpv",
162  VertexContainer = jetdef._cflags.Jet.Context[modspec or jetdef.context]["Vertices"],
163  OriginCorrectedName = "",
164  OnlyAssignPV = True,
165  )
166  return origin_setpv
167 
168 
169 def getJetPtAssociationTool(jetdef, modspec):
170 
171  from JetRecConfig.JetDefinition import buildJetAlgName
172 
173  truthJetAlg = buildJetAlgName(jetdef.algorithm, jetdef.radius)+'Truth'+str(modspec)+'Jets'
174 
175  jetPtAssociation = CompFactory.JetPtAssociationTool('jetPtAssociation',
176  MatchingJetContainer = truthJetAlg,
177  AssociationName = "GhostTruth")
178 
179  return jetPtAssociation
180 
181 
182 def getQGTaggingTool(jetdef, modspec):
183  trkopt = modspec or jetdef.context # allow to overide jetdef.context if modspec is specified
184  trackingKeys = jetdef._cflags.Jet.Context[trkopt]
185 
186  qgtagging = CompFactory.JetQGTaggerVariableTool('qgtagging',
187  VertexContainer = trackingKeys["Vertices"],
188  TrackVertexAssociation = trackingKeys["TVA"],
189  TrackSelector = idTrackSelToolFromJetCtx(trkopt,trackingKeys),
190  )
191 
192  return qgtagging
193 
194 
195 def getPFlowfJVTTool(jetdef, modspec):
196 
197  from JetCalibTools import JetCalibToolsConfig
198  calibString = "AnalysisLatest:mc:JetArea_Residual_EtaJES"
199  if( modspec and modspec == "CustomVtx" ) :
200  if jetdef._cflags.GeoModel.Run is LHCPeriod.Run3:
201  calibString = "AnalysisLatest:mc:JetArea_Residual_EtaJES:Kt4EMPFlowNeutEventShape:HggPrimaryVertices"
202  else:
203  calibString = "AnalysisLatest:mc:JetArea_Residual_EtaJES:Kt4EMPFlowCustomVtxEventShape:HggPrimaryVertices"
204  jetCalibrationTool = JetCalibToolsConfig.getJetCalibToolFromString(jetdef, calibString)
205 
206  wPFOTool = CompFactory.getComp('CP::WeightPFOTool')("fJVT__wPFO")
207 
208  trackingKeys = jetdef._cflags.Jet.Context[modspec or jetdef.context]
209 
210  fJVTTool = CompFactory.JetForwardPFlowJvtTool("fJVT",
211  verticesName = trackingKeys["Vertices"],
212  TrackVertexAssociation = trackingKeys["TVA"],
213  WeightPFOTool = wPFOTool,
214  JetCalibrationTool = jetCalibrationTool,
215  FEName = jetdef.inputdef.containername,
216  ORName = "",
217  FjvtRawName = "DFCommonJets_fJvt",
218  includePV = False)
219 
220  return fJVTTool
221 
222 
223 def getPFlowbJVTTool(jetdef, modspec):
224 
225  from JetCalibTools import JetCalibToolsConfig
226  jetCalibrationTool = JetCalibToolsConfig.getJetCalibToolFromString(jetdef, "AnalysisLatest:mc:JetArea_Residual_EtaJES")
227 
228  wPFOTool = CompFactory.getComp('CP::WeightPFOTool')("bJVT__wPFO")
229 
230  trackingKeys = jetdef._cflags.Jet.Context[modspec or jetdef.context]
231 
232  bJVTTool = CompFactory.JetBalancePFlowJvtTool('bJVT',
233  verticesName = trackingKeys["Vertices"],
234  TrackVertexAssociation = trackingKeys["TVA"],
235  WeightPFOTool = wPFOTool,
236  JetCalibrationTool = jetCalibrationTool,
237  FEName = jetdef.inputdef.containername,
238  ORNameFE = "",
239  BjvtRawName = 'DFCommonJets_bJvt',
240  includePV = True)
241 
242  return bJVTTool
243 
244 def getBoostedJetTaggerTool(jetdef, modspec):
245 
246  jssutils = CompFactory.JSSTaggerUtils("JSSTaggerUtils/MyTagger")
247 
248 
249  bjtTool = CompFactory.BoostedJetTaggerTool("BoostedJetTaggerTool",
250  MLTagger = jssutils,
251  DecorationName = "QGTransformer",
252  CalibArea = "QGConstituentTagger/Nov24",
253  ConfigFile = "QGTagger_AntiKt04PFlow_Transformer.dat"
254  )
255 
256  return bjtTool
JetMomentToolsConfig.getJetPtAssociationTool
def getJetPtAssociationTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:169
JetMomentToolsConfig.idTrackSelToolFromJetCtx
def idTrackSelToolFromJetCtx(trkOpt, trkProperties)
Definition: JetMomentToolsConfig.py:25
vtune_athena.format
format
Definition: vtune_athena.py:14
JetMomentToolsConfig.getConstitFourMomTool
def getConstitFourMomTool(jetdef, modspec="")
Definition: JetMomentToolsConfig.py:54
JetMomentToolsConfig.getOriginCorrVxTool
def getOriginCorrVxTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:159
python.JetDefinition.buildJetAlgName
def buildJetAlgName(finder, mainParam, variableRMassScale=-1.0, variableRMinRadius=-1.0)
Definition: JetDefinition.py:50
JetMomentToolsConfig.getPFlowbJVTTool
def getPFlowbJVTTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:223
JetCalibToolsConfig.getJetCalibToolFromString
def getJetCalibToolFromString(jetdef, modspec)
Definition: JetCalibToolsConfig.py:249
JetMomentToolsConfig.getNNJvtTool
def getNNJvtTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:117
JetMomentToolsConfig.getBoostedJetTaggerTool
def getBoostedJetTaggerTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:244
JetMomentToolsConfig.getPFlowfJVTTool
def getPFlowfJVTTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:195
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
JetMomentToolsConfig.getJVFTool
def getJVFTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:90
str
Definition: BTagTrackIpAccessor.cxx:11
JetMomentToolsConfig.getTrackMomentsTool
def getTrackMomentsTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:126
JetMomentToolsConfig.getJVTTool
def getJVTTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:107
JetRecToolsConfig.getIDTrackSelectionTool
def getIDTrackSelectionTool(toolname, **toolProps)
Definition: JetRecToolsConfig.py:19
JetMomentToolsConfig.getQGTaggingTool
def getQGTaggingTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:182
JetMomentToolsConfig.getTrackSumMomentsTool
def getTrackSumMomentsTool(jetdef, modspec)
Definition: JetMomentToolsConfig.py:142
JetMomentToolsConfig.getEMScaleMomTool
def getEMScaleMomTool(jetdef, modspec="")
Definition: JetMomentToolsConfig.py:32