Back to home page

Project CMSSW displayed by LXR

 
 

    


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 ### ==== Make PAT Muons ====
0011 import PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi
0012 patMuonsWithoutTrigger = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.clone(
0013     muonSource = 'muons',
0014     # embed the tracks, so we don't have to carry them around
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     # then switch off some features we don't need
0023     #addTeVRefits = False, ## <<--- this doesn't work. PAT bug ??
0024     embedPickyMuon = False,
0025     embedTpfmsMuon = False,
0026     userIsolation = cms.PSet(),   # no extra isolation beyond what's in reco::Muon itself
0027     isoDeposits = cms.PSet(), # no heavy isodeposits
0028     addGenMatch = False,       # no mc: T&P doesn't take it from here anyway.
0029 )
0030 # Reset all these; the default in muonProducer_cfi is not empty, but wrong
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 ##   | |  | | (_| | || (__| | | | |  _ <  / ___ \ V  V /   | |___| |
0040 ##   |_|  |_|\__,_|\__\___|_| |_| |_| \_\/_/   \_\_/\_/    |_____|_|
0041 ##
0042 ##
0043 from MuonAnalysis.MuonAssociators.muonL1Match_cfi import muonL1Match as muonL1Info
0044 
0045 ## Define a generic function, so that it can be used with existing PAT Muons
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"), # will be -999 in case of no match
0050     ]
0051     patMuonProducer.userData.userFloats.src += [
0052         cms.InputTag(l1ModuleLabel, "deltaR"),  # will be 999 in case of no match
0053     ]
0054     patMuonProducer.userData.userFloats.src += [
0055         cms.InputTag(l1ModuleLabel, "deltaPhi"),  # will be 999 in case of no match
0056     ]
0057     patMuonProducer.userData.userInts.src += [
0058         cms.InputTag(l1ModuleLabel, "bx"),  # will be -999 in case of no match
0059     ]
0060     patMuonProducer.userData.userCands.src += [
0061         cms.InputTag(l1ModuleLabel)
0062     ]
0063 
0064 ## Do it for this collection of pat Muons
0065 addL1UserData(patMuonsWithoutTrigger, "muonL1Info")
0066 
0067 ##    __  __       _       _       _   _ _   _____
0068 ##   |  \/  | __ _| |_ ___| |__   | | | | | |_   _|
0069 ##   | |\/| |/ _` | __/ __| '_ \  | |_| | |   | |
0070 ##   | |  | | (_| | || (__| | | | |  _  | |___| |
0071 ##   |_|  |_|\__,_|\__\___|_| |_| |_| |_|_____|_|
0072 ##
0073 ##
0074 
0075 ### ==== Unpack trigger, and match ====
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 #patTrigger = cms.EDFilter("PATTriggerObjectStandAloneSelector",
0083 #    src = cms.InputTag("patTriggerFull"),
0084 #    cut = cms.string('coll("hltL1extraParticles") || coll("hltL2MuonCandidates") || coll("hltIterL3MuonCandidates") || coll("hltGlbTrkMuonCands") || coll("hltMuTrackJpsiCtfTrackCands") || coll("hltMuTrackJpsiEffCtfTrackCands") || coll("hltMuTkMuJpsiTrackerMuonCands")'),
0085 #)
0086 
0087 ### ==== Then perform a match for all HLT triggers of interest
0088 muonTriggerMatchHLT = cms.EDProducer( "PATTriggerMatcherDRDPtLessByR",
0089     src     = cms.InputTag( "patMuonsWithoutTrigger" ),
0090     matched = cms.InputTag( "patTrigger" ),
0091     matchedCuts = cms.string(""),
0092 #    andOr          = cms.bool( False ),
0093 #    filterIdsEnum  = cms.vstring( '*' ),
0094 #    filterIds      = cms.vint32( 0 ),
0095 #    filterLabels   = cms.vstring( '*' ),
0096 #    pathNames      = cms.vstring( '*' ),
0097 #    collectionTags = cms.vstring( '*' ),
0098     maxDPtRel = cms.double( 0.5 ),
0099     maxDeltaR = cms.double( 0.5 ),
0100     resolveAmbiguities    = cms.bool( True ),
0101     resolveByMatchQuality = cms.bool( True ) #change with respect to previous tag
0102 )
0103 
0104 ### == For HLT triggers which are just L1s, we need a different matcher
0105 from MuonAnalysis.MuonAssociators.muonHLTL1Match_cfi import muonHLTL1Match
0106 muonMatchL1 = muonHLTL1Match.clone(
0107     src     = muonTriggerMatchHLT.src,
0108     matched = muonTriggerMatchHLT.matched,
0109 )
0110 
0111 ### Single Mu L1
0112 muonMatchHLTL1 = muonMatchL1.clone(matchedCuts = cms.string('coll("hltL1extraParticles")'))
0113 muonMatchHLTL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL2MuonCandidates")'), maxDeltaR = 0.3, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 1.2
0114 muonMatchHLTL3 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltIterL3MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
0115 muonMatchHLTL3T = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltGlbTrkMuonCands")'),  maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
0116 muonMatchHLTL3fromL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltIterL3FromL2MuonCandidates")'),  maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
0117 muonMatchHLTTkMu =  muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltHighPtTkMuonCands")'),  maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
0118 muonMatchHLTCtfTrack  = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'),    maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning.
0119 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning.
0120 muonMatchHLTTrackMu  = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.
0121 muonMatchHLTTrackIt  = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltTracksIter")'), maxDeltaR = 0.1, maxDPtRel = 1.0) #maxDeltaR Changed accordingly to Zoltan tuning.
0122 
0123 patTriggerMatchers1Mu = cms.Sequence(
0124       #muonMatchHLTL1 +   # keep off by default, since it is slow and usually not needed
0125       muonMatchHLTL2 +
0126       muonMatchHLTL3 +
0127       muonMatchHLTL3T +
0128       muonMatchHLTL3fromL2 +
0129       muonMatchHLTTkMu
0130 )
0131 patTriggerMatchers1MuInputTags = [
0132     #cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
0133     #cms.InputTag('muonMatchHLTL1'),
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 ## ==== Embed ====
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 ## ==== Trigger Sequence ====
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 #Changed accordingly to Zoltan tuning. It was: 1.2
0235         process.muonL1Info.maxDeltaEta   = 0.2
0236         process.muonL1Info.fallbackToME1 = True
0237     if hasattr(process, 'muonMatchHLTL1'):
0238         process.muonMatchHLTL1.maxDeltaR     = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
0239         process.muonMatchHLTL1.maxDeltaEta   = 0.2
0240         process.muonMatchHLTL1.fallbackToME1 = True
0241 
0242 
0243 def useL1Stage2Candidates(process):
0244     if hasattr(process, 'muonL1Info'):
0245         # l1PhiOffest might need a second look
0246         # barrel seems not to requre it, whereas encaps do
0247         # anyhow the effect is of the order of 0.02
0248         #process.muonL1Info.l1PhiOffset = cms.double()
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())