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 
24 nanoMetadata = cms.EDProducer("UniqueStringProducer",
25  strings = cms.PSet(
26  tag = cms.string("untagged"),
27  )
28 )
29 
30 linkedObjects = cms.EDProducer("PATObjectCrossLinker",
31  jets=cms.InputTag("finalJets"),
32  muons=cms.InputTag("finalMuons"),
33  electrons=cms.InputTag("finalElectrons"),
34  taus=cms.InputTag("finalTaus"),
35  photons=cms.InputTag("finalPhotons"),
36 )
37 
38 simpleCleanerTable = cms.EDProducer("NanoAODSimpleCrossCleaner",
39  name=cms.string("cleanmask"),
40  doc=cms.string("simple cleaning mask with priority to leptons"),
41  jets=cms.InputTag("linkedObjects","jets"),
42  muons=cms.InputTag("linkedObjects","muons"),
43  electrons=cms.InputTag("linkedObjects","electrons"),
44  taus=cms.InputTag("linkedObjects","taus"),
45  photons=cms.InputTag("linkedObjects","photons"),
46  jetSel=cms.string("pt>15"),
47  muonSel=cms.string("isPFMuon && innerTrack.validFraction >= 0.49 && ( isGlobalMuon && globalTrack.normalizedChi2 < 3 && combinedQuality.chi2LocalPosition < 12 && combinedQuality.trkKink < 20 && segmentCompatibility >= 0.303 || segmentCompatibility >= 0.451 )"),
48  electronSel=cms.string(""),
49  tauSel=cms.string(""),
50  photonSel=cms.string(""),
51  jetName=cms.string("Jet"),muonName=cms.string("Muon"),electronName=cms.string("Electron"),
52  tauName=cms.string("Tau"),photonName=cms.string("Photon")
53 )
54 
55 btagSFdir="PhysicsTools/NanoAOD/data/btagSF/"
56 
57 btagWeightTable = cms.EDProducer("BTagSFProducer",
58  src = cms.InputTag("linkedObjects","jets"),
59  cut = cms.string("pt > 25. && abs(eta) < 2.5"),
60  discNames = cms.vstring(
61  "pfCombinedInclusiveSecondaryVertexV2BJetTags",
62  "pfDeepCSVJetTags:probb+pfDeepCSVJetTags:probbb", #if multiple MiniAOD branches need to be summed up (e.g., DeepCSV b+bb), separate them using '+' delimiter
63  "pfCombinedMVAV2BJetTags"
64  ),
65  discShortNames = cms.vstring(
66  "CSVV2",
67  "DeepCSVB",
68  "CMVA"
69  ),
70  weightFiles = cms.vstring( #default settings are for 2017 94X. toModify function is called later for other eras.
71  btagSFdir+"CSVv2_94XSF_V2_B_F.csv",
72  btagSFdir+"DeepCSV_94XSF_V2_B_F.csv",
73  "unavailable" #if SFs for an algorithm in an era is unavailable, the corresponding branch will not be stored
74  ),
75  operatingPoints = cms.vstring("3","3","3"), #loose = 0, medium = 1, tight = 2, reshaping = 3
76  measurementTypesB = cms.vstring("iterativefit","iterativefit","iterativefit"), #e.g. "comb", "incl", "ttbar", "iterativefit"
77  measurementTypesC = cms.vstring("iterativefit","iterativefit","iterativefit"),
78  measurementTypesUDSG = cms.vstring("iterativefit","iterativefit","iterativefit"),
79  sysTypes = cms.vstring("central","central","central")
80 )
81 
82 run2_miniAOD_80XLegacy.toModify(btagWeightTable,
83  cut = cms.string("pt > 25. && abs(eta) < 2.4"), #80X corresponds to 2016, |eta| < 2.4
84  weightFiles = cms.vstring( #80X corresponds to 2016 SFs
85  btagSFdir+"CSVv2_Moriond17_B_H.csv",
86  "unavailable",
87  btagSFdir+"cMVAv2_Moriond17_B_H.csv"
88  )
89 )
90 
91 run2_nanoAOD_92X.toModify(btagWeightTable, #92X corresponds to MCv1, for which SFs are unavailable
92  weightFiles = cms.vstring(
93  "unavailable",
94  "unavailable",
95  "unavailable"
96  )
97 )
98 
99 genWeightsTable = cms.EDProducer("GenWeightsTableProducer",
100  genEvent = cms.InputTag("generator"),
101  lheInfo = cms.InputTag("externalLHEProducer"),
102  preferredPDFs = cms.VPSet( # see https://lhapdf.hepforge.org/pdfsets.html
103  cms.PSet( name = cms.string("PDF4LHC15_nnlo_30_pdfas"), lhaid = cms.uint32(91400) ),
104  cms.PSet( name = cms.string("NNPDF31_nnlo_hessian_pdfas"), lhaid = cms.uint32(306000) ),
105  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 ...
106  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 )
107  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)
108  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)
109  ),
110  namedWeightIDs = cms.vstring(),
111  namedWeightLabels = cms.vstring(),
112  lheWeightPrecision = cms.int32(14),
113  maxPdfWeights = cms.uint32(150),
114  debug = cms.untracked.bool(False),
115 )
116 lheInfoTable = cms.EDProducer("LHETablesProducer",
117  lheInfo = cms.InputTag("externalLHEProducer"),
118  precision = cms.int32(14),
119  storeLHEParticles = cms.bool(True)
120 )
121 
122 l1bits=cms.EDProducer("L1TriggerResultsConverter", src=cms.InputTag("gtStage2Digis"), legacyL1=cms.bool(False))
123 
124 nanoSequence = cms.Sequence(
125  nanoMetadata + jetSequence + muonSequence + tauSequence + electronSequence+photonSequence+vertexSequence+metSequence+
126  isoTrackSequence + # must be after all the leptons
127  linkedObjects +
128  jetTables + muonTables + tauTables + electronTables + photonTables + globalTables +vertexTables+ metTables+simpleCleanerTable + triggerObjectTables + isoTrackTables +
129  l1bits)
130 
131 nanoSequenceMC = cms.Sequence(genParticleSequence + particleLevelSequence + nanoSequence + jetMC + muonMC + electronMC + photonMC + tauMC + metMC + ttbarCatMCProducers + globalTablesMC + btagWeightTable + genWeightsTable + genParticleTables + particleLevelTables + lheInfoTable + ttbarCategoryTable )
132 
133 
134 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
135 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask
137  print("Updating process to run DeepCSV btag on legacy 80X datasets")
138  updateJetCollection(
139  process,
140  jetSource = cms.InputTag('slimmedJets'),
141  jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute','L2L3Residual']), 'None'),
142  btagDiscriminators = ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc'], ## to add discriminators
143  btagPrefix = ''
144  )
145  process.load("Configuration.StandardSequences.MagneticField_cff")
146  process.looseJetId.src="selectedUpdatedPatJets"
147  process.tightJetId.src="selectedUpdatedPatJets"
148  process.tightJetIdLepVeto.src="selectedUpdatedPatJets"
149  process.bJetVars.src="selectedUpdatedPatJets"
150  process.slimmedJetsWithUserData.src="selectedUpdatedPatJets"
151  process.qgtagger80x.srcJets="selectedUpdatedPatJets"
152  patAlgosToolsTask = getPatAlgosToolsTask(process)
153  patAlgosToolsTask .add(process.updatedPatJets)
154  patAlgosToolsTask .add(process.patJetCorrFactors)
155  process.additionalendpath = cms.EndPath(patAlgosToolsTask)
156  return process
158  print("Updating process to run DeepCSV btag on 94X re-miniAOD of legacy 80X datasets")
159  updateJetCollection(
160  process,
161  jetSource = cms.InputTag('slimmedJets'),
162  jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute','L2L3Residual']), 'None'),
163  btagDiscriminators = ['pfDeepFlavourJetTags:probb','pfDeepFlavourJetTags:probbb','pfDeepFlavourJetTags:problepb'], ## to add discriminators
164  btagPrefix = ''
165  )
166  process.load("Configuration.StandardSequences.MagneticField_cff")
167  process.looseJetId.src="selectedUpdatedPatJets"
168  process.tightJetId.src="selectedUpdatedPatJets"
169  process.tightJetIdLepVeto.src="selectedUpdatedPatJets"
170  process.bJetVars.src="selectedUpdatedPatJets"
171  process.slimmedJetsWithUserData.src="selectedUpdatedPatJets"
172  process.qgtagger80x.srcJets="selectedUpdatedPatJets"
173  process.pfDeepFlavourJetTags.graph_path = 'RecoBTag/Combined/data/DeepFlavourV03_10X_training/constant_graph.pb'
174  process.pfDeepFlavourJetTags.lp_names = ["cpf_input_batchnorm/keras_learning_phase"]
175  patAlgosToolsTask = getPatAlgosToolsTask(process)
176  patAlgosToolsTask .add(process.updatedPatJets)
177  patAlgosToolsTask .add(process.patJetCorrFactors)
178  process.additionalendpath = cms.EndPath(patAlgosToolsTask)
179  return process
180 
181 
183  run2_miniAOD_80XLegacy.toModify(process, nanoAOD_addDeepBTagFor80X)
184  run2_nanoAOD_94X2016.toModify(process, nanoAOD_addDeepFlavourTagFor94X2016)
185  return process
186 
187 
189  process = nanoAOD_customizeCommon(process)
190  if hasattr(process,'calibratedPatElectrons80X'):
191  process.calibratedPatElectrons80X.isMC = cms.bool(False)
192  process.calibratedPatPhotons80X.isMC = cms.bool(False)
193  return process
194 
195 def nanoAOD_customizeMC(process):
196  process = nanoAOD_customizeCommon(process)
197  if hasattr(process,'calibratedPatElectrons80X'):
198  process.calibratedPatElectrons80X.isMC = cms.bool(True)
199  process.calibratedPatPhotons80X.isMC = cms.bool(True)
200  return process
201 
202 ### Era dependent customization
203 _80x_sequence = nanoSequence.copy()
204 #remove stuff
205 _80x_sequence.remove(isoTrackTable)
206 _80x_sequence.remove(isoTrackSequence)
207 #add stuff
208 _80x_sequence.insert(_80x_sequence.index(jetSequence), extraFlagsProducers)
209 _80x_sequence.insert(_80x_sequence.index(l1bits)+1, extraFlagsTable)
210 
211 run2_miniAOD_80XLegacy.toReplaceWith( nanoSequence, _80x_sequence)
212 
213 
214 
def nanoAOD_addDeepBTagFor80X(process)
Definition: nano_cff.py:136
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def nanoAOD_customizeMC(process)
Definition: nano_cff.py:195
def nanoAOD_customizeCommon(process)
Definition: nano_cff.py:182
def nanoAOD_addDeepFlavourTagFor94X2016(process)
Definition: nano_cff.py:157
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
def getPatAlgosToolsTask(process)
Definition: helpers.py:14
def nanoAOD_customizeData(process)
Definition: nano_cff.py:188