1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
28 nanoMetadata = cms.EDProducer(
"UniqueStringProducer",
30 tag = cms.string(
"untagged"),
34 linkedObjects = cms.EDProducer(
"PATObjectCrossLinker",
35 jets=cms.InputTag(
"finalJets"),
36 muons=cms.InputTag(
"finalMuons"),
37 electrons=cms.InputTag(
"finalElectrons"),
38 taus=cms.InputTag(
"finalTaus"),
39 photons=cms.InputTag(
"finalPhotons"),
42 simpleCleanerTable = cms.EDProducer(
"NanoAODSimpleCrossCleaner",
43 name=cms.string(
"cleanmask"),
44 doc=cms.string(
"simple cleaning mask with priority to leptons"),
45 jets=cms.InputTag(
"linkedObjects",
"jets"),
46 muons=cms.InputTag(
"linkedObjects",
"muons"),
47 electrons=cms.InputTag(
"linkedObjects",
"electrons"),
48 taus=cms.InputTag(
"linkedObjects",
"taus"),
49 photons=cms.InputTag(
"linkedObjects",
"photons"),
50 jetSel=cms.string(
"pt>15"),
51 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 )"),
52 electronSel=cms.string(
""),
53 tauSel=cms.string(
""),
54 photonSel=cms.string(
""),
55 jetName=cms.string(
"Jet"),muonName=cms.string(
"Muon"),electronName=cms.string(
"Electron"),
56 tauName=cms.string(
"Tau"),photonName=cms.string(
"Photon")
60 lhcInfoTable = cms.EDProducer(
"LHCInfoProducer",
61 precision = cms.int32(10),
64 nanoSequenceCommon = cms.Sequence(
65 nanoMetadata + jetSequence + cms.Sequence(extraFlagsProducersTask, muonTask, tauTask, boostedTauTask, electronTask, lowPtElectronTask, photonTask,
66 vertexTablesTask,isoTrackTask) + jetLepSequence +
68 jetTables + cms.Sequence(muonTablesTask, tauTablesTask, boostedTauTablesTask, electronTablesTask, lowPtElectronTablesTask, photonTablesTask, globalTablesTask) + metTables + simpleCleanerTable + cms.Sequence(extraFlagsTableTask,isoTrackTablesTask)
71 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTablesTask)
72 nanoSequenceOnlyData = cms.Sequence(cms.Sequence(protonTablesTask) + lhcInfoTable)
74 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyData + nanoSequenceOnlyFullSim)
76 nanoSequenceFS = cms.Sequence(
77 cms.Sequence(genParticleTask,particleLevelTask) + nanoSequenceCommon + jetMC + cms.Sequence(muonMCTask, electronMCTask, lowPtElectronMCTask, photonMCTask,
78 tauMCTask,boostedTauMCTask) + metMC +
79 cms.Sequence(ttbarCatMCProducersTask,globalTablesMCTask,cms.Task(btagWeightTable),genWeightsTableTask,genVertexTablesTask,genParticleTablesTask,particleLevelTablesTask,ttbarCategoryTableTask) )
82 nanoSequenceMC = nanoSequenceFS.copy()
83 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
86 import RecoTauTag.RecoTau.tools.runTauIdMVA
as tauIdConfig
88 updatedTauName =
"slimmedTausUpdated"
89 tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug =
False, updatedTauName = updatedTauName,
90 toKeep = [
"deepTau2017v2p1" ])
91 tauIdEmbedder.runTauID()
92 _tauTask = patTauMVAIDsTask.copy()
93 _tauTask.add(process.rerunMvaIsolationTask)
94 _tauTask.add(finalTaus)
95 process.tauTask = _tauTask.copy()
99 updatedBoostedTauName =
"slimmedTausBoostedNewID"
100 boostedTauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug=
False,
101 originalTauName =
"slimmedTausBoosted",
102 updatedTauName = updatedBoostedTauName,
104 toKeep = [
"2017v2",
"dR0p32017v2",
"newDM2017v2",
"againstEle2018",])
105 boostedTauIdEmbedder.runTauID()
106 _boostedTauTask = process.rerunMvaIsolationTaskBoosted.copy()
107 _boostedTauTask.add(getattr(process, updatedBoostedTauName))
108 _boostedTauTask.add(process.finalBoostedTaus)
110 process.boostedTauTask = _boostedTauTask.copy()
117 _btagDiscriminators=[]
119 print(
"Updating process to run DeepCSV btag")
120 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb',
'pfDeepCSVJetTags:probc']
122 print(
"Updating process to run DeepFlavour btag")
123 _btagDiscriminators += [
'pfDeepFlavourJetTags:probb',
'pfDeepFlavourJetTags:probbb',
'pfDeepFlavourJetTags:problepb',
'pfDeepFlavourJetTags:probc']
124 if len(_btagDiscriminators)==0:
return process
125 print(
"Will recalculate the following discriminators: "+
", ".
join(_btagDiscriminators))
128 jetSource = cms.InputTag(
'slimmedJets'),
129 jetCorrections = (
'AK4PFchs', cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
130 btagDiscriminators = _btagDiscriminators,
131 postfix =
'WithDeepInfo',
133 process.load(
"Configuration.StandardSequences.MagneticField_cff")
134 process.jetCorrFactorsNano.src=
"selectedUpdatedPatJetsWithDeepInfo"
135 process.updatedJets.jetSource=
"selectedUpdatedPatJetsWithDeepInfo"
139 if addDeepMETProducer:
141 print(
"add DeepMET Producers")
142 process.load(
'RecoMET.METPUSubtraction.deepMETProducer_cfi')
144 process.deepMETsResponseTune = process.deepMETProducer.clone()
146 process.deepMETsResponseTune.graph_path = ResponseTune_Graph.value()
147 process.metTables += process.deepMetTables
150 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
151 from PhysicsTools.PatAlgos.slimming.puppiForMET_cff
import makePuppiesFromMiniAOD
155 nanoAOD_DeepMET_switch = cms.PSet(
156 nanoAOD_addDeepMET_switch = cms.untracked.bool(
True),
157 nanoAOD_produceDeepMET_switch = cms.untracked.bool(
False),
158 ResponseTune_Graph = cms.untracked.string(
'RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2018.pb')
160 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
162 modifier.toModify(nanoAOD_DeepMET_switch, nanoAOD_produceDeepMET_switch = cms.untracked.bool(
True))
163 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
164 modifier.toModify(nanoAOD_DeepMET_switch, ResponseTune_Graph=cms.untracked.string(
"RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2016.pb"))
165 if nanoAOD_DeepMET_switch.nanoAOD_addDeepMET_switch:
167 addDeepMETProducer=nanoAOD_DeepMET_switch.nanoAOD_produceDeepMET_switch,
168 ResponseTune_Graph=nanoAOD_DeepMET_switch.ResponseTune_Graph)
171 extractDeepMETs = nanoAOD_DeepMET_switch.nanoAOD_addDeepMET_switch
and not nanoAOD_DeepMET_switch.nanoAOD_produceDeepMET_switch
174 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(process.jetSequence),cms.Sequence(process.fullPatMetSequence))
175 process.basicJetsForMetForT1METNano = process.basicJetsForMet.clone(
176 src = process.updatedJetsWithUserData.src,
178 type1JetPtThreshold = 0.0,
179 calcMuonSubtrRawPtAsValueMap = cms.bool(
True),
181 process.jetSequence.insert(process.jetSequence.index(process.updatedJetsWithUserData),cms.Sequence(process.basicJetsForMetForT1METNano))
182 process.updatedJetsWithUserData.userFloats.muonSubtrRawPt = cms.InputTag(
"basicJetsForMetForT1METNano:MuonSubtrRawPt")
183 process.corrT1METJetTable.src = process.finalJets.src
184 process.corrT1METJetTable.cut =
"pt<15 && abs(eta)<9.9"
185 for table
in process.jetTable, process.corrT1METJetTable:
186 table.variables.muonSubtrFactor =
Var(
"1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc=
"1-(muon-subtracted raw pt)/(raw pt)",precision=6)
187 process.metTables += process.corrT1METJetTable
192 nanoAOD_PuppiV15_switch = cms.PSet(
193 recoMetFromPFCs = cms.untracked.bool(
False),
194 reclusterJets = cms.untracked.bool(
False),
196 run2_nanoAOD_106Xv1.toModify(nanoAOD_PuppiV15_switch,recoMetFromPFCs=
True,reclusterJets=
True)
197 if nanoAOD_PuppiV15_switch.reclusterJets:
201 addToProcessAndTask(
'ak4PuppiJets', ak4PFJets.clone (src =
'puppi', doAreaFastjet =
True, jetPtMin = 10.), process, task)
203 addJetCollection(process,
205 jetSource = cms.InputTag(
'ak4PuppiJets'),
206 algo =
'AK', rParam=0.4,
207 genJetCollection=cms.InputTag(
'slimmedGenJets'),
208 jetCorrections = (
'AK4PFPuppi', [
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual'],
'None'),
209 pfCandidates = cms.InputTag(
'packedPFCandidates'),
210 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
211 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
212 muSource =cms.InputTag(
'slimmedMuons'),
213 elSource = cms.InputTag(
'slimmedElectrons'),
214 genParticles= cms.InputTag(
'prunedGenParticles'),
215 getJetMCFlavour=
False
218 process.patJetsPuppi.addGenPartonMatch = cms.bool(
False)
219 process.patJetsPuppi.addGenJetMatch = cms.bool(
False)
221 runMetCorAndUncFromMiniAOD(process,isData=isData,metType=
"Puppi",postfix=
"Puppi",jetFlavor=
"AK4PFPuppi", recoMetFromPFCs=
bool(nanoAOD_PuppiV15_switch.recoMetFromPFCs), reclusterJets=
bool(nanoAOD_PuppiV15_switch.reclusterJets))
222 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(process.jetSequence),cms.Sequence(process.puppiMETSequence+process.fullPatMetSequencePuppi))
229 for modname
in electron_id_modules_WorkingPoints_nanoAOD.modules:
232 electronTask_ = process.egmGsfElectronIDTask.copy()
233 electronTask_.add(electronTask.copy())
234 process.electronTask = electronTask_.copy()
235 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
236 modifier.toModify(process.electronMVAValueMapProducer, src =
"slimmedElectronsUpdated")
237 modifier.toModify(process.egmGsfElectronIDs, physicsObjectSrc =
"slimmedElectronsUpdated")
240 for modname
in photon_id_modules_WorkingPoints_nanoAOD.modules:
243 photonTask_ = process.egmPhotonIDTask.copy()
244 photonTask_.add(photonTask.copy())
245 process.photonTask = photonTask_.copy()
246 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1:
247 modifier.toModify(process.photonMVAValueMapProducer, src =
"slimmedPhotonsTo106X")
248 modifier.toModify(process.egmPhotonIDs, physicsObjectSrc =
"slimmedPhotonsTo106X")
251 def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload):
252 _btagDiscriminators=[]
254 print(
"Updating process to run DeepCSV btag to AK8 jets")
255 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb']
256 if addDeepBoostedJet:
257 print(
"Updating process to run DeepBoostedJet on datasets before 103X")
259 _btagDiscriminators += pfDeepBoostedJetTagsAll
261 print(
"Updating process to run ParticleNet before it's included in MiniAOD")
263 _btagDiscriminators += pfParticleNetJetTagsAll
264 if addParticleNetMass:
266 _btagDiscriminators += _pfParticleNetMassRegressionOutputs
268 print(
"Updating process to run DeepDoubleX on datasets before 104X")
269 _btagDiscriminators += [
'pfDeepDoubleBvLJetTags:probHbb', \
270 'pfDeepDoubleCvLJetTags:probHcc', \
271 'pfDeepDoubleCvBJetTags:probHcc', \
272 'pfMassIndependentDeepDoubleBvLJetTags:probHbb',
'pfMassIndependentDeepDoubleCvLJetTags:probHcc',
'pfMassIndependentDeepDoubleCvBJetTags:probHcc']
274 print(
"Updating process to run DeepDoubleXv2 on datasets before 11X")
275 _btagDiscriminators += [
276 'pfMassIndependentDeepDoubleBvLV2JetTags:probHbb',
277 'pfMassIndependentDeepDoubleCvLV2JetTags:probHcc',
278 'pfMassIndependentDeepDoubleCvBV2JetTags:probHcc'
280 if len(_btagDiscriminators)==0:
return process
281 print(
"Will recalculate the following discriminators on AK8 jets: "+
", ".
join(_btagDiscriminators))
284 jetSource = cms.InputTag(
'slimmedJetsAK8'),
285 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
286 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
288 jetCorrections = (jecPayload.value(), cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
289 btagDiscriminators = _btagDiscriminators,
290 postfix=
'AK8WithDeepInfo',
293 process.jetCorrFactorsAK8.src=
"selectedUpdatedPatJetsAK8WithDeepInfo"
294 process.updatedJetsAK8.jetSource=
"selectedUpdatedPatJetsAK8WithDeepInfo"
297 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
301 fixEE2017Params = {
'userawPt':
True,
'ptThreshold':50.0,
'minEtaThreshold':2.65,
'maxEtaThreshold': 3.139},
302 postfix =
"FixEE2017")
303 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(jetSequence),process.fullPatMetSequenceFixEE2017)
307 process.puppiNoLep.useExistingWeights =
True
308 process.puppi.useExistingWeights =
True
309 run2_nanoAOD_106Xv1.toModify(process.puppiNoLep, useExistingWeights =
False)
310 run2_nanoAOD_106Xv1.toModify(process.puppi, useExistingWeights =
False)
312 nanoAOD_addDeepInfo_switch = cms.PSet(
313 nanoAOD_addDeepBTag_switch = cms.untracked.bool(
False),
314 nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(
False),
316 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepBTag_switch = cms.untracked.bool(
True))
317 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
318 modifier.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(
True))
320 addDeepBTag=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepBTag_switch,
321 addDeepFlavour=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepFlavourTag_switch)
322 nanoAOD_addDeepInfoAK8_switch = cms.PSet(
323 nanoAOD_addDeepBTag_switch = cms.untracked.bool(
False),
324 nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(
False),
325 nanoAOD_addDeepDoubleX_switch = cms.untracked.bool(
False),
326 nanoAOD_addDeepDoubleXV2_switch = cms.untracked.bool(
False),
327 nanoAOD_addParticleNet_switch = cms.untracked.bool(
False),
328 nanoAOD_addParticleNetMass_switch = cms.untracked.bool(
False),
329 jecPayload = cms.untracked.string(
'AK8PFPuppi')
332 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK8_switch,
333 nanoAOD_addDeepBTag_switch =
True,
334 jecPayload =
'AK8PFchs')
336 (run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1).toModify(
337 nanoAOD_addDeepInfoAK8_switch,
338 nanoAOD_addDeepBoostedJet_switch =
True,
339 nanoAOD_addDeepDoubleX_switch =
True,
340 nanoAOD_addDeepDoubleXV2_switch =
True,
341 nanoAOD_addParticleNet_switch =
True,
342 nanoAOD_addParticleNetMass_switch =
True,
345 run2_nanoAOD_106Xv1.toModify(
346 nanoAOD_addDeepInfoAK8_switch,
347 nanoAOD_addDeepDoubleXV2_switch =
True,
348 nanoAOD_addParticleNet_switch =
True,
349 nanoAOD_addParticleNetMass_switch =
True,
352 run2_nanoAOD_106Xv2.toModify(
353 nanoAOD_addDeepInfoAK8_switch,
354 nanoAOD_addParticleNetMass_switch =
True,
358 addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
359 addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
360 addDeepDoubleX=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleX_switch,
361 addDeepDoubleXV2=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleXV2_switch,
362 addParticleNet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNet_switch,
363 addParticleNetMass=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNetMass_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))
366 (~(run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1 | run2_nanoAOD_106Xv1)).toModify(process,
lambda p :
nanoAOD_addBoostedTauIds(p))
372 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
379 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
385 pdgSelection=
"?(abs(pdgId) == 11|| abs(pdgId)==13 || abs(pdgId)==15 ||abs(pdgId)== 12 || abs(pdgId)== 14 || abs(pdgId)== 16|| abs(pdgId)== 24|| pdgId== 23)"
387 ptPrecision=
"{}?{}:{}".
format(pdgSelection, CandVars.pt.precision.value(),genParticleTable.variables.pt.precision.value())
388 process.genParticleTable.variables.pt.precision=cms.string(ptPrecision)
389 phiPrecision=
"{} ? {} : {}".
format(pdgSelection, CandVars.phi.precision.value(), genParticleTable.variables.phi.precision.value())
390 process.genParticleTable.variables.phi.precision=cms.string(phiPrecision)
391 etaPrecision=
"{} ? {} : {}".
format(pdgSelection, CandVars.eta.precision.value(), genParticleTable.variables.eta.precision.value())
392 process.genParticleTable.variables.eta.precision=cms.string(etaPrecision)