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