CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
jets_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
6 
7 
8 ##################### User floats producers, selectors ##########################
9 from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets
10 
11 chsForSATkJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0'))
12 softActivityJets = ak4PFJets.clone(src = 'chsForSATkJets', doAreaFastjet = False, jetPtMin=1)
13 softActivityJets10 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("softActivityJets"), cut = cms.string('pt>10'))
14 softActivityJets5 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("softActivityJets"), cut = cms.string('pt>5'))
15 softActivityJets2 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("softActivityJets"), cut = cms.string('pt>2'))
16 
18 # Note: Safe to always add 'L2L3Residual' as MC contains dummy L2L3Residual corrections (always set to 1)
19 # (cf. https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CMSSW_7_6_4_and_above )
20 jetCorrFactorsNano = patJetCorrFactors.clone(src='slimmedJets',
21  levels = cms.vstring('L1FastJet',
22  'L2Relative',
23  'L3Absolute',
24  'L2L3Residual'),
25  primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
26 )
27 jetCorrFactorsAK8 = patJetCorrFactors.clone(src='slimmedJetsAK8',
28  levels = cms.vstring('L1FastJet',
29  'L2Relative',
30  'L3Absolute',
31  'L2L3Residual'),
32  payload = cms.string('AK8PFPuppi'),
33  primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
34 )
35 run2_miniAOD_80XLegacy.toModify(jetCorrFactorsAK8, payload = cms.string('AK8PFchs')) # ak8PFJetsCHS in 2016 80X miniAOD
36 
38 
39 updatedJets = updatedPatJets.clone(
40  addBTagInfo=False,
41  jetSource='slimmedJets',
42  jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactorsNano") ),
43 )
44 
45 updatedJetsAK8 = updatedPatJets.clone(
46  addBTagInfo=False,
47  jetSource='slimmedJetsAK8',
48  jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactorsAK8") ),
49 )
50 
51 
52 looseJetId = cms.EDProducer("PatJetIDValueMapProducer",
53  filterParams=cms.PSet(
54  version = cms.string('WINTER16'),
55  quality = cms.string('LOOSE'),
56  ),
57  src = cms.InputTag("updatedJets")
58 )
59 tightJetId = cms.EDProducer("PatJetIDValueMapProducer",
60  filterParams=cms.PSet(
61  version = cms.string('RUN2ULCHS'),
62  quality = cms.string('TIGHT'),
63  ),
64  src = cms.InputTag("updatedJets")
65 )
66 tightJetIdLepVeto = cms.EDProducer("PatJetIDValueMapProducer",
67  filterParams=cms.PSet(
68  version = cms.string('RUN2ULCHS'),
69  quality = cms.string('TIGHTLEPVETO'),
70  ),
71  src = cms.InputTag("updatedJets")
72 )
73 run2_jme_2016.toModify( tightJetId.filterParams, version = "RUN2UL16CHS" )
74 run2_jme_2016.toModify( tightJetIdLepVeto.filterParams, version = "RUN2UL16CHS" )
75 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
76  modifier.toModify( tightJetId.filterParams, version = "WINTER16" )
77  modifier.toModify( tightJetIdLepVeto.filterParams, version = "WINTER16" )
78 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
79  modifier.toModify( tightJetId.filterParams, version = "WINTER17" )
80  modifier.toModify( tightJetIdLepVeto.filterParams, version = "WINTER17" )
81 run2_nanoAOD_102Xv1.toModify( tightJetId.filterParams, version = "SUMMER18" )
82 run2_nanoAOD_102Xv1.toModify( tightJetIdLepVeto.filterParams, version = "SUMMER18" )
83 
84 
85 looseJetIdAK8 = cms.EDProducer("PatJetIDValueMapProducer",
86  filterParams=cms.PSet(
87  version = cms.string('WINTER16'),
88  quality = cms.string('LOOSE'),
89  ),
90  src = cms.InputTag("updatedJetsAK8")
91 )
92 tightJetIdAK8 = cms.EDProducer("PatJetIDValueMapProducer",
93  filterParams=cms.PSet(
94  version = cms.string('RUN2ULPUPPI'),
95  quality = cms.string('TIGHT'),
96  ),
97  src = cms.InputTag("updatedJetsAK8")
98 )
99 tightJetIdLepVetoAK8 = cms.EDProducer("PatJetIDValueMapProducer",
100  filterParams=cms.PSet(
101  version = cms.string('RUN2ULPUPPI'),
102  quality = cms.string('TIGHTLEPVETO'),
103  ),
104  src = cms.InputTag("updatedJetsAK8")
105 )
106 run2_jme_2016.toModify( tightJetIdAK8.filterParams, version = "RUN2UL16PUPPI" )
107 run2_jme_2016.toModify( tightJetIdLepVetoAK8.filterParams, version = "RUN2UL16PUPPI" )
108 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
109  modifier.toModify( tightJetIdAK8.filterParams, version = "WINTER16" )
110  modifier.toModify( tightJetIdLepVetoAK8.filterParams, version = "WINTER16" )
111 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
112  modifier.toModify( tightJetIdAK8.filterParams, version = "WINTER17PUPPI" )
113  modifier.toModify( tightJetIdLepVetoAK8.filterParams, version = "WINTER17PUPPI" )
114 run2_nanoAOD_102Xv1.toModify( tightJetIdAK8.filterParams, version = "SUMMER18PUPPI" )
115 run2_nanoAOD_102Xv1.toModify( tightJetIdLepVetoAK8.filterParams, version = "SUMMER18PUPPI" )
116 
117 
118 bJetVars = cms.EDProducer("JetRegressionVarProducer",
119  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
120  src = cms.InputTag("updatedJets"),
121  svsrc = cms.InputTag("slimmedSecondaryVertices"),
122  gpsrc = cms.InputTag("prunedGenParticles"),
123  #musrc = cms.InputTag("slimmedMuons"),
124  #elesrc = cms.InputTag("slimmedElectrons")
125 )
126 
127 jercVars = cms.EDProducer("BetaStarPackedCandidateVarProducer",
128  srcJet = cms.InputTag("updatedJets"),
129  srcPF = cms.InputTag("packedPFCandidates"),
130  maxDR = cms.double(0.4)
131 )
132 
133 updatedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder",
134  src = cms.InputTag("updatedJets"),
135  userFloats = cms.PSet(
136  leadTrackPt = cms.InputTag("bJetVars:leadTrackPt"),
137  leptonPtRel = cms.InputTag("bJetVars:leptonPtRel"),
138  leptonPtRatio = cms.InputTag("bJetVars:leptonPtRatio"),
139  leptonPtRelInv = cms.InputTag("bJetVars:leptonPtRelInv"),
140  leptonPtRelv0 = cms.InputTag("bJetVars:leptonPtRelv0"),
141  leptonPtRatiov0 = cms.InputTag("bJetVars:leptonPtRatiov0"),
142  leptonPtRelInvv0 = cms.InputTag("bJetVars:leptonPtRelInvv0"),
143  leptonDeltaR = cms.InputTag("bJetVars:leptonDeltaR"),
144  leptonPt = cms.InputTag("bJetVars:leptonPt"),
145  vtxPt = cms.InputTag("bJetVars:vtxPt"),
146  vtxMass = cms.InputTag("bJetVars:vtxMass"),
147  vtx3dL = cms.InputTag("bJetVars:vtx3dL"),
148  vtx3deL = cms.InputTag("bJetVars:vtx3deL"),
149  ptD = cms.InputTag("bJetVars:ptD"),
150  genPtwNu = cms.InputTag("bJetVars:genPtwNu"),
151  qgl = cms.InputTag('qgtagger:qgLikelihood'),
152  puId94XDisc = cms.InputTag('pileupJetId94X:fullDiscriminant'),
153  puId102XDisc = cms.InputTag('pileupJetId102X:fullDiscriminant'),
154  puId106XUL16Disc = cms.InputTag('pileupJetId106XUL16:fullDiscriminant'),
155  puId106XUL16APVDisc = cms.InputTag('pileupJetId106XUL16APV:fullDiscriminant'),
156  puId106XUL17Disc = cms.InputTag('pileupJetId106XUL17:fullDiscriminant'),
157  puId106XUL18Disc = cms.InputTag('pileupJetId106XUL18:fullDiscriminant'),
158  chFPV0EF = cms.InputTag("jercVars:chargedFromPV0EnergyFraction"),
159  ),
160  userInts = cms.PSet(
161  tightId = cms.InputTag("tightJetId"),
162  tightIdLepVeto = cms.InputTag("tightJetIdLepVeto"),
163  vtxNtrk = cms.InputTag("bJetVars:vtxNtrk"),
164  leptonPdgId = cms.InputTag("bJetVars:leptonPdgId"),
165  puId106XUL16Id = cms.InputTag('pileupJetId106XUL16:fullId'),
166  puId106XUL16APVId = cms.InputTag('pileupJetId106XUL16APV:fullId'),
167  puId106XUL17Id = cms.InputTag('pileupJetId106XUL17:fullId'),
168  puId106XUL18Id = cms.InputTag('pileupJetId106XUL18:fullId'),
169  ),
170 )
171 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
172  modifier.toModify(updatedJetsWithUserData.userInts,
173  looseId = cms.InputTag("looseJetId"),
174  )
175 
176 updatedJetsAK8WithUserData = cms.EDProducer("PATJetUserDataEmbedder",
177  src = cms.InputTag("updatedJetsAK8"),
178  userInts = cms.PSet(
179  tightId = cms.InputTag("tightJetIdAK8"),
180  tightIdLepVeto = cms.InputTag("tightJetIdLepVetoAK8"),
181  ),
182 )
183 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
184  modifier.toModify(updatedJetsAK8WithUserData.userInts,
185  looseId = cms.InputTag("looseJetIdAK8"),
186  )
187 
188 
189 finalJets = cms.EDFilter("PATJetRefSelector",
190  src = cms.InputTag("updatedJetsWithUserData"),
191  cut = cms.string("pt > 15")
192 )
193 
194 finalJetsAK8 = cms.EDFilter("PATJetRefSelector",
195  src = cms.InputTag("updatedJetsAK8WithUserData"),
196  cut = cms.string("pt > 170")
197 )
198 
199 lepInJetVars = cms.EDProducer("LepInJetProducer",
200  src = cms.InputTag("updatedJetsAK8WithUserData"),
201  srcEle = cms.InputTag("finalElectrons"),
202  srcMu = cms.InputTag("finalMuons")
203 )
204 
205 
206 
207 ##################### Tables for final output and docs ##########################
208 
209 
210 
211 jetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
212  src = cms.InputTag("linkedObjects","jets"),
213  cut = cms.string(""), #we should not filter on cross linked collections
214  name = cms.string("Jet"),
215  doc = cms.string("slimmedJets, i.e. ak4 PFJets CHS with JECs applied, after basic selection (" + finalJets.cut.value()+")"),
216  singleton = cms.bool(False), # the number of entries is variable
217  extension = cms.bool(False), # this is the main table for the jets
218  externalVariables = cms.PSet(
219  bRegCorr = ExtVar(cms.InputTag("bjetNN:corr"),float, doc="pt correction for b-jet energy regression",precision=10),
220  bRegRes = ExtVar(cms.InputTag("bjetNN:res"),float, doc="res on pt corrected with b-jet regression",precision=6),
221  cRegCorr = ExtVar(cms.InputTag("cjetNN:corr"),float, doc="pt correction for c-jet energy regression",precision=10),
222  cRegRes = ExtVar(cms.InputTag("cjetNN:res"),float, doc="res on pt corrected with c-jet regression",precision=6),
223  ),
224  variables = cms.PSet(P4Vars,
225  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
226  nMuons = Var("?hasOverlaps('muons')?overlaps('muons').size():0", int, doc="number of muons in the jet"),
227  muonIdx1 = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", int, doc="index of first matching muon"),
228  muonIdx2 = Var("?overlaps('muons').size()>1?overlaps('muons')[1].key():-1", int, doc="index of second matching muon"),
229  electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"),
230  electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"),
231  nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"),
232  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),
233  btagDeepFlavB = Var("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10),
234  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
235  btagDeepCvL = Var("?bDiscriminator('pfDeepCSVJetTags:probc')>=0?bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')):-1", float,doc="DeepCSV c vs udsg discriminator",precision=10),
236  btagDeepCvB = Var("?bDiscriminator('pfDeepCSVJetTags:probc')>=0?bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')):-1",float,doc="DeepCSV c vs b+bb discriminator",precision=10),
237  btagDeepFlavCvL = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg')):-1",float,doc="DeepJet c vs uds+g discriminator",precision=10),
238  btagDeepFlavCvB = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')):-1",float,doc="DeepJet c vs b+bb+lepb discriminator",precision=10),
239  btagDeepFlavQG = Var("?(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds'))>0?bDiscriminator('pfDeepFlavourJetTags:probg')/(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds')):-1",float,doc="DeepJet g vs uds discriminator",precision=10),
240  puIdDisc = Var("userFloat('puId106XUL18Disc')", float,doc="Pileup ID discriminant with 106X (2018) training",precision=10),
241  puId = Var("userInt('puId106XUL18Id')", int,doc="Pileup ID flags with 106X (2018) training"),
242  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"),
243  qgl = Var("?userFloat('qgl')>0?userFloat('qgl'):-1",float,doc="Quark vs Gluon likelihood discriminator",precision=10),
244  hfsigmaEtaEta = Var("userFloat('hfJetShowerShape:sigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10),
245  hfsigmaPhiPhi = Var("userFloat('hfJetShowerShape:sigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10),
246  hfcentralEtaStripSize = Var("userInt('hfJetShowerShape:centralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable) "),
247  hfadjacentEtaStripsSize = Var("userInt('hfJetShowerShape:adjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable) "),
248  nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
249  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
250  chHEF = Var("chargedHadronEnergyFraction()", float, doc="charged Hadron Energy Fraction", precision= 6),
251  neHEF = Var("neutralHadronEnergyFraction()", float, doc="neutral Hadron Energy Fraction", precision= 6),
252  chEmEF = Var("chargedEmEnergyFraction()", float, doc="charged Electromagnetic Energy Fraction", precision= 6),
253  neEmEF = Var("neutralEmEnergyFraction()", float, doc="neutral Electromagnetic Energy Fraction", precision= 6),
254  muEF = Var("muonEnergyFraction()", float, doc="muon Energy Fraction", precision= 6),
255  chFPV0EF = Var("userFloat('chFPV0EF')", float, doc="charged fromPV==0 Energy Fraction (energy excluded from CHS jets). Previously called betastar.", precision= 6),
256  )
257 )
258 
259 #jets are not as precise as muons
260 jetTable.variables.pt.precision=10
261 
262 ### Era dependent customization
263 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
264  # Deprecated after 106X
265  modifier.toModify(jetTable.variables,
266  btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
267  btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="DeepCSV charm btag discriminator",precision=10),
268  btagDeepFlavC = Var("bDiscriminator('pfDeepFlavourJetTags:probc')",float,doc="DeepFlavour charm tag discriminator",precision=10),
269  )
270 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
271  modifier.toModify( jetTable.variables, jetId = Var("userInt('tightIdLepVeto')*4+userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight, bit3 is tightLepVeto"))
272 run2_nanoAOD_102Xv1.toModify( jetTable.variables, puIdDisc = Var("userFloat('puId102XDisc')",float,doc="Pileup ID discriminant with 102X (2018) training",precision=10) )
273 run2_nanoAOD_102Xv1.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for pre-UL trainings") )
274 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify( jetTable.variables, puId = Var("userInt('puId106XUL16Id')",int,doc="Pileup ID flags with 106X (2016) training"))
275 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify( jetTable.variables, puIdDisc = Var("userFloat('puId106XUL16Disc')",float,doc="Pileup ID discriminant with 106X (2016) training",precision=10))
276 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify( jetTable.variables, puId = Var("userInt('puId106XUL16APVId')",int,doc="Pileup ID flags with 106X (2016APV) training"))
277 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify( jetTable.variables, puIdDisc = Var("userFloat('puId106XUL16APVDisc')",float,doc="Pileup ID discriminant with 106X (2016APV) training",precision=10))
278 run2_jme_2017.toModify( jetTable.variables, puId = Var("userInt('puId106XUL17Id')", int,doc="Pileup ID flags with 106X (2017) training"))
279 run2_jme_2017.toModify( jetTable.variables, puIdDisc = Var("userFloat('puId106XUL17Disc')", float,doc="Pileup ID discriminant with 106X (2017) training",precision=10))
280 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
281  modifier.toModify( jetTable.variables, puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pileup ID discriminant with 80X (2016) training",precision=10))
282  modifier.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for pre-UL trainings"))
283 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
284  modifier.toModify( jetTable.variables, puIdDisc = Var("userFloat('puId94XDisc')", float,doc="Pileup ID discriminant with 94X (2017) training",precision=10))
285  modifier.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for 2016/2017/2018 EOY trainings"))
286 
287 
288 bjetNN= cms.EDProducer("BJetEnergyRegressionMVA",
289  backend = cms.string("ONNX"),
290  batch_eval = cms.bool(True),
291  src = cms.InputTag("linkedObjects","jets"),
292  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
293  svsrc = cms.InputTag("slimmedSecondaryVertices"),
294  rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
295 
296  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2018.onnx"),
297  name = cms.string("JetRegNN"),
298  isClassifier = cms.bool(False),
299  variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR","Jet_neHEF",
300  "Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
301  "Jet_numDaughters_pt03","Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
302  "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
303  "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
304  "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
305  "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
306  "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
307  "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy",
308  "Jet_chHEF","Jet_chEmEF","Jet_leptonPtRelInv","isEle","isMu","isOther","Jet_mass","Jet_ptd"]),
309  variables = cms.PSet(
310  Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
311  Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
312  Jet_eta = cms.string("eta"),
313  Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
314  Jet_ptd = cms.string("userFloat('ptD')"),
315  Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
316  Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
317  Jet_vtxMass = cms.string("userFloat('vtxMass')"),
318  Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
319  Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
320  Jet_vtxPt = cms.string("userFloat('vtxPt')"),
321  #Jet_leptonPt = cms.string("userFloat('leptonPt')"),
322  Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
323  Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
324  Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
325  #Jet_leptonPdgId = cms.string("userInt('leptonPdgId')"),
326  Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
327  Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
328  Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
329  Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
330  isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
331  isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
332  isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
333  ),
334  inputTensorName = cms.string("ffwd_inp:0"),
335  outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
336  outputNames = cms.vstring(["corr","res"]),
337  outputFormulas = cms.vstring(["at(0)*0.27912887930870056+1.0545977354049683","0.5*(at(2)-at(1))*0.27912887930870056"]),
338 )
339 
340 cjetNN= cms.EDProducer("BJetEnergyRegressionMVA",
341  backend = cms.string("ONNX"),
342  batch_eval = cms.bool(True),
343 
344  src = cms.InputTag("linkedObjects","jets"),
345  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
346  svsrc = cms.InputTag("slimmedSecondaryVertices"),
347  rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
348 
349  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2018.onnx"),
350  name = cms.string("JetRegNN"),
351  isClassifier = cms.bool(False),
352  variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR",
353  "Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
354  "Jet_numDaughters_pt03","Jet_chEmEF","Jet_chHEF", "Jet_ptd","Jet_mass",
355  "Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
356  "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
357  "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
358  "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
359  "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
360  "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
361  "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy"]),
362  variables = cms.PSet(
363  Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
364  Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
365  Jet_eta = cms.string("eta"),
366  Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
367  Jet_ptd = cms.string("userFloat('ptD')"),
368  Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
369  Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
370  Jet_vtxMass = cms.string("userFloat('vtxMass')"),
371  Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
372  Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
373  Jet_vtxPt = cms.string("userFloat('vtxPt')"),
374  #Jet_leptonPt = cms.string("userFloat('leptonPt')"),
375  Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
376  Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
377  Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
378  #Jet_leptonPdgId = cms.string("userInt('leptonPdgId')"),
379  Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
380  Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
381  Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
382  Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
383  isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
384  isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
385  isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
386  ),
387  inputTensorName = cms.string("ffwd_inp:0"),
388  outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
389  outputNames = cms.vstring(["corr","res"]),
390  outputFormulas = cms.vstring(["at(0)*0.24325256049633026+0.993854820728302","0.5*(at(2)-at(1))*0.24325256049633026"]),
391 )
392 
393 
394 ##### Soft Activity tables
395 saJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
396  src = cms.InputTag("softActivityJets"),
397  cut = cms.string(""),
398  maxLen = cms.uint32(6),
399  name = cms.string("SoftActivityJet"),
400  doc = cms.string("jets clustered from charged candidates compatible with primary vertex (" + chsForSATkJets.cut.value()+")"),
401  singleton = cms.bool(False), # the number of entries is variable
402  extension = cms.bool(False), # this is the main table for the jets
403  variables = cms.PSet(P3Vars,
404  )
405 )
406 
407 saJetTable.variables.pt.precision=10
408 saJetTable.variables.eta.precision=8
409 saJetTable.variables.phi.precision=8
410 
411 saTable = cms.EDProducer("GlobalVariablesTableProducer",
412  variables = cms.PSet(
413  SoftActivityJetHT = ExtVar( cms.InputTag("softActivityJets"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt>1" ),
414  SoftActivityJetHT10 = ExtVar( cms.InputTag("softActivityJets10"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt , pt >10" ),
415  SoftActivityJetHT5 = ExtVar( cms.InputTag("softActivityJets5"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt>5" ),
416  SoftActivityJetHT2 = ExtVar( cms.InputTag("softActivityJets2"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt >2" ),
417  SoftActivityJetNjets10 = ExtVar( cms.InputTag("softActivityJets10"), "candidatesize", doc = "number of soft activity jet pt, pt >2" ),
418  SoftActivityJetNjets5 = ExtVar( cms.InputTag("softActivityJets5"), "candidatesize", doc = "number of soft activity jet pt, pt >5" ),
419  SoftActivityJetNjets2 = ExtVar( cms.InputTag("softActivityJets2"), "candidatesize", doc = "number of soft activity jet pt, pt >10" ),
420 
421  )
422 )
423 
424 
425 
426 ## BOOSTED STUFF #################
427 fatJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
428  src = cms.InputTag("finalJetsAK8"),
429  cut = cms.string(" pt > 170"), #probably already applied in miniaod
430  name = cms.string("FatJet"),
431  doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
432  singleton = cms.bool(False), # the number of entries is variable
433  extension = cms.bool(False), # this is the main table for the jets
434  variables = cms.PSet(P4Vars,
435  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"),
436  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
437  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
438  tau1 = Var("userFloat('NjettinessAK8Puppi:tau1')",float, doc="Nsubjettiness (1 axis)",precision=10),
439  tau2 = Var("userFloat('NjettinessAK8Puppi:tau2')",float, doc="Nsubjettiness (2 axis)",precision=10),
440  tau3 = Var("userFloat('NjettinessAK8Puppi:tau3')",float, doc="Nsubjettiness (3 axis)",precision=10),
441  tau4 = Var("userFloat('NjettinessAK8Puppi:tau4')",float, doc="Nsubjettiness (4 axis)",precision=10),
442  n2b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN2')?userFloat('nb1AK8PuppiSoftDrop:ecfN2'):-99999.", float, doc="N2 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
443  n3b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN3')?userFloat('nb1AK8PuppiSoftDrop:ecfN3'):-99999.", float, doc="N3 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
444  msoftdrop = Var("groomedMass('SoftDropPuppi')",float, doc="Corrected soft drop mass with PUPPI",precision=10),
445  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),
446  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
447  btagHbb = Var("bDiscriminator('pfBoostedDoubleSecondaryVertexAK8BJetTags')",float,doc="Higgs to BB tagger discriminator",precision=10),
448  btagDDBvLV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleBvLV2JetTags:probHbb')",float,doc="DeepDoubleX V2(mass-decorrelated) discriminator for H(Z)->bb vs QCD",precision=10),
449  btagDDCvLV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleCvLV2JetTags:probHcc')",float,doc="DeepDoubleX V2 (mass-decorrelated) discriminator for H(Z)->cc vs QCD",precision=10),
450  btagDDCvBV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleCvBV2JetTags:probHcc')",float,doc="DeepDoubleX V2 (mass-decorrelated) discriminator for H(Z)->cc vs H(Z)->bb",precision=10),
451  deepTag_TvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:TvsQCD')",float,doc="DeepBoostedJet tagger top vs QCD discriminator",precision=10),
452  deepTag_WvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:WvsQCD')",float,doc="DeepBoostedJet tagger W vs QCD discriminator",precision=10),
453  deepTag_ZvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:ZvsQCD')",float,doc="DeepBoostedJet tagger Z vs QCD discriminator",precision=10),
454  deepTag_H = Var("bDiscriminator('pfDeepBoostedJetTags:probHbb')+bDiscriminator('pfDeepBoostedJetTags:probHcc')+bDiscriminator('pfDeepBoostedJetTags:probHqqqq')",float,doc="DeepBoostedJet tagger H(bb,cc,4q) sum",precision=10),
455  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),
456  deepTag_QCDothers = Var("bDiscriminator('pfDeepBoostedJetTags:probQCDothers')",float,doc="DeepBoostedJet tagger QCDothers value",precision=10),
457  deepTagMD_TvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:TvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger top vs QCD discriminator",precision=10),
458  deepTagMD_WvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:WvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger W vs QCD discriminator",precision=10),
459  deepTagMD_ZvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z vs QCD discriminator",precision=10),
460  deepTagMD_ZHbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H->bb vs QCD discriminator",precision=10),
461  deepTagMD_ZbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z->bb vs QCD discriminator",precision=10),
462  deepTagMD_HbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:HbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger H->bb vs QCD discriminator",precision=10),
463  deepTagMD_ZHccvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHccvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H->cc vs QCD discriminator",precision=10),
464  deepTagMD_H4qvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:H4qvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger H->4q vs QCD discriminator",precision=10),
465  deepTagMD_bbvsLight = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:bbvsLight')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H/gluon->bb vs light flavour discriminator",precision=10),
466  deepTagMD_ccvsLight = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ccvsLight')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H/gluon->cc vs light flavour discriminator",precision=10),
467  particleNet_TvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:TvsQCD')",float,doc="ParticleNet tagger top vs QCD discriminator",precision=10),
468  particleNet_WvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:WvsQCD')",float,doc="ParticleNet tagger W vs QCD discriminator",precision=10),
469  particleNet_ZvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:ZvsQCD')",float,doc="ParticleNet tagger Z vs QCD discriminator",precision=10),
470  particleNet_HbbvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:HbbvsQCD')",float,doc="ParticleNet tagger H(->bb) vs QCD discriminator",precision=10),
471  particleNet_HccvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:HccvsQCD')",float,doc="ParticleNet tagger H(->cc) vs QCD discriminator",precision=10),
472  particleNet_H4qvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:H4qvsQCD')",float,doc="ParticleNet tagger H(->VV->qqqq) vs QCD discriminator",precision=10),
473  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),
474  particleNet_mass = Var("bDiscriminator('pfParticleNetMassRegressionJetTags:mass')",float,doc="ParticleNet mass regression",precision=10),
475  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),
476  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),
477  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),
478  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),
479  subJetIdx1 = Var("?nSubjetCollections()>0 && subjets('SoftDropPuppi').size()>0?subjets('SoftDropPuppi')[0].key():-1", int,
480  doc="index of first subjet"),
481  subJetIdx2 = Var("?nSubjetCollections()>0 && subjets('SoftDropPuppi').size()>1?subjets('SoftDropPuppi')[1].key():-1", int,
482  doc="index of second subjet"),
483 
484 # btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="CMVA V2 btag discriminator",precision=10),
485 #puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pileup ID discriminant",precision=10),
486  nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
487  ),
488  externalVariables = cms.PSet(
489  lsf3 = ExtVar(cms.InputTag("lepInJetVars:lsf3"),float, doc="Lepton Subjet Fraction (3 subjets)",precision=10),
490  muonIdx3SJ = ExtVar(cms.InputTag("lepInJetVars:muIdx3SJ"),int, doc="index of muon matched to jet"),
491  electronIdx3SJ = ExtVar(cms.InputTag("lepInJetVars:eleIdx3SJ"),int,doc="index of electron matched to jet"),
492  )
493 )
494 ### Era dependent customization
495 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
496  modifier.toModify( fatJetTable.variables.n2b1, expr = cms.string("userFloat('ak8PFJetsPuppiSoftDropValueMap:nb1AK8PuppiSoftDropN2')"),)
497  modifier.toModify( fatJetTable.variables.n3b1, expr = cms.string("userFloat('ak8PFJetsPuppiSoftDropValueMap:nb1AK8PuppiSoftDropN3')"),)
498  # Deprecated after 106X
499  modifier.toModify( fatJetTable.variables,
500  btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
501  btagDDBvL_noMD = Var("bDiscriminator('pfDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->bb vs QCD",precision=10),
502  btagDDCvL_noMD = Var("bDiscriminator('pfDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs QCD",precision=10),
503  btagDDCvB_noMD = Var("bDiscriminator('pfDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs H(Z)->bb",precision=10),
504  btagDDBvL = Var("bDiscriminator('pfMassIndependentDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->bb vs QCD",precision=10),
505  btagDDCvL = Var("bDiscriminator('pfMassIndependentDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs QCD",precision=10),
506  btagDDCvB = Var("bDiscriminator('pfMassIndependentDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs H(Z)->bb",precision=10),
507  )
508 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, msoftdrop_chs = Var("userFloat('ak8PFJetsCHSSoftDropMass')",float, doc="Legacy uncorrected soft drop mass with CHS",precision=10))
509 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau1, expr = cms.string("userFloat(\'ak8PFJetsPuppiValueMap:NjettinessAK8PuppiTau1\')"),)
510 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau2, expr = cms.string("userFloat(\'ak8PFJetsPuppiValueMap:NjettinessAK8PuppiTau2\')"),)
511 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau3, expr = cms.string("userFloat(\'ak8PFJetsPuppiValueMap:NjettinessAK8PuppiTau3\')"),)
512 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, tau4 = None)
513 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, n2b1 = None)
514 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, n3b1 = None)
515 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
516  modifier.toModify( fatJetTable.variables, jetId = Var("userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight"))
517 
518 run2_jme_2016.toModify( bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2016.onnx") )
519 run2_jme_2016.toModify( bjetNN,outputFormulas = cms.vstring(["at(0)*0.31976690888404846+1.047176718711853","0.5*(at(2)-at(1))*0.31976690888404846"]))
520 
521 run2_jme_2017.toModify( bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2017.onnx") )
522 run2_jme_2017.toModify( bjetNN,outputFormulas = cms.vstring(["at(0)*0.28225210309028625+1.055067777633667","0.5*(at(2)-at(1))*0.28225210309028625"]))
523 
524 run2_jme_2016.toModify( cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2016.onnx") )
525 run2_jme_2016.toModify( cjetNN,outputFormulas = cms.vstring(["at(0)*0.28862622380256653+0.9908722639083862","0.5*(at(2)-at(1))*0.28862622380256653"]))
526 
527 run2_jme_2017.toModify( cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2017.onnx") )
528 run2_jme_2017.toModify( cjetNN,outputFormulas = cms.vstring(["at(0)*0.24718524515628815+0.9927206635475159","0.5*(at(2)-at(1))*0.24718524515628815"]))
529 
530 
531 
532 subJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
533  src = cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked","SubJets"),
534  cut = cms.string(""), #probably already applied in miniaod
535  name = cms.string("SubJet"),
536  doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
537  singleton = cms.bool(False), # the number of entries is variable
538  extension = cms.bool(False), # this is the main table for the jets
539  variables = cms.PSet(P4Vars,
540  btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV b+bb tag discriminator",precision=10),
541  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
542  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
543  tau1 = Var("userFloat('NjettinessAK8Subjets:tau1')",float, doc="Nsubjettiness (1 axis)",precision=10),
544  tau2 = Var("userFloat('NjettinessAK8Subjets:tau2')",float, doc="Nsubjettiness (2 axis)",precision=10),
545  tau3 = Var("userFloat('NjettinessAK8Subjets:tau3')",float, doc="Nsubjettiness (3 axis)",precision=10),
546  tau4 = Var("userFloat('NjettinessAK8Subjets:tau4')",float, doc="Nsubjettiness (4 axis)",precision=10),
547  n2b1 = Var("userFloat('nb1AK8PuppiSoftDropSubjets:ecfN2')", float, doc="N2 with beta=1", precision=10),
548  n3b1 = Var("userFloat('nb1AK8PuppiSoftDropSubjets:ecfN3')", float, doc="N3 with beta=1", precision=10),
549  )
550 )
551 
552 # Deprecation/backcomp
553 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
554  # post 106X
555  modifier.toModify(subJetTable.variables,
556  btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
557  )
558 
559 #jets are not as precise as muons
560 fatJetTable.variables.pt.precision=10
561 subJetTable.variables.pt.precision=10
562 
563 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau1 = None)
564 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau2 = None)
565 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau3 = None)
566 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau4 = None)
567 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, n2b1 = None)
568 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, n3b1 = None)
569 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, btagCMVA = None, btagDeepB = None)
570 
571 
572 corrT1METJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
573  src = cms.InputTag("corrT1METJets"),
574  cut = cms.string(""),
575  name = cms.string("CorrT1METJet"),
576  doc = cms.string("Additional low-pt jets for Type-1 MET re-correction"),
577  singleton = cms.bool(False), # the number of entries is variable
578  extension = cms.bool(False), # this is the main table for the jets
579  variables = cms.PSet(
580  rawPt = Var("pt()*jecFactor('Uncorrected')",float,precision=10),
581  eta = Var("eta", float,precision=12),
582  phi = Var("phi", float, precision=12),
583  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
584  )
585 )
586 
587 
588 
589 ## MC STUFF ######################
590 jetMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
591  src = cms.InputTag("linkedObjects","jets"),
592  cut = cms.string(""), #we should not filter on cross linked collections
593  name = cms.string("Jet"),
594  singleton = cms.bool(False), # the number of entries is variable
595  extension = cms.bool(True), # this is an extension table for the jets
596  variables = cms.PSet(
597  partonFlavour = Var("partonFlavour()", int, doc="flavour from parton matching"),
598  hadronFlavour = Var("hadronFlavour()", int, doc="flavour from hadron ghost clustering"),
599  genJetIdx = Var("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().key():-1", int, doc="index of matched gen jet"),
600  )
601 )
602 genJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
603  src = cms.InputTag("slimmedGenJets"),
604  cut = cms.string("pt > 10"),
605  name = cms.string("GenJet"),
606  doc = cms.string("slimmedGenJets, i.e. ak4 Jets made with visible genparticles"),
607  singleton = cms.bool(False), # the number of entries is variable
608  extension = cms.bool(False), # this is the main table for the genjets
609  variables = cms.PSet(P4Vars,
610  #anything else?
611  )
612 )
613 patJetPartonsNano = cms.EDProducer('HadronAndPartonSelector',
614  src = cms.InputTag("generator"),
615  particles = cms.InputTag("prunedGenParticles"),
616  partonMode = cms.string("Auto"),
617  fullChainPhysPartons = cms.bool(True)
618 )
619 genJetFlavourAssociation = cms.EDProducer("JetFlavourClustering",
620  jets = genJetTable.src,
621  bHadrons = cms.InputTag("patJetPartonsNano","bHadrons"),
622  cHadrons = cms.InputTag("patJetPartonsNano","cHadrons"),
623  partons = cms.InputTag("patJetPartonsNano","physicsPartons"),
624  leptons = cms.InputTag("patJetPartonsNano","leptons"),
625  jetAlgorithm = cms.string("AntiKt"),
626  rParam = cms.double(0.4),
627  ghostRescaling = cms.double(1e-18),
628  hadronFlavourHasPriority = cms.bool(False)
629 )
630 genJetFlavourTable = cms.EDProducer("GenJetFlavourTableProducer",
631  name = genJetTable.name,
632  src = genJetTable.src,
633  cut = genJetTable.cut,
634  deltaR = cms.double(0.1),
635  jetFlavourInfos = cms.InputTag("slimmedGenJetsFlavourInfos"),
636 )
637 
638 genJetAK8Table = cms.EDProducer("SimpleCandidateFlatTableProducer",
639  src = cms.InputTag("slimmedGenJetsAK8"),
640  cut = cms.string("pt > 100."),
641  name = cms.string("GenJetAK8"),
642  doc = cms.string("slimmedGenJetsAK8, i.e. ak8 Jets made with visible genparticles"),
643  singleton = cms.bool(False), # the number of entries is variable
644  extension = cms.bool(False), # this is the main table for the genjets
645  variables = cms.PSet(P4Vars,
646  #anything else?
647  )
648 )
649 genJetAK8FlavourAssociation = cms.EDProducer("JetFlavourClustering",
650  jets = genJetAK8Table.src,
651  bHadrons = cms.InputTag("patJetPartonsNano","bHadrons"),
652  cHadrons = cms.InputTag("patJetPartonsNano","cHadrons"),
653  partons = cms.InputTag("patJetPartonsNano","physicsPartons"),
654  leptons = cms.InputTag("patJetPartonsNano","leptons"),
655  jetAlgorithm = cms.string("AntiKt"),
656  rParam = cms.double(0.8),
657  ghostRescaling = cms.double(1e-18),
658  hadronFlavourHasPriority = cms.bool(False)
659 )
660 genJetAK8FlavourTable = cms.EDProducer("GenJetFlavourTableProducer",
661  name = genJetAK8Table.name,
662  src = genJetAK8Table.src,
663  cut = genJetAK8Table.cut,
664  deltaR = cms.double(0.1),
665  jetFlavourInfos = cms.InputTag("genJetAK8FlavourAssociation"),
666 )
667 fatJetMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
668  src = fatJetTable.src,
669  cut = fatJetTable.cut,
670  name = fatJetTable.name,
671  singleton = cms.bool(False),
672  extension = cms.bool(True),
673  variables = cms.PSet(
674  nBHadrons = Var("jetFlavourInfo().getbHadrons().size()", "uint8", doc="number of b-hadrons"),
675  nCHadrons = Var("jetFlavourInfo().getcHadrons().size()", "uint8", doc="number of c-hadrons"),
676  hadronFlavour = Var("hadronFlavour()", int, doc="flavour from hadron ghost clustering"),
677  genJetAK8Idx = Var("?genJetFwdRef().backRef().isNonnull() && genJetFwdRef().backRef().pt() > 100.?genJetFwdRef().backRef().key():-1", int, doc="index of matched gen AK8 jet"),
678  )
679 )
680 
681 genSubJetAK8Table = cms.EDProducer("SimpleCandidateFlatTableProducer",
682  src = cms.InputTag("slimmedGenJetsAK8SoftDropSubJets"),
683  cut = cms.string(""), ## These don't get a pt cut, but in miniAOD only subjets from fat jets with pt > 100 are kept
684  name = cms.string("SubGenJetAK8"),
685  doc = cms.string("slimmedGenJetsAK8SoftDropSubJets, i.e. subjets of ak8 Jets made with visible genparticles"),
686  singleton = cms.bool(False), # the number of entries is variable
687  extension = cms.bool(False), # this is the main table for the genjets
688  variables = cms.PSet(P4Vars,
689  #anything else?
690  )
691 )
692 subjetMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
693  src = subJetTable.src,
694  cut = subJetTable.cut,
695  name = subJetTable.name,
696  singleton = cms.bool(False),
697  extension = cms.bool(True),
698  variables = cms.PSet(
699  nBHadrons = Var("jetFlavourInfo().getbHadrons().size()", "uint8", doc="number of b-hadrons"),
700  nCHadrons = Var("jetFlavourInfo().getcHadrons().size()", "uint8", doc="number of c-hadrons"),
701  hadronFlavour = Var("hadronFlavour()", int, doc="flavour from hadron ghost clustering"),
702  )
703 )
704 
705 ### Era dependent customization
706 run2_miniAOD_80XLegacy.toModify( genJetFlavourTable, jetFlavourInfos = cms.InputTag("genJetFlavourAssociation"),)
707 
708 from RecoJets.JetProducers.QGTagger_cfi import QGTagger
709 qgtagger=QGTagger.clone(srcJets="updatedJets",srcVertexCollection="offlineSlimmedPrimaryVertices")
710 
711 
712 from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId, _chsalgos_94x, _chsalgos_102x, _chsalgos_106X_UL16, _chsalgos_106X_UL16APV, _chsalgos_106X_UL17, _chsalgos_106X_UL18
713 pileupJetId94X=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_94x),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
714 pileupJetId102X=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_102x),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
715 pileupJetId106XUL16=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL16),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
716 pileupJetId106XUL16APV=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL16APV),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
717 pileupJetId106XUL17=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL17),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
718 pileupJetId106XUL18=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL18),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
719 
720 #before cross linking
721 jetUserDataTask = cms.Task(bJetVars, qgtagger, jercVars, tightJetId, tightJetIdLepVeto, pileupJetId94X, pileupJetId102X, pileupJetId106XUL16,pileupJetId106XUL16APV,pileupJetId106XUL17,pileupJetId106XUL18)
722 jetAK8UserDataTask = cms.Task(tightJetIdAK8,tightJetIdLepVetoAK8)
723 
724 _jetUserDataTask2016 = jetUserDataTask.copy()
725 _jetUserDataTask2016.add(looseJetId)
726 _jetAK8UserDataTask2016 = jetAK8UserDataTask.copy()
727 _jetAK8UserDataTask2016.add(looseJetIdAK8)
728 
729 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
730  modifier.toReplaceWith(jetUserDataTask,_jetUserDataTask2016)
731  modifier.toReplaceWith(jetAK8UserDataTask,_jetAK8UserDataTask2016)
732 
733 softActivityTask = cms.Task(chsForSATkJets,softActivityJets,softActivityJets2,softActivityJets5,softActivityJets10)
734 
735 #HF shower shape recomputation
736 #Only run if needed (i.e. if default MINIAOD info is missing or outdated because of new JECs...)
737 from RecoJets.JetProducers.hfJetShowerShape_cfi import hfJetShowerShape
738 hfJetShowerShapeforNanoAOD = hfJetShowerShape.clone(jets="updatedJets",vertices="offlineSlimmedPrimaryVertices")
739 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
740  modifier.toModify(updatedJetsWithUserData.userFloats,
741  hfsigmaEtaEta = cms.InputTag('hfJetShowerShapeforNanoAOD:sigmaEtaEta'),
742  hfsigmaPhiPhi = cms.InputTag('hfJetShowerShapeforNanoAOD:sigmaPhiPhi'),
743  )
744  modifier.toModify(updatedJetsWithUserData.userInts,
745  hfcentralEtaStripSize = cms.InputTag('hfJetShowerShapeforNanoAOD:centralEtaStripSize'),
746  hfadjacentEtaStripsSize = cms.InputTag('hfJetShowerShapeforNanoAOD:adjacentEtaStripsSize'),
747  )
748  modifier.toModify( jetTable.variables, hfsigmaEtaEta = Var("userFloat('hfsigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10))
749  modifier.toModify( jetTable.variables, hfsigmaPhiPhi = Var("userFloat('hfsigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10))
750  modifier.toModify( jetTable.variables, hfcentralEtaStripSize = Var("userInt('hfcentralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable) "))
751  modifier.toModify( jetTable.variables, hfadjacentEtaStripsSize = Var("userInt('hfadjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable) "))
752  modifier.toModify(jetUserDataTask, jetUserDataTask.add(hfJetShowerShapeforNanoAOD))
753 
754 #before cross linking
755 jetTask = cms.Task(jetCorrFactorsNano,updatedJets,jetUserDataTask,updatedJetsWithUserData,jetCorrFactorsAK8,updatedJetsAK8,jetAK8UserDataTask,updatedJetsAK8WithUserData,softActivityTask,finalJets,finalJetsAK8)
756 
757 #after lepton collections have been run
758 jetLepTask = cms.Task(lepInJetVars)
759 
760 #after cross linkining
761 jetTablesTask = cms.Task(bjetNN,cjetNN,jetTable,fatJetTable,subJetTable,saJetTable,saTable)
762 
763 #MC only producers and tables
764 jetMCTaskak4 = cms.Task(jetMCTable,genJetTable,patJetPartonsNano,genJetFlavourTable)
765 jetMCTaskak8 = cms.Task(genJetAK8Table,genJetAK8FlavourAssociation,genJetAK8FlavourTable,fatJetMCTable,genSubJetAK8Table,subjetMCTable)
766 jetMCTask = jetMCTaskak4.copy()
767 jetMCTask.add(jetMCTaskak8)
768 
769 _jetMCTaskak8 = jetMCTaskak8.copyAndExclude([genSubJetAK8Table])
770 
771 _jetMC_pre94XTask = jetMCTaskak4.copy()
772 _jetMC_pre94XTask.add(genJetFlavourAssociation)
773 _jetMC_pre94XTask.add(_jetMCTaskak8)
774 run2_miniAOD_80XLegacy.toReplaceWith(jetMCTask, _jetMC_pre94XTask)
def ExtVar
Definition: common_cff.py:31