1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
24 nanoMetadata = cms.EDProducer(
"UniqueStringProducer",
26 tag = cms.string(
"untagged"),
30 linkedObjects = cms.EDProducer(
"PATObjectCrossLinker",
31 jets=cms.InputTag(
"finalJets"),
32 muons=cms.InputTag(
"finalMuons"),
33 electrons=cms.InputTag(
"finalElectrons"),
34 taus=cms.InputTag(
"finalTaus"),
35 photons=cms.InputTag(
"finalPhotons"),
38 simpleCleanerTable = cms.EDProducer(
"NanoAODSimpleCrossCleaner",
39 name=cms.string(
"cleanmask"),
40 doc=cms.string(
"simple cleaning mask with priority to leptons"),
41 jets=cms.InputTag(
"linkedObjects",
"jets"),
42 muons=cms.InputTag(
"linkedObjects",
"muons"),
43 electrons=cms.InputTag(
"linkedObjects",
"electrons"),
44 taus=cms.InputTag(
"linkedObjects",
"taus"),
45 photons=cms.InputTag(
"linkedObjects",
"photons"),
46 jetSel=cms.string(
"pt>15"),
47 muonSel=cms.string(
"track.isNonnull && isLooseMuon && isPFMuon && innerTrack.validFraction >= 0.49 && ( isGlobalMuon && globalTrack.normalizedChi2 < 3 && combinedQuality.chi2LocalPosition < 12 && combinedQuality.trkKink < 20 && segmentCompatibility >= 0.303 || segmentCompatibility >= 0.451 )"),
48 electronSel=cms.string(
""),
49 tauSel=cms.string(
""),
50 photonSel=cms.string(
""),
51 jetName=cms.string(
"Jet"),muonName=cms.string(
"Muon"),electronName=cms.string(
"Electron"),
52 tauName=cms.string(
"Tau"),photonName=cms.string(
"Photon")
55 btagSFdir=
"PhysicsTools/NanoAOD/data/btagSF/"
57 btagWeightTable = cms.EDProducer(
"BTagSFProducer",
58 src = cms.InputTag(
"linkedObjects",
"jets"),
59 cut = cms.string(
"pt > 25. && abs(eta) < 2.5"),
60 discNames = cms.vstring(
61 "pfCombinedInclusiveSecondaryVertexV2BJetTags",
62 "pfDeepCSVJetTags:probb+pfDeepCSVJetTags:probbb",
63 "pfCombinedMVAV2BJetTags"
65 discShortNames = cms.vstring(
70 weightFiles = cms.vstring(
71 btagSFdir+
"CSVv2_94XSF_V2_B_F.csv",
72 btagSFdir+
"DeepCSV_94XSF_V2_B_F.csv",
75 operatingPoints = cms.vstring(
"3",
"3",
"3"),
76 measurementTypesB = cms.vstring(
"iterativefit",
"iterativefit",
"iterativefit"),
77 measurementTypesC = cms.vstring(
"iterativefit",
"iterativefit",
"iterativefit"),
78 measurementTypesUDSG = cms.vstring(
"iterativefit",
"iterativefit",
"iterativefit"),
79 sysTypes = cms.vstring(
"central",
"central",
"central")
82 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
83 modifier.toModify(btagWeightTable,
84 cut = cms.string(
"pt > 25. && abs(eta) < 2.4"),
85 weightFiles = cms.vstring(
86 btagSFdir+
"CSVv2_Moriond17_B_H.csv",
88 btagSFdir+
"cMVAv2_Moriond17_B_H.csv"
93 lheInfoTable = cms.EDProducer(
"LHETablesProducer",
94 lheInfo = cms.VInputTag(cms.InputTag(
"externalLHEProducer"), cms.InputTag(
"source")),
95 precision = cms.int32(14),
96 storeLHEParticles = cms.bool(
True)
99 l1bits=cms.EDProducer(
"L1TriggerResultsConverter", src=cms.InputTag(
"gtStage2Digis"), legacyL1=cms.bool(
False),
100 storeUnprefireableBit=cms.bool(
True), src_ext=cms.InputTag(
"gtStage2Digis"))
101 (run2_miniAOD_80XLegacy | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1).toModify(l1bits, storeUnprefireableBit=
False)
103 nanoSequenceCommon = cms.Sequence(
104 nanoMetadata + jetSequence + muonSequence + tauSequence + electronSequence+photonSequence+vertexSequence+
105 isoTrackSequence + jetLepSequence +
107 jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + isoTrackTables
109 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTables + l1bits)
111 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyFullSim)
113 nanoSequenceFS = cms.Sequence(genParticleSequence + genVertexTables + particleLevelSequence + nanoSequenceCommon + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + ttbarCatMCProducers + globalTablesMC + btagWeightTable + genWeightsTable + genVertexTable + genParticleTables + particleLevelTables + lheInfoTable + ttbarCategoryTable )
115 (run2_nanoAOD_92X | run2_miniAOD_80XLegacy | run2_nanoAOD_94X2016 | run2_nanoAOD_94X2016 | \
116 run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | \
117 run2_nanoAOD_102Xv1).toReplaceWith(nanoSequenceFS, nanoSequenceFS.copyAndExclude([genVertexTable, genVertexT0Table]))
120 nanoSequenceMC = nanoSequenceFS.copy()
121 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
124 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1:
125 modifier.toModify(extraFlagsTable, variables= cms.PSet())
126 modifier.toModify(extraFlagsTable, variables = dict(Flag_ecalBadCalibFilterV2 =
ExtVar(cms.InputTag(
"ecalBadCalibFilterNanoTagger"), bool, doc =
"Bad ECAL calib flag (updated xtal list)")))
129 import RecoTauTag.RecoTau.tools.runTauIdMVA
as tauIdConfig
131 updatedTauName =
"slimmedTausUpdated"
132 tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug =
False, updatedTauName = updatedTauName,
133 toKeep = [
"deepTau2017v2p1" ])
134 tauIdEmbedder.runTauID()
135 process.patTauMVAIDsSeq.insert(process.patTauMVAIDsSeq.index(getattr(process, updatedTauName)),
136 process.rerunMvaIsolationSequence)
141 _btagDiscriminators=[]
143 print(
"Updating process to run DeepCSV btag")
144 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb',
'pfDeepCSVJetTags:probc']
146 print(
"Updating process to run DeepFlavour btag")
147 _btagDiscriminators += [
'pfDeepFlavourJetTags:probb',
'pfDeepFlavourJetTags:probbb',
'pfDeepFlavourJetTags:problepb',
'pfDeepFlavourJetTags:probc']
148 if len(_btagDiscriminators)==0:
return process
149 print(
"Will recalculate the following discriminators: "+
", ".
join(_btagDiscriminators))
152 jetSource = cms.InputTag(
'slimmedJets'),
153 jetCorrections = (
'AK4PFchs', cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
154 btagDiscriminators = _btagDiscriminators,
155 postfix =
'WithDeepInfo',
157 process.load(
"Configuration.StandardSequences.MagneticField_cff")
158 process.jetCorrFactorsNano.src=
"selectedUpdatedPatJetsWithDeepInfo"
159 process.updatedJets.jetSource=
"selectedUpdatedPatJetsWithDeepInfo"
163 if addDeepMETProducer:
165 print(
"add DeepMET Producers")
166 process.load(
'RecoMET.METPUSubtraction.deepMETProducer_cfi')
167 process.deepMETsResolutionTune = process.deepMETProducer.clone()
168 process.deepMETsResponseTune = process.deepMETProducer.clone()
170 process.deepMETsResponseTune.graph_path = ResponseTune_Graph.value()
171 process.metTables += process.deepMetTables
174 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
175 from PhysicsTools.PatAlgos.slimming.puppiForMET_cff
import makePuppiesFromMiniAOD
178 nanoAOD_DeepMET_switch = cms.PSet(
179 nanoAOD_addDeepMET_switch = cms.untracked.bool(
True),
180 nanoAOD_produceDeepMET_switch = cms.untracked.bool(
False),
181 ResponseTune_Graph = cms.untracked.string(
'RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2018.pb')
183 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
185 modifier.toModify(nanoAOD_DeepMET_switch, nanoAOD_produceDeepMET_switch = cms.untracked.bool(
True))
186 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
187 modifier.toModify(nanoAOD_DeepMET_switch, ResponseTune_Graph=cms.untracked.string(
"RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2016.pb"))
188 if nanoAOD_DeepMET_switch.nanoAOD_addDeepMET_switch:
190 addDeepMETProducer=nanoAOD_DeepMET_switch.nanoAOD_produceDeepMET_switch,
191 ResponseTune_Graph=nanoAOD_DeepMET_switch.ResponseTune_Graph)
194 extractDeepMETs = nanoAOD_DeepMET_switch.nanoAOD_addDeepMET_switch
and not nanoAOD_DeepMET_switch.nanoAOD_produceDeepMET_switch
197 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(process.jetSequence),cms.Sequence(process.fullPatMetSequence))
198 process.basicJetsForMetForT1METNano = process.basicJetsForMet.clone(
199 src = process.updatedJetsWithUserData.src,
201 type1JetPtThreshold = 0.0,
202 calcMuonSubtrRawPtAsValueMap = cms.bool(
True),
204 process.jetSequence.insert(process.jetSequence.index(process.updatedJetsWithUserData),cms.Sequence(process.basicJetsForMetForT1METNano))
205 process.updatedJetsWithUserData.userFloats.muonSubtrRawPt = cms.InputTag(
"basicJetsForMetForT1METNano:MuonSubtrRawPt")
206 process.corrT1METJetTable.src = process.finalJets.src
207 process.corrT1METJetTable.cut =
"pt<15 && abs(eta)<9.9"
208 for table
in process.jetTable, process.corrT1METJetTable:
209 table.variables.muonSubtrFactor =
Var(
"1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc=
"1-(muon-subtracted raw pt)/(raw pt)",precision=6)
210 process.metTables += process.corrT1METJetTable
212 nanoAOD_PuppiV15_switch = cms.PSet(
213 recoMetFromPFCs = cms.untracked.bool(
False),
214 reclusterJets = cms.untracked.bool(
False),
216 run2_nanoAOD_106Xv1.toModify(nanoAOD_PuppiV15_switch,recoMetFromPFCs=
True,reclusterJets=
True)
217 runMetCorAndUncFromMiniAOD(process,isData=isData,metType=
"Puppi",postfix=
"Puppi",jetFlavor=
"AK4PFPuppi", recoMetFromPFCs=
bool(nanoAOD_PuppiV15_switch.recoMetFromPFCs), reclusterJets=
bool(nanoAOD_PuppiV15_switch.reclusterJets))
218 if nanoAOD_PuppiV15_switch.reclusterJets:
222 addToProcessAndTask(
'ak4PuppiJets', ak4PFJets.clone (src =
'puppi', doAreaFastjet =
True, jetPtMin = 10.), process, task)
224 addJetCollection(process,
226 jetSource = cms.InputTag(
'ak4PuppiJets'),
227 algo =
'AK', rParam=0.4,
228 genJetCollection=cms.InputTag(
'slimmedGenJets'),
229 jetCorrections = (
'AK4PFPuppi', [
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual'],
'None'),
230 pfCandidates = cms.InputTag(
'packedPFCandidates'),
231 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
232 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
233 muSource =cms.InputTag(
'slimmedMuons'),
234 elSource = cms.InputTag(
'slimmedElectrons'),
235 genParticles= cms.InputTag(
'prunedGenParticles'),
236 getJetMCFlavour=
False
239 process.patJetsPuppi.addGenPartonMatch = cms.bool(
False)
240 process.patJetsPuppi.addGenJetMatch = cms.bool(
False)
241 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(process.jetSequence),cms.Sequence(process.puppiMETSequence+process.fullPatMetSequencePuppi))
247 for modname
in electron_id_modules_WorkingPoints_nanoAOD.modules:
249 process.electronSequence.insert(process.electronSequence.index(process.bitmapVIDForEle),process.egmGsfElectronIDSequence)
250 for modifier
in run2_egamma_2017,run2_egamma_2018,run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
251 modifier.toModify(process.electronMVAValueMapProducer, src =
"slimmedElectronsUpdated")
252 modifier.toModify(process.egmGsfElectronIDs, physicsObjectSrc =
"slimmedElectronsUpdated")
256 for modname
in photon_id_modules_WorkingPoints_nanoAOD.modules:
258 process.photonSequence.insert(process.photonSequence.index(bitmapVIDForPho),process.egmPhotonIDSequence)
259 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1:
260 modifier.toModify(process.photonMVAValueMapProducer, src =
"slimmedPhotonsTo106X")
261 modifier.toModify(process.egmPhotonIDs, physicsObjectSrc =
"slimmedPhotonsTo106X")
264 def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, jecPayload):
265 _btagDiscriminators=[]
267 print(
"Updating process to run DeepCSV btag to AK8 jets")
268 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb']
269 if addDeepBoostedJet:
270 print(
"Updating process to run DeepBoostedJet on datasets before 103X")
272 _btagDiscriminators += pfDeepBoostedJetTagsAll
274 print(
"Updating process to run ParticleNet before it's included in MiniAOD")
276 _btagDiscriminators += pfParticleNetJetTagsAll
278 print(
"Updating process to run DeepDoubleX on datasets before 104X")
279 _btagDiscriminators += [
'pfDeepDoubleBvLJetTags:probHbb', \
280 'pfDeepDoubleCvLJetTags:probHcc', \
281 'pfDeepDoubleCvBJetTags:probHcc', \
282 'pfMassIndependentDeepDoubleBvLJetTags:probHbb',
'pfMassIndependentDeepDoubleCvLJetTags:probHcc',
'pfMassIndependentDeepDoubleCvBJetTags:probHcc']
284 print(
"Updating process to run DeepDoubleXv2 on datasets before 11X")
285 _btagDiscriminators += [
286 'pfMassIndependentDeepDoubleBvLV2JetTags:probHbb',
287 'pfMassIndependentDeepDoubleCvLV2JetTags:probHcc',
288 'pfMassIndependentDeepDoubleCvBV2JetTags:probHcc'
290 if len(_btagDiscriminators)==0:
return process
291 print(
"Will recalculate the following discriminators on AK8 jets: "+
", ".
join(_btagDiscriminators))
294 jetSource = cms.InputTag(
'slimmedJetsAK8'),
295 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
296 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
298 jetCorrections = (jecPayload.value(), cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
299 btagDiscriminators = _btagDiscriminators,
300 postfix=
'AK8WithDeepInfo',
303 process.jetCorrFactorsAK8.src=
"selectedUpdatedPatJetsAK8WithDeepInfo"
304 process.updatedJetsAK8.jetSource=
"selectedUpdatedPatJetsAK8WithDeepInfo"
307 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
311 fixEE2017Params = {
'userawPt':
True,
'ptThreshold':50.0,
'minEtaThreshold':2.65,
'maxEtaThreshold': 3.139},
312 postfix =
"FixEE2017")
313 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(jetSequence),process.fullPatMetSequenceFixEE2017)
317 process.puppiNoLep.useExistingWeights =
True
318 process.puppi.useExistingWeights =
True
319 run2_nanoAOD_106Xv1.toModify(process.puppiNoLep, useExistingWeights =
False)
320 run2_nanoAOD_106Xv1.toModify(process.puppi, useExistingWeights =
False)
322 nanoAOD_addDeepInfo_switch = cms.PSet(
323 nanoAOD_addDeepBTag_switch = cms.untracked.bool(
False),
324 nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(
False),
326 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepBTag_switch = cms.untracked.bool(
True))
327 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
328 modifier.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(
True))
330 addDeepBTag=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepBTag_switch,
331 addDeepFlavour=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepFlavourTag_switch)
332 nanoAOD_addDeepInfoAK8_switch = cms.PSet(
333 nanoAOD_addDeepBTag_switch = cms.untracked.bool(
False),
334 nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(
False),
335 nanoAOD_addDeepDoubleX_switch = cms.untracked.bool(
False),
336 nanoAOD_addDeepDoubleXV2_switch = cms.untracked.bool(
False),
337 nanoAOD_addParticleNet_switch = cms.untracked.bool(
False),
338 jecPayload = cms.untracked.string(
'AK8PFPuppi')
341 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK8_switch,
342 nanoAOD_addDeepBTag_switch =
True,
343 jecPayload =
'AK8PFchs')
345 (run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1).toModify(
346 nanoAOD_addDeepInfoAK8_switch,
347 nanoAOD_addDeepBoostedJet_switch =
True,
348 nanoAOD_addDeepDoubleX_switch =
True,
349 nanoAOD_addDeepDoubleXV2_switch =
True,
350 nanoAOD_addParticleNet_switch =
True,
353 run2_nanoAOD_106Xv1.toModify(
354 nanoAOD_addDeepInfoAK8_switch,
355 nanoAOD_addDeepDoubleXV2_switch =
True,
356 nanoAOD_addParticleNet_switch =
True,
359 addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
360 addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
361 addDeepDoubleX=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleX_switch,
362 addDeepDoubleXV2=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleXV2_switch,
363 addParticleNet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNet_switch,
364 jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload)
365 (run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1 | run2_nanoAOD_106Xv1).toModify(process,
lambda p :
nanoAOD_addTauIds(p))
371 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
378 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
383 _80x_sequence = nanoSequenceCommon.copy()
385 _80x_sequence.remove(isoTrackTables)
386 _80x_sequence.remove(isoTrackSequence)
388 _80x_sequence.insert(_80x_sequence.index(jetSequence), extraFlagsProducers)
389 _80x_sequence.insert(_80x_sequence.index(simpleCleanerTable)+1, extraFlagsTable)
391 run2_miniAOD_80XLegacy.toReplaceWith( nanoSequenceCommon, _80x_sequence)
393 _102x_sequence = nanoSequenceCommon.copy()
395 _102x_sequence.insert(_102x_sequence.index(jetSequence),extraFlagsProducers102x)
396 _102x_sequence.insert(_102x_sequence.index(simpleCleanerTable)+1,extraFlagsTable)
398 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1:
399 modifier.toReplaceWith(nanoSequenceCommon, _102x_sequence)