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
8 slimmedMuonsUpdated = cms.EDProducer(
"PATMuonUpdater",
9 src = cms.InputTag(
"slimmedMuons"),
10 vertices = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
11 computeMiniIso = cms.bool(
False),
12 pfCandsForMiniIso = cms.InputTag(
"packedPFCandidates"),
13 miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams,
14 recomputeMuonBasicSelectors = cms.bool(
False),
16 run2_nanoAOD_92X.toModify( slimmedMuonsUpdated, recomputeMuonBasicSelectors =
True )
17 run2_miniAOD_80XLegacy.toModify( slimmedMuonsUpdated, computeMiniIso =
True, recomputeMuonBasicSelectors =
True )
19 isoForMu = cms.EDProducer(
"MuonIsoValueMapProducer",
20 src = cms.InputTag(
"slimmedMuons"),
21 relative = cms.bool(
False),
22 rho_MiniIso = cms.InputTag(
"fixedGridRhoFastjetAll"),
23 EAFile_MiniIso = cms.FileInPath(
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
25 run2_miniAOD_80XLegacy.toModify(isoForMu, src =
"slimmedMuonsUpdated", EAFile_MiniIso =
"PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
26 run2_nanoAOD_92X.toModify(isoForMu, src =
"slimmedMuonsUpdated")
28 ptRatioRelForMu = cms.EDProducer(
"MuonJetVarProducer",
29 srcJet = cms.InputTag(
"updatedJets"),
30 srcLep = cms.InputTag(
"slimmedMuons"),
31 srcVtx = cms.InputTag(
"offlineSlimmedPrimaryVertices"),
33 run2_miniAOD_80XLegacy.toModify(ptRatioRelForMu, srcLep =
"slimmedMuonsUpdated")
34 run2_nanoAOD_92X.toModify(ptRatioRelForMu, srcLep =
"slimmedMuonsUpdated")
36 slimmedMuonsWithUserData = cms.EDProducer(
"PATMuonUserDataEmbedder",
37 src = cms.InputTag(
"slimmedMuons"),
38 userFloats = cms.PSet(
39 miniIsoChg = cms.InputTag(
"isoForMu:miniIsoChg"),
40 miniIsoAll = cms.InputTag(
"isoForMu:miniIsoAll"),
41 ptRatio = cms.InputTag(
"ptRatioRelForMu:ptRatio"),
42 ptRel = cms.InputTag(
"ptRatioRelForMu:ptRel"),
43 jetNDauChargedMVASel = cms.InputTag(
"ptRatioRelForMu:jetNDauChargedMVASel"),
46 jetForLepJetVar = cms.InputTag(
"ptRatioRelForMu:jetForLepJetVar")
49 run2_miniAOD_80XLegacy.toModify(slimmedMuonsWithUserData, src =
"slimmedMuonsUpdated")
50 run2_nanoAOD_92X.toModify(slimmedMuonsWithUserData, src =
"slimmedMuonsUpdated")
52 finalMuons = cms.EDFilter(
"PATMuonRefSelector",
53 src = cms.InputTag(
"slimmedMuonsWithUserData"),
54 cut = cms.string(
"pt > 3 && track.isNonnull && isLooseMuon")
57 muonMVATTH= cms.EDProducer(
"MuonBaseMVAValueMapProducer",
58 src = cms.InputTag(
"linkedObjects",
"muons"),
59 weightFile = cms.FileInPath(
"PhysicsTools/NanoAOD/data/mu_BDTG_94X.weights.xml"),
60 name = cms.string(
"muonMVATTH"),
61 isClassifier = cms.bool(
True),
62 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"]),
64 LepGood_pt = cms.string(
"pt"),
65 LepGood_eta = cms.string(
"eta"),
66 LepGood_jetNDauChargedMVASel = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
67 LepGood_miniRelIsoCharged = cms.string(
"userFloat('miniIsoChg')/pt"),
68 LepGood_miniRelIsoNeutral = cms.string(
"(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
69 LepGood_jetPtRelv2 = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
70 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)"),
71 LepGood_jetBTagCSV = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags'),0.0):0.0"),
72 LepGood_sip3d = cms.string(
"abs(dB('PV3D')/edB('PV3D'))"),
73 LepGood_dxy = cms.string(
"log(abs(dB('PV2D')))"),
74 LepGood_dz = cms.string(
"log(abs(dB('PVDZ')))"),
75 LepGood_segmentCompatibility = cms.string(
"segmentCompatibility"),
78 run2_miniAOD_80XLegacy.toModify(muonMVATTH.variables,
79 LepGood_jetPtRatio = cms.string(
"?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1"),
81 run2_miniAOD_80XLegacy.toModify(muonMVATTH,
82 weightFile =
"PhysicsTools/NanoAOD/data/mu_BDTG.weights.xml",
83 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"],
86 muonTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
87 src = cms.InputTag(
"linkedObjects",
"muons"),
89 name = cms.string(
"Muon"),
90 doc = cms.string(
"slimmedMuons after basic selection (" + finalMuons.cut.value()+
")"),
91 singleton = cms.bool(
False),
92 extension = cms.bool(
False),
93 variables = cms.PSet(CandVars,
94 ptErr =
Var(
"bestTrack().ptError()", float, doc =
"ptError of the muon track", precision=6),
95 dz =
Var(
"dB('PVDZ')",float,doc=
"dz (with sign) wrt first PV, in cm",precision=10),
96 dzErr =
Var(
"abs(edB('PVDZ'))",float,doc=
"dz uncertainty, in cm",precision=6),
97 dxy =
Var(
"dB('PV2D')",float,doc=
"dxy (with sign) wrt first PV, in cm",precision=10),
98 dxyErr =
Var(
"edB('PV2D')",float,doc=
"dxy uncertainty, in cm",precision=6),
99 ip3d =
Var(
"abs(dB('PV3D'))",float,doc=
"3D impact parameter wrt first PV, in cm",precision=10),
100 sip3d =
Var(
"abs(dB('PV3D')/edB('PV3D'))",float,doc=
"3D impact parameter significance wrt first PV",precision=10),
101 segmentComp =
Var(
"segmentCompatibility()", float, doc =
"muon segment compatibility", precision=14),
102 nStations =
Var(
"numberOfMatchedStations", int, doc =
"number of matched stations with default arbitration (segment & track)"),
103 nTrackerLayers =
Var(
"innerTrack().hitPattern().trackerLayersWithMeasurement()", int, doc =
"number of layers in the tracker"),
104 jetIdx =
Var(
"?hasUserCand('jet')?userCand('jet').key():-1", int, doc=
"index of the associated jet (-1 if none)"),
105 miniPFRelIso_chg =
Var(
"userFloat('miniIsoChg')/pt",float,doc=
"mini PF relative isolation, charged component"),
106 miniPFRelIso_all =
Var(
"userFloat('miniIsoAll')/pt",float,doc=
"mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
107 pfRelIso03_chg =
Var(
"pfIsolationR03().sumChargedHadronPt/pt",float,doc=
"PF relative isolation dR=0.3, charged component"),
108 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)"),
109 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)"),
110 tightCharge =
Var(
"?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0",int,doc=
"Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
111 isPFcand =
Var(
"isPFMuon",bool,doc=
"muon is PF candidate"),
112 mediumId =
Var(
"passed('CutBasedIdMedium')",bool,doc=
"cut-based ID, medium WP"),
113 tightId =
Var(
"passed('CutBasedIdTight')",bool,doc=
"cut-based ID, tight WP"),
114 softId =
Var(
"passed('SoftCutBasedId')",bool,doc=
"soft cut-based ID"),
115 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)"),
117 externalVariables = cms.PSet(
118 mvaTTH =
ExtVar(cms.InputTag(
"muonMVATTH"),float, doc=
"TTH MVA lepton ID score",precision=14),
122 muonsMCMatchForTable = cms.EDProducer(
"MCMatcher",
124 matched = cms.InputTag(
"finalGenParticles"),
125 mcPdgId = cms.vint32(13),
126 checkCharge = cms.bool(
False),
127 mcStatus = cms.vint32(1),
128 maxDeltaR = cms.double(0.3),
129 maxDPtRel = cms.double(0.5),
130 resolveAmbiguities = cms.bool(
True),
131 resolveByMatchQuality = cms.bool(
True),
134 muonMCTable = cms.EDProducer(
"CandMCMatchTableProducer",
136 mcMap = cms.InputTag(
"muonsMCMatchForTable"),
137 objName = muonTable.name,
138 objType = muonTable.name,
139 branchName = cms.string(
"genPart"),
140 docString = cms.string(
"MC matching to status==1 muons"),
143 muonSequence = cms.Sequence(isoForMu + ptRatioRelForMu + slimmedMuonsWithUserData + finalMuons)
144 muonMC = cms.Sequence(muonsMCMatchForTable + muonMCTable)
145 muonTables = cms.Sequence(muonMVATTH + muonTable)
147 _withUpdate_sequence = muonSequence.copy()
148 _withUpdate_sequence.replace(isoForMu, slimmedMuonsUpdated+isoForMu)
149 run2_nanoAOD_92X.toReplaceWith(muonSequence, _withUpdate_sequence)
150 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)