File indexing completed on 2024-09-07 04:37:20
0001 import FWCore.ParameterSet.Config as cms
0002
0003 from PhysicsTools.NanoAOD.nano_eras_cff import *
0004 from PhysicsTools.NanoAOD.common_cff import *
0005 from PhysicsTools.NanoAOD.simplePATMuonFlatTableProducer_cfi import simplePATMuonFlatTableProducer
0006
0007 import PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi
0008
0009
0010 slimmedMuonsUpdated = cms.EDProducer("PATMuonUpdater",
0011 src = cms.InputTag("slimmedMuons"),
0012 vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
0013 computeMiniIso = cms.bool(False),
0014 fixDxySign = cms.bool(True),
0015 pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
0016 miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams,
0017 recomputeMuonBasicSelectors = cms.bool(False),
0018 )
0019
0020 isoForMu = cms.EDProducer("MuonIsoValueMapProducer",
0021 src = cms.InputTag("slimmedMuonsUpdated"),
0022 relative = cms.bool(False),
0023 rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
0024 EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
0025 )
0026
0027 ptRatioRelForMu = cms.EDProducer("MuonJetVarProducer",
0028 srcJet = cms.InputTag("updatedJetsPuppi"),
0029 srcLep = cms.InputTag("slimmedMuonsUpdated"),
0030 srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
0031 )
0032
0033 muonMVAID = cms.EDProducer("EvaluateMuonMVAID",
0034 src = cms.InputTag("slimmedMuonsUpdated"),
0035 weightFile = cms.FileInPath("RecoMuon/MuonIdentification/data/mvaID.onnx"),
0036 backend = cms.string('ONNX'),
0037 name = cms.string("muonMVAID"),
0038 outputTensorName= cms.string("probabilities"),
0039 inputTensorName= cms.string("float_input"),
0040 outputNames = cms.vstring(["probGOOD", "wpMedium", "wpTight"]),
0041 batch_eval =cms.bool(True),
0042 outputFormulas = cms.vstring(["at(1)", "? at(1) > 0.08 ? 1 : 0", "? at(1) > 0.20 ? 1 : 0"]),
0043 variables = cms.VPSet(
0044 cms.PSet( name = cms.string("LepGood_global_muon"), expr = cms.string("isGlobalMuon")),
0045 cms.PSet( name = cms.string("LepGood_validFraction"), expr = cms.string("?innerTrack.isNonnull?innerTrack().validFraction:-99")),
0046 cms.PSet( name = cms.string("Muon_norm_chi2_extended")),
0047 cms.PSet( name = cms.string("LepGood_local_chi2"), expr = cms.string("combinedQuality().chi2LocalPosition")),
0048 cms.PSet( name = cms.string("LepGood_kink"), expr = cms.string("combinedQuality().trkKink")),
0049 cms.PSet( name = cms.string("LepGood_segmentComp"), expr = cms.string("segmentCompatibility")),
0050 cms.PSet( name = cms.string("Muon_n_Valid_hits_extended")),
0051 cms.PSet( name = cms.string("LepGood_n_MatchedStations"), expr = cms.string("numberOfMatchedStations()")),
0052 cms.PSet( name = cms.string("LepGood_Valid_pixel"), expr = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().numberOfValidPixelHits():-99")),
0053 cms.PSet( name = cms.string("LepGood_tracker_layers"), expr = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().trackerLayersWithMeasurement():-99")),
0054 cms.PSet( name = cms.string("LepGood_pt"), expr = cms.string("pt")),
0055 cms.PSet( name = cms.string("LepGood_eta"), expr = cms.string("eta")),
0056 )
0057 )
0058
0059
0060
0061
0062
0063
0064 slimmedMuonsWithUserData = cms.EDProducer("PATMuonUserDataEmbedder",
0065 src = cms.InputTag("slimmedMuonsUpdated"),
0066 userFloats = cms.PSet(
0067 miniIsoChg = cms.InputTag("isoForMu:miniIsoChg"),
0068 miniIsoAll = cms.InputTag("isoForMu:miniIsoAll"),
0069 ptRatio = cms.InputTag("ptRatioRelForMu:ptRatio"),
0070 ptRel = cms.InputTag("ptRatioRelForMu:ptRel"),
0071 jetNDauChargedMVASel = cms.InputTag("ptRatioRelForMu:jetNDauChargedMVASel"),
0072 mvaIDMuon_wpMedium = cms.InputTag("muonMVAID:wpMedium"),
0073 mvaIDMuon_wpTight = cms.InputTag("muonMVAID:wpTight"),
0074 mvaIDMuon = cms.InputTag("muonMVAID:probGOOD")
0075 ),
0076 userCands = cms.PSet(
0077 jetForLepJetVar = cms.InputTag("ptRatioRelForMu:jetForLepJetVar")
0078 ),
0079 )
0080
0081
0082 finalMuons = cms.EDFilter("PATMuonRefSelector",
0083 src = cms.InputTag("slimmedMuonsWithUserData"),
0084 cut = cms.string("pt > 15 || (pt > 3 && (passed('CutBasedIdLoose') || passed('SoftCutBasedId') || passed('SoftMvaId') || passed('CutBasedIdGlobalHighPt') || passed('CutBasedIdTrkHighPt')))")
0085 )
0086
0087 finalLooseMuons = cms.EDFilter("PATMuonRefSelector",
0088 src = cms.InputTag("slimmedMuonsWithUserData"),
0089 cut = cms.string("pt > 3 && track.isNonnull && isLooseMuon")
0090 )
0091
0092 muonPROMPTMVA= cms.EDProducer("MuonBaseMVAValueMapProducer",
0093 src = cms.InputTag("linkedObjects","muons"),
0094 weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_2022.weights.xml"),
0095 backend = cms.string("TMVA"),
0096 name = cms.string("muonPROMPTMVA"),
0097 isClassifier = cms.bool(True),
0098 variables = cms.VPSet(
0099 cms.PSet( name = cms.string("LepGood_pt"), expr = cms.string("pt")),
0100 cms.PSet( name = cms.string("LepGood_eta"), expr = cms.string("eta")),
0101 cms.PSet( name = cms.string("LepGood_pfRelIso03_all"), expr = cms.string("(pfIsolationR03().sumChargedHadronPt + max(pfIsolationR03().sumNeutralHadronEt + pfIsolationR03().sumPhotonEt - pfIsolationR03().sumPUPt/2,0.0))/pt")),
0102 cms.PSet( name = cms.string("LepGood_miniRelIsoCharged"), expr = cms.string("userFloat('miniIsoChg')/pt")),
0103 cms.PSet( name = cms.string("LepGood_miniRelIsoNeutral"), expr = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt")),
0104 cms.PSet( name = cms.string("LepGood_jetNDauChargedMVASel"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0")),
0105 cms.PSet( name = cms.string("LepGood_jetPtRelv2"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0")),
0106 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")),
0107 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)")),
0108 cms.PSet( name = cms.string("LepGood_sip3d"), expr = cms.string("abs(dB('PV3D')/edB('PV3D'))")),
0109 cms.PSet( name = cms.string("LepGood_dxy"), expr = cms.string("log(abs(dB('PV2D')))")),
0110 cms.PSet( name = cms.string("LepGood_dz"), expr = cms.string("log(abs(dB('PVDZ')))")),
0111 cms.PSet( name = cms.string("LepGood_segmentComp"), expr = cms.string("segmentCompatibility")),
0112 )
0113 )
0114
0115 _legacy_muon_BDT_variable = cms.VPSet(
0116 cms.PSet( name = cms.string("LepGood_pt"), expr = cms.string("pt")),
0117 cms.PSet( name = cms.string("LepGood_eta"), expr = cms.string("eta")),
0118 cms.PSet( name = cms.string("LepGood_jetNDauChargedMVASel"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0")),
0119 cms.PSet( name = cms.string("LepGood_miniRelIsoCharged"), expr = cms.string("userFloat('miniIsoChg')/pt")),
0120 cms.PSet( name = cms.string("LepGood_miniRelIsoNeutral"), expr = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt")),
0121 cms.PSet( name = cms.string("LepGood_jetPtRelv2"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0")),
0122 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")),
0123 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)")),
0124 cms.PSet( name = cms.string("LepGood_dxy"), expr = cms.string("log(abs(dB('PV2D')))")),
0125 cms.PSet( name = cms.string("LepGood_sip3d"), expr = cms.string("abs(dB('PV3D')/edB('PV3D'))")),
0126 cms.PSet( name = cms.string("LepGood_dz"), expr = cms.string("log(abs(dB('PVDZ')))")),
0127 cms.PSet( name = cms.string("LepGood_segmentComp"), expr = cms.string("segmentCompatibility")),
0128 )
0129
0130 muonMVALowPt = muonPROMPTMVA.clone(
0131 weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_lowpt.weights.xml"),
0132 name = cms.string("muonMVALowPt"),
0133 variables = _legacy_muon_BDT_variable
0134 )
0135
0136 run2_muon_2016.toModify(
0137 muonPROMPTMVA,
0138 weightFile = "PhysicsTools/NanoAOD/data/mu_BDTG_2016.weights.xml",
0139 variables = _legacy_muon_BDT_variable
0140 )
0141
0142 (run2_muon_2017 | run2_muon_2018).toModify(
0143 muonPROMPTMVA,
0144 weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"),
0145 variables = _legacy_muon_BDT_variable
0146 )
0147
0148 from TrackingTools.TransientTrack.TransientTrackBuilder_cfi import *
0149 muonBSConstrain = cms.EDProducer("MuonBeamspotConstraintValueMapProducer",
0150 src = cms.InputTag("linkedObjects","muons"),
0151 )
0152
0153 muonTable = simplePATMuonFlatTableProducer.clone(
0154 src = cms.InputTag("linkedObjects","muons"),
0155 name = cms.string("Muon"),
0156 doc = cms.string("slimmedMuons after basic selection (" + finalMuons.cut.value()+")"),
0157 variables = cms.PSet(CandVars,
0158 ptErr = Var("bestTrack().ptError()", float, doc = "ptError of the muon track", precision=6),
0159 tunepRelPt = Var("tunePMuonBestTrack().pt/pt",float,doc="TuneP relative pt, tunePpt/pt",precision=6),
0160 tuneP_pterr = Var("tunePMuonBestTrack().ptError()", float, doc = "pTerr from tunePMuonBestTrack", precision=6),
0161 dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
0162 dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
0163 dxybs = Var("dB('BS2D')",float,doc="dxy (with sign) wrt the beam spot, in cm",precision=10),
0164 dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
0165 dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
0166 ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
0167 sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV",precision=10),
0168 segmentComp = Var("segmentCompatibility()", float, doc = "muon segment compatibility", precision=14),
0169 nStations = Var("numberOfMatchedStations", "uint8", doc = "number of matched stations with default arbitration (segment & track)"),
0170 nTrackerLayers = Var("?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0", "uint8", doc = "number of layers in the tracker"),
0171 highPurity = Var("?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc = "inner track is high purity"),
0172 jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", "int16", doc="index of the associated jet (-1 if none)"),
0173 svIdx = Var("?hasUserCand('vertex')?userCand('vertex').key():-1", "int16", doc="index of matching secondary vertex"),
0174 tkRelIso = Var("isolationR03().sumPt/pt",float,doc="Tracker-based relative isolation dR=0.3 for highPt, trkIso/pt",precision=6),
0175 miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"),
0176 miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
0177 pfRelIso03_chg = Var("pfIsolationR03().sumChargedHadronPt/pt",float,doc="PF relative isolation dR=0.3, charged component"),
0178 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)"),
0179 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)"),
0180 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),
0181 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),
0182 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),
0183 tightCharge = Var("?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0", "uint8", doc="Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
0184 looseId = Var("passed('CutBasedIdLoose')",bool, doc="muon is loose muon"),
0185 isPFcand = Var("isPFMuon",bool,doc="muon is PF candidate"),
0186 isGlobal = Var("isGlobalMuon",bool,doc="muon is global muon"),
0187 isTracker = Var("isTrackerMuon",bool,doc="muon is tracker muon"),
0188 isStandalone = Var("isStandAloneMuon",bool,doc="muon is a standalone muon"),
0189 mediumId = Var("passed('CutBasedIdMedium')",bool,doc="cut-based ID, medium WP"),
0190 mediumPromptId = Var("passed('CutBasedIdMediumPrompt')",bool,doc="cut-based ID, medium prompt WP"),
0191 tightId = Var("passed('CutBasedIdTight')",bool,doc="cut-based ID, tight WP"),
0192 softId = Var("passed('SoftCutBasedId')",bool,doc="soft cut-based ID"),
0193 softMvaId = Var("passed('SoftMvaId')",bool,doc="soft MVA ID"),
0194 softMva = Var("softMvaValue()",float,doc="soft MVA ID score",precision=6),
0195 softMvaRun3 = Var("softMvaRun3Value()",float,doc="soft MVA Run3 ID score",precision=6),
0196 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)"),
0197 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)"),
0198 tkIsoId = Var("?passed('TkIsoTight')?2:passed('TkIsoLoose')","uint8",doc="TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
0199 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)"),
0200 mvaMuID = Var("userFloat('mvaIDMuon')", float, doc="MVA-based ID score",precision=6),
0201 mvaMuID_WP = Var("userFloat('mvaIDMuon_wpMedium') + userFloat('mvaIDMuon_wpTight')","uint8",doc="MVA-based ID selector WPs (1=MVAIDwpMedium,2=MVAIDwpTight)"),
0202 multiIsoId = Var("?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')","uint8",doc="MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
0203 puppiIsoId = Var("passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')", "uint8", doc="PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
0204 triggerIdLoose = Var("passed('TriggerIdLoose')",bool,doc="TriggerIdLoose ID"),
0205 inTimeMuon = Var("passed('InTimeMuon')",bool,doc="inTimeMuon ID"),
0206 jetNDauCharged = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0", "uint8", doc="number of charged daughters of the closest jet"),
0207 ),
0208 externalVariables = cms.PSet(
0209 promptMVA = ExtVar(cms.InputTag("muonPROMPTMVA"),float, doc="Prompt MVA lepton ID score. Corresponds to the previous mvaTTH",precision=14),
0210 mvaLowPt = ExtVar(cms.InputTag("muonMVALowPt"),float, doc="Low pt muon ID score",precision=14),
0211 fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:muFsrIndex"), "int16", doc="Index of the lowest-dR/ET2 among associated FSR photons"),
0212 bsConstrainedPt = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedPt"),float, doc="pT with beamspot constraint",precision=-1),
0213 bsConstrainedPtErr = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedPtErr"),float, doc="pT error with beamspot constraint ",precision=6),
0214 bsConstrainedChi2 = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedChi2"),float, doc="chi2 of beamspot constraint",precision=6),
0215 ),
0216 )
0217
0218
0219 muonTable.variables.eta.precision = 16
0220 muonTable.variables.phi.precision = 16
0221
0222
0223
0224 run2_nanoAOD_ANY.toModify(
0225 ptRatioRelForMu,srcJet="updatedJets"
0226 )
0227
0228
0229 muonsMCMatchForTable = cms.EDProducer("MCMatcher",
0230 src = muonTable.src,
0231 matched = cms.InputTag("finalGenParticles"),
0232 mcPdgId = cms.vint32(13),
0233 checkCharge = cms.bool(False),
0234 mcStatus = cms.vint32(1),
0235 maxDeltaR = cms.double(0.3),
0236 maxDPtRel = cms.double(0.5),
0237 resolveAmbiguities = cms.bool(True),
0238 resolveByMatchQuality = cms.bool(True),
0239 )
0240
0241 muonMCTable = cms.EDProducer("CandMCMatchTableProducer",
0242 src = muonTable.src,
0243 mcMap = cms.InputTag("muonsMCMatchForTable"),
0244 objName = muonTable.name,
0245 objType = muonTable.name,
0246 branchName = cms.string("genPart"),
0247 docString = cms.string("MC matching to status==1 muons"),
0248 )
0249
0250 muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons )
0251 muonMCTask = cms.Task(muonsMCMatchForTable,muonMCTable)
0252 muonTablesTask = cms.Task(muonPROMPTMVA,muonMVALowPt,muonBSConstrain,muonTable,muonMVAID)
0253