CMS 3D CMS Logo

jetsAK4_CHS_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
5 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
6 
7 
8 
10 # Note: Safe to always add 'L2L3Residual' as MC contains dummy L2L3Residual corrections (always set to 1)
11 # (cf. https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CMSSW_7_6_4_and_above )
12 jetCorrFactorsNano = patJetCorrFactors.clone(src='slimmedJets',
13  levels = cms.vstring('L1FastJet',
14  'L2Relative',
15  'L3Absolute',
16  'L2L3Residual'),
17  primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
18 )
19 
21 updatedJets = updatedPatJets.clone(
22  addBTagInfo=False,
23  jetSource='slimmedJets',
24  jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactorsNano") ),
25 )
26 
27 #
28 # JetID
29 #
30 looseJetId = cms.EDProducer("PatJetIDValueMapProducer",
31  filterParams=cms.PSet(
32  version = cms.string('WINTER16'),
33  quality = cms.string('LOOSE'),
34  ),
35  src = cms.InputTag("updatedJets")
36 )
37 tightJetId = cms.EDProducer("PatJetIDValueMapProducer",
38  filterParams=cms.PSet(
39  version = cms.string('RUN3WINTER22CHS'),
40  quality = cms.string('TIGHT'),
41  ),
42  src = cms.InputTag("updatedJets")
43 )
44 tightJetIdLepVeto = cms.EDProducer("PatJetIDValueMapProducer",
45  filterParams=cms.PSet(
46  version = cms.string('RUN3WINTER22CHS'),
47  quality = cms.string('TIGHTLEPVETO'),
48  ),
49  src = cms.InputTag("updatedJets")
50 )
51 run2_jme_2016.toModify(
52  tightJetId.filterParams, version = "RUN2UL16CHS"
53 ).toModify(
54  tightJetIdLepVeto.filterParams, version = "RUN2UL16CHS"
55 )
56 
57 (run2_jme_2017 | run2_jme_2018).toModify(
58  tightJetId.filterParams, version = "RUN2ULCHS"
59 ).toModify(
60  tightJetIdLepVeto.filterParams, version = "RUN2ULCHS"
61 )
62 
63 run3_jme_Winter22runsBCDEprompt.toModify(
64  tightJetId.filterParams, version = "RUN3WINTER22CHSrunsBCDEprompt"
65 ).toModify(
66  tightJetIdLepVeto.filterParams, version = "RUN3WINTER22CHSrunsBCDEprompt"
67 )
68 
69 bJetVars = cms.EDProducer("JetRegressionVarProducer",
70  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
71  src = cms.InputTag("updatedJets"),
72  svsrc = cms.InputTag("slimmedSecondaryVertices"),
73 )
74 
75 jercVars = cms.EDProducer("BetaStarPackedCandidateVarProducer",
76  srcJet = cms.InputTag("updatedJets"),
77  srcPF = cms.InputTag("packedPFCandidates"),
78  maxDR = cms.double(0.4)
79 )
80 
81 updatedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder",
82  src = cms.InputTag("updatedJets"),
83  userFloats = cms.PSet(
84  leadTrackPt = cms.InputTag("bJetVars:leadTrackPt"),
85  leptonPtRelv0 = cms.InputTag("bJetVars:leptonPtRelv0"),
86  leptonPtRelInvv0 = cms.InputTag("bJetVars:leptonPtRelInvv0"),
87  leptonDeltaR = cms.InputTag("bJetVars:leptonDeltaR"),
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  qgl = cms.InputTag('qgtagger:qgLikelihood'),
94  puIdNanoDisc = cms.InputTag('pileupJetIdNano:fullDiscriminant'),
95  chFPV0EF = cms.InputTag("jercVars:chargedFromPV0EnergyFraction"),
96  ),
97  userInts = cms.PSet(
98  tightId = cms.InputTag("tightJetId"),
99  tightIdLepVeto = cms.InputTag("tightJetIdLepVeto"),
100  vtxNtrk = cms.InputTag("bJetVars:vtxNtrk"),
101  leptonPdgId = cms.InputTag("bJetVars:leptonPdgId"),
102  puIdNanoId = cms.InputTag('pileupJetIdNano:fullId'),
103  ),
104 )
105 
106 
107 finalJets = cms.EDFilter("PATJetRefSelector",
108  src = cms.InputTag("updatedJetsWithUserData"),
109  cut = cms.string("pt > 15")
110 )
111 
112 
113 
114 
115 
116 jetTable = simpleCandidateFlatTableProducer.clone(
117  src = cms.InputTag("linkedObjects","jets"),
118  name = cms.string("Jet"),
119  doc = cms.string("slimmedJets, i.e. ak4 PFJets CHS with JECs applied, after basic selection (" + finalJets.cut.value()+")"),
120  externalVariables = cms.PSet(
121  bRegCorr = ExtVar(cms.InputTag("bjetNN:corr"),float, doc="pt correction for b-jet energy regression",precision=10),
122  bRegRes = ExtVar(cms.InputTag("bjetNN:res"),float, doc="res on pt corrected with b-jet regression",precision=6),
123  cRegCorr = ExtVar(cms.InputTag("cjetNN:corr"),float, doc="pt correction for c-jet energy regression",precision=10),
124  cRegRes = ExtVar(cms.InputTag("cjetNN:res"),float, doc="res on pt corrected with c-jet regression",precision=6),
125  ),
126  variables = cms.PSet(P4Vars,
127  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
128  nMuons = Var("?hasOverlaps('muons')?overlaps('muons').size():0", "uint8", doc="number of muons in the jet"),
129  muonIdx1 = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", "int16", doc="index of first matching muon"),
130  muonIdx2 = Var("?overlaps('muons').size()>1?overlaps('muons')[1].key():-1", "int16", doc="index of second matching muon"),
131  electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", "int16", doc="index of first matching electron"),
132  electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", "int16", doc="index of second matching electron"),
133  nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", "uint8", doc="number of electrons in the jet"),
134  svIdx1 = Var("?overlaps('vertices').size()>0?overlaps('vertices')[0].key():-1", "int16", doc="index of first matching secondary vertex"),
135  svIdx2 = Var("?overlaps('vertices').size()>1?overlaps('vertices')[1].key():-1", "int16", doc="index of second matching secondary vertex"),
136  nSVs = Var("?hasOverlaps('vertices')?overlaps('vertices').size():0", "uint8", doc="number of secondary vertices in the jet"),
137  btagDeepFlavB = Var("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10),
138  btagRobustParTAK4B = Var("bDiscriminator('pfParticleTransformerAK4JetTags:probb')+bDiscriminator('pfParticleTransformerAK4JetTags:probbb')+bDiscriminator('pfParticleTransformerAK4JetTags:problepb')",
139  float,
140  doc="RobustParTAK4 b+bb+lepb tag discriminator",
141  precision=10),
142  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),
143  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),
144  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),
145  btagRobustParTAK4CvL = Var("?(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probuds')+bDiscriminator('pfParticleTransformerAK4JetTags:probg'))>0?bDiscriminator('pfParticleTransformerAK4JetTags:probc')/(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probuds')+bDiscriminator('pfParticleTransformerAK4JetTags:probg')):-1",
146  float,
147  doc="RobustParTAK4 c vs uds+g discriminator",
148  precision=10),
149  btagRobustParTAK4CvB = Var("?(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probb')+bDiscriminator('pfParticleTransformerAK4JetTags:probbb')+bDiscriminator('pfParticleTransformerAK4JetTags:problepb'))>0?bDiscriminator('pfParticleTransformerAK4JetTags:probc')/(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')):-1",
150  float,
151  doc="RobustParTAK4 c vs b+bb+lepb discriminator",
152  precision=10),
153  btagRobustParTAK4QG = Var("?(bDiscriminator('pfParticleTransformerAK4JetTags:probg')+bDiscriminator('pfParticleTransformerAK4JetTags:probuds'))>0?bDiscriminator('pfParticleTransformerAK4JetTags:probg')/(bDiscriminator('pfParticleTransformerAK4JetTags:probg')+bDiscriminator('pfParticleTransformerAK4JetTags:probuds')):-1",
154  float,
155  doc="RobustParTAK4 g vs uds discriminator",
156  precision=10),
157  btagPNetB = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:BvsAll')>0?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:BvsAll'):-1",float,precision=10,doc="ParticleNet b vs. udscg"),
158  btagPNetCvL = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:CvsL')>0?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:CvsL'):-1",float,precision=10,doc="ParticleNet c vs. udsg"),
159  btagPNetCvB = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:CvsB')>0?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:CvsB'):-1",float,precision=10,doc="ParticleNet c vs. b"),
160  btagPNetQvG = Var("?abs(eta())<2.5?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:QvsG'):bDiscriminator('pfParticleNetFromMiniAODAK4CHSForwardDiscriminatorsJetTags:QvsG')",float,precision=10,doc="ParticleNet q (udsbc) vs. g"),
161  btagPNetTauVJet = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:TauVsJet')>0?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags:TauVsJet'):-1",float,precision=10,doc="ParticleNet tau vs. jet"),
162  PNetRegPtRawCorr = Var("?abs(eta())<2.5?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralJetTags:ptcorr'):bDiscriminator('pfParticleNetFromMiniAODAK4CHSForwardJetTags:ptcorr')",float,precision=10,doc="ParticleNet universal flavor-aware visible pT regression (no neutrinos), correction relative to raw jet pT"),
163  PNetRegPtRawCorrNeutrino = Var("?abs(eta())<2.5?bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralJetTags:ptnu'):bDiscriminator('pfParticleNetFromMiniAODAK4CHSForwardJetTags:ptnu')",float,precision=10,doc="ParticleNet universal flavor-aware pT regression neutrino correction, relative to visible. To apply full regression, multiply raw jet pT by both PNetRegPtRawCorr and PNetRegPtRawCorrNeutrino."),
164  PNetRegPtRawRes = Var("?abs(eta())<2.5?0.5*(bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralJetTags:ptreshigh')-bDiscriminator('pfParticleNetFromMiniAODAK4CHSCentralJetTags:ptreslow')):0.5*(bDiscriminator('pfParticleNetFromMiniAODAK4CHSForwardJetTags:ptreshigh')-bDiscriminator('pfParticleNetFromMiniAODAK4CHSForwardJetTags:ptreslow'))",float,precision=10,doc="ParticleNet universal flavor-aware jet pT resolution estimator, (q84 - q16)/2"),
165  puIdDisc = Var("userFloat('puIdNanoDisc')", float,doc="Pileup ID discriminant with 106X (2018) training",precision=10),
166  puId = Var("userInt('puIdNanoId')", "uint8", doc="Pileup ID flags with 106X (2018) training"),
167  jetId = Var("userInt('tightId')*2+4*userInt('tightIdLepVeto')", "uint8", doc="Jet ID flags bit1 is loose (always false in 2017 since it does not exist), bit2 is tight, bit3 is tightLepVeto"),
168  qgl = Var("?userFloat('qgl')>0?userFloat('qgl'):-1",float,doc="Quark vs Gluon likelihood discriminator",precision=10),
169  hfsigmaEtaEta = Var("userFloat('hfJetShowerShape:sigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10),
170  hfsigmaPhiPhi = Var("userFloat('hfJetShowerShape:sigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10),
171  hfcentralEtaStripSize = Var("userInt('hfJetShowerShape:centralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable) "),
172  hfadjacentEtaStripsSize = Var("userInt('hfJetShowerShape:adjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable) "),
173  nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
174  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
175  chHEF = Var("chargedHadronEnergyFraction()", float, doc="charged Hadron Energy Fraction", precision= 6),
176  neHEF = Var("neutralHadronEnergyFraction()", float, doc="neutral Hadron Energy Fraction", precision= 6),
177  chEmEF = Var("chargedEmEnergyFraction()", float, doc="charged Electromagnetic Energy Fraction", precision= 6),
178  neEmEF = Var("neutralEmEnergyFraction()", float, doc="neutral Electromagnetic Energy Fraction", precision= 6),
179  muEF = Var("muonEnergyFraction()", float, doc="muon Energy Fraction", precision= 6),
180  chFPV0EF = Var("userFloat('chFPV0EF')", float, doc="charged fromPV==0 Energy Fraction (energy excluded from CHS jets). Previously called betastar.", precision= 6),
181  )
182 )
183 
184 #jets are not as precise as muons
185 jetTable.variables.pt.precision=10
186 
187 
188 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify(
189  jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2016) training"
190 ).toModify(
191  jetTable.variables.puId, doc="Pileup ID flags with 106X (2016) training"
192 )
193 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify(
194  jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2016APV) training"
195 ).toModify(
196  jetTable.variables.puId, doc="Pileup ID flags with 106X (2016APV) training"
197 )
198 run2_jme_2017.toModify(
199  jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2017) training"
200 ).toModify(
201  jetTable.variables.puId, doc="Pileup ID flags with 106X (2017) training"
202 )
203 
204 run2_nanoAOD_ANY.toModify(
205  jetTable.variables,
206  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
207  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),
208  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),
209  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)
210 )
211 
212 (run3_nanoAOD_122 | run3_nanoAOD_124).toModify(
213  # New ParticleNet trainings are not available in MiniAOD until Run3 13X
214  jetTable.variables,
215  btagPNetB = None,
216  btagPNetCvL = None,
217  btagPNetCvB = None,
218  btagPNetQvG = None,
219  btagPNetTauVJet = None,
220  PNetRegPtRawCorr = None,
221  PNetRegPtRawCorrNeutrino = None,
222  PNetRegPtRawRes = None
223 )
224 
225 bjetNN = cms.EDProducer("BJetEnergyRegressionMVA",
226  backend = cms.string("ONNX"),
227  batch_eval = cms.bool(True),
228  src = cms.InputTag("linkedObjects","jets"),
229  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
230  svsrc = cms.InputTag("slimmedSecondaryVertices"),
231  rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
232 
233  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2018.onnx"),
234  name = cms.string("JetRegNN"),
235  isClassifier = cms.bool(False),
236  variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR","Jet_neHEF",
237  "Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
238  "Jet_numDaughters_pt03","Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
239  "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
240  "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
241  "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
242  "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
243  "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
244  "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy",
245  "Jet_chHEF","Jet_chEmEF","Jet_leptonPtRelInv","isEle","isMu","isOther","Jet_mass","Jet_ptd"]),
246  variables = cms.PSet(
247  Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
248  Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
249  Jet_eta = cms.string("eta"),
250  Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
251  Jet_ptd = cms.string("userFloat('ptD')"),
252  Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
253  Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
254  Jet_vtxMass = cms.string("userFloat('vtxMass')"),
255  Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
256  Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
257  Jet_vtxPt = cms.string("userFloat('vtxPt')"),
258  Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
259  Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
260  Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
261  Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
262  Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
263  Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
264  Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
265  isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
266  isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
267  isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
268  ),
269  inputTensorName = cms.string("ffwd_inp:0"),
270  outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
271  outputNames = cms.vstring(["corr","res"]),
272  outputFormulas = cms.vstring(["at(0)*0.27912887930870056+1.0545977354049683","0.5*(at(2)-at(1))*0.27912887930870056"]),
273 )
274 
275 cjetNN = cms.EDProducer("BJetEnergyRegressionMVA",
276  backend = cms.string("ONNX"),
277  batch_eval = cms.bool(True),
278 
279  src = cms.InputTag("linkedObjects","jets"),
280  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
281  svsrc = cms.InputTag("slimmedSecondaryVertices"),
282  rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
283 
284  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2018.onnx"),
285  name = cms.string("JetRegNN"),
286  isClassifier = cms.bool(False),
287  variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR",
288  "Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
289  "Jet_numDaughters_pt03","Jet_chEmEF","Jet_chHEF", "Jet_ptd","Jet_mass",
290  "Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
291  "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
292  "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
293  "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
294  "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
295  "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
296  "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy"]),
297  variables = cms.PSet(
298  Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
299  Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
300  Jet_eta = cms.string("eta"),
301  Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
302  Jet_ptd = cms.string("userFloat('ptD')"),
303  Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
304  Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
305  Jet_vtxMass = cms.string("userFloat('vtxMass')"),
306  Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
307  Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
308  Jet_vtxPt = cms.string("userFloat('vtxPt')"),
309  Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
310  Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
311  Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
312  Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
313  Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
314  Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
315  Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
316  isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
317  isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
318  isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
319  ),
320  inputTensorName = cms.string("ffwd_inp:0"),
321  outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
322  outputNames = cms.vstring(["corr","res"]),
323  outputFormulas = cms.vstring(["at(0)*0.24325256049633026+0.993854820728302","0.5*(at(2)-at(1))*0.24325256049633026"]),
324 )
325 
326 
327 run2_jme_2016.toModify(
328  bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2016.onnx")
329 ).toModify(
330  bjetNN,outputFormulas = cms.vstring(["at(0)*0.31976690888404846+1.047176718711853","0.5*(at(2)-at(1))*0.31976690888404846"])
331 ).toModify(
332  cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2016.onnx")
333 ).toModify(
334  cjetNN, outputFormulas = cms.vstring(["at(0)*0.28862622380256653+0.9908722639083862","0.5*(at(2)-at(1))*0.28862622380256653"])
335 )
336 
337 run2_jme_2017.toModify(
338  bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2017.onnx")
339 ).toModify(
340  bjetNN,outputFormulas = cms.vstring(["at(0)*0.28225210309028625+1.055067777633667","0.5*(at(2)-at(1))*0.28225210309028625"])
341 ).toModify(
342  cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2017.onnx")
343 ).toModify(
344  cjetNN, outputFormulas = cms.vstring(["at(0)*0.24718524515628815+0.9927206635475159","0.5*(at(2)-at(1))*0.24718524515628815"])
345 )
346 
347 
348 #
349 # Quark-Gluon Likelihood (QGL)
350 #
351 from RecoJets.JetProducers.QGTagger_cfi import QGTagger
352 qgtagger=QGTagger.clone(srcJets="updatedJets",srcVertexCollection="offlineSlimmedPrimaryVertices")
353 
354 #
355 # PileUp ID
356 #
357 from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId, _chsalgos_94x, _chsalgos_102x, _chsalgos_106X_UL16, _chsalgos_106X_UL16APV, _chsalgos_106X_UL17, _chsalgos_106X_UL18
358 pileupJetIdNano=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL18),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
359 run2_jme_2017.toModify(
360  pileupJetIdNano, algos = _chsalgos_106X_UL17
361 )
362 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify(
363  pileupJetIdNano, algos = _chsalgos_106X_UL16
364 )
365 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify(
366  pileupJetIdNano, algos = _chsalgos_106X_UL16APV
367 )
368 
369 
373 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
374 def nanoAOD_addDeepInfoAK4CHS(process,addDeepBTag,addDeepFlavour,addParticleNet,addRobustParTAK4=False):
375  _btagDiscriminators=[]
376  if addDeepBTag:
377  print("Updating process to run DeepCSV btag")
378  _btagDiscriminators += ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc']
379  if addDeepFlavour:
380  print("Updating process to run DeepFlavour btag")
381  _btagDiscriminators += ['pfDeepFlavourJetTags:probb','pfDeepFlavourJetTags:probbb','pfDeepFlavourJetTags:problepb','pfDeepFlavourJetTags:probc']
382  if addParticleNet:
383  print("Updating process to run ParticleNetAK4")
384  from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK4_cff import _pfParticleNetFromMiniAODAK4CHSCentralJetTagsAll as pfParticleNetFromMiniAODAK4CHSCentralJetTagsAll
385  from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK4_cff import _pfParticleNetFromMiniAODAK4CHSForwardJetTagsAll as pfParticleNetFromMiniAODAK4CHSForwardJetTagsAll
386  _btagDiscriminators += pfParticleNetFromMiniAODAK4CHSCentralJetTagsAll
387  _btagDiscriminators += pfParticleNetFromMiniAODAK4CHSForwardJetTagsAll
388  if addRobustParTAK4:
389  print("Updating process to run RobustParTAK4")
390  from RecoBTag.ONNXRuntime.pfParticleTransformerAK4_cff import _pfParticleTransformerAK4JetTagsAll as pfParticleTransformerAK4JetTagsAll
391  _btagDiscriminators += pfParticleTransformerAK4JetTagsAll
392 
393  if len(_btagDiscriminators)==0: return process
394  print("Will recalculate the following discriminators: "+", ".join(_btagDiscriminators))
395  updateJetCollection(
396  process,
397  jetSource = cms.InputTag('slimmedJets'),
398  jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute','L2L3Residual']), 'None'),
399  btagDiscriminators = _btagDiscriminators,
400  postfix = 'WithDeepInfo',
401  )
402  process.load("Configuration.StandardSequences.MagneticField_cff")
403  process.jetCorrFactorsNano.src="selectedUpdatedPatJetsWithDeepInfo"
404  process.updatedJets.jetSource="selectedUpdatedPatJetsWithDeepInfo"
405  return process
406 
407 nanoAOD_addDeepInfoAK4CHS_switch = cms.PSet(
408  nanoAOD_addDeepBTag_switch = cms.untracked.bool(False),
409  nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(False),
410  nanoAOD_addParticleNet_switch = cms.untracked.bool(False),
411  nanoAOD_addRobustParTAK4Tag_switch = cms.untracked.bool(False)
412 )
413 
414 
417 
418 #
419 # ML-based FastSim refinement
420 #
421 from Configuration.Eras.Modifier_fastSim_cff import fastSim
423 
424  fastSim.toModify( process.jetTable.variables,
425  btagDeepFlavBunrefined = process.jetTable.variables.btagDeepFlavB.clone(),
426  btagDeepFlavCvBunrefined = process.jetTable.variables.btagDeepFlavCvB.clone(),
427  btagDeepFlavCvLunrefined = process.jetTable.variables.btagDeepFlavCvL.clone(),
428  btagDeepFlavQGunrefined = process.jetTable.variables.btagDeepFlavQG.clone(),
429  )
430 
431  fastSim.toModify( process.jetTable.variables,
432  btagDeepFlavB = None,
433  btagDeepFlavCvB = None,
434  btagDeepFlavCvL = None,
435  btagDeepFlavQG = None,
436  )
437 
438  fastSim.toModify( process.jetTable.externalVariables,
439  btagDeepFlavB = ExtVar(cms.InputTag("btagDeepFlavRefineNN:btagDeepFlavBrefined"), float, doc="DeepJet b+bb+lepb tag discriminator", precision=10),
440  btagDeepFlavCvB = ExtVar(cms.InputTag("btagDeepFlavRefineNN:btagDeepFlavCvBrefined"), float, doc="DeepJet c vs b+bb+lepb discriminator", precision=10),
441  btagDeepFlavCvL = ExtVar(cms.InputTag("btagDeepFlavRefineNN:btagDeepFlavCvLrefined"), float, doc="DeepJet c vs uds+g discriminator", precision=10),
442  btagDeepFlavQG = ExtVar(cms.InputTag("btagDeepFlavRefineNN:btagDeepFlavQGrefined"), float, doc="DeepJet g vs uds discriminator", precision=10),
443  )
444 
445  process.btagDeepFlavRefineNN= cms.EDProducer("JetBaseMVAValueMapProducer",
446  backend = cms.string("ONNX"),
447  batch_eval = cms.bool(True),
448  disableONNXGraphOpt = cms.bool(True),
449 
450  src = cms.InputTag("linkedObjects","jets"),
451 
452  weightFile=cms.FileInPath("PhysicsTools/NanoAOD/data/btagDeepFlavRefineNN_CHS.onnx"),
453  name = cms.string("btagDeepFlavRefineNN"),
454 
455  isClassifier = cms.bool(False),
456  variablesOrder = cms.vstring(["GenJet_pt","GenJet_eta","Jet_hadronFlavour",
457  "Jet_btagDeepFlavB","Jet_btagDeepFlavCvB","Jet_btagDeepFlavCvL","Jet_btagDeepFlavQG"]),
458  variables = cms.PSet(
459  GenJet_pt = cms.string("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().pt():pt"),
460  GenJet_eta = cms.string("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().eta():eta"),
461  Jet_hadronFlavour = cms.string("hadronFlavour()"),
462  Jet_btagDeepFlavB = cms.string("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')"),
463  Jet_btagDeepFlavCvB = cms.string("?(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"),
464  Jet_btagDeepFlavCvL = cms.string("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg')):-1"),
465  Jet_btagDeepFlavQG = cms.string("?(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds'))>0?bDiscriminator('pfDeepFlavourJetTags:probg')/(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds')):-1"),
466  ),
467  inputTensorName = cms.string("input"),
468  outputTensorName = cms.string("output"),
469  outputNames = cms.vstring(["btagDeepFlavBrefined","btagDeepFlavCvBrefined","btagDeepFlavCvLrefined","btagDeepFlavQGrefined"]),
470  outputFormulas = cms.vstring(["at(0)","at(1)","at(2)","at(3)"]),
471  )
472 
473  fastSim.toModify(process.jetTablesTask, process.jetTablesTask.add(process.btagDeepFlavRefineNN))
474 
475  return process
476 
477 
478 
481 basicJetsForMetForT1METNano = cms.EDProducer("PATJetCleanerForType1MET",
482  src = updatedJetsWithUserData.src,
483  jetCorrEtaMax = cms.double(9.9),
484  jetCorrLabel = cms.InputTag("L3Absolute"),
485  jetCorrLabelRes = cms.InputTag("L2L3Residual"),
486  offsetCorrLabel = cms.InputTag("L1FastJet"),
487  skipEM = cms.bool(False),
488  skipEMfractionThreshold = cms.double(0.9),
489  skipMuonSelection = cms.string('isGlobalMuon | isStandAloneMuon'),
490  skipMuons = cms.bool(True),
491  type1JetPtThreshold = cms.double(0.0),
492  calcMuonSubtrRawPtAsValueMap = cms.bool(True)
493 )
494 
495 updatedJetsWithUserData.userFloats.muonSubtrRawPt = cms.InputTag("basicJetsForMetForT1METNano:MuonSubtrRawPt")
496 
497 corrT1METJetTable = simpleCandidateFlatTableProducer.clone(
498  src = finalJets.src,
499  cut = cms.string("pt<15 && abs(eta)<9.9"),
500  name = cms.string("CorrT1METJet"),
501  doc = cms.string("Additional low-pt ak4 CHS jets for Type-1 MET re-correction"),
502  variables = cms.PSet(
503  rawPt = Var("pt()*jecFactor('Uncorrected')",float,precision=10),
504  eta = Var("eta", float,precision=12),
505  phi = Var("phi", float, precision=12),
506  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
507  )
508 )
509 
510 corrT1METJetTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
511 jetTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
512 
513 jetForMETTask = cms.Task(basicJetsForMetForT1METNano,corrT1METJetTable)
514 
515 #before cross linking
516 jetUserDataTask = cms.Task(bJetVars,qgtagger,jercVars,tightJetId,tightJetIdLepVeto,pileupJetIdNano)
517 
518 #before cross linking
519 jetTask = cms.Task(jetCorrFactorsNano,updatedJets,jetUserDataTask,updatedJetsWithUserData,finalJets)
520 
521 #after cross linkining
522 jetTablesTask = cms.Task(bjetNN,cjetNN,jetTable)
def ExtVar(tag, valtype, doc=None, precision=-1)
Definition: common_cff.py:27
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
def nanoAOD_refineFastSim_bTagDeepFlav(process)
User floats producers, selectors ##########################.
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def nanoAOD_addDeepInfoAK4CHS(process, addDeepBTag, addDeepFlavour, addParticleNet, addRobustParTAK4=False)
static std::string join(char **cmd)
Definition: RemoteFile.cc:19