CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/MuonAnalysis/MuonAssociators/python/patMuonsWithTrigger_cff.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.Config as cms
00002 
00003 ##    __  __       _          ____   _  _____   __  __                       
00004 ##   |  \/  | __ _| | _____  |  _ \ / \|_   _| |  \/  |_   _  ___  _ __  ___ 
00005 ##   | |\/| |/ _` | |/ / _ \ | |_) / _ \ | |   | |\/| | | | |/ _ \| '_ \/ __|
00006 ##   | |  | | (_| |   <  __/ |  __/ ___ \| |   | |  | | |_| | (_) | | | \__ \
00007 ##   |_|  |_|\__,_|_|\_\___| |_| /_/   \_\_|   |_|  |_|\__,_|\___/|_| |_|___/
00008 ##                                                                           
00009 ##   
00010 ### ==== Make PAT muons ====
00011 import PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi
00012 patMuonsWithoutTrigger = PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi.patMuons.clone(
00013     muonSource = 'muons',
00014     # embed the tracks, so we don't have to carry them around
00015     embedTrack          = True,
00016     embedCombinedMuon   = True,
00017     embedStandAloneMuon = True,
00018     embedPFCandidate    = False,
00019     embedCaloMETMuonCorrs = cms.bool(False),
00020     embedTcMETMuonCorrs   = cms.bool(False),
00021     # then switch off some features we don't need
00022     #addTeVRefits = False, ## <<--- this doesn't work. PAT bug ??
00023     embedPickyMuon = False,
00024     embedTpfmsMuon = False, 
00025     userIsolation = cms.PSet(),   # no extra isolation beyond what's in reco::Muon itself
00026     isoDeposits = cms.PSet(), # no heavy isodeposits
00027     addGenMatch = False,       # no mc: T&P doesn't take it from here anyway.
00028 )
00029 # Reset all these; the default in muonProducer_cfi is not empty, but wrong
00030 patMuonsWithoutTrigger.userData.userInts.src    = []
00031 patMuonsWithoutTrigger.userData.userFloats.src  = []
00032 patMuonsWithoutTrigger.userData.userCands.src   = []
00033 patMuonsWithoutTrigger.userData.userClasses.src = []
00034 
00035 ##    __  __       _       _       ____      ___        __  _     _ 
00036 ##   |  \/  | __ _| |_ ___| |__   |  _ \    / \ \      / / | |   / |
00037 ##   | |\/| |/ _` | __/ __| '_ \  | |_) |  / _ \ \ /\ / /  | |   | |
00038 ##   | |  | | (_| | || (__| | | | |  _ <  / ___ \ V  V /   | |___| |
00039 ##   |_|  |_|\__,_|\__\___|_| |_| |_| \_\/_/   \_\_/\_/    |_____|_|
00040 ##                                                                  
00041 ##   
00042 from MuonAnalysis.MuonAssociators.muonL1Match_cfi import muonL1Match as muonL1Info
00043 
00044 ## Define a generic function, so that it can be used with existing PAT muons
00045 def muons.">addL1UserData(patMuonProducer, l1ModuleLabel = "muonL1Info"):
00046     "Load variables inside PAT muon, from module <l1ModuleLabel> that you must run before it"
00047     patMuonProducer.userData.userInts.src += [
00048         cms.InputTag(l1ModuleLabel, "quality"), # will be -999 in case of no match
00049     ]
00050     patMuonProducer.userData.userFloats.src += [  
00051         cms.InputTag(l1ModuleLabel, "deltaR"),  # will be 999 in case of no match
00052     ]
00053     patMuonProducer.userData.userCands.src += [
00054         cms.InputTag(l1ModuleLabel)
00055     ]
00056 
00057 ## Do it for this collection of pat muons
00058 addL1UserData(patMuonsWithoutTrigger, "muonL1Info")
00059 
00060 ##    __  __       _       _       _   _ _   _____ 
00061 ##   |  \/  | __ _| |_ ___| |__   | | | | | |_   _|
00062 ##   | |\/| |/ _` | __/ __| '_ \  | |_| | |   | |  
00063 ##   | |  | | (_| | || (__| | | | |  _  | |___| |  
00064 ##   |_|  |_|\__,_|\__\___|_| |_| |_| |_|_____|_|  
00065 ##                                                 
00066 ##   
00067 
00068 ### ==== Unpack trigger, and match ====
00069 from PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cfi import patTrigger as patTriggerFull
00070 patTriggerFull.onlyStandAlone = True
00071 patTrigger = cms.EDFilter("PATTriggerObjectStandAloneSelector",
00072     src = cms.InputTag("patTriggerFull"),
00073     cut = cms.string('coll("hltL1extraParticles") || coll("hltL2MuonCandidates") || coll("hltL3MuonCandidates") || coll("hltGlbTrkMuonCands") || coll("hltMuTrackJpsiCtfTrackCands") || coll("hltMuTrackJpsiEffCtfTrackCands") || coll("hltMuTkMuJpsiTrackerMuonCands")'),
00074 ) 
00075 
00076 ### ==== Then perform a match for all HLT triggers of interest
00077 muonTriggerMatchHLT = cms.EDProducer( "PATTriggerMatcherDRDPtLessByR",
00078     src     = cms.InputTag( "patMuonsWithoutTrigger" ),
00079     matched = cms.InputTag( "patTrigger" ),
00080     matchedCuts = cms.string(""),
00081 #    andOr          = cms.bool( False ),
00082 #    filterIdsEnum  = cms.vstring( '*' ),
00083 #    filterIds      = cms.vint32( 0 ),
00084 #    filterLabels   = cms.vstring( '*' ),
00085 #    pathNames      = cms.vstring( '*' ),
00086 #    collectionTags = cms.vstring( '*' ),
00087     maxDPtRel = cms.double( 0.5 ),
00088     maxDeltaR = cms.double( 0.5 ),
00089     resolveAmbiguities    = cms.bool( True ),
00090     resolveByMatchQuality = cms.bool( True ) #change with respect to previous tag
00091 )
00092 
00093 ### == For HLT triggers which are just L1s, we need a different matcher
00094 from MuonAnalysis.MuonAssociators.muonHLTL1Match_cfi import muonHLTL1Match
00095 muonMatchL1 = muonHLTL1Match.clone(
00096     src     = muonTriggerMatchHLT.src,
00097     matched = muonTriggerMatchHLT.matched,
00098 )
00099 
00100 ### Single Mu L1
00101 muonMatchHLTL1 = muonMatchL1.clone(matchedCuts = cms.string('coll("hltL1extraParticles")'))
00102 muonMatchHLTL2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL2MuonCandidates")'), maxDeltaR = 0.3, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 1.2
00103 muonMatchHLTL3 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltL3MuonCandidates")'), maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
00104 muonMatchHLTL3T = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltGlbTrkMuonCands")'),  maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. It was: 0.5
00105 muonMatchHLTCtfTrack  = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiCtfTrackCands")'),    maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. 
00106 muonMatchHLTCtfTrack2 = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTrackJpsiEffCtfTrackCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0)  #maxDeltaR Changed accordingly to Zoltan tuning. 
00107 muonMatchHLTTrackMu  = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning. 
00108 
00109 patTriggerMatchers1Mu = cms.Sequence(
00110       muonMatchHLTL1 +
00111       muonMatchHLTL2 +
00112       muonMatchHLTL3 +
00113       muonMatchHLTL3T 
00114 )
00115 patTriggerMatchers1MuInputTags = [
00116     cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
00117     cms.InputTag('muonMatchHLTL1'),
00118     cms.InputTag('muonMatchHLTL2'),
00119     cms.InputTag('muonMatchHLTL3'),
00120     cms.InputTag('muonMatchHLTL3T'),
00121 ]
00122 
00123 patTriggerMatchers2Mu = cms.Sequence(
00124     muonMatchHLTCtfTrack  +
00125     muonMatchHLTCtfTrack2 +
00126     muonMatchHLTTrackMu
00127 )
00128 patTriggerMatchers2MuInputTags = [
00129     cms.InputTag('muonMatchHLTCtfTrack'),
00130     cms.InputTag('muonMatchHLTCtfTrack2'),
00131     cms.InputTag('muonMatchHLTTrackMu'),
00132 ]
00133 
00134 ## ==== Embed ====
00135 patMuonsWithTrigger = cms.EDProducer( "PATTriggerMatchMuonEmbedder",
00136     src     = cms.InputTag(  "patMuonsWithoutTrigger" ),
00137     matches = cms.VInputTag()
00138 )
00139 patMuonsWithTrigger.matches += patTriggerMatchers1MuInputTags
00140 patMuonsWithTrigger.matches += patTriggerMatchers2MuInputTags
00141 
00142 
00143 ## ==== Trigger Sequence ====
00144 patTriggerMatching = cms.Sequence(
00145     patTriggerFull * patTrigger * 
00146     patTriggerMatchers1Mu *
00147     patTriggerMatchers2Mu *
00148     patMuonsWithTrigger
00149 )
00150 
00151 patMuonsWithTriggerSequence = cms.Sequence(
00152     muonL1Info             *
00153     patMuonsWithoutTrigger *
00154     patTriggerMatching
00155 )
00156 
00157 
00158 
00159 def switchOffAmbiguityResolution(process):
00160     "Switch off ambiguity resolution: allow multiple reco muons to match to the same trigger muon"
00161     process.muonMatchHLTL1.resolveAmbiguities = False
00162     process.muonMatchHLTL2.resolveAmbiguities = False
00163     process.muonMatchHLTL3.resolveAmbiguities = False
00164     process.muonMatchHLTCtfTrack.resolveAmbiguities = False
00165     process.muonMatchHLTTrackMu.resolveAmbiguities  = False
00166 
00167 def changeTriggerProcessName(process, triggerProcessName, oldProcessName="HLT"):
00168     "Change the process name under which the trigger was run"
00169     patTriggerFull.processName = triggerProcessName
00170 
00171 def changeRecoMuonInput(process, recoMuonCollectionTag, oldRecoMuonCollectionTag=cms.InputTag("muons")):
00172     "Use a different input collection of reco muons"
00173     from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
00174     massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, oldRecoMuonCollectionTag, recoMuonCollectionTag)
00175 
00176 def useExistingPATMuons(process, newPatMuonTag, addL1Info=False):
00177     "Start from existing pat muons instead of producing them"
00178     process.patMuonsWithTriggerSequence.remove(process.patMuonsWithoutTrigger)
00179     process.patMuonsWithTriggerSequence.remove(process.muonL1Info)
00180     process.patMuonsWithTrigger.src = newPatMuonTag
00181     from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
00182     massSearchReplaceAnyInputTag(process.patMuonsWithTriggerSequence, cms.InputTag('patMuonsWithoutTrigger'), newPatMuonTag)
00183     if addL1Info:
00184         process.muonL1Info.src = newPatMuonTag.muonSource
00185         addL1UserData(getattr(process,newPatMuonTag.moduleLabel), 'muonL1Info')
00186 
00187 def addPreselection(process, cut):
00188     "Add a preselection cut to the muons before matching (might be relevant, due to ambiguity resolution in trigger matching!"
00189     process.patMuonsWithoutTriggerUnfiltered = process.patMuonsWithoutTrigger.clone()
00190     process.globalReplace('patMuonsWithoutTrigger', cms.EDFilter("PATMuonSelector", src = cms.InputTag('patMuonsWithoutTriggerUnfiltered'), cut = cms.string(cut))) 
00191     process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.patMuonsWithoutTriggerUnfiltered * process.patMuonsWithoutTrigger)
00192 
00193 def addMCinfo(process):
00194     "Add MC matching information to the muons"
00195     process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi")
00196     process.patMuonsWithTriggerSequence.replace(process.patMuonsWithoutTrigger, process.muonMatch + process.patMuonsWithoutTrigger)
00197     process.patMuonsWithoutTrigger.addGenMatch = True
00198     process.patMuonsWithoutTrigger.embedGenMatch = True
00199     process.patMuonsWithoutTrigger.genParticleMatch = 'muonMatch'
00200 
00201 def addDiMuonTriggers(process):
00202     print "[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default"
00203 
00204 def useL1MatchingWindowForSinglets(process):
00205     "Change the L1 trigger matching window to be suitable also for CSC single triggers"
00206     if hasattr(process, 'muonL1Info'):
00207         process.muonL1Info.maxDeltaR     = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
00208         process.muonL1Info.maxDeltaEta   = 0.2
00209         process.muonL1Info.fallbackToME1 = True
00210     if hasattr(process, 'muonMatchHLTL1'):
00211         process.muonMatchHLTL1.maxDeltaR     = 0.3 #Changed accordingly to Zoltan tuning. It was: 1.2
00212         process.muonMatchHLTL1.maxDeltaEta   = 0.2
00213         process.muonMatchHLTL1.fallbackToME1 = True
00214