File indexing completed on 2024-11-25 02:29:48
0001 import FWCore.ParameterSet.Config as cms
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 import PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi
0012 patMuonsWithoutTrigger = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.clone(
0013 muonSource = 'muons',
0014
0015 embedTrack = True,
0016 embedCombinedMuon = True,
0017 embedStandAloneMuon = True,
0018 embedPFCandidate = False,
0019 embedCaloMETMuonCorrs = cms.bool(False),
0020 embedTcMETMuonCorrs = cms.bool(False),
0021 embedPfEcalEnergy = cms.bool(False),
0022
0023
0024 embedPickyMuon = False,
0025 embedTpfmsMuon = False,
0026 userIsolation = cms.PSet(),
0027 isoDeposits = cms.PSet(),
0028 addGenMatch = False,
0029 )
0030
0031 patMuonsWithoutTrigger.userData.userInts.src = []
0032 patMuonsWithoutTrigger.userData.userFloats.src = []
0033 patMuonsWithoutTrigger.userData.userCands.src = []
0034 patMuonsWithoutTrigger.userData.userClasses.src = []
0035
0036
0037
0038
0039
0040
0041
0042
0043 from MuonAnalysis.MuonAssociators.muonL1Match_cfi import muonL1Match as muonL1Info
0044
0045
0046 def addL1UserData(patMuonProducer, l1ModuleLabel = "muonL1Info"):
0047 "Load variables inside PAT muon, from module <l1ModuleLabel> that you must run before it"
0048 patMuonProducer.userData.userInts.src += [
0049 cms.InputTag(l1ModuleLabel, "quality"),
0050 ]
0051 patMuonProducer.userData.userFloats.src += [
0052 cms.InputTag(l1ModuleLabel, "deltaR"),
0053 ]
0054 patMuonProducer.userData.userFloats.src += [
0055 cms.InputTag(l1ModuleLabel, "deltaPhi"),
0056 ]
0057 patMuonProducer.userData.userInts.src += [
0058 cms.InputTag(l1ModuleLabel, "bx"),
0059 ]
0060 patMuonProducer.userData.userCands.src += [
0061 cms.InputTag(l1ModuleLabel)
0062 ]
0063
0064
0065 addL1UserData(patMuonsWithoutTrigger, "muonL1Info")
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 from PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cfi import patTrigger as patTriggerFull
0077 patTriggerFull.onlyStandAlone = True
0078 patTrigger = cms.EDProducer("TriggerObjectFilterByCollection",
0079 src = cms.InputTag("patTriggerFull"),
0080 collections = cms.vstring("hltL1extraParticles", "hltGmtStage2Digis", "hltL2MuonCandidates", "hltIterL3MuonCandidates","hltIterL3FromL2MuonCandidates","hltHighPtTkMuonCands", "hltGlbTrkMuonCands", "hltMuTrackJpsiCtfTrackCands", "hltMuTrackJpsiEffCtfTrackCands", "hltMuTkMuJpsiTrackerMuonCands","hltTracksIter"),
0081 )
0082
0083
0084
0085
0086
0087
0088 muonTriggerMatchHLT = cms.EDProducer( "PATTriggerMatcherDRDPtLessByR",
0089 src = cms.InputTag( "patMuonsWithoutTrigger" ),
0090 matched = cms.InputTag( "patTrigger" ),
0091 matchedCuts = cms.string(""),
0092
0093
0094
0095
0096
0097
0098 maxDPtRel = cms.double( 0.5 ),
0099 maxDeltaR = cms.double( 0.5 ),
0100 resolveAmbiguities = cms.bool( True ),
0101 resolveByMatchQuality = cms.bool( True )
0102 )
0103
0104
0105 from MuonAnalysis.MuonAssociators.muonHLTL1Match_cfi import muonHLTL1Match
0106 muonMatchL1 = muonHLTL1Match.clone(
0107 src = muonTriggerMatchHLT.src,
0108 matched = muonTriggerMatchHLT.matched,
0109 )
0110
0111
0112 muonMatchHLTL1 = muonMatchL1.clone(matchedCuts = cms.string('coll("hltL1extraParticles")'))
0113 muonMatchHLTL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL2MuonCandidates")'), maxDeltaR = 0.3, maxDPtRel = 10.0)
0114 muonMatchHLTL3 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltIterL3MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0)
0115 muonMatchHLTL3T = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltGlbTrkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0)
0116 muonMatchHLTL3fromL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltIterL3FromL2MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0)
0117 muonMatchHLTTkMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltHighPtTkMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0)
0118 muonMatchHLTCtfTrack = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0)
0119 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0)
0120 muonMatchHLTTrackMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0)
0121 muonMatchHLTTrackIt = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltTracksIter")'), maxDeltaR = 0.1, maxDPtRel = 1.0)
0122
0123 patTriggerMatchers1Mu = cms.Sequence(
0124
0125 muonMatchHLTL2 +
0126 muonMatchHLTL3 +
0127 muonMatchHLTL3T +
0128 muonMatchHLTL3fromL2 +
0129 muonMatchHLTTkMu
0130 )
0131 patTriggerMatchers1MuInputTags = [
0132
0133
0134 cms.InputTag('muonMatchHLTL2'),
0135 cms.InputTag('muonMatchHLTL3'),
0136 cms.InputTag('muonMatchHLTL3T'),
0137 cms.InputTag('muonMatchHLTL3fromL2'),
0138 cms.InputTag('muonMatchHLTTkMu'),
0139 ]
0140
0141 patTriggerMatchers2Mu = cms.Sequence(
0142 muonMatchHLTCtfTrack +
0143 muonMatchHLTCtfTrack2 +
0144 muonMatchHLTTrackMu +
0145 muonMatchHLTTrackIt
0146 )
0147 patTriggerMatchers2MuInputTags = [
0148 cms.InputTag('muonMatchHLTCtfTrack'),
0149 cms.InputTag('muonMatchHLTCtfTrack2'),
0150 cms.InputTag('muonMatchHLTTrackMu'),
0151 cms.InputTag('muonMatchHLTTrackIt'),
0152 ]
0153
0154
0155 patMuonsWithTrigger = cms.EDProducer( "PATTriggerMatchMuonEmbedder",
0156 src = cms.InputTag( "patMuonsWithoutTrigger" ),
0157 matches = cms.VInputTag()
0158 )
0159 patMuonsWithTrigger.matches += patTriggerMatchers1MuInputTags
0160 patMuonsWithTrigger.matches += patTriggerMatchers2MuInputTags
0161
0162
0163
0164 patTriggerMatching = cms.Sequence(
0165 patTriggerFull * patTrigger *
0166 patTriggerMatchers1Mu *
0167 patTriggerMatchers2Mu *
0168 patMuonsWithTrigger
0169 )
0170
0171 patMuonsWithTriggerSequence = cms.Sequence(
0172 muonL1Info *
0173 patMuonsWithoutTrigger *
0174 patTriggerMatching
0175 )
0176
0177
0178
0179 def switchOffAmbiguityResolution(process):
0180 "Switch off ambiguity resolution: allow multiple reco muons to match to the same trigger muon"
0181 process.muonMatchHLTL1.resolveAmbiguities = False
0182 process.muonMatchHLTL2.resolveAmbiguities = False
0183 process.muonMatchHLTL3.resolveAmbiguities = False
0184 process.muonMatchHLTL3fromL2.resolveAmbiguities = False
0185 process.muonMatchHLTTkMu.resolveAmbiguities = False
0186 process.muonMatchHLTCtfTrack.resolveAmbiguities = False
0187 process.muonMatchHLTTrackMu.resolveAmbiguities = False
0188 process.muonMatchHLTTrackIt.resolveAmbiguities = False
0189
0190 def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT"):
0191 "Change the process name under which the trigger was run"
0192 patTriggerFull.processName = triggerProcessName
0193
0194 def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons")):
0195 "Use a different input collection of reco muons"
0196 from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
0197 massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, oldRecoMuonCollectionTag, recoMuonCollectionTag)
0198
0199 def useExistingPATMuons(process, newPatMuonTag, addL1Info=False):
0200 "Start from existing pat Muons instead of producing them"
0201 process.patMuonsWithTriggerSequence.remove(process.patMuonsWithoutTrigger)
0202 process.patMuonsWithTriggerSequence.remove(process.muonL1Info)
0203 process.patMuonsWithTrigger.src = newPatMuonTag
0204 from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
0205 massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, cms.InputTag('patMuonsWithoutTrigger'), newPatMuonTag)
0206 if addL1Info:
0207 process.muonL1Info.src = newPatMuonTag.muonSource
0208 addL1UserData(getattr(process,newPatMuonTag.moduleLabel), 'muonL1Info')
0209
0210 def addPreselection(process, cut):
0211 "Add a preselection cut to the muons before matching (might be relevant, due to ambiguity resolution in trigger matching!"
0212 process.patMuonsWithoutTriggerUnfiltered = process.patMuonsWithoutTrigger.clone()
0213 process.globalReplace('patMuonsWithoutTrigger', cms.EDFilter("PATMuonSelector", src = cms.InputTag('patMuonsWithoutTriggerUnfiltered'), cut = cms.string(cut)))
0214 process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.patMuonsWithoutTriggerUnfiltered * process.patMuonsWithoutTrigger)
0215
0216 def addMCinfo(process):
0217 "Add MC matching information to the muons"
0218 process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
0219 process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.muonMatch + process.patMuonsWithoutTrigger)
0220 process.patMuonsWithoutTrigger.addGenMatch = True
0221 process.patMuonsWithoutTrigger.embedGenMatch = True
0222 process.patMuonsWithoutTrigger.genParticleMatch = 'muonMatch'
0223
0224 def addDiMuonTriggers(process):
0225 print("[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default")
0226
0227 def addHLTL1Passthrough(process, embedder="patMuonsWithTrigger"):
0228 process.patMuonsWithTriggerSequence.replace(process.muonMatchHLTL3, process.muonMatchHLTL1 + process.muonMatchHLTL3)
0229 getattr(process,embedder).matches += [ cms.InputTag('muonMatchHLTL1'), cms.InputTag('muonMatchHLTL1','propagatedReco') ]
0230
0231 def useL1MatchingWindowForSinglets(process):
0232 "Change the L1 trigger matching window to be suitable also for CSC single triggers"
0233 if hasattr(process, 'muonL1Info'):
0234 process.muonL1Info.maxDeltaR = 0.3
0235 process.muonL1Info.maxDeltaEta = 0.2
0236 process.muonL1Info.fallbackToME1 = True
0237 if hasattr(process, 'muonMatchHLTL1'):
0238 process.muonMatchHLTL1.maxDeltaR = 0.3
0239 process.muonMatchHLTL1.maxDeltaEta = 0.2
0240 process.muonMatchHLTL1.fallbackToME1 = True
0241
0242
0243 def useL1Stage2Candidates(process):
0244 if hasattr(process, 'muonL1Info'):
0245
0246
0247
0248
0249 process.muonL1Info.useMB2InOverlap = cms.bool(True)
0250 process.muonL1Info.useStage2L1 = cms.bool(True)
0251 process.muonL1Info.preselection = cms.string("")
0252 process.muonL1Info.matched = cms.InputTag("gmtStage2Digis:Muon:")
0253
0254 def appendL1MatchingAlgo(process, algo = "quality"):
0255 if hasattr(process, 'muonL1Info'):
0256 newMuonL1Info = process.muonL1Info.clone(sortBy = cms.string(algo),
0257 sortByQuality = cms.bool(algo == "quality"),
0258 sortByDeltaPhi = cms.bool(algo == "deltaEta"),
0259 sortByDeltaEta = cms.bool(algo == "deltaPhi"),
0260 sortByPt = cms.bool(algo == "pt"),
0261 maxDeltaR = cms.double(0.3))
0262 setattr(process, "muonL1Info" + algo.title(), newMuonL1Info)
0263 process.patMuonsWithTriggerSequence.replace(process.muonL1Info, process.muonL1Info + getattr(process, 'muonL1Info' + algo.title()))
0264 addL1UserData(patMuonsWithoutTrigger, "muonL1Info" + algo.title())