CMS 3D CMS Logo

Functions
puppiJetMETReclusteringTools Namespace Reference

Functions

def puppiAK4METReclusterFromMiniAOD (process, runOnMC, useExistingWeights, btagDiscriminatorsAK4=None)
 
def puppiAK8ReclusterFromMiniAOD (process, runOnMC, useExistingWeights, btagDiscriminatorsAK8=None, btagDiscriminatorsAK8Subjets=None)
 

Function Documentation

◆ puppiAK4METReclusterFromMiniAOD()

def puppiJetMETReclusteringTools.puppiAK4METReclusterFromMiniAOD (   process,
  runOnMC,
  useExistingWeights,
  btagDiscriminatorsAK4 = None 
)

Definition at line 7 of file puppiJetMETReclusteringTools.py.

References helpers.addToProcessAndTask(), helpers.getPatAlgosToolsTask(), runMETCorrectionsAndUncertainties.runMetCorAndUncFromMiniAOD(), and jetTools.setupPuppiForPackedPF().

Referenced by puppiJetMETReclusteringFromMiniAOD_cff.setupPuppiAK4AK8METReclustering().

7 def puppiAK4METReclusterFromMiniAOD(process, runOnMC, useExistingWeights, btagDiscriminatorsAK4=None):
8 
9  task = getPatAlgosToolsTask(process)
10 
11  pfLabel = "packedPFCandidates"
12  pvLabel = "offlineSlimmedPrimaryVertices"
13  svLabel = "slimmedSecondaryVertices"
14  muLabel = "slimmedMuons"
15  elLabel = "slimmedElectrons"
16  gpLabel = "prunedGenParticles"
17 
18  genJetsCollection = "slimmedGenJets"
19 
20 
28  puppiLabel, puppiNoLepLabel = setupPuppiForPackedPF(process, useExistingWeights)
29 
30 
38  process.load("RecoJets.JetProducers.ak4PFJets_cfi")
39  task.add(process.ak4PFJetsPuppi)
40  process.ak4PFJetsPuppi.src = pfLabel
41  process.ak4PFJetsPuppi.srcWeights = puppiLabel
42 
44  process.ak4PFJetsPuppiTracksAssociatorAtVertex = cms.EDProducer("JetTracksAssociatorAtVertex",
45  j2tParametersVX,
46  jets = cms.InputTag("ak4PFJetsPuppi")
47  )
48  task.add(process.ak4PFJetsPuppiTracksAssociatorAtVertex)
49  process.patJetPuppiCharge = cms.EDProducer("JetChargeProducer",
50  src = cms.InputTag("ak4PFJetsPuppiTracksAssociatorAtVertex"),
51  var = cms.string("Pt"),
52  exp = cms.double(1.0)
53  )
54 
55  #
56  # PATify jets
57  #
58  addJetCollection(
59  process,
60  postfix = "",
61  labelName = "Puppi",
62  jetSource = cms.InputTag("ak4PFJetsPuppi"),
63  algo = "ak",
64  rParam = 0.4,
65  pfCandidates = cms.InputTag(pfLabel),
66  pvSource = cms.InputTag(pvLabel),
67  svSource = cms.InputTag(svLabel),
68  muSource = cms.InputTag(muLabel),
69  elSource = cms.InputTag(elLabel),
70  genJetCollection = cms.InputTag(genJetsCollection),
71  genParticles = cms.InputTag(gpLabel),
72  jetCorrections = ('AK4PFPuppi', cms.vstring(["L2Relative", "L3Absolute"]), ''),
73  getJetMCFlavour = runOnMC
74  )
75  process.patJetsPuppi.jetChargeSource = cms.InputTag("patJetPuppiCharge")
76  process.selectedPatJetsPuppi.cut = cms.string("pt > 10")
77  if hasattr(process,"patJetFlavourAssociationPuppi"):
78  process.patJetFlavourAssociationPuppi.weights = cms.InputTag(puppiLabel)
79 
80  #=============================================
81  #
82  # Update the selectedPatJet collection.
83  # This is where we setup
84  # - JEC
85  # - b-tagging discriminators
86  #
87  #=============================================
88  # update slimmedJetsPuppi to include taggers
90  addToProcessAndTask('slimmedJetsPuppiNoDeepTags', slimmedJets.clone(
91  src = "selectedPatJetsPuppi",
92  packedPFCandidates = pfLabel,
93  dropDaughters = "0",
94  rekeyDaughters = "0",
95  ),
96  process, task
97  )
98 
99  updateJetCollection(
100  process,
101  jetSource = cms.InputTag("slimmedJetsPuppiNoDeepTags"),
102  # updateJetCollection defaults to MiniAOD inputs but
103  # here it is made explicit (as in training or MINIAOD redoing)
104  pfCandidates = cms.InputTag(pfLabel),
105  pvSource = cms.InputTag(pvLabel),
106  svSource = cms.InputTag(svLabel),
107  muSource = cms.InputTag(muLabel),
108  elSource = cms.InputTag(elLabel),
109  jetCorrections = ("AK4PFPuppi", cms.vstring(["L2Relative", "L3Absolute"]), "None"),
110  btagDiscriminators = btagDiscriminatorsAK4.names.value() if btagDiscriminatorsAK4 is not None else ['None'],
111  postfix = 'SlimmedDeepFlavour',
112  printWarning = False
113  )
114 
115  addToProcessAndTask("slimmedJetsPuppi", process.selectedUpdatedPatJetsSlimmedDeepFlavour.clone(), process, task)
116  del process.selectedUpdatedPatJetsSlimmedDeepFlavour
117 
118 
123  from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
125  isData=not(runOnMC),
126  jetCollUnskimmed="slimmedJetsPuppi",
127  metType="Puppi",
128  postfix="Puppi",
129  jetFlavor="AK4PFPuppi",
130  puppiProducerLabel=puppiLabel,
131  puppiProducerForMETLabel=puppiNoLepLabel,
132  recoMetFromPFCs=True
133  )
134 
135 
141  if not(runOnMC):
142  runOnData(process, names=["Jets","METs"], outputModules = [])
143 
144  return process
145 
146 
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def runMetCorAndUncFromMiniAOD(process, metType="PF", jetCollUnskimmed="slimmedJets", photonColl="slimmedPhotons", electronColl="slimmedElectrons", muonColl="slimmedMuons", tauColl="slimmedTaus", pfCandColl="packedPFCandidates", jetFlavor="AK4PFchs", jetCleaning="LepClean", isData=False, manualJetConfig=False, reclusterJets=None, jetSelection="pt>15 && abs(eta)<9.9", recoMetFromPFCs=None, jetCorLabelL3="ak4PFCHSL1FastL2L3Corrector", jetCorLabelRes="ak4PFCHSL1FastL2L3ResidualCorrector", CHS=False, puppiProducerLabel="puppi", puppiProducerForMETLabel="puppiNoLep", reapplyJEC=True, jecUncFile="", computeMETSignificance=True, fixEE2017=False, fixEE2017Params=None, extractDeepMETs=False, campaign="", era="", postfix="")
def puppiAK4METReclusterFromMiniAOD(process, runOnMC, useExistingWeights, btagDiscriminatorsAK4=None)
def setupPuppiForPackedPF(process, useExistingWeights=True, postfix='')
Definition: jetTools.py:242
def getPatAlgosToolsTask(process)
Definition: helpers.py:13

