232 def addRecoJetCollection(self,
235 inputCollection = "",
236 genJetsCollection = "",
238 bTagDiscriminators = None,
239 JETCorrLevels = None,
241 print(
"jetCollectionTools::RecoJetAdder::addRecoJetCollection: Adding Reco Jet Collection: {}".
format(jet))
245 if inputCollection
and inputCollection
not in [
246 "slimmedJets",
"slimmedJetsAK8",
"slimmedJetsPuppi",
"slimmedCaloJets",
248 raise RuntimeError(
"Invalid input collection: %s" % inputCollection)
250 if bTagDiscriminators
is None:
251 bTagDiscriminators = self.bTagDiscriminators
253 if JETCorrLevels
is None:
254 JETCorrLevels = self.JETCorrLevels
259 recoJetInfo = RecoJetInfo(jet, inputCollection)
260 jetLower = recoJetInfo.jetLower
261 jetUpper = recoJetInfo.jetUpper
262 tagName = recoJetInfo.jetTagName
264 if inputCollection ==
"slimmedJets":
265 assert(jetLower ==
"ak4pfchs")
266 elif inputCollection ==
"slimmedJetsAK8":
267 assert(jetLower ==
"ak8pfpuppi")
268 elif inputCollection ==
"slimmedJetsPuppi":
269 assert(jetLower ==
"ak4pfpuppi")
270 elif inputCollection ==
"slimmedCaloJets":
271 assert(jetLower ==
"ak4calo")
279 if not inputCollection
or recoJetInfo.doCalo:
280 print(
"jetCollectionTools::RecoJetAdder::addRecoJetCollection: inputCollection not specified. Building recojet collection now")
290 pfCand = self.pfLabel
294 if recoJetInfo.jetPUMethod
not in [
"",
"cs" ]:
295 pfCand += recoJetInfo.jetPUMethod
299 if pfCand
not in self.prerequisites:
303 if recoJetInfo.jetPUMethod
in [
"",
"cs" ]:
308 elif recoJetInfo.jetPUMethod ==
"chs":
309 setattr(proc, pfCand,
310 cms.EDFilter(
"CandPtrSelector",
311 src = cms.InputTag(self.pfLabel),
312 cut = cms.string(
"fromPV"),
315 self.prerequisites.
append(pfCand)
319 elif recoJetInfo.jetPUMethod ==
"puppi":
320 setattr(proc, pfCand,
322 candName = self.pfLabel,
323 vertexName = self.pvLabel,
326 self.prerequisites.
append(pfCand)
330 elif recoJetInfo.jetPUMethod ==
"sk":
331 setattr(proc, pfCand,
333 PFCandidates = self.pfLabel,
334 rParam = recoJetInfo.jetSizeNr,
337 self.prerequisites.
append(pfCand)
339 raise RuntimeError(
"Currently unsupported PU method: '%s'" % recoJetInfo.jetPUMethod)
346 if not recoJetInfo.doCalo:
347 jetCollection =
'{}Collection'.
format(tagName)
349 if jetCollection
in self.main:
350 raise ValueError(
"Step '%s' already implemented" % jetCollection)
352 setattr(proc, jetCollection, ak4PFJetsCS.clone(
354 doAreaFastjet =
True,
356 jetAlgorithm = supportedJetAlgos[recoJetInfo.jetAlgo],
357 rParam = recoJetInfo.jetSizeNr,
358 useConstituentSubtraction = recoJetInfo.doCS,
359 csRParam = 0.4
if recoJetInfo.doCS
else -1.,
360 csRho_EtaMax = PFJetParameters.Rho_EtaMax
if recoJetInfo.doCS
else -1.,
361 useExplicitGhosts = recoJetInfo.doCS
or recoJetInfo.jetPUMethod ==
"sk",
364 if recoJetInfo.jetPUMethod ==
"puppi":
365 _jets = getattr(proc, jetCollection)
366 _jets.src = self.pfLabel
367 _jets.srcWeights = pfCand
368 _jets.applyWeights =
True
369 currentTasks.append(jetCollection)
371 jetCollection = inputCollection
376 if recoJetInfo.jetPUMethod ==
"puppi":
377 jetCorrLabel =
"Puppi"
378 elif recoJetInfo.jetPUMethod
in [
"cs",
"sk" ]:
381 jetCorrLabel = recoJetInfo.jetPUMethod
388 recoJetInfo.jetAlgo.upper(),
390 "Calo" if recoJetInfo.doCalo
else recoJetInfo.jetReco.upper(),
400 jetSource = cms.InputTag(jetCollection),
401 algo = recoJetInfo.jetAlgo,
402 rParam = recoJetInfo.jetSizeNr,
403 pvSource = cms.InputTag(self.pvLabel),
404 pfCandidates = cms.InputTag(self.pfLabel),
405 svSource = cms.InputTag(self.svLabel),
406 muSource = cms.InputTag(self.muLabel),
407 elSource = cms.InputTag(self.elLabel),
408 btagDiscriminators = bTagDiscriminators
if not recoJetInfo.doCalo
else [
"None" ],
409 jetCorrections = jetCorrections,
410 genJetCollection = cms.InputTag(genJetsCollection),
411 genParticles = cms.InputTag(self.gpLabel),
414 getJetMCFlavour =
not recoJetInfo.doCalo
and recoJetInfo.jetPUMethod !=
"cs"
417 delattr(proc,
'patJetGenJetMatch{}'.
format(tagName))
418 delattr(proc,
'patJetPartonMatch{}'.
format(tagName))
419 getJetMCFlavour =
False
421 setattr(getattr(proc,
"patJets{}".
format(tagName)),
"getJetMCFlavour", cms.bool(getJetMCFlavour))
422 setattr(getattr(proc,
"patJetCorrFactors{}".
format(tagName)),
"payload", cms.string(recoJetInfo.jetCorrPayload))
423 selJet =
"selectedPatJets{}".
format(tagName)
425 selJet = inputCollection
427 if not recoJetInfo.skipUserData:
431 jercVar =
"jercVars{}".
format(tagName)
432 if jercVar
in self.main:
433 raise ValueError(
"Step '%s' already implemented" % jercVar)
434 setattr(proc, jercVar, proc.jercVars.clone(srcJet = selJet))
435 currentTasks.append(jercVar)
439 looseJetId =
"looseJetId{}".
format(tagName)
440 if looseJetId
in self.main:
441 raise ValueError(
"Step '%s' already implemented" % looseJetId)
442 setattr(proc, looseJetId, proc.looseJetId.clone(
444 filterParams=proc.looseJetId.filterParams.clone(
449 currentTasks.append(looseJetId)
453 tightJetId =
"tightJetId{}".
format(tagName)
454 if tightJetId
in self.main:
455 raise ValueError(
"Step '%s' already implemented" % tightJetId)
456 setattr(proc, tightJetId, proc.tightJetId.clone(
458 filterParams=proc.tightJetId.filterParams.clone(
459 version =
"SUMMER18{}".
format(
"PUPPI" if recoJetInfo.jetPUMethod ==
"puppi" else "")
463 tightJetIdObj = getattr(proc, tightJetId)
464 run2_jme_2016.toModify(
465 tightJetIdObj.filterParams,
468 run2_jme_2017.toModify(
469 tightJetIdObj.filterParams,
470 version =
'WINTER17{}'.
format(
"PUPPI" if recoJetInfo.jetPUMethod ==
"puppi" else "")
472 currentTasks.append(tightJetId)
476 tightJetIdLepVeto =
"tightJetIdLepVeto{}".
format(tagName)
477 if tightJetIdLepVeto
in self.main:
478 raise ValueError(
"Step '%s' already implemented" % tightJetIdLepVeto)
479 setattr(proc, tightJetIdLepVeto, proc.tightJetIdLepVeto.clone(
481 filterParams=proc.tightJetIdLepVeto.filterParams.clone(
482 version =
"SUMMER18{}".
format(
"PUPPI" if recoJetInfo.jetPUMethod ==
"puppi" else "")
486 tightJetIdLepVetoObj = getattr(proc, tightJetIdLepVeto)
487 run2_jme_2016.toModify(
488 tightJetIdLepVetoObj.filterParams,
491 run2_jme_2017.toModify(
492 tightJetIdLepVetoObj.filterParams,
493 version =
'WINTER17{}'.
format(
"PUPPI" if recoJetInfo.jetPUMethod ==
"puppi" else ""),
495 currentTasks.append(tightJetIdLepVeto)
499 selectedPatJetsWithUserData =
"{}WithUserData".
format(selJet)
500 if selectedPatJetsWithUserData
in self.main:
501 raise ValueError(
"Step '%s' already implemented" % selectedPatJetsWithUserData)
502 setattr(proc, selectedPatJetsWithUserData,
503 cms.EDProducer(
"PATJetUserDataEmbedder",
504 src = cms.InputTag(selJet),
505 userFloats = cms.PSet(
506 chFPV0EF = cms.InputTag(
"{}:chargedFromPV0EnergyFraction".
format(jercVar)),
507 chFPV1EF = cms.InputTag(
"{}:chargedFromPV1EnergyFraction".
format(jercVar)),
508 chFPV2EF = cms.InputTag(
"{}:chargedFromPV2EnergyFraction".
format(jercVar)),
509 chFPV3EF = cms.InputTag(
"{}:chargedFromPV3EnergyFraction".
format(jercVar)),
512 tightId = cms.InputTag(tightJetId),
513 tightIdLepVeto = cms.InputTag(tightJetIdLepVeto),
517 selectedPatJetsWithUserDataObj = getattr(proc, selectedPatJetsWithUserData)
518 run2_jme_2016.toModify(selectedPatJetsWithUserDataObj.userInts,
519 looseId = cms.InputTag(looseJetId),
521 currentTasks.append(selectedPatJetsWithUserData)
523 selectedPatJetsWithUserData =
"selectedPatJets{}".
format(tagName)
529 jetCorrFactors =
"jetCorrFactors{}".
format(tagName)
530 if jetCorrFactors
in self.main:
531 raise ValueError(
"Step '%s' already implemented" % jetCorrFactors)
533 setattr(proc, jetCorrFactors, patJetCorrFactors.clone(
534 src = selectedPatJetsWithUserData,
535 levels = JETCorrLevels,
536 primaryVertices = self.pvLabel,
537 payload = recoJetInfo.jetCorrPayload,
538 rho =
"fixedGridRhoFastjetAll{}".
format(
"Calo" if recoJetInfo.doCalo
else ""),
541 currentTasks.append(jetCorrFactors)
543 updatedJets =
"updatedJets{}".
format(tagName)
544 if updatedJets
in self.main:
545 raise ValueError(
"Step '%s' already implemented" % updatedJets)
547 setattr(proc, updatedJets, updatedPatJets.clone(
549 jetSource = selectedPatJetsWithUserData,
550 jetCorrFactorsSource = [jetCorrFactors],
553 currentTasks.append(updatedJets)
555 self.main.extend(currentTasks)