1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
20 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff
import run2_miniAOD_80XLegacy
21 from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff
import run2_nanoAOD_94X2016
22 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff
import run2_nanoAOD_94XMiniAODv1
23 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff
import run2_nanoAOD_94XMiniAODv2
24 from Configuration.Eras.Modifier_run2_nanoAOD_102Xv1_cff
import run2_nanoAOD_102Xv1
26 nanoMetadata = cms.EDProducer(
"UniqueStringProducer",
28 tag = cms.string(
"untagged"),
32 linkedObjects = cms.EDProducer(
"PATObjectCrossLinker",
33 jets=cms.InputTag(
"finalJets"),
34 muons=cms.InputTag(
"finalMuons"),
35 electrons=cms.InputTag(
"finalElectrons"),
36 taus=cms.InputTag(
"finalTaus"),
37 photons=cms.InputTag(
"finalPhotons"),
40 simpleCleanerTable = cms.EDProducer(
"NanoAODSimpleCrossCleaner",
41 name=cms.string(
"cleanmask"),
42 doc=cms.string(
"simple cleaning mask with priority to leptons"),
43 jets=cms.InputTag(
"linkedObjects",
"jets"),
44 muons=cms.InputTag(
"linkedObjects",
"muons"),
45 electrons=cms.InputTag(
"linkedObjects",
"electrons"),
46 taus=cms.InputTag(
"linkedObjects",
"taus"),
47 photons=cms.InputTag(
"linkedObjects",
"photons"),
48 jetSel=cms.string(
"pt>15"),
49 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 )"),
50 electronSel=cms.string(
""),
51 tauSel=cms.string(
""),
52 photonSel=cms.string(
""),
53 jetName=cms.string(
"Jet"),muonName=cms.string(
"Muon"),electronName=cms.string(
"Electron"),
54 tauName=cms.string(
"Tau"),photonName=cms.string(
"Photon")
57 btagSFdir=
"PhysicsTools/NanoAOD/data/btagSF/" 59 btagWeightTable = cms.EDProducer(
"BTagSFProducer",
60 src = cms.InputTag(
"linkedObjects",
"jets"),
61 cut = cms.string(
"pt > 25. && abs(eta) < 2.5"),
62 discNames = cms.vstring(
63 "pfCombinedInclusiveSecondaryVertexV2BJetTags",
64 "pfDeepCSVJetTags:probb+pfDeepCSVJetTags:probbb",
65 "pfCombinedMVAV2BJetTags" 67 discShortNames = cms.vstring(
72 weightFiles = cms.vstring(
73 btagSFdir+
"CSVv2_94XSF_V2_B_F.csv",
74 btagSFdir+
"DeepCSV_94XSF_V2_B_F.csv",
77 operatingPoints = cms.vstring(
"3",
"3",
"3"),
78 measurementTypesB = cms.vstring(
"iterativefit",
"iterativefit",
"iterativefit"),
79 measurementTypesC = cms.vstring(
"iterativefit",
"iterativefit",
"iterativefit"),
80 measurementTypesUDSG = cms.vstring(
"iterativefit",
"iterativefit",
"iterativefit"),
81 sysTypes = cms.vstring(
"central",
"central",
"central")
84 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
85 modifier.toModify(btagWeightTable,
86 cut = cms.string(
"pt > 25. && abs(eta) < 2.4"),
87 weightFiles = cms.vstring(
88 btagSFdir+
"CSVv2_Moriond17_B_H.csv",
90 btagSFdir+
"cMVAv2_Moriond17_B_H.csv" 95 genWeightsTable = cms.EDProducer(
"GenWeightsTableProducer",
96 genEvent = cms.InputTag(
"generator"),
97 genLumiInfoHeader = cms.InputTag(
"generator"),
98 lheInfo = cms.VInputTag(cms.InputTag(
"externalLHEProducer"), cms.InputTag(
"source")),
99 preferredPDFs = cms.VPSet(
100 cms.PSet( name = cms.string(
"PDF4LHC15_nnlo_30_pdfas"), lhaid = cms.uint32(91400) ),
101 cms.PSet( name = cms.string(
"NNPDF31_nnlo_hessian_pdfas"), lhaid = cms.uint32(306000) ),
102 cms.PSet( name = cms.string(
"NNPDF30_nlo_as_0118"), lhaid = cms.uint32(260000) ),
103 cms.PSet( name = cms.string(
"NNPDF30_lo_as_0130"), lhaid = cms.uint32(262000) ),
104 cms.PSet( name = cms.string(
"NNPDF30_nlo_nf_4_pdfas"), lhaid = cms.uint32(292000) ),
105 cms.PSet( name = cms.string(
"NNPDF30_nlo_nf_5_pdfas"), lhaid = cms.uint32(292200) ),
106 cms.PSet( name = cms.string(
"NNPDF31_lo_as_0130"), lhaid = cms.uint32(315200) ),
108 namedWeightIDs = cms.vstring(),
109 namedWeightLabels = cms.vstring(),
110 lheWeightPrecision = cms.int32(14),
111 keepAllPSWeights = cms.bool(
False),
112 maxPdfWeights = cms.uint32(150),
113 debug = cms.untracked.bool(
False),
115 lheInfoTable = cms.EDProducer(
"LHETablesProducer",
116 lheInfo = cms.VInputTag(cms.InputTag(
"externalLHEProducer"), cms.InputTag(
"source")),
117 precision = cms.int32(14),
118 storeLHEParticles = cms.bool(
True)
121 l1bits=cms.EDProducer(
"L1TriggerResultsConverter", src=cms.InputTag(
"gtStage2Digis"), legacyL1=cms.bool(
False))
123 nanoSequenceCommon = cms.Sequence(
124 nanoMetadata + jetSequence + muonSequence + tauSequence + electronSequence+photonSequence+vertexSequence+
125 isoTrackSequence + jetLepSequence +
127 jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + isoTrackTables
129 nanoSequenceOnlyFullSim = cms.Sequence(triggerObjectTables + l1bits)
131 nanoSequence = cms.Sequence(nanoSequenceCommon + nanoSequenceOnlyFullSim)
133 nanoSequenceFS = cms.Sequence(genParticleSequence + particleLevelSequence + nanoSequenceCommon + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + ttbarCatMCProducers + globalTablesMC + btagWeightTable + genWeightsTable + genParticleTables + particleLevelTables + lheInfoTable + ttbarCategoryTable )
135 nanoSequenceMC = nanoSequenceFS.copy()
136 nanoSequenceMC.insert(nanoSequenceFS.index(nanoSequenceCommon)+1,nanoSequenceOnlyFullSim)
139 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1:
140 modifier.toModify(extraFlagsTable, variables= cms.PSet())
141 modifier.toModify(extraFlagsTable, variables =
dict(Flag_ecalBadCalibFilterV2 =
ExtVar(cms.InputTag(
"ecalBadCalibFilterNanoTagger"), bool, doc =
"Bad ECAL calib flag (updated xtal list)")))
144 import RecoTauTag.RecoTau.tools.runTauIdMVA
as tauIdConfig
146 updatedTauName =
"slimmedTausUpdated" 147 tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, cms, debug =
False, updatedTauName = updatedTauName,
148 toKeep = [
"deepTau2017v2p1" ])
149 tauIdEmbedder.runTauID()
150 process.patTauMVAIDsSeq.insert(process.patTauMVAIDsSeq.index(getattr(process, updatedTauName)),
151 process.rerunMvaIsolationSequence)
156 _btagDiscriminators=[]
158 print(
"Updating process to run DeepCSV btag")
159 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb',
'pfDeepCSVJetTags:probc']
161 print(
"Updating process to run DeepFlavour btag")
162 _btagDiscriminators += [
'pfDeepFlavourJetTags:probb',
'pfDeepFlavourJetTags:probbb',
'pfDeepFlavourJetTags:problepb',
'pfDeepFlavourJetTags:probc']
163 if len(_btagDiscriminators)==0:
return process
164 print(
"Will recalculate the following discriminators: "+
", ".
join(_btagDiscriminators))
167 jetSource = cms.InputTag(
'slimmedJets'),
168 jetCorrections = (
'AK4PFchs', cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
169 btagDiscriminators = _btagDiscriminators,
170 postfix =
'WithDeepInfo',
172 process.load(
"Configuration.StandardSequences.MagneticField_cff")
173 process.jetCorrFactorsNano.src=
"selectedUpdatedPatJetsWithDeepInfo" 174 process.updatedJets.jetSource=
"selectedUpdatedPatJetsWithDeepInfo" 176 process.pfDeepFlavourJetTagsWithDeepInfo.graph_path =
'RecoBTag/Combined/data/DeepFlavourV03_10X_training/constant_graph.pb' 177 process.pfDeepFlavourJetTagsWithDeepInfo.lp_names = [
"cpf_input_batchnorm/keras_learning_phase"]
180 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
184 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(process.jetSequence),cms.Sequence(process.fullPatMetSequence))
185 process.basicJetsForMetForT1METNano = process.basicJetsForMet.clone(
186 src = process.updatedJetsWithUserData.src,
188 type1JetPtThreshold = 0.0,
189 calcMuonSubtrRawPtAsValueMap = cms.bool(
True),
191 process.jetSequence.insert(process.jetSequence.index(process.updatedJetsWithUserData),cms.Sequence(process.basicJetsForMetForT1METNano))
192 process.updatedJetsWithUserData.userFloats.muonSubtrRawPt = cms.InputTag(
"basicJetsForMetForT1METNano:MuonSubtrRawPt")
193 process.corrT1METJetTable.src = process.finalJets.src
194 process.corrT1METJetTable.cut =
"pt<15 && abs(eta)<9.9" 195 for table
in process.jetTable, process.corrT1METJetTable:
196 table.variables.muonSubtrFactor =
Var(
"1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc=
"1-(muon-subtracted raw pt)/(raw pt)",precision=6)
197 process.metTables += process.corrT1METJetTable
208 for modname
in electron_id_modules_WorkingPoints_nanoAOD.modules:
210 process.electronSequence.insert(process.electronSequence.index(bitmapVIDForEle),process.egmGsfElectronIDSequence)
211 for modifier
in run2_miniAOD_80XLegacy, :
212 modifier.toModify(process.electronMVAValueMapProducer, srcMiniAOD =
"slimmedElectronsUpdated")
213 modifier.toModify(process.electronMVAVariableHelper, srcMiniAOD =
"slimmedElectronsUpdated")
214 modifier.toModify(process.egmGsfElectronIDs, physicsObjectSrc =
"slimmedElectronsUpdated")
215 if hasattr(process,
"heepIDVarValueMaps"):
216 modifier.toModify(process.heepIDVarValueMaps, elesMiniAOD =
"slimmedElectronsUpdated")
218 for modname
in photon_id_modules_WorkingPoints_nanoAOD.modules:
220 process.photonSequence.insert(process.photonSequence.index(bitmapVIDForPho),process.egmPhotonIDSequence)
224 _btagDiscriminators=[]
226 print(
"Updating process to run DeepCSV btag to AK8 jets")
227 _btagDiscriminators += [
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probbb']
228 if addDeepBoostedJet:
229 print(
"Updating process to run DeepBoostedJet on datasets before 103X")
231 from RecoBTag.MXNet.pfDeepBoostedDiscriminatorsJetTags_cfi
import pfDeepBoostedDiscriminatorsJetTags
232 from RecoBTag.MXNet.pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags_cfi
import pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags
233 from RecoBTag.MXNet.Parameters.V02.pfDeepBoostedJetPreprocessParams_cfi
import pfDeepBoostedJetPreprocessParams
as pfDeepBoostedJetPreprocessParamsV02
234 from RecoBTag.MXNet.Parameters.V02.pfMassDecorrelatedDeepBoostedJetPreprocessParams_cfi
import pfMassDecorrelatedDeepBoostedJetPreprocessParams
as pfMassDecorrelatedDeepBoostedJetPreprocessParamsV02
235 pfDeepBoostedJetTags.preprocessParams = pfDeepBoostedJetPreprocessParamsV02
236 pfDeepBoostedJetTags.model_path =
'RecoBTag/Combined/data/DeepBoostedJet/V02/full/resnet-symbol.json' 237 pfDeepBoostedJetTags.param_path =
'RecoBTag/Combined/data/DeepBoostedJet/V02/full/resnet-0000.params' 238 pfMassDecorrelatedDeepBoostedJetTags.preprocessParams = pfMassDecorrelatedDeepBoostedJetPreprocessParamsV02
239 pfMassDecorrelatedDeepBoostedJetTags.model_path =
'RecoBTag/Combined/data/DeepBoostedJet/V02/decorrelated/resnet-symbol.json' 240 pfMassDecorrelatedDeepBoostedJetTags.param_path =
'RecoBTag/Combined/data/DeepBoostedJet/V02/decorrelated/resnet-0000.params' 242 pfDeepBoostedJetTagsProbs = [
'pfDeepBoostedJetTags:' + flav_name
243 for flav_name
in pfDeepBoostedJetTags.flav_names]
244 pfDeepBoostedJetTagsMetaDiscrs = [
'pfDeepBoostedDiscriminatorsJetTags:' + disc.name.value()
245 for disc
in pfDeepBoostedDiscriminatorsJetTags.discriminators]
246 pfMassDecorrelatedDeepBoostedJetTagsProbs = [
'pfMassDecorrelatedDeepBoostedJetTags:' + flav_name
247 for flav_name
in pfMassDecorrelatedDeepBoostedJetTags.flav_names]
248 pfMassDecorrelatedDeepBoostedJetTagsMetaDiscrs = [
'pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:' + disc.name.value()
249 for disc
in pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags.discriminators]
250 pfDeepBoostedJetTagsAll = pfDeepBoostedJetTagsProbs + pfDeepBoostedJetTagsMetaDiscrs + \
251 pfMassDecorrelatedDeepBoostedJetTagsProbs + pfMassDecorrelatedDeepBoostedJetTagsMetaDiscrs
252 _btagDiscriminators += pfDeepBoostedJetTagsAll
254 print(
"Updating process to run DeepDoubleX on datasets before 104X")
255 _btagDiscriminators += [
'pfDeepDoubleBvLJetTags:probHbb', \
256 'pfDeepDoubleCvLJetTags:probHcc', \
257 'pfDeepDoubleCvBJetTags:probHcc', \
258 'pfMassIndependentDeepDoubleBvLJetTags:probHbb',
'pfMassIndependentDeepDoubleCvLJetTags:probHcc',
'pfMassIndependentDeepDoubleCvBJetTags:probHcc']
259 if len(_btagDiscriminators)==0:
return process
260 print(
"Will recalculate the following discriminators on AK8 jets: "+
", ".
join(_btagDiscriminators))
263 jetSource = cms.InputTag(
'slimmedJetsAK8'),
264 pvSource = cms.InputTag(
'offlineSlimmedPrimaryVertices'),
265 svSource = cms.InputTag(
'slimmedSecondaryVertices'),
267 jetCorrections = (jecPayload.value(), cms.vstring([
'L1FastJet',
'L2Relative',
'L3Absolute',
'L2L3Residual']),
'None'),
268 btagDiscriminators = _btagDiscriminators,
269 postfix=
'AK8WithDeepInfo',
272 process.jetCorrFactorsAK8.src=
"selectedUpdatedPatJetsAK8WithDeepInfo" 273 process.updatedJetsAK8.jetSource=
"selectedUpdatedPatJetsAK8WithDeepInfo" 276 from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties
import runMetCorAndUncFromMiniAOD
280 fixEE2017Params = {
'userawPt':
True,
'ptThreshold':50.0,
'minEtaThreshold':2.65,
'maxEtaThreshold': 3.139},
281 postfix =
"FixEE2017")
282 process.nanoSequenceCommon.insert(process.nanoSequenceCommon.index(jetSequence),process.fullPatMetSequenceFixEE2017)
287 nanoAOD_addDeepInfo_switch = cms.PSet(
288 nanoAOD_addDeepBTag_switch = cms.untracked.bool(
False),
289 nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(
False),
291 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepBTag_switch = cms.untracked.bool(
True))
292 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
293 modifier.toModify(nanoAOD_addDeepInfo_switch, nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(
True))
295 addDeepBTag=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepBTag_switch,
296 addDeepFlavour=nanoAOD_addDeepInfo_switch.nanoAOD_addDeepFlavourTag_switch)
297 nanoAOD_addDeepInfoAK8_switch = cms.PSet(
298 nanoAOD_addDeepBTag_switch = cms.untracked.bool(
False),
299 nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(
True),
300 nanoAOD_addDeepDoubleX_switch = cms.untracked.bool(
True),
301 jecPayload = cms.untracked.string(
'AK8PFPuppi')
304 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK8_switch,
305 nanoAOD_addDeepBTag_switch = cms.untracked.bool(
True),
306 nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(
False),
307 nanoAOD_addDeepDoubleX_switch = cms.untracked.bool(
False),
308 jecPayload = cms.untracked.string(
'AK8PFchs'))
310 addDeepBTag=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBTag_switch,
311 addDeepBoostedJet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepBoostedJet_switch,
312 addDeepDoubleX=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleX_switch,
313 jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload)
320 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
327 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
332 _80x_sequence = nanoSequenceCommon.copy()
334 _80x_sequence.remove(isoTrackTables)
335 _80x_sequence.remove(isoTrackSequence)
337 _80x_sequence.insert(_80x_sequence.index(jetSequence), extraFlagsProducers)
338 _80x_sequence.insert(_80x_sequence.index(simpleCleanerTable)+1, extraFlagsTable)
340 run2_miniAOD_80XLegacy.toReplaceWith( nanoSequenceCommon, _80x_sequence)
342 _102x_sequence = nanoSequenceCommon.copy()
344 _102x_sequence.insert(_102x_sequence.index(jetSequence),extraFlagsProducers102x)
345 _102x_sequence.insert(_102x_sequence.index(simpleCleanerTable)+1,extraFlagsTable)
347 for modifier
in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1:
348 modifier.toReplaceWith(nanoSequenceCommon, _102x_sequence)
def nanoAOD_addDeepInfo(process, addDeepBTag, addDeepFlavour)
def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, jecPayload)
S & print(S &os, JobReport::InputFile const &f)
def nanoAOD_customizeMC(process)
def nanoAOD_activateVID(process)
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
def nanoAOD_customizeCommon(process)
def nanoAOD_recalibrateMETs(process, isData)
def nanoAOD_runMETfixEE2017(process, isData)
static std::string join(char **cmd)
def nanoAOD_addTauIds(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, postfix="")
def nanoAOD_customizeData(process)