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
15 from PhysicsTools.NanoAOD.met_cff import *
19 
20 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
21 from Configuration.Eras.Modifier_run2_nanoAOD_92X_cff import run2_nanoAOD_92X
22 from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff import run2_nanoAOD_94X2016
23 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff import run2_nanoAOD_94XMiniAODv1
24 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff import run2_nanoAOD_94XMiniAODv2
25 from Configuration.Eras.Modifier_run2_nanoAOD_102Xv1_cff import run2_nanoAOD_102Xv1
26 
27 nanoMetadata = cms.EDProducer("UniqueStringProducer",
28  strings = cms.PSet(
29  tag = cms.string("untagged"),
30  )
31 )
32 
33 linkedObjects = cms.EDProducer("PATObjectCrossLinker",
34  jets=cms.InputTag("finalJets"),
35  muons=cms.InputTag("finalMuons"),
36  electrons=cms.InputTag("finalElectrons"),
37  taus=cms.InputTag("finalTaus"),
38  photons=cms.InputTag("finalPhotons"),
39 )
40 
41 simpleCleanerTable = cms.EDProducer("NanoAODSimpleCrossCleaner",
42  name=cms.string("cleanmask"),
43  doc=cms.string("simple cleaning mask with priority to leptons"),
44  jets=cms.InputTag("linkedObjects","jets"),
45  muons=cms.InputTag("linkedObjects","muons"),
46  electrons=cms.InputTag("linkedObjects","electrons"),
47  taus=cms.InputTag("linkedObjects","taus"),
48  photons=cms.InputTag("linkedObjects","photons"),
49  jetSel=cms.string("pt>15"),
50  muonSel=cms.string("isPFMuon && innerTrack.validFraction >= 0.49 && ( isGlobalMuon && globalTrack.normalizedChi2 < 3 && combinedQuality.chi2LocalPosition < 12 && combinedQuality.trkKink < 20 && segmentCompatibility >= 0.303 || segmentCompatibility >= 0.451 )"),
51  electronSel=cms.string(""),
52  tauSel=cms.string(""),
53  photonSel=cms.string(""),
54  jetName=cms.string("Jet"),muonName=cms.string("Muon"),electronName=cms.string("Electron"),
55  tauName=cms.string("Tau"),photonName=cms.string("Photon")
56 )
57 
58 btagSFdir="PhysicsTools/NanoAOD/data/btagSF/"
59 
60 btagWeightTable = cms.EDProducer("BTagSFProducer",
61  src = cms.InputTag("linkedObjects","jets"),
62  cut = cms.string("pt > 25. && abs(eta) < 2.5"),
63  discNames = cms.vstring(
64  "pfCombinedInclusiveSecondaryVertexV2BJetTags",
65  "pfDeepCSVJetTags:probb+pfDeepCSVJetTags:probbb", #if multiple MiniAOD branches need to be summed up (e.g., DeepCSV b+bb), separate them using '+' delimiter
66  "pfCombinedMVAV2BJetTags"
67  ),
68  discShortNames = cms.vstring(
69  "CSVV2",
70  "DeepCSVB",
71  "CMVA"
72  ),
73  weightFiles = cms.vstring( #default settings are for 2017 94X. toModify function is called later for other eras.
74  btagSFdir+"CSVv2_94XSF_V2_B_F.csv",
75  btagSFdir+"DeepCSV_94XSF_V2_B_F.csv",
76  "unavailable" #if SFs for an algorithm in an era is unavailable, the corresponding branch will not be stored
77  ),
78  operatingPoints = cms.vstring("3","3","3"), #loose = 0, medium = 1, tight = 2, reshaping = 3
79  measurementTypesB = cms.vstring("iterativefit","iterativefit","iterativefit"), #e.g. "comb", "incl", "ttbar", "iterativefit"
80  measurementTypesC = cms.vstring("iterativefit","iterativefit","iterativefit"),
81  measurementTypesUDSG = cms.vstring("iterativefit","iterativefit","iterativefit"),
82  sysTypes = cms.vstring("central","central","central")
83 )
84 
85 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016: # to be updated when SF for Summer16MiniAODv3 MC will be available
86  modifier.toModify(btagWeightTable,
87  cut = cms.string("pt > 25. && abs(eta) < 2.4"), #80X corresponds to 2016, |eta| < 2.4
88  weightFiles = cms.vstring( #80X corresponds to 2016 SFs
89  btagSFdir+"CSVv2_Moriond17_B_H.csv",
90  "unavailable",
91  btagSFdir+"cMVAv2_Moriond17_B_H.csv"
92  )
93  )
94 
95 run2_nanoAOD_92X.toModify(btagWeightTable, #92X corresponds to MCv1, for which SFs are unavailable
96  weightFiles = cms.vstring(
97  "unavailable",
98  "unavailable",
99  "unavailable"
100  )
101 )
102 
103 genWeightsTable = cms.EDProducer("GenWeightsTableProducer",
104  genEvent = cms.InputTag("generator"),
105  lheInfo = cms.InputTag("externalLHEProducer"),
106  preferredPDFs = cms.VPSet( # see https://lhapdf.hepforge.org/pdfsets.html
107  cms.PSet( name = cms.string("PDF4LHC15_nnlo_30_pdfas"), lhaid = cms.uint32(91400) ),
108  cms.PSet( name = cms.string("NNPDF31_nnlo_hessian_pdfas"), lhaid = cms.uint32(306000) ),
109  cms.PSet( name = cms.string("NNPDF30_nlo_as_0118"), lhaid = cms.uint32(260000) ), # for some 92X samples. Note that the nominal weight, 260000, is not included in the LHE ...
110  cms.PSet( name = cms.string("NNPDF30_lo_as_0130"), lhaid = cms.uint32(262000) ), # some MLM 80X samples have only this (e.g. /store/mc/RunIISummer16MiniAODv2/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6_ext1-v2/120000/02A210D6-F5C3-E611-B570-008CFA197BD4.root )
111  cms.PSet( name = cms.string("NNPDF30_nlo_nf_4_pdfas"), lhaid = cms.uint32(292000) ), # some FXFX 80X samples have only this (e.g. WWTo1L1Nu2Q, WWTo4Q)
112  cms.PSet( name = cms.string("NNPDF30_nlo_nf_5_pdfas"), lhaid = cms.uint32(292200) ), # some FXFX 80X samples have only this (e.g. DYJetsToLL_Pt, WJetsToLNu_Pt, DYJetsToNuNu_Pt)
113  ),
114  namedWeightIDs = cms.vstring(),
115  namedWeightLabels = cms.vstring(),
116  lheWeightPrecision = cms.int32(14),
117  maxPdfWeights = cms.uint32(150),
118  debug = cms.untracked.bool(False),
119 )
120 lheInfoTable = cms.EDProducer("LHETablesProducer",
121  lheInfo = cms.InputTag("externalLHEProducer"),
122  precision = cms.int32(14),
123  storeLHEParticles = cms.bool(True)
124 )
125 
126 l1bits=cms.EDProducer("L1TriggerResultsConverter", src=cms.InputTag("gtStage2Digis"), legacyL1=cms.bool(False))
127 
128 nanoSequenceCommon = cms.Sequence(
129  nanoMetadata + jetSequence + muonSequence + tauSequence + electronSequence+photonSequence+vertexSequence+
130  isoTrackSequence + # must be after all the leptons
131  linkedObjects +
132  jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + isoTrackTables
133  )
134 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTables + l1bits)
135 
136 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyFullSim)
137 
138 nanoSequenceFS = cms.Sequence(genParticleSequence + particleLevelSequence + nanoSequenceCommon + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + ttbarCatMCProducers + globalTablesMC + btagWeightTable + genWeightsTable + genParticleTables + particleLevelTables + lheInfoTable + ttbarCategoryTable )
139 
140 nanoSequenceMC = nanoSequenceFS.copy()
141 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
142 
143 # modify extraFlagsTable to store ecalBadCalibFilter decision which is re-run with updated bad crystal list for 2017 and 2018 samples
144 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1:
145  modifier.toModify(extraFlagsTable, variables= cms.PSet())
146  modifier.toModify(extraFlagsTable, variables = dict(Flag_ecalBadCalibFilterV2 = ExtVar(cms.InputTag("ecalBadCalibFilterNanoTagger"), bool, doc = "Bad ECAL calib flag (updated xtal list)")))
147 
148 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
149 def nanoAOD_addDeepInfo(process,addDeepBTag,addDeepFlavour):
150  _btagDiscriminators=[]
151  if addDeepBTag:
152  print("Updating process to run DeepCSV btag")
153  _btagDiscriminators += ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc']
154  if addDeepFlavour:
155  print("Updating process to run DeepFlavour btag")
156  _btagDiscriminators += ['pfDeepFlavourJetTags:probb','pfDeepFlavourJetTags:probbb','pfDeepFlavourJetTags:problepb']
157  if len(_btagDiscriminators)==0: return process
158  print("Will recalculate the following discriminators: "+", ".join(_btagDiscriminators))
159  updateJetCollection(
160  process,
161  jetSource = cms.InputTag('slimmedJets'),
162  jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute','L2L3Residual']), 'None'),
163  btagDiscriminators = _btagDiscriminators,
164  postfix = 'WithDeepInfo',
165  )
166  process.load("Configuration.StandardSequences.MagneticField_cff")
167  process.looseJetId.src="selectedUpdatedPatJetsWithDeepInfo"
168  process.tightJetId.src="selectedUpdatedPatJetsWithDeepInfo"
169  process.tightJetIdLepVeto.src="selectedUpdatedPatJetsWithDeepInfo"
170  process.bJetVars.src="selectedUpdatedPatJetsWithDeepInfo"
171  process.slimmedJetsWithUserData.src="selectedUpdatedPatJetsWithDeepInfo"
172  process.qgtagger80x.srcJets="selectedUpdatedPatJetsWithDeepInfo"
173  if addDeepFlavour:
174  process.pfDeepFlavourJetTagsWithDeepInfo.graph_path = 'RecoBTag/Combined/data/DeepFlavourV03_10X_training/constant_graph.pb'
175  process.pfDeepFlavourJetTagsWithDeepInfo.lp_names = ["cpf_input_batchnorm/keras_learning_phase"]
176  return process
177 
178 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
179 #from PhysicsTools.PatAlgos.slimming.puppiForMET_cff import makePuppiesFromMiniAOD
180 def nanoAOD_recalibrateMETs(process,isData):
181  runMetCorAndUncFromMiniAOD(process,isData=isData)
182  process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(jetSequence),cms.Sequence(process.fullPatMetSequence))
183 # makePuppiesFromMiniAOD(process,True) # call this before in the global customizer otherwise it would reset photon IDs in VID
184 # runMetCorAndUncFromMiniAOD(process,isData=isData,metType="Puppi",postfix="Puppi",jetFlavor="AK4PFPuppi")
185 # process.puppiNoLep.useExistingWeights = False
186 # process.puppi.useExistingWeights = False
187 # process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(jetSequence),cms.Sequence(process.puppiMETSequence+process.fullPatMetSequencePuppi))
188  return process
189 
191 def nanoAOD_activateVID(process):
192  switchOnVIDElectronIdProducer(process,DataFormat.MiniAOD)
193  for modname in electron_id_modules_WorkingPoints_nanoAOD.modules:
194  setupAllVIDIdsInModule(process,modname,setupVIDElectronSelection)
195  process.electronSequence.insert(process.electronSequence.index(bitmapVIDForEle),process.egmGsfElectronIDSequence)
196  for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_92X:
197  modifier.toModify(process.electronMVAValueMapProducer, srcMiniAOD = "slimmedElectronsUpdated")
198  modifier.toModify(process.electronMVAVariableHelper, srcMiniAOD = "slimmedElectronsUpdated")
199  modifier.toModify(process.egmGsfElectronIDs, physicsObjectSrc = "slimmedElectronsUpdated")
200  if hasattr(process,"heepIDVarValueMaps"):
201  modifier.toModify(process.heepIDVarValueMaps, elesMiniAOD = "slimmedElectronsUpdated")
202  switchOnVIDPhotonIdProducer(process,DataFormat.MiniAOD) # do not call this to avoid resetting photon IDs in VID, if called before inside makePuppiesFromMiniAOD
203  for modname in photon_id_modules_WorkingPoints_nanoAOD.modules:
204  setupAllVIDIdsInModule(process,modname,setupVIDPhotonSelection)
205  process.photonSequence.insert(process.photonSequence.index(bitmapVIDForPho),process.egmPhotonIDSequence)
206  return process
207 
208 def nanoAOD_addDeepInfoAK8(process,addDeepBTag,addDeepBoostedJet,jecPayload):
209  _btagDiscriminators=[]
210  if addDeepBTag:
211  print("Updating process to run DeepCSV btag to AK8 jets")
212  _btagDiscriminators += ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb']
213  if addDeepBoostedJet:
214  print("Updating process to run DeepBoostedJet on datasets before 103X")
215  from RecoBTag.MXNet.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsAll as pfDeepBoostedJetTagsAll
216  _btagDiscriminators += pfDeepBoostedJetTagsAll
217  if len(_btagDiscriminators)==0: return process
218  print("Will recalculate the following discriminators on AK8 jets: "+", ".join(_btagDiscriminators))
219  updateJetCollection(
220  process,
221  jetSource = cms.InputTag('slimmedJetsAK8'),
222  pvSource = cms.InputTag('offlineSlimmedPrimaryVertices'),
223  svSource = cms.InputTag('slimmedSecondaryVertices'),
224  rParam = 0.8,
225  jetCorrections = (jecPayload.value(), cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual']), 'None'),
226  btagDiscriminators = _btagDiscriminators,
227  postfix='AK8WithDeepInfo',
228  printWarning = False
229  )
230  process.looseJetIdAK8.src = "selectedUpdatedPatJetsAK8WithDeepInfo"
231  process.tightJetIdAK8.src = "selectedUpdatedPatJetsAK8WithDeepInfo"
232  process.tightJetIdLepVetoAK8.src = "selectedUpdatedPatJetsAK8WithDeepInfo"
233  process.slimmedJetsAK8WithUserData.src = "selectedUpdatedPatJetsAK8WithDeepInfo"
234  return process
235 
236 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
237 def nanoAOD_runMETfixEE2017(process,isData):
238  runMetCorAndUncFromMiniAOD(process,isData=isData,
239  fixEE2017 = True,
240  fixEE2017Params = {'userawPt': True, 'ptThreshold':50.0, 'minEtaThreshold':2.65, 'maxEtaThreshold': 3.139},
241  postfix = "FixEE2017")
242  process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(jetSequence),process.fullPatMetSequenceFixEE2017)
243 
245 # makePuppiesFromMiniAOD(process,True) # call this here as it calls switchOnVIDPhotonIdProducer
246  process = nanoAOD_activateVID(process)
247  nanoAOD_addDeepInfo_switch = cms.PSet(
248  nanoAOD_addDeepBTag_switch = cms.untracked.bool(False),
249  nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(False),
250  )
251  run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepBTag_switch = cms.untracked.bool(True))
252  for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
253  modifier.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(True))
254  process = nanoAOD_addDeepInfo(process,
255  addDeepBTag=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepBTag_switch,
256  addDeepFlavour=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepFlavourTag_switch)
257  nanoAOD_addDeepInfoAK8_switch = cms.PSet(
258  nanoAOD_addDeepBTag_switch = cms.untracked.bool(False),
259  nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(True), # will deactivate this in future miniAOD releases
260  jecPayload = cms.untracked.string('AK8PFPuppi')
261  )
262  # deepAK8 should not run on 80X, that contains ak8PFJetsCHS jets
263  run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK8_switch,
264  nanoAOD_addDeepBTag_switch = cms.untracked.bool(True),
265  nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(False),
266  jecPayload = cms.untracked.string('AK8PFchs'))
267  process = nanoAOD_addDeepInfoAK8(process,
268  addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
269  addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
270  jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload)
271  return process
272 
274  process = nanoAOD_customizeCommon(process)
275  process = nanoAOD_recalibrateMETs(process,isData=True)
276  for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
277  modifier.toModify(process, nanoAOD_runMETfixEE2017(process,isData=True))
278  return process
279 
280 def nanoAOD_customizeMC(process):
281  process = nanoAOD_customizeCommon(process)
282  process = nanoAOD_recalibrateMETs(process,isData=False)
283  for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
284  modifier.toModify(process, nanoAOD_runMETfixEE2017(process,isData=False))
285  return process
286 
287 ### Era dependent customization
288 _80x_sequence = nanoSequenceCommon.copy()
289 #remove stuff
290 _80x_sequence.remove(isoTrackTables)
291 _80x_sequence.remove(isoTrackSequence)
292 #add stuff
293 _80x_sequence.insert(_80x_sequence.index(jetSequence), extraFlagsProducers)
294 _80x_sequence.insert(_80x_sequence.index(simpleCleanerTable)+1, extraFlagsTable)
295 
296 run2_miniAOD_80XLegacy.toReplaceWith( nanoSequenceCommon, _80x_sequence)
297 
298 _102x_sequence = nanoSequenceCommon.copy()
299 #add stuff
300 _102x_sequence.insert(_102x_sequence.index(jetSequence),extraFlagsProducers102x)
301 _102x_sequence.insert(_102x_sequence.index(simpleCleanerTable)+1,extraFlagsTable)
302 
303 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1:
304  modifier.toReplaceWith(nanoSequenceCommon, _102x_sequence)
def nanoAOD_addDeepInfo(process, addDeepBTag, addDeepFlavour)
Definition: nano_cff.py:149
def switchOnVIDElectronIdProducer(process, dataFormat, task=None)
Electrons.
Definition: vid_id_tools.py:66
def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:31
def setupAllVIDIdsInModule(process, id_module_name, setupFunction, patProducer=None, addUserData=True, task=None)
Definition: vid_id_tools.py:49
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def nanoAOD_customizeMC(process)
Definition: nano_cff.py:280
def nanoAOD_activateVID(process)
Definition: nano_cff.py:191
def nanoAOD_customizeCommon(process)
Definition: nano_cff.py:244
def nanoAOD_recalibrateMETs(process, isData)
Definition: nano_cff.py:180
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, jecPayload)
Definition: nano_cff.py:208
def nanoAOD_runMETfixEE2017(process, isData)
Definition: nano_cff.py:237
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def switchOnVIDPhotonIdProducer(process, dataFormat, task=None)
Photons.
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, postfix="")
def nanoAOD_customizeData(process)
Definition: nano_cff.py:273