1 import FWCore.ParameterSet.Config
as cms
5 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff
import run2_miniAOD_80XLegacy
6 from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff
import run2_nanoAOD_94X2016
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"),
118 self.prerequisites.append(packedGenPartNoNu)
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),
129 self.prerequisites.append(genJetsCollection)
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)
190 self.jetAlgo.upper(), self.
jetSize,
"Calo" if self.
doCalo else self.jetReco.upper()
206 Tool to schedule modules for building a recojet collection with input MiniAODs 214 self.
pvLabel =
"offlineSlimmedPrimaryVertices" 223 resultSequence = cms.Sequence()
224 for idx, task
in enumerate(tasks):
226 resultSequence = cms.Sequence(getattr(proc, task))
228 resultSequence.insert(idx, getattr(proc, task))
229 return resultSequence
234 inputCollection =
"",
235 genJetsCollection =
"",
237 bTagDiscriminators =
None,
238 JETCorrLevels =
None,
240 print(
"jetCollectionTools::RecoJetAdder::addRecoJetCollection: Adding Reco Jet Collection: {}".
format(jet))
244 if inputCollection
and inputCollection
not in [
245 "slimmedJets",
"slimmedJetsAK8",
"slimmedJetsPuppi",
"slimmedCaloJets",
247 raise RuntimeError(
"Invalid input collection: %s" % inputCollection)
249 if bTagDiscriminators
is None:
252 if JETCorrLevels
is None:
259 jetLower = recoJetInfo.jetLower
260 jetUpper = recoJetInfo.jetUpper
261 tagName = recoJetInfo.jetTagName
263 if inputCollection ==
"slimmedJets":
264 assert(jetLower ==
"ak4pfchs")
265 elif inputCollection ==
"slimmedJetsAK8":
266 assert(jetLower ==
"ak8pfpuppi")
267 elif inputCollection ==
"slimmedJetsPuppi":
268 assert(jetLower ==
"ak4pfpuppi")
269 elif inputCollection ==
"slimmedCaloJets":
270 assert(jetLower ==
"ak4calo")
278 if not inputCollection
or recoJetInfo.doCalo:
279 print(
"jetCollectionTools::RecoJetAdder::addRecoJetCollection: inputCollection not specified. Building recojet collection now")
293 if recoJetInfo.jetPUMethod
not in [
"",
"cs" ]:
294 pfCand += recoJetInfo.jetPUMethod
302 if recoJetInfo.jetPUMethod
in [
"",
"cs" ]:
307 elif recoJetInfo.jetPUMethod ==
"chs":
308 setattr(proc, pfCand,
309 cms.EDFilter(
"CandPtrSelector",
310 src = cms.InputTag(self.
pfLabel),
311 cut = cms.string(
"fromPV"),
314 self.prerequisites.append(pfCand)
318 elif recoJetInfo.jetPUMethod ==
"puppi":
319 setattr(proc, pfCand,
325 self.prerequisites.append(pfCand)
329 elif recoJetInfo.jetPUMethod ==
"sk":
330 setattr(proc, pfCand,
333 rParam = recoJetInfo.jetSizeNr,
336 self.prerequisites.append(pfCand)
338 raise RuntimeError(
"Currently unsupported PU method: '%s'" % recoJetInfo.jetPUMethod)
345 if not recoJetInfo.doCalo:
346 jetCollection =
'{}Collection'.
format(tagName)
348 if jetCollection
in self.
main:
349 raise ValueError(
"Step '%s' already implemented" % jetCollection)
351 setattr(proc, jetCollection, ak4PFJetsCS.clone(
353 doAreaFastjet =
True,
355 jetAlgorithm = supportedJetAlgos[recoJetInfo.jetAlgo],
356 rParam = recoJetInfo.jetSizeNr,
357 useConstituentSubtraction = recoJetInfo.doCS,
358 csRParam = 0.4
if recoJetInfo.doCS
else -1.,
359 csRho_EtaMax = PFJetParameters.Rho_EtaMax
if recoJetInfo.doCS
else -1.,
360 useExplicitGhosts = recoJetInfo.doCS
or recoJetInfo.jetPUMethod ==
"sk",
363 currentTasks.append(jetCollection)
365 jetCollection = inputCollection
370 if recoJetInfo.jetPUMethod ==
"puppi":
371 jetCorrLabel =
"Puppi" 372 elif recoJetInfo.jetPUMethod
in [
"cs",
"sk" ]:
375 jetCorrLabel = recoJetInfo.jetPUMethod
382 recoJetInfo.jetAlgo.upper(),
384 "Calo" if recoJetInfo.doCalo
else recoJetInfo.jetReco.upper(),
394 jetSource = cms.InputTag(jetCollection),
395 algo = recoJetInfo.jetAlgo,
396 rParam = recoJetInfo.jetSizeNr,
397 pvSource = cms.InputTag(self.
pvLabel),
398 pfCandidates = cms.InputTag(self.
pfLabel),
399 svSource = cms.InputTag(self.
svLabel),
400 muSource = cms.InputTag(self.
muLabel),
401 elSource = cms.InputTag(self.
elLabel),
402 btagDiscriminators = bTagDiscriminators
if not recoJetInfo.doCalo
else [
"None" ],
403 jetCorrections = jetCorrections,
404 genJetCollection = cms.InputTag(genJetsCollection),
405 genParticles = cms.InputTag(self.
gpLabel),
408 getJetMCFlavour =
not recoJetInfo.doCalo
and recoJetInfo.jetPUMethod !=
"cs" 410 setattr(getattr(proc,
"patJets{}".
format(tagName)),
"getJetMCFlavour", cms.bool(getJetMCFlavour))
411 setattr(getattr(proc,
"patJetCorrFactors{}".
format(tagName)),
"payload", cms.string(recoJetInfo.jetCorrPayload))
412 selJet =
"selectedPatJets{}".
format(tagName)
414 selJet = inputCollection
416 if not recoJetInfo.skipUserData:
420 jercVar =
"jercVars{}".
format(tagName)
421 if jercVar
in self.
main:
422 raise ValueError(
"Step '%s' already implemented" % jercVar)
423 setattr(proc, jercVar, proc.jercVars.clone(srcJet = selJet))
424 currentTasks.append(jercVar)
428 looseJetId =
"looseJetId{}".
format(tagName)
429 if looseJetId
in self.
main:
430 raise ValueError(
"Step '%s' already implemented" % looseJetId)
431 setattr(proc, looseJetId, proc.looseJetId.clone(src = selJet))
435 tightJetId =
"tightJetId{}".
format(tagName)
436 if tightJetId
in self.
main:
437 raise ValueError(
"Step '%s' already implemented" % tightJetId)
438 setattr(proc, tightJetId, proc.tightJetId.clone(src = selJet))
439 currentTasks.append(tightJetId)
443 tightJetIdLepVeto =
"tightJetIdLepVeto{}".
format(tagName)
444 if tightJetIdLepVeto
in self.
main:
445 raise ValueError(
"Step '%s' already implemented" % tightJetIdLepVeto)
446 setattr(proc, tightJetIdLepVeto, proc.tightJetIdLepVeto.clone(src = selJet))
447 currentTasks.append(tightJetIdLepVeto)
451 selectedPatJetsWithUserData =
"{}WithUserData".
format(selJet)
452 if selectedPatJetsWithUserData
in self.
main:
453 raise ValueError(
"Step '%s' already implemented" % selectedPatJetsWithUserData)
454 setattr(proc, selectedPatJetsWithUserData,
455 cms.EDProducer(
"PATJetUserDataEmbedder",
456 src = cms.InputTag(selJet),
457 userFloats = cms.PSet(
458 jercCHPUF = cms.InputTag(
"{}:chargedHadronPUEnergyFraction".
format(jercVar)),
459 jercCHF = cms.InputTag(
"{}:chargedHadronCHSEnergyFraction".
format(jercVar)),
462 tightId = cms.InputTag(tightJetId),
463 tightIdLepVeto = cms.InputTag(tightJetIdLepVeto),
467 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
468 selectedPatJetsWithUserDataObj = getattr(proc, selectedPatJetsWithUserData)
469 modifier.toModify(selectedPatJetsWithUserDataObj.userInts,
470 looseId = looseJetId,
471 tightIdLepVeto =
None,
473 currentTasks.append(selectedPatJetsWithUserData)
475 selectedPatJetsWithUserData =
"selectedPatJets{}".
format(tagName)
481 jetCorrFactors =
"jetCorrFactors{}".
format(tagName)
482 if jetCorrFactors
in self.
main:
483 raise ValueError(
"Step '%s' already implemented" % jetCorrFactors)
485 setattr(proc, jetCorrFactors, patJetCorrFactors.clone(
486 src = selectedPatJetsWithUserData,
487 levels = JETCorrLevels,
488 primaryVertices = self.
pvLabel,
489 payload = recoJetInfo.jetCorrPayload,
490 rho =
"fixedGridRhoFastjetAll{}".
format(
"Calo" if recoJetInfo.doCalo
else ""),
493 currentTasks.append(jetCorrFactors)
495 updatedJets =
"updatedJets{}".
format(tagName)
496 if updatedJets
in self.
main:
497 raise ValueError(
"Step '%s' already implemented" % updatedJets)
499 setattr(proc, updatedJets, updatedPatJets.clone(
501 jetSource = selectedPatJetsWithUserData,
502 jetCorrFactorsSource = [jetCorrFactors],
506 currentTasks.append(updatedJets)
507 self.main.extend(currentTasks)
S & print(S &os, JobReport::InputFile const &f)
static std::string join(char **cmd)