CMS 3D CMS Logo

muons_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
5 from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
6 
8 
9 # this below is used only in some eras
10 slimmedMuonsUpdated = cms.EDProducer("PATMuonUpdater",
11  src = cms.InputTag("slimmedMuons"),
12  vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
13  computeMiniIso = cms.bool(False),
14  fixDxySign = cms.bool(True),
15  pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
16  miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams, # so they're in sync
17  recomputeMuonBasicSelectors = cms.bool(False),
18 )
19 
20 isoForMu = cms.EDProducer("MuonIsoValueMapProducer",
21  src = cms.InputTag("slimmedMuonsUpdated"),
22  relative = cms.bool(False),
23  rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
24  EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
25 )
26 
27 ptRatioRelForMu = cms.EDProducer("MuonJetVarProducer",
28  srcJet = cms.InputTag("updatedJetsPuppi"),
29  srcLep = cms.InputTag("slimmedMuonsUpdated"),
30  srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
31 )
32 
33 muonMVAID = cms.EDProducer("EvaluateMuonMVAID",
34  src = cms.InputTag("slimmedMuonsUpdated"),
35  weightFile = cms.FileInPath("RecoMuon/MuonIdentification/data/mvaID.onnx"),
36  isClassifier = cms.bool(False),
37  backend = cms.string('ONNX'),
38  name = cms.string("muonMVAID"),
39  outputTensorName= cms.string("probabilities"),
40  inputTensorName= cms.string("float_input"),
41  outputNames = cms.vstring(["probGOOD", "wpMedium", "wpTight"]),
42  batch_eval =cms.bool(True),
43  outputFormulas = cms.vstring(["at(1)", "? at(1) > 0.08 ? 1 : 0", "? at(1) > 0.20 ? 1 : 0"]),
44  variablesOrder = cms.vstring(["LepGood_global_muon","LepGood_validFraction","Muon_norm_chi2_extended","LepGood_local_chi2","LepGood_kink","LepGood_segmentComp","Muon_n_Valid_hits_extended","LepGood_n_MatchedStations","LepGood_Valid_pixel","LepGood_tracker_layers","LepGood_pt","LepGood_eta"]),
45  variables = cms.PSet(
46  LepGood_global_muon = cms.string("isGlobalMuon"),
47  LepGood_validFraction = cms.string("?innerTrack.isNonnull?innerTrack().validFraction:-99"),
48  LepGood_local_chi2 = cms.string("combinedQuality().chi2LocalPosition"),
49  LepGood_kink = cms.string("combinedQuality().trkKink"),
50  LepGood_segmentComp = cms.string("segmentCompatibility"),
51  LepGood_n_MatchedStations = cms.string("numberOfMatchedStations()"),
52  LepGood_Valid_pixel = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().numberOfValidPixelHits():-99"),
53  LepGood_tracker_layers = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().trackerLayersWithMeasurement():-99"),
54  LepGood_pt = cms.string("pt"),
55  LepGood_eta = cms.string("eta"),
56  )
57 )
58 
59 slimmedMuonsWithUserData = cms.EDProducer("PATMuonUserDataEmbedder",
60  src = cms.InputTag("slimmedMuonsUpdated"),
61  userFloats = cms.PSet(
62  miniIsoChg = cms.InputTag("isoForMu:miniIsoChg"),
63  miniIsoAll = cms.InputTag("isoForMu:miniIsoAll"),
64  ptRatio = cms.InputTag("ptRatioRelForMu:ptRatio"),
65  ptRel = cms.InputTag("ptRatioRelForMu:ptRel"),
66  jetNDauChargedMVASel = cms.InputTag("ptRatioRelForMu:jetNDauChargedMVASel"),
67  mvaIDMuon_wpMedium = cms.InputTag("muonMVAID:wpMedium"),
68  mvaIDMuon_wpTight = cms.InputTag("muonMVAID:wpTight"),
69  mvaIDMuon = cms.InputTag("muonMVAID:probGOOD")
70  ),
71  userCands = cms.PSet(
72  jetForLepJetVar = cms.InputTag("ptRatioRelForMu:jetForLepJetVar") # warning: Ptr is null if no match is found
73  ),
74 )
75 
76 
77 finalMuons = cms.EDFilter("PATMuonRefSelector",
78  src = cms.InputTag("slimmedMuonsWithUserData"),
79  cut = cms.string("pt > 15 || (pt > 3 && (passed('CutBasedIdLoose') || passed('SoftCutBasedId') || passed('SoftMvaId') || passed('CutBasedIdGlobalHighPt') || passed('CutBasedIdTrkHighPt')))")
80 )
81 
82 finalLooseMuons = cms.EDFilter("PATMuonRefSelector", # for isotrack cleaning
83  src = cms.InputTag("slimmedMuonsWithUserData"),
84  cut = cms.string("pt > 3 && track.isNonnull && isLooseMuon")
85 )
86 
87 muonMVATTH= cms.EDProducer("MuonBaseMVAValueMapProducer",
88  src = cms.InputTag("linkedObjects","muons"),
89  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"),
90  name = cms.string("muonMVATTH"),
91  isClassifier = cms.bool(True),
92  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"]),
93  variables = cms.PSet(
94  LepGood_pt = cms.string("pt"),
95  LepGood_eta = cms.string("eta"),
96  LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
97  LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"),
98  LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
99  LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
100  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"),
101  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)"),
102  LepGood_dxy = cms.string("log(abs(dB('PV2D')))"),
103  LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
104  LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
105  LepGood_segmentComp = cms.string("segmentCompatibility"),
106 
107  )
108 )
109 
110 muonMVALowPt = muonMVATTH.clone(
111  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_lowpt.weights.xml"),
112  name = cms.string("muonMVALowPt"),
113 )
114 
115 run2_muon_2016.toModify(
116  muonMVATTH,
117  weightFile = "PhysicsTools/NanoAOD/data/mu_BDTG_2016.weights.xml",
118 )
119 
121 muonBSConstrain = cms.EDProducer("MuonBeamspotConstraintValueMapProducer",
122  src = cms.InputTag("linkedObjects","muons"),
123 )
124 
125 muonTable = simpleCandidateFlatTableProducer.clone(
126  src = cms.InputTag("linkedObjects","muons"),
127  name = cms.string("Muon"),
128  doc = cms.string("slimmedMuons after basic selection (" + finalMuons.cut.value()+")"),
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  dxybs = Var("dB('BS2D')",float,doc="dxy (with sign) wrt the beam spot, in cm",precision=10),
135  dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
136  dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
137  ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
138  sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV",precision=10),
139  segmentComp = Var("segmentCompatibility()", float, doc = "muon segment compatibility", precision=14), # keep higher precision since people have cuts with 3 digits on this
140  nStations = Var("numberOfMatchedStations", "uint8", doc = "number of matched stations with default arbitration (segment & track)"),
141  nTrackerLayers = Var("?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0", "uint8", doc = "number of layers in the tracker"),
142  highPurity = Var("?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc = "inner track is high purity"),
143  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", "int16", doc="index of the associated jet (-1 if none)"),
144  svIdx = Var("?hasUserCand('vertex')?userCand('vertex').key():-1", "int16", doc="index of matching secondary vertex"),
145  tkRelIso = Var("isolationR03().sumPt/tunePMuonBestTrack().pt",float,doc="Tracker-based relative isolation dR=0.3 for highPt, trkIso/tunePpt",precision=6),
146  miniPFRelIso_chg = Var("userFloat('miniIsoChg')/pt",float,doc="mini PF relative isolation, charged component"),
147  miniPFRelIso_all = Var("userFloat('miniIsoAll')/pt",float,doc="mini PF relative isolation, total (with scaled rho*EA PU corrections)"),
148  pfRelIso03_chg = Var("pfIsolationR03().sumChargedHadronPt/pt",float,doc="PF relative isolation dR=0.3, charged component"),
149  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)"),
150  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)"),
151  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),
152  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),
153  tightCharge = Var("?(muonBestTrack().ptError()/muonBestTrack().pt() < 0.2)?2:0", "uint8", doc="Tight charge criterion using pterr/pt of muonBestTrack (0:fail, 2:pass)"),
154  looseId = Var("passed('CutBasedIdLoose')",bool, doc="muon is loose muon"),
155  isPFcand = Var("isPFMuon",bool,doc="muon is PF candidate"),
156  isGlobal = Var("isGlobalMuon",bool,doc="muon is global muon"),
157  isTracker = Var("isTrackerMuon",bool,doc="muon is tracker muon"),
158  isStandalone = Var("isStandAloneMuon",bool,doc="muon is a standalone muon"),
159  mediumId = Var("passed('CutBasedIdMedium')",bool,doc="cut-based ID, medium WP"),
160  mediumPromptId = Var("passed('CutBasedIdMediumPrompt')",bool,doc="cut-based ID, medium prompt WP"),
161  tightId = Var("passed('CutBasedIdTight')",bool,doc="cut-based ID, tight WP"),
162  softId = Var("passed('SoftCutBasedId')",bool,doc="soft cut-based ID"),
163  softMvaId = Var("passed('SoftMvaId')",bool,doc="soft MVA ID"),
164  softMva = Var("softMvaValue()",float,doc="soft MVA ID score",precision=6),
165  softMvaRun3 = Var("softMvaRun3Value()",float,doc="soft MVA Run3 ID score",precision=6),
166  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)"),
167  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)"),
168  tkIsoId = Var("?passed('TkIsoTight')?2:passed('TkIsoLoose')","uint8",doc="TkIso ID (1=TkIsoLoose, 2=TkIsoTight)"),
169  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)"),
170  mvaMuID = Var("userFloat('mvaIDMuon')", float, doc="MVA-based ID score",precision=6),
171  mvaMuID_WP = Var("userFloat('mvaIDMuon_wpMedium') + userFloat('mvaIDMuon_wpTight')","uint8",doc="MVA-based ID selector WPs (1=MVAIDwpMedium,2=MVAIDwpTight)"),
172  multiIsoId = Var("?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')","uint8",doc="MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
173  puppiIsoId = Var("passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')", "uint8", doc="PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
174  triggerIdLoose = Var("passed('TriggerIdLoose')",bool,doc="TriggerIdLoose ID"),
175  inTimeMuon = Var("passed('InTimeMuon')",bool,doc="inTimeMuon ID"),
176  jetNDauCharged = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0", "uint8", doc="number of charged daughters of the closest jet"),
177  ),
178  externalVariables = cms.PSet(
179  mvaTTH = ExtVar(cms.InputTag("muonMVATTH"),float, doc="TTH MVA lepton ID score",precision=14),
180  mvaLowPt = ExtVar(cms.InputTag("muonMVALowPt"),float, doc="Low pt muon ID score",precision=14),
181  fsrPhotonIdx = ExtVar(cms.InputTag("leptonFSRphotons:muFsrIndex"), "int16", doc="Index of the lowest-dR/ET2 among associated FSR photons"),
182  bsConstrainedPt = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedPt"),float, doc="pT with beamspot constraint",precision=-1),
183  bsConstrainedPtErr = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedPtErr"),float, doc="pT error with beamspot constraint ",precision=6),
184  bsConstrainedChi2 = ExtVar(cms.InputTag("muonBSConstrain:muonBSConstrainedChi2"),float, doc="chi2 of beamspot constraint",precision=6),
185  ),
186 )
187 
188 # Increase precision of eta and phi
189 muonTable.variables.eta.precision = 16
190 muonTable.variables.phi.precision = 16
191 
192 
193 # Revert back to AK4 CHS jets for Run 2
194 run2_nanoAOD_ANY.toModify(
195  ptRatioRelForMu,srcJet="updatedJets"
196 )
197 
198 
199 muonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
200  src = muonTable.src, # final reco collection
201  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
202  mcPdgId = cms.vint32(13), # one or more PDG ID (13 = mu); absolute values (see below)
203  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
204  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
205  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
206  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
207  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
208  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
209 )
210 
211 muonMCTable = cms.EDProducer("CandMCMatchTableProducer",
212  src = muonTable.src,
213  mcMap = cms.InputTag("muonsMCMatchForTable"),
214  objName = muonTable.name,
215  objType = muonTable.name, #cms.string("Muon"),
216  branchName = cms.string("genPart"),
217  docString = cms.string("MC matching to status==1 muons"),
218 )
219 
220 muonTask = cms.Task(slimmedMuonsUpdated,isoForMu,ptRatioRelForMu,slimmedMuonsWithUserData,finalMuons,finalLooseMuons )
221 muonMCTask = cms.Task(muonsMCMatchForTable,muonMCTable)
222 muonTablesTask = cms.Task(muonMVATTH,muonMVALowPt,muonBSConstrain,muonTable,muonMVAID)
223 
def ExtVar(tag, valtype, doc=None, precision=-1)
Definition: common_cff.py:27
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16