Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-04 01:26:10

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 from PhysicsTools.NanoAOD.nano_eras_cff import *
0004 from PhysicsTools.NanoAOD.common_cff import *
0005 import PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi
0006 
0007 # this below is used only in some eras
0008 slimmedMuonsUpdated = cms.EDProducer("PATMuonUpdater",
0009     src = cms.InputTag("slimmedMuons"),
0010     vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
0011     computeMiniIso = cms.bool(False),
0012     fixDxySign = cms.bool(True),
0013     pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
0014     miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams, # so they're in sync
0015     recomputeMuonBasicSelectors = cms.bool(False),
0016 )
0017 run2_miniAOD_80XLegacy.toModify( slimmedMuonsUpdated, computeMiniIso = True, recomputeMuonBasicSelectors = True )
0018 
0019 isoForMu = cms.EDProducer("MuonIsoValueMapProducer",
0020     src = cms.InputTag("slimmedMuonsUpdated"),
0021     relative = cms.bool(False),
0022     rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
0023     EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
0024 )
0025 run2_miniAOD_80XLegacy.toModify(isoForMu, EAFile_MiniIso = "PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
0026 run2_nanoAOD_94X2016.toModify(isoForMu, EAFile_MiniIso = "PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
0027 
0028 ptRatioRelForMu = cms.EDProducer("MuonJetVarProducer",
0029     srcJet = cms.InputTag("updatedJetsPuppi"),
0030     srcLep = cms.InputTag("slimmedMuonsUpdated"),
0031     srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
0032 )
0033 
0034 slimmedMuonsWithUserData = cms.EDProducer("PATMuonUserDataEmbedder",
0035      src = cms.InputTag("slimmedMuonsUpdated"),
0036      userFloats = cms.PSet(
0037         miniIsoChg = cms.InputTag("isoForMu:miniIsoChg"),
0038         miniIsoAll = cms.InputTag("isoForMu:miniIsoAll"),
0039         ptRatio = cms.InputTag("ptRatioRelForMu:ptRatio"),
0040         ptRel = cms.InputTag("ptRatioRelForMu:ptRel"),
0041         jetNDauChargedMVASel = cms.InputTag("ptRatioRelForMu:jetNDauChargedMVASel"),
0042      ),
0043      userCands = cms.PSet(
0044         jetForLepJetVar = cms.InputTag("ptRatioRelForMu:jetForLepJetVar") # warning: Ptr is null if no match is found
0045      ),
0046 )
0047 
0048 finalMuons = cms.EDFilter("PATMuonRefSelector",
0049     src = cms.InputTag("slimmedMuonsWithUserData"),
0050     cut = cms.string("pt > 15 || (pt > 3 && (passed('CutBasedIdLoose') || passed('SoftCutBasedId') || passed('SoftMvaId') || passed('CutBasedIdGlobalHighPt') || passed('CutBasedIdTrkHighPt')))")
0051 )
0052 
0053 finalLooseMuons = cms.EDFilter("PATMuonRefSelector", # for isotrack cleaning
0054     src = cms.InputTag("slimmedMuonsWithUserData"),
0055     cut = cms.string("pt > 3 && track.isNonnull && isLooseMuon")
0056 )
0057 
0058 muonMVATTH= cms.EDProducer("MuonBaseMVAValueMapProducer",
0059     src = cms.InputTag("linkedObjects","muons"),
0060     weightFile =  cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"),
0061     name = cms.string("muonMVATTH"),
0062     isClassifier = cms.bool(True),
0063     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"]),
0064     variables = cms.PSet(
0065         LepGood_pt = cms.string("pt"),
0066         LepGood_eta = cms.string("eta"),
0067         LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
0068         LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"),
0069         LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
0070         LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
0071         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"),
0072         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)"),
0073         LepGood_dxy = cms.string("log(abs(dB('PV2D')))"),
0074         LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
0075         LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
0076         LepGood_segmentComp = cms.string("segmentCompatibility"),
0077 
0078     )
0079 )
0080 
0081 muonMVALowPt = muonMVATTH.clone(
0082     weightFile =  cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_lowpt.weights.xml"),
0083     name = cms.string("muonMVALowPt"),
0084 )
0085 
0086 run2_muon_2016.toModify(muonMVATTH,
0087         weightFile = "PhysicsTools/NanoAOD/data/mu_BDTG_2016.weights.xml",
0088     )
0089 
0090 muonTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
0091     src = cms.InputTag("linkedObjects","muons"),
0092     cut = cms.string(""), #we should not filter on cross linked collections
0093     name = cms.string("Muon"),
0094     doc  = cms.string("slimmedMuons after basic selection (" + finalMuons.cut.value()+")"),
0095     singleton = cms.bool(False), # the number of entries is variable
0096     extension = cms.bool(False), # this is the main table for the muons
0097     variables = cms.PSet(CandVars,
0098         ptErr   = Var("bestTrack().ptError()", float, doc = "ptError of the muon track", precision=6),
0099         tunepRelPt = Var("tunePMuonBestTrack().pt/pt",float,doc="TuneP relative pt, tunePpt/pt",precision=6),
0100         dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
0101         dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
0102         dxybs = Var("dB('BS2D')",float,doc="dxy (with sign) wrt the beam spot, in cm",precision=10),
0103         dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
0104         dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
0105         ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
0106         sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV",precision=10),
0107         segmentComp   = Var("segmentCompatibility()", float, doc = "muon segment compatibility", precision=14), # keep higher precision since people have cuts with 3 digits on this
0108         nStations = Var("numberOfMatchedStations", int, doc = "number of matched stations with default arbitration (segment & track)"),
0109         nTrackerLayers = Var("?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0", int, doc = "number of layers in the tracker"),
0110         highPurity = Var("?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc = "inner track is high purity"),
0111         jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
0112         tkRelIso = Var("isolationR03().sumPt/tunePMuonBestTrack().pt",float,doc="Tracker-based relative isolation dR=0.3 for highPt, trkIso/tunePpt",precision=6),
0113         miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"),
0114         miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
0115         pfRelIso03_chg = Var("pfIsolationR03().sumChargedHadronPt/pt",float,doc="PF relative isolation dR=0.3, charged component"),
0116         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)"),
0117         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)"),
0118         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),
0119         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),
0120         tightCharge = Var("?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",int,doc="Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
0121         looseId  = Var("passed('CutBasedIdLoose')",bool, doc="muon is loose muon"),
0122         isPFcand = Var("isPFMuon",bool,doc="muon is PF candidate"),
0123         isGlobal = Var("isGlobalMuon",bool,doc="muon is global muon"),
0124         isTracker = Var("isTrackerMuon",bool,doc="muon is tracker muon"),
0125         isStandalone = Var("isStandAloneMuon",bool,doc="muon is a standalone muon"),
0126         mediumId = Var("passed('CutBasedIdMedium')",bool,doc="cut-based ID, medium WP"),
0127         mediumPromptId = Var("passed('CutBasedIdMediumPrompt')",bool,doc="cut-based ID, medium prompt WP"),
0128         tightId = Var("passed('CutBasedIdTight')",bool,doc="cut-based ID, tight WP"),
0129         softId = Var("passed('SoftCutBasedId')",bool,doc="soft cut-based ID"),
0130         softMvaId = Var("passed('SoftMvaId')",bool,doc="soft MVA ID"),
0131         softMva = Var("softMvaValue()",float,doc="soft MVA ID score",precision=6),
0132         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)"),
0133         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)"),
0134         tkIsoId = Var("?passed('TkIsoTight')?2:passed('TkIsoLoose')","uint8",doc="TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
0135         mvaId = Var("passed('MvaLoose')+passed('MvaMedium')+passed('MvaTight')+passed('MvaVTight')+passed('MvaVVTight')","uint8",doc="Mva ID from miniAOD selector (1=MvaLoose, 2=MvaMedium, 3=MvaTight, 4=MvaVTight, 5=MvaVVTight)"),
0136         mvaLowPtId = Var("passed('LowPtMvaLoose')+passed('LowPtMvaMedium')","uint8", doc="Low Pt Mva ID from miniAOD selector (1=LowPtMvaLoose, 2=LowPtMvaMedium)"),
0137         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)"),
0138         multiIsoId = Var("?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')","uint8",doc="MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
0139         puppiIsoId = Var("passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')", "uint8", doc="PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
0140         triggerIdLoose = Var("passed('TriggerIdLoose')",bool,doc="TriggerIdLoose ID"), 
0141         inTimeMuon = Var("passed('InTimeMuon')",bool,doc="inTimeMuon ID"),
0142         jetNDauCharged = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0", "uint8", doc="number of charged daughters of the closest jet"),
0143         ),
0144     externalVariables = cms.PSet(
0145         mvaTTH = ExtVar(cms.InputTag("muonMVATTH"),float, doc="TTH MVA lepton ID score",precision=14),
0146         mvaLowPt = ExtVar(cms.InputTag("muonMVALowPt"),float, doc="Low pt muon ID score",precision=14),
0147         fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:muFsrIndex"),int, doc="Index of the lowest-dR/ET2 among associated FSR photons"),
0148     ),
0149 )
0150 
0151 
0152 for modifier in  run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
0153     modifier.toModify(muonTable.variables, puppiIsoId = None, softMva = None)
0154 
0155 run2_nanoAOD_102Xv1.toModify(muonTable.variables, puppiIsoId = None)
0156 
0157 # Revert back to AK4 CHS jets for Run 2
0158 run2_nanoAOD_ANY.toModify(ptRatioRelForMu,srcJet="updatedJets")
0159 
0160 
0161 muonsMCMatchForTable = cms.EDProducer("MCMatcher",       # cut on deltaR, deltaPt/Pt; pick best by deltaR
0162     src         = muonTable.src,                         # final reco collection
0163     matched     = cms.InputTag("finalGenParticles"),     # final mc-truth particle collection
0164     mcPdgId     = cms.vint32(13),               # one or more PDG ID (13 = mu); absolute values (see below)
0165     checkCharge = cms.bool(False),              # True = require RECO and MC objects to have the same charge
0166     mcStatus    = cms.vint32(1),                # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
0167     maxDeltaR   = cms.double(0.3),              # Minimum deltaR for the match
0168     maxDPtRel   = cms.double(0.5),              # Minimum deltaPt/Pt for the match
0169     resolveAmbiguities    = cms.bool(True),     # Forbid two RECO objects to match to the same GEN object
0170     resolveByMatchQuality = cms.bool(True),    # False = just match input in order; True = pick lowest deltaR pair first
0171 )
0172 
0173 muonMCTable = cms.EDProducer("CandMCMatchTableProducer",
0174     src     = muonTable.src,
0175     mcMap   = cms.InputTag("muonsMCMatchForTable"),
0176     objName = muonTable.name,
0177     objType = muonTable.name, #cms.string("Muon"),
0178     branchName = cms.string("genPart"),
0179     docString = cms.string("MC matching to status==1 muons"),
0180 )
0181 
0182 muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons )
0183 muonMCTask = cms.Task(muonsMCMatchForTable,muonMCTable)
0184 muonTablesTask = cms.Task(muonMVATTH,muonMVALowPt,muonTable)