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
23 from PhysicsTools.NanoAOD.met_cff import *
30 
31 nanoMetadata = cms.EDProducer("UniqueStringProducer",
32  strings = cms.PSet(
33  tag = cms.string("untagged"),
34  )
35 )
36 
37 linkedObjects = cms.EDProducer("PATObjectCrossLinker",
38  jets=cms.InputTag("finalJetsPuppi"),
39  muons=cms.InputTag("finalMuons"),
40  electrons=cms.InputTag("finalElectrons"),
41  lowPtElectrons=cms.InputTag("finalLowPtElectrons"),
42  taus=cms.InputTag("finalTaus"),
43  boostedTaus=cms.InputTag("finalBoostedTaus"),
44  photons=cms.InputTag("finalPhotons"),
45  vertices=cms.InputTag("slimmedSecondaryVertices")
46 )
47 
48 # Switch to AK4 CHS jets for Run-2
49 run2_nanoAOD_ANY.toModify(
50  linkedObjects, jets="finalJets"
51 )
52 
53 # boosted taus don't exist in 122X MINI
54 run3_nanoAOD_122.toModify(
55  linkedObjects, boostedTaus=None,
56 )
57 
58 lhcInfoTable = cms.EDProducer("LHCInfoProducer")
59 
60 nanoTableTaskCommon = cms.Task(
61  cms.Task(nanoMetadata),
62  jetPuppiTask, jetPuppiForMETTask, jetAK8Task,
63  extraFlagsProducersTask, muonTask, tauTask, boostedTauTask,
64  electronTask , lowPtElectronTask, photonTask,
65  vertexTask, isoTrackTask, jetAK8LepTask, # must be after all the leptons
66  softActivityTask,
67  cms.Task(linkedObjects),
68  jetPuppiTablesTask, jetAK8TablesTask,
69  muonTablesTask, fsrTablesTask, tauTablesTask, boostedTauTablesTask,
70  electronTablesTask, lowPtElectronTablesTask, photonTablesTask,
71  globalTablesTask, vertexTablesTask, metTablesTask, extraFlagsTableTask,
72  isoTrackTablesTask,softActivityTablesTask
73 )
74 
75 # Replace AK4 Puppi with AK4 CHS for Run-2
76 _nanoTableTaskCommonRun2 = nanoTableTaskCommon.copy()
77 _nanoTableTaskCommonRun2.replace(jetPuppiTask, jetTask)
78 _nanoTableTaskCommonRun2.replace(jetPuppiForMETTask, jetForMETTask)
79 _nanoTableTaskCommonRun2.replace(jetPuppiTablesTask, jetTablesTask)
80 run2_nanoAOD_ANY.toReplaceWith(
81  nanoTableTaskCommon, _nanoTableTaskCommonRun2
82 )
83 
84 nanoSequenceCommon = cms.Sequence(nanoTableTaskCommon)
85 
86 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTablesTask)
87 nanoSequenceOnlyData = cms.Sequence(cms.Sequence(protonTablesTask) + lhcInfoTable)
88 
89 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyData + nanoSequenceOnlyFullSim)
90 
91 nanoTableTaskFS = cms.Task(
92  genParticleTask, particleLevelTask, jetMCTask, muonMCTask, electronMCTask, lowPtElectronMCTask, photonMCTask,
93  tauMCTask, boostedTauMCTask,
94  metMCTable, ttbarCatMCProducersTask, globalTablesMCTask, ttbarCategoryTableTask,
95  genWeightsTableTask, genVertexTablesTask, genParticleTablesTask, genProtonTablesTask, particleLevelTablesTask
96 )
97 
98 nanoSequenceFS = cms.Sequence(nanoSequenceCommon + cms.Sequence(nanoTableTaskFS))
99 
100 # GenVertex only stored in newer MiniAOD
101 nanoSequenceMC = nanoSequenceFS.copy()
102 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
103 
104 # modifier which adds new tauIDs (currently only deepTauId2017v2p1 is being added)
105 import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
106 def nanoAOD_addTauIds(process, idsToRun=[]):
107  if idsToRun: #no-empty list of tauIDs to run
108  updatedTauName = "slimmedTausUpdated"
109  tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug = False,
110  updatedTauName = updatedTauName,
111  postfix = "ForNano",
112  toKeep = idsToRun)
113  tauIdEmbedder.runTauID()
114  process.finalTaus.src = updatedTauName
115  #remember to adjust the selection and tables with added IDs
116 
117  process.tauTask.add( process.rerunMvaIsolationTaskForNano , process.patTauMVAIDsTask )
118 
119  return process
120 
121 def nanoAOD_addBoostedTauIds(process, idsToRun=[]):
122  if idsToRun: #no-empty list of tauIDs to run
123  updatedBoostedTauName = "slimmedTausBoostedNewID"
124  boostedTauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug = False,
125  originalTauName = "slimmedTausBoosted",
126  updatedTauName = updatedBoostedTauName,
127  postfix = "BoostedForNano",
128  toKeep = idsToRun)
129  boostedTauIdEmbedder.runTauID()
130  process.finalBoostedTaus.src = updatedBoostedTauName
131  #remember to adjust the selection and tables with added IDs
132 
133  process.boostedTauTask.add( process.rerunMvaIsolationTaskBoostedForNano, getattr(process, updatedBoostedTauName))
134 
135  return process
136 
138 def nanoAOD_activateVID(process):
139 
140  switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD,electronTask)
141  for modname in electron_id_modules_WorkingPoints_nanoAOD.modules:
142  setupAllVIDIdsInModule(process,modname,setupVIDElectronSelection)
143 
144  process.electronTask.add( process.egmGsfElectronIDTask )
145 
146  switchOnVIDPhotonIdProducer(process,DataFormat.MiniAOD,photonTask) # do not call this to avoid resetting photon IDs in VID, if called before inside makePuppiesFromMiniAOD
147  for modname in photon_id_modules_WorkingPoints_nanoAOD.modules:
148  setupAllVIDIdsInModule(process,modname,setupVIDPhotonSelection)
149 
150  process.photonTask.add( process.egmPhotonIDTask )
151 
152  return process
153 
155 
156  process = nanoAOD_activateVID(process)
157 
158  # This function is defined in jetsAK4_CHS_cff.py
159  process = nanoAOD_addDeepInfoAK4CHS(process,
160  addDeepBTag=nanoAOD_addDeepInfoAK4CHS_switch.nanoAOD_addDeepBTag_switch,
161  addDeepFlavour=nanoAOD_addDeepInfoAK4CHS_switch.nanoAOD_addDeepFlavourTag_switch
162  )
163 
164  # This function is defined in jetsAK8_cff.py
165  process = nanoAOD_addDeepInfoAK8(process,
166  addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
167  addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
168  addDeepDoubleX=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleX_switch,
169  addDeepDoubleXV2=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleXV2_switch,
170  addParticleNet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNet_switch,
171  addParticleNetMass=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNetMass_switch,
172  jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload
173  )
174 
175  nanoAOD_tau_switch = cms.PSet(
176  idsToAdd = cms.vstring()
177  )
178  (run2_nanoAOD_106Xv2 | run3_nanoAOD_122).toModify(
179  nanoAOD_tau_switch, idsToAdd = ["deepTau2018v2p5"]
180  ).toModify(
181  process, lambda p : nanoAOD_addTauIds(p, nanoAOD_tau_switch.idsToAdd.value())
182  )
183  nanoAOD_boostedTau_switch = cms.PSet(
184  idsToAdd = cms.vstring()
185  )
186  run2_nanoAOD_106Xv2.toModify(
187  nanoAOD_boostedTau_switch, idsToAdd = ["2017v2", "dR0p32017v2", "newDM2017v2","againstEle2018"]
188  ).toModify(
189  process, lambda p : nanoAOD_addBoostedTauIds(p, nanoAOD_boostedTau_switch.idsToAdd.value())
190  )
191 
192  return process
193 
195  process = nanoAOD_customizeCommon(process)
196  return process
197 
198 def nanoAOD_customizeMC(process):
199  process = nanoAOD_customizeCommon(process)
200  return process
201 
202 
204  pdgSelection="?(abs(pdgId) == 11|| abs(pdgId)==13 || abs(pdgId)==15 ||abs(pdgId)== 12 || abs(pdgId)== 14 || abs(pdgId)== 16|| abs(pdgId)== 24|| pdgId== 23)"
205  # Keep precision same as default RECO for selected particles
206  ptPrecision="{}?{}:{}".format(pdgSelection, CandVars.pt.precision.value(),genParticleTable.variables.pt.precision.value())
207  process.genParticleTable.variables.pt.precision=cms.string(ptPrecision)
208  phiPrecision="{} ? {} : {}".format(pdgSelection, CandVars.phi.precision.value(), genParticleTable.variables.phi.precision.value())
209  process.genParticleTable.variables.phi.precision=cms.string(phiPrecision)
210  etaPrecision="{} ? {} : {}".format(pdgSelection, CandVars.eta.precision.value(), genParticleTable.variables.eta.precision.value())
211  process.genParticleTable.variables.eta.precision=cms.string(etaPrecision)
212  return process
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 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)
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload)
Definition: jetsAK8_cff.py:146
def nanoAOD_activateVID(process)
Definition: nano_cff.py:138
def switchOnVIDPhotonIdProducer(process, dataFormat, task=None)
Photons.
def nanoWmassGenCustomize(process)
increasing the precision of selected GenParticles.
Definition: nano_cff.py:203
def nanoAOD_customizeMC(process)
Definition: nano_cff.py:198