1 import FWCore.ParameterSet.Config
as cms
5 from Configuration.Eras.Modifier_run2_jme_2016_cff
import run2_jme_2016
6 from Configuration.Eras.Modifier_run2_jme_2017_cff
import run2_jme_2017
11 from RecoJets.JetProducers.ak4GenJets_cfi
import ak4GenJets
21 from CommonTools.PileupAlgos.softKiller_cfi
import softKiller
32 Class to hold information of a genjet collection
43 jetRegex = re.compile(
44 r'(?P<{algo}>({algoList}))(?P<{size}>[0-9]+)gen'.
format(
46 algoList =
'|'.
join(supportedJetAlgos.keys()),
50 jetMatch = jetRegex.match(jet.lower())
52 raise RuntimeError(
'Invalid jet collection: %s' % jet)
64 Tool to schedule modules for building a genjet collection with input MiniAODs
74 resultSequence = cms.Sequence()
75 for idx, task
in enumerate(tasks):
77 resultSequence = cms.Sequence(getattr(proc, task))
79 resultSequence.insert(idx, getattr(proc, task))
89 print(
"jetCollectionTools::GenJetAdder::addGenJetCollection: Adding Gen Jet Collection: {}".
format(jet))
95 jetLower = jet.lower()
96 jetUpper = jet.upper()
106 if not inputCollection:
107 print(
"jetCollectionTools::GenJetAdder::addGenJetCollection: inputCollection not specified. Building genjet collection now")
111 packedGenPartNoNu =
"packedGenParticlesForJetsNoNu"
113 setattr(proc, packedGenPartNoNu, cms.EDFilter(
"CandPtrSelector",
114 src = cms.InputTag(
"packedGenParticles"),
115 cut = cms.string(
"abs(pdgId) != 12 && abs(pdgId) != 14 && abs(pdgId) != 16"),
122 genJetsCollection =
"{}{}{}".
format(genJetInfo.jetAlgo.upper(), genJetInfo.jetSize,
'GenJetsNoNu')
123 setattr(proc, genJetsCollection, ak4GenJets.clone(
124 src = packedGenPartNoNu,
125 jetAlgorithm = cms.string(supportedJetAlgos[genJetInfo.jetAlgo]),
126 rParam = cms.double(genJetInfo.jetSizeNr),
133 genFlavour =
"{}Flavour".
format(genJetInfo.jetTagName)
134 setattr(proc, genFlavour, patJetFlavourAssociation.clone(
135 jets = cms.InputTag(genJetsCollection),
136 jetAlgorithm = cms.string(supportedJetAlgos[genJetInfo.jetAlgo]),
137 rParam = cms.double(genJetInfo.jetSizeNr),
141 currentTasks.append(genFlavour)
142 self.
main.extend(currentTasks)
153 Class to hold information of a recojet collection
164 puMethodKey =
'puMethod'
165 jetRegex = re.compile(
166 r'(?P<{algo}>({algoList}))(?P<{size}>[0-9]+)(?P<{reco}>(pf|calo))(?P<{puMethod}>(chs|puppi|sk|cs|))'.
format(
168 algoList =
'|'.
join(supportedJetAlgos.keys()),
171 puMethod = puMethodKey,
174 jetMatch = jetRegex.match(jet.lower())
176 raise RuntimeError(
'Invalid jet collection: %s' % jet)
206 Tool to schedule modules for building a recojet collection with input MiniAODs
214 self.
pvLabel =
"offlineSlimmedPrimaryVertices"
224 resultSequence = cms.Sequence()
225 for idx, task
in enumerate(tasks):
227 resultSequence = cms.Sequence(getattr(proc, task))
229 resultSequence.insert(idx, getattr(proc, task))
230 return resultSequence
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:
253 if JETCorrLevels
is None:
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")
294 if recoJetInfo.jetPUMethod
not in [
"",
"cs" ]:
295 pfCand += recoJetInfo.jetPUMethod
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"),
319 elif recoJetInfo.jetPUMethod ==
"puppi":
320 setattr(proc, pfCand,
330 elif recoJetInfo.jetPUMethod ==
"sk":
331 setattr(proc, pfCand,
334 rParam = recoJetInfo.jetSizeNr,
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)
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)