CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/PhysicsTools/Configuration/python/SUSY_pattuple_cff.py

Go to the documentation of this file.
00001 #
00002 #  SUSY-PAT Configuration fragment
00003 #
00004 #  PAT Configuration for the SUSY group - 53X series
00005 #  More information here:
00006 #  https://twiki.cern.ch/twiki/bin/view/CMS/SusyPatLayer1DefV12
00007 #test
00008 
00009 
00010 import FWCore.ParameterSet.Config as cms
00011 
00012 def addDefaultSUSYPAT(process,mcInfo=True,HLTMenu='HLT',JetMETCorrections=['L2Relative', 'L3Absolute'],mcVersion='',theJetNames = ['AK5PF'],doValidation=False,extMatch=False,doSusyTopProjection=False,doType1MetCorrection=True,doType0MetCorrection=False):
00013     loadPF2PAT(process,mcInfo,JetMETCorrections,extMatch,doSusyTopProjection,doType1MetCorrection,doType0MetCorrection,'PF')
00014     addTagInfos(process,JetMETCorrections)
00015     if not mcInfo:
00016         removeMCDependence(process)
00017     loadPAT(process,JetMETCorrections,extMatch)
00018     addJetMET(process,theJetNames,JetMETCorrections,mcVersion)
00019     # loadType1METSequence(process)   # defines process.Type1METSequence
00020     # loadPATTriggers(process,HLTMenu,theJetNames,electronMatches,muonMatches,tauMatches,jetMatches,photonMatches)
00021 
00022     #-- Counter for the number of processed events --------------------------------
00023     process.eventCountProducer = cms.EDProducer("EventCountProducer")
00024 
00025     # Full path
00026     #process.load('RecoTauTag.Configuration.RecoPFTauTag_cff')
00027     process.susyPatDefaultSequence = cms.Sequence( process.eventCountProducer
00028                                                    # * process.PFTau
00029                                                    # * process.Type1METSequence
00030                                                    * process.patPF2PATSequence
00031                                                    * process.patPF2PATSequencePF
00032                                                    )
00033 
00034     if mcInfo and extMatch:
00035         extensiveMatching(process)
00036         process.susyPatDefaultSequence.replace(process.patDefaultSequence, process.extensiveMatching+process.patDefaultSequence)
00037     
00038     if doValidation:
00039         loadSusyValidation(process)
00040         process.susyPatDefaultSequence.replace(process.patPF2PATSequencePF, process.patPF2PATSequencePF * process.ak5CaloJetsL2L3 * process.metJESCorAK5CaloJet  * process.RecoSusyValidation * process.PatSusyValidation*process.MEtoEDMConverter)
00041 
00042 def extensiveMatching(process):
00043     process.load("SimGeneral.TrackingAnalysis.trackingParticlesNoSimHits_cfi")    # On RECO
00044     process.load("SimMuon.MCTruth.MuonAssociatorByHits_cfi")  # On RECO
00045     process.mergedTruth = cms.EDProducer("GenPlusSimParticleProducer",
00046         src           = cms.InputTag("g4SimHits"), # use "famosSimHits" for FAMOS
00047         setStatus     = cms.int32(5),             # set status = 8 for GEANT GPs
00048         filter        = cms.vstring("pt > 0.0"),  # just for testing (optional)
00049         genParticles   = cms.InputTag("genParticles") # original genParticle list
00050     )
00051     process.load("MuonAnalysis.MuonAssociators.muonClassificationByHits_cfi")
00052 
00053     from MuonAnalysis.MuonAssociators.muonClassificationByHits_cfi import addUserData as addClassByHits
00054     addClassByHits(process.patMuons,labels=['classByHitsGlb'],extraInfo=True)
00055     addClassByHits(process.patMuonsPF,labels=['classByHitsGlb'],extraInfo=True)
00056     
00057     process.extensiveMatching = cms.Sequence(process.mergedTruth+process.muonClassificationByHits)
00058 
00059 def loadPAT(process,JetMETCorrections,extMatch):
00060     #-- Changes for electron and photon ID ----------------------------------------
00061     from PhysicsTools.PatAlgos.tools.pfTools import usePFIso
00062     usePFIso( process )
00063     process.patElectrons.isolationValues = cms.PSet(
00064         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral03PFIdPFIso"),
00065         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll03PFIdPFIso"),
00066         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU03PFIdPFIso"),
00067         pfPhotons = cms.InputTag("elPFIsoValueGamma03PFIdPFIso"),
00068         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged03PFIdPFIso")
00069         )
00070     process.patElectrons.isolationValuesNoPFId = cms.PSet(
00071         pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral03NoPFIdPFIso"),
00072         pfChargedAll = cms.InputTag("elPFIsoValueChargedAll03NoPFIdPFIso"),
00073         pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU03NoPFIdPFIso"),
00074         pfPhotons = cms.InputTag("elPFIsoValueGamma03NoPFIdPFIso"),
00075         pfChargedHadrons = cms.InputTag("elPFIsoValueCharged03NoPFIdPFIso")
00076         )
00077     process.patDefaultSequence.replace(process.patElectrons,process.eleIsoSequence+process.patElectrons)
00078     process.patDefaultSequence.replace(process.patMuons,process.muIsoSequence+process.patMuons)
00079     
00080     # Turn off photon-electron cleaning (i.e., flag only)
00081     process.cleanPatPhotons.checkOverlaps.electrons.requireNoOverlaps = False
00082 
00083     # Embed tracks, since we drop them
00084     process.patElectrons.embedTrack = True
00085     process.patMuons.embedTrack   = True
00086 
00087     #include tau decay mode in pat::Taus (elese it will just be uninitialized)
00088     #decay modes are dropped and have to be redone, this is a bit dangorous since the decay modes insered are *not* the ones used in RECO
00089     #process.patTaus.addDecayMode = True
00090     #process.makePatTaus.replace( process.patTaus, process.shrinkingConePFTauDecayModeProducer + process.patTaus )
00091 
00092     #Additional electron ids as defined for VBTF
00093     process.load("ElectroWeakAnalysis.WENu.simpleEleIdSequence_cff")
00094     process.patElectrons.electronIDSources = cms.PSet(
00095     eidTight = cms.InputTag("eidTight"),
00096     eidLoose = cms.InputTag("eidLoose"),
00097     eidRobustTight = cms.InputTag("eidRobustTight"),
00098     eidRobustHighEnergy = cms.InputTag("eidRobustHighEnergy"),
00099     eidRobustLoose = cms.InputTag("eidRobustLoose"),
00100     simpleEleId95relIso= cms.InputTag("simpleEleId95relIso"),
00101     simpleEleId90relIso= cms.InputTag("simpleEleId90relIso"),
00102     simpleEleId85relIso= cms.InputTag("simpleEleId85relIso"),
00103     simpleEleId80relIso= cms.InputTag("simpleEleId80relIso"),
00104     simpleEleId70relIso= cms.InputTag("simpleEleId70relIso"),
00105     simpleEleId60relIso= cms.InputTag("simpleEleId60relIso"),
00106     simpleEleId95cIso= cms.InputTag("simpleEleId95cIso"),
00107     simpleEleId90cIso= cms.InputTag("simpleEleId90cIso"),
00108     simpleEleId85cIso= cms.InputTag("simpleEleId85cIso"),
00109     simpleEleId80cIso= cms.InputTag("simpleEleId80cIso"),
00110     simpleEleId70cIso= cms.InputTag("simpleEleId70cIso"),
00111     simpleEleId60cIso= cms.InputTag("simpleEleId60cIso"))
00112     process.patDefaultSequence.replace(process.patElectrons,process.simpleEleIdSequence+process.patElectrons)
00113     
00114     #-- Tuning of Monte Carlo matching --------------------------------------------
00115     # Also match with leptons of opposite charge
00116     process.electronMatch.checkCharge = False
00117     process.electronMatch.maxDeltaR   = cms.double(0.2)
00118     process.electronMatch.maxDPtRel   = cms.double(999999.)
00119     process.muonMatch.checkCharge     = False
00120     process.muonMatch.maxDeltaR       = cms.double(0.2)
00121     process.muonMatch.maxDPtRel       = cms.double(999999.)
00122     #process.tauMatch.checkCharge      = False
00123     #process.tauMatch.maxDeltaR        = cms.double(0.3)
00124     process.patJetPartonMatch.maxDeltaR  = cms.double(0.25)
00125     process.patJetPartonMatch.maxDPtRel  = cms.double(999999.)
00126     process.patJetGenJetMatch.maxDeltaR  = cms.double(0.25)
00127     process.patJetGenJetMatch.maxDPtRel  = cms.double(999999.)
00128     if extMatch:
00129         process.electronMatch.mcStatus = cms.vint32(1,5)
00130         process.electronMatch.matched = "mergedTruth"
00131         process.muonMatch.mcStatus = cms.vint32(1,5)
00132         process.muonMatch.matched = "mergedTruth"
00133         process.patJetPartonMatch.matched = "mergedTruth"
00134         process.patJetPartons.src = "mergedTruth"
00135         process.photonMatch.matched = "mergedTruth"
00136         #process.tauGenJets.genParticles = "mergedTruth"
00137         #process.tauMatch.matched = "mergedTruth"
00138 
00139 
00140     #-- Taus ----------------------------------------------------------------------
00141     #some tau discriminators have been switched off during development. They can be switched on again...
00142     #setattr(process.patTaus.tauIDSources, "trackIsolation", cms.InputTag("shrinkingConePFTauDiscriminationByTrackIsolation"))
00143     #setattr(process.patTaus.tauIDSources, "ecalIsolation", cms.InputTag("shrinkingConePFTauDiscriminationByECALIsolation"))
00144     #setattr(process.patTaus.tauIDSources, "byIsolation", cms.InputTag("shrinkingConePFTauDiscriminationByIsolation"))
00145     #setattr(process.patTaus.tauIDSources, "leadingPionPtCut", cms.InputTag("shrinkingConePFTauDiscriminationByLeadingPionPtCut"))
00146     #setattr(process.patTaus.tauIDSources, "trackIsolationUsingLeadingPion", cms.InputTag("shrinkingConePFTauDiscriminationByTrackIsolationUsingLeadingPion"))
00147     #setattr(process.patTaus.tauIDSources, "ecalIsolationUsingLeadingPion", cms.InputTag("shrinkingConePFTauDiscriminationByECALIsolationUsingLeadingPion"))
00148     #setattr(process.patTaus.tauIDSources, "byIsolationUsingLeadingPion", cms.InputTag("shrinkingConePFTauDiscriminationByIsolationUsingLeadingPion"))
00149     #setattr(process.patTaus.tauIDSources, "byTaNC", cms.InputTag("shrinkingConePFTauDiscriminationByTaNC"))
00150     #setattr(process.patTaus.tauIDSources, "byTaNCfrOnePercent", cms.InputTag("shrinkingConePFTauDiscriminationByTaNCfrOnePercent"))
00151     #setattr(process.patTaus.tauIDSources, "byTaNCfrHalfPercent", cms.InputTag("shrinkingConePFTauDiscriminationByTaNCfrHalfPercent"))
00152     #setattr(process.patTaus.tauIDSources, "byTaNCfrQuarterPercent", cms.InputTag("shrinkingConePFTauDiscriminationByTaNCfrQuarterPercent"))
00153     #setattr(process.patTaus.tauIDSources, "byTaNCfrTenthPercent", cms.InputTag("shrinkingConePFTauDiscriminationByTaNCfrTenthPercent"))
00154 
00155 
00156     #-- Jet corrections -----------------------------------------------------------
00157     # L1 FastJet jet corrections
00158     # kt6PFJets for FastJet corrections are already run and placed before jetCorrection calculation
00159     # apply FastJet corrections only if demanded
00160     # TODO: Check if still necessary to switch here
00161     if ("L1FastJet" in JetMETCorrections):
00162         process.pfJets.doAreaFastjet = True
00163         process.pfJetsPF.doAreaFastjet = True
00164 
00165 def loadPF2PAT(process,mcInfo,JetMETCorrections,extMatch,doSusyTopProjection,doType1MetCorrection,doType0MetCorrection,postfix):
00166     #-- PAT standard config -------------------------------------------------------
00167     process.load("PhysicsTools.PatAlgos.patSequences_cff")
00168     #-- Jet corrections -----------------------------------------------------------
00169     process.patJetCorrFactors.levels = JetMETCorrections 
00170     #-- PF2PAT config -------------------------------------------------------------
00171     from PhysicsTools.PatAlgos.tools.pfTools import usePF2PAT
00172     usePF2PAT(process,runPF2PAT=True,
00173         jetAlgo             = 'AK5',
00174         runOnMC             = (mcInfo==1),
00175         postfix             = postfix,
00176         jetCorrections      = ('AK5PFchs', JetMETCorrections),
00177         typeIMetCorrections = doType1MetCorrection)
00178 
00179     if doType0MetCorrection:
00180         getattr(process,'patType1CorrectedPFMet'+postfix).srcType1Corrections = cms.VInputTag(
00181             cms.InputTag("patPFJetMETtype1p2Corr"+postfix,"type1"),
00182             cms.InputTag("patPFMETtype0Corr"+postfix)
00183         )
00184 
00185 
00186     #process.patJetsPF.embedGenJetMatch = False
00187     #process.patJetsPF.embedPFCandidates = False
00188     #drop tracks 
00189     process.patElectronsPF.embedTrack   = True
00190     process.patMuonsPF.embedTrack       = True
00191     process.electronMatchPF.maxDeltaR   = cms.double(0.2)
00192     process.electronMatchPF.maxDPtRel   = cms.double(999999.)
00193     process.electronMatchPF.checkCharge = False
00194     process.muonMatchPF.maxDeltaR       = cms.double(0.2)
00195     process.muonMatchPF.maxDPtRel       = cms.double(999999.)
00196     process.muonMatchPF.checkCharge     = False
00197     if extMatch:
00198         process.electronMatchPF.mcStatus        = cms.vint32(1,5)
00199         process.electronMatchPF.matched         = "mergedTruth"
00200         process.muonMatchPF.mcStatus            = cms.vint32(1,5)
00201         process.muonMatchPF.matched             = "mergedTruth"
00202         process.genParticlesForJets.src         = "mergedTruth"
00203         process.genParticlesForJetsNoMuNoNu.src = "mergedTruth"
00204         process.genParticlesForJetsNoNu.src     = "mergedTruth"
00205         process.patJetPartonMatchPF.matched     = "mergedTruth"
00206         process.patJetPartonsPF.src             = "mergedTruth"
00207         process.photonMatchPF.matched           = "mergedTruth"
00208         #process.tauGenJetsPF.genParticles = "mergedTruth"
00209         #process.tauMatchPF.matched = "mergedTruth"
00210         
00211     #Remove jet pt cut
00212     #process.pfJetsPF.ptMin = 0.
00213     #include tau decay mode in pat::Taus (elese it will just be uninitialized)
00214     #process.patTausPF.addDecayMode = True
00215     #process.patTausPF.decayModeSrc = "shrinkingConePFTauDecayModeProducerPF" 
00216 
00217     #Set isolation cone to 0.3 for PF leptons
00218     # TODO: fix this for electrons and muons
00219     #process.pfElectrons.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("elPFIsoValueCharged03PFId"))
00220     #process.pfElectrons.deltaBetaIsolationValueMap = cms.InputTag("elPFIsoValuePU03PFId")
00221     #process.pfElectrons.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("elPFIsoValueNeutral03PFId"), cms.InputTag("elPFIsoValueGamma03PFId"))
00222     #process.pfIsolatedElectrons.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("elPFIsoValueCharged03PFId"))
00223     #process.pfIsolatedElectrons.deltaBetaIsolationValueMap = cms.InputTag("elPFIsoValuePU03PFId")
00224     #process.pfIsolatedElectrons.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("elPFIsoValueNeutral03PFId"), cms.InputTag("elPFIsoValueGamma03PFId"))
00225     
00226     #process.pfElectronsPF.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("elPFIsoValueCharged03PFIdPF"))
00227     #process.pfElectronsPF.deltaBetaIsolationValueMap = cms.InputTag("elPFIsoValuePU03PFIdPF")
00228     #process.pfElectronsPF.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("elPFIsoValueNeutral03PFIdPF"), cms.InputTag("elPFIsoValueGamma03PFIdPF"))
00229     #process.pfIsolatedElectronsPF.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("elPFIsoValueCharged03PFIdPF"))
00230     #process.pfIsolatedElectronsPF.deltaBetaIsolationValueMap = cms.InputTag("elPFIsoValuePU03PFIdPF")
00231     #process.pfIsolatedElectronsPF.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("elPFIsoValueNeutral03PFIdPF"), cms.InputTag("elPFIsoValueGamma03PFIdPF"))
00232 
00233     #process.pfMuons.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("muPFIsoValueCharged03mu03"))
00234     #process.pfMuons.deltaBetaIsolationValueMap = cms.InputTag("muPFIsoValuePU03")
00235     #process.pfMuons.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("muPFIsoValueNeutral03"), cms.InputTag("muPFIsoValueGamma03"))
00236     #process.pfIsolatedMuons.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("muPFIsoValueCharged03mu03"))
00237     #process.pfIsolatedMuons.deltaBetaIsolationValueMap = cms.InputTag("muPFIsoValuePU03")
00238     #process.pfIsolatedMuons.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("muPFIsoValueNeutral03"), cms.InputTag("muPFIsoValueGamma03"))
00239 
00240     #process.pfMuonsPF.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("muPFIsoValueCharged03mu03PF"))
00241     #process.pfMuonsPF.deltaBetaIsolationValueMap = cms.InputTag("muPFIsoValuePU03PF")
00242     #process.pfMuonsPF.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("muPFIsoValueNeutral03PF"), cms.InputTag("muPFIsoValueGamma03PF"))
00243     #process.pfIsolatedMuonsPF.isolationValueMapsCharged = cms.VInputTag(cms.InputTag("muPFIsoValueCharged03mu03PF"))
00244     #process.pfIsolatedMuonsPF.deltaBetaIsolationValueMap = cms.InputTag("muPFIsoValuePU03PF")
00245     #process.pfIsolatedMuonsPF.isolationValueMapsNeutral = cms.VInputTag(cms.InputTag("muPFIsoValueNeutral03PF"), cms.InputTag("muPFIsoValueGamma03PF"))
00246 
00247     #-- Enable pileup sequence -------------------------------------------------------------
00248     #Vertices
00249     process.goodVertices = cms.EDFilter("VertexSelector",
00250         src = cms.InputTag("offlinePrimaryVertices"),
00251         cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
00252         filter = cms.bool(False),
00253     )
00254 
00255     process.pfPileUpPF.Vertices = "goodVertices"
00256     process.pfPileUpPF.Enable = True
00257 
00258     process.pfNoPileUpSequencePF.replace(process.pfPileUpPF,
00259                                          process.goodVertices + process.pfPileUpPF)
00260 
00261     if not doSusyTopProjection:
00262         return
00263     #-- Top projection selection -----------------------------------------------------------
00264     #Electrons
00265     #relax all selectors *before* pat-lepton creation
00266     process.pfElectronsFromVertexPF.dzCut = 9999.0
00267     process.pfElectronsFromVertexPF.d0Cut = 9999.0
00268     process.pfSelectedElectronsPF.cut = ""
00269     process.pfRelaxedElectronsPF = process.pfIsolatedElectronsPF.clone(isolationCut = 3.)
00270     process.pfIsolatedElectronsPF.isolationCut = 0.15
00271     
00272     process.pfElectronsFromGoodVertex = cms.EDFilter(
00273         "IPCutPFCandidateSelector",
00274         src = cms.InputTag("pfIsolatedElectronsPF"),  # PFCandidate source
00275         vertices = cms.InputTag("goodVertices"),  # vertices source
00276         d0Cut = cms.double(0.04),  # transverse IP
00277         dzCut = cms.double(1.),  # longitudinal IP
00278         d0SigCut = cms.double(99.),  # transverse IP significance
00279         dzSigCut = cms.double(99.),  # longitudinal IP significance
00280     )
00281    
00282     electronSelection =  "abs( eta ) < 2.5 & pt > 5"
00283     electronSelection += " & mva_e_pi > 0.4" # same as patElectron::mva()
00284     #electronSelection += " & (isEB & (sigmaIetaIeta < 0.024 & hadronicOverEm < 0.15) | isEE & (sigmaIetaIeta < 0.040 & hadronicOverEm < 0.10))" #caloIdVL
00285     #electronSelection += " & (isEB & (deltaPhiSuperClusterTrackAtVtx < 0.15 & deltaEtaSuperClusterTrackAtVtx < 0.01) | isEE & (deltaPhiSuperClusterTrackAtVtx < 0.10 & deltaEtaSuperClusterTrackAtVtx < 0.01))" #trkIdVL
00286     electronSelection += " & gsfTrackRef().isNonnull() & gsfTrackRef().trackerExpectedHitsInner().numberOfHits() <= 0"
00287     process.pfUnclusteredElectronsPF = cms.EDFilter( "GenericPFCandidateSelector",
00288         src = cms.InputTag("pfElectronsFromGoodVertex"), #pfSelectedElectronsPF
00289         cut = cms.string(electronSelection)
00290     )    
00291     process.pfElectronSequencePF.replace(process.pfIsolatedElectronsPF,
00292                                          process.pfIsolatedElectronsPF + 
00293                                          process.goodVertices * process.pfElectronsFromGoodVertex + 
00294                                          process.pfUnclusteredElectronsPF + process.pfRelaxedElectronsPF)
00295     process.patElectronsPF.pfElectronSource = "pfRelaxedElectronsPF"
00296     process.pfNoElectronPF.topCollection  = "pfUnclusteredElectronsPF"
00297     #Muons
00298     #relaxe built-in preselection
00299     process.pfMuonsFromVertexPF.dzCut = 9999.0
00300     process.pfMuonsFromVertexPF.d0Cut = 9999.0
00301     process.pfSelectedMuonsPF.cut = ""
00302     process.pfRelaxedMuonsPF = process.pfIsolatedMuonsPF.clone(isolationCut = 3)
00303     process.pfIsolatedMuonsPF.isolationCut = 0.15
00304     
00305     process.pfMuonsFromGoodVertex = cms.EDFilter(
00306         "IPCutPFCandidateSelector",
00307         src = cms.InputTag("pfIsolatedMuonsPF"),  # PFCandidate source
00308         vertices = cms.InputTag("goodVertices"),  # vertices source
00309         d0Cut = cms.double(0.02),  # transverse IP
00310         dzCut = cms.double(1.),  # longitudinal IP
00311         d0SigCut = cms.double(99.),  # transverse IP significance
00312         dzSigCut = cms.double(99.),  # longitudinal IP significance
00313     )
00314     muonSelection =  "abs( eta ) < 2.5 & pt > 5"
00315     #GlobalMuonPromptTight
00316     muonSelection += " & muonRef().isNonnull & muonRef().isGlobalMuon()"
00317     muonSelection += " & muonRef().isTrackerMuon() & muonRef().numberOfMatches > 1"
00318     muonSelection += " & muonRef().globalTrack().normalizedChi2() < 10"
00319     muonSelection += " & muonRef().Track().numberOfValidHits() > 10"
00320     muonSelection += " & muonRef().globalTrack().hitPattern().numberOfValidMuonHits() > 0"
00321     muonSelection += " & muonRef().innerTrack().hitPattern().numberOfValidPixelHits() > 0"
00322     process.pfUnclusteredMuonsPF = cms.EDFilter( "GenericPFCandidateSelector",
00323         src = cms.InputTag("pfMuonsFromGoodVertex"), #pfSelectedMuonsPF
00324         cut = cms.string(muonSelection)
00325     )    
00326     process.pfMuonSequencePF.replace(process.pfIsolatedMuonsPF,
00327                                      process.pfIsolatedMuonsPF + 
00328                                      process.goodVertices * process.pfMuonsFromGoodVertex +
00329                                      process.pfUnclusteredMuonsPF + process.pfRelaxedMuonsPF)
00330     process.patMuonsPF.pfMuonSource  = "pfRelaxedMuonsPF"
00331     process.pfNoMuonPF.topCollection = "pfUnclusteredMuonsPF"
00332     #Taus
00333     # TODO: Fix taus in 52X
00334     #process.pfTausPF.discriminators = cms.VPSet()
00335     #process.pfUnclusteredTausPF = process.pfTausPF.clone(
00336     #    cut = cms.string("pt < 0")
00337     #)
00338     #process.pfTauSequencePF.replace(process.pfTausPF, process.pfTausPF+ process.pfUnclusteredTausPF)
00339     #process.pfNoTauPF.topCollection = "pfUnclusteredTausPF"
00340     
00341 
00342 def loadPATTriggers(process,HLTMenu,theJetNames,electronMatches,muonMatches,tauMatches,jetMatches,photonMatches):
00343     #-- Trigger matching ----------------------------------------------------------
00344     def pfSwitchOnTriggerMatchEmbedding(process, matches, src, embedder, sequence='patDefaultSequencePF'):
00345         setattr(process,src.replace('PF','TriggerMatchPF'),getattr(process,embedder).clone(src=src, matches=matches))
00346         theSequence = getattr(process,sequence)
00347         theSequence += getattr(process,src.replace('PF','TriggerMatchPF'))
00348     from PhysicsTools.PatAlgos.tools.trigTools import switchOnTrigger, switchOnTriggerMatchEmbedding
00349     switchOnTrigger(process, triggerProducer='patTrigger', triggerEventProducer='patTriggerEvent', sequence='patDefaultSequence', hltProcess=HLTMenu)
00350     process.patTriggerPF = process.patTrigger.clone()
00351     process.patTriggerEventPF = process.patTriggerEvent.clone()
00352     process.patDefaultSequencePF += process.patTriggerPF 
00353     process.patDefaultSequencePF += process.patTriggerEventPF 
00354     switchOnTrigger(process, triggerProducer='patTriggerPF', triggerEventProducer='patTriggerEventPF', sequence='patDefaultSequencePF', hltProcess=HLTMenu)
00355     #Electrons
00356     from PhysicsTools.PatAlgos.triggerLayer1.triggerMatcher_cfi import cleanElectronTriggerMatchHLTEle20SWL1R
00357     process.patElectronMatch = cleanElectronTriggerMatchHLTEle20SWL1R.clone(matchedCuts = cms.string( electronMatches ))
00358     process.patElectronMatchPF = cleanElectronTriggerMatchHLTEle20SWL1R.clone(matchedCuts = cms.string( electronMatches ), src='selectedPatElectronsPF')
00359     process.patDefaultSequencePF += process.patElectronMatchPF
00360     switchOnTriggerMatchEmbedding( process, ['patElectronMatch'], hltProcess=HLTMenu)
00361     pfSwitchOnTriggerMatchEmbedding( process, ['patElectronMatchPF'], 'selectedPatElectronsPF', 'cleanPatElectronsTriggerMatch' )
00362     #Muons
00363     from PhysicsTools.PatAlgos.triggerLayer1.triggerMatcher_cfi import cleanMuonTriggerMatchHLTMu9
00364     process.patMuonMatch = cleanMuonTriggerMatchHLTMu9.clone(matchedCuts = cms.string( muonMatches ))
00365     process.patMuonMatchPF = cleanMuonTriggerMatchHLTMu9.clone(matchedCuts = cms.string( muonMatches ),src = 'selectedPatMuonsPF',matched='patTriggerPF')
00366     process.patDefaultSequencePF += process.patMuonMatchPF
00367     switchOnTriggerMatchEmbedding( process, ['patMuonMatch'], hltProcess=HLTMenu)
00368     pfSwitchOnTriggerMatchEmbedding( process, ['patMuonMatchPF'], 'selectedPatMuonsPF', 'cleanPatMuonsTriggerMatch' )
00369     #Photons
00370     from PhysicsTools.PatAlgos.triggerLayer1.triggerMatcher_cfi import cleanPhotonTriggerMatchHLTPhoton20CleanedL1R
00371     process.patPhotonMatch = cleanPhotonTriggerMatchHLTPhoton20CleanedL1R.clone(matchedCuts = cms.string( photonMatches ))
00372     switchOnTriggerMatchEmbedding( process, ['patPhotonMatch'], hltProcess=HLTMenu)
00373     #Jets
00374     from PhysicsTools.PatAlgos.triggerLayer1.triggerMatcher_cfi import cleanJetTriggerMatchHLTJet15U
00375     process.patJetMatchAK5Calo = cleanJetTriggerMatchHLTJet15U.clone(matchedCuts = cms.string( jetMatches ),src='cleanPatJetsAK5Calo')
00376     switchOnTriggerMatchEmbedding( process, ['patJetMatchAK5Calo'], hltProcess=HLTMenu)
00377     for jetType in theJetNames:
00378         setattr(process,'patJetMatch'+jetType,cleanJetTriggerMatchHLTJet15U.clone(matchedCuts = cms.string( jetMatches ),src = 'cleanPatJets'+jetType))
00379     process.patJetMatchPF = cleanJetTriggerMatchHLTJet15U.clone(src='selectedPatJetsPF', matchedCuts = cms.string( jetMatches ))
00380     process.patDefaultSequencePF += process.patJetMatchPF
00381     for jetType in theJetNames:
00382         switchOnTriggerMatchEmbedding( process, ['patJetMatch'+jetType], hltProcess=HLTMenu)
00383     pfSwitchOnTriggerMatchEmbedding( process, ['patJetMatchPF'], 'selectedPatJetsPF', 'cleanPatJetsAK5CaloTriggerMatch' )
00384     #Taus
00385     from PhysicsTools.PatAlgos.triggerLayer1.triggerMatcher_cfi import cleanTauTriggerMatchHLTDoubleLooseIsoTau15
00386     process.patTauMatch = cleanTauTriggerMatchHLTDoubleLooseIsoTau15.clone(matchedCuts = cms.string( tauMatches ))
00387     process.patTauMatchPF = cleanTauTriggerMatchHLTDoubleLooseIsoTau15.clone(src='selectedPatTausPF', matchedCuts = cms.string( tauMatches ))
00388     process.patDefaultSequencePF += process.patTauMatchPF
00389     switchOnTriggerMatchEmbedding( process, ['patTauMatch'], hltProcess=HLTMenu)
00390     pfSwitchOnTriggerMatchEmbedding( process, ['patTauMatchPF'], 'selectedPatTausPF', 'cleanPatTausTriggerMatch' )
00391 
00392 def loadType1METSequence(process):
00393     process.load("JetMETCorrections.Type1MET.pfMETCorrections_cff")
00394     ## Type 0?
00395     # process.pfType1CorrectedMet.srcCHSSums = cms.VInputTag(cms.InputTag("pfchsMETcorr","type0"))
00396     # process.pfType1CorrectedMet.applyType2Corrections = cms.bool(False)
00397     # process.pfType1CorrectedMet.type0Rsoft = cms.double(0.6)
00398     # process.pfType1CorrectedMet.applyType0Corrections = cms.bool(True)
00399     process.Type1METSequence = cms.Sequence(process.producePFMETCorrections)
00400 
00401 
00402 def addTypeIIMet(process) :
00403     # Add reco::MET with Type II correction 
00404     from PhysicsTools.PatAlgos.recoLayer0.jetMETCorrections_cff import metJESCorAK5CaloJet
00405     process.metJESCorAK5CaloJetTypeII = metJESCorAK5CaloJet.clone()
00406     process.metJESCorAK5CaloJetTypeII.useTypeII = True
00407     process.metJESCorAK5CaloJetTypeII.hasMuonsCorr = False
00408     # Add muon corrections for above II reco::MET
00409     process.metJESCorAK5CaloJetMuonsTypeII = process.metJESCorAK5CaloJetMuons.clone(
00410         uncorMETInputTag = cms.InputTag('metJESCorAK5CaloJetTypeII')
00411         )
00412     # Add to recoLayer0 sequence
00413     process.patMETCorrections.replace(
00414         process.metJESCorAK5CaloJet,
00415         (process.metJESCorAK5CaloJetTypeII*
00416          process.metJESCorAK5CaloJetMuonsTypeII)+
00417         process.metJESCorAK5CaloJet
00418         )
00419     # Add pat::MET with Type II correction
00420     process.patMETsAK5CaloTypeII = process.patMETs.clone(
00421         metSource = cms.InputTag("metJESCorAK5CaloJetMuonsTypeII")
00422         )
00423     # Add to producersLayer1 sequence
00424     process.patDefaultSequence.replace(
00425         process.patMETsAK5Calo,
00426         process.patMETsAK5Calo+
00427         process.patMETsAK5CaloTypeII
00428         )
00429 
00430 def addTagInfos(process,JetMETCorrections):
00431     from PhysicsTools.PatAlgos.tools.jetTools import switchJetCollection
00432     switchJetCollection( process,
00433                      jetCollection=cms.InputTag('ak5CaloJets'),
00434                      jetCorrLabel=('AK5Calo', JetMETCorrections))
00435 
00436 def addSUSYJetCollection(process,JetMETCorrections,jets = 'IC5Calo',mcVersion='',doJTA=True,doType1MET=True,doJetID=True,jetIdLabel=None):
00437     from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection
00438     algorithm = jets[0:3]
00439     type = jets[3:len(jets)]
00440     jetCorrLabel = (jets,cms.vstring(JetMETCorrections))
00441     if 'IC' in algorithm: collection = algorithm.replace('IC','iterativeCone')
00442     elif 'SC' in algorithm: collection = algorithm.replace('SC','sisCone')
00443     elif 'AK' in algorithm: collection = algorithm.replace('AK','ak')
00444     elif 'KT' in algorithm: collection = algorithm.replace('KT','kt')
00445     else: raise ValueError, "Unknown jet algorithm: %s" % (jets)
00446     jetIdLabel = algorithm.lower()
00447     if type == 'Calo':
00448         jetCollection = '%(collection)sCaloJets' % locals()
00449         if not 'AK7' in algorithm:
00450             doType1MET = True
00451     elif type == 'PF':
00452         jetCollection = '%(collection)sPFJets' % locals()
00453         doJetID = False
00454     elif type == 'JPT':
00455         if 'IC' in algorithm: collectionJPT = algorithm.replace('IC','Icone')
00456         elif 'SC' in algorithm: collectionJPT = algorithm.replace('SC','sisCone')
00457         elif 'AK' in algorithm: collectionJPT = algorithm.replace('AK','AntiKt')
00458         else: raise ValueError, "Unknown jet algorithm: %s" % (jets)
00459         jetCollection = 'JetPlusTrackZSPCorJet%(collectionJPT)s' % locals()
00460     elif type == 'Track':
00461         jetCollection = '%(collection)sTrackJets' % locals()
00462         jetCorrLabel = None
00463         doJetID = False
00464     else: raise ValueError, "Unknown jet type: %s" % (jets)
00465     
00466     addJetCollection(process, cms.InputTag(jetCollection),
00467                      algorithm, type,
00468                      doJTA            = doJTA,
00469                      doBTagging       = True,
00470                      jetCorrLabel     = jetCorrLabel,
00471                      doType1MET       = doType1MET,
00472                      doL1Cleaning     = True,
00473                      doL1Counters     = True,
00474                      doJetID          = doJetID,
00475                      jetIdLabel       = jetIdLabel,
00476                      genJetCollection = cms.InputTag('%(collection)sGenJets' % locals())
00477                      )
00478 
00479 def addJetMET(process,theJetNames,JetMETCorrections,mcVersion):
00480     #-- Extra Jet/MET collections -------------------------------------------------
00481     # Add a few jet collections...
00482     for jetName in theJetNames:
00483         addSUSYJetCollection(process,JetMETCorrections,jetName,mcVersion)
00484     
00485     #-- Tune contents of jet collections  -----------------------------------------
00486     theJetNames.append('')
00487     for jetName in theJetNames:
00488         module = getattr(process,'patJets'+jetName)
00489         module.addTagInfos = False    # Remove tag infos
00490         module.embedGenJetMatch = False # Only keep reference, since we anyway keep the genJet collections
00491         #module.embedCaloTowers = True # To drop calo towers
00492     theJetNames.pop()
00493     
00494     # Add tcMET
00495     from PhysicsTools.PatAlgos.tools.metTools import addTcMET #, addPfMET
00496     addTcMET(process,'TC')
00497     #addPfMET(process,'PF') #is in PF2PAT
00498 
00499     # Rename default jet collection for uniformity
00500     process.cleanPatJetsAK5Calo = process.cleanPatJets
00501     process.patMETsAK5Calo      = process.patMETs
00502     
00503     # TODO: fix type2 MET in 52X
00504     #addTypeIIMet(process)
00505 
00506     # Modify subsequent modules
00507     process.patHemispheres.patJets = process.cleanPatJetsAK5Calo.label()
00508     process.countPatJets.src       = process.cleanPatJetsAK5Calo.label()
00509     
00510     # Modify counters' input
00511     process.patCandidateSummary.candidates.remove(cms.InputTag('patMETs'))
00512     process.patCandidateSummary.candidates.append(cms.InputTag('patMETsAK5Calo'))
00513     process.patCandidateSummary.candidates.append(cms.InputTag('patMHTsAK5Calo'))
00514     process.cleanPatCandidateSummary.candidates.remove(cms.InputTag('cleanPatJets'))
00515     process.cleanPatCandidateSummary.candidates.append(cms.InputTag('cleanPatJetsAK5Calo'))
00516     # Add new jet collections to counters (MET done automatically)
00517     for jets in theJetNames: 
00518         process.patCandidateSummary.candidates.append(cms.InputTag('patJets'+jets))
00519         process.selectedPatCandidateSummary.candidates.append(cms.InputTag('selectedPatJets'+jets))
00520         process.cleanPatCandidateSummary.candidates.append(cms.InputTag('cleanPatJets'+jets))
00521     
00522 def removeMCDependence( process ):
00523     #-- Remove MC dependence ------------------------------------------------------
00524     from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
00525     removeMCMatching(process, ['All'])
00526 
00527 def loadSusyValidation(process):
00528     process.load("JetMETCorrections.Configuration.JetCorrectionProducers_cff")
00529     process.load("DQM.Physics.susyValidation_cfi")
00530     process.load("DQMServices.Components.MEtoEDMConverter_cfi")
00531     process.load("DQMServices.Core.DQM_cfg")
00532     process.load("DQMServices.Components.DQMEnvironment_cfi")
00533     process.DQMStore = cms.Service("DQMStore")
00534     process.DQMStore.collateHistograms = cms.untracked.bool(True)
00535     process.options = cms.untracked.PSet(
00536         fileMode = cms.untracked.string('NOMERGE')
00537     )
00538 
00539 def getSUSY_pattuple_outputCommands( process ):
00540     from PhysicsTools.PatAlgos.patEventContent_cff import patEventContent, patExtraAodEventContent, patTriggerEventContent, patTriggerStandAloneEventContent, patEventContentTriggerMatch
00541     keepList = []
00542     susyAddEventContent = [ # PAT Objects
00543     #'keep *_triggerMatched*_*_*',         
00544     # Keep PF2PAT output
00545     'keep *_selectedPatMuonsPF_*_*',         
00546     'keep *_selectedPatElectronsPF_*_*',         
00547     'keep *_selectedPatTausPF_*_*',         
00548     'keep *_selectedPatJetsPF_*_*',
00549     #L1 trigger info         
00550     'keep L1GlobalTriggerObjectMapRecord_*_*_*',
00551     'keep L1GlobalTriggerReadoutRecord_*_*_*',
00552     # Generator information
00553     'keep recoGenJets_*GenJets*_*_*',
00554     'keep recoGenMETs_*_*_*',
00555     #Number of processed events
00556     'keep edmMergeableCounter_eventCountProducer_*_*',
00557     'keep recoRecoChargedRefCandidates_trackRefsForJets_*_*',
00558     #'keep recoTrackJets_ak5TrackJets_*_*',
00559     'keep *_electronMergedSeeds_*_*',
00560     'keep *_Conversions_*_*',
00561     'keep recoPFCandidates_particleFlow_*_*',
00562     #'keep recoSuperClusters_corrected*_*_*',
00563     #'keep recoSuperClusters_pfElectronTranslator_*_*',
00564     #'keep *_gsfElectronCores_*_*',    #Keep electron core
00565     #'keep *_photonCore_*_*',        #Keep electron core
00566     'keep recoConversions_conversions_*_*',
00567     'keep recoTracks_*onversions_*_*',
00568     'keep HcalNoiseSummary_*_*_*', #Keep the one in RECO
00569     'keep *BeamHaloSummary_*_*_*',
00570     # Keep Gap Vertices for comparison
00571     'keep *_offlinePrimaryVerticesGap_*_*',
00572     'keep *_offlinePrimaryVerticesGapWithBS_*_*',
00573     #DQM
00574     'keep *_MEtoEDMConverter_*_PAT',
00575     'drop recoTracks_generalTracks*_*_*',
00576     'drop *_towerMaker_*_*',
00577     'keep *_pfType1CorrectedMet*_*_*',
00578     ]
00579     keepList.extend(patEventContent)
00580     keepList.extend(patExtraAodEventContent)
00581     keepList.extend(patTriggerEventContent)
00582     keepList.extend(patEventContentTriggerMatch)
00583     keepList.extend(susyAddEventContent)
00584     return keepList
00585