CMS 3D CMS Logo

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