test
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", "hltGlbTrkMuonCands", "hltMuTrackJpsiCtfTrackCands", "hltMuTrackJpsiEffCtfTrackCands", "hltMuTkMuJpsiTrackerMuonCands"),
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 muonMatchHLTCtfTrack = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
111 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
112 muonMatchHLTTrackMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
113 
114 patTriggerMatchers1Mu = cms.Sequence(
115  #muonMatchHLTL1 + # keep off by default, since it is slow and usually not needed
116  muonMatchHLTL2 +
117  muonMatchHLTL3 +
118  muonMatchHLTL3T
119 )
120 patTriggerMatchers1MuInputTags = [
121  #cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
122  #cms.InputTag('muonMatchHLTL1'),
123  cms.InputTag('muonMatchHLTL2'),
124  cms.InputTag('muonMatchHLTL3'),
125  cms.InputTag('muonMatchHLTL3T'),
126 ]
127 
128 patTriggerMatchers2Mu = cms.Sequence(
129  muonMatchHLTCtfTrack +
130  muonMatchHLTCtfTrack2 +
131  muonMatchHLTTrackMu
132 )
133 patTriggerMatchers2MuInputTags = [
134  cms.InputTag('muonMatchHLTCtfTrack'),
135  cms.InputTag('muonMatchHLTCtfTrack2'),
136  cms.InputTag('muonMatchHLTTrackMu'),
137 ]
138 
139 ## ==== Embed ====
140 patMuonsWithTrigger = cms.EDProducer( "PATTriggerMatchMuonEmbedder",
141  src = cms.InputTag( "patMuonsWithoutTrigger" ),
142  matches = cms.VInputTag()
143 )
144 patMuonsWithTrigger.matches += patTriggerMatchers1MuInputTags
145 patMuonsWithTrigger.matches += patTriggerMatchers2MuInputTags
146 
147 
148 ## ==== Trigger Sequence ====
149 patTriggerMatching = cms.Sequence(
150  patTriggerFull * patTrigger *
151  patTriggerMatchers1Mu *
152  patTriggerMatchers2Mu *
153  patMuonsWithTrigger
154 )
155 
156 patMuonsWithTriggerSequence = cms.Sequence(
157  muonL1Info *
158  patMuonsWithoutTrigger *
159  patTriggerMatching
160 )
161 
162 
163 
165  "Switch off ambiguity resolution: allow multiple reco muons to match to the same trigger muon"
166  process.muonMatchHLTL1.resolveAmbiguities = False
167  process.muonMatchHLTL2.resolveAmbiguities = False
168  process.muonMatchHLTL3.resolveAmbiguities = False
169  process.muonMatchHLTCtfTrack.resolveAmbiguities = False
170  process.muonMatchHLTTrackMu.resolveAmbiguities = False
171 
172 def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT"):
173  "Change the process name under which the trigger was run"
174  patTriggerFull.processName = triggerProcessName
175 
176 def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons")):
177  "Use a different input collection of reco muons"
178  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
179  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, oldRecoMuonCollectionTag, recoMuonCollectionTag)
180 
181 def useExistingPATMuons(process, newPatMuonTag, addL1Info=False):
182  "Start from existing pat Muons instead of producing them"
183  process.patMuonsWithTriggerSequence.remove(process.patMuonsWithoutTrigger)
184  process.patMuonsWithTriggerSequence.remove(process.muonL1Info)
185  process.patMuonsWithTrigger.src = newPatMuonTag
186  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
187  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, cms.InputTag('patMuonsWithoutTrigger'), newPatMuonTag)
188  if addL1Info:
189  process.muonL1Info.src = newPatMuonTag.muonSource
190  addL1UserData(getattr(process,newPatMuonTag.moduleLabel), 'muonL1Info')
191 
192 def addPreselection(process, cut):
193  "Add a preselection cut to the muons before matching (might be relevant, due to ambiguity resolution in trigger matching!"
194  process.patMuonsWithoutTriggerUnfiltered = process.patMuonsWithoutTrigger.clone()
195  process.globalReplace('patMuonsWithoutTrigger', cms.EDFilter("PATMuonSelector", src = cms.InputTag('patMuonsWithoutTriggerUnfiltered'), cut = cms.string(cut)))
196  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.patMuonsWithoutTriggerUnfiltered * process.patMuonsWithoutTrigger)
197 
198 def addMCinfo(process):
199  "Add MC matching information to the muons"
200  process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
201  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.muonMatch + process.patMuonsWithoutTrigger)
202  process.patMuonsWithoutTrigger.addGenMatch = True
203  process.patMuonsWithoutTrigger.embedGenMatch = True
204  process.patMuonsWithoutTrigger.genParticleMatch = 'muonMatch'
205 
206 def addDiMuonTriggers(process):
207  print "[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default"
208 
209 def addHLTL1Passthrough(process, embedder="patMuonsWithTrigger"):
210  process.patMuonsWithTriggerSequence.replace(process.muonMatchHLTL3, process.muonMatchHLTL1 + process.muonMatchHLTL3)
211  getattr(process,embedder).matches += [ cms.InputTag('muonMatchHLTL1'), cms.InputTag('muonMatchHLTL1','propagatedReco') ]
212 
213 def useExtendedL1Match(process, patMuonProd="patMuonsWithoutTrigger", byWhat=["ByQ"]):
214  process.load("MuonAnalysis.MuonAssociators.muonL1MultiMatch_cfi")
215  process.globalReplace('muonL1Info', process.muonL1MultiMatch.clone(src = process.muonL1Info.src.value()))
216  pmp = getattr(process, patMuonProd)
217  for X in byWhat:
218  pmp.userData.userInts.src += [ cms.InputTag('muonL1Info', "quality"+X) ]
219  pmp.userData.userFloats.src += [ cms.InputTag('muonL1Info', "deltaR"+X) ]
220  pmp.userData.userCands.src += [ cms.InputTag('muonL1Info', X) ]
221 
223  "Change the L1 trigger matching window to be suitable also for CSC single triggers"
224  if hasattr(process, 'muonL1Info'):
225  process.muonL1Info.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
226  process.muonL1Info.maxDeltaEta = 0.2
227  process.muonL1Info.fallbackToME1 = True
228  if hasattr(process, 'muonMatchHLTL1'):
229  process.muonMatchHLTL1.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
230  process.muonMatchHLTL1.maxDeltaEta = 0.2
231  process.muonMatchHLTL1.fallbackToME1 = True
232 
def massSearchReplaceAnyInputTag
Definition: helpers.py:262
def addL1UserData
Define a generic function, so that it can be used with existing PAT Muons.