CMS 3D CMS Logo

nano_cff.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import FWCore.ParameterSet.Config as cms
3 
7 
33 
34 nanoMetadata = cms.EDProducer("UniqueStringProducer",
35  strings = cms.PSet(
36  tag = cms.string("untagged"),
37  )
38 )
39 
40 linkedObjects = cms.EDProducer("PATObjectCrossLinker",
41  jets=cms.InputTag("finalJetsPuppi"),
42  muons=cms.InputTag("finalMuons"),
43  electrons=cms.InputTag("finalElectrons"),
44  lowPtElectrons=cms.InputTag("finalLowPtElectrons"),
45  taus=cms.InputTag("finalTaus"),
46  photons=cms.InputTag("finalPhotons"),
47 )
48 
49 # Switch to AK4 CHS jets for Run-2
50 run2_nanoAOD_ANY.toModify(linkedObjects, jets="finalJets")
51 
52 simpleCleanerTable = cms.EDProducer("NanoAODSimpleCrossCleaner",
53  name=cms.string("cleanmask"),
54  doc=cms.string("simple cleaning mask with priority to leptons"),
55  jets=cms.InputTag("linkedObjects","jets"),
56  muons=cms.InputTag("linkedObjects","muons"),
57  electrons=cms.InputTag("linkedObjects","electrons"),
58  lowPtElectrons=cms.InputTag("linkedObjects","lowPtElectrons"),
59  taus=cms.InputTag("linkedObjects","taus"),
60  photons=cms.InputTag("linkedObjects","photons"),
61  jetSel=cms.string("pt>15"),
62  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 )"),
63  electronSel=cms.string(""),
64  lowPtElectronSel=cms.string(""),
65  tauSel=cms.string(""),
66  photonSel=cms.string(""),
67  jetName=cms.string("Jet"),muonName=cms.string("Muon"),electronName=cms.string("Electron"),
68  lowPtElectronName=cms.string("LowPtElectron"),
69  tauName=cms.string("Tau"),photonName=cms.string("Photon")
70 )
71 
72 
73 lhcInfoTable = cms.EDProducer("LHCInfoProducer")
74 
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, # must be after all the leptons
81  softActivityTask,
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
88 )
89 
90 # Replace AK4 Puppi with AK4 CHS for Run-2
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)
96 
97 nanoSequenceCommon = cms.Sequence(nanoTableTaskCommon)
98 
99 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTablesTask)
100 nanoSequenceOnlyData = cms.Sequence(cms.Sequence(protonTablesTask) + lhcInfoTable)
101 
102 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyData + nanoSequenceOnlyFullSim)
103 
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
109 )
110 
111 nanoSequenceFS = cms.Sequence(nanoSequenceCommon + cms.Sequence(nanoTableTaskFS))
112 
113 # GenVertex only stored in newer MiniAOD
114 nanoSequenceMC = nanoSequenceFS.copy()
115 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
116 
117 # modifier which adds new tauIDs (currently only deepTauId2017v2p1 is being added)
118 
119 import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
120 def nanoAOD_addTauIds(process, idsToRun=[]):
121  if idsToRun: #no-empty list of tauIDs to run
122  updatedTauName = "slimmedTausUpdated"
123  tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug = False,
124  updatedTauName = updatedTauName,
125  postfix = "ForNano",
126  toKeep = idsToRun)
127  tauIdEmbedder.runTauID()
128  _tauTask = patTauMVAIDsTask.copy()
129  _tauTask.add(process.rerunMvaIsolationTaskForNano)
130  _tauTask.add(finalTaus)
131  process.finalTaus.src = updatedTauName
132  #remember to adjust the selection and tables with added IDs
133 
134  process.tauTask = _tauTask.copy()
135 
136  return process
137 
138 def nanoAOD_addBoostedTauIds(process, idsToRun=[]):
139  if idsToRun: #no-empty list of tauIDs to run
140  updatedBoostedTauName = "slimmedTausBoostedNewID"
141  boostedTauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug = False,
142  originalTauName = "slimmedTausBoosted",
143  updatedTauName = updatedBoostedTauName,
144  postfix = "BoostedForNano",
145  toKeep = idsToRun)
146  boostedTauIdEmbedder.runTauID()
147  _boostedTauTask = process.rerunMvaIsolationTaskBoostedForNano.copy()
148  _boostedTauTask.add(getattr(process, updatedBoostedTauName))
149  _boostedTauTask.add(process.finalBoostedTaus)
150  process.finalBoostedTaus.src = updatedBoostedTauName
151  #remember to adjust the selection and tables with added IDs
152 
153  process.boostedTauTask = _boostedTauTask.copy()
154 
155  return process
156 
157 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
158 def nanoAOD_recalibrateMETs(process,isData):
159  # add DeepMETs
160  nanoAOD_DeepMET_switch = cms.PSet(
161  ResponseTune_Graph = cms.untracked.string('RecoMET/METPUSubtraction/data/models/deepmet/deepmet_resp_v1_2018/model.graphdef')
162  )
163 
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()
169 
170  runMetCorAndUncFromMiniAOD(process,isData=isData)
171  process.nanoSequenceCommon.insert(2,cms.Sequence(process.fullPatMetSequence))
172 
173 
174  from PhysicsTools.PatAlgos.slimming.puppiForMET_cff import makePuppiesFromMiniAOD
175  makePuppiesFromMiniAOD(process,True)
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")
181 
182 # makePuppiesFromMiniAOD(process,True) # call this before in the global customizer otherwise it would reset photon IDs in VID
183  nanoAOD_PuppiV15_switch = cms.PSet(
184  recoMetFromPFCs = cms.untracked.bool(False),
185  reclusterJets = cms.untracked.bool(False),
186  )
187  #run2_nanoAOD_106Xv1.toModify(nanoAOD_PuppiV15_switch,recoMetFromPFCs=True,reclusterJets=True)
188  if nanoAOD_PuppiV15_switch.reclusterJets:
189  from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets
190  from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
191  task = getPatAlgosToolsTask(process)
192  addToProcessAndTask('ak4PuppiJets', ak4PFJets.clone (src = 'puppi', doAreaFastjet = True, jetPtMin = 10.), process, task)
193  from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
194  addJetCollection(process,
195  labelName = 'Puppi',
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
207  )
208 
209  process.patJetsPuppi.addGenPartonMatch = cms.bool(False)
210  process.patJetsPuppi.addGenJetMatch = cms.bool(False)
211 
212  print("nanoAOD_PuppiV15_switch.reclusterJets is true")
213 
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))
216 
217  return process
218 
220 def nanoAOD_activateVID(process):
221 
222  switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD,electronTask)
223  for modname in electron_id_modules_WorkingPoints_nanoAOD.modules:
224  setupAllVIDIdsInModule(process,modname,setupVIDElectronSelection)
225 
226  electronTask_ = process.egmGsfElectronIDTask.copy()
227  electronTask_.add(electronTask.copy())
228  process.electronTask = electronTask_.copy()
229 
230  switchOnVIDPhotonIdProducer(process,DataFormat.MiniAOD,photonTask) # do not call this to avoid resetting photon IDs in VID, if called before inside makePuppiesFromMiniAOD
231  for modname in photon_id_modules_WorkingPoints_nanoAOD.modules:
232  setupAllVIDIdsInModule(process,modname,setupVIDPhotonSelection)
233 
234  photonTask_ = process.egmPhotonIDTask.copy()
235  photonTask_.add(photonTask.copy())
236  process.photonTask = photonTask_.copy()
237  return process
238 
239 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
240 def nanoAOD_runMETfixEE2017(process,isData):
241  runMetCorAndUncFromMiniAOD(process,isData=isData,
242  fixEE2017 = True,
243  fixEE2017Params = {'userawPt': True, 'ptThreshold':50.0, 'minEtaThreshold':2.65, 'maxEtaThreshold': 3.139},
244  postfix = "FixEE2017")
245  process.nanoSequenceCommon.insert(2,process.fullPatMetSequenceFixEE2017)
246 
247 
248 def nanoAOD_customizeCommon(process):
249 
250  process = nanoAOD_activateVID(process)
251 
252  # This function is defined in jetsAK4_CHS_cff.py
253  process = nanoAOD_addDeepInfoAK4CHS(process,
254  addDeepBTag=nanoAOD_addDeepInfoAK4CHS_switch.nanoAOD_addDeepBTag_switch,
255  addDeepFlavour=nanoAOD_addDeepInfoAK4CHS_switch.nanoAOD_addDeepFlavourTag_switch
256  )
257 
258  # This function is defined in jetsAK8_cff.py
259  process = nanoAOD_addDeepInfoAK8(process,
260  addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
261  addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
262  addDeepDoubleX=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleX_switch,
263  addDeepDoubleXV2=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleXV2_switch,
264  addParticleNet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNet_switch,
265  addParticleNetMass=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNetMass_switch,
266  jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload
267  )
268 
269  nanoAOD_tau_switch = cms.PSet(
270  idsToAdd = cms.vstring()
271  )
272  (run2_nanoAOD_106Xv2 | run3_nanoAOD_122).toModify(nanoAOD_tau_switch, idsToAdd = ["deepTau2018v2p5"])
273  (run2_nanoAOD_106Xv2 | run3_nanoAOD_122).toModify(process, lambda p : nanoAOD_addTauIds(p, nanoAOD_tau_switch.idsToAdd.value()))
274  nanoAOD_boostedTau_switch = cms.PSet(
275  idsToAdd = cms.vstring()
276  )
277  run2_nanoAOD_106Xv2.toModify(nanoAOD_boostedTau_switch, idsToAdd = ["2017v2", "dR0p32017v2", "newDM2017v2","againstEle2018"])
278  run2_nanoAOD_106Xv2.toModify(process, lambda p : nanoAOD_addBoostedTauIds(p, nanoAOD_boostedTau_switch.idsToAdd.value()))
279 
280  return process
281 
282 def nanoAOD_customizeData(process):
283  process = nanoAOD_customizeCommon(process)
284  return process
285 
286 def nanoAOD_customizeMC(process):
287  process = nanoAOD_customizeCommon(process)
288  return process
289 
290 
291 def nanoWmassGenCustomize(process):
292  pdgSelection="?(abs(pdgId) == 11|| abs(pdgId)==13 || abs(pdgId)==15 ||abs(pdgId)== 12 || abs(pdgId)== 14 || abs(pdgId)== 16|| abs(pdgId)== 24|| pdgId== 23)"
293  # Keep precision same as default RECO for selected particles
294  ptPrecision="{}?{}:{}".format(pdgSelection, CandVars.pt.precision.value(),genParticleTable.variables.pt.precision.value())
295  process.genParticleTable.variables.pt.precision=cms.string(ptPrecision)
296  phiPrecision="{} ? {} : {}".format(pdgSelection, CandVars.phi.precision.value(), genParticleTable.variables.phi.precision.value())
297  process.genParticleTable.variables.phi.precision=cms.string(phiPrecision)
298  etaPrecision="{} ? {} : {}".format(pdgSelection, CandVars.eta.precision.value(), genParticleTable.variables.eta.precision.value())
299  process.genParticleTable.variables.eta.precision=cms.string(etaPrecision)
300  return process
301 
def nanoAOD_customizeCommon(process)
Definition: nano_cff.py:154
def nanoAOD_customizeData(process)
Definition: nano_cff.py:194
def nanoAOD_addTauIds(process, idsToRun=[])
Definition: nano_cff.py:106
def switchOnVIDElectronIdProducer(process, dataFormat, task=None)
Electrons.
Definition: vid_id_tools.py:66
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def nanoAOD_addBoostedTauIds(process, idsToRun=[])
Definition: nano_cff.py:121
def setupAllVIDIdsInModule(process, id_module_name, setupFunction, patProducer=None, addUserData=True, task=None)
Definition: vid_id_tools.py:49
def nanoAOD_addDeepInfoAK4CHS(process, addDeepBTag, addDeepFlavour)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload)
Definition: jetsAK8_cff.py:146
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, campaign="", era="", postfix="")
def nanoAOD_recalibrateMETs(process, isData)
Definition: nano_cff.py:158
def nanoAOD_runMETfixEE2017(process, isData)
Definition: nano_cff.py:240
def nanoAOD_activateVID(process)
Definition: nano_cff.py:138
these imports do need to be "frozen" for V10
def getPatAlgosToolsTask(process)
Definition: helpers.py:13
def switchOnVIDPhotonIdProducer(process, dataFormat, task=None)
Photons.
def nanoWmassGenCustomize(process)
increasing the precision of selected GenParticles.
Definition: nano_cff.py:203
def makePuppiesFromMiniAOD(process, createScheduledSequence=False)
def nanoAOD_customizeMC(process)
Definition: nano_cff.py:198