CMS 3D CMS Logo

jetsAK4_Puppi_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
5 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
6 
7 
8 
10 # Note: Safe to always add 'L2L3Residual' as MC contains dummy L2L3Residual corrections (always set to 1)
11 # (cf. https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CMSSW_7_6_4_and_above )
12 jetPuppiCorrFactorsNano = patJetCorrFactors.clone(src='slimmedJetsPuppi',
13  levels = cms.vstring('L1FastJet',
14  'L2Relative',
15  'L3Absolute',
16  'L2L3Residual'),
17  payload = cms.string('AK4PFPuppi'),
18  primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
19 )
20 
22 
23 updatedJetsPuppi = updatedPatJets.clone(
24  addBTagInfo=False,
25  jetSource='slimmedJetsPuppi',
26  jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetPuppiCorrFactorsNano") ),
27 )
28 
29 tightJetPuppiId = cms.EDProducer("PatJetIDValueMapProducer",
30  filterParams=cms.PSet(
31  version = cms.string('RUN3PUPPIruns2022FGruns2023CD'),
32  quality = cms.string('TIGHT'),
33  ),
34  src = cms.InputTag("updatedJetsPuppi")
35 )
36 tightJetPuppiIdLepVeto = cms.EDProducer("PatJetIDValueMapProducer",
37  filterParams=cms.PSet(
38  version = cms.string('RUN3PUPPIruns2022FGruns2023CD'),
39  quality = cms.string('TIGHTLEPVETO'),
40  ),
41  src = cms.InputTag("updatedJetsPuppi")
42 )
43 
44 run2_jme_2016.toModify(
45  tightJetPuppiId.filterParams, version = "RUN2UL16PUPPI"
46 ).toModify(
47  tightJetPuppiIdLepVeto.filterParams, version = "RUN2UL16PUPPI"
48 )
49 
50 (run2_jme_2017 | run2_jme_2018 | run3_nanoAOD_122 | run3_nanoAOD_124).toModify(
51  tightJetPuppiId.filterParams, version = "RUN2ULPUPPI"
52 ).toModify(
53  tightJetPuppiIdLepVeto.filterParams, version = "RUN2ULPUPPI"
54 )
55 
56 run3_jme_Winter22runsBCDEprompt.toModify(
57  tightJetPuppiId.filterParams, version = "RUN3PUPPIruns2022BCDEprompt"
58 ).toModify(
59  tightJetPuppiIdLepVeto.filterParams, version = "RUN3PUPPIruns2022BCDEprompt"
60 )
61 
62 #HF shower shape recomputation
63 from RecoJets.JetProducers.hfJetShowerShape_cfi import hfJetShowerShape
64 hfJetPuppiShowerShapeforNanoAOD = hfJetShowerShape.clone(jets="updatedJetsPuppi",vertices="offlineSlimmedPrimaryVertices")
65 
66 updatedJetsPuppiWithUserData = cms.EDProducer("PATJetUserDataEmbedder",
67  src = cms.InputTag("updatedJetsPuppi"),
68  userFloats = cms.PSet(
69  hfsigmaEtaEta = cms.InputTag('hfJetPuppiShowerShapeforNanoAOD:sigmaEtaEta'),
70  hfsigmaPhiPhi = cms.InputTag('hfJetPuppiShowerShapeforNanoAOD:sigmaPhiPhi'),
71  ),
72  userInts = cms.PSet(
73  tightId = cms.InputTag("tightJetPuppiId"),
74  tightIdLepVeto = cms.InputTag("tightJetPuppiIdLepVeto"),
75  hfcentralEtaStripSize = cms.InputTag('hfJetPuppiShowerShapeforNanoAOD:centralEtaStripSize'),
76  hfadjacentEtaStripsSize = cms.InputTag('hfJetPuppiShowerShapeforNanoAOD:adjacentEtaStripsSize'),
77  ),
78 )
79 
80 finalJetsPuppi = cms.EDFilter("PATJetRefSelector",
81  src = cms.InputTag("updatedJetsPuppiWithUserData"),
82  cut = cms.string("pt > 15")
83 )
84 
85 
86 jetPuppiTable = simpleCandidateFlatTableProducer.clone(
87  src = cms.InputTag("linkedObjects","jets"),
88  name = cms.string("Jet"),
89  doc = cms.string("slimmedJetsPuppi, i.e. ak4 PFJets Puppi with JECs applied, after basic selection (" + finalJetsPuppi.cut.value()+")"),
90  externalVariables = cms.PSet(),
91  variables = cms.PSet(P4Vars,
92  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
93  nMuons = Var("?hasOverlaps('muons')?overlaps('muons').size():0", "uint8", doc="number of muons in the jet"),
94  muonIdx1 = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", "int16", doc="index of first matching muon"),
95  muonIdx2 = Var("?overlaps('muons').size()>1?overlaps('muons')[1].key():-1", "int16", doc="index of second matching muon"),
96  electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", "int16", doc="index of first matching electron"),
97  electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", "int16", doc="index of second matching electron"),
98  nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", "uint8", doc="number of electrons in the jet"),
99  svIdx1 = Var("?overlaps('vertices').size()>0?overlaps('vertices')[0].key():-1", "int16", doc="index of first matching secondary vertex"),
100  svIdx2 = Var("?overlaps('vertices').size()>1?overlaps('vertices')[1].key():-1", "int16", doc="index of second matching secondary vertex"),
101  nSVs = Var("?hasOverlaps('vertices')?overlaps('vertices').size():0", "uint8", doc="number of secondary vertices in the jet"),
102  btagDeepFlavB = Var("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10),
103  btagRobustParTAK4B = Var("bDiscriminator('pfParticleTransformerAK4JetTags:probb')+bDiscriminator('pfParticleTransformerAK4JetTags:probbb')+bDiscriminator('pfParticleTransformerAK4JetTags:problepb')",float,doc="RobustParTAK4 b+bb+lepb tag discriminator",precision=10),
104  btagDeepFlavCvL = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg')):-1",float,doc="DeepJet c vs uds+g discriminator",precision=10),
105  btagDeepFlavCvB = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')):-1",float,doc="DeepJet c vs b+bb+lepb discriminator",precision=10),
106  btagDeepFlavQG = Var("?(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds'))>0?bDiscriminator('pfDeepFlavourJetTags:probg')/(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds')):-1",float,doc="DeepJet g vs uds discriminator",precision=10),
107  btagRobustParTAK4CvL = Var("?(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probuds')+bDiscriminator('pfParticleTransformerAK4JetTags:probg'))>0?bDiscriminator('pfParticleTransformerAK4JetTags:probc')/(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probuds')+bDiscriminator('pfParticleTransformerAK4JetTags:probg')):-1",float,doc="RobustParTAK4 c vs uds+g discriminator",precision=10),
108  btagRobustParTAK4CvB = Var("?(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probb')+bDiscriminator('pfParticleTransformerAK4JetTags:probbb')+bDiscriminator('pfParticleTransformerAK4JetTags:problepb'))>0?bDiscriminator('pfParticleTransformerAK4JetTags:probc')/(bDiscriminator('pfParticleTransformerAK4JetTags:probc')+bDiscriminator('pfParticleTransformerAK4JetTags:probb')+bDiscriminator('pfParticleTransformerAK4JetTags:probbb')+bDiscriminator('pfParticleTransformerAK4JetTags:problepb')):-1",float,doc="RobustParTAK4 c vs b+bb+lepb discriminator",precision=10),
109  btagRobustParTAK4QG = Var("?(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),
110  btagPNetB = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:BvsAll')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:BvsAll'):-1",float,precision=10,doc="ParticleNet b vs. udscg"),
111  btagPNetCvL = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsL')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsL'):-1",float,precision=10,doc="ParticleNet c vs. udsg"),
112  btagPNetCvB = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsB')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsB'):-1",float,precision=10,doc="ParticleNet c vs. b"),
113  btagPNetQvG = Var("?abs(eta())<2.5?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:QvsG'):bDiscriminator('pfParticleNetFromMiniAODAK4PuppiForwardDiscriminatorsJetTags:QvsG')",float,precision=10,doc="ParticleNet q (udsbc) vs. g"),
114  btagPNetTauVJet = Var("?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:TauVsJet')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:TauVsJet'):-1",float,precision=10,doc="ParticleNet tau vs. jet"),
115  PNetRegPtRawCorr = Var("?abs(eta())<2.5?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralJetTags:ptcorr'):bDiscriminator('pfParticleNetFromMiniAODAK4PuppiForwardJetTags:ptcorr')",float,precision=10,doc="ParticleNet universal flavor-aware visible pT regression (no neutrinos), correction relative to raw jet pT"),
116  PNetRegPtRawCorrNeutrino = Var("?abs(eta())<2.5?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralJetTags:ptnu'):bDiscriminator('pfParticleNetFromMiniAODAK4PuppiForwardJetTags:ptnu')",float,precision=10,doc="ParticleNet universal flavor-aware pT regression neutrino correction, relative to visible. To apply full regression, multiply raw jet pT by both PNetRegPtRawCorr and PNetRegPtRawCorrNeutrino."),
117  PNetRegPtRawRes = Var("?abs(eta())<2.5?0.5*(bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralJetTags:ptreshigh')-bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralJetTags:ptreslow')):0.5*(bDiscriminator('pfParticleNetFromMiniAODAK4PuppiForwardJetTags:ptreshigh')-bDiscriminator('pfParticleNetFromMiniAODAK4PuppiForwardJetTags:ptreslow'))",float,precision=10,doc="ParticleNet universal flavor-aware jet pT resolution estimator, (q84 - q16)/2"),
118  jetId = Var("userInt('tightId')*2+4*userInt('tightIdLepVeto')", "uint8",doc="Jet ID flag: bit2 is tight, bit3 is tightLepVeto"),
119  hfsigmaEtaEta = Var("userFloat('hfsigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10),
120  hfsigmaPhiPhi = Var("userFloat('hfsigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10),
121  hfcentralEtaStripSize = Var("userInt('hfcentralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable)"),
122  hfadjacentEtaStripsSize = Var("userInt('hfadjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable)"),
123  nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
124  chMultiplicity = Var("chargedMultiplicity()","uint8",doc="(Puppi-weighted) Number of charged particles in the jet"),
125  neMultiplicity = Var("neutralMultiplicity()","uint8",doc="(Puppi-weighted) Number of neutral particles in the jet"),
126  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
127  chHEF = Var("chargedHadronEnergyFraction()", float, doc="charged Hadron Energy Fraction", precision= 6),
128  neHEF = Var("neutralHadronEnergyFraction()", float, doc="neutral Hadron Energy Fraction", precision= 6),
129  chEmEF = Var("chargedEmEnergyFraction()", float, doc="charged Electromagnetic Energy Fraction", precision= 6),
130  neEmEF = Var("neutralEmEnergyFraction()", float, doc="neutral Electromagnetic Energy Fraction", precision= 6),
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  muEF = Var("muonEnergyFraction()", float, doc="muon Energy Fraction", precision= 6),
134  )
135 )
136 
137 run2_nanoAOD_ANY.toModify(
138  jetPuppiTable.variables,
139  btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
140  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),
141  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),
142  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)
143 )
144 
145 (run3_nanoAOD_122 | run3_nanoAOD_124).toModify(
146  jetPuppiTable.variables,
147  # New ParticleNet trainings are not available in MiniAOD until Run3 13X
148  btagPNetB = None,
149  btagPNetCvL = None,
150  btagPNetCvB = None,
151  btagPNetQvG = None,
152  btagPNetTauVJet = None,
153  PNetRegPtRawCorr = None,
154  PNetRegPtRawCorrNeutrino = None,
155  PNetRegPtRawRes = None,
156  # Remove for V11 and earlier Run3 versions
157  chMultiplicity = None,
158  neMultiplicity = None,
159  hfHEF = None,
160  hfEmEF = None
161 )
162 
163 #jets are not as precise as muons
164 jetPuppiTable.variables.pt.precision=10
165 
166 
170 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
171 def nanoAOD_addDeepInfoAK4(process,addParticleNet,addRobustParTAK4=False):
172  _btagDiscriminators=[]
173  if addParticleNet:
174  print("Updating process to run ParticleNetAK4")
175  from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK4_cff import _pfParticleNetFromMiniAODAK4PuppiCentralJetTagsAll as pfParticleNetFromMiniAODAK4PuppiCentralJetTagsAll
176  from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK4_cff import _pfParticleNetFromMiniAODAK4PuppiForwardJetTagsAll as pfParticleNetFromMiniAODAK4PuppiForwardJetTagsAll
177  _btagDiscriminators += pfParticleNetFromMiniAODAK4PuppiCentralJetTagsAll
178  _btagDiscriminators += pfParticleNetFromMiniAODAK4PuppiForwardJetTagsAll
179  if addRobustParTAK4:
180  print("Updating process to run RobustParTAK4")
181  from RecoBTag.ONNXRuntime.pfParticleTransformerAK4_cff import _pfParticleTransformerAK4JetTagsAll as pfParticleTransformerAK4JetTagsAll
182  _btagDiscriminators += pfParticleTransformerAK4JetTagsAll
183  if len(_btagDiscriminators)==0: return process
184  print("Will recalculate the following discriminators: "+", ".join(_btagDiscriminators))
185  updateJetCollection(
186  process,
187  jetSource = cms.InputTag('slimmedJetsPuppi'),
188  jetCorrections = ('AK4PFPuppi', cms.vstring(['L2Relative', 'L3Absolute']), 'None'),
189  btagDiscriminators = _btagDiscriminators,
190  postfix = 'PuppiWithDeepInfo',
191  )
192  process.load("Configuration.StandardSequences.MagneticField_cff")
193  process.jetPuppiCorrFactorsNano.src = "selectedUpdatedPatJetsPuppiWithDeepInfo"
194  process.updatedJetsPuppi.jetSource = "selectedUpdatedPatJetsPuppiWithDeepInfo"
195  return process
196 
197 nanoAOD_addDeepInfoAK4_switch = cms.PSet(
198  nanoAOD_addParticleNet_switch = cms.untracked.bool(False),
199  nanoAOD_addRobustParTAK4Tag_switch = cms.untracked.bool(False)
200 )
201 
202 
205 
206 
209 basicJetsPuppiForMetForT1METNano = cms.EDProducer("PATJetCleanerForType1MET",
210  src = updatedJetsPuppiWithUserData.src,
211  jetCorrEtaMax = cms.double(9.9),
212  jetCorrLabel = cms.InputTag("L3Absolute"),
213  jetCorrLabelRes = cms.InputTag("L2L3Residual"),
214  offsetCorrLabel = cms.InputTag("L1FastJet"),
215  skipEM = cms.bool(False),
216  skipEMfractionThreshold = cms.double(0.9),
217  skipMuonSelection = cms.string('isGlobalMuon | isStandAloneMuon'),
218  skipMuons = cms.bool(True),
219  type1JetPtThreshold = cms.double(0.0),
220  calcMuonSubtrRawPtAsValueMap = cms.bool(True)
221 )
222 
223 updatedJetsPuppiWithUserData.userFloats.muonSubtrRawPt = cms.InputTag("basicJetsPuppiForMetForT1METNano:MuonSubtrRawPt")
224 
225 corrT1METJetPuppiTable = simpleCandidateFlatTableProducer.clone(
226  src = finalJetsPuppi.src,
227  cut = cms.string("pt<15 && abs(eta)<9.9"),
228  name = cms.string("CorrT1METJet"),
229  doc = cms.string("Additional low-pt ak4 Puppi jets for Type-1 MET re-correction"),
230  variables = cms.PSet(
231  rawPt = Var("pt()*jecFactor('Uncorrected')",float,precision=10),
232  eta = Var("eta", float,precision=12),
233  phi = Var("phi", float, precision=12),
234  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
235  EmEF = Var("chargedEmEnergyFraction()+neutralEmEnergyFraction()", float, doc="charged+neutral Electromagnetic Energy Fraction", precision=6),
236  )
237 )
238 
239 corrT1METJetPuppiTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
240 jetPuppiTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
241 
242 jetPuppiForMETTask = cms.Task(basicJetsPuppiForMetForT1METNano,corrT1METJetPuppiTable)
243 
244 #before cross linking
245 jetPuppiUserDataTask = cms.Task(tightJetPuppiId, tightJetPuppiIdLepVeto, hfJetPuppiShowerShapeforNanoAOD)
246 
247 #before cross linking
248 jetPuppiTask = cms.Task(jetPuppiCorrFactorsNano,updatedJetsPuppi,jetPuppiUserDataTask,updatedJetsPuppiWithUserData,finalJetsPuppi)
249 
250 #after cross linkining
251 jetPuppiTablesTask = cms.Task(jetPuppiTable)
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
def nanoAOD_addDeepInfoAK4(process, addParticleNet, addRobustParTAK4=False)
User floats producers, selectors ##########################.
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19