CMS 3D CMS Logo

jetsAK4_CHS_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
5 
6 
7 
9 # Note: Safe to always add 'L2L3Residual' as MC contains dummy L2L3Residual corrections (always set to 1)
10 # (cf. https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CMSSW_7_6_4_and_above )
11 jetCorrFactorsNano = patJetCorrFactors.clone(src='slimmedJets',
12  levels = cms.vstring('L1FastJet',
13  'L2Relative',
14  'L3Absolute',
15  'L2L3Residual'),
16  primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
17 )
18 
20 updatedJets = updatedPatJets.clone(
21  addBTagInfo=False,
22  jetSource='slimmedJets',
23  jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactorsNano") ),
24 )
25 
26 #
27 # JetID
28 #
29 looseJetId = cms.EDProducer("PatJetIDValueMapProducer",
30  filterParams=cms.PSet(
31  version = cms.string('WINTER16'),
32  quality = cms.string('LOOSE'),
33  ),
34  src = cms.InputTag("updatedJets")
35 )
36 tightJetId = cms.EDProducer("PatJetIDValueMapProducer",
37  filterParams=cms.PSet(
38  version = cms.string('RUN2ULCHS'),
39  quality = cms.string('TIGHT'),
40  ),
41  src = cms.InputTag("updatedJets")
42 )
43 tightJetIdLepVeto = cms.EDProducer("PatJetIDValueMapProducer",
44  filterParams=cms.PSet(
45  version = cms.string('RUN2ULCHS'),
46  quality = cms.string('TIGHTLEPVETO'),
47  ),
48  src = cms.InputTag("updatedJets")
49 )
50 run2_jme_2016.toModify( tightJetId.filterParams, version = "RUN2UL16CHS" )
51 run2_jme_2016.toModify( tightJetIdLepVeto.filterParams, version = "RUN2UL16CHS" )
52 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
53  modifier.toModify( tightJetId.filterParams, version = "WINTER16" )
54  modifier.toModify( tightJetIdLepVeto.filterParams, version = "WINTER16" )
55 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
56  modifier.toModify( tightJetId.filterParams, version = "WINTER17" )
57  modifier.toModify( tightJetIdLepVeto.filterParams, version = "WINTER17" )
58 run2_nanoAOD_102Xv1.toModify( tightJetId.filterParams, version = "SUMMER18" )
59 run2_nanoAOD_102Xv1.toModify( tightJetIdLepVeto.filterParams, version = "SUMMER18" )
60 
61 bJetVars = cms.EDProducer("JetRegressionVarProducer",
62  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
63  src = cms.InputTag("updatedJets"),
64  svsrc = cms.InputTag("slimmedSecondaryVertices"),
65  gpsrc = cms.InputTag("prunedGenParticles"),
66  #musrc = cms.InputTag("slimmedMuons"),
67  #elesrc = cms.InputTag("slimmedElectrons")
68 )
69 
70 jercVars = cms.EDProducer("BetaStarPackedCandidateVarProducer",
71  srcJet = cms.InputTag("updatedJets"),
72  srcPF = cms.InputTag("packedPFCandidates"),
73  maxDR = cms.double(0.4)
74 )
75 
76 updatedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder",
77  src = cms.InputTag("updatedJets"),
78  userFloats = cms.PSet(
79  leadTrackPt = cms.InputTag("bJetVars:leadTrackPt"),
80  leptonPtRel = cms.InputTag("bJetVars:leptonPtRel"),
81  leptonPtRatio = cms.InputTag("bJetVars:leptonPtRatio"),
82  leptonPtRelInv = cms.InputTag("bJetVars:leptonPtRelInv"),
83  leptonPtRelv0 = cms.InputTag("bJetVars:leptonPtRelv0"),
84  leptonPtRatiov0 = cms.InputTag("bJetVars:leptonPtRatiov0"),
85  leptonPtRelInvv0 = cms.InputTag("bJetVars:leptonPtRelInvv0"),
86  leptonDeltaR = cms.InputTag("bJetVars:leptonDeltaR"),
87  leptonPt = cms.InputTag("bJetVars:leptonPt"),
88  vtxPt = cms.InputTag("bJetVars:vtxPt"),
89  vtxMass = cms.InputTag("bJetVars:vtxMass"),
90  vtx3dL = cms.InputTag("bJetVars:vtx3dL"),
91  vtx3deL = cms.InputTag("bJetVars:vtx3deL"),
92  ptD = cms.InputTag("bJetVars:ptD"),
93  genPtwNu = cms.InputTag("bJetVars:genPtwNu"),
94  qgl = cms.InputTag('qgtagger:qgLikelihood'),
95  puIdNanoDisc = cms.InputTag('pileupJetIdNano:fullDiscriminant'),
96  chFPV0EF = cms.InputTag("jercVars:chargedFromPV0EnergyFraction"),
97  ),
98  userInts = cms.PSet(
99  tightId = cms.InputTag("tightJetId"),
100  tightIdLepVeto = cms.InputTag("tightJetIdLepVeto"),
101  vtxNtrk = cms.InputTag("bJetVars:vtxNtrk"),
102  leptonPdgId = cms.InputTag("bJetVars:leptonPdgId"),
103  puIdNanoId = cms.InputTag('pileupJetIdNano:fullId'),
104  ),
105 )
106 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
107  modifier.toModify(updatedJetsWithUserData.userInts,
108  looseId = cms.InputTag("looseJetId"),
109  )
110 
111 
112 finalJets = cms.EDFilter("PATJetRefSelector",
113  src = cms.InputTag("updatedJetsWithUserData"),
114  cut = cms.string("pt > 15")
115 )
116 
117 
118 
119 
120 
121 jetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
122  src = cms.InputTag("linkedObjects","jets"),
123  cut = cms.string(""), #we should not filter on cross linked collections
124  name = cms.string("Jet"),
125  doc = cms.string("slimmedJets, i.e. ak4 PFJets CHS with JECs applied, after basic selection (" + finalJets.cut.value()+")"),
126  singleton = cms.bool(False), # the number of entries is variable
127  extension = cms.bool(False), # this is the main table for the jets
128  externalVariables = cms.PSet(
129  bRegCorr = ExtVar(cms.InputTag("bjetNN:corr"),float, doc="pt correction for b-jet energy regression",precision=10),
130  bRegRes = ExtVar(cms.InputTag("bjetNN:res"),float, doc="res on pt corrected with b-jet regression",precision=6),
131  cRegCorr = ExtVar(cms.InputTag("cjetNN:corr"),float, doc="pt correction for c-jet energy regression",precision=10),
132  cRegRes = ExtVar(cms.InputTag("cjetNN:res"),float, doc="res on pt corrected with c-jet regression",precision=6),
133  ),
134  variables = cms.PSet(P4Vars,
135  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
136  nMuons = Var("?hasOverlaps('muons')?overlaps('muons').size():0", int, doc="number of muons in the jet"),
137  muonIdx1 = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", int, doc="index of first matching muon"),
138  muonIdx2 = Var("?overlaps('muons').size()>1?overlaps('muons')[1].key():-1", int, doc="index of second matching muon"),
139  electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"),
140  electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"),
141  nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"),
142  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),
143  btagDeepFlavB = Var("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10),
144  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
145  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),
146  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),
147  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),
148  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),
149  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),
150  puIdDisc = Var("userFloat('puIdNanoDisc')", float,doc="Pileup ID discriminant with 106X (2018) training",precision=10),
151  puId = Var("userInt('puIdNanoId')", int,doc="Pileup ID flags with 106X (2018) training"),
152  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"),
153  qgl = Var("?userFloat('qgl')>0?userFloat('qgl'):-1",float,doc="Quark vs Gluon likelihood discriminator",precision=10),
154  hfsigmaEtaEta = Var("userFloat('hfJetShowerShape:sigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10),
155  hfsigmaPhiPhi = Var("userFloat('hfJetShowerShape:sigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10),
156  hfcentralEtaStripSize = Var("userInt('hfJetShowerShape:centralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable) "),
157  hfadjacentEtaStripsSize = Var("userInt('hfJetShowerShape:adjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable) "),
158  nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
159  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
160  chHEF = Var("chargedHadronEnergyFraction()", float, doc="charged Hadron Energy Fraction", precision= 6),
161  neHEF = Var("neutralHadronEnergyFraction()", float, doc="neutral Hadron Energy Fraction", precision= 6),
162  chEmEF = Var("chargedEmEnergyFraction()", float, doc="charged Electromagnetic Energy Fraction", precision= 6),
163  neEmEF = Var("neutralEmEnergyFraction()", float, doc="neutral Electromagnetic Energy Fraction", precision= 6),
164  muEF = Var("muonEnergyFraction()", float, doc="muon Energy Fraction", precision= 6),
165  chFPV0EF = Var("userFloat('chFPV0EF')", float, doc="charged fromPV==0 Energy Fraction (energy excluded from CHS jets). Previously called betastar.", precision= 6),
166  )
167 )
168 
169 #jets are not as precise as muons
170 jetTable.variables.pt.precision=10
171 
172 
173 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
174  # Deprecated after 106X
175  modifier.toModify(jetTable.variables,
176  btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
177  btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="DeepCSV charm btag discriminator",precision=10),
178  btagDeepFlavC = Var("bDiscriminator('pfDeepFlavourJetTags:probc')",float,doc="DeepFlavour charm tag discriminator",precision=10),
179  )
180 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
181  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"))
182 
183 run2_nanoAOD_102Xv1.toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 102X (2018) training")
184 run2_nanoAOD_102Xv1.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for pre-UL trainings"))
185 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2016) training")
186 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puId, doc="Pileup ID flags with 106X (2016) training")
187 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2016APV) training")
188 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puId, doc="Pileup ID flags with 106X (2016APV) training")
189 run2_jme_2017.toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2017) training")
190 run2_jme_2017.toModify( jetTable.variables.puId, doc="Pileup ID flags with 106X (2017) training")
191 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
192  modifier.toModify( jetTable.variables, puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pileup ID discriminant with 80X (2016) training",precision=10))
193  modifier.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for pre-UL trainings"))
194 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
195  modifier.toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 94X (2017) training")
196  modifier.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for 2016/2017/2018 EOY trainings"))
197 
198 bjetNN = cms.EDProducer("BJetEnergyRegressionMVA",
199  backend = cms.string("ONNX"),
200  batch_eval = cms.bool(True),
201  src = cms.InputTag("linkedObjects","jets"),
202  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
203  svsrc = cms.InputTag("slimmedSecondaryVertices"),
204  rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
205 
206  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2018.onnx"),
207  name = cms.string("JetRegNN"),
208  isClassifier = cms.bool(False),
209  variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR","Jet_neHEF",
210  "Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
211  "Jet_numDaughters_pt03","Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
212  "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
213  "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
214  "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
215  "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
216  "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
217  "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy",
218  "Jet_chHEF","Jet_chEmEF","Jet_leptonPtRelInv","isEle","isMu","isOther","Jet_mass","Jet_ptd"]),
219  variables = cms.PSet(
220  Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
221  Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
222  Jet_eta = cms.string("eta"),
223  Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
224  Jet_ptd = cms.string("userFloat('ptD')"),
225  Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
226  Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
227  Jet_vtxMass = cms.string("userFloat('vtxMass')"),
228  Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
229  Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
230  Jet_vtxPt = cms.string("userFloat('vtxPt')"),
231  #Jet_leptonPt = cms.string("userFloat('leptonPt')"),
232  Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
233  Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
234  Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
235  #Jet_leptonPdgId = cms.string("userInt('leptonPdgId')"),
236  Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
237  Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
238  Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
239  Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
240  isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
241  isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
242  isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
243  ),
244  inputTensorName = cms.string("ffwd_inp:0"),
245  outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
246  outputNames = cms.vstring(["corr","res"]),
247  outputFormulas = cms.vstring(["at(0)*0.27912887930870056+1.0545977354049683","0.5*(at(2)-at(1))*0.27912887930870056"]),
248 )
249 
250 cjetNN = cms.EDProducer("BJetEnergyRegressionMVA",
251  backend = cms.string("ONNX"),
252  batch_eval = cms.bool(True),
253 
254  src = cms.InputTag("linkedObjects","jets"),
255  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
256  svsrc = cms.InputTag("slimmedSecondaryVertices"),
257  rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
258 
259  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2018.onnx"),
260  name = cms.string("JetRegNN"),
261  isClassifier = cms.bool(False),
262  variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR",
263  "Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
264  "Jet_numDaughters_pt03","Jet_chEmEF","Jet_chHEF", "Jet_ptd","Jet_mass",
265  "Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
266  "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
267  "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
268  "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
269  "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
270  "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
271  "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy"]),
272  variables = cms.PSet(
273  Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
274  Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
275  Jet_eta = cms.string("eta"),
276  Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
277  Jet_ptd = cms.string("userFloat('ptD')"),
278  Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
279  Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
280  Jet_vtxMass = cms.string("userFloat('vtxMass')"),
281  Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
282  Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
283  Jet_vtxPt = cms.string("userFloat('vtxPt')"),
284  #Jet_leptonPt = cms.string("userFloat('leptonPt')"),
285  Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
286  Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
287  Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
288  #Jet_leptonPdgId = cms.string("userInt('leptonPdgId')"),
289  Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
290  Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
291  Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
292  Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
293  isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
294  isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
295  isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
296  ),
297  inputTensorName = cms.string("ffwd_inp:0"),
298  outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
299  outputNames = cms.vstring(["corr","res"]),
300  outputFormulas = cms.vstring(["at(0)*0.24325256049633026+0.993854820728302","0.5*(at(2)-at(1))*0.24325256049633026"]),
301 )
302 
303 
304 run2_jme_2016.toModify( bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2016.onnx") )
305 run2_jme_2016.toModify( bjetNN,outputFormulas = cms.vstring(["at(0)*0.31976690888404846+1.047176718711853","0.5*(at(2)-at(1))*0.31976690888404846"]))
306 
307 run2_jme_2017.toModify( bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2017.onnx") )
308 run2_jme_2017.toModify( bjetNN,outputFormulas = cms.vstring(["at(0)*0.28225210309028625+1.055067777633667","0.5*(at(2)-at(1))*0.28225210309028625"]))
309 
310 run2_jme_2016.toModify( cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2016.onnx") )
311 run2_jme_2016.toModify( cjetNN,outputFormulas = cms.vstring(["at(0)*0.28862622380256653+0.9908722639083862","0.5*(at(2)-at(1))*0.28862622380256653"]))
312 
313 run2_jme_2017.toModify( cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2017.onnx") )
314 run2_jme_2017.toModify( cjetNN,outputFormulas = cms.vstring(["at(0)*0.24718524515628815+0.9927206635475159","0.5*(at(2)-at(1))*0.24718524515628815"]))
315 
316 
317 #
318 # Quark-Gluon Likelihood (QGL)
319 #
320 from RecoJets.JetProducers.QGTagger_cfi import QGTagger
321 qgtagger=QGTagger.clone(srcJets="updatedJets",srcVertexCollection="offlineSlimmedPrimaryVertices")
322 
323 #
324 # PileUp ID
325 #
326 from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId, _chsalgos_94x, _chsalgos_102x, _chsalgos_106X_UL16, _chsalgos_106X_UL16APV, _chsalgos_106X_UL17, _chsalgos_106X_UL18
327 pileupJetIdNano=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL18),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
328 run2_jme_2017.toModify(pileupJetIdNano, algos = _chsalgos_106X_UL17)
329 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify(pileupJetIdNano, algos = _chsalgos_106X_UL16)
330 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify(pileupJetIdNano, algos = _chsalgos_106X_UL16APV)
331 run2_nanoAOD_102Xv1.toModify(pileupJetIdNano, algos = _chsalgos_102x)
332 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
333  modifier.toModify(pileupJetIdNano, algos = _chsalgos_94x)
334 
335 
339 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
340 def nanoAOD_addDeepInfoAK4CHS(process,addDeepBTag,addDeepFlavour):
341  _btagDiscriminators=[]
342  if addDeepBTag:
343  print("Updating process to run DeepCSV btag")
344  _btagDiscriminators += ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc']
345  if addDeepFlavour:
346  print("Updating process to run DeepFlavour btag")
347  _btagDiscriminators += ['pfDeepFlavourJetTags:probb','pfDeepFlavourJetTags:probbb','pfDeepFlavourJetTags:problepb','pfDeepFlavourJetTags:probc']
348  if len(_btagDiscriminators)==0: return process
349  print("Will recalculate the following discriminators: "+", ".join(_btagDiscriminators))
350  updateJetCollection(
351  process,
352  jetSource = cms.InputTag('slimmedJets'),
353  jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute','L2L3Residual']), 'None'),
354  btagDiscriminators = _btagDiscriminators,
355  postfix = 'WithDeepInfo',
356  )
357  process.load("Configuration.StandardSequences.MagneticField_cff")
358  process.jetCorrFactorsNano.src="selectedUpdatedPatJetsWithDeepInfo"
359  process.updatedJets.jetSource="selectedUpdatedPatJetsWithDeepInfo"
360  return process
361 
362 nanoAOD_addDeepInfoAK4CHS_switch = cms.PSet(
363  nanoAOD_addDeepBTag_switch = cms.untracked.bool(False),
364  nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(False),
365 )
366 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK4CHS_switch, nanoAOD_addDeepBTag_switch = cms.untracked.bool(True))
367 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
368  modifier.toModify(nanoAOD_addDeepInfoAK4CHS_switch, nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(True))
369 
372 
373 
376 basicJetsForMetForT1METNano = cms.EDProducer("PATJetCleanerForType1MET",
377  src = updatedJetsWithUserData.src,
378  jetCorrEtaMax = cms.double(9.9),
379  jetCorrLabel = cms.InputTag("L3Absolute"),
380  jetCorrLabelRes = cms.InputTag("L2L3Residual"),
381  offsetCorrLabel = cms.InputTag("L1FastJet"),
382  skipEM = cms.bool(False),
383  skipEMfractionThreshold = cms.double(0.9),
384  skipMuonSelection = cms.string('isGlobalMuon | isStandAloneMuon'),
385  skipMuons = cms.bool(True),
386  type1JetPtThreshold = cms.double(0.0),
387  calcMuonSubtrRawPtAsValueMap = cms.bool(True)
388 )
389 
390 updatedJetsWithUserData.userFloats.muonSubtrRawPt = cms.InputTag("basicJetsForMetForT1METNano:MuonSubtrRawPt")
391 
392 corrT1METJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
393  src = finalJets.src,
394  cut = cms.string("pt<15 && abs(eta)<9.9"),
395  name = cms.string("CorrT1METJet"),
396  doc = cms.string("Additional low-pt ak4 CHS jets for Type-1 MET re-correction"),
397  singleton = cms.bool(False), # the number of entries is variable
398  extension = cms.bool(False), # this is the main table for the jets
399  variables = cms.PSet(
400  rawPt = Var("pt()*jecFactor('Uncorrected')",float,precision=10),
401  eta = Var("eta", float,precision=12),
402  phi = Var("phi", float, precision=12),
403  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
404  )
405 )
406 
407 corrT1METJetTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
408 jetTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
409 
410 jetForMETTask = cms.Task(basicJetsForMetForT1METNano,corrT1METJetTable)
411 
412 #before cross linking
413 jetUserDataTask = cms.Task(bJetVars,qgtagger,jercVars,tightJetId,tightJetIdLepVeto,pileupJetIdNano)
414 
415 #
416 # HF shower shape recomputation
417 # Only run if needed (i.e. if default MINIAOD info is missing or outdated because of new JECs...)
418 #
419 from RecoJets.JetProducers.hfJetShowerShape_cfi import hfJetShowerShape
420 hfJetShowerShapeforNanoAOD = hfJetShowerShape.clone(jets="updatedJets",vertices="offlineSlimmedPrimaryVertices")
421 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
422  modifier.toModify(updatedJetsWithUserData.userFloats,
423  hfsigmaEtaEta = cms.InputTag('hfJetShowerShapeforNanoAOD:sigmaEtaEta'),
424  hfsigmaPhiPhi = cms.InputTag('hfJetShowerShapeforNanoAOD:sigmaPhiPhi'),
425  )
426  modifier.toModify(updatedJetsWithUserData.userInts,
427  hfcentralEtaStripSize = cms.InputTag('hfJetShowerShapeforNanoAOD:centralEtaStripSize'),
428  hfadjacentEtaStripsSize = cms.InputTag('hfJetShowerShapeforNanoAOD:adjacentEtaStripsSize'),
429  )
430  modifier.toModify(jetTable.variables, hfsigmaEtaEta = Var("userFloat('hfsigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10))
431  modifier.toModify(jetTable.variables, hfsigmaPhiPhi = Var("userFloat('hfsigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10))
432  modifier.toModify(jetTable.variables, hfcentralEtaStripSize = Var("userInt('hfcentralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable)"))
433  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)"))
434  modifier.toModify(jetUserDataTask, jetUserDataTask.add(hfJetShowerShapeforNanoAOD))
435 
436 _jetUserDataTask2016 = jetUserDataTask.copy()
437 _jetUserDataTask2016.add(looseJetId)
438 
439 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
440  modifier.toReplaceWith(jetUserDataTask,_jetUserDataTask2016)
441 
442 #before cross linking
443 jetTask = cms.Task(jetCorrFactorsNano,updatedJets,jetUserDataTask,updatedJetsWithUserData,finalJets)
444 
445 #after cross linkining
446 jetTablesTask = cms.Task(bjetNN,cjetNN,jetTable)
def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:31
User floats producers, selectors ##########################.
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def nanoAOD_addDeepInfoAK4CHS(process, addDeepBTag, addDeepFlavour)