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.userCands.src += [
55  cms.InputTag(l1ModuleLabel)
56  ]
57 
58 ## Do it for this collection of pat Muons
59 addL1UserData(patMuonsWithoutTrigger, "muonL1Info")
60 
61 ## __ __ _ _ _ _ _ _____
62 ## | \/ | __ _| |_ ___| |__ | | | | | |_ _|
63 ## | |\/| |/ _` | __/ __| '_ \ | |_| | | | |
64 ## | | | | (_| | || (__| | | | | _ | |___| |
65 ## |_| |_|\__,_|\__\___|_| |_| |_| |_|_____|_|
66 ##
67 ##
68 
69 ### ==== Unpack trigger, and match ====
70 from PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cfi import patTrigger as patTriggerFull
71 patTriggerFull.onlyStandAlone = True
72 patTrigger = cms.EDProducer("TriggerObjectFilterByCollection",
73  src = cms.InputTag("patTriggerFull"),
74  collections = cms.vstring("hltL1extraParticles", "hltL2MuonCandidates", "hltL3MuonCandidates", "hltHighPtTkMuonCands", "hltGlbTrkMuonCands", "hltMuTrackJpsiCtfTrackCands", "hltMuTrackJpsiEffCtfTrackCands", "hltMuTkMuJpsiTrackerMuonCands","hltTracksIter"),
75 )
76 #patTrigger = cms.EDFilter("PATTriggerObjectStandAloneSelector",
77 # src = cms.InputTag("patTriggerFull"),
78 # cut = cms.string('coll("hltL1extraParticles") || coll("hltL2MuonCandidates") || coll("hltL3MuonCandidates") || coll("hltGlbTrkMuonCands") || coll("hltMuTrackJpsiCtfTrackCands") || coll("hltMuTrackJpsiEffCtfTrackCands") || coll("hltMuTkMuJpsiTrackerMuonCands")'),
79 #)
80 
81 ### ==== Then perform a match for all HLT triggers of interest
82 muonTriggerMatchHLT = cms.EDProducer( "PATTriggerMatcherDRDPtLessByR",
83  src = cms.InputTag( "patMuonsWithoutTrigger" ),
84  matched = cms.InputTag( "patTrigger" ),
85  matchedCuts = cms.string(""),
86 # andOr = cms.bool( False ),
87 # filterIdsEnum = cms.vstring( '*' ),
88 # filterIds = cms.vint32( 0 ),
89 # filterLabels = cms.vstring( '*' ),
90 # pathNames = cms.vstring( '*' ),
91 # collectionTags = cms.vstring( '*' ),
92  maxDPtRel = cms.double( 0.5 ),
93  maxDeltaR = cms.double( 0.5 ),
94  resolveAmbiguities = cms.bool( True ),
95  resolveByMatchQuality = cms.bool( True ) #change with respect to previous tag
96 )
97 
98 ### == For HLT triggers which are just L1s, we need a different matcher
99 from MuonAnalysis.MuonAssociators.muonHLTL1Match_cfi import muonHLTL1Match
100 muonMatchL1 = muonHLTL1Match.clone(
101  src = muonTriggerMatchHLT.src,
102  matched = muonTriggerMatchHLT.matched,
103 )
104 
105 ### Single Mu L1
106 muonMatchHLTL1 = muonMatchL1.clone(matchedCuts = cms.string('coll("hltL1extraParticles")'))
107 muonMatchHLTL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL2MuonCandidates")'), maxDeltaR = 0.3, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 1.2
108 muonMatchHLTL3 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL3MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
109 muonMatchHLTL3T = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltGlbTrkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
110 muonMatchHLTTkMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltHighPtTkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
111 muonMatchHLTCtfTrack = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
112 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
113 muonMatchHLTTrackMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
114 muonMatchHLTTrackIt = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltTracksIter")'), maxDeltaR = 0.1, maxDPtRel = 1.0) #maxDeltaR Changed accordingly to Zoltan tuning.
115 
116 patTriggerMatchers1Mu = cms.Sequence(
117  #muonMatchHLTL1 + # keep off by default, since it is slow and usually not needed
118  muonMatchHLTL2 +
119  muonMatchHLTL3 +
120  muonMatchHLTL3T +
121  muonMatchHLTTkMu
122 )
123 patTriggerMatchers1MuInputTags = [
124  #cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
125  #cms.InputTag('muonMatchHLTL1'),
126  cms.InputTag('muonMatchHLTL2'),
127  cms.InputTag('muonMatchHLTL3'),
128  cms.InputTag('muonMatchHLTL3T'),
129  cms.InputTag('muonMatchHLTTkMu'),
130 ]
131 
132 patTriggerMatchers2Mu = cms.Sequence(
133  muonMatchHLTCtfTrack +
134  muonMatchHLTCtfTrack2 +
135  muonMatchHLTTrackMu +
136  muonMatchHLTTrackIt
137 )
138 patTriggerMatchers2MuInputTags = [
139  cms.InputTag('muonMatchHLTCtfTrack'),
140  cms.InputTag('muonMatchHLTCtfTrack2'),
141  cms.InputTag('muonMatchHLTTrackMu'),
142  cms.InputTag('muonMatchHLTTrackIt'),
143 ]
144 
145 ## ==== Embed ====
146 patMuonsWithTrigger = cms.EDProducer( "PATTriggerMatchMuonEmbedder",
147  src = cms.InputTag( "patMuonsWithoutTrigger" ),
148  matches = cms.VInputTag()
149 )
150 patMuonsWithTrigger.matches += patTriggerMatchers1MuInputTags
151 patMuonsWithTrigger.matches += patTriggerMatchers2MuInputTags
152 
153 
154 ## ==== Trigger Sequence ====
155 patTriggerMatching = cms.Sequence(
156  patTriggerFull * patTrigger *
157  patTriggerMatchers1Mu *
158  patTriggerMatchers2Mu *
159  patMuonsWithTrigger
160 )
161 
162 patMuonsWithTriggerSequence = cms.Sequence(
163  muonL1Info *
164  patMuonsWithoutTrigger *
165  patTriggerMatching
166 )
167 
168 
169 
171  "Switch off ambiguity resolution: allow multiple reco muons to match to the same trigger muon"
172  process.muonMatchHLTL1.resolveAmbiguities = False
173  process.muonMatchHLTL2.resolveAmbiguities = False
174  process.muonMatchHLTL3.resolveAmbiguities = False
175  process.muonMatchHLTTkMu.resolveAmbiguities = False
176  process.muonMatchHLTCtfTrack.resolveAmbiguities = False
177  process.muonMatchHLTTrackMu.resolveAmbiguities = False
178  process.muonMatchHLTTrackIt.resolveAmbiguities = False
179 
180 def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT"):
181  "Change the process name under which the trigger was run"
182  patTriggerFull.processName = triggerProcessName
183 
184 def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons")):
185  "Use a different input collection of reco muons"
186  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
187  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, oldRecoMuonCollectionTag, recoMuonCollectionTag)
188 
189 def useExistingPATMuons(process, newPatMuonTag, addL1Info=False):
190  "Start from existing pat Muons instead of producing them"
191  process.patMuonsWithTriggerSequence.remove(process.patMuonsWithoutTrigger)
192  process.patMuonsWithTriggerSequence.remove(process.muonL1Info)
193  process.patMuonsWithTrigger.src = newPatMuonTag
194  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
195  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, cms.InputTag('patMuonsWithoutTrigger'), newPatMuonTag)
196  if addL1Info:
197  process.muonL1Info.src = newPatMuonTag.muonSource
198  addL1UserData(getattr(process,newPatMuonTag.moduleLabel), 'muonL1Info')
199 
200 def addPreselection(process, cut):
201  "Add a preselection cut to the muons before matching (might be relevant, due to ambiguity resolution in trigger matching!"
202  process.patMuonsWithoutTriggerUnfiltered = process.patMuonsWithoutTrigger.clone()
203  process.globalReplace('patMuonsWithoutTrigger', cms.EDFilter("PATMuonSelector", src = cms.InputTag('patMuonsWithoutTriggerUnfiltered'), cut = cms.string(cut)))
204  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.patMuonsWithoutTriggerUnfiltered * process.patMuonsWithoutTrigger)
205 
206 def addMCinfo(process):
207  "Add MC matching information to the muons"
208  process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
209  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.muonMatch + process.patMuonsWithoutTrigger)
210  process.patMuonsWithoutTrigger.addGenMatch = True
211  process.patMuonsWithoutTrigger.embedGenMatch = True
212  process.patMuonsWithoutTrigger.genParticleMatch = 'muonMatch'
213 
214 def addDiMuonTriggers(process):
215  print "[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default"
216 
217 def addHLTL1Passthrough(process, embedder="patMuonsWithTrigger"):
218  process.patMuonsWithTriggerSequence.replace(process.muonMatchHLTL3, process.muonMatchHLTL1 + process.muonMatchHLTL3)
219  getattr(process,embedder).matches += [ cms.InputTag('muonMatchHLTL1'), cms.InputTag('muonMatchHLTL1','propagatedReco') ]
220 
221 def useExtendedL1Match(process, patMuonProd="patMuonsWithoutTrigger", byWhat=["ByQ"]):
222  process.load("MuonAnalysis.MuonAssociators.muonL1MultiMatch_cfi")
223  process.globalReplace('muonL1Info', process.muonL1MultiMatch.clone(src = process.muonL1Info.src.value()))
224  pmp = getattr(process, patMuonProd)
225  for X in byWhat:
226  pmp.userData.userInts.src += [ cms.InputTag('muonL1Info', "quality"+X) ]
227  pmp.userData.userFloats.src += [ cms.InputTag('muonL1Info', "deltaR"+X) ]
228  pmp.userData.userCands.src += [ cms.InputTag('muonL1Info', X) ]
229 
231  "Change the L1 trigger matching window to be suitable also for CSC single triggers"
232  if hasattr(process, 'muonL1Info'):
233  process.muonL1Info.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
234  process.muonL1Info.maxDeltaEta = 0.2
235  process.muonL1Info.fallbackToME1 = True
236  if hasattr(process, 'muonMatchHLTL1'):
237  process.muonMatchHLTL1.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
238  process.muonMatchHLTL1.maxDeltaEta = 0.2
239  process.muonMatchHLTL1.fallbackToME1 = True
240 
def massSearchReplaceAnyInputTag
Definition: helpers.py:262
def addL1UserData
Define a generic function, so that it can be used with existing PAT Muons.