CMS 3D CMS Logo

muons_cff.py
Go to the documentation of this file.
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
10 
11 # this below is used only in some eras
12 slimmedMuonsUpdated = cms.EDProducer("PATMuonUpdater",
13  src = cms.InputTag("slimmedMuons"),
14  vertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
15  computeMiniIso = cms.bool(False),
16  fixDxySign = cms.bool(True),
17  pfCandsForMiniIso = cms.InputTag("packedPFCandidates"),
18  miniIsoParams = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.miniIsoParams, # so they're in sync
19  recomputeMuonBasicSelectors = cms.bool(False),
20 )
21 run2_miniAOD_80XLegacy.toModify( slimmedMuonsUpdated, computeMiniIso = True, recomputeMuonBasicSelectors = True )
22 
23 isoForMu = cms.EDProducer("MuonIsoValueMapProducer",
24  src = cms.InputTag("slimmedMuonsUpdated"),
25  relative = cms.bool(False),
26  rho_MiniIso = cms.InputTag("fixedGridRhoFastjetAll"),
27  EAFile_MiniIso = cms.FileInPath("PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_94X.txt"),
28 )
29 run2_miniAOD_80XLegacy.toModify(isoForMu, EAFile_MiniIso = "PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
30 run2_nanoAOD_94X2016.toModify(isoForMu, EAFile_MiniIso = "PhysicsTools/NanoAOD/data/effAreaMuons_cone03_pfNeuHadronsAndPhotons_80X.txt")
31 
32 ptRatioRelForMu = cms.EDProducer("MuonJetVarProducer",
33  srcJet = cms.InputTag("updatedJets"),
34  srcLep = cms.InputTag("slimmedMuonsUpdated"),
35  srcVtx = cms.InputTag("offlineSlimmedPrimaryVertices"),
36 )
37 
38 slimmedMuonsWithUserData = cms.EDProducer("PATMuonUserDataEmbedder",
39  src = cms.InputTag("slimmedMuonsUpdated"),
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"),
46  ),
47  userCands = cms.PSet(
48  jetForLepJetVar = cms.InputTag("ptRatioRelForMu:jetForLepJetVar") # warning: Ptr is null if no match is found
49  ),
50 )
51 
52 finalMuons = cms.EDFilter("PATMuonRefSelector",
53  src = cms.InputTag("slimmedMuonsWithUserData"),
54  cut = cms.string("pt > 3 && (passed('CutBasedIdLoose') || passed('SoftCutBasedId') || passed('SoftMvaId') || passed('CutBasedIdGlobalHighPt') || passed('CutBasedIdTrkHighPt'))")
55 )
56 
57 finalLooseMuons = cms.EDFilter("PATMuonRefSelector", # for isotrack cleaning
58  src = cms.InputTag("slimmedMuonsWithUserData"),
59  cut = cms.string("pt > 3 && track.isNonnull && isLooseMuon")
60 )
61 
62 muonMVATTH= cms.EDProducer("MuonBaseMVAValueMapProducer",
63  src = cms.InputTag("linkedObjects","muons"),
64  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"),
65  name = cms.string("muonMVATTH"),
66  isClassifier = cms.bool(True),
67  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"]),
68  variables = cms.PSet(
69  LepGood_pt = cms.string("pt"),
70  LepGood_eta = cms.string("eta"),
71  LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"),
72  LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"),
73  LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"),
74  LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"),
75  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"),
76  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)"),
77  LepGood_dxy = cms.string("log(abs(dB('PV2D')))"),
78  LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"),
79  LepGood_dz = cms.string("log(abs(dB('PVDZ')))"),
80  LepGood_segmentComp = cms.string("segmentCompatibility"),
81 
82  )
83 )
84 
85 muonMVALowPt = muonMVATTH.clone(
86  weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_lowpt.weights.xml"),
87  name = cms.string("muonMVALowPt"),
88 )
89 
90 run2_muon_2016.toModify(muonMVATTH,
91  weightFile = "PhysicsTools/NanoAOD/data/mu_BDTG_2016.weights.xml",
92  )
93 
94 from MuonAnalysis.MuonAssociators.muonFSRProducer_cfi import muonFSRProducer
95 muonFSRphotons = muonFSRProducer.clone(
96  packedPFCandidates = cms.InputTag("packedPFCandidates"),
97  slimmedElectrons = cms.InputTag("slimmedElectrons"),
98  muons = cms.InputTag("linkedObjects","muons"),
99 )
100 from MuonAnalysis.MuonAssociators.muonFSRAssociator_cfi import muonFSRAssociator
101 muonFSRassociation = muonFSRAssociator.clone(
102  photons = cms.InputTag("muonFSRphotons"),
103  muons = cms.InputTag("linkedObjects","muons"),
104 )
105 
106 fsrTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
107  src = cms.InputTag("muonFSRphotons"),
108  cut = cms.string(""), #we should not filter on cross linked collections
109  name = cms.string("FsrPhoton"),
110  doc = cms.string("Final state radiation photons emitted by muons"),
111  singleton = cms.bool(False), # the number of entries is variable
112  extension = cms.bool(False), # this is the main table for the muons
113  variables = cms.PSet(P3Vars,
114  relIso03 = Var("userFloat('relIso03')",float,doc="relative isolation in a 0.3 cone without CHS"),
115  dROverEt2 = Var("userFloat('dROverEt2')",float,doc="deltaR to associated muon divided by photon et2"),
116  muonIdx = Var("?hasUserCand('associatedMuon')?userCand('associatedMuon').key():-1",int, doc="index of associated muon")
117  )
118  )
119 
120 muonTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
121  src = cms.InputTag("linkedObjects","muons"),
122  cut = cms.string(""), #we should not filter on cross linked collections
123  name = cms.string("Muon"),
124  doc = cms.string("slimmedMuons after basic selection (" + finalMuons.cut.value()+")"),
125  singleton = cms.bool(False), # the number of entries is variable
126  extension = cms.bool(False), # this is the main table for the muons
127  variables = cms.PSet(CandVars,
128  ptErr = Var("bestTrack().ptError()", float, doc = "ptError of the muon track", precision=6),
129  tunepRelPt = Var("tunePMuonBestTrack().pt/pt",float,doc="TuneP relative pt, tunePpt/pt",precision=6),
130  dz = Var("dB('PVDZ')",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
131  dzErr = Var("abs(edB('PVDZ'))",float,doc="dz uncertainty, in cm",precision=6),
132  dxybs = Var("dB('BS2D')",float,doc="dxy (with sign) wrt the beam spot, in cm",precision=10),
133  dxy = Var("dB('PV2D')",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
134  dxyErr = Var("edB('PV2D')",float,doc="dxy uncertainty, in cm",precision=6),
135  ip3d = Var("abs(dB('PV3D'))",float,doc="3D impact parameter wrt first PV, in cm",precision=10),
136  sip3d = Var("abs(dB('PV3D')/edB('PV3D'))",float,doc="3D impact parameter significance wrt first PV",precision=10),
137  segmentComp = Var("segmentCompatibility()", float, doc = "muon segment compatibility", precision=14), # keep higher precision since people have cuts with 3 digits on this
138  nStations = Var("numberOfMatchedStations", int, doc = "number of matched stations with default arbitration (segment & track)"),
139  nTrackerLayers = Var("?track.isNonnull?innerTrack().hitPattern().trackerLayersWithMeasurement():0", int, doc = "number of layers in the tracker"),
140  highPurity = Var("?track.isNonnull?innerTrack().quality('highPurity'):0", bool, doc = "inner track is high purity"),
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')+passed('MvaVTight')+passed('MvaVVTight')","uint8",doc="Mva ID from miniAOD selector (1=MvaLoose, 2=MvaMedium, 3=MvaTight, 4=MvaVTight, 5=MvaVVTight)"),
165  mvaLowPtId = Var("passed('LowPtMvaLoose')+passed('LowPtMvaMedium')","uint8", doc="Low Pt Mva ID from miniAOD selector (1=LowPtMvaLoose, 2=LowPtMvaMedium)"),
166  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)"),
167  multiIsoId = Var("?passed('MultiIsoMedium')?2:passed('MultiIsoLoose')","uint8",doc="MultiIsoId from miniAOD selector (1=MultiIsoLoose, 2=MultiIsoMedium)"),
168  puppiIsoId = Var("passed('PuppiIsoLoose')+passed('PuppiIsoMedium')+passed('PuppiIsoTight')", "uint8", doc="PuppiIsoId from miniAOD selector (1=Loose, 2=Medium, 3=Tight)"),
169  triggerIdLoose = Var("passed('TriggerIdLoose')",bool,doc="TriggerIdLoose ID"),
170  inTimeMuon = Var("passed('InTimeMuon')",bool,doc="inTimeMuon ID"),
171  jetNDauCharged = Var("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0", "uint8", doc="number of charged daughters of the closest jet"),
172  ),
173  externalVariables = cms.PSet(
174  mvaTTH = ExtVar(cms.InputTag("muonMVATTH"),float, doc="TTH MVA lepton ID score",precision=14),
175  mvaLowPt = ExtVar(cms.InputTag("muonMVALowPt"),float, doc="Low pt muon ID score",precision=14),
176  fsrPhotonIdx = ExtVar(cms.InputTag("muonFSRassociation:fsrIndex"),int, doc="Index of the associated FSR photon"),
177  ),
178 )
179 
180 
181 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
182  modifier.toModify(muonTable.variables, puppiIsoId = None, softMva = None)
183 
184 run2_nanoAOD_102Xv1.toModify(muonTable.variables, puppiIsoId = None)
185 
186 
187 muonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
188  src = muonTable.src, # final reco collection
189  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
190  mcPdgId = cms.vint32(13), # one or more PDG ID (13 = mu); absolute values (see below)
191  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
192  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
193  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
194  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
195  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
196  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
197 )
198 
199 muonMCTable = cms.EDProducer("CandMCMatchTableProducer",
200  src = muonTable.src,
201  mcMap = cms.InputTag("muonsMCMatchForTable"),
202  objName = muonTable.name,
203  objType = muonTable.name, #cms.string("Muon"),
204  branchName = cms.string("genPart"),
205  docString = cms.string("MC matching to status==1 muons"),
206 )
207 
208 muonSequence = cms.Sequence(slimmedMuonsUpdated+isoForMu + ptRatioRelForMu + slimmedMuonsWithUserData + finalMuons + finalLooseMuons )
209 muonMC = cms.Sequence(muonsMCMatchForTable + muonMCTable)
210 muonTables = cms.Sequence(muonFSRphotons + muonFSRassociation + muonMVATTH + muonMVALowPt + muonTable + fsrTable)
211 
def ExtVar(tag, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:31
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20