ATLAS Offline Software
StandardJetMods.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 """
3 This module defines the standard JetModifier tools used in jet reco
4 
5 Definitions are grouped in a dictionary of tool configurations using the helpers defined
6 in package configs.
7 This dict maps a modifier alias to the JetModifier config object
8 that in turn will be responsible for generating a configured tool.
9 
10 The JetModifier config class is defined in JetDefinition.py
11 
12  Args to the JetModifier constructor are:
13  1. Tool Type (ignored if the helper is a custom one)
14  2. Tool Name (ignored if the helper is a custom one)
15  3. createfn : helper function which build the actual tool. If none, we just instantiate the tool type.
16  4. prereqs : Prerequisites (default to []). Can also be a function which returns a list
17  X. all other keyword arguments are directly interpreted as Property of the tool.
18  for ex, passing 'PtMin=10.' will configure the tool as in 'tool.PtMin = 10'
19  we can pass function as the value :
20  'JetContainerName=nameFunc' will configure as in 'tool.JetContainerName=nameFunc(jetdef, modspec)'
21 
22  --> should this be by default? prefer to avoid ignored args
23 """
24 from .JetDefinition import JetModifier
25 from .Utilities import ldict
26 from .StandardJetConstits import inputsFromContext
27 
28 stdJetModifiers = ldict()
29 
30 
32 stdJetModifiers.update(
33  Sort = JetModifier("JetSorter","jetsort"),
34  Filter = JetModifier("JetFilterTool","jetptfilter_{modspec}",
35  # we give a function as PtMin : it will be evaluated when instantiating the tool (modspec is specified with this tool
36  # alias like "Filter:10000" --> PtMin=100000).
37  PtMin = lambda jdef,modspec: int(modspec)
38  ),
39  Filter_ifnotESD = JetModifier("JetFilterTool","jetptfilter_{modspec}",
40  PtMin = lambda _,modspec: 1,
41  ),
42  # Filter that can be easily turned off via pre-exec for e.g. PHYSVAL
43  Filter_calibThreshold = JetModifier("JetFilterTool","jetptfilter_{modspec}",
44  PtMin = lambda jetdef,modspec: 1 if not jetdef._cflags.Jet.useCalibJetThreshold else int(modspec),
45  )
46 )
47 
48 
53 
54 # Calibration
55 try:
56  from JetCalibTools import JetCalibToolsConfig
57  stdJetModifiers.update(
58  Calib = JetModifier("JetCalibrationTool","jetcalib_jetcoll_calibseq",
59  createfn=JetCalibToolsConfig.getJetCalibToolFromString,
60  prereqs=lambda mod,jetdef : JetCalibToolsConfig.getJetCalibToolPrereqs(mod,jetdef)+[inputsFromContext("Vertices")])
61  )
62 except ModuleNotFoundError:
63  # In some releases (AthGeneration) JetCalibTools is not existing
64  pass
65 
66 # TBD:
67 # All items below in principle will support decoration mode, rather
68 # than only non-const modification. Mode of operation should be
69 # determined by interface called from parent tool/alg.
70 
71 
72 # Many JetMoment tools need to know the name of the container they operate on.
73 # We set the function below as the 'JetContainer' property so the config system
74 # can assign the right name to the c++ tool.
75 def _jetname(jetdef,modspec):
76  return jetdef.fullname()
77 
78 def isMC(flags):
79  """A simple filter function for testing if we're running in MC
80  returns (bool, str) where the str contains an explanation of why the bool is False.
81  (probably worth re-allocating somehere else)"""
82  return flags.Input.isMC, "Input file is not MC"
83 
84 
85 def _constitContainername(jetdef,modspec):
86  """Returns the exact constituent container name used to build jetdef"""
87  constitdef = jetdef.inputdef
88  containername = constitdef.containername(jetdef).split(':')[-1] if callable(constitdef.containername) else constitdef.containername
89  return containername
90 
91 
92 # Standard jet moments
93 try:
94  from JetMomentTools import JetMomentToolsConfig
95  stdJetModifiers.update(
96 
97  # Easy cases, no special config or prereqs, just default tool config
98  ClusterMoments = JetModifier("JetClusterMomentsTool", "clsmoms", JetContainer = _jetname),
99  ECPSFrac = JetModifier("JetECPSFractionTool", "ecpsfrac", JetContainer = _jetname),
100  Width = JetModifier("JetWidthTool", "width", JetContainer = _jetname),
101 
102  # More complex cases here
103  CaloEnergies = JetModifier("JetCaloEnergies", "jetens",
104  prereqs=["mod:EMScaleMom"],
105  Calculations=["EMFrac", "HECFrac", "PSFrac", "FracSamplingMax"], JetContainer = _jetname,
106  ),
107 
108  CaloEnergiesLargeR = JetModifier("JetCaloEnergies", "jetenslargeR",
109  prereqs=["mod:EMScaleMom"],
110  Calculations=["EMFrac", "HECFrac", "PSFrac", "EM3Frac", "Tile0Frac", "EffNClusts"], JetContainer = _jetname,
111  calcClusterBasedVars = True,
112  ),
113 
114  # CaloEnergiesClus is only relevant for FE-based jet collections
115  CaloEnergiesClus = JetModifier("JetCaloEnergies", "jetensclus",
116  prereqs=["mod:EMScaleMom"],
117  Calculations=["EMFrac", "HECFrac", "PSFrac", "FracSamplingMax"], JetContainer = _jetname,
118  calcClusterBasedVars = True),
119 
120  CaloQuality = JetModifier("JetCaloQualityTool", "caloqual",
121  TimingCuts = [5,10],
122  Calculations = ["LArQuality", "N90Constituents", "NegativeE", "Timing", "HECQuality", "Centroid", "AverageLArQF", "BchCorrCell"],JetContainer = _jetname),
123 
124  CaloQualityFE = JetModifier("JetCaloQualityToolFE", "caloqualFE",
125  TimingCuts = [5,10],
126  ThresholdCuts = [90],
127  Calculations = ["LArQuality", "NegativeE", "Timing", "HECQuality", "Centroid", "AverageLArQF", "BchCorrCell"],JetContainer = _jetname),
128 
129  N90 = JetModifier("JetCaloQualityTool", "n90",
130  Calculations = ["N90Constituents"],JetContainer = _jetname),
131 
132  ConstitFourMom = JetModifier("JetConstitFourMomTool", "constitfourmom_basename",
133  createfn=JetMomentToolsConfig.getConstitFourMomTool,),
134  EMScaleMom = JetModifier("JetEMScaleMomTool", "emscalemom_basename",
135  createfn=JetMomentToolsConfig.getEMScaleMomTool,
136  JetContainer = _jetname),
137 
138  JVF = JetModifier("JetVertexFractionTool", "jvf",
139  createfn=JetMomentToolsConfig.getJVFTool,
140  prereqs = [inputsFromContext("TVA"), "mod:TrackMoments", inputsFromContext("Vertices")],
141  JetContainer = _jetname),
142  JVT = JetModifier("JetVertexTaggerTool", "jvt",
143  createfn=JetMomentToolsConfig.getJVTTool,
144  prereqs = [ "mod:JVF" ],JetContainer = _jetname),
145  NNJVT = JetModifier("JetVertexNNTagger", "nnjvt",
146  createfn=JetMomentToolsConfig.getNNJvtTool,
147  prereqs = [ "mod:JVF" ],JetContainer = _jetname),
148  LArHVCorr = JetModifier("JetLArHVTool", "larhvcorr",
149  prereqs = ["mod:EMScaleMom"],JetContainer = _jetname),
150  OriginSetPV = JetModifier("JetOriginCorrectionTool", "origin_setpv",
151  prereqs = [ "mod:JVF" ],JetContainer = _jetname, OnlyAssignPV=True),
152  TrackMoments = JetModifier("JetTrackMomentsTool", "trkmoms",
153  createfn=JetMomentToolsConfig.getTrackMomentsTool,
154  prereqs = [ inputsFromContext("TVA"),"ghost:Track" ],JetContainer = _jetname),
155 
156  TrackSumMoments = JetModifier("JetTrackSumMomentsTool", "trksummoms",
157  createfn=JetMomentToolsConfig.getTrackSumMomentsTool,
158  prereqs = [ inputsFromContext("TVA"),"ghost:Track" ],JetContainer = _jetname),
159  Charge = JetModifier("JetChargeTool", "jetcharge",
160  prereqs = [ "ghost:Track" ]),
161 
162  QGTagging = JetModifier("JetQGTaggerVariableTool", "qgtagging",
163  createfn=JetMomentToolsConfig.getQGTaggingTool,
164  prereqs = lambda _,jetdef :
165  [inputsFromContext("TVA"),"mod:TrackMoments"] +
166  (["mod:JetPtAssociation"] if not isMC(jetdef._cflags) else []),
167  JetContainer = _jetname),
168 
169  fJVT = JetModifier("JetForwardPFlowJvtTool", "fJVT",
170  createfn=JetMomentToolsConfig.getPFlowfJVTTool,
171  prereqs = [inputsFromContext("TVA"),inputsFromContext("EventDensity"),inputsFromContext("Vertices"),"mod:NNJVT"],
172  JetContainer = _jetname),
173 
174  bJVT = JetModifier("JetBalancePFlowJvtTool", "bJVT",
175  createfn=JetMomentToolsConfig.getPFlowbJVTTool,
176  prereqs = [inputsFromContext("EventDensity"),inputsFromContext("Vertices"),"mod:NNJVT"],
177  JetContainer = _jetname),
178 
179  ConstitFrac = JetModifier("JetConstituentFrac", "constitFrac",
180  JetContainer = _jetname,
181  ),
182 
183  groomMRatio = JetModifier("JetGroomMRatio", "groomMRatio",
184  JetContainer = _jetname,
185  ),
186 
187  JetPtAssociation = JetModifier("JetPtAssociationTool", "jetPtAssociation",
188  filterfn=isMC,
189  createfn=JetMomentToolsConfig.getJetPtAssociationTool,
190  prereqs=["ghost:Truth"],
191  JetContainer = _jetname
192  ),
193 
194  # *******************
195  # Isolation variables
196  jetiso = JetModifier("JetIsolationTool","iso",
197  JetContainer=_jetname,
198  InputConstitContainer = _constitContainername,
199  IsolationCalculations = ["IsoFixedCone:5:Pt", "IsoFixedCone:5:PtPUsub",],
200  RhoKey = lambda jetdef, specs : "Kt4"+jetdef.inputdef.label+"EventShape" ,
201  prereqs= ["input:EventDensity"], #lambda spec,jetdef : ["input:Kt4"+jetdef.inputdef.label+"EventShape",],
202  ),
203 
204  jetisoTruth = JetModifier("JetIsolationTool","isoTruth",
205  JetContainer=_jetname,
206  InputConstitContainer = _constitContainername,
207  IsolationCalculations = ["IsoFixedCone:5:Pt", ],
208  RhoKey = "",
209  ),
210 
211 
212  )
213 except ModuleNotFoundError:
214  # In some releases (AthGeneration) JetMomentTools is not existing
215  pass
216 
217 # Truth labelling moments
218 from ParticleJetTools import ParticleJetToolsConfig
219 stdJetModifiers.update(
220  # Easy cases, no special config or prereqs, just default tool config
221  PartonTruthLabel = JetModifier("Analysis::JetPartonTruthLabel","partontruthlabel",
222  prereqs=["ghost:Partons"]),
223 
224  # More complex cases here
225  JetDeltaRLabel = JetModifier("ParticleJetDeltaRLabelTool","jetdrlabeler_jetptmin",
226  createfn=ParticleJetToolsConfig.getJetDeltaRLabelTool,
227  prereqs=["ghost:BHadronsFinal",
228  "ghost:CHadronsFinal",
229  "ghost:TausFinal"]
230  ),
231 
232 
233  JetGhostLabel = JetModifier("ParticleJetGhostLabelTool","jetghostlabeler",
234  createfn=ParticleJetToolsConfig.getJetGhostLabelTool,
235  prereqs=["ghost:BHadronsFinal",
236  "ghost:CHadronsFinal",
237  "ghost:TausFinal"]
238  ),
239 
240 
241  JetTaggingTruthLabel = JetModifier("JetTaggingTruthLabel", "truthlabeler_{mods}",
242  filterfn=isMC,
243  createfn=ParticleJetToolsConfig.getJetTruthLabelTool,
244  prereqs=lambda modspec,jetdef: ParticleJetToolsConfig.getJetTruthLabelToolPrereqs(jetdef, modspec),
245  ),
246 
247  JetPileupLabel = JetModifier("JetPileupLabel", "pileuplabeler_{mods}",
248  filterfn=isMC,
249  createfn=ParticleJetToolsConfig.getJetPileupLabelTool,
250  prereqs=["input:AntiKt4TruthDressedWZJets"]
251  ),
252 )
253 
254 
255 
256 # Substructure tools
257 stdJetModifiers.update(
258  nsubjettiness = JetModifier( "NSubjettinessTool", "nsubjettiness",Alpha = 1.0),
259  nsubjettinessR = JetModifier( "NSubjettinessRatiosTool", "nsubjettinessR",),
260 
261 
262  ktdr = JetModifier("KtDeltaRTool", "ktdr", JetRadius = 0.4),
263 
264  ktsplitter = JetModifier( "KTSplittingScaleTool", "ktsplitter"),
265 
266  angularity = JetModifier( "AngularityTool", "angularity"),
267 
268  dipolarity = JetModifier( "DipolarityTool", "dipolarity",SubJetRadius = 0.3),
269 
270  planarflow = JetModifier( "PlanarFlowTool", "planarflow"),
271 
272  ktmassdrop = JetModifier( "KtMassDropTool", "ktmassdrop"),
273 
274  ecorr = JetModifier( "EnergyCorrelatorTool", "ecorr", Beta = 1.0),
275  ecorrR = JetModifier( "EnergyCorrelatorRatiosTool", "ecorrR", ),
276 
277  ecorrgeneral = JetModifier( "EnergyCorrelatorGeneralizedTool", "ecorrgeneral", DoLSeries = True),
278  ecorrgeneralratios = JetModifier( "EnergyCorrelatorGeneralizedRatiosTool", "ecorrgeneralratios", DoLSeries = True),
279 
280  comshapes = JetModifier( "CenterOfMassShapesTool","comshapes"),
281 
282  pull = JetModifier("JetPullTool", "pull", UseEtaInsteadOfY = False, IncludeTensorMoments = True ),
283 
284  charge = JetModifier( "JetChargeTool", "charge", K=1.0),
285 
286  qw = JetModifier( "QwTool", "qw"),
287 
288  softdropobs = JetModifier("SoftDropObservablesTool", "softdropobs"),
289 
290 )
291 
292 # VR track-jet decorations
293 stdJetModifiers.update(
294  vr = JetModifier( "FlavorTagDiscriminants::VRJetOverlapDecoratorTool", "vr")
295 )
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParticleJetToolsConfig.getJetTruthLabelToolPrereqs
def getJetTruthLabelToolPrereqs(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:181
JetCalibToolsConfig.getJetCalibToolPrereqs
def getJetCalibToolPrereqs(modspec, jetdef)
Definition: JetCalibToolsConfig.py:202
python.StandardJetContext.inputsFromContext
def inputsFromContext(inputKey, prefix="", suffix="")
Definition: StandardJetContext.py:106
python.StandardJetMods.isMC
def isMC(flags)
Definition: StandardJetMods.py:78
python.StandardJetMods._constitContainername
def _constitContainername(jetdef, modspec)
Definition: StandardJetMods.py:85
python.Utilities.ldict
Definition: Utilities.py:139
python.JetDefinition.JetModifier
Definition: JetDefinition.py:248
python.StandardJetMods._jetname
def _jetname(jetdef, modspec)
Definition: StandardJetMods.py:75
Trk::split
@ split
Definition: LayerMaterialProperties.h:38