1 import FWCore.ParameterSet.Config
as cms
5 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi
import simpleCandidateFlatTableProducer
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 isClassifier = cms.bool(
False),
37 backend = cms.string(
'ONNX'),
38 name = cms.string(
"muonMVAID"),
39 outputTensorName= cms.string(
"probabilities"),
40 inputTensorName= cms.string(
"float_input"),
41 outputNames = cms.vstring([
"probGOOD",
"wpMedium",
"wpTight"]),
42 batch_eval =cms.bool(
True),
43 outputFormulas = cms.vstring([
"at(1)",
"? at(1) > 0.08 ? 1 : 0",
"? at(1) > 0.20 ? 1 : 0"]),
44 variablesOrder = cms.vstring([
"LepGood_global_muon",
"LepGood_validFraction",
"Muon_norm_chi2_extended",
"LepGood_local_chi2",
"LepGood_kink",
"LepGood_segmentComp",
"Muon_n_Valid_hits_extended",
"LepGood_n_MatchedStations",
"LepGood_Valid_pixel",
"LepGood_tracker_layers",
"LepGood_pt",
"LepGood_eta"]),
46 LepGood_global_muon = cms.string(
"isGlobalMuon"),
47 LepGood_validFraction = cms.string(
"?innerTrack.isNonnull?innerTrack().validFraction:-99"),
48 LepGood_local_chi2 = cms.string(
"combinedQuality().chi2LocalPosition"),
49 LepGood_kink = cms.string(
"combinedQuality().trkKink"),
50 LepGood_segmentComp = cms.string(
"segmentCompatibility"),
51 LepGood_n_MatchedStations = cms.string(
"numberOfMatchedStations()"),
52 LepGood_Valid_pixel = cms.string(
"?innerTrack.isNonnull()?innerTrack().hitPattern().numberOfValidPixelHits():-99"),
53 LepGood_tracker_layers = cms.string(
"?innerTrack.isNonnull()?innerTrack().hitPattern().trackerLayersWithMeasurement():-99"),
54 LepGood_pt = cms.string(
"pt"),
55 LepGood_eta = cms.string(
"eta"),
59 slimmedMuonsWithUserData = cms.EDProducer(
"PATMuonUserDataEmbedder",
60 src = cms.InputTag(
"slimmedMuonsUpdated"),
61 userFloats = cms.PSet(
62 miniIsoChg = cms.InputTag(
"isoForMu:miniIsoChg"),
63 miniIsoAll = cms.InputTag(
"isoForMu:miniIsoAll"),
64 ptRatio = cms.InputTag(
"ptRatioRelForMu:ptRatio"),
65 ptRel = cms.InputTag(
"ptRatioRelForMu:ptRel"),
66 jetNDauChargedMVASel = cms.InputTag(
"ptRatioRelForMu:jetNDauChargedMVASel"),
67 mvaIDMuon_wpMedium = cms.InputTag(
"muonMVAID:wpMedium"),
68 mvaIDMuon_wpTight = cms.InputTag(
"muonMVAID:wpTight")
71 jetForLepJetVar = cms.InputTag(
"ptRatioRelForMu:jetForLepJetVar")
75 (run2_nanoAOD_106Xv2 | run3_nanoAOD_122 ).toModify(slimmedMuonsWithUserData.userFloats,
76 mvaIDMuon = cms.InputTag(
"muonMVAID:probGOOD"))
79 finalMuons = cms.EDFilter(
"PATMuonRefSelector",
80 src = cms.InputTag(
"slimmedMuonsWithUserData"),
81 cut = cms.string(
"pt > 15 || (pt > 3 && (passed('CutBasedIdLoose') || passed('SoftCutBasedId') || passed('SoftMvaId') || passed('CutBasedIdGlobalHighPt') || passed('CutBasedIdTrkHighPt')))")
84 finalLooseMuons = cms.EDFilter(
"PATMuonRefSelector",
85 src = cms.InputTag(
"slimmedMuonsWithUserData"),
86 cut = cms.string(
"pt > 3 && track.isNonnull && isLooseMuon")
89 muonMVATTH= cms.EDProducer(
"MuonBaseMVAValueMapProducer",
90 src = cms.InputTag(
"linkedObjects",
"muons"),
91 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"),
92 name = cms.string(
"muonMVATTH"),
93 isClassifier = cms.bool(
True),
94 variablesOrder = cms.vstring([
"LepGood_pt",
"LepGood_eta",
"LepGood_jetNDauChargedMVASel",
"LepGood_miniRelIsoCharged",
"LepGood_miniRelIsoNeutral",
"LepGood_jetPtRelv2",
"LepGood_jetDF",
"LepGood_jetPtRatio",
"LepGood_dxy",
"LepGood_sip3d",
"LepGood_dz",
"LepGood_segmentComp"]),
96 LepGood_pt = cms.string(
"pt"),
97 LepGood_eta = cms.string(
"eta"),
98 LepGood_jetNDauChargedMVASel = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
99 LepGood_miniRelIsoCharged = cms.string(
"userFloat('miniIsoChg')/pt"),
100 LepGood_miniRelIsoNeutral = cms.string(
"(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
101 LepGood_jetPtRelv2 = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
102 LepGood_jetDF = 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"),
103 LepGood_jetPtRatio = 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)"),
104 LepGood_dxy = cms.string(
"log(abs(dB('PV2D')))"),
105 LepGood_sip3d = cms.string(
"abs(dB('PV3D')/edB('PV3D'))"),
106 LepGood_dz = cms.string(
"log(abs(dB('PVDZ')))"),
107 LepGood_segmentComp = cms.string(
"segmentCompatibility"),
112 muonMVALowPt = muonMVATTH.clone(
113 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_lowpt.weights.xml"),
114 name = cms.string(
"muonMVALowPt"),
117 run2_muon_2016.toModify(
119 weightFile =
"PhysicsTools/NanoAOD/data/mu_BDTG_2016.weights.xml",
123 muonBSConstrain = cms.EDProducer(
"MuonBeamspotConstraintValueMapProducer",
124 src = cms.InputTag(
"linkedObjects",
"muons"),
127 muonTable = simpleCandidateFlatTableProducer.clone(
128 src = cms.InputTag(
"linkedObjects",
"muons"),
129 name = cms.string(
"Muon"),
130 doc = cms.string(
"slimmedMuons after basic selection (" + finalMuons.cut.value()+
")"),
131 variables = cms.PSet(CandVars,
132 ptErr =
Var(
"bestTrack().ptError()", float, doc =
"ptError of the muon track", precision=6),
133 tunepRelPt =
Var(
"tunePMuonBestTrack().pt/pt",float,doc=
"TuneP relative pt, tunePpt/pt",precision=6),
134 dz =
Var(
"dB('PVDZ')",float,doc=
"dz (with sign) wrt first PV, in cm",precision=10),
135 dzErr =
Var(
"abs(edB('PVDZ'))",float,doc=
"dz uncertainty, in cm",precision=6),
136 dxybs =
Var(
"dB('BS2D')",float,doc=
"dxy (with sign) wrt the beam spot, in cm",precision=10),
137 dxy =
Var(
"dB('PV2D')",float,doc=
"dxy (with sign) wrt first PV, in cm",precision=10),
138 dxyErr =
Var(
"edB('PV2D')",float,doc=
"dxy uncertainty, in cm",precision=6),
139 ip3d =
Var(
"abs(dB('PV3D'))",float,doc=
"3D impact parameter wrt first PV, in cm",precision=10),
140 sip3d =
Var(
"abs(dB('PV3D')/edB('PV3D'))",float,doc=
"3D impact parameter significance wrt first PV",precision=10),
141 segmentComp =
Var(
"segmentCompatibility()", float, doc =
"muon segment compatibility", precision=14),
142 nStations =
Var(
"numberOfMatchedStations",
"uint8", doc =
"number of matched stations with default arbitration (segment & track)"),
143 nTrackerLayers =
Var(
"?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0",
"uint8", doc =
"number of layers in the tracker"),
144 highPurity =
Var(
"?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc =
"inner track is high purity"),
145 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1",
"int16", doc=
"index of the associated jet (-1 if none)"),
146 svIdx =
Var(
"?hasUserCand('vertex')?userCand('vertex').key():-1",
"int16", doc=
"index of matching secondary vertex"),
147 tkRelIso =
Var(
"isolationR03().sumPt/tunePMuonBestTrack().pt",float,doc=
"Tracker-based relative isolation dR=0.3 for highPt, trkIso/tunePpt",precision=6),
148 miniPFRelIso_chg =
Var(
"userFloat('miniIsoChg')/pt",float,doc=
"mini PF relative isolation, charged component"),
149 miniPFRelIso_all =
Var(
"userFloat('miniIsoAll')/pt",float,doc=
"mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
150 pfRelIso03_chg =
Var(
"pfIsolationR03().sumChargedHadronPt/pt",float,doc=
"PF relative isolation dR=0.3, charged component"),
151 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)"),
152 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)"),
153 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),
154 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),
155 tightCharge =
Var(
"?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",
"uint8", doc=
"Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
156 looseId =
Var(
"passed('CutBasedIdLoose')",bool, doc=
"muon is loose muon"),
157 isPFcand =
Var(
"isPFMuon",bool,doc=
"muon is PF candidate"),
158 isGlobal =
Var(
"isGlobalMuon",bool,doc=
"muon is global muon"),
159 isTracker =
Var(
"isTrackerMuon",bool,doc=
"muon is tracker muon"),
160 isStandalone =
Var(
"isStandAloneMuon",bool,doc=
"muon is a standalone muon"),
161 mediumId =
Var(
"passed('CutBasedIdMedium')",bool,doc=
"cut-based ID, medium WP"),
162 mediumPromptId =
Var(
"passed('CutBasedIdMediumPrompt')",bool,doc=
"cut-based ID, medium prompt WP"),
163 tightId =
Var(
"passed('CutBasedIdTight')",bool,doc=
"cut-based ID, tight WP"),
164 softId =
Var(
"passed('SoftCutBasedId')",bool,doc=
"soft cut-based ID"),
165 softMvaId =
Var(
"passed('SoftMvaId')",bool,doc=
"soft MVA ID"),
166 softMva =
Var(
"softMvaValue()",float,doc=
"soft MVA ID score",precision=6),
167 softMvaRun3 =
Var(
"softMvaRun3Value()",float,doc=
"soft MVA Run3 ID score",precision=6),
168 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)"),
169 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)"),
170 tkIsoId =
Var(
"?passed('TkIsoTight')?2:passed('TkIsoLoose')",
"uint8",doc=
"TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
171 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)"),
172 mvaMuID =
Var(
"mvaIDValue()",float,doc=
"MVA-based ID score ",precision=6),
173 mvaMuID_WP =
Var(
"userFloat('mvaIDMuon_wpMedium') + userFloat('mvaIDMuon_wpTight')",
"uint8",doc=
"MVA-based ID selector WPs (1=MVAIDwpMedium,2=MVAIDwpTight)"),
174 multiIsoId =
Var(
"?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')",
"uint8",doc=
"MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
175 puppiIsoId =
Var(
"passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')",
"uint8", doc=
"PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
176 triggerIdLoose =
Var(
"passed('TriggerIdLoose')",bool,doc=
"TriggerIdLoose ID"),
177 inTimeMuon =
Var(
"passed('InTimeMuon')",bool,doc=
"inTimeMuon ID"),
178 jetNDauCharged =
Var(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0",
"uint8", doc=
"number of charged daughters of the closest jet"),
180 externalVariables = cms.PSet(
181 mvaTTH =
ExtVar(cms.InputTag(
"muonMVATTH"),float, doc=
"TTH MVA lepton ID score",precision=14),
182 mvaLowPt =
ExtVar(cms.InputTag(
"muonMVALowPt"),float, doc=
"Low pt muon ID score",precision=14),
183 fsrPhotonIdx =
ExtVar(cms.InputTag(
"leptonFSRphotons:muFsrIndex"),
"int16", doc=
"Index of the lowest-dR/ET2 among associated FSR photons"),
184 bsConstrainedPt =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedPt"),float, doc=
"pT with beamspot constraint",precision=-1),
185 bsConstrainedPtErr =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedPtErr"),float, doc=
"pT error with beamspot constraint ",precision=6),
186 bsConstrainedChi2 =
ExtVar(cms.InputTag(
"muonBSConstrain:muonBSConstrainedChi2"),float, doc=
"chi2 of beamspot constraint",precision=6),
191 muonTable.variables.eta.precision = 16
192 muonTable.variables.phi.precision = 16
194 (run2_nanoAOD_106Xv2 | run3_nanoAOD_122).toModify(muonTable.variables,mvaMuID=
None).toModify(
195 muonTable.variables, mvaMuID =
Var(
"userFloat('mvaIDMuon')", float, doc=
"MVA-based ID score",precision=6))
199 run2_nanoAOD_ANY.toModify(
200 ptRatioRelForMu,srcJet=
"updatedJets" 204 muonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
206 matched = cms.InputTag(
"finalGenParticles"),
207 mcPdgId = cms.vint32(13),
208 checkCharge = cms.bool(
False),
209 mcStatus = cms.vint32(1),
210 maxDeltaR = cms.double(0.3),
211 maxDPtRel = cms.double(0.5),
212 resolveAmbiguities = cms.bool(
True),
213 resolveByMatchQuality = cms.bool(
True),
216 muonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
218 mcMap = cms.InputTag(
"muonsMCMatchForTable"),
219 objName = muonTable.name,
220 objType = muonTable.name,
221 branchName = cms.string(
"genPart"),
222 docString = cms.string(
"MC matching to status==1 muons"),
225 muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons )
226 muonMCTask = cms.Task(muonsMCMatchForTable,muonMCTable)
227 muonTablesTask = cms.Task(muonMVATTH,muonMVALowPt,muonBSConstrain,muonTable,muonMVAID)
def ExtVar(tag, valtype, doc=None, precision=-1)
def Var(expr, valtype, doc=None, precision=-1)