◆ puppiAK8ReclusterFromMiniAOD()

def puppiJetMETReclusteringTools.puppiAK8ReclusterFromMiniAOD (   process,
  runOnMC,
  useExistingWeights,
  btagDiscriminatorsAK8 = None,
  btagDiscriminatorsAK8Subjets = None 
)

Definition at line 147 of file puppiJetMETReclusteringTools.py.

References helpers.addToProcessAndTask(), helpers.getPatAlgosToolsTask(), and jetTools.setupPuppiForPackedPF().

Referenced by puppiJetMETReclusteringFromMiniAOD_cff.setupPuppiAK4AK8METReclustering().

147 def puppiAK8ReclusterFromMiniAOD(process, runOnMC, useExistingWeights, btagDiscriminatorsAK8=None, btagDiscriminatorsAK8Subjets=None):
148 
149  task = getPatAlgosToolsTask(process)
150 
151  pfLabel = "packedPFCandidates"
152  pvLabel = "offlineSlimmedPrimaryVertices"
153  svLabel = "slimmedSecondaryVertices"
154  muLabel = "slimmedMuons"
155  elLabel = "slimmedElectrons"
156  gpLabel = "prunedGenParticles"
157 
158  genJetsAK8Collection = "slimmedGenJetsAK8"
159  genSubJetsForAK8Collection = "slimmedGenJetsAK8SoftDropSubJets"
160 
161 
169  puppiLabel, puppiNoLepLabel = setupPuppiForPackedPF(process, useExistingWeights)
170 
171 
179  process.load("RecoJets.JetProducers.ak8PFJets_cfi")
180  task.add(process.ak8PFJetsPuppi)
181  task.add(process.ak8PFJetsPuppiSoftDrop)
182 
183  # AK8 jet constituents for softdrop
184  process.ak8PFJetsPuppi.src = pfLabel
185  process.ak8PFJetsPuppi.srcWeights = puppiLabel
186 
187  # AK8 jet constituents for softdrop
188  from CommonTools.RecoAlgos.miniAODJetConstituentSelector_cfi import miniAODJetConstituentSelector
189  addToProcessAndTask("ak8PFJetsPuppiConstituents", miniAODJetConstituentSelector.clone(
190  src = cms.InputTag("ak8PFJetsPuppi"),
191  cut = cms.string("pt > 100.0 && abs(rapidity()) < 2.4")
192  ),
193  process, task
194  )
195 
196  # Soft-drop grooming
197  process.ak8PFJetsPuppiSoftDrop.src = "ak8PFJetsPuppiConstituents:constituents"
198  process.ak8PFJetsPuppiSoftDrop.srcWeights = puppiLabel
199 
200  # Soft-drop mass
201  process.load("RecoJets.JetProducers.ak8PFJetsPuppi_groomingValueMaps_cfi")
202  task.add(process.ak8PFJetsPuppiSoftDropMass)
203  process.ak8PFJetsPuppiSoftDropMass.src = "ak8PFJetsPuppi"
204  process.ak8PFJetsPuppiSoftDropMass.matched = "ak8PFJetsPuppiSoftDrop"
205  #=============================================
206  #
207  # PATify
208  #
209  #=============================================
210  #
211  # AK8 jets
212  #
213  addJetCollection(
214  process,
215  labelName = "AK8Puppi",
216  jetSource = cms.InputTag("ak8PFJetsPuppi"),
217  algo = "ak",
218  rParam = 0.8,
219  pfCandidates = cms.InputTag(pfLabel),
220  pvSource = cms.InputTag(pvLabel),
221  svSource = cms.InputTag(svLabel),
222  muSource = cms.InputTag(muLabel),
223  elSource = cms.InputTag(elLabel),
224  genJetCollection = cms.InputTag(genJetsAK8Collection),
225  genParticles = cms.InputTag(gpLabel),
226  jetCorrections = ("AK8PFPuppi", cms.vstring(["L2Relative", "L3Absolute"]), "None"),
227  getJetMCFlavour = runOnMC,
228  )
229  if hasattr(process,"patJetFlavourAssociationAK8Puppi"):
230  process.patJetFlavourAssociationAK8Puppi.weights = cms.InputTag(puppiLabel)
231 
232  process.patJetsAK8Puppi.userData.userFloats.src = [] # start with empty list of user floats
233  process.patJetsAK8Puppi.userData.userFloats.src += ["ak8PFJetsPuppiSoftDropMass"]
234  process.patJetsAK8Puppi.addTagInfos = cms.bool(False)
235 
236  process.selectedPatJetsAK8Puppi.cut = cms.string("pt > 100")
237  process.selectedPatJetsAK8Puppi.cutLoose = cms.string("pt > 30")
238  process.selectedPatJetsAK8Puppi.nLoose = cms.uint32(3)
239 
240  #
241  # Add AK8 Njetiness
242  #
243  from RecoJets.JetProducers.nJettinessAdder_cfi import Njettiness
244  addToProcessAndTask("NjettinessAK8Puppi", Njettiness.clone(
245  src = "ak8PFJetsPuppi",
246  srcWeights = puppiLabel
247  ),
248  process, task
249  )
250  process.patJetsAK8Puppi.userData.userFloats.src += [
251  "NjettinessAK8Puppi:tau1",
252  "NjettinessAK8Puppi:tau2",
253  "NjettinessAK8Puppi:tau3",
254  "NjettinessAK8Puppi:tau4"
255  ]
256 
257  #
258  # AK8 soft-drop jets
259  #
260  addJetCollection(
261  process,
262  labelName = "AK8PFPuppiSoftDrop",
263  jetSource = cms.InputTag("ak8PFJetsPuppiSoftDrop"),
264  btagDiscriminators = ["None"],
265  pfCandidates = cms.InputTag(pfLabel),
266  pvSource = cms.InputTag(pvLabel),
267  svSource = cms.InputTag(svLabel),
268  muSource = cms.InputTag(muLabel),
269  elSource = cms.InputTag(elLabel),
270  genJetCollection = cms.InputTag(genJetsAK8Collection),
271  genParticles = cms.InputTag(gpLabel),
272  jetCorrections = ("AK8PFPuppi", cms.vstring(["L2Relative", "L3Absolute"]), "None"),
273  getJetMCFlavour = False # jet flavor disabled regardless if running on MC or data
274  )
275 
276  #
277  # Soft-drop subjets
278  #
279  addJetCollection(
280  process,
281  labelName = "AK8PFPuppiSoftDropSubjets",
282  jetSource = cms.InputTag("ak8PFJetsPuppiSoftDrop", "SubJets"),
283  algo = "ak", # needed for subjet flavor clustering
284  rParam = 0.8, # needed for subjet flavor clustering
285  explicitJTA = True, # needed for subjet b tagging
286  svClustering = True, # needed for subjet b tagging
287  pfCandidates = cms.InputTag(pfLabel),
288  pvSource = cms.InputTag(pvLabel),
289  svSource = cms.InputTag(svLabel),
290  muSource = cms.InputTag(muLabel),
291  elSource = cms.InputTag(elLabel),
292  genJetCollection = cms.InputTag(genSubJetsForAK8Collection),
293  genParticles = cms.InputTag(gpLabel),
294  fatJets = cms.InputTag("ak8PFJetsPuppi"), # needed for subjet flavor clustering
295  groomedFatJets = cms.InputTag("ak8PFJetsPuppiSoftDrop"), # needed for subjet flavor clustering
296  jetCorrections = ("AK4PFPuppi", cms.vstring(["L2Relative", "L3Absolute"]), "None"),
297  )
298  if hasattr(process,"patJetFlavourAssociationAK8PFPuppiSoftDropSubjets"):
299  process.patJetFlavourAssociationAK8PFPuppiSoftDropSubjets.weights = cms.InputTag(puppiLabel)
300 
301  #=============================================
302  #
303  #
304  #
305  #=============================================
306  #
307  # add groomed ECFs and N-subjettiness to soft dropped pat::Jets for fat jets and subjets
308  #
309  process.load('RecoJets.JetProducers.ECF_cff')
310 
311  addToProcessAndTask('nb1AK8PuppiSoftDrop', process.ecfNbeta1.clone(
312  src = cms.InputTag("ak8PFJetsPuppiSoftDrop"),
313  srcWeights = puppiLabel,
314  cuts = cms.vstring('', '', 'pt > 250')
315  ),
316  process, task
317  )
318  process.patJetsAK8PFPuppiSoftDrop.userData.userFloats.src += [
319  'nb1AK8PuppiSoftDrop:ecfN2',
320  'nb1AK8PuppiSoftDrop:ecfN3',
321  ]
322 
323  addToProcessAndTask('nb2AK8PuppiSoftDrop', process.ecfNbeta2.clone(
324  src = cms.InputTag("ak8PFJetsPuppiSoftDrop"),
325  srcWeights = puppiLabel,
326  cuts = cms.vstring('', '', 'pt > 250')
327  ),
328  process, task
329  )
330  process.patJetsAK8PFPuppiSoftDrop.userData.userFloats.src += [
331  'nb2AK8PuppiSoftDrop:ecfN2',
332  'nb2AK8PuppiSoftDrop:ecfN3',
333  ]
334 
335  #
336  # add groomed ECFs and N-subjettiness to soft drop subjets
337  #
338  addToProcessAndTask("nb1AK8PuppiSoftDropSubjets", process.ecfNbeta1.clone(
339  src = cms.InputTag("ak8PFJetsPuppiSoftDrop", "SubJets"),
340  srcWeights = puppiLabel,
341  ),
342  process, task
343  )
344 
345  process.patJetsAK8PFPuppiSoftDropSubjets.userData.userFloats.src += [
346  'nb1AK8PuppiSoftDropSubjets:ecfN2',
347  'nb1AK8PuppiSoftDropSubjets:ecfN3'
348  ]
349 
350  addToProcessAndTask("nb2AK8PuppiSoftDropSubjets", process.ecfNbeta2.clone(
351  src = cms.InputTag("ak8PFJetsPuppiSoftDrop", "SubJets"),
352  srcWeights = puppiLabel,
353  ),
354  process, task
355  )
356 
357  process.patJetsAK8PFPuppiSoftDropSubjets.userData.userFloats.src += [
358  'nb2AK8PuppiSoftDropSubjets:ecfN2',
359  'nb2AK8PuppiSoftDropSubjets:ecfN3'
360  ]
361 
362  addToProcessAndTask("NjettinessAK8Subjets", Njettiness.clone(
363  src = cms.InputTag("ak8PFJetsPuppiSoftDrop", "SubJets"),
364  srcWeights = puppiLabel
365  ),
366  process, task
367  )
368  process.patJetsAK8PFPuppiSoftDropSubjets.userData.userFloats.src += [
369  "NjettinessAK8Subjets:tau1",
370  "NjettinessAK8Subjets:tau2",
371  "NjettinessAK8Subjets:tau3",
372  "NjettinessAK8Subjets:tau4",
373  ]
374 
375  addToProcessAndTask("slimmedJetsAK8PFPuppiSoftDropSubjetsNoDeepTags", cms.EDProducer("PATJetSlimmer",
376  src = cms.InputTag("selectedPatJetsAK8PFPuppiSoftDropSubjets"),
377  packedPFCandidates = cms.InputTag(pfLabel),
378  dropJetVars = cms.string("1"),
379  dropDaughters = cms.string("0"),
380  rekeyDaughters = cms.string("0"),
381  dropTrackRefs = cms.string("1"),
382  dropSpecific = cms.string("1"),
383  dropTagInfos = cms.string("1"),
384  modifyJets = cms.bool(True),
385  mixedDaughters = cms.bool(False),
386  modifierConfig = cms.PSet( modifications = cms.VPSet() )
387  ),
388  process, task
389  )
390 
391  updateJetCollection(
392  process,
393  labelName = "AK8PFPuppiSoftDropSubjets",
394  postfix = 'SlimmedDeepFlavour',
395  jetSource = cms.InputTag("slimmedJetsAK8PFPuppiSoftDropSubjetsNoDeepTags"),
396  # updateJetCollection defaults to MiniAOD inputs but
397  # here it is made explicit (as in training or MINIAOD redoing)
398  pfCandidates = cms.InputTag(pfLabel),
399  pvSource = cms.InputTag(pvLabel),
400  svSource = cms.InputTag(svLabel),
401  muSource = cms.InputTag(muLabel),
402  elSource = cms.InputTag(elLabel),
403  jetCorrections = ("AK4PFPuppi", cms.vstring(["L2Relative", "L3Absolute"]), "None"),
404  printWarning = False,
405  btagDiscriminators = btagDiscriminatorsAK8Subjets.names.value() if btagDiscriminatorsAK8Subjets is not None else ['None'],
406  )
407 
408 
409  addToProcessAndTask("slimmedJetsAK8PFPuppiSoftDropPacked", cms.EDProducer("BoostedJetMerger",
410  jetSrc = cms.InputTag("selectedPatJetsAK8PFPuppiSoftDrop"),
411  subjetSrc = cms.InputTag("selectedUpdatedPatJetsAK8PFPuppiSoftDropSubjetsSlimmedDeepFlavour")
412  ),
413  process, task
414  )
415 
416  addToProcessAndTask("packedPatJetsAK8", cms.EDProducer("JetSubstructurePacker",
417  jetSrc = cms.InputTag("selectedPatJetsAK8Puppi"),
418  distMax = cms.double(0.8),
419  algoTags = cms.VInputTag(
420  cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked")
421  ),
422  algoLabels = cms.vstring(
423  'SoftDropPuppi'
424  ),
425  fixDaughters = cms.bool(False),
426  packedPFCandidates = cms.InputTag(pfLabel),
427  ),
428  process, task
429  )
430 
431  #=============================================
432  #
433  # Update the selectedPatJet collection.
434  # This is where we setup
435  # - JEC
436  # - b-tagging discriminators
437  #
438  #=============================================
439  from PhysicsTools.PatAlgos.slimming.slimmedJets_cfi import slimmedJetsAK8
440  addToProcessAndTask("slimmedJetsAK8NoDeepTags", slimmedJetsAK8.clone(rekeyDaughters = "0"), process, task)
441  # Reconfigure the slimmedAK8 jet information to keep
442  process.slimmedJetsAK8NoDeepTags.dropDaughters = cms.string("pt < 170")
443  process.slimmedJetsAK8NoDeepTags.dropSpecific = cms.string("pt < 170")
444  process.slimmedJetsAK8NoDeepTags.dropTagInfos = cms.string("pt < 170")
445 
446  updateJetCollection(
447  process,
448  jetSource = cms.InputTag("slimmedJetsAK8NoDeepTags"),
449  # updateJetCollection defaults to MiniAOD inputs but
450  # here it is made explicit (as in training or MINIAOD redoing)
451  pfCandidates = cms.InputTag(pfLabel),
452  pvSource = cms.InputTag(pvLabel),
453  svSource = cms.InputTag(svLabel),
454  muSource = cms.InputTag(muLabel),
455  elSource = cms.InputTag(elLabel),
456  rParam = 0.8,
457  jetCorrections = ('AK8PFPuppi', cms.vstring(["L2Relative", "L3Absolute"]), 'None'),
458  btagDiscriminators = btagDiscriminatorsAK8.names.value() if btagDiscriminatorsAK8 is not None else ['None'],
459  postfix = "SlimmedAK8DeepTags",
460  printWarning = False
461  )
462 
463  addToProcessAndTask("slimmedJetsAK8", process.selectedUpdatedPatJetsSlimmedAK8DeepTags.clone(), process, task)
464  del process.selectedUpdatedPatJetsSlimmedAK8DeepTags
465 
466 
472  if not(runOnMC):
473  runOnData(process, names=["Jets"], outputModules = [])
474 
475  return process
476 
477 
def puppiAK8ReclusterFromMiniAOD(process, runOnMC, useExistingWeights, btagDiscriminatorsAK8=None, btagDiscriminatorsAK8Subjets=None)
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def setupPuppiForPackedPF(process, useExistingWeights=True, postfix='')
Definition: jetTools.py:242
def getPatAlgosToolsTask(process)
Definition: helpers.py:13