ATLAS Offline Software
Loading...
Searching...
No Matches
JetAnalysisConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3
4
5# AnaAlgorithm import(s):
6from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
7from AnalysisAlgorithmsConfig.ConfigSequence import groupBlocks
8from AnalysisAlgorithmsConfig.ConfigAccumulator import (
9 DataType, ConfigDeprecationWarning, JetUncertaintyWarning)
10from AthenaCommon.SystemOfUnits import GeV
11from AthenaConfiguration.Enums import LHCPeriod
12import re
13import warnings
14
15
16def _parseJetCollection(jetCollection):
17 """Parse a jet collection name into its components.
18
19 Returns (radius, jetInput, trim, hasBTag) where:
20 radius -- the jet radius parameter (2, 4, 6, or 10)
21 jetInput -- the input type string (e.g. 'EMPFlow', 'UFO', ...)
22 trim -- the trimming suffix string, or None
23 hasBTag -- whether the original collection name had a '_BTagging' suffix
24 """
25 hasBTag = False
26 btIndex = jetCollection.find('_BTagging')
27 if btIndex != -1:
28 jetCollection = jetCollection[:btIndex]
29 hasBTag = True
30
31 jetCollectionName = jetCollection
32 if jetCollection == "AnalysisJets":
33 jetCollectionName = "AntiKt4EMPFlowJets"
34 elif jetCollection == "AnalysisLargeRJets":
35 jetCollectionName = "AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets"
36
37 collection_pattern = re.compile(
38 r"AntiKt(\d+)(EMTopo|EMPFlow|LCTopo|TrackCaloCluster|UFO|Track|HI)"
39 r"(TrimmedPtFrac5SmallR20|CSSKSoftDropBeta100Zcut10)?Jets")
40 match = collection_pattern.match(jetCollectionName)
41 if not match:
42 raise ValueError(
43 "Jet collection {0} does not match expected pattern!".format(jetCollectionName))
44 radius = int(match.group(1))
45 if radius not in [2, 4, 6, 10]:
46 raise ValueError(
47 "Jet collection has unsupported radius '{0}'!".format(radius))
48 jetInput = match.group(2)
49 trim = match.group(3)
50 return radius, jetInput, trim, hasBTag
51
52
53class PreJetAnalysisConfig (ConfigBlock) :
54 """the ConfigBlock for the common preprocessing of jet sequences"""
55
56 def __init__ (self) :
57 super (PreJetAnalysisConfig, self).__init__ ()
58 self.addOption ('containerName', '', type=str,
59 noneAction='error',
60 info="the name of the output container after calibration.")
61 self.addOption ('jetCollection', '', type=str,
62 noneAction='error',
63 info="the jet container to run on. It is interpreted to determine "
64 "the correct config blocks to call for small- or large-R jets.")
65 self.addOption('outputTruthLabelIDs', False, type=bool,
66 info='enable or disable `HadronConeExclTruthLabelID` and `PartonTruthLabelID` decorations.')
67 self.addOption ('runOriginalObjectLink', False, type=bool,
68 info='sets up an instance of `CP::AsgOriginalObjectLinkAlg` to link systematically-varied containers to the base one.')
69 self.addOption ('runGhostMuonAssociation', None, type=bool,
70 info="whether to set up the jet-ghost-muon association algorithm "
71 "`CP::JetGhostMuonAssociationAlg`. If left empty, automatically defaults to `False` for PHYSLITE and `True` otherwise.")
72 self.addOption ('runTruthJetTagging', True, type=bool,
73 info="whether to set up the jet truth tagging algorithm "
74 "`CP::JetTruthTagAlg`.")
75
76 def instanceName (self) :
77 """Return the instance name for this block"""
78 return self.containerName
79
80 def makeAlgs (self, config) :
81
82
83 if config.isPhyslite() and self.jetCollection == 'AntiKt4EMPFlowJets' :
84 config.setSourceName (self.containerName, "AnalysisJets", originalName = self.jetCollection)
85 elif config.isPhyslite() and self.jetCollection == 'AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets' :
86 config.setSourceName (self.containerName, "AnalysisLargeRJets", originalName = self.jetCollection)
87 else :
88 config.setSourceName (self.containerName, self.jetCollection, originalName = self.jetCollection)
89
90 # Parse and store jet collection metadata for downstream blocks
91 radius, jetInput, trim, hasBTag = _parseJetCollection(self.jetCollection)
92 config.setContainerMeta(self.containerName, 'jetRadius', radius)
93 config.setContainerMeta(self.containerName, 'jetInput', jetInput)
94 config.setContainerMeta(self.containerName, 'jetTrim', trim)
95 config.setContainerMeta(self.containerName, 'hasBTag', hasBTag)
96
97 # Relink original jets in case of b-tagging calibration
98 if self.runOriginalObjectLink or hasBTag :
99 alg = config.createAlgorithm( 'CP::AsgOriginalObjectLinkAlg',
100 'JetOriginalObjectLinkAlg',
101 reentrant=True )
102 alg.baseContainerName = self.jetCollection
103 alg.particles = config.readName (self.containerName)
104 if config.wantCopy (self.containerName) :
105 alg.particlesOut = config.copyName (self.containerName)
106 alg.preselection = config.getPreselection (self.containerName, '')
107
108 # Set up the jet ghost muon association algorithm:
109 if (self.runGhostMuonAssociation is None and not config.isPhyslite()) or \
110 (self.runGhostMuonAssociation is True):
111 alg = config.createAlgorithm( 'CP::JetGhostMuonAssociationAlg',
112 'JetGhostMuonAssociationAlg' )
113 alg.jets = config.readName (self.containerName)
114 if config.isPhyslite():
115 alg.muons = "AnalysisMuons"
116 if config.wantCopy (self.containerName) :
117 alg.jetsOut = config.copyName (self.containerName)
118 taggerName = "GN2HLv01" if config.geometry() >= LHCPeriod.Run4 else "GN2v01"
119 extraInputs = [
120 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.DFCommonJets_jetClean_LooseBad".format(baseName=self.jetCollection)),
121 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.DFCommonJets_jetClean_TightBad".format(baseName=self.jetCollection)),
122 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.{tagger}_pb".format(baseName=self.jetCollection, tagger=taggerName)),
123 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.{tagger}_pc".format(baseName=self.jetCollection, tagger=taggerName)),
124 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.{tagger}_ptau".format(baseName=self.jetCollection, tagger=taggerName)),
125 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.{tagger}_pu".format(baseName=self.jetCollection, tagger=taggerName))]
126 config.setExtraInputs (extraInputs)
127
128 if self.runTruthJetTagging and config.dataType() is not DataType.Data:
129 # Decorate jets with isHS labels (required to retrieve Jvt SFs)
130 alg = config.createAlgorithm( 'CP::JetDecoratorAlg', 'JetPileupLabelAlg' )
131 config.addPrivateTool( 'decorator', 'JetPileupLabelingTool' )
132 alg.jets = config.readName (self.containerName)
133 alg.jetsOut = config.copyName (self.containerName)
134 alg.decorator.RecoJetContainer = alg.jetsOut.replace ('%SYS%', 'NOSYS')
135 alg.decorator.SuppressOutputDependence=True
136 if self.jetCollection == 'AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets' :
137 extraInputs = [
138 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.GN2Xv01_phbb".format(baseName= self.jetCollection)),
139 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.GN2Xv01_phcc".format(baseName= self.jetCollection)),
140 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.GN2Xv01_pqcd".format(baseName= self.jetCollection)),
141 ( 'xAOD::JetContainer' , "StoreGateSvc+{baseName}.GN2Xv01_ptop".format(baseName= self.jetCollection))]
142 config.setExtraInputs (extraInputs)
143
144 # Set up shallow copy if needed and not yet done
145 if config.wantCopy (self.containerName) :
146 alg = config.createAlgorithm( 'CP::AsgShallowCopyAlg', 'JetShallowCopyAlg' )
147 alg.input = config.readName (self.containerName)
148 alg.output = config.copyName (self.containerName)
149 alg.outputType = 'xAOD::JetContainer'
150 if self.jetCollection == 'AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets' :
151 alg.declareDecorations = ['GN2Xv01_phbb', 'GN2Xv01_phcc',
152 'GN2Xv01_pqcd', 'GN2Xv01_ptop']
153
154 config.addOutputVar (self.containerName, 'pt', 'pt')
155 config.addOutputVar (self.containerName, 'eta', 'eta', noSys=True)
156 config.addOutputVar (self.containerName, 'phi', 'phi', noSys=True)
157 config.addOutputVar (self.containerName, 'charge', 'charge', noSys=True, enabled=False)
158
159
160 if self.outputTruthLabelIDs and config.dataType() is not DataType.Data:
161 config.addOutputVar (self.containerName, 'HadronConeExclTruthLabelID', 'HadronConeExclTruthLabelID', noSys=True, auxType="int")
162 config.addOutputVar (self.containerName, 'PartonTruthLabelID', 'PartonTruthLabelID', noSys=True, auxType="int")
163
164
165
166class SmallRJetAnalysisConfig (ConfigBlock) :
167 """the ConfigBlock for the small-r jet sequence"""
168
169 def __init__ (self) :
170 super (SmallRJetAnalysisConfig, self).__init__ ()
171 self.addOption ('containerName', '', type=str,
172 noneAction='error',
173 info="the name of the output container after calibration.")
174 self.addOption ('jetCollection', '', type=str,
175 noneAction='error',
176 info="the jet container to run on. It is interpreted to determine "
177 "the correct config blocks to call for small- or large-R jets.")
178 self.addOption ('runJvtUpdate', False, type=bool,
179 info="whether to update the JVT.")
180 self.addOption ('runNNJvtUpdate', False, type=bool,
181 info="whether to update the NN-JVT.")
182 self.addOption ('runJvtSelection', True, type=bool,
183 info="whether to run JVT selection.")
184 self.addOption ('runFJvtSelection', False, type=bool,
185 info="whether to run forward JVT selection.")
186 self.addOption ('jvtWP', "FixedEffPt", type=str,
187 info="which Jvt WP to apply.")
188 self.addOption ('fJvtWP', "Loose", type=str,
189 info="which fJvt WP to apply.")
190 self.addOption ('runJvtEfficiency', True, type=bool,
191 info="whether to calculate the JVT efficiency.")
192 self.addOption ('runFJvtEfficiency', False, type=bool,
193 info="whether to calculate the forward JVT efficiency.")
194 self.addOption ('runUncertainties', True, type=bool,
195 info="whether to configure JetUncertaintiesTool.", expertMode=True)
196 self.addOption ('systematicsModelJES', "Category", type=str,
197 info="the NP reduction scheme to use for JES: All, Global, Category, "
198 "Scenario. The default is Category.")
199 self.addOption ('systematicsModelJER', "Full", type=str,
200 info="the NP reduction scheme to use for JER: All, Full, Simple. The "
201 "default is Full.")
202 self.addOption ('runJERsystematicsOnData', False, type=bool,
203 info="whether to run the All/Full JER model variations also on data samples. Expert option!",
204 expertMode=True)
205 self.addOption ('recalibratePhyslite', True, type=bool,
206 info="whether to run the `CP::JetCalibrationAlg` on PHYSLITE derivations.")
207 # Calibration tool options
208 self.addOption ('calibToolConfigFile', None, type=str,
209 info="the name of the config file to use for the jet calibration "
210 "tool. Expert option to override JetETmiss recommendations.",
211 expertMode=True)
212 self.addOption ('calibToolCalibArea', None, type=str,
213 info="name of the CVMFS area to use for the jet calibration "
214 "tool. Expert option to override JetETmiss recommendations.",
215 expertMode=True)
216 self.addOption ('calibToolCalibSeq', None, type=str,
217 info="name of the sequence to use for the jet calibration "
218 "tool (e.g. `JetArea_Residual_EtaJES_GSC`). Expert option to override "
219 "JetETmiss recommendations.",
220 expertMode=True)
221 # Uncertainties tool options
222 self.addOption ('uncertToolConfigPath', None, type=str,
223 info="name (str) of the config file to use for the jet uncertainty "
224 "tool. Expert option to override JetETmiss recommendations. The "
225 "default is None.",
226 expertMode=True)
227 self.addOption ('uncertToolCalibArea', None, type=str,
228 info="name (str) of the CVMFS area to use for the jet uncertainty "
229 "tool. Expert option to override JetETmiss recommendations. The "
230 "default is None.",
231 expertMode=True)
232 self.addOption ('uncertToolMCType', None, type=str,
233 info="data type (str) to use for the jet uncertainty tool (e.g. "
234 "'AF3' or 'MC16'). Expert option to override JetETmiss "
235 "recommendations. The default is None.",
236 expertMode=True)
237
238 def instanceName (self) :
239 """Return the instance name for this block"""
240 return self.containerName
241
242 def getUncertaintyToolSettings(self, config):
243
244 # Retrieve appropriate JES/JER recommendations for the JetUncertaintiesTool.
245 # We do this separately from the tool declaration, as we may need to set uo
246 # two such tools, but they have to be private.
247
248 jetInput = config.getContainerMeta(self.containerName, 'jetInput', failOnMiss=True)
249 # Config file:
250 config_file = None
251 if self.systematicsModelJES == "All" and self.systematicsModelJER == "All":
252 config_file = "R4_AllNuisanceParameters_AllJERNP.config"
253 elif "Scenario" in self.systematicsModelJES:
254 if self.systematicsModelJER != "Simple":
255 raise ValueError(
256 "Invalid uncertainty configuration - Scenario* systematicsModelJESs can "
257 "only be used together with the Simple systematicsModelJER")
258 config_file = "R4_{0}_SimpleJER.config".format(self.systematicsModelJES)
259 elif self.systematicsModelJES in ["Global", "Category"] and self.systematicsModelJER in ["Simple", "Full"]:
260 config_file = "R4_{0}Reduction_{1}JER.config".format(self.systematicsModelJES, self.systematicsModelJER)
261 else:
262 raise ValueError(
263 "Invalid combination of systematicsModelJES and systematicsModelJER settings: "
264 "systematicsModelJES: {0}, systematicsModelJER: {1}".format(self.systematicsModelJES, self.systematicsModelJER) )
265
266 # Calibration area:
267 calib_area = None
268 if self.uncertToolCalibArea is not None:
269 calib_area = self.uncertToolCalibArea
270
271 # Expert override for config path:
272 if self.uncertToolConfigPath is not None:
273 config_file = self.uncertToolConfigPath
274 else:
275 if config.geometry() is LHCPeriod.Run2:
276 if config.dataType() is DataType.FastSim:
277 config_file = "rel22/Fall2024_PreRec/" + config_file
278 else:
279 if jetInput == "HI":
280 config_file = "HIJetUncertainties/Spring2023/HI" + config_file
281 else:
282 config_file = "rel22/Summer2023_PreRec/" + config_file
283 else:
284 if config.dataType() is DataType.FastSim:
285 config_file = "rel22/Winter2025_AF3_PreRec/" + config_file
286 else:
287 if jetInput == "HI":
288 config_file = "HIJetUncertainties/Spring2023/HI" + config_file
289 else:
290 config_file = "rel22/Winter2025_PreRec/" + config_file
291
292 # MC type:
293 mc_type = None
294 if self.uncertToolMCType is not None:
295 mc_type = self.uncertToolMCType
296 else:
297 if config.geometry() is LHCPeriod.Run2:
298 if config.dataType() is DataType.FastSim:
299 mc_type = "AF3"
300 else:
301 mc_type = "MC20"
302 else:
303 if config.dataType() is DataType.FastSim:
304 mc_type = "MC23AF3"
305 else:
306 if jetInput == "HI":
307 mc_type = "MC16"
308 else:
309 mc_type = "MC23"
310
311 return config_file, calib_area, mc_type
312
313
314 def createUncertaintyTool(self, jetUncertaintiesAlg, config, jetCollectionName, doPseudoData=False):
315
316 # Create an instance of JetUncertaintiesTool, following JetETmiss recommendations.
317 # To run Jet Energy Resolution (JER) uncertainties in the "Full" or "All" schemes,
318 # we need two sets of tools: one configured as normal (MC), the other with the
319 # exact same settings but pretending to run on data (pseudo-data).
320 # This is achieved by passing "isPseudoData=True" to the arguments.
321
322 # Retrieve the common configuration settings
323 configFile, calibArea, mcType = self.getUncertaintyToolSettings(config)
324
325 # The main tool for all JES+JER combinations
326 config.addPrivateTool( 'uncertaintiesTool', 'JetUncertaintiesTool' )
327 jetUncertaintiesAlg.uncertaintiesTool.JetDefinition = jetCollectionName[:-4]
328 jetUncertaintiesAlg.uncertaintiesTool.ConfigFile = configFile
329 if calibArea is not None:
330 jetUncertaintiesAlg.uncertaintiesTool.CalibArea = calibArea
331 jetUncertaintiesAlg.uncertaintiesTool.MCType = mcType
332 jetUncertaintiesAlg.uncertaintiesTool.IsData = (config.dataType() is DataType.Data)
333 jetUncertaintiesAlg.uncertaintiesTool.PseudoDataJERsmearingMode = False
334
335 if config.dataType() is DataType.Data and not (doPseudoData and self.runJERsystematicsOnData):
336 # we don't want any systematics on data if we're not using the right JER model!
337 jetUncertaintiesAlg.affectingSystematicsFilter = '.*'
338 if config.dataType() is not DataType.Data and doPseudoData and not self.runJERsystematicsOnData:
339 # The secondary tool for pseudo-data JER smearing
340 config.addPrivateTool( 'uncertaintiesToolPD', 'JetUncertaintiesTool' )
341 jetUncertaintiesAlg.uncertaintiesToolPD.JetDefinition = jetCollectionName[:-4]
342 jetUncertaintiesAlg.uncertaintiesToolPD.ConfigFile = configFile
343 if calibArea is not None:
344 jetUncertaintiesAlg.uncertaintiesToolPD.CalibArea = calibArea
345 jetUncertaintiesAlg.uncertaintiesToolPD.MCType = mcType
346
347 # This is the part that is different!
348 jetUncertaintiesAlg.uncertaintiesToolPD.IsData = True
349 jetUncertaintiesAlg.uncertaintiesToolPD.PseudoDataJERsmearingMode = True
350
351
352 def makeAlgs (self, config) :
353
354 # Self-select: only run for radius-4 jets
355 if config.getContainerMeta(self.containerName, 'jetRadius', failOnMiss=True) != 4:
356 return
357
358
359 jetCollectionName=self.jetCollection
360 if(self.jetCollection=="AnalysisJets") :
361 jetCollectionName="AntiKt4EMPFlowJets"
362 if(self.jetCollection=="AnalysisLargeRJets") :
363 jetCollectionName="AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets"
364
365 jetInput = config.getContainerMeta(self.containerName, 'jetInput', failOnMiss=True)
366
367 if jetInput not in ["EMTopo", "EMPFlow", "HI"]:
368 raise ValueError(
369 "Unsupported input type '{0}' for R=0.4 jets!".format(jetInput) )
370
371 if self.jvtWP not in ["FixedEffPt"]:
372 raise ValueError(
373 "Unsupported NNJvt WP '{0}'".format(self.jvtWP) )
374
375 if self.fJvtWP not in ["Loose", "Tight", "Tighter"]:
376 raise ValueError(
377 "Unsupported fJvt WP '{0}'".format(self.fJvtWP) )
378
379 if not config.isPhyslite() or self.recalibratePhyslite:
380 # Create calibration tool as public so it can be shared
381 # (e.g. with FTAG1LITE's JetCalibratedPtDecoratorAlg).
382 # Must be created before the algorithm so EventLoop
383 # initialises the tool first.
384 calibToolName = 'JetCalibTool_' + jetCollectionName[:-4]
385 calibTool = config.createPublicTool( 'JetCalibrationTool', calibToolName )
386 calibTool.JetCollection = jetCollectionName[:-4]
387 # Get the correct string to use in the config file name
388 if jetInput == "EMPFlow":
389 if config.geometry() is LHCPeriod.Run2:
390 configFile = "PreRec_R22_PFlow_ResPU_EtaJES_GSC_February23_230215.config"
391 calibTool.CalibArea = "00-04-82"
392 elif config.geometry() >= LHCPeriod.Run3:
393 configFile = "AntiKt4EMPFlow_MC23a_PreRecR22_Phase2_CalibConfig_ResPU_EtaJES_GSC_241208_InSitu.config"
394 calibTool.CalibArea = "00-04-83"
395 elif jetInput == "HI":
396 if config.geometry() is LHCPeriod.Run2:
397 configFile = "JES_MC16_HI_Jan2021_5TeV.config"
398 if config.geometry() is LHCPeriod.Run3:
399 configFile = "AntiKt4HI_MC23_EtaJES_Run3PreRec_Run2VJet_Run3EtaInt_5p36TeV.config"
400 calibTool.CalibArea = "00-04-83"
401 else:
402 if config.dataType() is DataType.FastSim:
403 configFile = "JES_MC16Recommendation_AFII_{0}_Apr2019_Rel21.config"
404 else:
405 configFile = "JES_MC16Recommendation_Consolidated_{0}_Apr2019_Rel21.config"
406 configFile = configFile.format(jetInput)
407 if self.calibToolCalibArea is not None:
408 calibTool.CalibArea = self.calibToolCalibArea
409 if self.calibToolConfigFile is not None:
410 configFile = self.calibToolConfigFile
411 calibTool.ConfigFile = configFile
412 if config.dataType() is DataType.Data:
413 if jetInput == "HI":
414 calibTool.CalibSequence = 'EtaJES_Insitu'
415 else:
416 calibTool.CalibSequence = 'JetArea_Residual_EtaJES_GSC_Insitu'
417 else:
418 if jetInput == "EMPFlow":
419 calibTool.CalibSequence = 'JetArea_Residual_EtaJES_GSC'
420 elif jetInput == "HI":
421 calibTool.CalibSequence = 'EtaJES'
422 else:
423 calibTool.CalibSequence = 'JetArea_Residual_EtaJES_GSC_Smear'
424 if self.calibToolCalibSeq is not None:
425 calibTool.CalibSequence = self.calibToolCalibSeq
426 calibTool.IsData = (config.dataType() is DataType.Data)
427 # Prepare the jet calibration algorithm
428 alg = config.createAlgorithm( 'CP::JetCalibrationAlg', 'JetCalibrationAlg' )
429 alg.HIsetup = jetInput == "HI"
430 alg.calibrationTool = f'{calibTool.getType()}/{calibTool.getName()}'
431 alg.jets = config.readName (self.containerName)
432 alg.jetsOut = config.copyName (self.containerName)
433
434
435 if (config.dataType() is not DataType.Data):
436 alg = config.createAlgorithm( 'CP::JetPartonTruthLabelAlg',
437 'JetPartonTruthLabelAlg' )
438 config.addPrivateTool( 'LabelTool', 'Analysis::JetPartonTruthLabel' )
439 alg.jets = config.readName (self.containerName)
440
441 # Jet uncertainties
443 alg = config.createAlgorithm( 'CP::JetUncertaintiesAlg', 'JetUncertaintiesAlg' )
444 self.createUncertaintyTool(alg, config, jetCollectionName, doPseudoData=( self.systematicsModelJER in ["Full","All"] ))
445 alg.jets = config.readName (self.containerName)
446 alg.jetsOut = config.copyName (self.containerName)
447 alg.preselection = config.getPreselection (self.containerName, '')
448
449 # Set up the JVT update algorithm:
450 if self.runJvtUpdate :
451 alg = config.createAlgorithm( 'CP::JvtUpdateAlg', 'JvtUpdateAlg' )
452 config.addPrivateTool( 'jvtTool', 'JetVertexTaggerTool' )
453 alg.jvtTool.JetContainer = self.jetCollection
454 alg.jvtTool.SuppressInputDependence=True
455 alg.jets = config.readName (self.containerName)
456 alg.jetsOut = config.copyName (self.containerName)
457 alg.preselection = config.getPreselection (self.containerName, '')
458
460 assert jetInput=="EMPFlow", "NN JVT only defined for PFlow jets"
461 alg = config.createAlgorithm( 'CP::JetDecoratorAlg', 'NNJvtUpdateAlg' )
462 config.addPrivateTool( 'decorator', 'JetPileupTag::JetVertexNNTagger' )
463 alg.jets = config.readName (self.containerName)
464 alg.jetsOut = config.copyName (self.containerName)
465 # Set this actually to the *output* collection
466 alg.decorator.JetContainer = alg.jetsOut.replace ('%SYS%', 'NOSYS')
467 alg.decorator.SuppressInputDependence=True
468 alg.decorator.SuppressOutputDependence=True
469
470 # Set up the jet efficiency scale factor calculation algorithm
471 # Change the truthJetCollection property to AntiKt4TruthWZJets if preferred
473 assert jetInput=="EMPFlow", "NNJvt WPs and SFs only valid for PFlow jets"
474 warnings.warn_explicit(
475 "jvtWP, runJvtSelection and runJvtEfficiency"
476 " are deprecated - please use a"
477 " JVTWorkingPoint block instead.",
478 ConfigDeprecationWarning, filename='', lineno=0)
479
480 alg = config.createAlgorithm('CP::AsgSelectionAlg', 'JvtSelectionAlg')
481 config.addPrivateTool('selectionTool', 'CP::NNJvtSelectionTool')
482 alg.selectionTool.JetContainer = config.readName(self.containerName)
483 alg.selectionTool.JvtMomentName = "NNJvt"
484 alg.selectionTool.WorkingPoint = self.jvtWP
485 alg.selectionTool.MaxPtForJvt = 60*GeV
486 alg.selectionDecoration = "jvt_selection,as_char"
487 alg.particles = config.readName(self.containerName)
488
489 if self.runJvtEfficiency and config.dataType() is not DataType.Data:
490 alg = config.createAlgorithm( 'CP::JvtEfficiencyAlg', 'JvtEfficiencyAlg' )
491 config.addPrivateTool( 'efficiencyTool', 'CP::NNJvtEfficiencyTool' )
492 alg.efficiencyTool.JetContainer = config.readName(self.containerName)
493 alg.efficiencyTool.MaxPtForJvt = 60*GeV
494 alg.efficiencyTool.WorkingPoint = self.jvtWP
495 if config.geometry() is LHCPeriod.Run2:
496 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/NNJvtSFFile_Run2_EMPFlow.root"
497 else:
498 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/NNJvtSFFile_Run3_EMPFlow.root"
499 alg.selection = 'jvt_selection,as_char'
500 alg.scaleFactorDecoration = 'jvt_effSF_%SYS%'
501 alg.outOfValidity = 2
502 alg.outOfValidityDeco = 'no_jvt'
503 alg.skipBadEfficiency = False
504 alg.jets = config.readName (self.containerName)
505 alg.preselection = config.getPreselection (self.containerName, '')
506 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, 'jvtEfficiency')
507 config.addSelection (self.containerName, 'baselineJvt', 'jvt_selection,as_char', preselection=False)
508
510 assert jetInput=="EMPFlow", "fJvt WPs and SFs only valid for PFlow jets"
511 warnings.warn_explicit(
512 "fJvtWP, runFJvtSelection and runFJvtEfficiency"
513 " are deprecated - please use a"
514 " FJVTWorkingPoint block instead.",
515 ConfigDeprecationWarning, filename='', lineno=0)
516
517 alg = config.createAlgorithm('CP::AsgSelectionAlg', 'FJvtSelectionAlg')
518 config.addPrivateTool('selectionTool', 'CP::FJvtSelectionTool')
519 alg.selectionTool.JetContainer = config.readName(self.containerName)
520 alg.selectionTool.JvtMomentName = "DFCommonJets_fJvt"
521 alg.selectionTool.WorkingPoint = self.fJvtWP
522 alg.selectionDecoration = "fjvt_selection,as_char"
523 alg.particles = config.readName(self.containerName)
524
525 if self.runFJvtEfficiency and config.dataType() is not DataType.Data:
526 alg = config.createAlgorithm( 'CP::JvtEfficiencyAlg', 'FJvtEfficiencyAlg' )
527 config.addPrivateTool( 'efficiencyTool', 'CP::FJvtEfficiencyTool' )
528 alg.efficiencyTool.JetContainer = config.readName(self.containerName)
529 alg.efficiencyTool.WorkingPoint = self.fJvtWP
530 if config.geometry() is LHCPeriod.Run2:
531 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/fJvtSFFile_Run2_EMPFlow.root"
532 else:
533 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/fJvtSFFile_Run3_EMPFlow.root"
534 alg.selection = 'fjvt_selection,as_char'
535 alg.scaleFactorDecoration = 'fjvt_effSF_%SYS%'
536 alg.outOfValidity = 2
537 alg.outOfValidityDeco = 'no_fjvt'
538 alg.skipBadEfficiency = False
539 alg.jets = config.readName (self.containerName)
540 alg.preselection = config.getPreselection (self.containerName, '')
541 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, 'fjvtEfficiency')
542 config.addSelection (self.containerName, 'baselineFJvt', 'fjvt_selection,as_char', preselection=False)
543
544 # Additional decorations
545 alg = config.createAlgorithm( 'CP::AsgEnergyDecoratorAlg', 'AsgEnergyDecoratorAlg' )
546 alg.particles = config.readName (self.containerName)
547
548 config.addOutputVar (self.containerName, 'e_%SYS%', 'e')
549
550
551class RScanJetAnalysisConfig (ConfigBlock) :
552 """the ConfigBlock for the r-scan jet sequence"""
553
554 def __init__ (self) :
555 super (RScanJetAnalysisConfig, self).__init__ ()
556 self.addOption ('containerName', '', type=str,
557 noneAction='error',
558 info="the name of the output container after calibration.")
559 self.addOption ('jetCollection', '', type=str,
560 noneAction='error',
561 info="the jet container to run on. It is interpreted to determine "
562 "the correct config blocks to call for small- or large-R jets.")
563 self.addOption ('recalibratePhyslite', True, type=bool,
564 info="whether to run the CP::JetCalibrationAlg on PHYSLITE "
565 "derivations. The default is True.")
566
567 def instanceName (self) :
568 """Return the instance name for this block"""
569 return self.containerName
570
571 def makeAlgs (self, config) :
572
573 # Self-select: only run for r-scan jets (radius 2 or 6)
574 radius = config.getContainerMeta(self.containerName, 'jetRadius', failOnMiss=True)
575 if radius not in [2, 6]:
576 return
577
578 jetCollectionName=self.jetCollection
579 if(self.jetCollection=="AnalysisJets") :
580 jetCollectionName="AntiKt4EMPFlowJets"
581 if(self.jetCollection=="AnalysisLargeRJets") :
582 jetCollectionName="AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets"
583
584 jetInput = config.getContainerMeta(self.containerName, 'jetInput', failOnMiss=True)
585
586 if not config.isPhyslite() or self.recalibratePhyslite:
587 if jetInput not in ["LCTopo", "HI"]:
588 raise ValueError(
589 "Unsupported input type '{0}' for R-scan jets!".format(jetInput) )
590 # Create calibration tool before algorithm (EventLoop ordering)
591 calibToolName = 'JetCalibTool_' + jetCollectionName[:-4]
592 calibTool = config.createPublicTool( 'JetCalibrationTool', calibToolName )
593 calibTool.JetCollection = jetCollectionName[:-4]
594 if jetInput=="LCTopo":
595 calibTool.ConfigFile = \
596 "JES_MC16Recommendation_Rscan{0}LC_Feb2022_R21.config".format(radius)
597 if config.dataType() is DataType.Data:
598 calibTool.CalibSequence = "JetArea_Residual_EtaJES_GSC_Insitu"
599 else:
600 calibTool.CalibSequence = "JetArea_Residual_EtaJES_GSC_Smear"
601 elif jetInput=="HI":
602 calibTool.ConfigFile = \
603 "JES_MC16_HI_Jan2021_5TeV.config"
604 if config.dataType() is DataType.Data:
605 calibTool.CalibSequence = "EtaJES_Insitu"
606 else:
607 calibTool.CalibSequence = "EtaJES"
608 calibTool.IsData = (config.dataType() is DataType.Data)
609 # Prepare the jet calibration algorithm
610 alg = config.createAlgorithm( 'CP::JetCalibrationAlg', 'JetCalibrationAlg' )
611 alg.HIsetup = jetInput == "HI"
612 alg.calibrationTool = f'{calibTool.getType()}/{calibTool.getName()}'
613 alg.jets = config.readName (self.containerName)
614 warnings.warn_explicit(
615 "Uncertainties for R-Scan jets are not yet released!",
616 JetUncertaintyWarning, filename='', lineno=0)
617
618
619class LargeRJetAnalysisConfig (ConfigBlock) :
620 """the ConfigBlock for the large-r jet sequence"""
621
622 def __init__ (self) :
623 super (LargeRJetAnalysisConfig, self).__init__ ()
624 self.addOption ('containerName', '', type=str,
625 noneAction='error',
626 info="the name of the output container after calibration.")
627 self.addOption ('jetCollection', '', type=str,
628 noneAction='error',
629 info="the jet container to run on. It is interpreted to determine "
630 "the correct config blocks to call for small- or large-R jets.")
631 self.addOption ('jetInput', '', type=str,
632 noneAction='error',
633 info="the type of jet input. Supported options are: `UFO`.")
634 self.addOption ('recalibratePhyslite', True, type=bool,
635 info="whether to run the CP::JetCalibrationAlg on PHYSLITE "
636 "derivations. The default is True.")
637 self.addOption ('runUncertainties', True, type=bool,
638 info="whether to configure JetUncertaintiesTool.", expertMode=True )
639 self.addOption ('systematicsModelJER', "Full", type=str)
640 self.addOption ('systematicsModelJMS', "Full", type=str)
641 self.addOption ('systematicsModelJMR', "Full", type=str,
642 info="the NP reduction scheme to use for JMR: Full, Simple. The default is Full.")
643 self.addOption ('runJERsystematicsOnData', False, type=bool,
644 info="whether to run the All/Full JER model variations also on data samples. Expert option!",
645 expertMode=True)
646 # Adding these options to override the jet uncertainty config file when we have new recommendations
647 # Calibration tool options
648 self.addOption ('calibToolConfigFile', None, type=str,
649 info="name of the config file to use for the jet calibration "
650 "tool. Expert option to override JetETmiss recommendations.",
651 expertMode=True)
652 self.addOption ('calibToolCalibArea', None, type=str,
653 info="name of the CVMFS area to use for the jet calibration "
654 "tool. Expert option to override JetETmiss recommendations.",
655 expertMode=True)
656 self.addOption ('calibToolCalibSeq', None, type=str,
657 info="name of the sequence to use for the jet calibration "
658 "tool (e.g. `JetArea_Residual_EtaJES_GSC`). Expert option to override "
659 "JetETmiss recommendations.",
660 expertMode=True)
661 # Uncertainties tool options
662 self.addOption ('uncertToolConfigPath', None, type=str,
663 info="name of the config file to use for the JES, JER, and JMS uncertainty "
664 "tool. Expert option to override JetETmiss recommendations.",
665 expertMode=True)
666 self.addOption ('uncertToolConfigPathJMR', None, type=str,
667 info="name of the config file to use for the JMR uncertainty "
668 "tool. Expert option to override JetETmiss recommendations.",
669 expertMode=True)
670 self.addOption ('uncertToolCalibArea', None, type=str,
671 info="name (str) of the CVMFS area to use for the jet uncertainty "
672 "tool. Expert option to override JetETmiss recommendations. The "
673 "default is None.",
674 expertMode=True)
675 self.addOption ('uncertToolMCType', None, type=str,
676 info="data type (str) to use for the jet uncertainty tool (e.g. "
677 "'AF3' or 'MC16'). Expert option to override JetETmiss "
678 "recommendations. The default is None.",
679 expertMode=True)
680 self.addOption ('minPt', 200.*GeV, type=float,
681 info=r"the minimum $p_\mathrm{T}$ cut (in MeV) to apply to calibrated large-R jets.")
682 self.addOption ('maxPt', 3000.*GeV, type=float,
683 info=r"the maximum $p_\mathrm{T}$ cut (in MeV) to apply to calibrated large-R jets.")
684 self.addOption ('maxEta', 0., type=float,
685 info=r"the maximum $\vert\eta\vert$ cut to apply to calibrated large-R jets.")
686 self.addOption ('maxRapidity', 2., type=float,
687 info="the maximum rapidity cut to apply to calibrated large-R jets.")
688 self.addOption ('minMass', 40.*GeV, type=float,
689 info="the minimum mass cut (in MeV) to apply to calibrated large-R jets.")
690 self.addOption ('maxMass', 600.*GeV, type=float,
691 info="the maximum mass cut (in MeV) to apply to calibrated large-R jets.")
692
693 def instanceName (self) :
694 """Return the instance name for this block"""
695 return self.containerName
696
697 def getUncertaintyToolSettings(self, config):
698 # Retrieve appropriate JES/JER recommendations for the JetUncertaintiesTool.
699 # We do this separately from the tool declaration, as we may need to set uo
700 # two such tools, but they have to be private.
701
702
703 # Config file:
704 config_file = None
705 if self.systematicsModelJER in ["Simple", "Full"] and self.systematicsModelJMS in ["Simple", "Full"]:
706 config_file = "R10_CategoryJES_{0}JER_{1}JMS.config".format(self.systematicsModelJER, self.systematicsModelJMS)
707 else:
708 raise ValueError(
709 "Invalid request for systematicsModelJER/JMS settings: "
710 "systematicsModelJER = '{0}', "
711 "systematicsModelJMS = '{1}'".format(self.systematicsModelJER, self.systematicsModelJMS) )
712 if self.uncertToolConfigPath is not None:
713 # Expert override
714 config_file = self.uncertToolConfigPath
715 else:
716 if config.geometry() in [LHCPeriod.Run2, LHCPeriod.Run3]:
717 config_file = "rel22/Summer2025_PreRec/" + config_file
718 else:
719 warnings.warn_explicit(
720 "Uncertainties for UFO jets are not for Run 4!"
721 " are deprecated - please use a"
722 " JVTWorkingPoint block instead.",
723 JetUncertaintyWarning, filename='', lineno=0)
724
725
726 # Calibration area:
727 calib_area = None
728 if self.uncertToolCalibArea is not None:
729 calib_area = self.uncertToolCalibArea
730
731 # MC type:
732 if self.uncertToolMCType is not None:
733 mc_type = self.uncertToolMCType
734 else:
735 if config.dataType() is DataType.FastSim:
736 if config.geometry() is LHCPeriod.Run2:
737 mc_type = "MC20AF3"
738 else:
739 mc_type = "MC23AF3"
740 else:
741 if config.geometry() is LHCPeriod.Run2:
742 mc_type = "MC20"
743 else:
744 mc_type = "MC23"
745
746 return config_file, calib_area, mc_type
747
748 def createUncertaintyTool(self, jetUncertaintiesAlg, config, jetCollectionName, doPseudoData=False):
749 '''
750 Create instance(s) of JetUncertaintiesTool following JetETmiss recommendations.
751
752 JER uncertainties under the "Full" scheme must be run on MC samples twice:
753 1. Normal (MC) mode,
754 2. Pseudodata (PD) mode, as if the events are Data.
755 '''
756
757 # Retrieve the common configuration settings
758 configFile, calibArea, mcType = self.getUncertaintyToolSettings(config)
759
760 # The main tool for all JER combinations
761 config.addPrivateTool( 'uncertaintiesTool', 'JetUncertaintiesTool' )
762 jetUncertaintiesAlg.uncertaintiesTool.JetDefinition = jetCollectionName[:-4]
763 jetUncertaintiesAlg.uncertaintiesTool.ConfigFile = configFile
764 if calibArea is not None:
765 jetUncertaintiesAlg.uncertaintiesTool.CalibArea = calibArea
766 jetUncertaintiesAlg.uncertaintiesTool.MCType = mcType
767 jetUncertaintiesAlg.uncertaintiesTool.IsData = (config.dataType() is DataType.Data)
768 jetUncertaintiesAlg.uncertaintiesTool.PseudoDataJERsmearingMode = False
769
770 # JER smearing on data
771 if config.dataType() is DataType.Data and not (config.isPhyslite() and doPseudoData and self.runJERsystematicsOnData):
772 # we don't want any systematics on data if we're not using the right JER model!
773 jetUncertaintiesAlg.affectingSystematicsFilter = '.*'
774
775 if config.dataType() is not (DataType.Data and config.isPhyslite()) and doPseudoData and not self.runJERsystematicsOnData:
776 # The secondary tool for pseudo-data JER smearing
777 config.addPrivateTool( 'uncertaintiesToolPD', 'JetUncertaintiesTool' )
778 jetUncertaintiesAlg.uncertaintiesToolPD.JetDefinition = jetCollectionName[:-4]
779 jetUncertaintiesAlg.uncertaintiesToolPD.ConfigFile = configFile
780 if calibArea is not None:
781 jetUncertaintiesAlg.uncertaintiesToolPD.CalibArea = calibArea
782 jetUncertaintiesAlg.uncertaintiesToolPD.MCType = mcType
783 jetUncertaintiesAlg.uncertaintiesToolPD.IsData = True
784 jetUncertaintiesAlg.uncertaintiesToolPD.PseudoDataJERsmearingMode = True
785
786 def createFFSmearingTool(self, jetFFSmearingAlg, config):
787 # Retrieve appropriate large-R jet mass resolution recommendations for the FFJetSmearingTool.
788
789 # Config file:
790 if self.systematicsModelJMR in ["Simple", "Full"]:
791 config_file = f"R10_{self.systematicsModelJMR}JMR.config"
792 else:
793 raise ValueError(
794 f"Invalid request for systematicsModelJMR settings: {self.systematicsModelJMR}"
795 )
796
797 # Expert override for config path:
798 if self.uncertToolConfigPathJMR is not None:
799 config_file = self.uncertToolConfigPathJMR
800 else:
801 config_file = "rel22/Summer2025_PreRec/" + config_file
802 if config.geometry() is LHCPeriod.Run4:
803 warnings.warn_explicit(
804 "Uncertainties for UFO jets are not for Run 4!",
805 JetUncertaintyWarning, filename='', lineno=0)
806
807 # MC type:
808 if config.geometry() is LHCPeriod.Run2:
809 if config.dataType() is DataType.FastSim:
810 mc_type = "MC20AF3"
811 else:
812 mc_type = "MC20"
813 elif config.geometry() >= LHCPeriod.Run3:
814 if config.dataType() is DataType.FastSim:
815 mc_type = "MC23AF3"
816 else:
817 mc_type = "MC23"
818
819 # Set up the FF smearing tool
820 config.addPrivateTool( 'FFSmearingTool', 'CP::FFJetSmearingTool')
821 jetFFSmearingAlg.FFSmearingTool.MassDef = "UFO"
822 jetFFSmearingAlg.FFSmearingTool.MCType = mc_type
823 jetFFSmearingAlg.FFSmearingTool.ConfigFile = config_file
824
825 def makeAlgs (self, config) :
826
827 # Self-select: only run for large-R (radius 10) jets
828 if config.getContainerMeta(self.containerName, 'jetRadius', failOnMiss=True) != 10:
829 return
830
831 configFile = None
832 calibSeq = None
833 calibArea = None
834
835 jetCollectionName=self.jetCollection
836 if(self.jetCollection=="AnalysisJets") :
837 jetCollectionName="AntiKt4EMPFlowJets"
838 if(self.jetCollection=="AnalysisLargeRJets") :
839 jetCollectionName="AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets"
840
841 jetInput = config.getContainerMeta(self.containerName, 'jetInput', failOnMiss=True)
842 trim = config.getContainerMeta(self.containerName, 'jetTrim', failOnMiss=True)
843
844 if jetInput not in ["UFO"]:
845 raise ValueError("Invalid input type '{0}' for large-R jets!".format(jetInput) )
846
847 if not trim:
848 raise ValueError("Untrimmed large-R jets are not supported!")
849
850 configFile = "JES_MC20PreRecommendation_R10_UFO_CSSK_SoftDrop_JMS_R21Insitu_26Nov2024.config"
851 calibArea = "00-04-83"
852 if self.calibToolConfigFile is not None:
853 configFile = self.calibToolConfigFile
854
855 if config.dataType() is not DataType.Data:
856 calibSeq = "EtaJES_JMS"
857 elif config.dataType() is DataType.Data:
858 calibSeq = "EtaJES_JMS_Insitu"
859 if self.calibToolCalibSeq is not None:
860 calibSeq = self.calibToolCalibSeq
861
862 if self.calibToolCalibArea is not None:
863 calibArea = self.calibToolCalibArea
864
865 if not config.isPhyslite() or self.recalibratePhyslite:
866 # Create calibration tool before algorithm (EventLoop ordering)
867 calibToolName = 'JetCalibTool_' + jetCollectionName[:-4]
868 calibTool = config.createPublicTool( 'JetCalibrationTool', calibToolName )
869
870 calibTool.JetCollection = jetCollectionName[:-4]
871
872 if configFile is None:
873 raise ValueError(f'Unsupported: {jetInput=}, {config.dataType()=}')
874 calibTool.ConfigFile = configFile
875
876 if calibSeq is None:
877 raise ValueError(f'Unsupported: {jetInput=}, {config.dataType()=}')
878 calibTool.CalibSequence = calibSeq
879
880 if calibArea is not None:
881 calibTool.CalibArea = calibArea
882
883 calibTool.IsData = (config.dataType() is DataType.Data)
884 # Prepare the jet calibration algorithm
885 alg = config.createAlgorithm( 'CP::JetCalibrationAlg', 'JetCalibrationAlg' )
886 alg.calibrationTool = f'{calibTool.getType()}/{calibTool.getName()}'
887 alg.jets = config.readName(self.containerName)
888 alg.jetsOut = config.copyName(self.containerName)
889
890 if (config.dataType() is not DataType.Data):
891 alg = config.createAlgorithm( 'CP::JetPartonTruthLabelAlg',
892 'JetPartonTruthLabelAlg' )
893 config.addPrivateTool( 'LabelTool', 'Analysis::JetPartonTruthLabel' )
894 alg.jets = config.readName (self.containerName)
895
896 # Jet uncertainties
897 if jetInput == "UFO" and config.dataType() in [DataType.FullSim, DataType.FastSim] and self.runUncertainties:
898 alg = config.createAlgorithm( 'CP::JetUncertaintiesAlg', 'JetUncertaintiesAlg' )
899 self.createUncertaintyTool(alg, config, jetCollectionName, doPseudoData=( self.systematicsModelJER in ["Full","All"] ))
900
901 alg.uncertaintiesTool.JetDefinition = jetCollectionName[:-4]
902
903 # R=1.0 jets have a validity range
904 alg.outOfValidity = 2 # SILENT
905 alg.outOfValidityDeco = 'outOfValidity'
906
907 alg.jets = config.readName (self.containerName)
908 alg.jetsOut = config.copyName (self.containerName)
909 alg.preselection = config.getPreselection (self.containerName, '')
910
911 if jetInput != "UFO" and self.runUncertainties:
912 alg = config.createAlgorithm( 'CP::JetUncertaintiesAlg', 'JetUncertaintiesAlg' )
913
914 # R=1.0 jets have a validity range
915 alg.outOfValidity = 2 # SILENT
916 alg.outOfValidityDeco = 'outOfValidity'
917 config.addPrivateTool( 'uncertaintiesTool', 'JetUncertaintiesTool' )
918
919 alg.uncertaintiesTool.JetDefinition = jetCollectionName[:-4]
920 alg.uncertaintiesTool.ConfigFile = \
921 "rel21/Moriond2018/R10_{0}Mass_all.config".format(self.largeRMass)
922 alg.uncertaintiesTool.MCType = "MC16a"
923 alg.uncertaintiesTool.IsData = (config.dataType() is DataType.Data)
924
925 alg.jets = config.readName (self.containerName)
926 alg.jetsOut = config.copyName (self.containerName)
927 alg.preselection = config.getPreselection (self.containerName, '')
928 config.addSelection (self.containerName, '', 'outOfValidity')
929
930 if jetInput == "UFO" and config.dataType() is not DataType.Data:
931 # set up the FF smearing algorithm
932 alg = config.createAlgorithm( 'CP::JetFFSmearingAlg', 'JetFFSmearingAlg' )
933 self.createFFSmearingTool(alg, config)
934 alg.outOfValidity = 2 # SILENT
935 alg.outOfValidityDeco = 'outOfValidityJMR'
936 alg.jets = config.readName (self.containerName)
937 alg.jetsOut = config.copyName (self.containerName)
938 alg.preselection = config.getPreselection (self.containerName, '')
939
940 if self.minPt > 0 or self.maxPt > 0 or self.maxEta > 0 or self.maxRapidity > 0:
941 # Set up the the pt-eta selection
942 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'JetPtEtaCutAlg' )
943 alg.selectionDecoration = 'selectPtEta,as_bits'
944 config.addPrivateTool( 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
945 alg.selectionTool.minPt = self.minPt
946 alg.selectionTool.maxPt = self.maxPt
947 alg.selectionTool.maxEta = self.maxEta
948 alg.selectionTool.maxRapidity = self.maxRapidity
949 alg.particles = config.readName (self.containerName)
950 alg.preselection = config.getPreselection (self.containerName, '')
951 config.addSelection (self.containerName, '', alg.selectionDecoration,
952 preselection=True)
953
954 if self.minMass > 0 or self.maxMass > 0:
955 # Set up the the mass selection
956 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'JetMassCutAlg' )
957 alg.selectionDecoration = 'selectMass,as_bits'
958 config.addPrivateTool( 'selectionTool', 'CP::AsgMassSelectionTool' )
959 alg.selectionTool.minM = self.minMass
960 alg.selectionTool.maxM = self.maxMass
961 alg.particles = config.readName (self.containerName)
962 alg.preselection = config.getPreselection (self.containerName, '')
963 config.addSelection (self.containerName, '', alg.selectionDecoration,
964 preselection=True)
965
966 config.addOutputVar (self.containerName, 'm', 'm')
967
969 """the ConfigBlock for the Jvt working point selection"""
970
971 def __init__ (self) :
972 super (JvtWorkingPointSelectionConfig, self).__init__ ()
973 self.setBlockName('JvtWorkingPointSelectionConfig')
974 self.addOption ('containerName', '', type=str,
975 noneAction='error',
976 info="the name of the input container.")
977 self.addOption ('selectionName', '', type=str,
978 noneAction='error',
979 info="the name of the jet selection to define (e.g. `tight` or `loose`).")
980 self.addOption ('jvtWP', '', type=str,
981 noneAction='error',
982 info="the NNJvt WP to use. Supported WPs: `FixedEffPt`.")
983 self.addOption ('useSuffix', True, type=bool,
984 info="whether the working point name is to be used as suffix ."
985 "Not to be disabled if multiple working points are scheduled.")
986
987 def instanceName (self) :
988 return self.containerName + '_' + self.selectionName
989
990 def makeAlgs (self, config) :
991
992 suffix = f"_{self.jvtWP}" if self.useSuffix else ""
993 decorationName = f"jvt_selection{suffix},as_char"
994 selectionName = self.selectionName
995
996 alg = config.createAlgorithm('CP::AsgSelectionAlg', f'JvtSelectionAlg_{self.jvtWP}')
997 config.addPrivateTool('selectionTool', 'CP::NNJvtSelectionTool')
998 alg.selectionTool.JetContainer = config.readName(self.containerName)
999 alg.selectionTool.JvtMomentName = "NNJvt"
1000 alg.selectionTool.WorkingPoint = self.jvtWP
1001 alg.selectionTool.MaxPtForJvt = 60*GeV
1002 alg.selectionDecoration = decorationName
1003 alg.particles = config.readName(self.containerName)
1004
1005 config.addSelection (self.containerName, selectionName, decorationName, preselection=False)
1006
1007
1009 """the ConfigBlock for the Jvt working point efficiency"""
1010
1011 def __init__ (self) :
1012 super (JvtWorkingPointEfficiencyConfig, self).__init__ ()
1013 self.setBlockName('JvtWorkingPointEfficiencyConfig')
1014 self.addDependency('EventSelection', required=False)
1015 self.addDependency('EventSelectionMerger', required=False)
1016 self.addOption ('containerName', '', type=str,
1017 noneAction='error',
1018 info="the name of the input container.")
1019 self.addOption ('selectionName', '', type=str,
1020 noneAction='error',
1021 info="the name of the jet selection to define (e.g. `tight` or `loose`).")
1022 self.addOption ('jvtWP', '', type=str,
1023 noneAction='error',
1024 info="the NNJvt WP to use. Supported WPs: `FixedEffPt`.")
1025 self.addOption ('useSuffix', True, type=bool,
1026 info="whether the working point name is to be used as suffix ."
1027 "Not to be disabled if multiple working points are scheduled.")
1028 self.addOption ('noEffSF', False, type=bool,
1029 info="disables the calculation of efficiencies and scale factors. "
1030 "Only useful to test a new WP for which scale factors are not available.",
1031 expertMode=True)
1032
1033 def instanceName (self) :
1034 return self.containerName + '_' + self.selectionName
1035
1036 def makeAlgs (self, config) :
1037
1038 suffix = f"_{self.jvtWP}" if self.useSuffix else ""
1039 decorationName = f"jvt_selection{suffix},as_char"
1040
1041 if not self.noEffSF and config.dataType() is not DataType.Data:
1042 alg = config.createAlgorithm( 'CP::JvtEfficiencyAlg', f'JvtEfficiencyAlg_{self.jvtWP}' )
1043 config.addPrivateTool( 'efficiencyTool', 'CP::NNJvtEfficiencyTool' )
1044 alg.efficiencyTool.JetContainer = config.readName(self.containerName)
1045 alg.efficiencyTool.MaxPtForJvt = 60*GeV
1046 alg.efficiencyTool.WorkingPoint = self.jvtWP
1047 if config.geometry() is LHCPeriod.Run2:
1048 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/NNJvtSFFile_Run2_EMPFlow.root"
1049 else:
1050 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/NNJvtSFFile_Run3_EMPFlow.root"
1051 alg.selection = decorationName
1052 alg.scaleFactorDecoration = f'jvt_effSF{suffix}_%SYS%'
1053 alg.outOfValidity = 2
1054 alg.outOfValidityDeco = f'no_jvt{suffix}'
1055 alg.skipBadEfficiency = False
1056 alg.jets = config.readName (self.containerName)
1057 alg.preselection = config.getPreselection (self.containerName, '')
1058
1059 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, f'jvtEfficiency{suffix}')
1060
1061
1063 """the ConfigBlock for the event Jvt working point efficiency"""
1064
1065 def __init__ (self) :
1066 super (JvtWorkingPointEventEfficiencyConfig, self).__init__ ()
1067 self.setBlockName('JvtWorkingPointEventEfficiencyConfig')
1068 self.addDependency('JvtWorkingPointEfficiencyConfig', required=True)
1069 self.addDependency('OverlapRemoval', required=False)
1070 self.addDependency('EventSelection', required=False)
1071 self.addDependency('EventSelectionMerger', required=False)
1072 self.addOption ('containerName', '', type=str,
1073 noneAction='error',
1074 info="the name of the input container.")
1075 self.addOption ('selectionName', '', type=str,
1076 noneAction='error',
1077 info="the name of the jet selection to define (e.g. `tight` or `loose`).")
1078 self.addOption ('jvtWP', '', type=str,
1079 noneAction='error',
1080 info="the NNJvt WP to use. Supported WPs: `FixedEffPt`.")
1081 self.addOption ('useSuffix', True, type=bool,
1082 info="whether the working point name is to be used as suffix ."
1083 "Not to be disabled if multiple working points are scheduled.")
1084 self.addOption ('noEffSF', False, type=bool,
1085 info="disables the calculation of efficiencies and scale factors. "
1086 "Only useful to test a new WP for which scale factors are not available.",
1087 expertMode=True)
1088 self.addOption ('eventSF', True, type=bool,
1089 info="add calculation of event-level efficiency SF.")
1090
1091 def instanceName (self) :
1092 return self.containerName + '_' + self.selectionName
1093
1094 def makeAlgs (self, config) :
1095
1096 if (not self.noEffSF and self.eventSF and
1097 config.dataType() is not DataType.Data):
1098 suffix = f"_{self.jvtWP}" if self.useSuffix else ""
1099 alg = config.createAlgorithm( 'CP::AsgEventScaleFactorAlg', f'JvtEventScaleFactorAlg_{self.jvtWP}' )
1100 preselection = config.getFullSelection (self.containerName, '')
1101 alg.preselection = preselection + f'&&no_jvt{suffix}' if preselection else f'no_jvt{suffix}'
1102 alg.scaleFactorInputDecoration = f'jvt_effSF{suffix}_%SYS%'
1103 alg.scaleFactorOutputDecoration = f'jvt_effSF{suffix}_%SYS%'
1104 alg.particles = config.readName (self.containerName)
1105
1106 config.addOutputVar('EventInfo', alg.scaleFactorOutputDecoration, f'weight_jvt_effSF{suffix}')
1107
1108
1110 """the ConfigBlock for the fJvt working point selection"""
1111
1112 def __init__ (self) :
1113 super (FJvtWorkingPointSelectionConfig, self).__init__ ()
1114 self.setBlockName('FJvtWorkingPointSelectionConfig')
1115 self.addOption ('containerName', '', type=str,
1116 noneAction='error',
1117 info="the name of the input container.")
1118 self.addOption ('selectionName', '', type=str,
1119 noneAction='error',
1120 info="the name of the jet selection to define (e.g. `tight` or `loose`).")
1121 self.addOption ('fjvtWP', '', type=str,
1122 noneAction='error',
1123 info="the fJvt WP to use. Supported WPs: `Loose`, `Tight`, `Tighter`.")
1124 self.addOption ('useSuffix', True, type=bool,
1125 info="whether the working point name is to be used as suffix ."
1126 "Not to be disabled if multiple working points are scheduled.")
1127
1128 def instanceName (self) :
1129 return self.containerName + '_' + self.selectionName
1130
1131 def makeAlgs (self, config) :
1132
1133 suffix = f"_{self.fjvtWP}" if self.useSuffix else ""
1134 decorationName = f"fjvt_selection{suffix},as_char"
1135 selectionName = self.selectionName
1136
1137 alg = config.createAlgorithm('CP::AsgSelectionAlg', f'FJvtSelectionAlg_{self.fjvtWP}')
1138 config.addPrivateTool('selectionTool', 'CP::FJvtSelectionTool')
1139 alg.selectionTool.JetContainer = config.readName(self.containerName)
1140 alg.selectionTool.JvtMomentName = "DFCommonJets_fJvt"
1141 alg.selectionTool.WorkingPoint = self.fjvtWP
1142 alg.selectionDecoration = decorationName
1143 alg.particles = config.readName(self.containerName)
1144
1145 config.addSelection (self.containerName, selectionName, decorationName, preselection=False)
1146
1147
1149 """the ConfigBlock for the fJvt working point efficiency"""
1150
1151 def __init__ (self) :
1152 super (FJvtWorkingPointEfficiencyConfig, self).__init__ ()
1153 self.setBlockName('FJvtWorkingPointEfficiencyConfig')
1154 self.addDependency('EventSelection', required=False)
1155 self.addDependency('EventSelectionMerger', required=False)
1156 self.addOption ('containerName', '', type=str,
1157 noneAction='error',
1158 info="the name of the input container.")
1159 self.addOption ('selectionName', '', type=str,
1160 noneAction='error',
1161 info="the name of the jet selection to define (e.g. `tight` or `loose`).")
1162 self.addOption ('fjvtWP', '', type=str,
1163 noneAction='error',
1164 info="the fJvt WP to use. Supported WPs: `Loose`, `Tight`, `Tighter`.")
1165 self.addOption ('useSuffix', True, type=bool,
1166 info="whether the working point name is to be used as suffix ."
1167 "Not to be disabled if multiple working points are scheduled.")
1168 self.addOption ('noEffSF', False, type=bool,
1169 info="disables the calculation of efficiencies and scale factors. "
1170 "Only useful to test a new WP for which scale factors are not available.",
1171 expertMode=True)
1172
1173 def instanceName (self) :
1174 return self.containerName + '_' + self.selectionName
1175
1176 def makeAlgs (self, config) :
1177
1178 suffix = f"_{self.fjvtWP}" if self.useSuffix else ""
1179 decorationName = f"fjvt_selection{suffix},as_char"
1180
1181 if not self.noEffSF and config.dataType() is not DataType.Data:
1182 alg = config.createAlgorithm( 'CP::JvtEfficiencyAlg', f'FJvtEfficiencyAlg_{self.fjvtWP}' )
1183 config.addPrivateTool( 'efficiencyTool', 'CP::FJvtEfficiencyTool' )
1184 alg.efficiencyTool.JetContainer = config.readName(self.containerName)
1185 alg.efficiencyTool.WorkingPoint = self.fjvtWP
1186 if config.geometry() is LHCPeriod.Run2:
1187 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/fJvtSFFile_Run2_EMPFlow.root"
1188 else:
1189 alg.efficiencyTool.SFFile = "JetJvtEfficiency/May2024/fJvtSFFile_Run3_EMPFlow.root"
1190 alg.selection = decorationName
1191 alg.scaleFactorDecoration = f'fjvt_effSF{suffix}_%SYS%'
1192 alg.outOfValidity = 2
1193 alg.outOfValidityDeco = f'no_fjvt{suffix}'
1194 alg.skipBadEfficiency = False
1195 alg.jets = config.readName (self.containerName)
1196 alg.preselection = config.getPreselection (self.containerName, '')
1197
1198 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, f'fjvtEfficiency{suffix}')
1199
1200
1202 """the ConfigBlock for the event fJvt working point efficiency"""
1203
1204 def __init__ (self) :
1205 super (FJvtWorkingPointEventEfficiencyConfig, self).__init__ ()
1206 self.setBlockName('FJvtWorkingPointEventEfficiencyConfig')
1207 self.addDependency('FJvtWorkingPointEfficiencyConfig', required=True)
1208 self.addDependency('OverlapRemoval', required=False)
1209 self.addDependency('EventSelection', required=False)
1210 self.addDependency('EventSelectionMerger', required=False)
1211 self.addOption ('containerName', '', type=str,
1212 noneAction='error',
1213 info="the name of the input container.")
1214 self.addOption ('selectionName', '', type=str,
1215 noneAction='error',
1216 info="the name of the jet selection to define (e.g. `tight` or `loose`).")
1217 self.addOption ('fjvtWP', '', type=str,
1218 noneAction='error',
1219 info="the fJvt WP to use. Supported WPs: `Loose`, `Tight`, `Tighter`.")
1220 self.addOption ('useSuffix', True, type=bool,
1221 info="whether the working point name is to be used as suffix ."
1222 "Not to be disabled if multiple working points are scheduled.")
1223 self.addOption ('noEffSF', False, type=bool,
1224 info="disables the calculation of efficiencies and scale factors. "
1225 "Only useful to test a new WP for which scale factors are not available.",
1226 expertMode=True)
1227 self.addOption ('eventSF', True, type=bool,
1228 info="add calculation of event-level efficiency SF.")
1229
1230 def instanceName (self) :
1231 return self.containerName + '_' + self.selectionName
1232
1233 def makeAlgs (self, config) :
1234
1235 if (not self.noEffSF and self.eventSF and
1236 config.dataType() is not DataType.Data):
1237 suffix = f"_{self.fjvtWP}" if self.useSuffix else ""
1238 alg = config.createAlgorithm( 'CP::AsgEventScaleFactorAlg', f'ForwardJvtEventScaleFactorAlg_{self.fjvtWP}' )
1239 preselection = config.getFullSelection (self.containerName, '')
1240 alg.preselection = preselection + f'&&no_fjvt{suffix}' if preselection else f'no_fjvt{suffix}'
1241 alg.scaleFactorInputDecoration = f'fjvt_effSF{suffix}_%SYS%'
1242 alg.scaleFactorOutputDecoration = f'fjvt_effSF{suffix}_%SYS%'
1243 alg.particles = config.readName (self.containerName)
1244
1245 config.addOutputVar('EventInfo', alg.scaleFactorOutputDecoration, f'weight_fjvt_effSF{suffix}')
1246
1247
1248@groupBlocks
1249def Jets(seq):
1250 seq.append(PreJetAnalysisConfig())
1251 seq.append(SmallRJetAnalysisConfig())
1252 seq.append(RScanJetAnalysisConfig())
1253 seq.append(LargeRJetAnalysisConfig())
1254
1255@groupBlocks
1257 seq.append(JvtWorkingPointSelectionConfig())
1260
1261@groupBlocks
if(pathvar)
createFFSmearingTool(self, jetFFSmearingAlg, config)
createUncertaintyTool(self, jetUncertaintiesAlg, config, jetCollectionName, doPseudoData=False)
createUncertaintyTool(self, jetUncertaintiesAlg, config, jetCollectionName, doPseudoData=False)
Definition Jets.py:1
_parseJetCollection(jetCollection)