1 import FWCore.ParameterSet.Config
as cms
2 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff
import run2_miniAOD_80XLegacy
3 from Configuration.Eras.Modifier_run2_nanoAOD_92X_cff
import run2_nanoAOD_92X
4 from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff
import run2_nanoAOD_94X2016
9 slimmedMuonsUpdated = cms.EDProducer(
"PATMuonUpdater",
10 src = cms.InputTag(
"slimmedMuons"),
11 vertices = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
12 computeMiniIso = cms.bool(
False),
13 pfCandsForMiniIso = cms.InputTag(
"packedPFCandidates"),
14 miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams,
15 recomputeMuonBasicSelectors = cms.bool(
False),
17 run2_nanoAOD_92X.toModify( slimmedMuonsUpdated, recomputeMuonBasicSelectors =
True )
18 run2_miniAOD_80XLegacy.toModify( slimmedMuonsUpdated, computeMiniIso =
True, recomputeMuonBasicSelectors =
True )
20 isoForMu = cms.EDProducer(
"MuonIsoValueMapProducer",
21 src = cms.InputTag(
"slimmedMuons"),
22 relative = cms.bool(
False),
23 rho_MiniIso = cms.InputTag(
"fixedGridRhoFastjetAll"),
24 EAFile_MiniIso = cms.FileInPath(
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
26 run2_miniAOD_80XLegacy.toModify(isoForMu, src =
"slimmedMuonsUpdated", EAFile_MiniIso =
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
27 run2_nanoAOD_94X2016.toModify(isoForMu, EAFile_MiniIso =
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
28 run2_nanoAOD_92X.toModify(isoForMu, src =
"slimmedMuonsUpdated")
30 ptRatioRelForMu = cms.EDProducer(
"MuonJetVarProducer",
31 srcJet = cms.InputTag(
"updatedJets"),
32 srcLep = cms.InputTag(
"slimmedMuons"),
33 srcVtx = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
35 run2_miniAOD_80XLegacy.toModify(ptRatioRelForMu, srcLep =
"slimmedMuonsUpdated")
36 run2_nanoAOD_92X.toModify(ptRatioRelForMu, srcLep =
"slimmedMuonsUpdated")
38 slimmedMuonsWithUserData = cms.EDProducer(
"PATMuonUserDataEmbedder",
39 src = cms.InputTag(
"slimmedMuons"),
40 userFloats = cms.PSet(
41 miniIsoChg = cms.InputTag(
"isoForMu:miniIsoChg"),
42 miniIsoAll = cms.InputTag(
"isoForMu:miniIsoAll"),
43 ptRatio = cms.InputTag(
"ptRatioRelForMu:ptRatio"),
44 ptRel = cms.InputTag(
"ptRatioRelForMu:ptRel"),
45 jetNDauChargedMVASel = cms.InputTag(
"ptRatioRelForMu:jetNDauChargedMVASel"),
48 jetForLepJetVar = cms.InputTag(
"ptRatioRelForMu:jetForLepJetVar")
51 run2_miniAOD_80XLegacy.toModify(slimmedMuonsWithUserData, src =
"slimmedMuonsUpdated")
52 run2_nanoAOD_92X.toModify(slimmedMuonsWithUserData, src =
"slimmedMuonsUpdated")
54 finalMuons = cms.EDFilter(
"PATMuonRefSelector",
55 src = cms.InputTag(
"slimmedMuonsWithUserData"),
56 cut = cms.string(
"pt > 3 && track.isNonnull && isLooseMuon")
59 muonMVATTH= cms.EDProducer(
"MuonBaseMVAValueMapProducer",
60 src = cms.InputTag(
"linkedObjects",
"muons"),
61 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_94X.weights.xml"),
62 name = cms.string(
"muonMVATTH"),
63 isClassifier = cms.bool(
True),
64 variablesOrder = cms.vstring([
"LepGood_pt",
"LepGood_eta",
"LepGood_jetNDauChargedMVASel",
"LepGood_miniRelIsoCharged",
"LepGood_miniRelIsoNeutral",
"LepGood_jetPtRelv2",
"LepGood_jetBTagCSV",
"LepGood_jetPtRatio",
"LepGood_sip3d",
"LepGood_dxy",
"LepGood_dz",
"LepGood_segmentCompatibility"]),
66 LepGood_pt = cms.string(
"pt"),
67 LepGood_eta = cms.string(
"eta"),
68 LepGood_jetNDauChargedMVASel = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
69 LepGood_miniRelIsoCharged = cms.string(
"userFloat('miniIsoChg')/pt"),
70 LepGood_miniRelIsoNeutral = cms.string(
"(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
71 LepGood_jetPtRelv2 = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
72 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)"),
73 LepGood_jetBTagCSV = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags'),0.0):0.0"),
74 LepGood_sip3d = cms.string(
"abs(dB('PV3D')/edB('PV3D'))"),
75 LepGood_dxy = cms.string(
"log(abs(dB('PV2D')))"),
76 LepGood_dz = cms.string(
"log(abs(dB('PVDZ')))"),
77 LepGood_segmentCompatibility = cms.string(
"segmentCompatibility"),
81 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
82 modifier.toModify(muonMVATTH.variables,
83 LepGood_jetPtRatio = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1"),
85 modifier.toModify(muonMVATTH,
86 weightFile =
"PhysicsTools/NanoAOD/data/mu_BDTG.weights.xml",
87 variablesOrder = [
"LepGood_pt",
"LepGood_eta",
"LepGood_jetNDauChargedMVASel",
"LepGood_miniRelIsoCharged",
"LepGood_miniRelIsoNeutral",
"LepGood_jetPtRelv2",
"LepGood_jetPtRatio",
"LepGood_jetBTagCSV",
"LepGood_sip3d",
"LepGood_dxy",
"LepGood_dz",
"LepGood_segmentCompatibility"],
90 muonTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
91 src = cms.InputTag(
"linkedObjects",
"muons"),
93 name = cms.string(
"Muon"),
94 doc = cms.string(
"slimmedMuons after basic selection (" + finalMuons.cut.value()+
")"),
95 singleton = cms.bool(
False),
96 extension = cms.bool(
False),
97 variables = cms.PSet(CandVars,
98 ptErr =
Var(
"bestTrack().ptError()", float, doc =
"ptError of the muon track", precision=6),
99 dz =
Var(
"dB('PVDZ')",float,doc=
"dz (with sign) wrt first PV, in cm",precision=10),
100 dzErr =
Var(
"abs(edB('PVDZ'))",float,doc=
"dz uncertainty, in cm",precision=6),
101 dxy =
Var(
"dB('PV2D')",float,doc=
"dxy (with sign) wrt first PV, in cm",precision=10),
102 dxyErr =
Var(
"edB('PV2D')",float,doc=
"dxy uncertainty, in cm",precision=6),
103 ip3d =
Var(
"abs(dB('PV3D'))",float,doc=
"3D impact parameter wrt first PV, in cm",precision=10),
104 sip3d =
Var(
"abs(dB('PV3D')/edB('PV3D'))",float,doc=
"3D impact parameter significance wrt first PV",precision=10),
105 segmentComp =
Var(
"segmentCompatibility()", float, doc =
"muon segment compatibility", precision=14),
106 nStations =
Var(
"numberOfMatchedStations", int, doc =
"number of matched stations with default arbitration (segment & track)"),
107 nTrackerLayers =
Var(
"innerTrack().hitPattern().trackerLayersWithMeasurement()", int, doc =
"number of layers in the tracker"),
108 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1", int, doc=
"index of the associated jet (-1 if none)"),
109 miniPFRelIso_chg =
Var(
"userFloat('miniIsoChg')/pt",float,doc=
"mini PF relative isolation, charged component"),
110 miniPFRelIso_all =
Var(
"userFloat('miniIsoAll')/pt",float,doc=
"mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
111 pfRelIso03_chg =
Var(
"pfIsolationR03().sumChargedHadronPt/pt",float,doc=
"PF relative isolation dR=0.3, charged component"),
112 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)"),
113 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)"),
114 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),
115 tightCharge =
Var(
"?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",int,doc=
"Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
116 isPFcand =
Var(
"isPFMuon",bool,doc=
"muon is PF candidate"),
117 isGlobal =
Var(
"isGlobalMuon",bool,doc=
"muon is global muon"),
118 isTracker =
Var(
"isTrackerMuon",bool,doc=
"muon is tracker muon"),
119 mediumId =
Var(
"passed('CutBasedIdMedium')",bool,doc=
"cut-based ID, medium WP"),
120 mediumPromptId =
Var(
"passed('CutBasedIdMediumPrompt')",bool,doc=
"cut-based ID, medium prompt WP"),
121 tightId =
Var(
"passed('CutBasedIdTight')",bool,doc=
"cut-based ID, tight WP"),
122 softId =
Var(
"passed('SoftCutBasedId')",bool,doc=
"soft cut-based ID"),
123 softMvaId =
Var(
"passed('SoftMvaId')",bool,doc=
"soft MVA ID"),
124 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)"),
125 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)"),
126 tkIsoId =
Var(
"?passed('TkIsoTight')?2:passed('TkIsoLoose')",
"uint8",doc=
"TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
127 mvaId =
Var(
"passed('MvaLoose')+passed('MvaMedium')+passed('MvaTight')",
"uint8",doc=
"Mva ID from miniAOD selector (1=MvaLoose, 2=MvaMedium, 3=MvaTight)"),
128 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)"),
129 multiIsoId =
Var(
"?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')",
"uint8",doc=
"MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
130 triggerIdLoose =
Var(
"passed('TriggerIdLoose')",bool,doc=
"TriggerIdLoose ID"),
131 inTimeMuon =
Var(
"passed('InTimeMuon')",bool,doc=
"inTimeMuon ID"),
133 externalVariables = cms.PSet(
134 mvaTTH =
ExtVar(cms.InputTag(
"muonMVATTH"),float, doc=
"TTH MVA lepton ID score",precision=14),
138 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
139 modifier.toModify(muonTable.variables,
140 jetRelIso =
Var(
"(1./userFloat('ptRatio'))-1.",float,doc=
"Relative isolation in matched jet (1/ptRatio-1, 0 if no matched jet (2016 definition))",precision=8),
143 muonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
145 matched = cms.InputTag(
"finalGenParticles"),
146 mcPdgId = cms.vint32(13),
147 checkCharge = cms.bool(
False),
148 mcStatus = cms.vint32(1),
149 maxDeltaR = cms.double(0.3),
150 maxDPtRel = cms.double(0.5),
151 resolveAmbiguities = cms.bool(
True),
152 resolveByMatchQuality = cms.bool(
True),
155 muonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
157 mcMap = cms.InputTag(
"muonsMCMatchForTable"),
158 objName = muonTable.name,
159 objType = muonTable.name,
160 branchName = cms.string(
"genPart"),
161 docString = cms.string(
"MC matching to status==1 muons"),
164 muonSequence = cms.Sequence(isoForMu + ptRatioRelForMu + slimmedMuonsWithUserData + finalMuons)
165 muonMC = cms.Sequence(muonsMCMatchForTable + muonMCTable)
166 muonTables = cms.Sequence(muonMVATTH + muonTable)
168 _withUpdate_sequence = muonSequence.copy()
169 _withUpdate_sequence.replace(isoForMu, slimmedMuonsUpdated+isoForMu)
170 run2_nanoAOD_92X.toReplaceWith(muonSequence, _withUpdate_sequence)
171 run2_miniAOD_80XLegacy.toReplaceWith(muonSequence, _withUpdate_sequence)
def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)