CMS 3D CMS Logo

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