CMS 3D CMS Logo

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