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.
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  # then switch off some features we don't need
22  #addTeVRefits = False, ## <<--- this doesn't work. PAT bug ??
23  embedPickyMuon = False,
24  embedTpfmsMuon = False,
25  userIsolation = cms.PSet(), # no extra isolation beyond what's in reco::Muon itself
26  isoDeposits = cms.PSet(), # no heavy isodeposits
27  addGenMatch = False, # no mc: T&P doesn't take it from here anyway.
28 )
29 # Reset all these; the default in muonProducer_cfi is not empty, but wrong
30 patMuonsWithoutTrigger.userData.userInts.src = []
31 patMuonsWithoutTrigger.userData.userFloats.src = []
32 patMuonsWithoutTrigger.userData.userCands.src = []
33 patMuonsWithoutTrigger.userData.userClasses.src = []
34 
35 ## __ __ _ _ ____ ___ __ _ _
36 ## | \/ | __ _| |_ ___| |__ | _ \ / \ \ / / | | / |
37 ## | |\/| |/ _` | __/ __| '_ \ | |_) | / _ \ \ /\ / / | | | |
38 ## | | | | (_| | || (__| | | | | _ < / ___ \ V V / | |___| |
39 ## |_| |_|\__,_|\__\___|_| |_| |_| \_\/_/ \_\_/\_/ |_____|_|
40 ##
41 ##
42 from MuonAnalysis.MuonAssociators.muonL1Match_cfi import muonL1Match as muonL1Info
43 
44 ## Define a generic function, so that it can be used with existing PAT Muons
45 def addL1UserData(patMuonProducer, l1ModuleLabel = "muonL1Info"):
46  "Load variables inside PAT muon, from module <l1ModuleLabel> that you must run before it"
47  patMuonProducer.userData.userInts.src += [
48  cms.InputTag(l1ModuleLabel, "quality"), # will be -999 in case of no match
49  ]
50  patMuonProducer.userData.userFloats.src += [
51  cms.InputTag(l1ModuleLabel, "deltaR"), # will be 999 in case of no match
52  ]
53  patMuonProducer.userData.userCands.src += [
54  cms.InputTag(l1ModuleLabel)
55  ]
56 
57 ## Do it for this collection of pat Muons
58 addL1UserData(patMuonsWithoutTrigger, "muonL1Info")
59 
60 ## __ __ _ _ _ _ _ _____
61 ## | \/ | __ _| |_ ___| |__ | | | | | |_ _|
62 ## | |\/| |/ _` | __/ __| '_ \ | |_| | | | |
63 ## | | | | (_| | || (__| | | | | _ | |___| |
64 ## |_| |_|\__,_|\__\___|_| |_| |_| |_|_____|_|
65 ##
66 ##
67 
68 ### ==== Unpack trigger, and match ====
69 from PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cfi import patTrigger as patTriggerFull
70 patTriggerFull.onlyStandAlone = True
71 patTrigger = cms.EDFilter("PATTriggerObjectStandAloneSelector",
72  src = cms.InputTag("patTriggerFull"),
73  cut = cms.string('coll("hltL1extraParticles") || coll("hltL2MuonCandidates") || coll("hltL3MuonCandidates") || coll("hltGlbTrkMuonCands") || coll("hltMuTrackJpsiCtfTrackCands") || coll("hltMuTrackJpsiEffCtfTrackCands") || coll("hltMuTkMuJpsiTrackerMuonCands")'),
74 )
75 
76 ### ==== Then perform a match for all HLT triggers of interest
77 muonTriggerMatchHLT = cms.EDProducer( "PATTriggerMatcherDRDPtLessByR",
78  src = cms.InputTag( "patMuonsWithoutTrigger" ),
79  matched = cms.InputTag( "patTrigger" ),
80  matchedCuts = cms.string(""),
81 # andOr = cms.bool( False ),
82 # filterIdsEnum = cms.vstring( '*' ),
83 # filterIds = cms.vint32( 0 ),
84 # filterLabels = cms.vstring( '*' ),
85 # pathNames = cms.vstring( '*' ),
86 # collectionTags = cms.vstring( '*' ),
87  maxDPtRel = cms.double( 0.5 ),
88  maxDeltaR = cms.double( 0.5 ),
89  resolveAmbiguities = cms.bool( True ),
90  resolveByMatchQuality = cms.bool( True ) #change with respect to previous tag
91 )
92 
93 ### == For HLT triggers which are just L1s, we need a different matcher
94 from MuonAnalysis.MuonAssociators.muonHLTL1Match_cfi import muonHLTL1Match
95 muonMatchL1 = muonHLTL1Match.clone(
96  src = muonTriggerMatchHLT.src,
97  matched = muonTriggerMatchHLT.matched,
98 )
99 
100 ### Single Mu L1
101 muonMatchHLTL1 = muonMatchL1.clone(matchedCuts = cms.string('coll("hltL1extraParticles")'))
102 muonMatchHLTL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL2MuonCandidates")'), maxDeltaR = 0.3, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 1.2
103 muonMatchHLTL3 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL3MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
104 muonMatchHLTL3T = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltGlbTrkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
105 muonMatchHLTCtfTrack = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
106 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
107 muonMatchHLTTrackMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
108 
109 patTriggerMatchers1Mu = cms.Sequence(
110  muonMatchHLTL1 +
111  muonMatchHLTL2 +
112  muonMatchHLTL3 +
113  muonMatchHLTL3T
114 )
115 patTriggerMatchers1MuInputTags = [
116  cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
117  cms.InputTag('muonMatchHLTL1'),
118  cms.InputTag('muonMatchHLTL2'),
119  cms.InputTag('muonMatchHLTL3'),
120  cms.InputTag('muonMatchHLTL3T'),
121 ]
122 
123 patTriggerMatchers2Mu = cms.Sequence(
124  muonMatchHLTCtfTrack +
125  muonMatchHLTCtfTrack2 +
126  muonMatchHLTTrackMu
127 )
128 patTriggerMatchers2MuInputTags = [
129  cms.InputTag('muonMatchHLTCtfTrack'),
130  cms.InputTag('muonMatchHLTCtfTrack2'),
131  cms.InputTag('muonMatchHLTTrackMu'),
132 ]
133 
134 ## ==== Embed ====
135 patMuonsWithTrigger = cms.EDProducer( "PATTriggerMatchMuonEmbedder",
136  src = cms.InputTag( "patMuonsWithoutTrigger" ),
137  matches = cms.VInputTag()
138 )
139 patMuonsWithTrigger.matches += patTriggerMatchers1MuInputTags
140 patMuonsWithTrigger.matches += patTriggerMatchers2MuInputTags
141 
142 
143 ## ==== Trigger Sequence ====
144 patTriggerMatching = cms.Sequence(
145  patTriggerFull * patTrigger *
146  patTriggerMatchers1Mu *
147  patTriggerMatchers2Mu *
148  patMuonsWithTrigger
149 )
150 
151 patMuonsWithTriggerSequence = cms.Sequence(
152  muonL1Info *
153  patMuonsWithoutTrigger *
154  patTriggerMatching
155 )
156 
157 
158 
160  "Switch off ambiguity resolution: allow multiple reco muons to match to the same trigger muon"
161  process.muonMatchHLTL1.resolveAmbiguities = False
162  process.muonMatchHLTL2.resolveAmbiguities = False
163  process.muonMatchHLTL3.resolveAmbiguities = False
164  process.muonMatchHLTCtfTrack.resolveAmbiguities = False
165  process.muonMatchHLTTrackMu.resolveAmbiguities = False
166 
167 def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT"):
168  "Change the process name under which the trigger was run"
169  patTriggerFull.processName = triggerProcessName
170 
171 def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons")):
172  "Use a different input collection of reco muons"
173  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
174  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, oldRecoMuonCollectionTag, recoMuonCollectionTag)
175 
176 def useExistingPATMuons(process, newPatMuonTag, addL1Info=False):
177  "Start from existing pat Muons instead of producing them"
178  process.patMuonsWithTriggerSequence.remove(process.patMuonsWithoutTrigger)
179  process.patMuonsWithTriggerSequence.remove(process.muonL1Info)
180  process.patMuonsWithTrigger.src = newPatMuonTag
181  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
182  massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, cms.InputTag('patMuonsWithoutTrigger'), newPatMuonTag)
183  if addL1Info:
184  process.muonL1Info.src = newPatMuonTag.muonSource
185  addL1UserData(getattr(process,newPatMuonTag.moduleLabel), 'muonL1Info')
186 
187 def addPreselection(process, cut):
188  "Add a preselection cut to the muons before matching (might be relevant, due to ambiguity resolution in trigger matching!"
189  process.patMuonsWithoutTriggerUnfiltered = process.patMuonsWithoutTrigger.clone()
190  process.globalReplace('patMuonsWithoutTrigger', cms.EDFilter("PATMuonSelector", src = cms.InputTag('patMuonsWithoutTriggerUnfiltered'), cut = cms.string(cut)))
191  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.patMuonsWithoutTriggerUnfiltered * process.patMuonsWithoutTrigger)
192 
193 def addMCinfo(process):
194  "Add MC matching information to the muons"
195  process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
196  process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.muonMatch + process.patMuonsWithoutTrigger)
197  process.patMuonsWithoutTrigger.addGenMatch = True
198  process.patMuonsWithoutTrigger.embedGenMatch = True
199  process.patMuonsWithoutTrigger.genParticleMatch = 'muonMatch'
200 
201 def addDiMuonTriggers(process):
202  print "[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default"
203 
205  "Change the L1 trigger matching window to be suitable also for CSC single triggers"
206  if hasattr(process, 'muonL1Info'):
207  process.muonL1Info.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
208  process.muonL1Info.maxDeltaEta = 0.2
209  process.muonL1Info.fallbackToME1 = True
210  if hasattr(process, 'muonMatchHLTL1'):
211  process.muonMatchHLTL1.maxDeltaR = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
212  process.muonMatchHLTL1.maxDeltaEta = 0.2
213  process.muonMatchHLTL1.fallbackToME1 = True
214 
def massSearchReplaceAnyInputTag
Definition: helpers.py:258
def addL1UserData
Define a generic function, so that it can be used with existing PAT Muons.