CMS 3D CMS Logo

patMuonsWithTrigger_cff.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import FWCore.ParameterSet.Config as cms
3 
4 
13 patMuonsWithoutTrigger = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.clone(
14  muonSource = 'muons',
15  # embed the tracks, so we don't have to carry them around
16  embedTrack = True,
17  embedCombinedMuon = True,
18  embedStandAloneMuon = True,
19  embedPFCandidate = False,
20  embedCaloMETMuonCorrs = cms.bool(False),
21  embedTcMETMuonCorrs = cms.bool(False),
22  embedPfEcalEnergy = cms.bool(False),
23  # then switch off some features we don't need
24  #addTeVRefits = False, ## <<--- this doesn't work. PAT bug ??
25  embedPickyMuon = False,
26  embedTpfmsMuon = False,
27  userIsolation = cms.PSet(), # no extra isolation beyond what's in reco::Muon itself
28  isoDeposits = cms.PSet(), # no heavy isodeposits
29  addGenMatch = False, # no mc: T&P doesn't take it from here anyway.
30 )
31 # Reset all these; the default in muonProducer_cfi is not empty, but wrong
32 patMuonsWithoutTrigger.userData.userInts.src = []
33 patMuonsWithoutTrigger.userData.userFloats.src = []
34 patMuonsWithoutTrigger.userData.userCands.src = []
35 patMuonsWithoutTrigger.userData.userClasses.src = []
36 
37 
44 from MuonAnalysis.MuonAssociators.muonL1Match_cfi import muonL1Match as muonL1Info
45 
46 
47 def addL1UserData(patMuonProducer, l1ModuleLabel = "muonL1Info"):
48  "Load variables inside PAT muon, from module <l1ModuleLabel> that you must run before it"
49  patMuonProducer.userData.userInts.src += [
50  cms.InputTag(l1ModuleLabel, "quality"), # will be -999 in case of no match
51  ]
52  patMuonProducer.userData.userFloats.src += [
53  cms.InputTag(l1ModuleLabel, "deltaR"), # will be 999 in case of no match
54  ]
55  patMuonProducer.userData.userFloats.src += [
56  cms.InputTag(l1ModuleLabel, "deltaPhi"), # will be 999 in case of no match
57  ]
58  patMuonProducer.userData.userInts.src += [
59  cms.InputTag(l1ModuleLabel, "bx"), # will be -999 in case of no match
60  ]
61  patMuonProducer.userData.userCands.src += [
62  cms.InputTag(l1ModuleLabel)
63  ]
64 
65 
66 addL1UserData(patMuonsWithoutTrigger, "muonL1Info")
67 
68 
75 
76 
77 from PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cfi import patTrigger as patTriggerFull
78 patTriggerFull.onlyStandAlone = True
79 patTrigger = cms.EDProducer("TriggerObjectFilterByCollection",
80  src = cms.InputTag("patTriggerFull"),
81  collections = cms.vstring("hltL1extraParticles", "hltGmtStage2Digis", "hltL2MuonCandidates", "hltIterL3MuonCandidates","hltIterL3FromL2MuonCandidates","hltHighPtTkMuonCands", "hltGlbTrkMuonCands", "hltMuTrackJpsiCtfTrackCands", "hltMuTrackJpsiEffCtfTrackCands", "hltMuTkMuJpsiTrackerMuonCands","hltTracksIter"),
82 )
83 #patTrigger = cms.EDFilter("PATTriggerObjectStandAloneSelector",
84 # src = cms.InputTag("patTriggerFull"),
85 # cut = cms.string('coll("hltL1extraParticles") || coll("hltL2MuonCandidates") || coll("hltIterL3MuonCandidates") || coll("hltGlbTrkMuonCands") || coll("hltMuTrackJpsiCtfTrackCands") || coll("hltMuTrackJpsiEffCtfTrackCands") || coll("hltMuTkMuJpsiTrackerMuonCands")'),
86 #)
87 
88 
89 muonTriggerMatchHLT = cms.EDProducer( "PATTriggerMatcherDRDPtLessByR",
90  src = cms.InputTag( "patMuonsWithoutTrigger" ),
91  matched = cms.InputTag( "patTrigger" ),
92  matchedCuts = cms.string(""),
93 # andOr = cms.bool( False ),
94 # filterIdsEnum = cms.vstring( '*' ),
95 # filterIds = cms.vint32( 0 ),
96 # filterLabels = cms.vstring( '*' ),
97 # pathNames = cms.vstring( '*' ),
98 # collectionTags = cms.vstring( '*' ),
99  maxDPtRel = cms.double( 0.5 ),
100  maxDeltaR = cms.double( 0.5 ),
101  resolveAmbiguities = cms.bool( True ),
102  resolveByMatchQuality = cms.bool( True ) #change with respect to previous tag
103 )
104 
105 
106 from MuonAnalysis.MuonAssociators.muonHLTL1Match_cfi import muonHLTL1Match
107 muonMatchL1 = muonHLTL1Match.clone(
108  src = muonTriggerMatchHLT.src,
109  matched = muonTriggerMatchHLT.matched,
110 )
111 
112 
113 muonMatchHLTL1 = muonMatchL1.clone(matchedCuts = cms.string('coll("hltL1extraParticles")'))
114 muonMatchHLTL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL2MuonCandidates")'), maxDeltaR = 0.3, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 1.2
115 muonMatchHLTL3 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltIterL3MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
116 muonMatchHLTL3T = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltGlbTrkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
117 muonMatchHLTL3fromL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltIterL3FromL2MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
118 muonMatchHLTTkMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltHighPtTkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
119 muonMatchHLTCtfTrack = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
120 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
121 muonMatchHLTTrackMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
122 muonMatchHLTTrackIt = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltTracksIter")'), maxDeltaR = 0.1, maxDPtRel = 1.0) #maxDeltaR Changed accordingly to Zoltan tuning.
123 
124 patTriggerMatchers1Mu = cms.Sequence(
125  #muonMatchHLTL1 + # keep off by default, since it is slow and usually not needed
126  muonMatchHLTL2 +
127  muonMatchHLTL3 +
128  muonMatchHLTL3T +
129  muonMatchHLTL3fromL2 +
130  muonMatchHLTTkMu
131 )
132 patTriggerMatchers1MuInputTags = [
133  #cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
134  #cms.InputTag('muonMatchHLTL1'),
135  cms.InputTag('muonMatchHLTL2'),
136  cms.InputTag('muonMatchHLTL3'),
137  cms.InputTag('muonMatchHLTL3T'),
138  cms.InputTag('muonMatchHLTL3fromL2'),
139  cms.InputTag('muonMatchHLTTkMu'),
140 ]
141 
142 patTriggerMatchers2Mu = cms.Sequence(
143  muonMatchHLTCtfTrack +
144  muonMatchHLTCtfTrack2 +
145  muonMatchHLTTrackMu +
146  muonMatchHLTTrackIt
147 )
148 patTriggerMatchers2MuInputTags = [
149  cms.InputTag('muonMatchHLTCtfTrack'),
150  cms.InputTag('muonMatchHLTCtfTrack2'),
151  cms.InputTag('muonMatchHLTTrackMu'),
152  cms.InputTag('muonMatchHLTTrackIt'),
153 ]
154 
155 
156 patMuonsWithTrigger = cms.EDProducer( "PATTriggerMatchMuonEmbedder",
157  src = cms.InputTag( "patMuonsWithoutTrigger" ),
158  matches = cms.VInputTag()
159 )
160 patMuonsWithTrigger.matches += patTriggerMatchers1MuInputTags
161 patMuonsWithTrigger.matches += patTriggerMatchers2MuInputTags
162 
163 
164 
165 patTriggerMatching = cms.Sequence(
166  patTriggerFull * patTrigger *
167  patTriggerMatchers1Mu *
168  patTriggerMatchers2Mu *
169  patMuonsWithTrigger
170 )
171 
172 patMuonsWithTriggerSequence = cms.Sequence(
173  muonL1Info *
174  patMuonsWithoutTrigger *
175  patTriggerMatching
176 )
177 
178 
179 
181  "Switch off ambiguity resolution: allow multiple reco muons to match to the same trigger muon"
182  process.muonMatchHLTL1.resolveAmbiguities = False
183  process.muonMatchHLTL2.resolveAmbiguities = False
184  process.muonMatchHLTL3.resolveAmbiguities = False
185  process.muonMatchHLTL3fromL2.resolveAmbiguities = False
186  process.muonMatchHLTTkMu.resolveAmbiguities = False
187  process.muonMatchHLTCtfTrack.resolveAmbiguities = False
188  process.muonMatchHLTTrackMu.resolveAmbiguities = False
189  process.muonMatchHLTTrackIt.resolveAmbiguities = False
190 
191 def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT"):
192  "Change the process name under which the trigger was run"
193  patTriggerFull.processName = triggerProcessName
194 
195 def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons")):
196  "Use a different input collection of reco muons"
197  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
198  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, oldRecoMuonCollectionTag, recoMuonCollectionTag)
199 
200 def useExistingPATMuons(process, newPatMuonTag, addL1Info=False):
201  "Start from existing pat Muons instead of producing them"
202  process.patMuonsWithTriggerSequence.remove(process.patMuonsWithoutTrigger)
203  process.patMuonsWithTriggerSequence.remove(process.muonL1Info)
204  process.patMuonsWithTrigger.src = newPatMuonTag
205  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
206  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, cms.InputTag('patMuonsWithoutTrigger'), newPatMuonTag)
207  if addL1Info:
208  process.muonL1Info.src = newPatMuonTag.muonSource
209  addL1UserData(getattr(process,newPatMuonTag.moduleLabel), 'muonL1Info')
210 
211 def addPreselection(process, cut):
212  "Add a preselection cut to the muons before matching (might be relevant, due to ambiguity resolution in trigger matching!"
213  process.patMuonsWithoutTriggerUnfiltered = process.patMuonsWithoutTrigger.clone()
214  process.globalReplace('patMuonsWithoutTrigger', cms.EDFilter("PATMuonSelector", src = cms.InputTag('patMuonsWithoutTriggerUnfiltered'), cut = cms.string(cut)))
215  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.patMuonsWithoutTriggerUnfiltered * process.patMuonsWithoutTrigger)
216 
217 def addMCinfo(process):
218  "Add MC matching information to the muons"
219  process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
220  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.muonMatch + process.patMuonsWithoutTrigger)
221  process.patMuonsWithoutTrigger.addGenMatch = True
222  process.patMuonsWithoutTrigger.embedGenMatch = True
223  process.patMuonsWithoutTrigger.genParticleMatch = 'muonMatch'
224 
225 def addDiMuonTriggers(process):
226  print("[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default")
227 
228 def addHLTL1Passthrough(process, embedder="patMuonsWithTrigger"):
229  process.patMuonsWithTriggerSequence.replace(process.muonMatchHLTL3, process.muonMatchHLTL1 + process.muonMatchHLTL3)
230  getattr(process,embedder).matches += [ cms.InputTag('muonMatchHLTL1'), cms.InputTag('muonMatchHLTL1','propagatedReco') ]
231 
233  "Change the L1 trigger matching window to be suitable also for CSC single triggers"
234  if hasattr(process, 'muonL1Info'):
235  process.muonL1Info.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
236  process.muonL1Info.maxDeltaEta = 0.2
237  process.muonL1Info.fallbackToME1 = True
238  if hasattr(process, 'muonMatchHLTL1'):
239  process.muonMatchHLTL1.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
240  process.muonMatchHLTL1.maxDeltaEta = 0.2
241  process.muonMatchHLTL1.fallbackToME1 = True
242 
243 
245  if hasattr(process, 'muonL1Info'):
246  # l1PhiOffest might need a second look
247  # barrel seems not to requre it, whereas encaps do
248  # anyhow the effect is of the order of 0.02
249  #process.muonL1Info.l1PhiOffset = cms.double()
250  process.muonL1Info.useMB2InOverlap = cms.bool(True)
251  process.muonL1Info.useStage2L1 = cms.bool(True)
252  process.muonL1Info.preselection = cms.string("")
253  process.muonL1Info.matched = cms.InputTag("gmtStage2Digis:Muon:")
254 
255 def appendL1MatchingAlgo(process, algo = "quality"):
256  if hasattr(process, 'muonL1Info'):
257  newMuonL1Info = process.muonL1Info.clone(sortBy = cms.string(algo),
258  sortByQuality = cms.bool(algo == "quality"),
259  sortByDeltaPhi = cms.bool(algo == "deltaEta"),
260  sortByDeltaEta = cms.bool(algo == "deltaPhi"),
261  sortByPt = cms.bool(algo == "pt"),
262  maxDeltaR = cms.double(0.3))
263  setattr(process, "muonL1Info" + algo.title(), newMuonL1Info)
264  process.patMuonsWithTriggerSequence.replace(process.muonL1Info, process.muonL1Info + getattr(process, 'muonL1Info' + algo.title()))
265  addL1UserData(patMuonsWithoutTrigger, "muonL1Info" + algo.title())
patMuonsWithTrigger_cff.switchOffAmbiguityResolution
def switchOffAmbiguityResolution(process)
Definition: patMuonsWithTrigger_cff.py:180
muonProducer_cfi
patMuonsWithTrigger_cff.addDiMuonTriggers
def addDiMuonTriggers(process)
Definition: patMuonsWithTrigger_cff.py:225
patMuonsWithTrigger_cff.addHLTL1Passthrough
def addHLTL1Passthrough(process, embedder="patMuonsWithTrigger")
Definition: patMuonsWithTrigger_cff.py:228
patMuonsWithTrigger_cff.useExistingPATMuons
def useExistingPATMuons(process, newPatMuonTag, addL1Info=False)
Definition: patMuonsWithTrigger_cff.py:200
patMuonsWithTrigger_cff.addMCinfo
def addMCinfo(process)
Definition: patMuonsWithTrigger_cff.py:217
patMuonsWithTrigger_cff.addL1UserData
def addL1UserData(patMuonProducer, l1ModuleLabel="muonL1Info")
Define a generic function, so that it can be used with existing PAT Muons.
Definition: patMuonsWithTrigger_cff.py:47
patMuonsWithTrigger_cff.changeTriggerProcessName
def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT")
Definition: patMuonsWithTrigger_cff.py:191
patMuonsWithTrigger_cff.useL1MatchingWindowForSinglets
def useL1MatchingWindowForSinglets(process)
Definition: patMuonsWithTrigger_cff.py:232
patMuonsWithTrigger_cff.appendL1MatchingAlgo
def appendL1MatchingAlgo(process, algo="quality")
Definition: patMuonsWithTrigger_cff.py:255
helpers
triggerProducer_cfi
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
muonL1Match_cfi
patMuonsWithTrigger_cff.addPreselection
def addPreselection(process, cut)
Definition: patMuonsWithTrigger_cff.py:211
MassReplace.massSearchReplaceAnyInputTag
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
Definition: MassReplace.py:79
patMuonsWithTrigger_cff.useL1Stage2Candidates
def useL1Stage2Candidates(process)
Definition: patMuonsWithTrigger_cff.py:244
patMuonsWithTrigger_cff.changeRecoMuonInput
def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons"))
Definition: patMuonsWithTrigger_cff.py:195