1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
32 nanoMetadata = cms.EDProducer(
"UniqueStringProducer",
34 tag = cms.string(
"untagged"),
38 linkedObjects = cms.EDProducer(
"PATObjectCrossLinker",
39 jets=cms.InputTag(
"finalJetsPuppi"),
40 muons=cms.InputTag(
"finalMuons"),
41 electrons=cms.InputTag(
"finalElectrons"),
42 lowPtElectrons=cms.InputTag(
"finalLowPtElectrons"),
43 taus=cms.InputTag(
"finalTaus"),
44 photons=cms.InputTag(
"finalPhotons"),
48 run2_nanoAOD_ANY.toModify(linkedObjects, jets=
"finalJets")
50 simpleCleanerTable = cms.EDProducer(
"NanoAODSimpleCrossCleaner",
51 name=cms.string(
"cleanmask"),
52 doc=cms.string(
"simple cleaning mask with priority to leptons"),
53 jets=cms.InputTag(
"linkedObjects",
"jets"),
54 muons=cms.InputTag(
"linkedObjects",
"muons"),
55 electrons=cms.InputTag(
"linkedObjects",
"electrons"),
56 lowPtElectrons=cms.InputTag(
"linkedObjects",
"lowPtElectrons"),
57 taus=cms.InputTag(
"linkedObjects",
"taus"),
58 photons=cms.InputTag(
"linkedObjects",
"photons"),
59 jetSel=cms.string(
"pt>15"),
60 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 )"),
61 electronSel=cms.string(
""),
62 lowPtElectronSel=cms.string(
""),
63 tauSel=cms.string(
""),
64 photonSel=cms.string(
""),
65 jetName=cms.string(
"Jet"),muonName=cms.string(
"Muon"),electronName=cms.string(
"Electron"),
66 lowPtElectronName=cms.string(
"LowPtElectron"),
67 tauName=cms.string(
"Tau"),photonName=cms.string(
"Photon")
71 lhcInfoTable = cms.EDProducer(
"LHCInfoProducer",
72 precision = cms.int32(10),
75 nanoTableTaskCommon = cms.Task(
76 cms.Task(nanoMetadata),
77 jetPuppiTask, jetPuppiForMETTask, jetAK8Task,
78 extraFlagsProducersTask, muonTask, tauTask, boostedTauTask,
79 electronTask , lowPtElectronTask, photonTask,
80 vertexTask, isoTrackTask, jetAK8LepTask,
82 cms.Task(linkedObjects),
83 jetPuppiTablesTask, jetAK8TablesTask,
84 muonTablesTask, fsrTablesTask, tauTablesTask, boostedTauTablesTask,
85 electronTablesTask, lowPtElectronTablesTask, photonTablesTask,
86 globalTablesTask, vertexTablesTask, metTablesTask, simpleCleanerTable, extraFlagsTableTask,
87 isoTrackTablesTask,softActivityTablesTask
91 _nanoTableTaskCommonRun2 = nanoTableTaskCommon.copy()
92 _nanoTableTaskCommonRun2.replace(jetPuppiTask, jetTask)
93 _nanoTableTaskCommonRun2.replace(jetPuppiForMETTask, jetForMETTask)
94 _nanoTableTaskCommonRun2.replace(jetPuppiTablesTask, jetTablesTask)
95 run2_nanoAOD_ANY.toReplaceWith(nanoTableTaskCommon, _nanoTableTaskCommonRun2)
97 nanoSequenceCommon = cms.Sequence(nanoTableTaskCommon)
99 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTablesTask)
100 nanoSequenceOnlyData = cms.Sequence(cms.Sequence(protonTablesTask) + lhcInfoTable)
102 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyData + nanoSequenceOnlyFullSim)
104 nanoTableTaskFS = cms.Task(
105 genParticleTask, particleLevelTask, jetMCTask, muonMCTask, electronMCTask, lowPtElectronMCTask, photonMCTask,
106 tauMCTask, boostedTauMCTask,
107 metMCTable, ttbarCatMCProducersTask, globalTablesMCTask, cms.Task(btagWeightTable), ttbarCategoryTableTask,
108 genWeightsTableTask, genVertexTablesTask, genParticleTablesTask, genProtonTablesTask, particleLevelTablesTask
111 nanoSequenceFS = cms.Sequence(nanoSequenceCommon + cms.Sequence(nanoTableTaskFS))
114 nanoSequenceMC = nanoSequenceFS.copy()
115 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
118 import RecoTauTag.RecoTau.tools.runTauIdMVA
as tauIdConfig
121 updatedTauName =
"slimmedTausUpdated" 122 tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug =
False,
123 updatedTauName = updatedTauName,
125 tauIdEmbedder.runTauID()
126 _tauTask = patTauMVAIDsTask.copy()
127 _tauTask.add(process.rerunMvaIsolationTask)
128 _tauTask.add(finalTaus)
129 process.finalTaus.src = updatedTauName
132 process.tauTask = _tauTask.copy()
138 updatedBoostedTauName =
"slimmedTausBoostedNewID" 139 boostedTauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug =
False,
140 originalTauName =
"slimmedTausBoosted",
141 updatedTauName = updatedBoostedTauName,
144 boostedTauIdEmbedder.runTauID()
145 _boostedTauTask = process.rerunMvaIsolationTaskBoosted.copy()
146 _boostedTauTask.add(getattr(process, updatedBoostedTauName))
147 _boostedTauTask.add(process.finalBoostedTaus)
148 process.finalBoostedTaus.src = updatedBoostedTauName
151 process.boostedTauTask = _boostedTauTask.copy()
155 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
158 nanoAOD_DeepMET_switch = cms.PSet(
159 ResponseTune_Graph = cms.untracked.string(
'RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2018.pb')
161 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
162 modifier.toModify(nanoAOD_DeepMET_switch, ResponseTune_Graph=cms.untracked.string(
"RecoMET/METPUSubtraction/data/deepmet/deepmet_resp_v1_2016.pb"))
164 print(
"add DeepMET Producers")
165 process.load(
'RecoMET.METPUSubtraction.deepMETProducer_cfi')
166 process.deepMETsResolutionTune = process.deepMETProducer.clone()
167 process.deepMETsResponseTune = process.deepMETProducer.clone()
168 process.deepMETsResponseTune.graph_path = nanoAOD_DeepMET_switch.ResponseTune_Graph.value()
171 process.nanoSequenceCommon.insert(2,cms.Sequence(process.fullPatMetSequence))
174 from PhysicsTools.PatAlgos.slimming.puppiForMET_cff
import makePuppiesFromMiniAOD
176 process.puppiNoLep.useExistingWeights =
True 177 process.puppi.useExistingWeights =
True 178 run2_nanoAOD_106Xv1.toModify(process.puppiNoLep, useExistingWeights =
False)
179 run2_nanoAOD_106Xv1.toModify(process.puppi, useExistingWeights =
False)
180 print(
"will make Puppies on top of MINIAOD")
183 nanoAOD_PuppiV15_switch = cms.PSet(
184 recoMetFromPFCs = cms.untracked.bool(
False),
185 reclusterJets = cms.untracked.bool(
False),
187 run2_nanoAOD_106Xv1.toModify(nanoAOD_PuppiV15_switch,recoMetFromPFCs=
True,reclusterJets=
True)
188 if nanoAOD_PuppiV15_switch.reclusterJets:
192 addToProcessAndTask(
'ak4PuppiJets', ak4PFJets.clone (src =
'puppi', doAreaFastjet =
True, jetPtMin = 10.), process, task)
194 addJetCollection(process,
196 jetSource = cms.InputTag(
'ak4PuppiJets'),
197 algo =
'AK', rParam=0.4,
198 genJetCollection=cms.InputTag(
'slimmedGenJets'),
199 jetCorrections = (
'AK4PFPuppi', [
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual'],
'None'),
200 pfCandidates = cms.InputTag(
'packedPFCandidates'),
201 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
202 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
203 muSource =cms.InputTag(
'slimmedMuons'),
204 elSource = cms.InputTag(
'slimmedElectrons'),
205 genParticles= cms.InputTag(
'prunedGenParticles'),
206 getJetMCFlavour=
False 209 process.patJetsPuppi.addGenPartonMatch = cms.bool(
False)
210 process.patJetsPuppi.addGenJetMatch = cms.bool(
False)
212 print(
"nanoAOD_PuppiV15_switch.reclusterJets is true")
214 runMetCorAndUncFromMiniAOD(process,isData=isData,metType=
"Puppi",postfix=
"Puppi",jetFlavor=
"AK4PFPuppi", recoMetFromPFCs=
bool(nanoAOD_PuppiV15_switch.recoMetFromPFCs), reclusterJets=
bool(nanoAOD_PuppiV15_switch.reclusterJets))
215 process.nanoSequenceCommon.insert(2,cms.Sequence(process.puppiMETSequence+process.fullPatMetSequencePuppi))
223 for modname
in electron_id_modules_WorkingPoints_nanoAOD.modules:
226 electronTask_ = process.egmGsfElectronIDTask.copy()
227 electronTask_.add(electronTask.copy())
228 process.electronTask = electronTask_.copy()
229 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
230 modifier.toModify(process.electronMVAValueMapProducer, src =
"slimmedElectronsUpdated")
231 modifier.toModify(process.egmGsfElectronIDs, physicsObjectSrc =
"slimmedElectronsUpdated")
234 for modname
in photon_id_modules_WorkingPoints_nanoAOD.modules:
237 photonTask_ = process.egmPhotonIDTask.copy()
238 photonTask_.add(photonTask.copy())
239 process.photonTask = photonTask_.copy()
240 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_94X2016,run2_nanoAOD_102Xv1:
241 modifier.toModify(process.photonMVAValueMapProducer, src =
"slimmedPhotonsTo106X")
242 modifier.toModify(process.egmPhotonIDs, physicsObjectSrc =
"slimmedPhotonsTo106X")
245 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
249 fixEE2017Params = {
'userawPt':
True,
'ptThreshold':50.0,
'minEtaThreshold':2.65,
'maxEtaThreshold': 3.139},
250 postfix =
"FixEE2017")
251 process.nanoSequenceCommon.insert(2,process.fullPatMetSequenceFixEE2017)
260 addDeepBTag=nanoAOD_addDeepInfoAK4CHS_switch.nanoAOD_addDeepBTag_switch,
261 addDeepFlavour=nanoAOD_addDeepInfoAK4CHS_switch.nanoAOD_addDeepFlavourTag_switch
266 addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
267 addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
268 addDeepDoubleX=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleX_switch,
269 addDeepDoubleXV2=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleXV2_switch,
270 addParticleNet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNet_switch,
271 addParticleNetMass=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNetMass_switch,
272 jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload
275 nanoAOD_tau_switch = cms.PSet(
276 idsToAdd = cms.vstring()
278 (run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1 | run2_nanoAOD_106Xv1).toModify(nanoAOD_tau_switch, idsToAdd = [
"deepTau2017v2p1"])
279 (run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1 | run2_nanoAOD_106Xv1).toModify(process,
lambda p :
nanoAOD_addTauIds(p, nanoAOD_tau_switch.idsToAdd.value()))
280 nanoAOD_boostedTau_switch = cms.PSet(
281 idsToAdd = cms.vstring()
283 run2_nanoAOD_106Xv2.toModify(nanoAOD_boostedTau_switch, idsToAdd = [
"2017v2",
"dR0p32017v2",
"newDM2017v2",
"againstEle2018"])
284 run2_nanoAOD_106Xv2.toModify(process,
lambda p :
nanoAOD_addBoostedTauIds(p, nanoAOD_boostedTau_switch.idsToAdd.value()))
290 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94X2016,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
292 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
298 for modifier
in run2_miniAOD_80XLegacy,run2_nanoAOD_94X2016,run2_nanoAOD_94XMiniAODv1,run2_nanoAOD_94XMiniAODv2,run2_nanoAOD_102Xv1,run2_nanoAOD_106Xv1:
300 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
306 pdgSelection=
"?(abs(pdgId) == 11|| abs(pdgId)==13 || abs(pdgId)==15 ||abs(pdgId)== 12 || abs(pdgId)== 14 || abs(pdgId)== 16|| abs(pdgId)== 24|| pdgId== 23)" 308 ptPrecision=
"{}?{}:{}".
format(pdgSelection, CandVars.pt.precision.value(),genParticleTable.variables.pt.precision.value())
309 process.genParticleTable.variables.pt.precision=cms.string(ptPrecision)
310 phiPrecision=
"{} ? {} : {}".
format(pdgSelection, CandVars.phi.precision.value(), genParticleTable.variables.phi.precision.value())
311 process.genParticleTable.variables.phi.precision=cms.string(phiPrecision)
312 etaPrecision=
"{} ? {} : {}".
format(pdgSelection, CandVars.eta.precision.value(), genParticleTable.variables.eta.precision.value())
313 process.genParticleTable.variables.eta.precision=cms.string(etaPrecision)
317 _modifiers = ( run2_miniAOD_80XLegacy |
318 run2_nanoAOD_94XMiniAODv1 |
319 run2_nanoAOD_94XMiniAODv2 |
320 run2_nanoAOD_94X2016 |
321 run2_nanoAOD_102Xv1 |
322 run2_nanoAOD_106Xv1 )
323 _modifiers.toModify(linkedObjects,lowPtElectrons=
"")
324 _modifiers.toModify(simpleCleanerTable,lowPtElectrons=
"")
def addToProcessAndTask(label, module, process, task)
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload)
def nanoAOD_customizeMC(process)
def nanoAOD_activateVID(process)
def nanoWmassGenCustomize(process)
increasing the precision of selected GenParticles.
def nanoAOD_customizeCommon(process)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def nanoAOD_recalibrateMETs(process, isData)
def nanoAOD_addTauIds(process, idsToRun=[])
def nanoAOD_runMETfixEE2017(process, isData)
def nanoAOD_addBoostedTauIds(process, idsToRun=[])
def nanoAOD_addDeepInfoAK4CHS(process, addDeepBTag, addDeepFlavour)
def getPatAlgosToolsTask(process)
def runMetCorAndUncFromMiniAOD(process, metType="PF", jetCollUnskimmed="slimmedJets", photonColl="slimmedPhotons", electronColl="slimmedElectrons", muonColl="slimmedMuons", tauColl="slimmedTaus", pfCandColl="packedPFCandidates", jetFlavor="AK4PFchs", jetCleaning="LepClean", isData=False, manualJetConfig=False, reclusterJets=None, jetSelection="pt>15 && abs(eta)<9.9", recoMetFromPFCs=None, jetCorLabelL3="ak4PFCHSL1FastL2L3Corrector", jetCorLabelRes="ak4PFCHSL1FastL2L3ResidualCorrector", CHS=False, reapplyJEC=True, jecUncFile="", computeMETSignificance=True, fixEE2017=False, fixEE2017Params=None, extractDeepMETs=False, postfix="")
def nanoAOD_customizeData(process)