1 import FWCore.ParameterSet.Config
as cms
5 from PhysicsTools.NanoAOD.simplePATMuonFlatTableProducer_cfi
import simplePATMuonFlatTableProducer
10 slimmedMuonsUpdated = cms.EDProducer(
"PATMuonUpdater",
11 src = cms.InputTag(
"slimmedMuons"),
12 vertices = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
13 computeMiniIso = cms.bool(
False),
14 fixDxySign = cms.bool(
True),
15 pfCandsForMiniIso = cms.InputTag(
"packedPFCandidates"),
16 miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams,
17 recomputeMuonBasicSelectors = cms.bool(
False),
20 isoForMu = cms.EDProducer(
"MuonIsoValueMapProducer",
21 src = cms.InputTag(
"slimmedMuonsUpdated"),
22 relative = cms.bool(
False),
23 rho_MiniIso = cms.InputTag(
"fixedGridRhoFastjetAll"),
24 EAFile_MiniIso = cms.FileInPath(
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
27 ptRatioRelForMu = cms.EDProducer(
"MuonJetVarProducer",
28 srcJet = cms.InputTag(
"updatedJetsPuppi"),
29 srcLep = cms.InputTag(
"slimmedMuonsUpdated"),
30 srcVtx = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
33 muonMVAID = cms.EDProducer(
"EvaluateMuonMVAID",
34 src = cms.InputTag(
"slimmedMuonsUpdated"),
35 weightFile = cms.FileInPath(
"RecoMuon/MuonIdentification/data/mvaID.onnx"),
36 backend = cms.string(
'ONNX'),
37 name = cms.string(
"muonMVAID"),
38 outputTensorName= cms.string(
"probabilities"),
39 inputTensorName= cms.string(
"float_input"),
40 outputNames = cms.vstring([
"probGOOD",
"wpMedium",
"wpTight"]),
41 batch_eval =cms.bool(
True),
42 outputFormulas = cms.vstring([
"at(1)",
"? at(1) > 0.08 ? 1 : 0",
"? at(1) > 0.20 ? 1 : 0"]),
43 variables = cms.VPSet(
44 cms.PSet( name = cms.string(
"LepGood_global_muon"), expr = cms.string(
"isGlobalMuon")),
45 cms.PSet( name = cms.string(
"LepGood_validFraction"), expr = cms.string(
"?innerTrack.isNonnull?innerTrack().validFraction:-99")),
46 cms.PSet( name = cms.string(
"Muon_norm_chi2_extended")),
47 cms.PSet( name = cms.string(
"LepGood_local_chi2"), expr = cms.string(
"combinedQuality().chi2LocalPosition")),
48 cms.PSet( name = cms.string(
"LepGood_kink"), expr = cms.string(
"combinedQuality().trkKink")),
49 cms.PSet( name = cms.string(
"LepGood_segmentComp"), expr = cms.string(
"segmentCompatibility")),
50 cms.PSet( name = cms.string(
"Muon_n_Valid_hits_extended")),
51 cms.PSet( name = cms.string(
"LepGood_n_MatchedStations"), expr = cms.string(
"numberOfMatchedStations()")),
52 cms.PSet( name = cms.string(
"LepGood_Valid_pixel"), expr = cms.string(
"?innerTrack.isNonnull()?innerTrack().hitPattern().numberOfValidPixelHits():-99")),
53 cms.PSet( name = cms.string(
"LepGood_tracker_layers"), expr = cms.string(
"?innerTrack.isNonnull()?innerTrack().hitPattern().trackerLayersWithMeasurement():-99")),
54 cms.PSet( name = cms.string(
"LepGood_pt"), expr = cms.string(
"pt")),
55 cms.PSet( name = cms.string(
"LepGood_eta"), expr = cms.string(
"eta")),
64 slimmedMuonsWithUserData = cms.EDProducer(
"PATMuonUserDataEmbedder",
65 src = cms.InputTag(
"slimmedMuonsUpdated"),
66 userFloats = cms.PSet(
67 miniIsoChg = cms.InputTag(
"isoForMu:miniIsoChg"),
68 miniIsoAll = cms.InputTag(
"isoForMu:miniIsoAll"),
69 ptRatio = cms.InputTag(
"ptRatioRelForMu:ptRatio"),
70 ptRel = cms.InputTag(
"ptRatioRelForMu:ptRel"),
71 jetNDauChargedMVASel = cms.InputTag(
"ptRatioRelForMu:jetNDauChargedMVASel"),
72 mvaIDMuon_wpMedium = cms.InputTag(
"muonMVAID:wpMedium"),
73 mvaIDMuon_wpTight = cms.InputTag(
"muonMVAID:wpTight"),
74 mvaIDMuon = cms.InputTag(
"muonMVAID:probGOOD")
77 jetForLepJetVar = cms.InputTag(
"ptRatioRelForMu:jetForLepJetVar")
82 finalMuons = cms.EDFilter(
"PATMuonRefSelector",
83 src = cms.InputTag(
"slimmedMuonsWithUserData"),
84 cut = cms.string(
"pt > 15 || (pt > 3 && (passed('CutBasedIdLoose') || passed('SoftCutBasedId') || passed('SoftMvaId') || passed('CutBasedIdGlobalHighPt') || passed('CutBasedIdTrkHighPt')))")
87 finalLooseMuons = cms.EDFilter(
"PATMuonRefSelector",
88 src = cms.InputTag(
"slimmedMuonsWithUserData"),
89 cut = cms.string(
"pt > 3 && track.isNonnull && isLooseMuon")
92 muonPROMPTMVA= cms.EDProducer(
"MuonBaseMVAValueMapProducer",
93 src = cms.InputTag(
"linkedObjects",
"muons"),
94 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_2022.weights.xml"),
95 backend = cms.string(
"TMVA"),
96 name = cms.string(
"muonPROMPTMVA"),
97 isClassifier = cms.bool(
True),
98 variables = cms.VPSet(
99 cms.PSet( name = cms.string(
"LepGood_pt"), expr = cms.string(
"pt")),
100 cms.PSet( name = cms.string(
"LepGood_eta"), expr = cms.string(
"eta")),
101 cms.PSet( name = cms.string(
"LepGood_pfRelIso03_all"), expr = cms.string(
"(pfIsolationR03().sumChargedHadronPt + max(pfIsolationR03().sumNeutralHadronEt + pfIsolationR03().sumPhotonEt - pfIsolationR03().sumPUPt/2,0.0))/pt")),
102 cms.PSet( name = cms.string(
"LepGood_miniRelIsoCharged"), expr = cms.string(
"userFloat('miniIsoChg')/pt")),
103 cms.PSet( name = cms.string(
"LepGood_miniRelIsoNeutral"), expr = cms.string(
"(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt")),
104 cms.PSet( name = cms.string(
"LepGood_jetNDauChargedMVASel"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0")),
105 cms.PSet( name = cms.string(
"LepGood_jetPtRelv2"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0")),
106 cms.PSet( name = cms.string(
"LepGood_jetDF"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0")),
107 cms.PSet( name = cms.string(
"LepGood_jetPtRatio"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt)")),
108 cms.PSet( name = cms.string(
"LepGood_sip3d"), expr = cms.string(
"abs(dB('PV3D')/edB('PV3D'))")),
109 cms.PSet( name = cms.string(
"LepGood_dxy"), expr = cms.string(
"log(abs(dB('PV2D')))")),
110 cms.PSet( name = cms.string(
"LepGood_dz"), expr = cms.string(
"log(abs(dB('PVDZ')))")),
111 cms.PSet( name = cms.string(
"LepGood_segmentComp"), expr = cms.string(
"segmentCompatibility")),
115 _legacy_muon_BDT_variable = cms.VPSet(
116 cms.PSet( name = cms.string(
"LepGood_pt"), expr = cms.string(
"pt")),
117 cms.PSet( name = cms.string(
"LepGood_eta"), expr = cms.string(
"eta")),
118 cms.PSet( name = cms.string(
"LepGood_jetNDauChargedMVASel"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0")),
119 cms.PSet( name = cms.string(
"LepGood_miniRelIsoCharged"), expr = cms.string(
"userFloat('miniIsoChg')/pt")),
120 cms.PSet( name = cms.string(
"LepGood_miniRelIsoNeutral"), expr = cms.string(
"(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt")),
121 cms.PSet( name = cms.string(
"LepGood_jetPtRelv2"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0")),
122 cms.PSet( name = cms.string(
"LepGood_jetDF"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0")),
123 cms.PSet( name = cms.string(
"LepGood_jetPtRatio"), expr = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt)")),
124 cms.PSet( name = cms.string(
"LepGood_dxy"), expr = cms.string(
"log(abs(dB('PV2D')))")),
125 cms.PSet( name = cms.string(
"LepGood_sip3d"), expr = cms.string(
"abs(dB('PV3D')/edB('PV3D'))")),
126 cms.PSet( name = cms.string(
"LepGood_dz"), expr = cms.string(
"log(abs(dB('PVDZ')))")),
127 cms.PSet( name = cms.string(
"LepGood_segmentComp"), expr = cms.string(
"segmentCompatibility")),
130 muonMVALowPt = muonPROMPTMVA.clone(
131 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_lowpt.weights.xml"),
132 name = cms.string(
"muonMVALowPt"),
133 variables = _legacy_muon_BDT_variable
136 run2_muon_2016.toModify(
138 weightFile =
"PhysicsTools/NanoAOD/data/mu_BDTG_2016.weights.xml",
139 variables = _legacy_muon_BDT_variable
142 (run2_muon_2017 | run2_muon_2018).toModify(
144 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"),
145 variables = _legacy_muon_BDT_variable
149 muonBSConstrain = cms.EDProducer(
"MuonBeamspotConstraintValueMapProducer",
150 src = cms.InputTag(
"linkedObjects",
"muons"),
153 muonTable = simplePATMuonFlatTableProducer.clone(
154 src = cms.InputTag(
"linkedObjects",
"muons"),
155 name = cms.string(
"Muon"),
156 doc = cms.string(
"slimmedMuons after basic selection (" + finalMuons.cut.value()+
")"),
157 variables = cms.PSet(CandVars,
158 ptErr =
Var(
"bestTrack().ptError()", float, doc =
"ptError of the muon track", precision=6),
159 tunepRelPt =
Var(
"tunePMuonBestTrack().pt/pt",float,doc=
"TuneP relative pt, tunePpt/pt",precision=6),
160 tuneP_pterr =
Var(
"tunePMuonBestTrack().ptError()", float, doc =
"pTerr from tunePMuonBestTrack", precision=6),
161 dz =
Var(
"dB('PVDZ')",float,doc=
"dz (with sign) wrt first PV, in cm",precision=10),
162 dzErr =
Var(
"abs(edB('PVDZ'))",float,doc=
"dz uncertainty, in cm",precision=6),
163 dxybs =
Var(
"dB('BS2D')",float,doc=
"dxy (with sign) wrt the beam spot, in cm",precision=10),
164 dxy =
Var(
"dB('PV2D')",float,doc=
"dxy (with sign) wrt first PV, in cm",precision=10),
165 dxyErr =
Var(
"edB('PV2D')",float,doc=
"dxy uncertainty, in cm",precision=6),
166 ip3d =
Var(
"abs(dB('PV3D'))",float,doc=
"3D impact parameter wrt first PV, in cm",precision=10),
167 sip3d =
Var(
"abs(dB('PV3D')/edB('PV3D'))",float,doc=
"3D impact parameter significance wrt first PV",precision=10),
168 segmentComp =
Var(
"segmentCompatibility()", float, doc =
"muon segment compatibility", precision=14),
169 nStations =
Var(
"numberOfMatchedStations",
"uint8", doc =
"number of matched stations with default arbitration (segment & track)"),
170 nTrackerLayers =
Var(
"?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0",
"uint8", doc =
"number of layers in the tracker"),
171 highPurity =
Var(
"?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc =
"inner track is high purity"),
172 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1",
"int16", doc=
"index of the associated jet (-1 if none)"),
173 svIdx =
Var(
"?hasUserCand('vertex')?userCand('vertex').key():-1",
"int16", doc=
"index of matching secondary vertex"),
174 tkRelIso =
Var(
"isolationR03().sumPt/pt",float,doc=
"Tracker-based relative isolation dR=0.3 for highPt, trkIso/pt",precision=6),
175 miniPFRelIso_chg =
Var(
"userFloat('miniIsoChg')/pt",float,doc=
"mini PF relative isolation, charged component"),
176 miniPFRelIso_all =
Var(
"userFloat('miniIsoAll')/pt",float,doc=
"mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
177 pfRelIso03_chg =
Var(
"pfIsolationR03().sumChargedHadronPt/pt",float,doc=
"PF relative isolation dR=0.3, charged component"),
178 pfRelIso03_all =
Var(
"(pfIsolationR03().sumChargedHadronPt + max(pfIsolationR03().sumNeutralHadronEt + pfIsolationR03().sumPhotonEt - pfIsolationR03().sumPUPt/2,0.0))/pt",float,doc=
"PF relative isolation dR=0.3, total (deltaBeta corrections)"),
179 pfRelIso04_all =
Var(
"(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt",float,doc=
"PF relative isolation dR=0.4, total (deltaBeta corrections)"),
180 jetRelIso =
Var(
"?userCand('jetForLepJetVar').isNonnull()?(1./userFloat('ptRatio'))-1.:-1.",float,doc=
"Relative isolation in matched jet (1/ptRatio-1), -1 if none",precision=8),
181 jetPtRelv2 =
Var(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0",float,doc=
"Relative momentum of the lepton with respect to the closest jet after subtracting the lepton",precision=8),
182 jetDF =
Var(
"?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0",float,doc=
"value of the DEEPJET b tagging algorithm discriminator of the associated jet (0 if none)",precision=8,lazyEval=
True),
183 tightCharge =
Var(
"?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",
"uint8", doc=
"Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
184 looseId =
Var(
"passed('CutBasedIdLoose')",bool, doc=
"muon is loose muon"),
185 isPFcand =
Var(
"isPFMuon",bool,doc=
"muon is PF candidate"),
186 isGlobal =
Var(
"isGlobalMuon",bool,doc=
"muon is global muon"),
187 isTracker =
Var(
"isTrackerMuon",bool,doc=
"muon is tracker muon"),
188 isStandalone =
Var(
"isStandAloneMuon",bool,doc=
"muon is a standalone muon"),
189 mediumId =
Var(
"passed('CutBasedIdMedium')",bool,doc=
"cut-based ID, medium WP"),
190 mediumPromptId =
Var(
"passed('CutBasedIdMediumPrompt')",bool,doc=
"cut-based ID, medium prompt WP"),
191 tightId =
Var(
"passed('CutBasedIdTight')",bool,doc=
"cut-based ID, tight WP"),
192 softId =
Var(
"passed('SoftCutBasedId')",bool,doc=
"soft cut-based ID"),
193 softMvaId =
Var(
"passed('SoftMvaId')",bool,doc=
"soft MVA ID"),
194 softMva =
Var(
"softMvaValue()",float,doc=
"soft MVA ID score",precision=6),
195 softMvaRun3 =
Var(
"softMvaRun3Value()",float,doc=
"soft MVA Run3 ID score",precision=6),
196 highPtId =
Var(
"?passed('CutBasedIdGlobalHighPt')?2:passed('CutBasedIdTrkHighPt')",
"uint8",doc=
"high-pT cut-based ID (1 = tracker high pT, 2 = global high pT, which includes tracker high pT)"),
197 pfIsoId =
Var(
"passed('PFIsoVeryLoose')+passed('PFIsoLoose')+passed('PFIsoMedium')+passed('PFIsoTight')+passed('PFIsoVeryTight')+passed('PFIsoVeryVeryTight')",
"uint8",doc=
"PFIso ID from miniAOD selector (1=PFIsoVeryLoose, 2=PFIsoLoose, 3=PFIsoMedium, 4=PFIsoTight, 5=PFIsoVeryTight, 6=PFIsoVeryVeryTight)"),
198 tkIsoId =
Var(
"?passed('TkIsoTight')?2:passed('TkIsoLoose')",
"uint8",doc=
"TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
199 miniIsoId =
Var(
"passed('MiniIsoLoose')+passed('MiniIsoMedium')+passed('MiniIsoTight')+passed('MiniIsoVeryTight')",
"uint8",doc=
"MiniIso ID from miniAOD selector (1=MiniIsoLoose, 2=MiniIsoMedium, 3=MiniIsoTight, 4=MiniIsoVeryTight)"),
200 mvaMuID =
Var(
"userFloat('mvaIDMuon')", float, doc=
"MVA-based ID score",precision=6),
201 mvaMuID_WP =
Var(
"userFloat('mvaIDMuon_wpMedium') + userFloat('mvaIDMuon_wpTight')",
"uint8",doc=
"MVA-based ID selector WPs (1=MVAIDwpMedium,2=MVAIDwpTight)"),
202 multiIsoId =
Var(
"?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')",
"uint8",doc=
"MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
203 puppiIsoId =
Var(
"passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')",
"uint8", doc=
"PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
204 triggerIdLoose =
Var(
"passed('TriggerIdLoose')",bool,doc=
"TriggerIdLoose ID"),
205 inTimeMuon =
Var(
"passed('InTimeMuon')",bool,doc=
"inTimeMuon ID"),
206 jetNDauCharged =
Var(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0",
"uint8", doc=
"number of charged daughters of the closest jet"),
208 externalVariables = cms.PSet(
209 promptMVA =
ExtVar(cms.InputTag(
"muonPROMPTMVA"),float, doc=
"Prompt MVA lepton ID score. Corresponds to the previous mvaTTH",precision=14),
210 mvaLowPt =
ExtVar(cms.InputTag(
"muonMVALowPt"),float, doc=
"Low pt muon ID score",precision=14),
211 fsrPhotonIdx =
ExtVar(cms.InputTag(
"leptonFSRphotons:muFsrIndex"),
"int16", doc=
"Index of the lowest-dR/ET2 among associated FSR photons"),
212 bsConstrainedPt =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedPt"),float, doc=
"pT with beamspot constraint",precision=-1),
213 bsConstrainedPtErr =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedPtErr"),float, doc=
"pT error with beamspot constraint ",precision=6),
214 bsConstrainedChi2 =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedChi2"),float, doc=
"chi2 of beamspot constraint",precision=6),
219 muonTable.variables.eta.precision = 16
220 muonTable.variables.phi.precision = 16
224 run2_nanoAOD_ANY.toModify(
225 ptRatioRelForMu,srcJet=
"updatedJets" 229 muonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
231 matched = cms.InputTag(
"finalGenParticles"),
232 mcPdgId = cms.vint32(13),
233 checkCharge = cms.bool(
False),
234 mcStatus = cms.vint32(1),
235 maxDeltaR = cms.double(0.3),
236 maxDPtRel = cms.double(0.5),
237 resolveAmbiguities = cms.bool(
True),
238 resolveByMatchQuality = cms.bool(
True),
241 muonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
243 mcMap = cms.InputTag(
"muonsMCMatchForTable"),
244 objName = muonTable.name,
245 objType = muonTable.name,
246 branchName = cms.string(
"genPart"),
247 docString = cms.string(
"MC matching to status==1 muons"),
250 muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons )
251 muonMCTask = cms.Task(muonsMCMatchForTable,muonMCTable)
252 muonTablesTask = cms.Task(muonPROMPTMVA,muonMVALowPt,muonBSConstrain,muonTable,muonMVAID)
def Var(expr, valtype, doc=None, precision=-1, lazyEval=False)
def ExtVar(tag, valtype, doc=None, precision=-1)