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 nanoTableTaskCommon = cms.Task(
65 cms.Task(nanoMetadata), jetTask, extraFlagsProducersTask, muonTask, tauTask, boostedTauTask,
66 electronTask , lowPtElectronTask, photonTask,
67 vertexTask, isoTrackTask, jetLepTask,
68 cms.Task(linkedObjects),
69 jetTablesTask, muonTablesTask, tauTablesTask, boostedTauTablesTask,
70 electronTablesTask, lowPtElectronTablesTask, photonTablesTask,
71 globalTablesTask, vertexTablesTask, metTablesTask, simpleCleanerTable, extraFlagsTableTask,
75 nanoSequenceCommon = cms.Sequence(nanoTableTaskCommon)
77 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTablesTask)
78 nanoSequenceOnlyData = cms.Sequence(cms.Sequence(protonTablesTask) + lhcInfoTable)
80 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyData + nanoSequenceOnlyFullSim)
82 nanoTableTaskFS = cms.Task(genParticleTask, particleLevelTask, jetMCTask, muonMCTask, electronMCTask, lowPtElectronMCTask, photonMCTask,
83 tauMCTask, boostedTauMCTask,
84 metMCTable, ttbarCatMCProducersTask, globalTablesMCTask, cms.Task(btagWeightTable), ttbarCategoryTableTask,
85 genWeightsTableTask, genVertexTablesTask, genParticleTablesTask, particleLevelTablesTask)
87 nanoSequenceFS = cms.Sequence(nanoSequenceCommon + cms.Sequence(nanoTableTaskFS))
90 nanoSequenceMC = nanoSequenceFS.copy()
91 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
94 import RecoTauTag.RecoTau.tools.runTauIdMVA
as tauIdConfig
96 updatedTauName =
"slimmedTausUpdated"
97 tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug =
False, updatedTauName = updatedTauName,
98 toKeep = [
"deepTau2017v2p1" ])
99 tauIdEmbedder.runTauID()
100 _tauTask = patTauMVAIDsTask.copy()
101 _tauTask.add(process.rerunMvaIsolationTask)
102 _tauTask.add(finalTaus)
103 process.tauTask = _tauTask.copy()
107 updatedBoostedTauName =
"slimmedTausBoostedNewID"
108 boostedTauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug=
False,
109 originalTauName =
"slimmedTausBoosted",
110 updatedTauName = updatedBoostedTauName,
112 toKeep = [
"2017v2",
"dR0p32017v2",
"newDM2017v2",
"againstEle2018",])
113 boostedTauIdEmbedder.runTauID()
114 _boostedTauTask = process.rerunMvaIsolationTaskBoosted.copy()
115 _boostedTauTask.add(getattr(process, updatedBoostedTauName))
116 _boostedTauTask.add(process.finalBoostedTaus)
118 process.boostedTauTask = _boostedTauTask.copy()
125 _btagDiscriminators=[]
127 print(
"Updating process to run DeepCSV btag")
128 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb',
'pfDeepCSVJetTags:probc']
130 print(
"Updating process to run DeepFlavour btag")
131 _btagDiscriminators += [
'pfDeepFlavourJetTags:probb',
'pfDeepFlavourJetTags:probbb',
'pfDeepFlavourJetTags:problepb',
'pfDeepFlavourJetTags:probc']
132 if len(_btagDiscriminators)==0:
return process
133 print(
"Will recalculate the following discriminators: "+
", ".
join(_btagDiscriminators))
136 jetSource = cms.InputTag(
'slimmedJets'),
137 jetCorrections = (
'AK4PFchs', cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
138 btagDiscriminators = _btagDiscriminators,
139 postfix =
'WithDeepInfo',
141 process.load(
"Configuration.StandardSequences.MagneticField_cff")
142 process.jetCorrFactorsNano.src=
"selectedUpdatedPatJetsWithDeepInfo"
143 process.updatedJets.jetSource=
"selectedUpdatedPatJetsWithDeepInfo"
147 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
150 nanoAOD_DeepMET_switch = cms.PSet(
151 ResponseTune_Graph = cms.untracked.string(
'RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2018.pb')
153 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
154 modifier.toModify(nanoAOD_DeepMET_switch, ResponseTune_Graph=cms.untracked.string(
"RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2016.pb"))
156 print(
"add DeepMET Producers")
157 process.load(
'RecoMET.METPUSubtraction.deepMETProducer_cfi')
158 process.deepMETsResolutionTune = process.deepMETProducer.clone()
159 process.deepMETsResponseTune = process.deepMETProducer.clone()
160 process.deepMETsResponseTune.graph_path = nanoAOD_DeepMET_switch.ResponseTune_Graph.value()
163 process.nanoSequenceCommon.insert(2,cms.Sequence(process.fullPatMetSequence))
166 from PhysicsTools.PatAlgos.slimming.puppiForMET_cff
import makePuppiesFromMiniAOD
168 process.puppiNoLep.useExistingWeights =
True
169 process.puppi.useExistingWeights =
True
170 run2_nanoAOD_106Xv1.toModify(process.puppiNoLep, useExistingWeights =
False)
171 run2_nanoAOD_106Xv1.toModify(process.puppi, useExistingWeights =
False)
172 print(
"will make Puppies on top of MINIAOD")
175 nanoAOD_PuppiV15_switch = cms.PSet(
176 recoMetFromPFCs = cms.untracked.bool(
False),
177 reclusterJets = cms.untracked.bool(
False),
179 run2_nanoAOD_106Xv1.toModify(nanoAOD_PuppiV15_switch,recoMetFromPFCs=
True,reclusterJets=
True)
180 if nanoAOD_PuppiV15_switch.reclusterJets:
184 addToProcessAndTask(
'ak4PuppiJets', ak4PFJets.clone (src =
'puppi', doAreaFastjet =
True, jetPtMin = 10.), process, task)
186 addJetCollection(process,
188 jetSource = cms.InputTag(
'ak4PuppiJets'),
189 algo =
'AK', rParam=0.4,
190 genJetCollection=cms.InputTag(
'slimmedGenJets'),
191 jetCorrections = (
'AK4PFPuppi', [
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual'],
'None'),
192 pfCandidates = cms.InputTag(
'packedPFCandidates'),
193 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
194 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
195 muSource =cms.InputTag(
'slimmedMuons'),
196 elSource = cms.InputTag(
'slimmedElectrons'),
197 genParticles= cms.InputTag(
'prunedGenParticles'),
198 getJetMCFlavour=
False
201 process.patJetsPuppi.addGenPartonMatch = cms.bool(
False)
202 process.patJetsPuppi.addGenJetMatch = cms.bool(
False)
204 print(
"nanoAOD_PuppiV15_switch.reclusterJets is true")
206 runMetCorAndUncFromMiniAOD(process,isData=isData,metType=
"Puppi",postfix=
"Puppi",jetFlavor=
"AK4PFPuppi", recoMetFromPFCs=bool(nanoAOD_PuppiV15_switch.recoMetFromPFCs), reclusterJets=bool(nanoAOD_PuppiV15_switch.reclusterJets))
207 process.nanoSequenceCommon.insert(2,cms.Sequence(process.puppiMETSequence+process.fullPatMetSequencePuppi))
215 for modname
in electron_id_modules_WorkingPoints_nanoAOD.modules:
218 electronTask_ = process.egmGsfElectronIDTask.copy()
219 electronTask_.add(electronTask.copy())
220 process.electronTask = electronTask_.copy()
221 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
222 modifier.toModify(process.electronMVAValueMapProducer, src =
"slimmedElectronsUpdated")
223 modifier.toModify(process.egmGsfElectronIDs, physicsObjectSrc =
"slimmedElectronsUpdated")
226 for modname
in photon_id_modules_WorkingPoints_nanoAOD.modules:
229 photonTask_ = process.egmPhotonIDTask.copy()
230 photonTask_.add(photonTask.copy())
231 process.photonTask = photonTask_.copy()
232 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1:
233 modifier.toModify(process.photonMVAValueMapProducer, src =
"slimmedPhotonsTo106X")
234 modifier.toModify(process.egmPhotonIDs, physicsObjectSrc =
"slimmedPhotonsTo106X")
237 def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload):
238 _btagDiscriminators=[]
240 print(
"Updating process to run DeepCSV btag to AK8 jets")
241 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb']
242 if addDeepBoostedJet:
243 print(
"Updating process to run DeepBoostedJet on datasets before 103X")
245 _btagDiscriminators += pfDeepBoostedJetTagsAll
247 print(
"Updating process to run ParticleNet before it's included in MiniAOD")
249 _btagDiscriminators += pfParticleNetJetTagsAll
250 if addParticleNetMass:
252 _btagDiscriminators += _pfParticleNetMassRegressionOutputs
254 print(
"Updating process to run DeepDoubleX on datasets before 104X")
255 _btagDiscriminators += [
'pfDeepDoubleBvLJetTags:probHbb', \
256 'pfDeepDoubleCvLJetTags:probHcc', \
257 'pfDeepDoubleCvBJetTags:probHcc', \
258 'pfMassIndependentDeepDoubleBvLJetTags:probHbb',
'pfMassIndependentDeepDoubleCvLJetTags:probHcc',
'pfMassIndependentDeepDoubleCvBJetTags:probHcc']
260 print(
"Updating process to run DeepDoubleXv2 on datasets before 11X")
261 _btagDiscriminators += [
262 'pfMassIndependentDeepDoubleBvLV2JetTags:probHbb',
263 'pfMassIndependentDeepDoubleCvLV2JetTags:probHcc',
264 'pfMassIndependentDeepDoubleCvBV2JetTags:probHcc'
266 if len(_btagDiscriminators)==0:
return process
267 print(
"Will recalculate the following discriminators on AK8 jets: "+
", ".
join(_btagDiscriminators))
270 jetSource = cms.InputTag(
'slimmedJetsAK8'),
271 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
272 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
274 jetCorrections = (jecPayload.value(), cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
275 btagDiscriminators = _btagDiscriminators,
276 postfix=
'AK8WithDeepInfo',
279 process.jetCorrFactorsAK8.src=
"selectedUpdatedPatJetsAK8WithDeepInfo"
280 process.updatedJetsAK8.jetSource=
"selectedUpdatedPatJetsAK8WithDeepInfo"
283 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
287 fixEE2017Params = {
'userawPt':
True,
'ptThreshold':50.0,
'minEtaThreshold':2.65,
'maxEtaThreshold': 3.139},
288 postfix =
"FixEE2017")
289 process.nanoSequenceCommon.insert(2,process.fullPatMetSequenceFixEE2017)
293 process.basicJetsForMetForT1METNano = cms.EDProducer(
"PATJetCleanerForType1MET",
294 src = process.updatedJetsWithUserData.src,
295 jetCorrEtaMax = cms.double(9.9),
296 jetCorrLabel = cms.InputTag(
"L3Absolute"),
297 jetCorrLabelRes = cms.InputTag(
"L2L3Residual"),
298 offsetCorrLabel = cms.InputTag(
"L1FastJet"),
299 skipEM = cms.bool(
False),
300 skipEMfractionThreshold = cms.double(0.9),
301 skipMuonSelection = cms.string(
'isGlobalMuon | isStandAloneMuon'),
302 skipMuons = cms.bool(
True),
303 type1JetPtThreshold = cms.double(0.0),
304 calcMuonSubtrRawPtAsValueMap = cms.bool(
True)
307 process.jetTask.add(process.basicJetsForMetForT1METNano)
308 process.updatedJetsWithUserData.userFloats.muonSubtrRawPt = cms.InputTag(
"basicJetsForMetForT1METNano:MuonSubtrRawPt")
309 process.corrT1METJetTable.src = process.finalJets.src
310 process.corrT1METJetTable.cut =
"pt<15 && abs(eta)<9.9"
311 process.metTablesTask.add(process.corrT1METJetTable)
313 for table
in process.jetTable, process.corrT1METJetTable:
314 table.variables.muonSubtrFactor =
Var(
"1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc=
"1-(muon-subtracted raw pt)/(raw pt)",precision=6)
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 nanoAOD_addParticleNetMass_switch = cms.untracked.bool(
False),
339 jecPayload = cms.untracked.string(
'AK8PFPuppi')
342 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK8_switch,
343 nanoAOD_addDeepBTag_switch =
True,
344 jecPayload =
'AK8PFchs')
346 (run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1).toModify(
347 nanoAOD_addDeepInfoAK8_switch,
348 nanoAOD_addDeepBoostedJet_switch =
True,
349 nanoAOD_addDeepDoubleX_switch =
True,
350 nanoAOD_addDeepDoubleXV2_switch =
True,
351 nanoAOD_addParticleNet_switch =
True,
352 nanoAOD_addParticleNetMass_switch =
True,
355 run2_nanoAOD_106Xv1.toModify(
356 nanoAOD_addDeepInfoAK8_switch,
357 nanoAOD_addDeepDoubleXV2_switch =
True,
358 nanoAOD_addParticleNet_switch =
True,
359 nanoAOD_addParticleNetMass_switch =
True,
362 run2_nanoAOD_106Xv2.toModify(
363 nanoAOD_addDeepInfoAK8_switch,
364 nanoAOD_addParticleNetMass_switch =
True,
368 addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
369 addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
370 addDeepDoubleX=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleX_switch,
371 addDeepDoubleXV2=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleXV2_switch,
372 addParticleNet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNet_switch,
373 addParticleNetMass=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNetMass_switch,
374 jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload)
375 (run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1 | run2_nanoAOD_106Xv1).toModify(process,
lambda p :
nanoAOD_addTauIds(p))
376 (~(run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1 | run2_nanoAOD_106Xv1)).toModify(process,
lambda p :
nanoAOD_addBoostedTauIds(p))
382 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94X2016,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
384 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
390 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94X2016,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
392 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
398 pdgSelection=
"?(abs(pdgId) == 11|| abs(pdgId)==13 || abs(pdgId)==15 ||abs(pdgId)== 12 || abs(pdgId)== 14 || abs(pdgId)== 16|| abs(pdgId)== 24|| pdgId== 23)"
400 ptPrecision=
"{}?{}:{}".
format(pdgSelection, CandVars.pt.precision.value(),genParticleTable.variables.pt.precision.value())
401 process.genParticleTable.variables.pt.precision=cms.string(ptPrecision)
402 phiPrecision=
"{} ? {} : {}".
format(pdgSelection, CandVars.phi.precision.value(), genParticleTable.variables.phi.precision.value())
403 process.genParticleTable.variables.phi.precision=cms.string(phiPrecision)
404 etaPrecision=
"{} ? {} : {}".
format(pdgSelection, CandVars.eta.precision.value(), genParticleTable.variables.eta.precision.value())
405 process.genParticleTable.variables.eta.precision=cms.string(etaPrecision)
def nanoAOD_customizeCommon
def nanoAOD_customizeData
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def nanoAOD_runMETfixEE2017
static std::string join(char **cmd)
def nanoWmassGenCustomize
increasing the precision of selected GenParticles.
def nanoAOD_addDeepInfoAK8
def runMetCorAndUncFromMiniAOD
def nanoAOD_addBoostedTauIds
def nanoAOD_recalibrateMETs