CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
patMuonsWithTrigger_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 ## __ __ _ ____ _ _____ __ __
4 ## | \/ | __ _| | _____ | _ \ / \|_ _| | \/ |_ _ ___ _ __ ___
5 ## | |\/| |/ _` | |/ / _ \ | |_) / _ \ | | | |\/| | | | |/ _ \| '_ \/ __|
6 ## | | | | (_| | < __/ | __/ ___ \| | | | | | |_| | (_) | | | \__ \
7 ## |_| |_|\__,_|_|\_\___| |_| /_/ \_\_| |_| |_|\__,_|\___/|_| |_|___/
8 ##
9 ##
10 ### ==== Make PAT Muons ====
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 ##
42 ##
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 ##
73 ##
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", "hltL3MuonCandidates", "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("hltL3MuonCandidates") || 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("hltL3MuonCandidates")'), 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 muonMatchHLTTkMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltHighPtTkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
117 muonMatchHLTCtfTrack = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
118 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
119 muonMatchHLTTrackMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
120 muonMatchHLTTrackIt = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltTracksIter")'), maxDeltaR = 0.1, maxDPtRel = 1.0) #maxDeltaR Changed accordingly to Zoltan tuning.
121 
122 patTriggerMatchers1Mu = cms.Sequence(
123  #muonMatchHLTL1 + # keep off by default, since it is slow and usually not needed
124  muonMatchHLTL2 +
125  muonMatchHLTL3 +
126  muonMatchHLTL3T +
127  muonMatchHLTTkMu
128 )
129 patTriggerMatchers1MuInputTags = [
130  #cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
131  #cms.InputTag('muonMatchHLTL1'),
132  cms.InputTag('muonMatchHLTL2'),
133  cms.InputTag('muonMatchHLTL3'),
134  cms.InputTag('muonMatchHLTL3T'),
135  cms.InputTag('muonMatchHLTTkMu'),
136 ]
137 
138 patTriggerMatchers2Mu = cms.Sequence(
139  muonMatchHLTCtfTrack +
140  muonMatchHLTCtfTrack2 +
141  muonMatchHLTTrackMu +
142  muonMatchHLTTrackIt
143 )
144 patTriggerMatchers2MuInputTags = [
145  cms.InputTag('muonMatchHLTCtfTrack'),
146  cms.InputTag('muonMatchHLTCtfTrack2'),
147  cms.InputTag('muonMatchHLTTrackMu'),
148  cms.InputTag('muonMatchHLTTrackIt'),
149 ]
150 
151 ## ==== Embed ====
152 patMuonsWithTrigger = cms.EDProducer( "PATTriggerMatchMuonEmbedder",
153  src = cms.InputTag( "patMuonsWithoutTrigger" ),
154  matches = cms.VInputTag()
155 )
156 patMuonsWithTrigger.matches += patTriggerMatchers1MuInputTags
157 patMuonsWithTrigger.matches += patTriggerMatchers2MuInputTags
158 
159 
160 ## ==== Trigger Sequence ====
161 patTriggerMatching = cms.Sequence(
162  patTriggerFull * patTrigger *
163  patTriggerMatchers1Mu *
164  patTriggerMatchers2Mu *
165  patMuonsWithTrigger
166 )
167 
168 patMuonsWithTriggerSequence = cms.Sequence(
169  muonL1Info *
170  patMuonsWithoutTrigger *
171  patTriggerMatching
172 )
173 
174 
175 
177  "Switch off ambiguity resolution: allow multiple reco muons to match to the same trigger muon"
178  process.muonMatchHLTL1.resolveAmbiguities = False
179  process.muonMatchHLTL2.resolveAmbiguities = False
180  process.muonMatchHLTL3.resolveAmbiguities = False
181  process.muonMatchHLTTkMu.resolveAmbiguities = False
182  process.muonMatchHLTCtfTrack.resolveAmbiguities = False
183  process.muonMatchHLTTrackMu.resolveAmbiguities = False
184  process.muonMatchHLTTrackIt.resolveAmbiguities = False
185 
186 def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT"):
187  "Change the process name under which the trigger was run"
188  patTriggerFull.processName = triggerProcessName
189 
190 def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons")):
191  "Use a different input collection of reco muons"
192  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
193  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, oldRecoMuonCollectionTag, recoMuonCollectionTag)
194 
195 def useExistingPATMuons(process, newPatMuonTag, addL1Info=False):
196  "Start from existing pat Muons instead of producing them"
197  process.patMuonsWithTriggerSequence.remove(process.patMuonsWithoutTrigger)
198  process.patMuonsWithTriggerSequence.remove(process.muonL1Info)
199  process.patMuonsWithTrigger.src = newPatMuonTag
200  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
201  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, cms.InputTag('patMuonsWithoutTrigger'), newPatMuonTag)
202  if addL1Info:
203  process.muonL1Info.src = newPatMuonTag.muonSource
204  addL1UserData(getattr(process,newPatMuonTag.moduleLabel), 'muonL1Info')
205 
206 def addPreselection(process, cut):
207  "Add a preselection cut to the muons before matching (might be relevant, due to ambiguity resolution in trigger matching!"
208  process.patMuonsWithoutTriggerUnfiltered = process.patMuonsWithoutTrigger.clone()
209  process.globalReplace('patMuonsWithoutTrigger', cms.EDFilter("PATMuonSelector", src = cms.InputTag('patMuonsWithoutTriggerUnfiltered'), cut = cms.string(cut)))
210  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.patMuonsWithoutTriggerUnfiltered * process.patMuonsWithoutTrigger)
211 
212 def addMCinfo(process):
213  "Add MC matching information to the muons"
214  process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
215  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.muonMatch + process.patMuonsWithoutTrigger)
216  process.patMuonsWithoutTrigger.addGenMatch = True
217  process.patMuonsWithoutTrigger.embedGenMatch = True
218  process.patMuonsWithoutTrigger.genParticleMatch = 'muonMatch'
219 
220 def addDiMuonTriggers(process):
221  print "[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default"
222 
223 def addHLTL1Passthrough(process, embedder="patMuonsWithTrigger"):
224  process.patMuonsWithTriggerSequence.replace(process.muonMatchHLTL3, process.muonMatchHLTL1 + process.muonMatchHLTL3)
225  getattr(process,embedder).matches += [ cms.InputTag('muonMatchHLTL1'), cms.InputTag('muonMatchHLTL1','propagatedReco') ]
226 
228  "Change the L1 trigger matching window to be suitable also for CSC single triggers"
229  if hasattr(process, 'muonL1Info'):
230  process.muonL1Info.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
231  process.muonL1Info.maxDeltaEta = 0.2
232  process.muonL1Info.fallbackToME1 = True
233  if hasattr(process, 'muonMatchHLTL1'):
234  process.muonMatchHLTL1.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
235  process.muonMatchHLTL1.maxDeltaEta = 0.2
236  process.muonMatchHLTL1.fallbackToME1 = True
237 
239  if hasattr(process, 'muonL1Info'):
240  # l1PhiOffest might need a second look
241  # barrel seems not to requre it, whereas encaps do
242  # anyhow the effect is of the order of 0.02
243  #process.muonL1Info.l1PhiOffset = cms.double()
244  process.muonL1Info.useMB2InOverlap = cms.bool(True)
245  process.muonL1Info.useStage2L1 = cms.bool(True)
246  process.muonL1Info.preselection = cms.string("")
247  process.muonL1Info.matched = cms.InputTag("gmtStage2Digis:Muon:")
248 
249 def appendL1MatchingAlgo(process, algo = "quality"):
250  if hasattr(process, 'muonL1Info'):
251  newMuonL1Info = process.muonL1Info.clone(sortBy = cms.string(algo),
252  sortByQuality = cms.bool(algo == "quality"),
253  sortByDeltaPhi = cms.bool(algo == "deltaEta"),
254  sortByDeltaEta = cms.bool(algo == "deltaPhi"),
255  sortByPt = cms.bool(algo == "pt"),
256  maxDeltaR = cms.double(0.3))
257  setattr(process, "muonL1Info" + algo.title(), newMuonL1Info)
258  process.patMuonsWithTriggerSequence.replace(process.muonL1Info, process.muonL1Info + getattr(process, 'muonL1Info' + algo.title()))
259  addL1UserData(patMuonsWithoutTrigger, "muonL1Info" + algo.title())
260 
def massSearchReplaceAnyInputTag
Definition: helpers.py:271
def addL1UserData
Define a generic function, so that it can be used with existing PAT Muons.