1 import FWCore.ParameterSet.Config
as cms
5 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi
import simpleCandidateFlatTableProducer
12 jetPuppiCorrFactorsNano = patJetCorrFactors.clone(src=
'slimmedJetsPuppi',
13 levels = cms.vstring(
'L1FastJet',
17 payload = cms.string(
'AK4PFPuppi'),
18 primaryVertices = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
23 updatedJetsPuppi = updatedPatJets.clone(
25 jetSource=
'slimmedJetsPuppi',
26 jetCorrFactorsSource=cms.VInputTag(cms.InputTag(
"jetPuppiCorrFactorsNano") ),
29 tightJetPuppiId = cms.EDProducer(
"PatJetIDValueMapProducer",
30 filterParams=cms.PSet(
31 version = cms.string(
'RUN3WINTER22PUPPI'),
32 quality = cms.string(
'TIGHT'),
34 src = cms.InputTag(
"updatedJetsPuppi")
36 tightJetPuppiIdLepVeto = cms.EDProducer(
"PatJetIDValueMapProducer",
37 filterParams=cms.PSet(
38 version = cms.string(
'RUN3WINTER22PUPPI'),
39 quality = cms.string(
'TIGHTLEPVETO'),
41 src = cms.InputTag(
"updatedJetsPuppi")
45 from RecoJets.JetProducers.hfJetShowerShape_cfi
import hfJetShowerShape
46 hfJetPuppiShowerShapeforNanoAOD = hfJetShowerShape.clone(jets=
"updatedJetsPuppi",vertices=
"offlineSlimmedPrimaryVertices")
48 updatedJetsPuppiWithUserData = cms.EDProducer(
"PATJetUserDataEmbedder",
49 src = cms.InputTag(
"updatedJetsPuppi"),
50 userFloats = cms.PSet(
51 hfsigmaEtaEta = cms.InputTag(
'hfJetPuppiShowerShapeforNanoAOD:sigmaEtaEta'),
52 hfsigmaPhiPhi = cms.InputTag(
'hfJetPuppiShowerShapeforNanoAOD:sigmaPhiPhi'),
55 tightId = cms.InputTag(
"tightJetPuppiId"),
56 tightIdLepVeto = cms.InputTag(
"tightJetPuppiIdLepVeto"),
57 hfcentralEtaStripSize = cms.InputTag(
'hfJetPuppiShowerShapeforNanoAOD:centralEtaStripSize'),
58 hfadjacentEtaStripsSize = cms.InputTag(
'hfJetPuppiShowerShapeforNanoAOD:adjacentEtaStripsSize'),
62 finalJetsPuppi = cms.EDFilter(
"PATJetRefSelector",
63 src = cms.InputTag(
"updatedJetsPuppiWithUserData"),
64 cut = cms.string(
"pt > 15")
68 jetPuppiTable = simpleCandidateFlatTableProducer.clone(
69 src = cms.InputTag(
"linkedObjects",
"jets"),
70 name = cms.string(
"Jet"),
71 doc = cms.string(
"slimmedJetsPuppi, i.e. ak4 PFJets Puppi with JECs applied, after basic selection (" + finalJetsPuppi.cut.value()+
")"),
72 externalVariables = cms.PSet(),
73 variables = cms.PSet(P4Vars,
74 area =
Var(
"jetArea()", float, doc=
"jet catchment area, for JECs",precision=10),
75 nMuons =
Var(
"?hasOverlaps('muons')?overlaps('muons').size():0",
"uint8", doc=
"number of muons in the jet"),
76 muonIdx1 =
Var(
"?overlaps('muons').size()>0?overlaps('muons')[0].key():-1",
"int16", doc=
"index of first matching muon"),
77 muonIdx2 =
Var(
"?overlaps('muons').size()>1?overlaps('muons')[1].key():-1",
"int16", doc=
"index of second matching muon"),
78 electronIdx1 =
Var(
"?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1",
"int16", doc=
"index of first matching electron"),
79 electronIdx2 =
Var(
"?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1",
"int16", doc=
"index of second matching electron"),
80 nElectrons =
Var(
"?hasOverlaps('electrons')?overlaps('electrons').size():0",
"uint8", doc=
"number of electrons in the jet"),
81 svIdx1 =
Var(
"?overlaps('vertices').size()>0?overlaps('vertices')[0].key():-1",
"int16", doc=
"index of first matching secondary vertex"),
82 svIdx2 =
Var(
"?overlaps('vertices').size()>1?overlaps('vertices')[1].key():-1",
"int16", doc=
"index of second matching secondary vertex"),
83 nSVs =
Var(
"?hasOverlaps('vertices')?overlaps('vertices').size():0",
"uint8", doc=
"number of secondary vertices in the jet"),
84 btagDeepFlavB =
Var(
"bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc=
"DeepJet b+bb+lepb tag discriminator",precision=10),
85 btagRobustParTAK4B =
Var(
"bDiscriminator('pfParticleTransformerAK4JetTags:probb')+bDiscriminator('pfParticleTransformerAK4JetTags:probbb')+bDiscriminator('pfParticleTransformerAK4JetTags:problepb')",float,doc=
"RobustParTAK4 b+bb+lepb tag discriminator",precision=10),
86 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),
87 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),
88 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),
89 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),
90 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),
91 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),
92 btagPNetB =
Var(
"?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:BvsAll')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:BvsAll'):-1",float,precision=10,doc=
"ParticleNet b vs. udscg"),
93 btagPNetCvL =
Var(
"?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsL')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsL'):-1",float,precision=10,doc=
"ParticleNet c vs. udsg"),
94 btagPNetCvB =
Var(
"?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsB')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:CvsB'):-1",float,precision=10,doc=
"ParticleNet c vs. b"),
95 btagPNetQvG =
Var(
"?abs(eta())<2.5?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:QvsG'):bDiscriminator('pfParticleNetFromMiniAODAK4PuppiForwardDiscriminatorsJetTags:QvsG')",float,precision=10,doc=
"ParticleNet q (udsbc) vs. g"),
96 btagPNetTauVJet =
Var(
"?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:TauVsJet')>0?bDiscriminator('pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags:TauVsJet'):-1",float,precision=10,doc=
"ParticleNet tau vs. jet"),
97 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"),
98 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."),
99 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"),
100 jetId =
Var(
"userInt('tightId')*2+4*userInt('tightIdLepVeto')",
"uint8",doc=
"Jet ID flag: bit2 is tight, bit3 is tightLepVeto"),
101 hfsigmaEtaEta =
Var(
"userFloat('hfsigmaEtaEta')",float,doc=
"sigmaEtaEta for HF jets (noise discriminating variable)",precision=10),
102 hfsigmaPhiPhi =
Var(
"userFloat('hfsigmaPhiPhi')",float,doc=
"sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10),
103 hfcentralEtaStripSize =
Var(
"userInt('hfcentralEtaStripSize')", int, doc=
"eta size of the central tower strip in HF (noise discriminating variable)"),
104 hfadjacentEtaStripsSize =
Var(
"userInt('hfadjacentEtaStripsSize')", int, doc=
"eta size of the strips next to the central tower strip in HF (noise discriminating variable)"),
105 nConstituents =
Var(
"numberOfDaughters()",
"uint8",doc=
"Number of particles in the jet"),
106 rawFactor =
Var(
"1.-jecFactor('Uncorrected')",float,doc=
"1 - Factor to get back to raw pT",precision=6),
107 chHEF =
Var(
"chargedHadronEnergyFraction()", float, doc=
"charged Hadron Energy Fraction", precision= 6),
108 neHEF =
Var(
"neutralHadronEnergyFraction()", float, doc=
"neutral Hadron Energy Fraction", precision= 6),
109 chEmEF =
Var(
"chargedEmEnergyFraction()", float, doc=
"charged Electromagnetic Energy Fraction", precision= 6),
110 neEmEF =
Var(
"neutralEmEnergyFraction()", float, doc=
"neutral Electromagnetic Energy Fraction", precision= 6),
111 muEF =
Var(
"muonEnergyFraction()", float, doc=
"muon Energy Fraction", precision= 6),
115 run2_nanoAOD_ANY.toModify(
116 jetPuppiTable.variables,
117 btagCSVV2 =
Var(
"bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=
" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
118 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),
119 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),
120 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)
123 (run3_nanoAOD_122 | run3_nanoAOD_124).toModify(
125 jetPuppiTable.variables,
130 btagPNetTauVJet =
None,
131 PNetRegPtRawCorr =
None,
132 PNetRegPtRawCorrNeutrino =
None,
133 PNetRegPtRawRes =
None,
137 jetPuppiTable.variables.pt.precision=10
145 _btagDiscriminators=[]
147 print(
"Updating process to run ParticleNetAK4")
148 from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK4_cff
import _pfParticleNetFromMiniAODAK4PuppiCentralJetTagsAll
as pfParticleNetFromMiniAODAK4PuppiCentralJetTagsAll
149 from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK4_cff
import _pfParticleNetFromMiniAODAK4PuppiForwardJetTagsAll
as pfParticleNetFromMiniAODAK4PuppiForwardJetTagsAll
150 _btagDiscriminators += pfParticleNetFromMiniAODAK4PuppiCentralJetTagsAll
151 _btagDiscriminators += pfParticleNetFromMiniAODAK4PuppiForwardJetTagsAll
153 print(
"Updating process to run RobustParTAK4")
155 _btagDiscriminators += pfParticleTransformerAK4JetTagsAll
157 if len(_btagDiscriminators)==0:
return process
158 print(
"Will recalculate the following discriminators: "+
", ".
join(_btagDiscriminators))
161 jetSource = cms.InputTag(
'slimmedJetsPuppi'),
162 jetCorrections = (
'AK4PFPuppi', cms.vstring([
'L2Relative',
'L3Absolute']),
'None'),
163 btagDiscriminators = _btagDiscriminators,
164 postfix =
'PuppiWithDeepInfo',
166 process.load(
"Configuration.StandardSequences.MagneticField_cff")
167 process.jetPuppiCorrFactorsNano.src =
"selectedUpdatedPatJetsPuppiWithDeepInfo" 168 process.updatedJetsPuppi.jetSource =
"selectedUpdatedPatJetsPuppiWithDeepInfo" 171 nanoAOD_addDeepInfoAK4_switch = cms.PSet(
172 nanoAOD_addParticleNet_switch = cms.untracked.bool(
False),
173 nanoAOD_addRobustParTAK4Tag_switch = cms.untracked.bool(
False)
183 basicJetsPuppiForMetForT1METNano = cms.EDProducer(
"PATJetCleanerForType1MET",
184 src = updatedJetsPuppiWithUserData.src,
185 jetCorrEtaMax = cms.double(9.9),
186 jetCorrLabel = cms.InputTag(
"L3Absolute"),
187 jetCorrLabelRes = cms.InputTag(
"L2L3Residual"),
188 offsetCorrLabel = cms.InputTag(
"L1FastJet"),
189 skipEM = cms.bool(
False),
190 skipEMfractionThreshold = cms.double(0.9),
191 skipMuonSelection = cms.string(
'isGlobalMuon | isStandAloneMuon'),
192 skipMuons = cms.bool(
True),
193 type1JetPtThreshold = cms.double(0.0),
194 calcMuonSubtrRawPtAsValueMap = cms.bool(
True)
197 updatedJetsPuppiWithUserData.userFloats.muonSubtrRawPt = cms.InputTag(
"basicJetsPuppiForMetForT1METNano:MuonSubtrRawPt")
199 corrT1METJetPuppiTable = simpleCandidateFlatTableProducer.clone(
200 src = finalJetsPuppi.src,
201 cut = cms.string(
"pt<15 && abs(eta)<9.9"),
202 name = cms.string(
"CorrT1METJet"),
203 doc = cms.string(
"Additional low-pt ak4 Puppi jets for Type-1 MET re-correction"),
204 variables = cms.PSet(
205 rawPt =
Var(
"pt()*jecFactor('Uncorrected')",float,precision=10),
206 eta =
Var(
"eta", float,precision=12),
207 phi =
Var(
"phi", float, precision=12),
208 area =
Var(
"jetArea()", float, doc=
"jet catchment area, for JECs",precision=10),
212 corrT1METJetPuppiTable.variables.muonSubtrFactor =
Var(
"1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc=
"1-(muon-subtracted raw pt)/(raw pt)",precision=6)
213 jetPuppiTable.variables.muonSubtrFactor =
Var(
"1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc=
"1-(muon-subtracted raw pt)/(raw pt)",precision=6)
215 jetPuppiForMETTask = cms.Task(basicJetsPuppiForMetForT1METNano,corrT1METJetPuppiTable)
218 jetPuppiUserDataTask = cms.Task(tightJetPuppiId, tightJetPuppiIdLepVeto, hfJetPuppiShowerShapeforNanoAOD)
221 jetPuppiTask = cms.Task(jetPuppiCorrFactorsNano,updatedJetsPuppi,jetPuppiUserDataTask,updatedJetsPuppiWithUserData,finalJetsPuppi)
224 jetPuppiTablesTask = cms.Task(jetPuppiTable)
def Var(expr, valtype, doc=None, precision=-1)
def nanoAOD_addDeepInfoAK4(process, addParticleNet, addRobustParTAK4=False)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
static std::string join(char **cmd)