1 import FWCore.ParameterSet.Config
as cms
2 from Configuration.Eras.Modifier_run2_muon_2016_cff
import run2_muon_2016
3 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff
import run2_miniAOD_80XLegacy
4 from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff
import run2_nanoAOD_94X2016
5 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv1_cff
import run2_nanoAOD_94XMiniAODv1
6 from Configuration.Eras.Modifier_run2_nanoAOD_94XMiniAODv2_cff
import run2_nanoAOD_94XMiniAODv2
7 from Configuration.Eras.Modifier_run2_nanoAOD_102Xv1_cff
import run2_nanoAOD_102Xv1
12 slimmedMuonsUpdated = cms.EDProducer(
"PATMuonUpdater",
13 src = cms.InputTag(
"slimmedMuons"),
14 vertices = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
15 computeMiniIso = cms.bool(
False),
16 pfCandsForMiniIso = cms.InputTag(
"packedPFCandidates"),
17 miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams,
18 recomputeMuonBasicSelectors = cms.bool(
False),
20 run2_miniAOD_80XLegacy.toModify( slimmedMuonsUpdated, computeMiniIso =
True, recomputeMuonBasicSelectors =
True )
22 isoForMu = cms.EDProducer(
"MuonIsoValueMapProducer",
23 src = cms.InputTag(
"slimmedMuons"),
24 relative = cms.bool(
False),
25 rho_MiniIso = cms.InputTag(
"fixedGridRhoFastjetAll"),
26 EAFile_MiniIso = cms.FileInPath(
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
28 run2_miniAOD_80XLegacy.toModify(isoForMu, src =
"slimmedMuonsUpdated", EAFile_MiniIso =
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
29 run2_nanoAOD_94X2016.toModify(isoForMu, EAFile_MiniIso =
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
31 ptRatioRelForMu = cms.EDProducer(
"MuonJetVarProducer",
32 srcJet = cms.InputTag(
"updatedJets"),
33 srcLep = cms.InputTag(
"slimmedMuons"),
34 srcVtx = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
36 run2_miniAOD_80XLegacy.toModify(ptRatioRelForMu, srcLep =
"slimmedMuonsUpdated")
39 slimmedMuonsWithUserData = cms.EDProducer(
"PATMuonUserDataEmbedder",
40 src = cms.InputTag(
"slimmedMuons"),
41 userFloats = cms.PSet(
42 miniIsoChg = cms.InputTag(
"isoForMu:miniIsoChg"),
43 miniIsoAll = cms.InputTag(
"isoForMu:miniIsoAll"),
44 ptRatio = cms.InputTag(
"ptRatioRelForMu:ptRatio"),
45 ptRel = cms.InputTag(
"ptRatioRelForMu:ptRel"),
46 jetNDauChargedMVASel = cms.InputTag(
"ptRatioRelForMu:jetNDauChargedMVASel"),
49 jetForLepJetVar = cms.InputTag(
"ptRatioRelForMu:jetForLepJetVar")
52 run2_miniAOD_80XLegacy.toModify(slimmedMuonsWithUserData, src =
"slimmedMuonsUpdated")
54 finalMuons = cms.EDFilter(
"PATMuonRefSelector",
55 src = cms.InputTag(
"slimmedMuonsWithUserData"),
56 cut = cms.string(
"pt > 3 && (passed('CutBasedIdLoose') || passed('SoftCutBasedId') || passed('SoftMvaId') || passed('CutBasedIdGlobalHighPt') || passed('CutBasedIdTrkHighPt'))")
59 finalLooseMuons = cms.EDFilter(
"PATMuonRefSelector",
60 src = cms.InputTag(
"slimmedMuonsWithUserData"),
61 cut = cms.string(
"pt > 3 && track.isNonnull && isLooseMuon")
64 muonMVATTH= cms.EDProducer(
"MuonBaseMVAValueMapProducer",
65 src = cms.InputTag(
"linkedObjects",
"muons"),
66 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"),
67 name = cms.string(
"muonMVATTH"),
68 isClassifier = cms.bool(
True),
69 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"]),
71 LepGood_pt = cms.string(
"pt"),
72 LepGood_eta = cms.string(
"eta"),
73 LepGood_jetNDauChargedMVASel = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
74 LepGood_miniRelIsoCharged = cms.string(
"userFloat('miniIsoChg')/pt"),
75 LepGood_miniRelIsoNeutral = cms.string(
"(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
76 LepGood_jetPtRelv2 = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
77 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"),
78 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)"),
79 LepGood_dxy = cms.string(
"log(abs(dB('PV2D')))"),
80 LepGood_sip3d = cms.string(
"abs(dB('PV3D')/edB('PV3D'))"),
81 LepGood_dz = cms.string(
"log(abs(dB('PVDZ')))"),
82 LepGood_segmentComp = cms.string(
"segmentCompatibility"),
87 muonMVALowPt = muonMVATTH.clone(
88 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_lowpt.weights.xml"),
89 name = cms.string(
"muonMVALowPt"),
92 run2_muon_2016.toModify(muonMVATTH,
93 weightFile =
"PhysicsTools/NanoAOD/data/mu_BDTG_2016.weights.xml",
96 from MuonAnalysis.MuonAssociators.muonFSRProducer_cfi
import muonFSRProducer
97 muonFSRphotons = muonFSRProducer.clone(
98 packedPFCandidates = cms.InputTag(
"packedPFCandidates"),
99 slimmedElectrons = cms.InputTag(
"slimmedElectrons"),
100 muons = cms.InputTag(
"linkedObjects",
"muons"),
102 from MuonAnalysis.MuonAssociators.muonFSRAssociator_cfi
import muonFSRAssociator
103 muonFSRassociation = muonFSRAssociator.clone(
104 photons = cms.InputTag(
"muonFSRphotons"),
105 muons = cms.InputTag(
"linkedObjects",
"muons"),
108 fsrTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
109 src = cms.InputTag(
"muonFSRphotons"),
110 cut = cms.string(
""),
111 name = cms.string(
"FsrPhoton"),
112 doc = cms.string(
"Final state radiation photons emitted by muons"),
113 singleton = cms.bool(
False),
114 extension = cms.bool(
False),
115 variables = cms.PSet(P3Vars,
116 relIso03 =
Var(
"userFloat('relIso03')",float,doc=
"relative isolation in a 0.3 cone without CHS"),
117 dROverEt2 =
Var(
"userFloat('dROverEt2')",float,doc=
"deltaR to associated muon divided by photon et2"),
118 muonIdx =
Var(
"?hasUserCand('associatedMuon')?userCand('associatedMuon').key():-1",int, doc=
"index of associated muon")
122 muonTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
123 src = cms.InputTag(
"linkedObjects",
"muons"),
124 cut = cms.string(
""),
125 name = cms.string(
"Muon"),
126 doc = cms.string(
"slimmedMuons after basic selection (" + finalMuons.cut.value()+
")"),
127 singleton = cms.bool(
False),
128 extension = cms.bool(
False),
129 variables = cms.PSet(CandVars,
130 ptErr =
Var(
"bestTrack().ptError()", float, doc =
"ptError of the muon track", precision=6),
131 tunepRelPt =
Var(
"tunePMuonBestTrack().pt/pt",float,doc=
"TuneP relative pt, tunePpt/pt",precision=6),
132 dz =
Var(
"dB('PVDZ')",float,doc=
"dz (with sign) wrt first PV, in cm",precision=10),
133 dzErr =
Var(
"abs(edB('PVDZ'))",float,doc=
"dz uncertainty, in cm",precision=6),
134 dxy =
Var(
"dB('PV2D')",float,doc=
"dxy (with sign) wrt first PV, in cm",precision=10),
135 dxyErr =
Var(
"edB('PV2D')",float,doc=
"dxy uncertainty, in cm",precision=6),
136 ip3d =
Var(
"abs(dB('PV3D'))",float,doc=
"3D impact parameter wrt first PV, in cm",precision=10),
137 sip3d =
Var(
"abs(dB('PV3D')/edB('PV3D'))",float,doc=
"3D impact parameter significance wrt first PV",precision=10),
138 segmentComp =
Var(
"segmentCompatibility()", float, doc =
"muon segment compatibility", precision=14),
139 nStations =
Var(
"numberOfMatchedStations", int, doc =
"number of matched stations with default arbitration (segment & track)"),
140 nTrackerLayers =
Var(
"?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0", int, doc =
"number of layers in the tracker"),
141 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1", int, doc=
"index of the associated jet (-1 if none)"),
142 tkRelIso =
Var(
"isolationR03().sumPt/tunePMuonBestTrack().pt",float,doc=
"Tracker-based relative isolation dR=0.3 for highPt, trkIso/tunePpt",precision=6),
143 miniPFRelIso_chg =
Var(
"userFloat('miniIsoChg')/pt",float,doc=
"mini PF relative isolation, charged component"),
144 miniPFRelIso_all =
Var(
"userFloat('miniIsoAll')/pt",float,doc=
"mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
145 pfRelIso03_chg =
Var(
"pfIsolationR03().sumChargedHadronPt/pt",float,doc=
"PF relative isolation dR=0.3, charged component"),
146 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)"),
147 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)"),
148 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),
149 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),
150 tightCharge =
Var(
"?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",int,doc=
"Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
151 looseId =
Var(
"passed('CutBasedIdLoose')",bool, doc=
"muon is loose muon"),
152 isPFcand =
Var(
"isPFMuon",bool,doc=
"muon is PF candidate"),
153 isGlobal =
Var(
"isGlobalMuon",bool,doc=
"muon is global muon"),
154 isTracker =
Var(
"isTrackerMuon",bool,doc=
"muon is tracker muon"),
155 mediumId =
Var(
"passed('CutBasedIdMedium')",bool,doc=
"cut-based ID, medium WP"),
156 mediumPromptId =
Var(
"passed('CutBasedIdMediumPrompt')",bool,doc=
"cut-based ID, medium prompt WP"),
157 tightId =
Var(
"passed('CutBasedIdTight')",bool,doc=
"cut-based ID, tight WP"),
158 softId =
Var(
"passed('SoftCutBasedId')",bool,doc=
"soft cut-based ID"),
159 softMvaId =
Var(
"passed('SoftMvaId')",bool,doc=
"soft MVA ID"),
160 softMva =
Var(
"softMvaValue()",float,doc=
"soft MVA ID score",precision=6),
161 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)"),
162 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)"),
163 tkIsoId =
Var(
"?passed('TkIsoTight')?2:passed('TkIsoLoose')",
"uint8",doc=
"TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
164 mvaId =
Var(
"passed('MvaLoose')+passed('MvaMedium')+passed('MvaTight')",
"uint8",doc=
"Mva ID from miniAOD selector (1=MvaLoose, 2=MvaMedium, 3=MvaTight)"),
165 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)"),
166 multiIsoId =
Var(
"?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')",
"uint8",doc=
"MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
167 puppiIsoId =
Var(
"passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')",
"uint8", doc=
"PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
168 triggerIdLoose =
Var(
"passed('TriggerIdLoose')",bool,doc=
"TriggerIdLoose ID"),
169 inTimeMuon =
Var(
"passed('InTimeMuon')",bool,doc=
"inTimeMuon ID"),
171 externalVariables = cms.PSet(
172 mvaTTH =
ExtVar(cms.InputTag(
"muonMVATTH"),float, doc=
"TTH MVA lepton ID score",precision=14),
173 mvaLowPt =
ExtVar(cms.InputTag(
"muonMVALowPt"),float, doc=
"Low pt muon ID score",precision=14),
174 fsrPhotonIdx =
ExtVar(cms.InputTag(
"muonFSRassociation:fsrIndex"),int, doc=
"Index of the associated FSR photon"),
179 for modifier
in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
180 modifier.toModify(muonTable.variables, puppiIsoId =
None, softMva =
None)
182 run2_nanoAOD_102Xv1.toModify(muonTable.variables, puppiIsoId =
None)
185 muonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
187 matched = cms.InputTag(
"finalGenParticles"),
188 mcPdgId = cms.vint32(13),
189 checkCharge = cms.bool(
False),
190 mcStatus = cms.vint32(1),
191 maxDeltaR = cms.double(0.3),
192 maxDPtRel = cms.double(0.5),
193 resolveAmbiguities = cms.bool(
True),
194 resolveByMatchQuality = cms.bool(
True),
197 muonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
199 mcMap = cms.InputTag(
"muonsMCMatchForTable"),
200 objName = muonTable.name,
201 objType = muonTable.name,
202 branchName = cms.string(
"genPart"),
203 docString = cms.string(
"MC matching to status==1 muons"),
206 muonSequence = cms.Sequence(isoForMu + ptRatioRelForMu + slimmedMuonsWithUserData + finalMuons + finalLooseMuons )
207 muonMC = cms.Sequence(muonsMCMatchForTable + muonMCTable)
208 muonTables = cms.Sequence(muonFSRphotons + muonFSRassociation + muonMVATTH + muonMVALowPt + muonTable + fsrTable)
210 _withUpdate_sequence = muonSequence.copy()
211 _withUpdate_sequence.replace(isoForMu, slimmedMuonsUpdated+isoForMu)
212 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)