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 dz =
Var(
"dB('PVDZ')",float,doc=
"dz (with sign) wrt first PV, in cm",precision=10),
161 dzErr =
Var(
"abs(edB('PVDZ'))",float,doc=
"dz uncertainty, in cm",precision=6),
162 dxybs =
Var(
"dB('BS2D')",float,doc=
"dxy (with sign) wrt the beam spot, in cm",precision=10),
163 dxy =
Var(
"dB('PV2D')",float,doc=
"dxy (with sign) wrt first PV, in cm",precision=10),
164 dxyErr =
Var(
"edB('PV2D')",float,doc=
"dxy uncertainty, in cm",precision=6),
165 ip3d =
Var(
"abs(dB('PV3D'))",float,doc=
"3D impact parameter wrt first PV, in cm",precision=10),
166 sip3d =
Var(
"abs(dB('PV3D')/edB('PV3D'))",float,doc=
"3D impact parameter significance wrt first PV",precision=10),
167 segmentComp =
Var(
"segmentCompatibility()", float, doc =
"muon segment compatibility", precision=14),
168 nStations =
Var(
"numberOfMatchedStations",
"uint8", doc =
"number of matched stations with default arbitration (segment & track)"),
169 nTrackerLayers =
Var(
"?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0",
"uint8", doc =
"number of layers in the tracker"),
170 highPurity =
Var(
"?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc =
"inner track is high purity"),
171 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1",
"int16", doc=
"index of the associated jet (-1 if none)"),
172 svIdx =
Var(
"?hasUserCand('vertex')?userCand('vertex').key():-1",
"int16", doc=
"index of matching secondary vertex"),
173 tkRelIso =
Var(
"isolationR03().sumPt/tunePMuonBestTrack().pt",float,doc=
"Tracker-based relative isolation dR=0.3 for highPt, trkIso/tunePpt",precision=6),
174 miniPFRelIso_chg =
Var(
"userFloat('miniIsoChg')/pt",float,doc=
"mini PF relative isolation, charged component"),
175 miniPFRelIso_all =
Var(
"userFloat('miniIsoAll')/pt",float,doc=
"mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
176 pfRelIso03_chg =
Var(
"pfIsolationR03().sumChargedHadronPt/pt",float,doc=
"PF relative isolation dR=0.3, charged component"),
177 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)"),
178 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)"),
179 jetRelIso =
Var(
"?userCand('jetForLepJetVar').isNonnull()?(1./userFloat('ptRatio'))-1.:(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt",float,doc=
"Relative isolation in matched jet (1/ptRatio-1, pfRelIso04_all if no matched jet)",precision=8),
180 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),
181 tightCharge =
Var(
"?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",
"uint8", doc=
"Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
182 looseId =
Var(
"passed('CutBasedIdLoose')",bool, doc=
"muon is loose muon"),
183 isPFcand =
Var(
"isPFMuon",bool,doc=
"muon is PF candidate"),
184 isGlobal =
Var(
"isGlobalMuon",bool,doc=
"muon is global muon"),
185 isTracker =
Var(
"isTrackerMuon",bool,doc=
"muon is tracker muon"),
186 isStandalone =
Var(
"isStandAloneMuon",bool,doc=
"muon is a standalone muon"),
187 mediumId =
Var(
"passed('CutBasedIdMedium')",bool,doc=
"cut-based ID, medium WP"),
188 mediumPromptId =
Var(
"passed('CutBasedIdMediumPrompt')",bool,doc=
"cut-based ID, medium prompt WP"),
189 tightId =
Var(
"passed('CutBasedIdTight')",bool,doc=
"cut-based ID, tight WP"),
190 softId =
Var(
"passed('SoftCutBasedId')",bool,doc=
"soft cut-based ID"),
191 softMvaId =
Var(
"passed('SoftMvaId')",bool,doc=
"soft MVA ID"),
192 softMva =
Var(
"softMvaValue()",float,doc=
"soft MVA ID score",precision=6),
193 softMvaRun3 =
Var(
"softMvaRun3Value()",float,doc=
"soft MVA Run3 ID score",precision=6),
194 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)"),
195 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)"),
196 tkIsoId =
Var(
"?passed('TkIsoTight')?2:passed('TkIsoLoose')",
"uint8",doc=
"TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
197 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)"),
198 mvaMuID =
Var(
"userFloat('mvaIDMuon')", float, doc=
"MVA-based ID score",precision=6),
199 mvaMuID_WP =
Var(
"userFloat('mvaIDMuon_wpMedium') + userFloat('mvaIDMuon_wpTight')",
"uint8",doc=
"MVA-based ID selector WPs (1=MVAIDwpMedium,2=MVAIDwpTight)"),
200 multiIsoId =
Var(
"?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')",
"uint8",doc=
"MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
201 puppiIsoId =
Var(
"passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')",
"uint8", doc=
"PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
202 triggerIdLoose =
Var(
"passed('TriggerIdLoose')",bool,doc=
"TriggerIdLoose ID"),
203 inTimeMuon =
Var(
"passed('InTimeMuon')",bool,doc=
"inTimeMuon ID"),
204 jetNDauCharged =
Var(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0",
"uint8", doc=
"number of charged daughters of the closest jet"),
206 externalVariables = cms.PSet(
207 promptMVA =
ExtVar(cms.InputTag(
"muonPROMPTMVA"),float, doc=
"Prompt MVA lepton ID score. Corresponds to the previous mvaTTH",precision=14),
208 mvaLowPt =
ExtVar(cms.InputTag(
"muonMVALowPt"),float, doc=
"Low pt muon ID score",precision=14),
209 fsrPhotonIdx =
ExtVar(cms.InputTag(
"leptonFSRphotons:muFsrIndex"),
"int16", doc=
"Index of the lowest-dR/ET2 among associated FSR photons"),
210 bsConstrainedPt =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedPt"),float, doc=
"pT with beamspot constraint",precision=-1),
211 bsConstrainedPtErr =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedPtErr"),float, doc=
"pT error with beamspot constraint ",precision=6),
212 bsConstrainedChi2 =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedChi2"),float, doc=
"chi2 of beamspot constraint",precision=6),
217 muonTable.variables.eta.precision = 16
218 muonTable.variables.phi.precision = 16
222 run2_nanoAOD_ANY.toModify(
223 ptRatioRelForMu,srcJet=
"updatedJets" 227 muonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
229 matched = cms.InputTag(
"finalGenParticles"),
230 mcPdgId = cms.vint32(13),
231 checkCharge = cms.bool(
False),
232 mcStatus = cms.vint32(1),
233 maxDeltaR = cms.double(0.3),
234 maxDPtRel = cms.double(0.5),
235 resolveAmbiguities = cms.bool(
True),
236 resolveByMatchQuality = cms.bool(
True),
239 muonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
241 mcMap = cms.InputTag(
"muonsMCMatchForTable"),
242 objName = muonTable.name,
243 objType = muonTable.name,
244 branchName = cms.string(
"genPart"),
245 docString = cms.string(
"MC matching to status==1 muons"),
248 muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons )
249 muonMCTask = cms.Task(muonsMCMatchForTable,muonMCTable)
250 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)