CMS 3D CMS Logo

jets_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
3 
5 
6 
7 
8 ##################### User floats producers, selectors ##########################
9 from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets
10 
11 chsForSATkJets = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string('charge()!=0 && pvAssociationQuality()>=5 && vertexRef().key()==0'))
12 softActivityJets = ak4PFJets.clone(src = 'chsForSATkJets', doAreaFastjet = False, jetPtMin=1)
13 softActivityJets10 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>10'))
14 softActivityJets5 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>5'))
15 softActivityJets2 = cms.EDFilter("CandPtrSelector", src = cms.InputTag("chsForSATkJets"), cut = cms.string('pt>2'))
16 
17 looseJetId = cms.EDProducer("PatJetIDValueMapProducer",
18  filterParams=cms.PSet(
19  version = cms.string('WINTER16'),
20  quality = cms.string('LOOSE'),
21  ),
22  src = cms.InputTag("slimmedJets")
23 )
24 tightJetId = cms.EDProducer("PatJetIDValueMapProducer",
25  filterParams=cms.PSet(
26  version = cms.string('WINTER16'),
27  quality = cms.string('TIGHT'),
28  ),
29  src = cms.InputTag("slimmedJets")
30 )
31 
32 
33 slimmedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder",
34  src = cms.InputTag("slimmedJets"),
35  userInts = cms.PSet(
36  tightId = cms.InputTag("tightJetId"),
37  looseId = cms.InputTag("looseJetId"),
38  ),
39 )
40 
41 
43 jetCorrFactors = patJetCorrFactors.clone(src='slimmedJetsWithUserData',
44  levels = cms.vstring('L1FastJet',
45  'L2Relative',
46  'L3Absolute',
47  'L2L3Residual'),
48  primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
49 )
51 updatedJets = updatedPatJets.clone(
52  addBTagInfo=False,
53  jetSource='slimmedJetsWithUserData',
54  jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactors") ),
55 )
56 
57 finalJets = cms.EDFilter("PATJetRefSelector",
58  src = cms.InputTag("updatedJets"),
59  cut = cms.string("pt > 15")
60 )
61 
62 
63 
64 
65 ##################### Tables for final output and docs ##########################
66 
67 
68 
69 jetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
70  src = cms.InputTag("linkedObjects","jets"),
71  cut = cms.string(""), #we should not filter on cross linked collections
72  name = cms.string("Jet"),
73  doc = cms.string("slimmedJets, i.e. ak4 PFJets CHS with JECs applied, after basic selection (" + finalJets.cut.value()+")"),
74  singleton = cms.bool(False), # the number of entries is variable
75  extension = cms.bool(False), # this is the main table for the jets
76  externalVariables = cms.PSet(
77  bReg = ExtVar(cms.InputTag("bjetMVA"),float, doc="pt corrected with b-jet regression",precision=14),
78  ),
79  variables = cms.PSet(P4Vars,
80  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
81  nMuons = Var("?hasOverlaps('muons')?overlaps('muons').size():0", int, doc="number of muons in the jet"),
82  muonIdx1 = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", int, doc="index of first matching muon"),
83  muonIdx2 = Var("?overlaps('muons').size()>1?overlaps('muons')[1].key():-1", int, doc="index of second matching muon"),
84  electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"),
85  electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"),
86  nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"),
87  btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
88  btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="DeepCSV b tag discriminator",precision=10),
89  btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV bb tag discriminator",precision=10),
90  btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="DeepCSV charm btag discriminator",precision=10),
91 #puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pilup ID discriminant",precision=10),
92  puId = Var("userInt('pileupJetId:fullId')",int,doc="Pilup ID flags"),
93  jetId = Var("userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight"),
94  qgl = Var("userFloat('QGTagger:qgLikelihood')",float,doc="Quark vs Gluon likelihood discriminator",precision=10),
95  nConstituents = Var("numberOfDaughters()",int,doc="Number of particles in the jet"),
96  rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
97  chHEF = Var("chargedHadronEnergy()/energy()", float, doc="charged Hadron Energy Fraction", precision= 6),
98  neHEF = Var("neutralHadronEnergy()/energy()", float, doc="neutral Hadron Energy Fraction", precision= 6),
99  chEmEF = Var("chargedEmEnergy()/energy()", float, doc="charged Electromagnetic Energy Fraction", precision= 6),
100  neEmEF = Var("neutralEmEnergy()/energy()", float, doc="charged Electromagnetic EnergyFraction", precision= 6),
101 
102  )
103 )
104 #jets are not as precise as muons
105 jetTable.variables.pt.precision=10
106 
107 ### Era dependent customization
108 run2_miniAOD_80XLegacy.toModify( jetTable.variables.qgl, expr="-1" )
109 
110 bjetMVA= cms.EDProducer("BJetEnergyRegressionMVA",
111  src = cms.InputTag("linkedObjects","jets"),
112  pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
113  svsrc = cms.InputTag("slimmedSecondaryVertices"),
114  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/bjet-regression.xml"),
115  name = cms.string("JetReg"),
116  isClassifier = cms.bool(False),
117  variablesOrder = cms.vstring(["Jet_pt","nPVs","Jet_eta","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonPt","Jet_leptonDeltaR","Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL"]),
118  variables = cms.PSet(
119  Jet_pt = cms.string("pt"),
120  Jet_eta = cms.string("eta"),
121  Jet_mt = cms.string("mt"),
122  Jet_leptonPt = cms.string("?overlaps('muons').size()>0?overlaps('muons')[0].pt():(?overlaps('electrons').size()>0?overlaps('electrons')[0].pt():0)"),
123  Jet_neHEF = cms.string("neutralHadronEnergy()/energy()"),
124  Jet_neEmEF = cms.string("neutralEmEnergy()/energy()"),
125  Jet_leptonDeltaR = cms.string('''?overlaps('muons').size()>0?deltaR(eta,phi,overlaps('muons')[0].eta,overlaps('muons')[0].phi):
126  (?overlaps('electrons').size()>0?deltaR(eta,phi,overlaps('electrons')[0].eta,overlaps('electrons')[0].phi):
127  0)'''),
128  )
129 
130 )
131 
132 ##### Soft Activity tables
133 saJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
134  src = cms.InputTag("softActivityJets"),
135  cut = cms.string(""),
136  maxLen = cms.uint32(6),
137  name = cms.string("SoftActivityJet"),
138  doc = cms.string("jets clustered from charged candidates compatible with primary vertex (" + chsForSATkJets.cut.value()+")"),
139  singleton = cms.bool(False), # the number of entries is variable
140  extension = cms.bool(False), # this is the main table for the jets
141  variables = cms.PSet(P3Vars,
142  )
143 )
144 
145 saJetTable.variables.pt.precision=10
146 saJetTable.variables.eta.precision=8
147 saJetTable.variables.phi.precision=8
148 
149 saTable = cms.EDProducer("GlobalVariablesTableProducer",
150  variables = cms.PSet(
151  SoftActivityJetHT = ExtVar( cms.InputTag("softActivityJets"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt>1" ),
152  SoftActivityJetHT10 = ExtVar( cms.InputTag("softActivityJets10"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt , pt >10" ),
153  SoftActivityJetHT5 = ExtVar( cms.InputTag("softActivityJets5"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt>5" ),
154  SoftActivityJetHT2 = ExtVar( cms.InputTag("softActivityJets2"), "candidatescalarsum", doc = "scalar sum of soft activity jet pt, pt >2" ),
155  SoftActivityJetNjets10 = ExtVar( cms.InputTag("softActivityJets10"), "candidatesize", doc = "number of soft activity jet pt, pt >2" ),
156  SoftActivityJetNjets5 = ExtVar( cms.InputTag("softActivityJets5"), "candidatesize", doc = "number of soft activity jet pt, pt >5" ),
157  SoftActivityJetNjets2 = ExtVar( cms.InputTag("softActivityJets2"), "candidatesize", doc = "number of soft activity jet pt, pt >10" ),
158 
159  )
160 )
161 
162 
163 
164 ## BOOSTED STUFF #################
165 fatJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
166  src = cms.InputTag("slimmedJetsAK8"),
167  cut = cms.string(" pt > 170"), #probably already applied in miniaod
168  name = cms.string("FatJet"),
169  doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
170  singleton = cms.bool(False), # the number of entries is variable
171  extension = cms.bool(False), # this is the main table for the jets
172  variables = cms.PSet(P4Vars,
173  area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
174  tau1 = Var("userFloat('ak8PFJetsCHSValueMap:NjettinessAK8CHSTau1')",float, doc="Nsubjettiness (1 axis)",precision=10),
175  tau2 = Var("userFloat('ak8PFJetsCHSValueMap:NjettinessAK8CHSTau2')",float, doc="Nsubjettiness (2 axis)",precision=10),
176  tau3 = Var("userFloat('ak8PFJetsCHSValueMap:NjettinessAK8CHSTau3')",float, doc="Nsubjettiness (3 axis)",precision=10),
177  msoftdrop = Var("userFloat('ak8PFJetsCHSValueMap:ak8PFJetsCHSSoftDropMass')",float, doc="Soft drop mass",precision=10),
178  mpruned = Var("userFloat('ak8PFJetsCHSValueMap:ak8PFJetsCHSPrunedMass')", float, doc="Pruned mass",precision=10),
179 
180  btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
181  btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="DeepCSV B btag discriminator",precision=10),
182  btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV BB btag discriminator",precision=10),
183  btagHbb = Var("bDiscriminator('pfBoostedDoubleSecondaryVertexAK8BJetTags')",float,doc="Higgs to BB tagger discriminator",precision=10),
184 
185  subJetIdx1 = Var("?numberOfSourceCandidatePtrs()>0 && sourceCandidatePtr(0).numberOfSourceCandidatePtrs()>0?sourceCandidatePtr(0).key():-1", int,
186  doc="index of first subjet"),
187  subJetIdx2 = Var("?numberOfSourceCandidatePtrs()>1 && sourceCandidatePtr(1).numberOfSourceCandidatePtrs()>0?sourceCandidatePtr(1).key():-1", int,
188  doc="index of second subjet"),
189  subJetIdx3 = Var("?numberOfSourceCandidatePtrs()>2 && sourceCandidatePtr(2).numberOfSourceCandidatePtrs()>0?sourceCandidatePtr(2).key():-1", int,
190  doc="index of third subjet"),
191 
192 # btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="CMVA V2 btag discriminator",precision=10),
193 #puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pilup ID discriminant",precision=10),
194 # nConstituents = Var("numberOfDaughters()",int,doc="Number of particles in the jet"),
195 # rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
196  )
197 )
198 ### Era dependent customization
199 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.mpruned, expr = cms.string("userFloat(\'ak8PFJetsCHSPrunedMass\')"),)
200 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.msoftdrop, expr = cms.string("userFloat(\'ak8PFJetsCHSSoftDropMass\')"),)
201 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau1, expr = cms.string("userFloat(\'NjettinessAK8:tau1\')"),)
202 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau2, expr = cms.string("userFloat(\'NjettinessAK8:tau2\')"),)
203 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau3, expr = cms.string("userFloat(\'NjettinessAK8:tau3\')"),)
204 
205 subJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
206  src = cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked","SubJets"),
207  cut = cms.string(""), #probably already applied in miniaod
208  name = cms.string("SubJet"),
209  doc = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
210  singleton = cms.bool(False), # the number of entries is variable
211  extension = cms.bool(False), # this is the main table for the jets
212  variables = cms.PSet(P4Vars,
213  btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
214  btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')",float,doc="CMVA V2 btag discriminator",precision=10),
215  btagDeepBB = Var("bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="CMVA V2 btag discriminator",precision=10),
216  )
217 )
218 
219 #jets are not as precise as muons
220 fatJetTable.variables.pt.precision=10
221 
222 
223 
224 
225 
226 
227 
228 ## MC STUFF ######################
229 jetMCTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
230  src = cms.InputTag("linkedObjects","jets"),
231  cut = cms.string(""), #we should not filter on cross linked collections
232  name = cms.string("Jet"),
233  singleton = cms.bool(False), # the number of entries is variable
234  extension = cms.bool(True), # this is an extension table for the jets
235  variables = cms.PSet(
236  partonFlavour = Var("partonFlavour()", int, doc="flavour from parton matching"),
237  hadronFlavour = Var("hadronFlavour()", int, doc="flavour from hadron ghost clustering"),
238  genJetIdx = Var("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().key():-1", int, doc="index of matched gen jet"),
239  )
240 )
241 genJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
242  src = cms.InputTag("slimmedGenJets"),
243  cut = cms.string("pt > 10"),
244  name = cms.string("GenJet"),
245  doc = cms.string("slimmedGenJets, i.e. ak4 Jets made with visible genparticles"),
246  singleton = cms.bool(False), # the number of entries is variable
247  extension = cms.bool(False), # this is the main table for the genjets
248  variables = cms.PSet(P4Vars,
249  #anything else?
250  )
251 )
252 
253 
254 
255 #before cross linking
256 jetSequence = cms.Sequence(looseJetId+tightJetId+slimmedJetsWithUserData+jetCorrFactors+updatedJets+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets)
257 #after cross linkining
258 jetTables = cms.Sequence(bjetMVA+ jetTable+fatJetTable+subJetTable+saJetTable+saTable)
259 
260 #MC only producers and tables
261 jetMC = cms.Sequence(jetMCTable+genJetTable)
262 
def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:31
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20