CMS 3D CMS Logo

jetsAK8_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
5 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
6 
8 # Note: Safe to always add 'L2L3Residual' as MC contains dummy L2L3Residual corrections (always set to 1)
9 # (cf. https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CMSSW_7_6_4_and_above )
10 jetCorrFactorsAK8 = patJetCorrFactors.clone(src='slimmedJetsAK8',
11  levels = cms.vstring('L1FastJet',
12  'L2Relative',
13  'L3Absolute',
14  'L2L3Residual'),
15  payload = cms.string('AK8PFPuppi'),
16  primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
17 )
18 
20 updatedJetsAK8 = updatedPatJets.clone(
21  addBTagInfo=False,
22  jetSource='slimmedJetsAK8',
23  jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactorsAK8") ),
24 )
25 
26 #
27 # JetID
28 #
29 looseJetIdAK8 = cms.EDProducer("PatJetIDValueMapProducer",
30  filterParams=cms.PSet(
31  version = cms.string('WINTER16'),
32  quality = cms.string('LOOSE'),
33  ),
34  src = cms.InputTag("updatedJetsAK8")
35 )
36 tightJetIdAK8 = cms.EDProducer("PatJetIDValueMapProducer",
37  filterParams=cms.PSet(
38  version = cms.string('RUN2ULPUPPI'),
39  quality = cms.string('TIGHT'),
40  ),
41  src = cms.InputTag("updatedJetsAK8")
42 )
43 tightJetIdLepVetoAK8 = cms.EDProducer("PatJetIDValueMapProducer",
44  filterParams=cms.PSet(
45  version = cms.string('RUN2ULPUPPI'),
46  quality = cms.string('TIGHTLEPVETO'),
47  ),
48  src = cms.InputTag("updatedJetsAK8")
49 )
50 
51 run2_jme_2016.toModify(
52  tightJetIdAK8.filterParams, version = "RUN2UL16PUPPI"
53 ).toModify(
54  tightJetIdLepVetoAK8.filterParams, version = "RUN2UL16PUPPI"
55 )
56 
57 updatedJetsAK8WithUserData = cms.EDProducer("PATJetUserDataEmbedder",
58  src = cms.InputTag("updatedJetsAK8"),
59  userFloats = cms.PSet(),
60  userInts = cms.PSet(
61  tightId = cms.InputTag("tightJetIdAK8"),
62  tightIdLepVeto = cms.InputTag("tightJetIdLepVetoAK8"),
63  ),
64 )
65 
66 finalJetsAK8 = cms.EDFilter("PATJetRefSelector",
67  src = cms.InputTag("updatedJetsAK8WithUserData"),
68  cut = cms.string("pt > 170")
69 )
70 
71 
72 lepInAK8JetVars = cms.EDProducer("LepInJetProducer",
73  src = cms.InputTag("updatedJetsAK8WithUserData"),
74  srcEle = cms.InputTag("finalElectrons"),
75  srcMu = cms.InputTag("finalMuons")
76 )
77 
78 fatJetTable = simpleCandidateFlatTableProducer.clone(
79  src = cms.InputTag("finalJetsAK8"),
80  cut = cms.string(" pt > 170"), #probably already applied in miniaod
81  name = cms.string("FatJet"),
82  doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
83  variables = cms.PSet(P4Vars,
84  jetId = Var("userInt('tightId')*2+4*userInt('tightIdLepVeto')",int,doc="Jet ID flags bit1 is loose (always false in 2017 since it does not exist), bit2 is tight, bit3 is tightLepVeto"),
85  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
86  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
87  tau1 = Var("userFloat('NjettinessAK8Puppi:tau1')",float, doc="Nsubjettiness (1 axis)",precision=10),
88  tau2 = Var("userFloat('NjettinessAK8Puppi:tau2')",float, doc="Nsubjettiness (2 axis)",precision=10),
89  tau3 = Var("userFloat('NjettinessAK8Puppi:tau3')",float, doc="Nsubjettiness (3 axis)",precision=10),
90  tau4 = Var("userFloat('NjettinessAK8Puppi:tau4')",float, doc="Nsubjettiness (4 axis)",precision=10),
91  n2b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN2')?userFloat('nb1AK8PuppiSoftDrop:ecfN2'):-99999.", float, doc="N2 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
92  n3b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN3')?userFloat('nb1AK8PuppiSoftDrop:ecfN3'):-99999.", float, doc="N3 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
93  msoftdrop = Var("groomedMass('SoftDropPuppi')",float, doc="Corrected soft drop mass with PUPPI",precision=10),
94  btagDeepB = Var("?(bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'))>=0?bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'):-1",float,doc="DeepCSV b+bb tag discriminator",precision=10),
95  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
96  btagHbb = Var("bDiscriminator('pfBoostedDoubleSecondaryVertexAK8BJetTags')",float,doc="Higgs to BB tagger discriminator",precision=10),
97  btagDDBvLV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleBvLV2JetTags:probHbb')",float,doc="DeepDoubleX V2(mass-decorrelated) discriminator for H(Z)->bb vs QCD",precision=10),
98  btagDDCvLV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleCvLV2JetTags:probHcc')",float,doc="DeepDoubleX V2 (mass-decorrelated) discriminator for H(Z)->cc vs QCD",precision=10),
99  btagDDCvBV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleCvBV2JetTags:probHcc')",float,doc="DeepDoubleX V2 (mass-decorrelated) discriminator for H(Z)->cc vs H(Z)->bb",precision=10),
100  deepTag_TvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:TvsQCD')",float,doc="DeepBoostedJet tagger top vs QCD discriminator",precision=10),
101  deepTag_WvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:WvsQCD')",float,doc="DeepBoostedJet tagger W vs QCD discriminator",precision=10),
102  deepTag_ZvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:ZvsQCD')",float,doc="DeepBoostedJet tagger Z vs QCD discriminator",precision=10),
103  deepTag_H = Var("bDiscriminator('pfDeepBoostedJetTags:probHbb')+bDiscriminator('pfDeepBoostedJetTags:probHcc')+bDiscriminator('pfDeepBoostedJetTags:probHqqqq')",float,doc="DeepBoostedJet tagger H(bb,cc,4q) sum",precision=10),
104  deepTag_QCD = Var("bDiscriminator('pfDeepBoostedJetTags:probQCDbb')+bDiscriminator('pfDeepBoostedJetTags:probQCDcc')+bDiscriminator('pfDeepBoostedJetTags:probQCDb')+bDiscriminator('pfDeepBoostedJetTags:probQCDc')+bDiscriminator('pfDeepBoostedJetTags:probQCDothers')",float,doc="DeepBoostedJet tagger QCD(bb,cc,b,c,others) sum",precision=10),
105  deepTag_QCDothers = Var("bDiscriminator('pfDeepBoostedJetTags:probQCDothers')",float,doc="DeepBoostedJet tagger QCDothers value",precision=10),
106  deepTagMD_TvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:TvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger top vs QCD discriminator",precision=10),
107  deepTagMD_WvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:WvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger W vs QCD discriminator",precision=10),
108  deepTagMD_ZvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z vs QCD discriminator",precision=10),
109  deepTagMD_ZHbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H->bb vs QCD discriminator",precision=10),
110  deepTagMD_ZbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z->bb vs QCD discriminator",precision=10),
111  deepTagMD_HbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:HbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger H->bb vs QCD discriminator",precision=10),
112  deepTagMD_ZHccvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHccvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H->cc vs QCD discriminator",precision=10),
113  deepTagMD_H4qvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:H4qvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger H->4q vs QCD discriminator",precision=10),
114  deepTagMD_bbvsLight = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:bbvsLight')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H/gluon->bb vs light flavour discriminator",precision=10),
115  deepTagMD_ccvsLight = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ccvsLight')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H/gluon->cc vs light flavour discriminator",precision=10),
116  particleNet_TvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:TvsQCD')",float,doc="ParticleNet tagger top vs QCD discriminator",precision=10),
117  particleNet_WvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:WvsQCD')",float,doc="ParticleNet tagger W vs QCD discriminator",precision=10),
118  particleNet_ZvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:ZvsQCD')",float,doc="ParticleNet tagger Z vs QCD discriminator",precision=10),
119  particleNet_HbbvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:HbbvsQCD')",float,doc="ParticleNet tagger H(->bb) vs QCD discriminator",precision=10),
120  particleNet_HccvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:HccvsQCD')",float,doc="ParticleNet tagger H(->cc) vs QCD discriminator",precision=10),
121  particleNet_H4qvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:H4qvsQCD')",float,doc="ParticleNet tagger H(->VV->qqqq) vs QCD discriminator",precision=10),
122  particleNet_QCD = Var("bDiscriminator('pfParticleNetJetTags:probQCDbb')+bDiscriminator('pfParticleNetJetTags:probQCDcc')+bDiscriminator('pfParticleNetJetTags:probQCDb')+bDiscriminator('pfParticleNetJetTags:probQCDc')+bDiscriminator('pfParticleNetJetTags:probQCDothers')",float,doc="ParticleNet tagger QCD(bb,cc,b,c,others) sum",precision=10),
123  particleNet_mass = Var("bDiscriminator('pfParticleNetMassRegressionJetTags:mass')",float,doc="ParticleNet mass regression",precision=10),
124  particleNetMD_Xbb = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probXbb')",float,doc="Mass-decorrelated ParticleNet tagger raw X->bb score. For X->bb vs QCD tagging, use Xbb/(Xbb+QCD)",precision=10),
125  particleNetMD_Xcc = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probXcc')",float,doc="Mass-decorrelated ParticleNet tagger raw X->cc score. For X->cc vs QCD tagging, use Xcc/(Xcc+QCD)",precision=10),
126  particleNetMD_Xqq = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probXqq')",float,doc="Mass-decorrelated ParticleNet tagger raw X->qq (uds) score. For X->qq vs QCD tagging, use Xqq/(Xqq+QCD). For W vs QCD tagging, use (Xcc+Xqq)/(Xcc+Xqq+QCD)",precision=10),
127  particleNetMD_QCD = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDbb')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDcc')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDb')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDc')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDothers')",float,doc="Mass-decorrelated ParticleNet tagger raw QCD score",precision=10),
128  subJetIdx1 = Var("?nSubjetCollections()>0 && subjets('SoftDropPuppi').size()>0?subjets('SoftDropPuppi')[0].key():-1", int,
129  doc="index of first subjet"),
130  subJetIdx2 = Var("?nSubjetCollections()>0 && subjets('SoftDropPuppi').size()>1?subjets('SoftDropPuppi')[1].key():-1", int,
131  doc="index of second subjet"),
132  nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
133  ),
134  externalVariables = cms.PSet(
135  lsf3 = ExtVar(cms.InputTag("lepInAK8JetVars:lsf3"),float, doc="Lepton Subjet Fraction (3 subjets)",precision=10),
136  muonIdx3SJ = ExtVar(cms.InputTag("lepInAK8JetVars:muIdx3SJ"),int, doc="index of muon matched to jet"),
137  electronIdx3SJ = ExtVar(cms.InputTag("lepInAK8JetVars:eleIdx3SJ"),int,doc="index of electron matched to jet"),
138  )
139 )
140 
141 
145 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
146 def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload):
147  _btagDiscriminators=[]
148  if addDeepBTag:
149  print("Updating process to run DeepCSV btag to AK8 jets")
150  _btagDiscriminators += ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb']
151  if addDeepBoostedJet:
152  print("Updating process to run DeepBoostedJet on datasets before 103X")
153  from RecoBTag.ONNXRuntime.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsAll as pfDeepBoostedJetTagsAll
154  _btagDiscriminators += pfDeepBoostedJetTagsAll
155  if addParticleNet:
156  print("Updating process to run ParticleNet before it's included in MiniAOD")
157  from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetJetTagsAll as pfParticleNetJetTagsAll
158  _btagDiscriminators += pfParticleNetJetTagsAll
159  if addParticleNetMass:
160  from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassRegressionOutputs
161  _btagDiscriminators += _pfParticleNetMassRegressionOutputs
162  if addDeepDoubleX:
163  print("Updating process to run DeepDoubleX on datasets before 104X")
164  _btagDiscriminators += ['pfDeepDoubleBvLJetTags:probHbb', \
165  'pfDeepDoubleCvLJetTags:probHcc', \
166  'pfDeepDoubleCvBJetTags:probHcc', \
167  'pfMassIndependentDeepDoubleBvLJetTags:probHbb', 'pfMassIndependentDeepDoubleCvLJetTags:probHcc', 'pfMassIndependentDeepDoubleCvBJetTags:probHcc']
168  if addDeepDoubleXV2:
169  print("Updating process to run DeepDoubleXv2 on datasets before 11X")
170  _btagDiscriminators += [
171  'pfMassIndependentDeepDoubleBvLV2JetTags:probHbb',
172  'pfMassIndependentDeepDoubleCvLV2JetTags:probHcc',
173  'pfMassIndependentDeepDoubleCvBV2JetTags:probHcc'
174  ]
175  if len(_btagDiscriminators)==0: return process
176  print("Will recalculate the following discriminators on AK8 jets: "+", ".join(_btagDiscriminators))
177  updateJetCollection(
178  process,
179  jetSource = cms.InputTag('slimmedJetsAK8'),
180  pvSource = cms.InputTag('offlineSlimmedPrimaryVertices'),
181  svSource = cms.InputTag('slimmedSecondaryVertices'),
182  rParam = 0.8,
183  jetCorrections = (jecPayload.value(), cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual']), 'None'),
184  btagDiscriminators = _btagDiscriminators,
185  postfix='AK8WithDeepInfo',
186  printWarning = False
187  )
188  process.jetCorrFactorsAK8.src="selectedUpdatedPatJetsAK8WithDeepInfo"
189  process.updatedJetsAK8.jetSource="selectedUpdatedPatJetsAK8WithDeepInfo"
190  return process
191 
192 nanoAOD_addDeepInfoAK8_switch = cms.PSet(
193  nanoAOD_addDeepBTag_switch = cms.untracked.bool(False),
194  nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(False),
195  nanoAOD_addDeepDoubleX_switch = cms.untracked.bool(False),
196  nanoAOD_addDeepDoubleXV2_switch = cms.untracked.bool(False),
197  nanoAOD_addParticleNet_switch = cms.untracked.bool(False),
198  nanoAOD_addParticleNetMass_switch = cms.untracked.bool(False),
199  jecPayload = cms.untracked.string('AK8PFPuppi')
200 )
201 
202 # for 106Xv2: only needs to run ParticleNet Mass regression; The rest are already in MiniAOD
203 run2_nanoAOD_106Xv2.toModify(
204  nanoAOD_addDeepInfoAK8_switch,
205  nanoAOD_addParticleNetMass_switch = True,
206 )
207 
210 
211 subJetTable = simpleCandidateFlatTableProducer.clone(
212  src = cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked","SubJets"),
213  name = cms.string("SubJet"),
214  doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
215  variables = cms.PSet(P4Vars,
216  btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV b+bb tag discriminator",precision=10),
217  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
218  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
219  tau1 = Var("userFloat('NjettinessAK8Subjets:tau1')",float, doc="Nsubjettiness (1 axis)",precision=10),
220  tau2 = Var("userFloat('NjettinessAK8Subjets:tau2')",float, doc="Nsubjettiness (2 axis)",precision=10),
221  tau3 = Var("userFloat('NjettinessAK8Subjets:tau3')",float, doc="Nsubjettiness (3 axis)",precision=10),
222  tau4 = Var("userFloat('NjettinessAK8Subjets:tau4')",float, doc="Nsubjettiness (4 axis)",precision=10),
223  n2b1 = Var("userFloat('nb1AK8PuppiSoftDropSubjets:ecfN2')", float, doc="N2 with beta=1", precision=10),
224  n3b1 = Var("userFloat('nb1AK8PuppiSoftDropSubjets:ecfN3')", float, doc="N3 with beta=1", precision=10),
225  )
226 )
227 
228 #jets are not as precise as muons
229 fatJetTable.variables.pt.precision=10
230 subJetTable.variables.pt.precision=10
231 
232 jetAK8UserDataTask = cms.Task(tightJetIdAK8,tightJetIdLepVetoAK8)
233 jetAK8Task = cms.Task(jetCorrFactorsAK8,updatedJetsAK8,jetAK8UserDataTask,updatedJetsAK8WithUserData,finalJetsAK8)
234 
235 #after lepton collections have been run
236 jetAK8LepTask = cms.Task(lepInAK8JetVars)
237 
238 jetAK8TablesTask = cms.Task(fatJetTable,subJetTable)
def ExtVar(tag, valtype, doc=None, precision=-1)
Definition: common_cff.py:27
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
User floats producers, selectors ##########################.
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload)
Definition: jetsAK8_cff.py:146
static std::string join(char **cmd)
Definition: RemoteFile.cc:19