CMS 3D CMS Logo

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