CMS 3D CMS Logo

custom_jme_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
4 
5 from CommonTools.PileupAlgos.Puppi_cff import puppi
6 
7 from RecoJets.JetProducers.PileupJetID_cfi import pileupJetIdCalculator, pileupJetId
8 from RecoJets.JetProducers.PileupJetID_cfi import _chsalgos_81x, _chsalgos_94x, _chsalgos_102x
9 
10 from PhysicsTools.NanoAOD.common_cff import Var, P4Vars
11 from PhysicsTools.NanoAOD.jetsAK4_CHS_cff import jetTable, jetCorrFactorsNano, updatedJets, finalJets, qgtagger, hfJetShowerShapeforNanoAOD
12 from PhysicsTools.NanoAOD.jetsAK4_Puppi_cff import jetPuppiTable, jetPuppiCorrFactorsNano, updatedJetsPuppi, updatedJetsPuppiWithUserData
13 from PhysicsTools.NanoAOD.jetMC_cff import genJetTable, genJetFlavourAssociation, genJetFlavourTable
14 
15 from PhysicsTools.PatAlgos.tools.jetCollectionTools import GenJetAdder, RecoJetAdder
16 from PhysicsTools.PatAlgos.tools.jetTools import supportedJetAlgos
17 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
18 
19 import copy
20 
21 bTagCSVV2 = ['pfCombinedInclusiveSecondaryVertexV2BJetTags']
22 bTagDeepCSV = ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc']
23 bTagDeepJet = [
24  'pfDeepFlavourJetTags:probb','pfDeepFlavourJetTags:probbb','pfDeepFlavourJetTags:problepb',
25  'pfDeepFlavourJetTags:probc','pfDeepFlavourJetTags:probuds','pfDeepFlavourJetTags:probg'
26 ]
27 from RecoBTag.ONNXRuntime.pfParticleNetAK4_cff import _pfParticleNetAK4JetTagsAll
28 bTagDiscriminatorsForAK4 = bTagCSVV2+bTagDeepCSV+bTagDeepJet+_pfParticleNetAK4JetTagsAll
29 
30 from RecoBTag.ONNXRuntime.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsAll
31 from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetJetTagsAll
32 
33 btagHbb = ['pfBoostedDoubleSecondaryVertexAK8BJetTags']
34 btagDDX = [
35  'pfDeepDoubleBvLJetTags:probHbb',
36  'pfDeepDoubleCvLJetTags:probHcc',
37  'pfDeepDoubleCvBJetTags:probHcc',
38  'pfMassIndependentDeepDoubleBvLJetTags:probHbb',
39  'pfMassIndependentDeepDoubleCvLJetTags:probHcc',
40  'pfMassIndependentDeepDoubleCvBJetTags:probHcc'
41 ]
42 btagDDXV2 = [
43  'pfMassIndependentDeepDoubleBvLV2JetTags:probHbb',
44  'pfMassIndependentDeepDoubleCvLV2JetTags:probHcc',
45  'pfMassIndependentDeepDoubleCvBV2JetTags:probHcc'
46 ]
47 
48 #
49 # By default, these collections are saved in NanoAODs:
50 # - ak4gen (GenJet in NanoAOD), slimmedGenJets in MiniAOD
51 # - ak8gen (GenJetAK8 in NanoAOD), slimmedGenJetsAK8 in MiniAOD
52 # Below is a list of genjets that we can save in NanoAOD. Set
53 # "enabled" to true if you want to store the jet collection
54 config_genjets = [
55  {
56  "jet" : "ak6gen",
57  "enabled" : False,
58  },
59 ]
60 config_genjets = list(filter(lambda k: k['enabled'], config_genjets))
61 #
62 # GenJets info in NanoAOD
63 #
64 nanoInfo_genjets = {
65  "ak6gen" : {
66  "name" : "GenJetAK6",
67  "doc" : "AK6 Gen jets (made with visible genparticles) with pt > 3 GeV", # default genjets pt cut after clustering is 3 GeV
68  },
69 }
70 #
71 # By default, these collections are saved in the main NanoAODs:
72 # - ak4pfpuppi (Jet in NanoAOD), slimmedJetsPuppi in MiniAOD
73 # - ak8pfpuppi (FatJet in NanoAOD), slimmedJetsAK8 in MiniAOD
74 # Below is a list of recojets that we can save in NanoAOD. Set
75 # "enabled" to true if you want to store the recojet collection.
76 #
77 config_recojets = [
78  {
79  "jet" : "ak4calo",
80  "enabled" : True,
81  "inputCollection" : "slimmedCaloJets", #Exist in MiniAOD
82  "genJetsCollection": "AK4GenJetsNoNu",
83  },
84  {
85  "jet" : "ak4pf",
86  "enabled" : False,
87  "inputCollection" : "",
88  "genJetsCollection": "AK4GenJetsNoNu",
89  "minPtFastjet" : 0.,
90  },
91  {
92  "jet" : "ak8pf",
93  "enabled" : False,
94  "inputCollection" : "",
95  "genJetsCollection": "AK8GenJetsNoNu",
96  "minPtFastjet" : 0.,
97  },
98 ]
99 config_recojets = list(filter(lambda k: k['enabled'], config_recojets))
100 #
101 # RecoJets info in NanoAOD
102 #
103 nanoInfo_recojets = {
104  "ak4calo" : {
105  "name": "JetCalo",
106  "doc" : "AK4 Calo jets with JECs applied",
107  },
108  "ak4pf" : {
109  "name" : "JetPF",
110  "doc" : "AK4 PF jets",
111  "ptcut" : "",
112  },
113  "ak8pf" : {
114  "name" : "FatJetPF",
115  "doc" : "AK8 PF jets",
116  "ptcut" : "",
117  },
118 }
119 
120 GENJETVARS = cms.PSet(P4Vars,
121  nConstituents = jetTable.variables.nConstituents,
122 )
123 PFJETVARS = cms.PSet(P4Vars,
124  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
125  area = jetTable.variables.area,
126  chHEF = jetTable.variables.chHEF,
127  neHEF = jetTable.variables.neHEF,
128  chEmEF = jetTable.variables.chEmEF,
129  neEmEF = jetTable.variables.neEmEF,
130  muEF = jetTable.variables.muEF,
131  hfHEF = Var("HFHadronEnergyFraction()",float,doc = "hadronic energy fraction in HF",precision = 6),
132  hfEmEF = Var("HFEMEnergyFraction()",float,doc = "electromagnetic energy fraction in HF",precision = 6),
133  nMuons = jetTable.variables.nMuons,
134  nElectrons = jetTable.variables.nElectrons,
135  nConstituents = jetTable.variables.nConstituents,
136  nConstChHads = Var("chargedHadronMultiplicity()",int,doc="number of charged hadrons in the jet"),
137  nConstNeuHads = Var("neutralHadronMultiplicity()",int,doc="number of neutral hadrons in the jet"),
138  nConstHFHads = Var("HFHadronMultiplicity()", int,doc="number of HF hadrons in the jet"),
139  nConstHFEMs = Var("HFEMMultiplicity()",int,doc="number of HF EMs in the jet"),
140  nConstMuons = Var("muonMultiplicity()",int,doc="number of muons in the jet"),
141  nConstElecs = Var("electronMultiplicity()",int,doc="number of electrons in the jet"),
142  nConstPhotons = Var("photonMultiplicity()",int,doc="number of photons in the jet"),
143 )
144 PUIDVARS = cms.PSet(
145  puId_dR2Mean = Var("?(pt>=10)?userFloat('puId_dR2Mean'):-1",float,doc="pT^2-weighted average square distance of jet constituents from the jet axis (PileUp ID BDT input variable)", precision=6),
146  puId_majW = Var("?(pt>=10)?userFloat('puId_majW'):-1",float,doc="major axis of jet ellipsoid in eta-phi plane (PileUp ID BDT input variable)", precision=6),
147  puId_minW = Var("?(pt>=10)?userFloat('puId_minW'):-1",float,doc="minor axis of jet ellipsoid in eta-phi plane (PileUp ID BDT input variable)", precision=6),
148  puId_frac01 = Var("?(pt>=10)?userFloat('puId_frac01'):-1",float,doc="fraction of constituents' pT contained within dR <0.1 (PileUp ID BDT input variable)", precision=6),
149  puId_frac02 = Var("?(pt>=10)?userFloat('puId_frac02'):-1",float,doc="fraction of constituents' pT contained within 0.1< dR <0.2 (PileUp ID BDT input variable)", precision=6),
150  puId_frac03 = Var("?(pt>=10)?userFloat('puId_frac03'):-1",float,doc="fraction of constituents' pT contained within 0.2< dR <0.3 (PileUp ID BDT input variable)", precision=6),
151  puId_frac04 = Var("?(pt>=10)?userFloat('puId_frac04'):-1",float,doc="fraction of constituents' pT contained within 0.3< dR <0.4 (PileUp ID BDT input variable)", precision=6),
152  puId_ptD = Var("?(pt>=10)?userFloat('puId_ptD'):-1",float,doc="pT-weighted average pT of constituents (PileUp ID BDT input variable)", precision=6),
153  puId_beta = Var("?(pt>=10)?userFloat('puId_beta'):-1",float,doc="fraction of pT of charged constituents associated to PV (PileUp ID BDT input variable)", precision=6),
154  puId_pull = Var("?(pt>=10)?userFloat('puId_pull'):-1",float,doc="magnitude of pull vector (PileUp ID BDT input variable)", precision=6),
155  puId_jetR = Var("?(pt>=10)?userFloat('puId_jetR'):-1",float,doc="fraction of jet pT carried by the leading constituent (PileUp ID BDT input variable)", precision=6),
156  puId_jetRchg = Var("?(pt>=10)?userFloat('puId_jetRchg'):-1",float,doc="fraction of jet pT carried by the leading charged constituent (PileUp ID BDT input variable)", precision=6),
157  puId_nCharged = Var("?(pt>=10)?userInt('puId_nCharged'):-1",int,doc="number of charged constituents (PileUp ID BDT input variable)"),
158 )
159 QGLVARS = cms.PSet(
160  qgl_axis2 = Var("?(pt>=10)?userFloat('qgl_axis2'):-1",float,doc="ellipse minor jet axis (Quark vs Gluon likelihood input variable)", precision=10),
161  qgl_ptD = Var("?(pt>=10)?userFloat('qgl_ptD'):-1",float,doc="pT-weighted average pT of constituents (Quark vs Gluon likelihood input variable)", precision=10),
162  qgl_mult = Var("?(pt>=10)?userInt('qgl_mult'):-1", int,doc="PF candidates multiplicity (Quark vs Gluon likelihood input variable)"),
163 )
164 BTAGVARS = cms.PSet(
165  btagDeepB = Var("?(pt>=15)&&((bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'))>=0)?bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'):-1",float,doc="DeepCSV b+bb tag discriminator",precision=10),
166  btagCSVV2 = Var("?(pt>=15)?bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags'):-1",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
167  btagDeepCvL = Var("?(pt>=15)&&(bDiscriminator('pfDeepCSVJetTags:probc')>=0)?bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')):-1", float,doc="DeepCSV c vs udsg discriminator",precision=10),
168  btagDeepCvB = Var("?(pt>=15)&&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),
169 )
170 DEEPJETVARS = cms.PSet(
171  btagDeepFlavB = Var("?(pt>=15)?bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb'):-1",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10),
172  btagDeepFlavC = Var("?(pt>=15)?bDiscriminator('pfDeepFlavourJetTags:probc'):-1",float,doc="DeepFlavour charm tag raw score",precision=10),
173  btagDeepFlavG = Var("?(pt>=15)?bDiscriminator('pfDeepFlavourJetTags:probg'):-1",float,doc="DeepFlavour gluon tag raw score",precision=10),
174  btagDeepFlavUDS = Var("?(pt>=15)?bDiscriminator('pfDeepFlavourJetTags:probuds'):-1",float,doc="DeepFlavour uds tag raw score",precision=10),
175  btagDeepFlavCvL = Var("?(pt>=15)&&(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),
176  btagDeepFlavCvB = Var("?(pt>=15)&&(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),
177  btagDeepFlavQG = Var("?(pt>=15)&&(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),
178 )
179 PARTICLENETAK4VARS = cms.PSet(
180  particleNetAK4_B = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:BvsAll'):-1",float,doc="ParticleNetAK4 tagger b vs all (udsg, c) discriminator",precision=10),
181  particleNetAK4_CvsL = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:CvsL'):-1",float,doc="ParticleNetAK4 tagger c vs udsg discriminator",precision=10),
182  particleNetAK4_CvsB = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:CvsB'):-1",float,doc="ParticleNetAK4 tagger c vs b discriminator",precision=10),
183  particleNetAK4_QvsG = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:QvsG'):-1",float,doc="ParticleNetAK4 tagger uds vs g discriminator",precision=10),
184  particleNetAK4_puIdDisc = Var("?(pt>=15)?1-bDiscriminator('pfParticleNetAK4JetTags:probpu'):-1",float,doc="ParticleNetAK4 tagger pileup jet discriminator",precision=10),
185 )
186 
187 CALOJETVARS = cms.PSet(P4Vars,
188  area = jetTable.variables.area,
189  rawFactor = jetTable.variables.rawFactor,
190  emf = Var("emEnergyFraction()", float, doc = "electromagnetic energy fraction", precision = 10),
191 )
192 
193 
194 #******************************************
195 #
196 #
197 # Reco Jets related functions
198 #
199 #
200 #******************************************
201 def AddJetID(proc, jetName="", jetSrc="", jetTableName="", jetTaskName=""):
202  """
203  Setup modules to calculate PF jet ID
204  """
205 
206  isPUPPIJet = True if "Puppi" in jetName else False
207 
208  looseJetId = "looseJetId{}".format(jetName)
209  setattr(proc, looseJetId, proc.looseJetId.clone(
210  src = jetSrc,
211  filterParams = proc.looseJetId.filterParams.clone(
212  version = "WINTER16"
213  ),
214  )
215  )
216 
217  tightJetId = "tightJetId{}".format(jetName)
218  setattr(proc, tightJetId, proc.tightJetId.clone(
219  src = jetSrc,
220  filterParams = proc.tightJetId.filterParams.clone(
221  version = "RUN2UL{}".format("PUPPI" if isPUPPIJet else "CHS")
222  ),
223  )
224  )
225 
226  tightJetIdLepVeto = "tightJetIdLepVeto{}".format(jetName)
227  setattr(proc, tightJetIdLepVeto, proc.tightJetIdLepVeto.clone(
228  src = jetSrc,
229  filterParams = proc.tightJetIdLepVeto.filterParams.clone(
230  version = "RUN2UL{}".format("PUPPI" if isPUPPIJet else "CHS")
231  ),
232  )
233  )
234 
235  for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
236  modifier.toModify(getattr(proc, tightJetId).filterParams, version = "WINTER16" )
237  modifier.toModify(getattr(proc, tightJetIdLepVeto).filterParams, version = "WINTER16" )
238  for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
239  modifier.toModify(getattr(proc, tightJetId).filterParams, version = "WINTER17{}".format("PUPPI" if isPUPPIJet else ""))
240  modifier.toModify(getattr(proc, tightJetIdLepVeto).filterParams, version = "WINTER17{}".format("PUPPI" if isPUPPIJet else ""))
241  run2_nanoAOD_102Xv1.toModify(getattr(proc, tightJetId).filterParams, version = "SUMMER18{}".format("PUPPI" if isPUPPIJet else "") )
242  run2_nanoAOD_102Xv1.toModify(getattr(proc, tightJetIdLepVeto).filterParams, version = "SUMMER18{}".format("PUPPI" if isPUPPIJet else "") )
243 
244  #
245  # Save variables as userInts in each jet
246  #
247  patJetWithUserData = "{}WithUserData".format(jetSrc)
248  getattr(proc, patJetWithUserData).userInts.tightId = cms.InputTag(tightJetId)
249  getattr(proc, patJetWithUserData).userInts.tightIdLepVeto = cms.InputTag(tightJetIdLepVeto)
250  for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
251  modifier.toModify(getattr(proc, patJetWithUserData).userInts, looseId = cms.InputTag(looseJetId))
252 
253  #
254  # Specfiy variables in the jetTable to save in NanoAOD
255  #
256  getattr(proc, jetTableName).variables.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")
257  for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
258  modifier.toModify(getattr(proc, jetTableName).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"))
259 
260 
261  getattr(proc,jetTaskName).add(getattr(proc, tightJetId))
262  getattr(proc,jetTaskName).add(getattr(proc, tightJetIdLepVeto))
263 
264  setattr(proc,"_"+jetTaskName+"_2016", getattr(proc,jetTaskName).copy())
265  getattr(proc,"_"+jetTaskName+"_2016").add(getattr(proc, looseJetId))
266  for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
267  modifier.toReplaceWith(getattr(proc,jetTaskName), getattr(proc, "_"+jetTaskName+"_2016"))
268 
269  return proc
270 
271 def AddPileUpJetIDVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName=""):
272  """
273  Setup modules to calculate pileup jet ID input variables for PF jet
274  """
275 
276  #
277  # Calculate pileup jet ID variables
278  #
279  puJetIdVarsCalculator = "puJetIdCalculator{}".format(jetName)
280  setattr(proc, puJetIdVarsCalculator, pileupJetIdCalculator.clone(
281  jets = jetSrc,
282  vertexes = "offlineSlimmedPrimaryVertices",
283  inputIsCorrected = True,
284  applyJec = False,
285  usePuppi = True if "Puppi" in jetName else False
286  )
287  )
288  getattr(proc,jetTaskName).add(getattr(proc, puJetIdVarsCalculator))
289 
290  #
291  # Get the variables
292  #
293  puJetIDVar = "puJetIDVar{}".format(jetName)
294  setattr(proc, puJetIDVar, cms.EDProducer("PileupJetIDVarProducer",
295  srcJet = cms.InputTag(jetSrc),
296  srcPileupJetId = cms.InputTag(puJetIdVarsCalculator)
297  )
298  )
299  getattr(proc,jetTaskName).add(getattr(proc, puJetIDVar))
300 
301  #
302  # Save variables as userFloats and userInts for each jet
303  #
304  patJetWithUserData = "{}WithUserData".format(jetSrc)
305  getattr(proc,patJetWithUserData).userFloats.puId_dR2Mean = cms.InputTag("{}:dR2Mean".format(puJetIDVar))
306  getattr(proc,patJetWithUserData).userFloats.puId_majW = cms.InputTag("{}:majW".format(puJetIDVar))
307  getattr(proc,patJetWithUserData).userFloats.puId_minW = cms.InputTag("{}:minW".format(puJetIDVar))
308  getattr(proc,patJetWithUserData).userFloats.puId_frac01 = cms.InputTag("{}:frac01".format(puJetIDVar))
309  getattr(proc,patJetWithUserData).userFloats.puId_frac02 = cms.InputTag("{}:frac02".format(puJetIDVar))
310  getattr(proc,patJetWithUserData).userFloats.puId_frac03 = cms.InputTag("{}:frac03".format(puJetIDVar))
311  getattr(proc,patJetWithUserData).userFloats.puId_frac04 = cms.InputTag("{}:frac04".format(puJetIDVar))
312  getattr(proc,patJetWithUserData).userFloats.puId_ptD = cms.InputTag("{}:ptD".format(puJetIDVar))
313  getattr(proc,patJetWithUserData).userFloats.puId_beta = cms.InputTag("{}:beta".format(puJetIDVar))
314  getattr(proc,patJetWithUserData).userFloats.puId_pull = cms.InputTag("{}:pull".format(puJetIDVar))
315  getattr(proc,patJetWithUserData).userFloats.puId_jetR = cms.InputTag("{}:jetR".format(puJetIDVar))
316  getattr(proc,patJetWithUserData).userFloats.puId_jetRchg = cms.InputTag("{}:jetRchg".format(puJetIDVar))
317  getattr(proc,patJetWithUserData).userInts.puId_nCharged = cms.InputTag("{}:nCharged".format(puJetIDVar))
318 
319  #
320  # Specfiy variables in the jet table to save in NanoAOD
321  #
322  getattr(proc,jetTableName).variables.puId_dR2Mean = PUIDVARS.puId_dR2Mean
323  getattr(proc,jetTableName).variables.puId_majW = PUIDVARS.puId_majW
324  getattr(proc,jetTableName).variables.puId_minW = PUIDVARS.puId_minW
325  getattr(proc,jetTableName).variables.puId_frac01 = PUIDVARS.puId_frac01
326  getattr(proc,jetTableName).variables.puId_frac02 = PUIDVARS.puId_frac02
327  getattr(proc,jetTableName).variables.puId_frac03 = PUIDVARS.puId_frac03
328  getattr(proc,jetTableName).variables.puId_frac04 = PUIDVARS.puId_frac04
329  getattr(proc,jetTableName).variables.puId_ptD = PUIDVARS.puId_ptD
330  getattr(proc,jetTableName).variables.puId_beta = PUIDVARS.puId_beta
331  getattr(proc,jetTableName).variables.puId_pull = PUIDVARS.puId_pull
332  getattr(proc,jetTableName).variables.puId_jetR = PUIDVARS.puId_jetR
333  getattr(proc,jetTableName).variables.puId_jetRchg = PUIDVARS.puId_jetRchg
334  getattr(proc,jetTableName).variables.puId_nCharged = PUIDVARS.puId_nCharged
335 
336  return proc
337 
338 def AddQGLTaggerVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName="", calculateQGLVars=False):
339  """
340  Schedule the QGTagger module to calculate input variables to the QG likelihood
341  """
342 
343  QGLTagger="qgtagger{}".format(jetName)
344  patJetWithUserData="{}WithUserData".format(jetSrc)
345 
346  if calculateQGLVars:
347  setattr(proc, QGLTagger, qgtagger.clone(
348  srcJets = jetSrc
349  )
350  )
351 
352  #
353  # Save variables as userFloats and userInts for each jet
354  #
355  getattr(proc,patJetWithUserData).userFloats.qgl_axis2 = cms.InputTag(QGLTagger+":axis2")
356  getattr(proc,patJetWithUserData).userFloats.qgl_ptD = cms.InputTag(QGLTagger+":ptD")
357  getattr(proc,patJetWithUserData).userInts.qgl_mult = cms.InputTag(QGLTagger+":mult")
358 
359  #
360  # Specfiy variables in the jet table to save in NanoAOD
361  #
362  getattr(proc,jetTableName).variables.qgl_axis2 = QGLVARS.qgl_axis2
363  getattr(proc,jetTableName).variables.qgl_ptD = QGLVARS.qgl_ptD
364  getattr(proc,jetTableName).variables.qgl_mult = QGLVARS.qgl_mult
365 
366  if calculateQGLVars:
367  getattr(proc,jetTaskName).add(getattr(proc, QGLTagger))
368 
369  return proc
370 
371 def AddBTaggingScores(proc, jetTableName=""):
372  """
373  Store b-tagging scores from various algortihm
374  """
375 
376  getattr(proc, jetTableName).variables.btagDeepB = BTAGVARS.btagDeepB
377  getattr(proc, jetTableName).variables.btagCSVV2 = BTAGVARS.btagCSVV2
378  getattr(proc, jetTableName).variables.btagDeepCvL = BTAGVARS.btagDeepCvL
379  getattr(proc, jetTableName).variables.btagDeepCvB = BTAGVARS.btagDeepCvB
380  getattr(proc, jetTableName).variables.btagDeepFlavB = DEEPJETVARS.btagDeepFlavB
381  getattr(proc, jetTableName).variables.btagDeepFlavCvL = DEEPJETVARS.btagDeepFlavCvL
382  getattr(proc, jetTableName).variables.btagDeepFlavCvB = DEEPJETVARS.btagDeepFlavCvB
383 
384  return proc
385 
386 def AddDeepJetGluonLQuarkScores(proc, jetTableName=""):
387  """
388  Store DeepJet raw score in jetTable for gluon and light quark
389  """
390 
391  getattr(proc, jetTableName).variables.btagDeepFlavG = DEEPJETVARS.btagDeepFlavG
392  getattr(proc, jetTableName).variables.btagDeepFlavUDS = DEEPJETVARS.btagDeepFlavUDS
393  getattr(proc, jetTableName).variables.btagDeepFlavQG = DEEPJETVARS.btagDeepFlavQG
394 
395  return proc
396 
397 def AddParticleNetAK4Scores(proc, jetTableName=""):
398  """
399  Store ParticleNetAK4 scores in jetTable
400  """
401 
402  getattr(proc, jetTableName).variables.particleNetAK4_B = PARTICLENETAK4VARS.particleNetAK4_B
403  getattr(proc, jetTableName).variables.particleNetAK4_CvsL = PARTICLENETAK4VARS.particleNetAK4_CvsL
404  getattr(proc, jetTableName).variables.particleNetAK4_CvsB = PARTICLENETAK4VARS.particleNetAK4_CvsB
405  getattr(proc, jetTableName).variables.particleNetAK4_QvsG = PARTICLENETAK4VARS.particleNetAK4_QvsG
406  getattr(proc, jetTableName).variables.particleNetAK4_puIdDisc = PARTICLENETAK4VARS.particleNetAK4_puIdDisc
407 
408  return proc
409 
410 def AddNewPatJets(proc, recoJetInfo, runOnMC):
411  """
412  Add patJet into custom nanoAOD
413  """
414 
415  jetName = recoJetInfo.jetUpper
416  payload = recoJetInfo.jetCorrPayload
417  doPF = recoJetInfo.doPF
418  doCalo = recoJetInfo.doCalo
419  patJetFinalColl = recoJetInfo.patJetFinalCollection
420 
421  nanoInfoForJet = nanoInfo_recojets[recoJetInfo.jet]
422  jetTablePrefix = nanoInfoForJet["name"]
423  jetTableDoc = nanoInfoForJet["doc"]
424  ptcut = nanoInfoForJet["ptcut"] if "ptcut" in nanoInfoForJet else 8
425  doPUIDVar = nanoInfoForJet["doPUIDVar"] if "doPUIDVar" in nanoInfoForJet else False
426  doQGL = nanoInfoForJet["doQGL"] if "doQGL" in nanoInfoForJet else False
427  doBTag = nanoInfoForJet["doBTag"] if "doBTag" in nanoInfoForJet else False
428 
429  SavePatJets(proc,
430  jetName, payload, patJetFinalColl, jetTablePrefix, jetTableDoc, doPF, doCalo,
431  ptcut=ptcut, doPUIDVar=doPUIDVar, doQGL=doQGL, doBTag=doBTag, runOnMC=runOnMC
432  )
433 
434  return proc
435 
436 def SavePatJets(proc, jetName, payload, patJetFinalColl, jetTablePrefix, jetTableDoc,
437  doPF, doCalo, ptcut, doPUIDVar=False, doQGL=False, doBTag=False, runOnMC=False):
438  """
439  Schedule modules for a given patJet collection and save its variables into custom NanoAOD
440  """
441 
442  #
443  # Setup jet correction factors
444  #
445  jetCorrFactors = "jetCorrFactorsNano{}".format(jetName)
446  setattr(proc, jetCorrFactors, jetCorrFactorsNano.clone(
447  src = patJetFinalColl,
448  payload = payload,
449  )
450  )
451 
452  #
453  # Update jets
454  #
455  srcJets = "updatedJets{}".format(jetName)
456  setattr(proc, srcJets, updatedJets.clone(
457  jetSource = patJetFinalColl,
458  jetCorrFactorsSource = [jetCorrFactors],
459  )
460  )
461 
462  #
463  # Setup UserDataEmbedder
464  #
465  srcJetsWithUserData = "updatedJets{}WithUserData".format(jetName)
466  setattr(proc, srcJetsWithUserData, cms.EDProducer("PATJetUserDataEmbedder",
467  src = cms.InputTag(srcJets),
468  userFloats = cms.PSet(),
469  userInts = cms.PSet(),
470  )
471  )
472 
473  #
474  # Filter jets with pt cut
475  #
476  finalJetsCut = "(pt >= {ptcut:.0f})".format(ptcut=ptcut)
477  if runOnMC:
478  finalJetsCut = "(pt >= {ptcut:.0f}) || ((pt < {ptcut:.0f}) && (genJetFwdRef().backRef().isNonnull()))".format(ptcut=ptcut)
479 
480  finalJetsForTable = "finalJets{}".format(jetName)
481  setattr(proc, finalJetsForTable, finalJets.clone(
482  src = srcJetsWithUserData,
483  cut = finalJetsCut
484  )
485  )
486 
487  #
488  # Save jets in table
489  #
490  tableContent = PFJETVARS
491  if doCalo:
492  tableContent = CALOJETVARS
493 
494  jetTableCutDefault = "" #Don't apply any cuts for the table.
495 
496  jetTableDocDefault = jetTableDoc + " with JECs applied. Jets with pt >= {ptcut:.0f} GeV are stored.".format(ptcut=ptcut)
497  if runOnMC:
498  jetTableDocDefault += "For jets with pt < {ptcut:.0f} GeV, only those matched to gen jets are stored.".format(ptcut=ptcut)
499 
500  jetTableName = "jet{}Table".format(jetName)
501  setattr(proc,jetTableName, cms.EDProducer("SimpleCandidateFlatTableProducer",
502  src = cms.InputTag(finalJetsForTable),
503  cut = cms.string(jetTableCutDefault),
504  name = cms.string(jetTablePrefix),
505  doc = cms.string(jetTableDocDefault),
506  singleton = cms.bool(False), # the number of entries is variable
507  extension = cms.bool(False), # this is the main table for the jets
508  variables = cms.PSet(tableContent)
509  )
510  )
511  getattr(proc,jetTableName).variables.pt.precision=10
512  getattr(proc,jetTableName).variables.rawFactor.precision=10
513 
514  #
515  # Save MC-only jet variables in table
516  #
517  jetMCTableName = "jet{}MCTable".format(jetName)
518  setattr(proc, jetMCTableName, cms.EDProducer("SimpleCandidateFlatTableProducer",
519  src = cms.InputTag(finalJetsForTable),
520  cut = getattr(proc,jetTableName).cut,
521  name = cms.string(jetTablePrefix),
522  singleton = cms.bool(False),
523  extension = cms.bool(True), # this is an extension table
524  variables = cms.PSet(
525  partonFlavour = Var("partonFlavour()", int, doc="flavour from parton matching"),
526  hadronFlavour = Var("hadronFlavour()", int, doc="flavour from hadron ghost clustering"),
527  genJetIdx = Var("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().key():-1", int, doc="index of matched gen jet"),
528  )
529  )
530  )
531 
532  #
533  # Define the jet modules Task first
534  #
535  jetTaskName = "jet{}Task".format(jetName)
536  setattr(proc, jetTaskName, cms.Task(
537  getattr(proc,jetCorrFactors),
538  getattr(proc,srcJets),
539  getattr(proc,srcJetsWithUserData),
540  getattr(proc,finalJetsForTable)
541  )
542  )
543  proc.nanoTableTaskCommon.add(getattr(proc,jetTaskName))
544 
545  #
546  # Define the jet tables Task
547  #
548  jetTableTaskName = "jet{}TablesTask".format(jetName)
549  setattr(proc, jetTableTaskName, cms.Task(getattr(proc,jetTableName)))
550  proc.nanoTableTaskCommon.add(getattr(proc,jetTableTaskName))
551 
552  jetMCTableTaskName = "jet{}MCTablesTask".format(jetName)
553  setattr(proc, jetMCTableTaskName, cms.Task(getattr(proc,jetMCTableName)))
554  if runOnMC:
555  proc.nanoTableTaskFS.add(getattr(proc,jetMCTableTaskName))
556 
557  #
558  # Schedule plugins to calculate Jet ID, PileUp Jet ID input variables, and Quark-Gluon Likehood input variables.
559  #
560  if doPF:
561  proc = AddJetID(proc, jetName=jetName, jetSrc=srcJets, jetTableName=jetTableName, jetTaskName=jetTaskName)
562  if doPUIDVar:
563  proc = AddPileUpJetIDVars(proc, jetName=jetName, jetSrc=srcJets, jetTableName=jetTableName, jetTaskName=jetTaskName)
564  if doQGL:
565  proc = AddQGLTaggerVars(proc,jetName=jetName, jetSrc=srcJets, jetTableName=jetTableName, jetTaskName=jetTaskName, calculateQGLVars=True)
566 
567  #
568  # Save b-tagging algorithm scores. Should only be done for jet collection with b-tagging
569  # calculated when reclustered or collection saved with b-tagging info in MiniAOD
570  #
571  if doBTag:
572  AddBTaggingScores(proc,jetTableName=jetTableName)
573  AddDeepJetGluonLQuarkScores(proc,jetTableName=jetTableName)
574  AddParticleNetAK4Scores(proc,jetTableName=jetTableName)
575 
576  return proc
577 
578 
579 def ReclusterAK4PuppiJets(proc, recoJA, runOnMC):
580  """
581  Recluster AK4 Puppi jets and replace slimmedJetsPuppi
582  that is used as default to save AK4 Puppi jets in NanoAODs.
583  """
584  print("custom_jme_cff::ReclusterAK4PuppiJets: Recluster AK4 PF Puppi jets")
585 
586  #
587  # Recluster AK4 Puppi jets
588  #
589  cfg = {
590  "jet" : "ak4pfpuppi",
591  "inputCollection" : "",
592  "genJetsCollection": "AK4GenJetsNoNu",
593  "bTagDiscriminators": bTagDiscriminatorsForAK4,
594  "minPtFastjet" : 0.,
595  }
596  recoJetInfo = recoJA.addRecoJetCollection(proc, **cfg)
597 
598  jetName = recoJetInfo.jetUpper
599  patJetFinalColl = recoJetInfo.patJetFinalCollection
600 
601  #
602  # Change the input jet source for jetCorrFactorsNano
603  # and updatedJets
604  #
605  proc.jetPuppiCorrFactorsNano.src=patJetFinalColl
606  proc.updatedJetsPuppi.jetSource=patJetFinalColl
607 
608  #
609  # Change pt cut
610  #
611  finalJetsPuppiCut = ""
612  if runOnMC:
613  finalJetsPuppiCut = "(pt >= 8) || ((pt < 8) && (genJetFwdRef().backRef().isNonnull()))"
614  else:
615  finalJetsPuppiCut = "(pt >= 8)"
616 
617  proc.finalJetsPuppi.cut = finalJetsPuppiCut
618  #
619  # Add a minimum pt cut for corrT1METJets.
620  #
621  proc.corrT1METJetPuppiTable.cut = "pt>=8 && pt<15 && abs(eta)<9.9"
622 
623  #
624  # Jet table
625  #
626  # For Run-2 eras, the main AK4 jet collection in NanoAOD is the CHS collection
627  run2_nanoAOD_ANY.toModify(proc.jetTable, name = "Jet")
628  # So need to change the table name for AK4 puppi here
629  run2_nanoAOD_ANY.toModify(proc.jetPuppiTable,
630  name = "JetPuppi",
631  src = cms.InputTag("finalJetsPuppi")
632  )
633 
634  #
635  # Jet table documentation
636  #
637  jetPuppiTableDoc = "AK4 PF Puppi jets with JECs applied. Jets with pt >= 8 GeV are stored."
638  if runOnMC:
639  jetPuppiTableDoc += "For jets with pt < 8 GeV, only those matched to AK4 Gen jets are stored."
640  proc.jetPuppiTable.doc = jetPuppiTableDoc
641 
642  proc.jetPuppiTable.variables.rawFactor.precision = 10
643 
644  #
645  # Add variables
646  #
647  proc.jetPuppiTable.variables.hfHEF = PFJETVARS.hfHEF
648  proc.jetPuppiTable.variables.hfEmEF = PFJETVARS.hfEmEF
649  proc.jetPuppiTable.variables.nConstChHads = PFJETVARS.nConstChHads
650  proc.jetPuppiTable.variables.nConstNeuHads = PFJETVARS.nConstNeuHads
651  proc.jetPuppiTable.variables.nConstHFHads = PFJETVARS.nConstHFHads
652  proc.jetPuppiTable.variables.nConstHFEMs = PFJETVARS.nConstHFEMs
653  proc.jetPuppiTable.variables.nConstMuons = PFJETVARS.nConstMuons
654  proc.jetPuppiTable.variables.nConstElecs = PFJETVARS.nConstElecs
655  proc.jetPuppiTable.variables.nConstPhotons = PFJETVARS.nConstPhotons
656 
657  #
658  # Add variables for pileup jet ID studies.
659  #
660 
661  proc = AddPileUpJetIDVars(proc,
662  jetName = jetName,
663  jetSrc = "updatedJetsPuppi",
664  jetTableName = "jetPuppiTable",
665  jetTaskName = "jetPuppiTask"
666  )
667  #
668  # Add variables for quark guon likelihood tagger studies.
669  # Save variables as userFloats and userInts in each jet
670  #
671  proc = AddQGLTaggerVars(proc,
672  jetName = jetName,
673  jetSrc = "updatedJetsPuppi",
674  jetTableName = "jetPuppiTable",
675  jetTaskName = "jetPuppiTask",
676  calculateQGLVars=True
677  )
678  #
679  # Save standard b-tagging and c-tagging variables
680  #
681  proc.jetPuppiTable.variables.btagDeepB = BTAGVARS.btagDeepB
682  proc.jetPuppiTable.variables.btagCSVV2 = BTAGVARS.btagCSVV2
683  proc.jetPuppiTable.variables.btagDeepCvL = BTAGVARS.btagDeepCvL
684  proc.jetPuppiTable.variables.btagDeepCvB = BTAGVARS.btagDeepCvB
685  #
686  # Save DeepJet b-tagging and c-tagging variables
687  #
688  proc.jetPuppiTable.variables.btagDeepFlavB = DEEPJETVARS.btagDeepFlavB
689  proc.jetPuppiTable.variables.btagDeepFlavCvL = DEEPJETVARS.btagDeepFlavCvL
690  proc.jetPuppiTable.variables.btagDeepFlavCvB = DEEPJETVARS.btagDeepFlavCvB
691  #
692  # Save DeepJet raw score for gluon and light quarks
693  #
694  proc.jetPuppiTable.variables.btagDeepFlavG = DEEPJETVARS.btagDeepFlavG
695  proc.jetPuppiTable.variables.btagDeepFlavUDS = DEEPJETVARS.btagDeepFlavUDS
696  proc.jetPuppiTable.variables.btagDeepFlavQG = DEEPJETVARS.btagDeepFlavQG
697  #
698  # Add ParticleNetAK4 scores
699  #
700  proc.jetPuppiTable.variables.particleNetAK4_B = PARTICLENETAK4VARS.particleNetAK4_B
701  proc.jetPuppiTable.variables.particleNetAK4_CvsL = PARTICLENETAK4VARS.particleNetAK4_CvsL
702  proc.jetPuppiTable.variables.particleNetAK4_CvsB = PARTICLENETAK4VARS.particleNetAK4_CvsB
703  proc.jetPuppiTable.variables.particleNetAK4_QvsG = PARTICLENETAK4VARS.particleNetAK4_QvsG
704  proc.jetPuppiTable.variables.particleNetAK4_puIdDisc = PARTICLENETAK4VARS.particleNetAK4_puIdDisc
705 
706  #
707  # For Run-2 eras, don't need to save the low pt AK4 Puppi jet table for MET
708  #
709  _jetPuppiForMETTask = proc.jetPuppiForMETTask.copyAndExclude([proc.corrT1METJetPuppiTable])
710  run2_nanoAOD_ANY.toReplaceWith(proc.jetPuppiForMETTask, _jetPuppiForMETTask)
711 
712  #
713  # Save MC-only jet variables in jet table
714  #
715  if runOnMC:
716 
717  jetMCTableName = "jet{}MCTable".format(jetName)
718  setattr(proc, jetMCTableName, proc.jetMCTable.clone(
719  src = proc.jetPuppiTable.src,
720  name = proc.jetPuppiTable.name
721  )
722  )
723  jetMCTableTaskName = "jet{}MCTablesTask".format(jetName)
724  setattr(proc, jetMCTableTaskName, cms.Task(getattr(proc,jetMCTableName)))
725 
726  _nanoTableTaskFS = proc.nanoTableTaskFS.copy()
727  _nanoTableTaskFS.add(getattr(proc,jetMCTableTaskName))
728  run2_nanoAOD_ANY.toReplaceWith(proc.nanoTableTaskFS, _nanoTableTaskFS)
729 
730  return proc
731 
732 def ReclusterAK4CHSJets(proc, recoJA, runOnMC):
733  """
734  Recluster AK4 CHS jets and replace slimmedJets that is used as default to
735  save AK4 CHS jets in NanoAODs (for Run-2).
736  """
737  print("custom_jme_cff::ReclusterAK4CHSJets: Recluster AK4 PF CHS jets")
738 
739  #
740  # Recluster AK4 CHS jets
741  #
742  cfg = {
743  "jet" : "ak4pfchs",
744  "inputCollection" : "",
745  "genJetsCollection": "AK4GenJetsNoNu",
746  "bTagDiscriminators": bTagDiscriminatorsForAK4,
747  "minPtFastjet" : 0.,
748  }
749  recoJetInfo = recoJA.addRecoJetCollection(proc, **cfg)
750 
751  jetName = recoJetInfo.jetUpper
752  patJetFinalColl = recoJetInfo.patJetFinalCollection
753 
754  #
755  # Change the input jet source for jetCorrFactorsNano
756  # and updatedJets
757  #
758  proc.jetCorrFactorsNano.src=patJetFinalColl
759  proc.updatedJets.jetSource=patJetFinalColl
760 
761  #
762  # Change pt cut
763  #
764  finalJetsCut = ""
765  if runOnMC:
766  finalJetsCut = "(pt >= 8) || ((pt < 8) && (genJetFwdRef().backRef().isNonnull()))"
767  else:
768  finalJetsCut = "(pt >= 8)"
769 
770  proc.finalJets.cut = finalJetsCut
771  #
772  # Add a minimum pt cut for corrT1METJets.
773  #
774  proc.corrT1METJetTable.cut = "pt>=8 && pt<15 && abs(eta)<9.9"
775 
776  #
777  # Jet table cut
778  #
779  jetTableCut = "" # must not have any cut at the jetTable for AK4 CHS as it has been cross-cleaned
780  proc.jetTable.src = cms.InputTag("finalJets")
781  proc.jetTable.cut = jetTableCut
782  proc.jetMCTable.cut = jetTableCut
783  proc.jetTable.name = "JetCHS"
784 
785  #
786  # For Run-2 eras, the main AK4 jet collection in NanoAOD is the CHS collection
787  #
788  run2_nanoAOD_ANY.toModify(proc.jetTable,
789  src = cms.InputTag("linkedObjects","jets"),
790  name = "Jet"
791  )
792 
793  #
794  # Jet table documentation
795  #
796  jetTableDoc = "AK4 PF CHS jets with JECs applied. Jets with pt >= 8 GeV are stored."
797  if runOnMC:
798  jetTableDoc += "For jets with pt < 8 GeV, only those matched to AK4 Gen jets are stored."
799  proc.jetTable.doc = jetTableDoc
800 
801  proc.jetTable.variables.rawFactor.precision = 10
802 
803  #
804  # Add variables
805  #
806  proc.jetTable.variables.hfHEF = PFJETVARS.hfHEF
807  proc.jetTable.variables.hfEmEF = PFJETVARS.hfEmEF
808  proc.jetTable.variables.nConstChHads = PFJETVARS.nConstChHads
809  proc.jetTable.variables.nConstNeuHads = PFJETVARS.nConstNeuHads
810  proc.jetTable.variables.nConstHFHads = PFJETVARS.nConstHFHads
811  proc.jetTable.variables.nConstHFEMs = PFJETVARS.nConstHFEMs
812  proc.jetTable.variables.nConstMuons = PFJETVARS.nConstMuons
813  proc.jetTable.variables.nConstElecs = PFJETVARS.nConstElecs
814  proc.jetTable.variables.nConstPhotons = PFJETVARS.nConstPhotons
815 
816  #
817  # Setup pileup jet ID with 80X training.
818  #
819  pileupJetId80X = "pileupJetId80X"
820  setattr(proc, pileupJetId80X, pileupJetId.clone(
821  jets = "updatedJets",
822  algos = cms.VPSet(_chsalgos_81x),
823  inputIsCorrected = True,
824  applyJec = False,
825  vertexes = "offlineSlimmedPrimaryVertices"
826  )
827  )
828  _jetUserDataTask = proc.jetUserDataTask.copy()
829  _jetUserDataTask.add(getattr(proc,pileupJetId80X))
830  for modifier in run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1:
831  modifier.toReplaceWith(proc.jetUserDataTask, _jetUserDataTask)
832  modifier.toModify(proc.updatedJetsWithUserData.userInts, puId80XfullId = cms.InputTag('pileupJetId80X:fullId'))
833  modifier.toModify(proc.jetTable.variables, puId = Var("userInt('puId80XfullId')", int, doc="Pileup ID flags with 80X (2016) training"))
834  run2_nanoAOD_94X2016.toModify(proc.updatedJetsWithUserData.userFloats, puId80XDisc = cms.InputTag("pileupJetId80X:fullDiscriminant"))
835  run2_nanoAOD_94X2016.toModify(proc.jetTable.variables, puIdDisc = Var("userFloat('puId80XDisc')",float,doc="Pilup ID discriminant with 80X (2016) training",precision=10))
836 
837  #
838  # Add charged energy fraction from other primary vertices
839  #
840  proc.updatedJetsWithUserData.userFloats.chFPV1EF = cms.InputTag("jercVars:chargedFromPV1EnergyFraction")
841  proc.updatedJetsWithUserData.userFloats.chFPV2EF = cms.InputTag("jercVars:chargedFromPV2EnergyFraction")
842  proc.updatedJetsWithUserData.userFloats.chFPV3EF = cms.InputTag("jercVars:chargedFromPV3EnergyFraction")
843  proc.jetTable.variables.chFPV1EF = Var("userFloat('chFPV1EF')", float, doc="charged fromPV==1 Energy Fraction (component of the total charged Energy Fraction).", precision= 6)
844  proc.jetTable.variables.chFPV2EF = Var("userFloat('chFPV2EF')", float, doc="charged fromPV==2 Energy Fraction (component of the total charged Energy Fraction).", precision= 6)
845  proc.jetTable.variables.chFPV3EF = Var("userFloat('chFPV3EF')", float, doc="charged fromPV==3 Energy Fraction (component of the total charged Energy Fraction).", precision= 6)
846 
847  #
848  # Add variables for pileup jet ID studies.
849  #
850  proc = AddPileUpJetIDVars(proc,
851  jetName = jetName,
852  jetSrc = "updatedJets",
853  jetTableName = "jetTable",
854  jetTaskName = "jetTask"
855  )
856  #
857  # Add variables for quark guon likelihood tagger studies.
858  # Save variables as userFloats and userInts in each jet
859  #
860  proc.updatedJetsWithUserData.userFloats.qgl_axis2 = cms.InputTag("qgtagger:axis2")
861  proc.updatedJetsWithUserData.userFloats.qgl_ptD = cms.InputTag("qgtagger:ptD")
862  proc.updatedJetsWithUserData.userInts.qgl_mult = cms.InputTag("qgtagger:mult")
863  #
864  # Save quark gluon likelihood input variables variables
865  #
866  proc.jetTable.variables.qgl_axis2 = QGLVARS.qgl_axis2
867  proc.jetTable.variables.qgl_ptD = QGLVARS.qgl_ptD
868  proc.jetTable.variables.qgl_mult = QGLVARS.qgl_mult
869  #
870  # Save standard b-tagging and c-tagging variables
871  #
872  proc.jetTable.variables.btagDeepB = BTAGVARS.btagDeepB
873  proc.jetTable.variables.btagCSVV2 = BTAGVARS.btagCSVV2
874  proc.jetTable.variables.btagDeepCvL = BTAGVARS.btagDeepCvL
875  proc.jetTable.variables.btagDeepCvB = BTAGVARS.btagDeepCvB
876  #
877  # Save DeepJet b-tagging and c-tagging variables
878  #
879  proc.jetTable.variables.btagDeepFlavB = DEEPJETVARS.btagDeepFlavB
880  proc.jetTable.variables.btagDeepFlavCvL = DEEPJETVARS.btagDeepFlavCvL
881  proc.jetTable.variables.btagDeepFlavCvB = DEEPJETVARS.btagDeepFlavCvB
882  #
883  # Save DeepJet raw score for gluon and light quarks
884  #
885  proc.jetTable.variables.btagDeepFlavG = DEEPJETVARS.btagDeepFlavG
886  proc.jetTable.variables.btagDeepFlavUDS = DEEPJETVARS.btagDeepFlavUDS
887  proc.jetTable.variables.btagDeepFlavQG = DEEPJETVARS.btagDeepFlavQG
888  #
889  # Add ParticleNetAK4 scores
890  #
891  proc.jetTable.variables.particleNetAK4_B = PARTICLENETAK4VARS.particleNetAK4_B
892  proc.jetTable.variables.particleNetAK4_CvsL = PARTICLENETAK4VARS.particleNetAK4_CvsL
893  proc.jetTable.variables.particleNetAK4_CvsB = PARTICLENETAK4VARS.particleNetAK4_CvsB
894  proc.jetTable.variables.particleNetAK4_QvsG = PARTICLENETAK4VARS.particleNetAK4_QvsG
895  proc.jetTable.variables.particleNetAK4_puIdDisc = PARTICLENETAK4VARS.particleNetAK4_puIdDisc
896 
897  #Adding hf shower shape producer to the jet sequence. By default this producer is not automatically rerun at the NANOAOD step
898  #The following lines make sure it is.
899  hfJetShowerShapeforCustomNanoAOD = "hfJetShowerShapeforCustomNanoAOD"
900  setattr(proc, hfJetShowerShapeforCustomNanoAOD, hfJetShowerShapeforNanoAOD.clone(jets="updatedJets",vertices="offlineSlimmedPrimaryVertices") )
901  proc.jetUserDataTask.add(getattr(proc, hfJetShowerShapeforCustomNanoAOD))
902  proc.updatedJetsWithUserData.userFloats.hfsigmaEtaEta = cms.InputTag('hfJetShowerShapeforCustomNanoAOD:sigmaEtaEta')
903  proc.updatedJetsWithUserData.userFloats.hfsigmaPhiPhi = cms.InputTag('hfJetShowerShapeforCustomNanoAOD:sigmaPhiPhi')
904  proc.updatedJetsWithUserData.userInts.hfcentralEtaStripSize = cms.InputTag('hfJetShowerShapeforCustomNanoAOD:centralEtaStripSize')
905  proc.updatedJetsWithUserData.userInts.hfadjacentEtaStripsSize = cms.InputTag('hfJetShowerShapeforCustomNanoAOD:adjacentEtaStripsSize')
906  proc.jetTable.variables.hfsigmaEtaEta = Var("userFloat('hfsigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10)
907  proc.jetTable.variables.hfsigmaPhiPhi = Var("userFloat('hfsigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10)
908  proc.jetTable.variables.hfcentralEtaStripSize = Var("userInt('hfcentralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable) ")
909  proc.jetTable.variables.hfadjacentEtaStripsSize = Var("userInt('hfadjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable) ")
910 
911  #
912  # Since AK4 Puppi jet is the main AK4 jet collection for Run-3, disable
913  # b-jets/c-jets NN-based mass regression for AK4 CHS.
914  #
915  _jetUserDataTask = proc.jetUserDataTask.copyAndExclude([proc.bJetVars])
916  (~run2_nanoAOD_ANY).toReplaceWith(proc.jetUserDataTask, _jetUserDataTask)
917 
918  _jetTablesTask = proc.jetTablesTask.copyAndExclude([proc.bjetNN, proc.cjetNN])
919  (~run2_nanoAOD_ANY).toReplaceWith(proc.jetTablesTask, _jetTablesTask)
920 
921  (~run2_nanoAOD_ANY).toModify(proc.updatedJetsWithUserData.userFloats,
922  leadTrackPt = None,
923  leptonPtRel = None,
924  leptonPtRatio = None,
925  leptonPtRelInv = None,
926  leptonPtRelv0 = None,
927  leptonPtRatiov0 = None,
928  leptonPtRelInvv0 = None,
929  leptonDeltaR = None,
930  leptonPt = None,
931  vtxPt = None,
932  vtxMass = None,
933  vtx3dL = None,
934  vtx3deL = None,
935  ptD = None,
936  genPtwNu = None
937  )
938 
939  (~run2_nanoAOD_ANY).toModify(proc.updatedJetsWithUserData.userInts,
940  vtxNtrk = None,
941  leptonPdgId = None
942  )
943 
944  (~run2_nanoAOD_ANY).toModify(proc.jetTable, externalVariables = cms.PSet())
945 
946  #
947  # For Run-3, don't need to save the low pt AK4 CHS jet table for MET
948  #
949  _jetForMETTask = proc.jetForMETTask.copyAndExclude([proc.corrT1METJetTable])
950  (~run2_nanoAOD_ANY).toReplaceWith(proc.jetForMETTask, _jetForMETTask)
951 
952  #
953  # Save MC-only jet variables in jet table
954  #
955  if runOnMC:
956  jetMCTableName = "jet{}MCTable".format(jetName)
957  setattr(proc, jetMCTableName, proc.jetMCTable.clone(
958  src = proc.jetTable.src,
959  name = proc.jetTable.name
960  )
961  )
962  jetMCTableTaskName = "jet{}MCTablesTask".format(jetName)
963  setattr(proc, jetMCTableTaskName, cms.Task(getattr(proc,jetMCTableName)))
964 
965  _nanoTableTaskFS = proc.nanoTableTaskFS.copy()
966  _nanoTableTaskFS.add(getattr(proc,jetMCTableTaskName))
967  (~run2_nanoAOD_ANY).toReplaceWith(proc.nanoTableTaskFS, _nanoTableTaskFS)
968 
969  return proc
970 
971 def AddNewAK8PuppiJetsForJEC(proc, recoJA, runOnMC):
972  """
973  Store a separate AK8 Puppi jet collection for JEC studies.
974  Only minimal info are stored
975  """
976  print("custom_jme_cff::AddNewAK8PuppiJetsForJEC: Make a new AK8 PF Puppi jet collection for JEC studies")
977 
978  #
979  # Recluster AK8 Puppi jets
980  #
981  cfg = {
982  "jet" : "ak8pfpuppi",
983  "inputCollection" : "",
984  "genJetsCollection": "AK8GenJetsNoNu",
985  "minPtFastjet" : 0., # Remove any pt threshold at the jet clustering stage.
986  }
987  recoJetInfo = recoJA.addRecoJetCollection(proc, **cfg)
988 
989  jetName = recoJetInfo.jetUpper
990  payload = recoJetInfo.jetCorrPayload
991 
992  patJetFinalColl = recoJetInfo.patJetFinalCollection
993  jetTablePrefix = "FatJetForJEC"
994  jetTableDoc = "AK8 PF Puppi jets with JECs applied. Reclustered for JEC studies so only minimal info stored."
995  ptcut = 15
996 
997  SavePatJets(proc,
998  jetName, payload, patJetFinalColl, jetTablePrefix, jetTableDoc, doPF=True,
999  doCalo=False, ptcut=ptcut, doPUIDVar=False, doQGL=False, doBTag=False, runOnMC=runOnMC
1000  )
1001 
1002  return proc
1003 
1004 def AddNewAK8CHSJets(proc, recoJA, runOnMC):
1005  """
1006  Store an AK8 CHS jet collection for JEC studies.
1007  """
1008  print("custom_jme_cff::AddNewAK8CHSJets: Make a new AK8 PF CHS jet collection for JEC studies")
1009 
1010  #
1011  # Recluster AK8 CHS jets
1012  #
1013  cfg = {
1014  "jet" : "ak8pfchs",
1015  "inputCollection" : "",
1016  "genJetsCollection": "AK8GenJetsNoNu",
1017  "minPtFastjet" : 0., # Remove any pt threshold at the jet clustering stage.
1018  }
1019  recoJetInfo = recoJA.addRecoJetCollection(proc, **cfg)
1020 
1021  jetName = recoJetInfo.jetUpper
1022  payload = recoJetInfo.jetCorrPayload
1023 
1024  patJetFinalColl = recoJetInfo.patJetFinalCollection
1025  jetTablePrefix = "FatJetCHS"
1026  jetTableDoc = "AK8 PF CHS jets with JECs applied. Reclustered for JEC studies so only minimal info stored."
1027  ptcut = 15
1028 
1029  SavePatJets(proc,
1030  jetName, payload, patJetFinalColl, jetTablePrefix, jetTableDoc, doPF=True,
1031  doCalo=False, ptcut=ptcut, doPUIDVar=False, doQGL=False, doBTag=False, runOnMC=runOnMC
1032  )
1033 
1034  return proc
1035 
1037  """
1038  Add more variables for AK8 PFPUPPI jets
1039  """
1040 
1041  proc.fatJetTable.variables.rawFactor.precision = 10
1042 
1043  #
1044  # These variables are not stored for AK8PFPUPPI (slimmedJetsAK8)
1045  # in MiniAOD if their pt < 170 GeV. Hence the conditional fill.
1046  #
1047  proc.fatJetTable.variables.chHEF = Var("?isPFJet()?chargedHadronEnergyFraction():-1", float, doc="charged Hadron Energy Fraction", precision = 6)
1048  proc.fatJetTable.variables.neHEF = Var("?isPFJet()?neutralHadronEnergyFraction():-1", float, doc="neutral Hadron Energy Fraction", precision = 6)
1049  proc.fatJetTable.variables.chEmEF = Var("?isPFJet()?chargedEmEnergyFraction():-1", float, doc="charged Electromagnetic Energy Fraction", precision = 6)
1050  proc.fatJetTable.variables.neEmEF = Var("?isPFJet()?neutralEmEnergyFraction():-1", float, doc="neutral Electromagnetic Energy Fraction", precision = 6)
1051  proc.fatJetTable.variables.muEF = Var("?isPFJet()?muonEnergyFraction():-1", float, doc="muon Energy Fraction", precision = 6)
1052  proc.fatJetTable.variables.hfHEF = Var("?isPFJet()?HFHadronEnergyFraction():-1", float, doc="energy fraction in forward hadronic calorimeter", precision = 6)
1053  proc.fatJetTable.variables.hfEmEF = Var("?isPFJet()?HFEMEnergyFraction():-1", float, doc="energy fraction in forward EM calorimeter", precision = 6)
1054  proc.fatJetTable.variables.nConstChHads = Var("?isPFJet()?chargedHadronMultiplicity():-1",int, doc="number of charged hadrons in the jet")
1055  proc.fatJetTable.variables.nConstNeuHads = Var("?isPFJet()?neutralHadronMultiplicity():-1",int, doc="number of neutral hadrons in the jet")
1056  proc.fatJetTable.variables.nConstHFHads = Var("?isPFJet()?HFHadronMultiplicity():-1", int, doc="number of HF Hadrons in the jet")
1057  proc.fatJetTable.variables.nConstHFEMs = Var("?isPFJet()?HFEMMultiplicity():-1", int, doc="number of HF EMs in the jet")
1058  proc.fatJetTable.variables.nConstMuons = Var("?isPFJet()?muonMultiplicity():-1", int, doc="number of muons in the jet")
1059  proc.fatJetTable.variables.nConstElecs = Var("?isPFJet()?electronMultiplicity():-1", int, doc="number of electrons in the jet")
1060  proc.fatJetTable.variables.nConstPhotons = Var("?isPFJet()?photonMultiplicity():-1", int, doc="number of photons in the jet")
1061 
1062  return proc
1063 #******************************************
1064 #
1065 #
1066 # Gen Jets related functions
1067 #
1068 #
1069 #******************************************
1070 def AddNewGenJets(proc, genJetInfo):
1071  """
1072  Add genJet into custom nanoAOD
1073  """
1074 
1075  genJetName = genJetInfo.jetUpper
1076  genJetAlgo = genJetInfo.jetAlgo
1077  genJetSize = genJetInfo.jetSize
1078  genJetSizeNr = genJetInfo.jetSizeNr
1079  genJetFinalColl = "{}{}{}".format(genJetAlgo.upper(), genJetSize, "GenJetsNoNu")
1080  genJetTablePrefix = nanoInfo_genjets[genJetInfo.jet]["name"]
1081  genJetTableDoc = nanoInfo_genjets[genJetInfo.jet]["doc"]
1082 
1083  SaveGenJets(proc, genJetName, genJetAlgo, genJetSizeNr, genJetFinalColl, genJetTablePrefix, genJetTableDoc, runOnMC=False)
1084 
1085  return proc
1086 
1087 def SaveGenJets(proc, genJetName, genJetAlgo, genJetSizeNr, genJetFinalColl, genJetTablePrefix, genJetTableDoc, runOnMC=False):
1088  """
1089  Schedule modules for a given genJet collection and save its variables into custom NanoAOD
1090  """
1091 
1092  genJetTableName = "jet{}Table".format(genJetName)
1093  setattr(proc, genJetTableName, genJetTable.clone(
1094  src = genJetFinalColl,
1095  cut = "", # No cut specified here. Save all gen jets after clustering
1096  name = genJetTablePrefix,
1097  doc = genJetTableDoc,
1098  variables = GENJETVARS
1099  )
1100  )
1101 
1102  genJetFlavourAssociationName = "genJet{}FlavourAssociation".format(genJetName)
1103  setattr(proc, genJetFlavourAssociationName, genJetFlavourAssociation.clone(
1104  jets = getattr(proc,genJetTableName).src,
1105  jetAlgorithm = supportedJetAlgos[genJetAlgo],
1106  rParam = genJetSizeNr,
1107  )
1108  )
1109 
1110  genJetFlavourTableName = "genJet{}FlavourTable".format(genJetName)
1111  setattr(proc, genJetFlavourTableName, genJetFlavourTable.clone(
1112  name = getattr(proc,genJetTableName).name,
1113  src = getattr(proc,genJetTableName).src,
1114  cut = getattr(proc,genJetTableName).cut,
1115  jetFlavourInfos = genJetFlavourAssociationName,
1116  )
1117  )
1118 
1119  genJetTaskName = "genJet{}Task".format(genJetName)
1120  setattr(proc, genJetTaskName, cms.Task(
1121  getattr(proc,genJetTableName),
1122  getattr(proc,genJetFlavourAssociationName),
1123  getattr(proc,genJetFlavourTableName)
1124  )
1125  )
1126  proc.jetMCTask.add(getattr(proc,genJetTaskName))
1127 
1128  return proc
1129 
1130 def ReclusterAK4GenJets(proc, genJA):
1131  """
1132  Recluster AK4 Gen jets and replace
1133  slimmedGenJets that is used as default
1134  to save AK4 Gen jets in NanoAODs.
1135  """
1136  print("custom_jme_cff::ReclusterAK4GenJets: Recluster AK4 Gen jets")
1137 
1138  #
1139  # Recluster AK4 Gen jet
1140  #
1141  cfg = {
1142  "jet" : "ak4gen",
1143  }
1144  genJetInfo = genJA.addGenJetCollection(proc, **cfg)
1145 
1146  genJetName = genJetInfo.jetUpper
1147  genJetAlgo = genJetInfo.jetAlgo
1148  genJetSize = genJetInfo.jetSize
1149  genJetSizeNr = genJetInfo.jetSizeNr
1150  selectedGenJets = "{}{}{}".format(genJetAlgo.upper(), genJetSize, "GenJetsNoNu")
1151 
1152  #
1153  # Change jet source to the newly clustered jet collection. Set very low pt cut for jets
1154  # to be stored in the GenJet Table
1155  #
1156  proc.genJetTable.src = selectedGenJets
1157  proc.genJetTable.cut = "" # No cut specified here. Save all gen jets after clustering
1158  proc.genJetTable.doc = "AK4 Gen jets (made with visible genparticles) with pt > 3 GeV" # default pt cut after clustering is 3 GeV
1159 
1160  genJetFlavourAssociationName = "genJet{}FlavourAssociation".format(genJetName)
1161  setattr(proc, genJetFlavourAssociationName, genJetFlavourAssociation.clone(
1162  jets = proc.genJetTable.src,
1163  jetAlgorithm = supportedJetAlgos[genJetAlgo],
1164  rParam = genJetSizeNr,
1165  )
1166  )
1167  proc.jetMCTask.add(getattr(proc, genJetFlavourAssociationName))
1168  return proc
1169 
1170 def AddNewAK8GenJetsForJEC(proc, genJA):
1171  """
1172  Make a separate AK8 Gen jet collection for JEC studies.
1173  """
1174  print("custom_jme_cff::AddNewAK8GenJetsForJEC: Add new AK8 Gen jets for JEC studies")
1175 
1176  #
1177  # Recluster AK8 Gen jet
1178  #
1179  cfg = {
1180  "jet" : "ak8gen",
1181  }
1182  genJetInfo = genJA.addGenJetCollection(proc, **cfg)
1183 
1184  genJetName = genJetInfo.jetUpper
1185  genJetAlgo = genJetInfo.jetAlgo
1186  genJetSize = genJetInfo.jetSize
1187  genJetSizeNr = genJetInfo.jetSizeNr
1188  genJetFinalColl = "{}{}{}".format(genJetAlgo.upper(), genJetSize, "GenJetsNoNu")
1189  genJetTablePrefix = "GenJetAK8ForJEC"
1190  genJetTableDoc = "AK8 Gen jets (made with visible genparticles) with pt > 3 GeV. Reclustered for JEC studies."
1191 
1192  SaveGenJets(proc, genJetName, genJetAlgo, genJetSizeNr, genJetFinalColl, genJetTablePrefix, genJetTableDoc, runOnMC=False)
1193 
1194  return proc
1195 
1197  proc.genJetTable.variables.nConstituents = GENJETVARS.nConstituents
1198  return proc
1199 
1201  proc.genJetAK8Table.variables.nConstituents = GENJETVARS.nConstituents
1202  return proc
1203 
1204 #===========================================================================
1205 #
1206 # Misc. functions
1207 #
1208 #===========================================================================
1210  """
1211  Remove default pt cuts for all jets set in jets_cff.py
1212  """
1213 
1214  proc.finalJets.cut = "" # 15 -> 10
1215  proc.finalJetsPuppi.cut = "" # 15 -> 10
1216  proc.finalJetsAK8.cut = "" # 170 -> 170
1217  proc.genJetTable.cut = "" # 10 -> 8
1218  proc.genJetFlavourTable.cut = "" # 10 -> 8
1219  proc.genJetAK8Table.cut = "" # 100 -> 80
1220  proc.genJetAK8FlavourTable.cut = "" # 100 -> 80
1221 
1222  return proc
1223 
1224 #===========================================================================
1225 #
1226 # CUSTOMIZATION function
1227 #
1228 #===========================================================================
1229 def PrepJMECustomNanoAOD(process,runOnMC):
1230 
1231 
1234  process = RemoveAllJetPtCuts(process)
1235 
1236 
1241  genJA = GenJetAdder()
1242  if runOnMC:
1243 
1246  process = AddVariablesForAK8GenJets(process)
1247 
1250  process = AddNewAK8GenJetsForJEC(process, genJA)
1251 
1254  process = ReclusterAK4GenJets(process, genJA)
1255  process = AddVariablesForAK4GenJets(process)
1256 
1259  for jetConfig in config_genjets:
1260  cfg = { k : v for k, v in jetConfig.items() if k != "enabled"}
1261  genJetInfo = genJA.addGenJetCollection(process, **cfg)
1262  AddNewGenJets(process, genJetInfo)
1263 
1264 
1269  recoJA = RecoJetAdder(runOnMC=runOnMC)
1270 
1273  process = AddVariablesForAK8PuppiJets(process)
1274 
1277  process = AddNewAK8PuppiJetsForJEC(process, recoJA, runOnMC)
1278 
1281  process = AddNewAK8CHSJets(process, recoJA, runOnMC)
1282 
1285  process = ReclusterAK4CHSJets(process, recoJA, runOnMC)
1286 
1289  process = ReclusterAK4PuppiJets(process, recoJA, runOnMC)
1290 
1293  for jetConfig in config_recojets:
1294  cfg = { k : v for k, v in jetConfig.items() if k != "enabled"}
1295  recoJetInfo = recoJA.addRecoJetCollection(process, **cfg)
1296  AddNewPatJets(process, recoJetInfo, runOnMC)
1297 
1298 
1303  def addAK4JetTasks(proc, addAK4CHSJetTasks, addAK4PuppiJetTasks):
1304  if addAK4CHSJetTasks:
1305  proc.nanoTableTaskCommon.add(proc.jetTask)
1306  proc.nanoTableTaskCommon.add(proc.jetTablesTask)
1307  proc.nanoTableTaskCommon.add(proc.jetForMETTask)
1308  if addAK4PuppiJetTasks:
1309  proc.nanoTableTaskCommon.add(proc.jetPuppiTask)
1310  proc.nanoTableTaskCommon.add(proc.jetPuppiTablesTask)
1311  proc.nanoTableTaskCommon.add(proc.jetPuppiForMETTask)
1312  return proc
1313 
1314  jmeNano_addAK4JetTasks_switch = cms.PSet(
1315  jmeNano_addAK4CHS_switch = cms.untracked.bool(True),
1316  jmeNano_addAK4Puppi_switch = cms.untracked.bool(False)
1317  )
1318  run2_nanoAOD_ANY.toModify(jmeNano_addAK4JetTasks_switch,
1319  jmeNano_addAK4CHS_switch = False,
1320  jmeNano_addAK4Puppi_switch = True
1321  )
1322  process = addAK4JetTasks(process,
1323  addAK4CHSJetTasks = jmeNano_addAK4JetTasks_switch.jmeNano_addAK4CHS_switch,
1324  addAK4PuppiJetTasks = jmeNano_addAK4JetTasks_switch.jmeNano_addAK4Puppi_switch,
1325  )
1326 
1327 
1330  if runOnMC:
1331  process.puTable.savePtHatMax = True
1332 
1333 
1336  if runOnMC:
1337  process.genWeightsTable.keepAllPSWeights = True
1338 
1339  return process
1340 
1341 from PhysicsTools.NanoAOD.V10.nano_cff import nanoAOD_customizeV10
1342 
1344  process = nanoAOD_customizeV10(process)
1345  process = PrepJMECustomNanoAOD(process,runOnMC=True)
1346 
1347  return process
1348 
1350  process = nanoAOD_customizeV10(process)
1351  process = PrepJMECustomNanoAOD(process,runOnMC=False)
1352  return process
def AddBTaggingScores(proc, jetTableName="")
def ReclusterAK4CHSJets(proc, recoJA, runOnMC)
def AddQGLTaggerVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName="", calculateQGLVars=False)
def RemoveAllJetPtCuts(proc)
def PrepJMECustomNanoAOD(process, runOnMC)
def AddNewPatJets(proc, recoJetInfo, runOnMC)
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20
def ReclusterAK4GenJets(proc, genJA)
def AddNewAK8CHSJets(proc, recoJA, runOnMC)
def AddNewAK8GenJetsForJEC(proc, genJA)
def SavePatJets(proc, jetName, payload, patJetFinalColl, jetTablePrefix, jetTableDoc, doPF, doCalo, ptcut, doPUIDVar=False, doQGL=False, doBTag=False, runOnMC=False)
def ReclusterAK4PuppiJets(proc, recoJA, runOnMC)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def AddDeepJetGluonLQuarkScores(proc, jetTableName="")
def nanoAOD_customizeV10(process)
Definition: nano_cff.py:6
def AddJetID(proc, jetName="", jetSrc="", jetTableName="", jetTaskName="")
def AddNewAK8PuppiJetsForJEC(proc, recoJA, runOnMC)
def AddNewGenJets(proc, genJetInfo)
def SaveGenJets(proc, genJetName, genJetAlgo, genJetSizeNr, genJetFinalColl, genJetTablePrefix, genJetTableDoc, runOnMC=False)
def AddVariablesForAK4GenJets(proc)
def AddVariablesForAK8PuppiJets(proc)
def AddParticleNetAK4Scores(proc, jetTableName="")
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
def AddVariablesForAK8GenJets(proc)
def PrepJMECustomNanoAOD_MC(process)
def AddPileUpJetIDVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName="")
def PrepJMECustomNanoAOD_Data(process)