def getBaseConfig(globaltag, testfile="", maxevents=0, datatype='data'):
    """Testing config for skims with Kappa"""
    # Set the global tag and datatype for testing or by grid-control ---------
    data = (datatype == 'data')
    if data:
        testfile = 'file:///storage/a/berger/kappatest/input/data_AOD_2012A.root'
        if '@' in globaltag:
            globaltag = 'FT53_V21A_AN6'
        maxevents = maxevents or 1000
    else:
        testfile = 'file:///storage/a/berger/kappatest/input/mc11.root'
        if '@' in globaltag:
            globaltag = 'START53_V27'
        maxevents = maxevents or 1000
        datatype = 'mc'
    print "GT:", globaltag, "| TYPE:", datatype, "| maxevents:", maxevents, "| file:", testfile

    # Basic process setup -----------------------------------------------------
    process = cms.Process('kappaSkim')
    process.source = cms.Source('PoolSource',
        fileNames=cms.untracked.vstring(testfile))
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(maxevents))

    # Includes + Global Tag ---------------------------------------------------
    process.load('FWCore.MessageService.MessageLogger_cfi')
    process.load('Configuration.StandardSequences.Services_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.Geometry.GeometryIdeal_cff')
    process.load('Configuration.Geometry.GeometryPilot2_cff')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
    process.load('RecoMuon.DetLayers.muonDetLayerGeometry_cfi')
    process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.GlobalTag.globaltag = globaltag + '::All'

    # Reduce amount of messages -----------------------------------------------
    process.MessageLogger.default = cms.untracked.PSet(
        ERROR=cms.untracked.PSet(limit=cms.untracked.int32(5)))
    process.MessageLogger.cerr.FwkReport.reportEvery = 40

    # Produce PF muon isolation -----------------------------------------------
    from CommonTools.ParticleFlow.Isolation.tools_cfi import isoDepositReplace
    process.pfmuIsoDepositPFCandidates = isoDepositReplace('muons', 'particleFlow')
    process.pfMuonIso = cms.Path(process.pfmuIsoDepositPFCandidates)

    # Require two good muons --------------------------------------------------
    process.goodMuons = cms.EDFilter('CandViewSelector',
        src=cms.InputTag('muons'),
        cut=cms.string("pt > 12.0 & abs(eta) < 8.0 & isGlobalMuon()"),
    )
    process.twoGoodMuons = cms.EDFilter('CandViewCountFilter',
        src=cms.InputTag('goodMuons'),
        minNumber=cms.uint32(2),
    )

    # Configure tuple generation ----------------------------------------------
    process.load('Kappa.Producers.KTuple_cff')
    process.kappatuple = cms.EDAnalyzer('KTuple',
        process.kappaTupleDefaultsBlock,
        outputFile=cms.string("kappa_" + datatype + ".root"),
    )
    process.kappatuple.verbose = cms.int32(0)
    process.kappatuple.profile = cms.bool(True)
    process.kappatuple.active = cms.vstring(
        'LV', 'TrackSummary', 'VertexSummary', 'BeamSpot',
        'MET', 'BasicJets',
    )
    if data:
        process.kappatuple.active += ['DataInfo']
    else:
        process.kappatuple.active += ['GenInfo', 'GenParticles']

    # custom whitelist, otherwise the HLT trigger bits are not sufficient!
    process.kappatuple.Info.hltWhitelist = cms.vstring(
        "^HLT_(Double)?Mu([0-9]+)_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",  # matches HLT_Mu17_Mu8_v*
        "^HLT_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",                      # matches HLT_DoubleMu7_v*
    )

    process.pathKappa = cms.Path(
        process.goodMuons * process.twoGoodMuons * process.kappatuple
    )

    # Process schedule --------------------------------------------------------
    process.schedule = cms.Schedule(process.pfMuonIso, process.pathKappa)
    return process
Example #2
0
def addMuonPFIsolation(process, muonSrc, patMuons):
    sequence = cms.Sequence()

    process.load("CommonTools.ParticleFlow.pfNoPileUp_cff")
    process.load("CommonTools.ParticleFlow.ParticleSelectors.pfSortByType_cff")

    # No PFchs, this is just a pre-requisite for pfSortByType (and a
    # placeholder for chs for the future)
    process.pfPileUp.Enable = False
    sequence *= process.pfNoPileUpSequence

    # Do the sorting by particle types
    sequence *= process.pfSortByTypeSequence

    # Create the iso deposits
    process.muPFIsoDepositAll     = tools.isoDepositReplace(muonSrc, "pfNoPileUp")
    process.muPFIsoDepositCharged = tools.isoDepositReplace(muonSrc, "pfAllChargedHadrons")
    process.muPFIsoDepositNeutral = tools.isoDepositReplace(muonSrc, "pfAllNeutralHadrons")
    process.muPFIsoDepositGamma   = tools.isoDepositReplace(muonSrc, "pfAllPhotons")
    sequence *= (process.muPFIsoDepositAll *
                 process.muPFIsoDepositCharged *
                 process.muPFIsoDepositNeutral *
                 process.muPFIsoDepositGamma)

    # Create the valus calculators
    prototype = cms.EDProducer("CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("dummy"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring(""),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )

    for a in ["All", "Charged", "Neutral", "Gamma"]:
        m = prototype.clone()
        m.deposits[0].src = "muPFIsoDeposit"+a
        setattr(process, "muPFIsoValue"+a, m)
        sequence *= m

    # Set the thresholds 
    process.muPFIsoValueAll.deposits[0].vetos = ['ConeVeto(0.001)','Threshold(1.0)']
    process.muPFIsoValueCharged.deposits[0].vetos = ['ConeVeto(0.0001)','Threshold(1.0)']
    process.muPFIsoValueNeutral.deposits[0].vetos = ['ConeVeto(0.01)','Threshold(1.0)']
    process.muPFIsoValueGamma.deposits[0].vetos = ['ConeVeto(0.01)','Threshold(1.0)']

    patMuons.isoDeposits = cms.PSet(
        particle         = cms.InputTag("muPFIsoDepositAll"),
        pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged"),
        pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral"),
        pfPhotons        = cms.InputTag("muPFIsoDepositGamma")
    )

    patMuons.isolationValues = cms.PSet(
        particle         = cms.InputTag("muPFIsoValueAll"),
        pfChargedHadrons = cms.InputTag("muPFIsoValueCharged"),
        pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral"),
        pfPhotons        = cms.InputTag("muPFIsoValueGamma"),
    )

    return sequence
Example #3
0
def addMuonPFIsolation(process, muonSrc, patMuons):
    sequence = cms.Sequence()

    process.load("CommonTools.ParticleFlow.pfNoPileUp_cff")
    process.load("CommonTools.ParticleFlow.ParticleSelectors.pfSortByType_cff")

    # No PFchs, this is just a pre-requisite for pfSortByType (and a
    # placeholder for chs for the future)
    process.pfPileUp.Enable = False
    sequence *= process.pfNoPileUpSequence

    # Do the sorting by particle types
    sequence *= process.pfSortByTypeSequence

    # Create the iso deposits
    process.muPFIsoDepositAll = tools.isoDepositReplace(muonSrc, "pfNoPileUp")
    process.muPFIsoDepositCharged = tools.isoDepositReplace(
        muonSrc, "pfAllChargedHadrons")
    process.muPFIsoDepositNeutral = tools.isoDepositReplace(
        muonSrc, "pfAllNeutralHadrons")
    process.muPFIsoDepositGamma = tools.isoDepositReplace(
        muonSrc, "pfAllPhotons")
    sequence *= (process.muPFIsoDepositAll * process.muPFIsoDepositCharged *
                 process.muPFIsoDepositNeutral * process.muPFIsoDepositGamma)

    # Create the valus calculators
    prototype = cms.EDProducer("CandIsolatorFromDeposits",
                               deposits=cms.VPSet(
                                   cms.PSet(src=cms.InputTag("dummy"),
                                            deltaR=cms.double(0.4),
                                            weight=cms.string('1'),
                                            vetos=cms.vstring(""),
                                            skipDefaultVeto=cms.bool(True),
                                            mode=cms.string('sum'))))

    for a in ["All", "Charged", "Neutral", "Gamma"]:
        m = prototype.clone()
        m.deposits[0].src = "muPFIsoDeposit" + a
        setattr(process, "muPFIsoValue" + a, m)
        sequence *= m

    # Set the thresholds
    process.muPFIsoValueAll.deposits[0].vetos = [
        'ConeVeto(0.001)', 'Threshold(1.0)'
    ]
    process.muPFIsoValueCharged.deposits[0].vetos = [
        'ConeVeto(0.0001)', 'Threshold(1.0)'
    ]
    process.muPFIsoValueNeutral.deposits[0].vetos = [
        'ConeVeto(0.01)', 'Threshold(1.0)'
    ]
    process.muPFIsoValueGamma.deposits[0].vetos = [
        'ConeVeto(0.01)', 'Threshold(1.0)'
    ]

    patMuons.isoDeposits = cms.PSet(
        particle=cms.InputTag("muPFIsoDepositAll"),
        pfChargedHadrons=cms.InputTag("muPFIsoDepositCharged"),
        pfNeutralHadrons=cms.InputTag("muPFIsoDepositNeutral"),
        pfPhotons=cms.InputTag("muPFIsoDepositGamma"))

    patMuons.isolationValues = cms.PSet(
        particle=cms.InputTag("muPFIsoValueAll"),
        pfChargedHadrons=cms.InputTag("muPFIsoValueCharged"),
        pfNeutralHadrons=cms.InputTag("muPFIsoValueNeutral"),
        pfPhotons=cms.InputTag("muPFIsoValueGamma"),
    )

    return sequence
def getBaseConfig(globaltag, testfile="", maxevents=0, datatype='data'):
    """Default config for Z+jet skims with Kappa

       This is used in a cmssw config file via:
       import skim_base
       process = skim_base.getBaseConfig('START53_V12', "testfile.root")
    """
    # Set the globalt tag and datatype for testing or by grid-control ---------
    data = (datatype == 'data')
    if data:
        testfile = 'file:/storage/8/dhaitz/testfiles/data_AOD_2012A.root'
        testfile = 'file:/storage/8/dhaitz/temp-DoubleMu/0C79FC3F-4083-E211-9CC5-20CF3027A5E2.root'
        if '@' in globaltag: globaltag = 'FT53_V21A_AN6'
        maxevents = maxevents or 100
    else:
        testfile = 'file:/storage/8/dhaitz/testfiles/rundepMC.root'
        if '@' in globaltag: globaltag = 'START53_V19F'
        maxevents = maxevents or 100
        datatype = 'mc'
    print "GT:", globaltag, "| TYPE:", datatype, "| maxevents:", maxevents, "| file:", testfile

    # Basic process setup -----------------------------------------------------
    process = cms.Process('kappaSkim')
    process.source = cms.Source('PoolSource',
        fileNames = cms.untracked.vstring(testfile))
    process.maxEvents = cms.untracked.PSet(
        input = cms.untracked.int32(maxevents))

    # Includes + Global Tag ---------------------------------------------------
    process.load('FWCore.MessageService.MessageLogger_cfi')
    process.load('Configuration.StandardSequences.Services_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.Geometry.GeometryIdeal_cff')
    process.load('Configuration.Geometry.GeometryPilot2_cff')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
    process.load('RecoMuon.DetLayers.muonDetLayerGeometry_cfi')
    process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.GlobalTag.globaltag = globaltag + '::All'

    # Reduce amount of messages -----------------------------------------------
    process.MessageLogger.default = cms.untracked.PSet(
        ERROR = cms.untracked.PSet(limit = cms.untracked.int32(5)))
    process.MessageLogger.cerr.FwkReport.reportEvery = 40

    # Produce PF muon isolation -----------------------------------------------
    from CommonTools.ParticleFlow.Isolation.tools_cfi import isoDepositReplace
    process.pfmuIsoDepositPFCandidates = isoDepositReplace('muons', 'particleFlow')
    process.pfMuonIso = cms.Path(process.pfmuIsoDepositPFCandidates)

    # Electrons ---------------------------------------------------------------
    process.load("Kappa.Skimming.KElectrons_cff")
    process.electrons = cms.Path(
        process.makeKappaElectrons)

    # Create good primary vertices to be used for PF association --------------
    from PhysicsTools.SelectorUtils.pvSelector_cfi import pvSelector
    process.goodOfflinePrimaryVertices = cms.EDFilter("PrimaryVertexObjectFilter",
        filterParams = pvSelector.clone(minNdof = cms.double(4.0), maxZ = cms.double(24.0)),
        src=cms.InputTag('offlinePrimaryVertices')
    )
    process.ak5PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.kt6PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')


    # CHS Jets with the NoPU sequence -----------------------------------------
    process.load('CommonTools.ParticleFlow.PFBRECO_cff')
    process.pfPileUp.Vertices = cms.InputTag('goodOfflinePrimaryVertices')
    process.pfPileUp.checkClosestZVertex = cms.bool(False)
    process.pfCHS = cms.Path(process.goodOfflinePrimaryVertices * process.PFBRECO)
    process.ak5PFJetsCHS = process.ak5PFJets.clone(src = cms.InputTag('pfNoPileUp'))
    process.kt6PFJetsCHS = process.kt6PFJets.clone(src = cms.InputTag('pfNoPileUp'))

    # Gen Jets without neutrinos ----------------------------------------------
    if datatype == 'mc':
        process.load('RecoJets.JetProducers.ak5GenJets_cfi')
        process.NoNuGenJets = cms.Path(process.genParticlesForJetsNoNu *
            process.genParticlesForJets *
            process.ak5GenJetsNoNu * process.kt6GenJetsNoNu * process.kt6GenJets
        )

    # Path to Redo all Jets ---------------------------------------------------
    process.jetsRedo = cms.Path(
        process.ak5PFJets * process.kt6PFJets *
        process.ak5PFJetsCHS * process.kt6PFJetsCHS
    )

    # QG TAGGER ----------------------------------------------------------------
    process.load('QuarkGluonTagger.EightTeV.QGTagger_RecoJets_cff')
    process.QGTagger.srcJets = cms.InputTag("ak5PFJets")

    process.AK5PFJetsQGTagger = process.QGTagger
    process.AK5PFJetsCHSQGTagger = process.QGTagger.clone(
        srcJets = cms.InputTag("ak5PFJetsCHS"),
        useCHS = cms.untracked.bool(True))


    process.QGTagging = cms.Path(process.QuarkGluonTagger
        * process.AK5PFJetsQGTagger * process.AK5PFJetsCHSQGTagger
        )

    # B-Tagging ----------------------------------------------------------------
    # b-tagging general configuration
    process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
    process.load("RecoBTag.Configuration.RecoBTag_cff")

    ### AK5
    # create a ak5PF jets and tracks association
    process.ak5PFJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone()
    process.ak5PFJetTracksAssociatorAtVertex.jets = "ak5PFJets"
    process.ak5PFJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak5PFImpactParameterTagInfos = process.impactParameterTagInfos.clone()
    process.ak5PFImpactParameterTagInfos.jetTracks = "ak5PFJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak5PFSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone()
    process.ak5PFSecondaryVertexTagInfos.trackIPTagInfos = "ak5PFImpactParameterTagInfos"
    process.ak5PFSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone()
    process.ak5PFSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(cms.InputTag("ak5PFSecondaryVertexTagInfos"))
    process.ak5PFCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone()
    process.ak5PFCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFImpactParameterTagInfos"),
        cms.InputTag("ak5PFSecondaryVertexTagInfos"))
    process.ak5PFCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone()
    process.ak5PFCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFImpactParameterTagInfos"),
        cms.InputTag("ak5PFSecondaryVertexTagInfos"))

    # sequence for AK5 b-tagging
    process.ak5PFJetBtagging = cms.Sequence(process.ak5PFJetTracksAssociatorAtVertex
        * process.ak5PFImpactParameterTagInfos
        * process.ak5PFSecondaryVertexTagInfos
        * process.ak5PFSecondaryVertexTagInfos
        * (process.ak5PFSimpleSecondaryVertexBJetTags + process.ak5PFCombinedSecondaryVertexBJetTags + process.ak5PFCombinedSecondaryVertexMVABJetTags))


    ### AK5 CHS
    # create a ak5PFCHS jets and tracks association
    process.ak5PFCHSJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone()
    process.ak5PFCHSJetTracksAssociatorAtVertex.jets = "ak5PFJetsCHS"
    process.ak5PFCHSJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak5PFCHSImpactParameterTagInfos = process.impactParameterTagInfos.clone()
    process.ak5PFCHSImpactParameterTagInfos.jetTracks = "ak5PFCHSJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak5PFCHSSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone()
    process.ak5PFCHSSecondaryVertexTagInfos.trackIPTagInfos = "ak5PFCHSImpactParameterTagInfos"
    process.ak5PFCHSSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone()
    process.ak5PFCHSSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(cms.InputTag("ak5PFCHSSecondaryVertexTagInfos"))
    process.ak5PFCHSCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone()
    process.ak5PFCHSCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSImpactParameterTagInfos"),
        cms.InputTag("ak5PFCHSSecondaryVertexTagInfos"))
    process.ak5PFCHSCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone()
    process.ak5PFCHSCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSImpactParameterTagInfos"),
        cms.InputTag("ak5PFCHSSecondaryVertexTagInfos"))

    # sequence for AK5CHS b-tagging
    process.ak5PFCHSJetBtagging = cms.Sequence(process.ak5PFCHSJetTracksAssociatorAtVertex
        * process.ak5PFCHSImpactParameterTagInfos
        * process.ak5PFCHSSecondaryVertexTagInfos
        * process.ak5PFCHSSecondaryVertexTagInfos
        * (process.ak5PFCHSSimpleSecondaryVertexBJetTags + process.ak5PFCHSCombinedSecondaryVertexBJetTags + process.ak5PFCHSCombinedSecondaryVertexMVABJetTags))


    # Add the modules for all the jet collections to the path
    process.BTagging = cms.Path(
        process.ak5PFJetBtagging
        * process.ak5PFCHSJetBtagging
    )


    # PU jet ID ---------------------------------------------------------------
    process.load("RecoJets.JetProducers.PileupJetID_cfi")

    # AK5
    process.ak5PFPuJetId = process.pileupJetIdProducer.clone(
       jets = cms.InputTag("ak5PFJets"),
       applyJec = cms.bool(True),
       inputIsCorrected = cms.bool(False),
       residualsTxt     = cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    process.ak5PFPuJetMva = process.pileupJetIdProducer.clone(
       jets = cms.InputTag("ak5PFJets"),
       jetids = cms.InputTag("ak5PFPuJetId"),
       applyJec = cms.bool(True),
       inputIsCorrected = cms.bool(False),
       residualsTxt     = cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )
    # AK5 CHS
    process.ak5PFCHSPuJetId = process.pileupJetIdProducerChs.clone(
       jets = cms.InputTag("ak5PFJetsCHS"),
       applyJec = cms.bool(True),
       inputIsCorrected = cms.bool(False),
       residualsTxt     = cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    process.ak5PFCHSPuJetMva = process.pileupJetIdProducerChs.clone(
       jets = cms.InputTag("ak5PFJetsCHS"),
       jetids = cms.InputTag("ak5PFCHSPuJetId"),
       applyJec = cms.bool(True),
       inputIsCorrected = cms.bool(False),
       residualsTxt     = cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )


    process.PUJetID = cms.Path(process.ak5PFPuJetId * process.ak5PFPuJetMva
                        * process.ak5PFCHSPuJetId * process.ak5PFCHSPuJetMva
                        )

    # MET filters -------------------------------------------------------------
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    # Create good vertices for the trackingFailure MET filter
    process.goodVertices = cms.EDFilter("VertexSelector",
        filter = cms.bool(False),
        src = cms.InputTag("offlinePrimaryVertices"),
        cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.rho < 2"),
    )
    # The good primary vertex filter for other MET filters
    process.primaryVertexFilter = cms.EDFilter("VertexSelector",
        filter = cms.bool(True),
        src = cms.InputTag("offlinePrimaryVertices"),
        cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
    )
    process.noscraping = cms.EDFilter("FilterOutScraping",
        applyfilter = cms.untracked.bool(True),
        debugOn = cms.untracked.bool(False),
        numtrack = cms.untracked.uint32(10),
        thresh = cms.untracked.double(0.25)
    )
    process.load('CommonTools.RecoAlgos.HBHENoiseFilter_cfi')
    process.load('RecoMET.METAnalyzers.CSCHaloFilter_cfi')
    process.load('RecoMET.METFilters.hcalLaserEventFilter_cfi')
    process.hcalLaserEventFilter.vetoByRunEventNumber = cms.untracked.bool(False)
    process.hcalLaserEventFilter.vetoByHBHEOccupancy = cms.untracked.bool(True)
    process.load('RecoMET.METFilters.EcalDeadCellTriggerPrimitiveFilter_cfi')
    process.EcalDeadCellTriggerPrimitiveFilter.tpDigiCollection = cms.InputTag("ecalTPSkimNA")
    process.load('RecoMET.METFilters.EcalDeadCellBoundaryEnergyFilter_cfi')
    process.load('RecoMET.METFilters.eeBadScFilter_cfi')
    process.load('RecoMET.METFilters.eeNoiseFilter_cfi')
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    process.load('RecoMET.METFilters.trackingFailureFilter_cfi')
    process.load('RecoMET.METFilters.inconsistentMuonPFCandidateFilter_cfi')
    process.load('RecoMET.METFilters.greedyMuonPFCandidateFilter_cfi')

    process.hcalLaserEventFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellTriggerPrimitiveFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellBoundaryEnergyFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.eeBadScFilter.taggingMode = cms.bool(True)
    process.eeNoiseFilter.taggingMode = cms.bool(True)
    process.ecalLaserCorrFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.inconsistentMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.greedyMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.beamScrapingFilter = process.inconsistentMuonPFCandidateFilter.clone(
        ptMin = cms.double(5000.0)
    )
    process.hcalNoiseFilter = process.beamScrapingFilter.clone()
    process.beamHaloFilter = process.beamScrapingFilter.clone()
    process.filtersSeq = cms.Sequence(
        process.primaryVertexFilter *
        process.hcalLaserEventFilter +
        process.EcalDeadCellTriggerPrimitiveFilter +
        process.EcalDeadCellBoundaryEnergyFilter +
        process.eeBadScFilter +
        process.eeNoiseFilter +
        process.ecalLaserCorrFilter +
        process.goodVertices * process.trackingFailureFilter +
        process.inconsistentMuonPFCandidateFilter +
        process.greedyMuonPFCandidateFilter +
        process.noscraping * process.beamScrapingFilter +
        process.HBHENoiseFilter * process.hcalNoiseFilter +
        process.CSCTightHaloFilter * process.beamHaloFilter
    )
    process.metFilters = cms.Path(process.filtersSeq)

    # MET correction ----------------------------------------------------------
    process.load("JetMETCorrections.Type1MET.pfMETCorrections_cff")
    process.pfchsMETcorr.src = cms.InputTag('goodOfflinePrimaryVertices')
    # Type-0
    process.pfMETCHS = process.pfType1CorrectedMet.clone(
        applyType1Corrections = cms.bool(False),
        applyType0Corrections = cms.bool(True)
    )
    # MET Path
    process.metCorrections = cms.Path(
            process.producePFMETCorrections * process.pfMETCHS
    )

    # Require two good muons --------------------------------------------------
    process.goodMuons = cms.EDFilter('CandViewSelector',
        src = cms.InputTag('muons'),
        cut = cms.string("pt > 12.0 & abs(eta) < 8.0 & isGlobalMuon()"),
    )
    process.twoGoodMuons = cms.EDFilter('CandViewCountFilter',
        src = cms.InputTag('goodMuons'),
        minNumber = cms.uint32(2),
    )

    # Configure tuple generation ----------------------------------------------
    process.load('Kappa.Producers.KTuple_cff')
    process.kappatuple = cms.EDAnalyzer('KTuple',
        process.kappaTupleDefaultsBlock,
        outputFile = cms.string("skim.root"),
        PFTaggedJets = cms.PSet(
            process.kappaNoCut,
            process.kappaNoRegEx,
            taggers = cms.vstring(
                "QGlikelihood", "QGmlp",
                "CombinedSecondaryVertexBJetTags", "CombinedSecondaryVertexMVABJetTags",
			    "puJetIDFullLoose", "puJetIDFullMedium", "puJetIDFullTight",
			    "puJetIDCutbasedLoose", "puJetIDCutbasedMedium", "puJetIDCutbasedTight",
            ),
            AK5PFTaggedJets = cms.PSet(
                src = cms.InputTag("ak5PFJets"),
                QGtagger = cms.InputTag("AK5PFJetsQGTagger"),
                Btagger = cms.InputTag("ak5PF"),
                PUJetID = cms.InputTag("ak5PFPuJetMva"),
                PUJetID_full = cms.InputTag("full"),
            ),
            AK5PFTaggedJetsCHS = cms.PSet(
                src = cms.InputTag("ak5PFJetsCHS"),
                QGtagger = cms.InputTag("AK5PFJetsCHSQGTagger"),
                Btagger = cms.InputTag("ak5PFCHS"),
                PUJetID = cms.InputTag("ak5PFCHSPuJetMva"),
                PUJetID_full = cms.InputTag("full"),
            )
        ),
    )

    process.kappatuple.verbose = cms.int32(0)
    process.kappatuple.active = cms.vstring(
        'LV', 'Muons', 'Electrons', 'TrackSummary', 'VertexSummary', 'BeamSpot',
        'JetArea', 'PFMET',
        'FilterSummary',
        'PFTaggedJets',
    )
    if data:
        additional_actives = ['DataMetadata']
    else:
        additional_actives = ['GenMetadata', 'GenParticles']
    for active in additional_actives:
        process.kappatuple.active.append(active)

    process.kappatuple.LV.blacklist += cms.vstring("AK5TrackJets", ".*KT.*", ".*AK7.*")
    process.kappatuple.PFMET.blacklist = cms.vstring("pfType1.*CorrectedMet")

    process.pathKappa = cms.Path(
        process.goodMuons * process.twoGoodMuons * process.kappatuple
    )

    # Process schedule --------------------------------------------------------
    process.schedule = cms.Schedule(
        process.metFilters,
        process.pfCHS,
        process.jetsRedo,
        process.BTagging,
        process.QGTagging,
        process.PUJetID,
        process.pfMuonIso,
        process.electrons,
        process.metCorrections,
        process.pathKappa,
    )
    if not data:
        process.schedule.insert(0, process.NoNuGenJets)

    return process
Example #5
0
def addPFMuonIsolation(process, module, sequence, verbose=False):
#    if verbose:
#        print "[Info] Adding particle isolation to muon with postfix '"+postfix+"'"

    if not hasattr(process, "pfCandidateSelectionByType"):
        addSelectedPFlowParticle(process, sequence, verbose=verbose)

    process.muPFIsoDepositAll = isoDepositReplace('muons',"pfNoPileUp")
    process.muPFIsoDepositCharged = isoDepositReplace('muons',"pfAllChargedHadrons")
    process.muPFIsoDepositNeutral = isoDepositReplace('muons',"pfAllNeutralHadrons")
    process.muPFIsoDepositGamma = isoDepositReplace('muons',"pfAllPhotons")
    #For Delta beta methos create an additional one fot charged particles from PV
    process.muPFIsoDepositPU = isoDepositReplace('muons',"pileUpHadrons")

    prototype = cms.EDProducer("CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("dummy"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring(""),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )

    for a in ["All", "Charged", "Neutral", "Gamma", "PU"]:
        m = prototype.clone()
        m.deposits[0].src = "muPFIsoDeposit"+a
        setattr(process, "muPFIsoValue"+a, m)
    process.muPFIsoValueAll.deposits[0].vetos = ['0.001','Threshold(0.5)']
    process.muPFIsoValueCharged.deposits[0].vetos = ['0.0001','Threshold(0.0)']
    process.muPFIsoValueNeutral.deposits[0].vetos = ['0.01','Threshold(0.5)']
    process.muPFIsoValueGamma.deposits[0].vetos = ['0.01','Threshold(0.5)']
    #For delta beta add one that has the same threshold as the neutral ones above
    process.muPFIsoValuePU.deposits[0].vetos = ['0.0001','Threshold(0.5)']
    
    process.patMuonIsolationSequence = cms.Sequence(
        process.muPFIsoDepositAll *
        process.muPFIsoDepositCharged *
        process.muPFIsoDepositNeutral *
        process.muPFIsoDepositGamma *
        process.muPFIsoDepositPU *
        process.muPFIsoValueAll *
        process.muPFIsoValueCharged *
        process.muPFIsoValueNeutral *
        process.muPFIsoValueGamma *
        process.muPFIsoValuePU
    )
    
    module.isoDeposits = cms.PSet(
        particle         = cms.InputTag("muPFIsoDepositAll"),
        pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged"),
        pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral"),
        pfPhotons        = cms.InputTag("muPFIsoDepositGamma")
    )

    #as you can see the PU deposit will be accessed by muon.userIso(0)
    module.isolationValues = cms.PSet(
        particle         = cms.InputTag("muPFIsoValueAll"),
        pfChargedHadrons = cms.InputTag("muPFIsoValueCharged"),
        pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral"),
        pfPhotons        = cms.InputTag("muPFIsoValueGamma"),
        user = cms.VInputTag(
            cms.InputTag("muPFIsoValuePU")
        )
    )

    process.patDefaultSequence.replace(module,
                                       process.patMuonIsolationSequence+module)
Example #6
0
def getBaseConfig(globaltag, testfile="", maxevents=0, datatype='data'):
    """Testing config for skims with Kappa"""
    # Set the global tag and datatype for testing or by grid-control ---------
    data = (datatype == 'data')
    testPaths = [
        '/home/short', '/storage/b/fs6-mirror/fcolombo/kappatest/input',
        '/nfs/dust/cms/user/fcolombo/kappatest/input',
        '/nfs/dust/cms/user/glusheno/kappatest/input'
    ]
    testPath = [p for p in testPaths if os.path.exists(p)][0]

    if data:
        testfile = "file:%s/" % testPath + (
            testPath == '/home/short') * "short_" + 'data_AOD_2012A.root'
        if '@' in globaltag:
            globaltag = 'FT53_V21A_AN6'
        maxevents = maxevents or (50 + (not testPath == '/home/short') * 950)
    else:
        testfile = "file:%s/" % testPath + (
            testPath == '/home/short') * "short_" + 'mc11.root'
        if '@' in globaltag:
            globaltag = 'START53_V27'
        maxevents = maxevents or (50 + (not testPath == '/home/short') * 950)
        datatype = 'mc'
    print "GT:", globaltag, "| TYPE:", datatype, "| maxevents:", maxevents, "| file:", testfile

    # Basic process setup -----------------------------------------------------
    process = cms.Process('kappaSkim')
    process.source = cms.Source('PoolSource',
                                fileNames=cms.untracked.vstring(testfile))
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(maxevents))

    # Includes + Global Tag ---------------------------------------------------
    process.load('FWCore.MessageService.MessageLogger_cfi')
    process.load('Configuration.StandardSequences.Services_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.Geometry.GeometryIdeal_cff')
    process.load('Configuration.Geometry.GeometryPilot2_cff')
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi'
    )
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi'
    )
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi'
    )
    process.load('RecoMuon.DetLayers.muonDetLayerGeometry_cfi')
    process.load(
        'Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.GlobalTag.globaltag = globaltag + '::All'

    # Reduce amount of messages -----------------------------------------------
    process.MessageLogger.default = cms.untracked.PSet(
        ERROR=cms.untracked.PSet(limit=cms.untracked.int32(5)))
    process.MessageLogger.cerr.FwkReport.reportEvery = 40

    # Produce PF muon isolation -----------------------------------------------
    from CommonTools.ParticleFlow.Isolation.tools_cfi import isoDepositReplace
    process.pfmuIsoDepositPFCandidates = isoDepositReplace(
        'muons', 'particleFlow')
    process.pfMuonIso = cms.Path(process.pfmuIsoDepositPFCandidates)

    # Require two good muons --------------------------------------------------
    process.goodMuons = cms.EDFilter(
        'CandViewSelector',
        src=cms.InputTag('muons'),
        cut=cms.string("pt > 12.0 & abs(eta) < 8.0 & isGlobalMuon()"),
    )
    process.twoGoodMuons = cms.EDFilter(
        'CandViewCountFilter',
        src=cms.InputTag('goodMuons'),
        minNumber=cms.uint32(2),
    )

    # Configure tuple generation ----------------------------------------------
    process.load('Kappa.Producers.KTuple_cff')
    process.kappatuple = cms.EDAnalyzer(
        'KTuple',
        process.kappaTupleDefaultsBlock,
        outputFile=cms.string("kappa_" + datatype + ".root"),
    )
    process.kappatuple.verbose = cms.int32(0)
    process.kappatuple.profile = cms.bool(True)
    process.kappatuple.active = cms.vstring(
        'LV',
        'TrackSummary',
        'VertexSummary',
        'BeamSpot',
        'MET',
        'BasicJets',
    )
    if data:
        process.kappatuple.active += ['DataInfo']
    else:
        process.kappatuple.active += ['GenInfo', 'GenParticles']

    # custom whitelist, otherwise the HLT trigger bits are not sufficient!
    process.kappatuple.Info.hltWhitelist = cms.vstring(
        "^HLT_(Double)?Mu([0-9]+)_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",  # matches HLT_Mu17_Mu8_v*
        "^HLT_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",  # matches HLT_DoubleMu7_v*
    )

    process.pathKappa = cms.Path(process.goodMuons * process.twoGoodMuons *
                                 process.kappatuple)

    # Process schedule --------------------------------------------------------
    process.schedule = cms.Schedule(process.pfMuonIso, process.pathKappa)
    return process
def load_muonPFiso_sequence(proc, seq_name, algo, coneR, src, src_charged_hadron='', src_neutral_hadron='', src_photon='', src_charged_pileup='', 
                            veto_charged_hadron='Threshold(0.0)', veto_neutral_hadron='Threshold(0.5)', veto_photon='Threshold(0.5)', veto_charged_pileup='Threshold(0.5)' ):

    doCH, doNH, doPh, doPU = False, False, False, False
    if src_charged_hadron != '': doCH = True
    if src_neutral_hadron != '': doNH = True
    if src_photon         != '': doPh = True
    if src_charged_pileup != '': doPU = True

    iso_seq = cms.Sequence()

    if doCH:
        setattr(proc, 'muPFIsoDepositCH'+algo, isoDepositReplace(src, src_charged_hadron))
        iso_seq += getattr(proc, 'muPFIsoDepositCH'+algo)

    if doNH:
        setattr(proc, 'muPFIsoDepositNH'+algo, isoDepositReplace(src, src_neutral_hadron))
        iso_seq += getattr(proc, 'muPFIsoDepositNH'+algo)

    if doPh:
        setattr(proc, 'muPFIsoDepositPh'+algo, isoDepositReplace(src, src_photon))
        iso_seq += getattr(proc, 'muPFIsoDepositPh'+algo)

    if doPU:
        setattr(proc, 'muPFIsoDepositPU'+algo, isoDepositReplace(src, src_charged_pileup))
        iso_seq += getattr(proc, 'muPFIsoDepositPU'+algo)

    iso_vals_seq = cms.Sequence()

    if doCH:
        setattr(proc, 'muPFIsoValueCH'+algo,
          cms.EDProducer('CandIsolatorFromDeposits',
            deposits = cms.VPSet(
              cms.PSet(
                src = cms.InputTag('muPFIsoDepositCH'+algo),
                deltaR = cms.double(coneR),
                weight = cms.string('1'),
                vetos = cms.vstring('0.0001',veto_charged_hadron),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
              )
            )
          )
        )
        iso_vals_seq += getattr(proc, 'muPFIsoValueCH'+algo)

    if doNH:
        setattr(proc, 'muPFIsoValueNH'+algo,
          cms.EDProducer('CandIsolatorFromDeposits',
            deposits = cms.VPSet(
              cms.PSet(
                src = cms.InputTag('muPFIsoDepositNH'+algo),
                deltaR = cms.double(coneR),
                weight = cms.string('1'),
                vetos = cms.vstring('0.01', veto_neutral_hadron ),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
              )
            )
          )
        )
        iso_vals_seq += getattr(proc, 'muPFIsoValueNH'+algo)

    if doPh:
        setattr(proc, 'muPFIsoValuePh'+algo,
          cms.EDProducer('CandIsolatorFromDeposits',
            deposits = cms.VPSet(
              cms.PSet(
                src = cms.InputTag('muPFIsoDepositPh'+algo),
                deltaR = cms.double(coneR),
                weight = cms.string('1'),
                vetos = cms.vstring('0.01', veto_photon),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
              )
            )
          )
        )
        iso_vals_seq += getattr(proc, 'muPFIsoValuePh'+algo)

    if doPU:
        setattr(proc, 'muPFIsoValuePU'+algo,
          cms.EDProducer('CandIsolatorFromDeposits',
            deposits = cms.VPSet(
              cms.PSet(
                src = cms.InputTag('muPFIsoDepositPU'+algo),
                deltaR = cms.double(coneR),
                weight = cms.string('1'),
                vetos = cms.vstring('0.01', veto_charged_pileup ),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
              )
            )
          )
        )
        iso_vals_seq += getattr(proc, 'muPFIsoValuePU'+algo)

    iso_seq *= iso_vals_seq

    setattr(proc, seq_name, iso_seq)
Example #8
0
def addPFMuonIsolationOld(process,module,postfix="",verbose=False):
    if verbose:
        print "[Info] Adding particle isolation to muon with postfix '"+postfix+"'"

    if not hasattr(process, "pfCandidateSelectionByType"):
        addSelectedPFlowParticle(process,verbose=verbose)
        
    #setup correct src of isolated object
    setattr(process,"isoDepMuonWithCharged"+postfix,
            isoDepositReplace(module.muonSource,
                              'pfAllChargedHadrons'))
    setattr(process,"isoDepMuonWithNeutral"+postfix,
            isoDepositReplace(module.muonSource,
                              'pfAllNeutralHadrons'))
    setattr(process,"isoDepMuonWithPhotons"+postfix,
            isoDepositReplace(module.muonSource,
                              'pfAllPhotons'))


    #compute isolation values form deposits
    process.load("PhysicsTools.PFCandProducer.Isolation.pfMuonIsolationFromDeposits_cff")
    if postfix!="":
        setattr(process,"isoValMuonWithCharged"+postfix,
                process.isoValMuonWithCharged.clone())
        getattr(process,"isoValMuonWithCharged"+postfix).deposits.src="isoDepMuonWithCharged"+postfix
        setattr(process,"isoValMuonWithNeutral"+postfix,
                process.isoValMuonWithNeutral.clone())
        getattr(process,"isoValMuonWithNeutral"+postfix).deposits.src="isoDepMuonWithNeutral"+postfix
        setattr(process,"isoValMuonWithPhotons"+postfix,
                process.isoValMuonWithPhotons.clone())
        getattr(process,"isoValMuonWithPhotons"+postfix).deposits.src="isoDepMuonWithPhotons"+postfix

    # Count and max pts
    for name in ["Charged", "Neutral", "Photons"]:
        prototype = getattr(process, "isoValMuonWith"+name+postfix)

        m = prototype.clone()
        m.deposits[0].mode = "count"
        setattr(process, "isoValCountMuonWith"+name+postfix, m)

        m = prototype.clone()
        m.deposits[0].mode = "max"
        m.deposits[0].vetos = []
        setattr(process, "isoValMaxMuonWith"+name+postfix, m)

    # Use the 0.5 min value for pt with charged cands in order to be similar with HpsTight
    for name in ["isoValCountMuonWithCharged", "isoValMaxMuonWithCharged"]:
        m = getattr(process, name+postfix).clone()
        m.deposits[0].vetos = ["Threshold(0.5)"]
        setattr(process, name+"Tight"+postfix, m)
    

    setattr(process,"patMuonIsolationFromDepositsSequence"+postfix,
            cms.Sequence(getattr(process,"isoValMuonWithCharged"+postfix) +
                         getattr(process,"isoValMuonWithNeutral"+postfix) +
                         getattr(process,"isoValMuonWithPhotons"+postfix) +
                         getattr(process,"isoValCountMuonWithCharged"+postfix) +
                         getattr(process,"isoValCountMuonWithNeutral"+postfix) +
                         getattr(process,"isoValCountMuonWithPhotons"+postfix) +                         
                         getattr(process,"isoValMaxMuonWithCharged"+postfix) +
                         getattr(process,"isoValMaxMuonWithNeutral"+postfix) +
                         getattr(process,"isoValMaxMuonWithPhotons"+postfix) +                  
                         getattr(process,"isoValCountMuonWithChargedTight"+postfix) +
                         getattr(process,"isoValMaxMuonWithChargedTight"+postfix) 
            )
    )

    setattr(process,"patMuonIsoDepositsSequence"+postfix,
            cms.Sequence(getattr(process,"isoDepMuonWithCharged"+postfix) +
                         getattr(process,"isoDepMuonWithNeutral"+postfix) +
                         getattr(process,"isoDepMuonWithPhotons"+postfix)
            )
    )
    setattr(process,"patMuonIsolationSequence"+postfix,
            cms.Sequence(getattr(process,"patMuonIsoDepositsSequence"+postfix) +
                         getattr(process,"patMuonIsolationFromDepositsSequence"+postfix)
            )
    )

    # The possible values for the keys are predefined...
    module.isoDeposits = cms.PSet(
        pfChargedHadrons = cms.InputTag("isoDepMuonWithCharged"+postfix),
        pfNeutralHadrons = cms.InputTag("isoDepMuonWithNeutral"+postfix),
        pfPhotons = cms.InputTag("isoDepMuonWithPhotons"+postfix)
    )
    module.isolationValues = cms.PSet(
        pfChargedHadrons = cms.InputTag("isoValMuonWithCharged"+postfix),
        pfNeutralHadrons = cms.InputTag("isoValMuonWithNeutral"+postfix),
        pfPhotons = cms.InputTag("isoValMuonWithPhotons"+postfix),
        # Only 5 slots available *sigh*
        user = cms.VInputTag(
                cms.InputTag("isoValCountMuonWithChargedTight"+postfix),
                cms.InputTag("isoValMaxMuonWithChargedTight"+postfix),
                cms.InputTag("isoValMaxMuonWithNeutral"+postfix),
                cms.InputTag("isoValCountMuonWithPhotons"+postfix),
                cms.InputTag("isoValMaxMuonWithPhotons"+postfix),
        )
#        pfChargedHadronsCount = cms.InputTag("isoValCountMuonWithCharged"+postfix),
#        pfNeutralHadronsCount = cms.InputTag("isoValCountMuonWithNeutral"+postfix),
#        pfPhotonsCount = cms.InputTag("isoValCountMuonWithPhotons"+postfix),
#        pfChargedHadronsMax = cms.InputTag("isoValMaxMuonWithCharged"+postfix),
#        pfNeutralHadronsMax = cms.InputTag("isoValMaxMuonWithNeutral"+postfix),
#        pfPhotonsMax = cms.InputTag("isoValMaxMuonWithPhotons"+postfix),
#        pfChargedHadronsTightCount = cms.InputTag("isoValCountMuonWithChargedTight"+postfix),
#        pfChargedHadronsTightMax = cms.InputTag("isoValMaxMuonWithChargedTight"+postfix),
    )

    process.patDefaultSequence.replace(module,
                                       getattr(process,"patMuonIsolationSequence"+postfix)+
                                       module
                                       )
Example #9
0
def load_muonPFiso_sequence(proc,
                            seq_name,
                            algo,
                            coneR,
                            src,
                            src_charged_hadron='',
                            src_neutral_hadron='',
                            src_photon='',
                            src_charged_pileup='',
                            veto_charged_hadron='Threshold(0.0)',
                            veto_neutral_hadron='Threshold(0.5)',
                            veto_photon='Threshold(0.5)',
                            veto_charged_pileup='Threshold(0.5)'):

    doCH, doNH, doPh, doPU = False, False, False, False
    if src_charged_hadron != '': doCH = True
    if src_neutral_hadron != '': doNH = True
    if src_photon != '': doPh = True
    if src_charged_pileup != '': doPU = True

    iso_seq = cms.Sequence()

    if doCH:
        setattr(proc, 'muPFIsoDepositCH' + algo,
                isoDepositReplace(src, src_charged_hadron))
        iso_seq += getattr(proc, 'muPFIsoDepositCH' + algo)

    if doNH:
        setattr(proc, 'muPFIsoDepositNH' + algo,
                isoDepositReplace(src, src_neutral_hadron))
        iso_seq += getattr(proc, 'muPFIsoDepositNH' + algo)

    if doPh:
        setattr(proc, 'muPFIsoDepositPh' + algo,
                isoDepositReplace(src, src_photon))
        iso_seq += getattr(proc, 'muPFIsoDepositPh' + algo)

    if doPU:
        setattr(proc, 'muPFIsoDepositPU' + algo,
                isoDepositReplace(src, src_charged_pileup))
        iso_seq += getattr(proc, 'muPFIsoDepositPU' + algo)

    iso_vals_seq = cms.Sequence()

    if doCH:
        setattr(
            proc, 'muPFIsoValueCH' + algo,
            cms.EDProducer(
                'CandIsolatorFromDeposits',
                deposits=cms.VPSet(
                    cms.PSet(src=cms.InputTag('muPFIsoDepositCH' + algo),
                             deltaR=cms.double(coneR),
                             weight=cms.string('1'),
                             vetos=cms.vstring('0.0001', veto_charged_hadron),
                             skipDefaultVeto=cms.bool(True),
                             mode=cms.string('sum')))))
        iso_vals_seq += getattr(proc, 'muPFIsoValueCH' + algo)

    if doNH:
        setattr(
            proc, 'muPFIsoValueNH' + algo,
            cms.EDProducer(
                'CandIsolatorFromDeposits',
                deposits=cms.VPSet(
                    cms.PSet(src=cms.InputTag('muPFIsoDepositNH' + algo),
                             deltaR=cms.double(coneR),
                             weight=cms.string('1'),
                             vetos=cms.vstring('0.01', veto_neutral_hadron),
                             skipDefaultVeto=cms.bool(True),
                             mode=cms.string('sum')))))
        iso_vals_seq += getattr(proc, 'muPFIsoValueNH' + algo)

    if doPh:
        setattr(
            proc, 'muPFIsoValuePh' + algo,
            cms.EDProducer('CandIsolatorFromDeposits',
                           deposits=cms.VPSet(
                               cms.PSet(src=cms.InputTag('muPFIsoDepositPh' +
                                                         algo),
                                        deltaR=cms.double(coneR),
                                        weight=cms.string('1'),
                                        vetos=cms.vstring('0.01', veto_photon),
                                        skipDefaultVeto=cms.bool(True),
                                        mode=cms.string('sum')))))
        iso_vals_seq += getattr(proc, 'muPFIsoValuePh' + algo)

    if doPU:
        setattr(
            proc, 'muPFIsoValuePU' + algo,
            cms.EDProducer(
                'CandIsolatorFromDeposits',
                deposits=cms.VPSet(
                    cms.PSet(src=cms.InputTag('muPFIsoDepositPU' + algo),
                             deltaR=cms.double(coneR),
                             weight=cms.string('1'),
                             vetos=cms.vstring('0.01', veto_charged_pileup),
                             skipDefaultVeto=cms.bool(True),
                             mode=cms.string('sum')))))
        iso_vals_seq += getattr(proc, 'muPFIsoValuePU' + algo)

    iso_seq *= iso_vals_seq

    setattr(proc, seq_name, iso_seq)
def getBaseConfig(globaltag, testfile="", maxevents=0, datatype='data'):
    """Default config for Z+jet skims with Kappa

       This is used in a cmssw config file via:
       import skim_base
       process = skim_base.getBaseConfig('START53_V12', "testfile.root")
    """
    # Set the globalt tag and datatype for testing or by grid-control ---------
    data = (datatype == 'data')
    if data:
        testfile = 'file:/storage/8/dhaitz/testfiles/data_AOD_2012A.root'
        if '@' in globaltag: globaltag = 'FT53_V21A_AN6'
        maxevents = maxevents or 100
    else:
        testfile = 'file:/storage/8/dhaitz/testfiles/rundepMC.root'
        if '@' in globaltag: globaltag = 'START53_V19F'
        maxevents = maxevents or 100
        datatype = 'mc'
    print "GT:", globaltag, "| TYPE:", datatype, "| maxevents:", maxevents, "| file:", testfile

    # Basic process setup -----------------------------------------------------
    process = cms.Process('kappaSkim')
    process.source = cms.Source('PoolSource',
                                fileNames=cms.untracked.vstring(testfile))
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(maxevents))

    # Includes + Global Tag ---------------------------------------------------
    process.load('FWCore.MessageService.MessageLogger_cfi')
    process.load('Configuration.StandardSequences.Services_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.Geometry.GeometryIdeal_cff')
    process.load('Configuration.Geometry.GeometryPilot2_cff')
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi'
    )
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi'
    )
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi'
    )
    process.load('RecoMuon.DetLayers.muonDetLayerGeometry_cfi')
    process.load(
        'Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.GlobalTag.globaltag = globaltag + '::All'

    # Reduce amount of messages -----------------------------------------------
    process.MessageLogger.default = cms.untracked.PSet(
        ERROR=cms.untracked.PSet(limit=cms.untracked.int32(5)))
    process.MessageLogger.cerr.FwkReport.reportEvery = 40

    # Produce PF muon isolation -----------------------------------------------
    from CommonTools.ParticleFlow.Isolation.tools_cfi import isoDepositReplace
    process.pfmuIsoDepositPFCandidates = isoDepositReplace(
        'muons', 'particleFlow')
    process.pfMuonIso = cms.Path(process.pfmuIsoDepositPFCandidates)

    # Create good primary vertices to be used for PF association --------------
    from PhysicsTools.SelectorUtils.pvSelector_cfi import pvSelector
    process.goodOfflinePrimaryVertices = cms.EDFilter(
        "PrimaryVertexObjectFilter",
        filterParams=pvSelector.clone(minNdof=cms.double(4.0),
                                      maxZ=cms.double(24.0)),
        src=cms.InputTag('offlinePrimaryVertices'))
    process.ak5PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.ak7PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.kt4PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.kt6PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')

    # CHS Jets with the NoPU sequence -----------------------------------------
    process.load('CommonTools.ParticleFlow.PFBRECO_cff')
    process.pfPileUp.Vertices = cms.InputTag('goodOfflinePrimaryVertices')
    process.pfPileUp.checkClosestZVertex = cms.bool(False)
    process.pfCHS = cms.Path(process.goodOfflinePrimaryVertices *
                             process.PFBRECO)
    process.ak5PFJetsCHS = process.ak5PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))
    process.ak7PFJetsCHS = process.ak7PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))
    process.kt4PFJetsCHS = process.kt4PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))
    process.kt6PFJetsCHS = process.kt6PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))

    # Gen Jets without neutrinos ----------------------------------------------
    if datatype == 'mc':
        process.load('RecoJets.JetProducers.ak5GenJets_cfi')
        process.NoNuGenJets = cms.Path(
            process.genParticlesForJetsNoNu * process.genParticlesForJets *
            process.ak5GenJetsNoNu * process.ak7GenJetsNoNu *
            process.kt4GenJetsNoNu * process.kt4GenJets *
            process.kt6GenJetsNoNu * process.kt6GenJets)

    # Path to Redo all Jets ---------------------------------------------------
    process.jetsRedo = cms.Path(process.ak5PFJets * process.ak7PFJets *
                                process.kt4PFJets * process.kt6PFJets *
                                process.ak5PFJetsCHS * process.ak7PFJetsCHS *
                                process.kt4PFJetsCHS * process.kt6PFJetsCHS)

    # QG TAGGER ----------------------------------------------------------------
    process.load('QuarkGluonTagger.EightTeV.QGTagger_RecoJets_cff')
    process.QGTagger.srcJets = cms.InputTag("ak5PFJets")

    process.AK5PFJetsQGTagger = process.QGTagger
    process.AK5PFJetsCHSQGTagger = process.QGTagger.clone(
        srcJets=cms.InputTag("ak5PFJetsCHS"), useCHS=cms.untracked.bool(True))

    process.AK7PFJetsQGTagger = process.QGTagger.clone(
        srcJets=cms.InputTag("ak7PFJets"))
    process.AK7PFJetsCHSQGTagger = process.QGTagger.clone(
        srcJets=cms.InputTag("ak7PFJetsCHS"), useCHS=cms.untracked.bool(True))

    process.QGTagging = cms.Path(
        process.QuarkGluonTagger * process.AK5PFJetsQGTagger *
        process.AK5PFJetsCHSQGTagger * process.AK7PFJetsQGTagger *
        process.AK7PFJetsCHSQGTagger)

    # B-Tagging ----------------------------------------------------------------
    # b-tagging general configuration
    process.load(
        "RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
    process.load("RecoBTag.Configuration.RecoBTag_cff")

    ### AK5
    # create a ak5PF jets and tracks association
    process.ak5PFJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone(
    )
    process.ak5PFJetTracksAssociatorAtVertex.jets = "ak5PFJets"
    process.ak5PFJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak5PFImpactParameterTagInfos = process.impactParameterTagInfos.clone(
    )
    process.ak5PFImpactParameterTagInfos.jetTracks = "ak5PFJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak5PFSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone(
    )
    process.ak5PFSecondaryVertexTagInfos.trackIPTagInfos = "ak5PFImpactParameterTagInfos"
    process.ak5PFSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone(
    )
    process.ak5PFSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFSecondaryVertexTagInfos"))
    process.ak5PFCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone(
    )
    process.ak5PFCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFImpactParameterTagInfos"),
        cms.InputTag("ak5PFSecondaryVertexTagInfos"))
    process.ak5PFCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone(
    )
    process.ak5PFCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFImpactParameterTagInfos"),
        cms.InputTag("ak5PFSecondaryVertexTagInfos"))

    # sequence for AK5 b-tagging
    process.ak5PFJetBtagging = cms.Sequence(
        process.ak5PFJetTracksAssociatorAtVertex *
        process.ak5PFImpactParameterTagInfos *
        process.ak5PFSecondaryVertexTagInfos *
        process.ak5PFSecondaryVertexTagInfos *
        (process.ak5PFSimpleSecondaryVertexBJetTags +
         process.ak5PFCombinedSecondaryVertexBJetTags +
         process.ak5PFCombinedSecondaryVertexMVABJetTags))

    ### AK5 CHS
    # create a ak5PFCHS jets and tracks association
    process.ak5PFCHSJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone(
    )
    process.ak5PFCHSJetTracksAssociatorAtVertex.jets = "ak5PFJetsCHS"
    process.ak5PFCHSJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak5PFCHSImpactParameterTagInfos = process.impactParameterTagInfos.clone(
    )
    process.ak5PFCHSImpactParameterTagInfos.jetTracks = "ak5PFCHSJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak5PFCHSSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone(
    )
    process.ak5PFCHSSecondaryVertexTagInfos.trackIPTagInfos = "ak5PFCHSImpactParameterTagInfos"
    process.ak5PFCHSSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone(
    )
    process.ak5PFCHSSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSSecondaryVertexTagInfos"))
    process.ak5PFCHSCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone(
    )
    process.ak5PFCHSCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSImpactParameterTagInfos"),
        cms.InputTag("ak5PFCHSSecondaryVertexTagInfos"))
    process.ak5PFCHSCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone(
    )
    process.ak5PFCHSCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSImpactParameterTagInfos"),
        cms.InputTag("ak5PFCHSSecondaryVertexTagInfos"))

    # sequence for AK5CHS b-tagging
    process.ak5PFCHSJetBtagging = cms.Sequence(
        process.ak5PFCHSJetTracksAssociatorAtVertex *
        process.ak5PFCHSImpactParameterTagInfos *
        process.ak5PFCHSSecondaryVertexTagInfos *
        process.ak5PFCHSSecondaryVertexTagInfos *
        (process.ak5PFCHSSimpleSecondaryVertexBJetTags +
         process.ak5PFCHSCombinedSecondaryVertexBJetTags +
         process.ak5PFCHSCombinedSecondaryVertexMVABJetTags))

    ### AK7
    # create a ak7PF jets and tracks association
    process.ak7PFJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone(
    )
    process.ak7PFJetTracksAssociatorAtVertex.jets = "ak7PFJets"
    process.ak7PFJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak7PFImpactParameterTagInfos = process.impactParameterTagInfos.clone(
    )
    process.ak7PFImpactParameterTagInfos.jetTracks = "ak7PFJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak7PFSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone(
    )
    process.ak7PFSecondaryVertexTagInfos.trackIPTagInfos = "ak7PFImpactParameterTagInfos"
    process.ak7PFSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone(
    )
    process.ak7PFSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFSecondaryVertexTagInfos"))
    process.ak7PFCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone(
    )
    process.ak7PFCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFImpactParameterTagInfos"),
        cms.InputTag("ak7PFSecondaryVertexTagInfos"))
    process.ak7PFCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone(
    )
    process.ak7PFCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFImpactParameterTagInfos"),
        cms.InputTag("ak7PFSecondaryVertexTagInfos"))

    # sequence for AK7 b-tagging
    process.ak7PFJetBtagging = cms.Sequence(
        process.ak7PFJetTracksAssociatorAtVertex *
        process.ak7PFImpactParameterTagInfos *
        process.ak7PFSecondaryVertexTagInfos *
        process.ak7PFSecondaryVertexTagInfos *
        (process.ak7PFSimpleSecondaryVertexBJetTags +
         process.ak7PFCombinedSecondaryVertexBJetTags +
         process.ak7PFCombinedSecondaryVertexMVABJetTags))

    ### AK7 CHS
    # create a ak7PFCHS jets and tracks association
    process.ak7PFCHSJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone(
    )
    process.ak7PFCHSJetTracksAssociatorAtVertex.jets = "ak7PFJetsCHS"
    process.ak7PFCHSJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak7PFCHSImpactParameterTagInfos = process.impactParameterTagInfos.clone(
    )
    process.ak7PFCHSImpactParameterTagInfos.jetTracks = "ak7PFCHSJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak7PFCHSSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone(
    )
    process.ak7PFCHSSecondaryVertexTagInfos.trackIPTagInfos = "ak7PFCHSImpactParameterTagInfos"
    process.ak7PFCHSSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone(
    )
    process.ak7PFCHSSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFCHSSecondaryVertexTagInfos"))
    process.ak7PFCHSCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone(
    )
    process.ak7PFCHSCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFCHSImpactParameterTagInfos"),
        cms.InputTag("ak7PFCHSSecondaryVertexTagInfos"))
    process.ak7PFCHSCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone(
    )
    process.ak7PFCHSCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFCHSImpactParameterTagInfos"),
        cms.InputTag("ak7PFCHSSecondaryVertexTagInfos"))

    # sequence for AK7CHS b-tagging
    process.ak7PFCHSJetBtagging = cms.Sequence(
        process.ak7PFCHSJetTracksAssociatorAtVertex *
        process.ak7PFCHSImpactParameterTagInfos *
        process.ak7PFCHSSecondaryVertexTagInfos *
        process.ak7PFCHSSecondaryVertexTagInfos *
        (process.ak7PFCHSSimpleSecondaryVertexBJetTags +
         process.ak7PFCHSCombinedSecondaryVertexBJetTags +
         process.ak7PFCHSCombinedSecondaryVertexMVABJetTags))

    # Add the modules for all the jet collections to the path
    process.BTagging = cms.Path(
        process.ak5PFJetBtagging * process.ak5PFCHSJetBtagging *
        process.ak7PFJetBtagging * process.ak7PFCHSJetBtagging)

    # PU jet ID ---------------------------------------------------------------
    process.load("RecoJets.JetProducers.PileupJetID_cfi")

    # AK5
    process.ak5PFPuJetId = process.pileupJetIdProducer.clone(
        jets=cms.InputTag("ak5PFJets"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    process.ak5PFPuJetMva = process.pileupJetIdProducer.clone(
        jets=cms.InputTag("ak5PFJets"),
        jetids=cms.InputTag("ak5PFPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )
    # AK5 CHS
    process.ak5PFCHSPuJetId = process.pileupJetIdProducerChs.clone(
        jets=cms.InputTag("ak5PFJetsCHS"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    process.ak5PFCHSPuJetMva = process.pileupJetIdProducerChs.clone(
        jets=cms.InputTag("ak5PFJetsCHS"),
        jetids=cms.InputTag("ak5PFCHSPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    # ak7
    process.ak7PFPuJetId = process.pileupJetIdProducer.clone(
        jets=cms.InputTag("ak7PFJets"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    process.ak7PFPuJetMva = process.pileupJetIdProducer.clone(
        jets=cms.InputTag("ak7PFJets"),
        jetids=cms.InputTag("ak7PFPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )
    # ak7 CHS
    process.ak7PFCHSPuJetId = process.pileupJetIdProducerChs.clone(
        jets=cms.InputTag("ak7PFJetsCHS"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    process.ak7PFCHSPuJetMva = process.pileupJetIdProducerChs.clone(
        jets=cms.InputTag("ak7PFJetsCHS"),
        jetids=cms.InputTag("ak7PFCHSPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
        residualsTxt=cms.FileInPath("RecoMET/METPUSubtraction/data/dummy.txt"),
    )

    process.PUJetID = cms.Path(
        process.ak5PFPuJetId * process.ak5PFPuJetMva *
        process.ak5PFCHSPuJetId * process.ak5PFCHSPuJetMva *
        process.ak7PFPuJetId * process.ak7PFPuJetMva *
        process.ak7PFCHSPuJetId * process.ak7PFCHSPuJetMva)

    # MET filters -------------------------------------------------------------
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    # Create good vertices for the trackingFailure MET filter
    process.goodVertices = cms.EDFilter(
        "VertexSelector",
        filter=cms.bool(False),
        src=cms.InputTag("offlinePrimaryVertices"),
        cut=cms.string(
            "!isFake && ndof > 4 && abs(z) <= 24 && position.rho < 2"),
    )
    # The good primary vertex filter for other MET filters
    process.primaryVertexFilter = cms.EDFilter(
        "VertexSelector",
        filter=cms.bool(True),
        src=cms.InputTag("offlinePrimaryVertices"),
        cut=cms.string(
            "!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
    )
    process.noscraping = cms.EDFilter("FilterOutScraping",
                                      applyfilter=cms.untracked.bool(True),
                                      debugOn=cms.untracked.bool(False),
                                      numtrack=cms.untracked.uint32(10),
                                      thresh=cms.untracked.double(0.25))
    process.load('CommonTools.RecoAlgos.HBHENoiseFilter_cfi')
    process.load('RecoMET.METAnalyzers.CSCHaloFilter_cfi')
    process.load('RecoMET.METFilters.hcalLaserEventFilter_cfi')
    process.hcalLaserEventFilter.vetoByRunEventNumber = cms.untracked.bool(
        False)
    process.hcalLaserEventFilter.vetoByHBHEOccupancy = cms.untracked.bool(True)
    process.load('RecoMET.METFilters.EcalDeadCellTriggerPrimitiveFilter_cfi')
    process.EcalDeadCellTriggerPrimitiveFilter.tpDigiCollection = cms.InputTag(
        "ecalTPSkimNA")
    process.load('RecoMET.METFilters.EcalDeadCellBoundaryEnergyFilter_cfi')
    process.load('RecoMET.METFilters.eeBadScFilter_cfi')
    process.load('RecoMET.METFilters.eeNoiseFilter_cfi')
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    process.load('RecoMET.METFilters.trackingFailureFilter_cfi')
    process.load('RecoMET.METFilters.inconsistentMuonPFCandidateFilter_cfi')
    process.load('RecoMET.METFilters.greedyMuonPFCandidateFilter_cfi')

    process.hcalLaserEventFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellTriggerPrimitiveFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellBoundaryEnergyFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.eeBadScFilter.taggingMode = cms.bool(True)
    process.eeNoiseFilter.taggingMode = cms.bool(True)
    process.ecalLaserCorrFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.inconsistentMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.greedyMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.beamScrapingFilter = process.inconsistentMuonPFCandidateFilter.clone(
        ptMin=cms.double(5000.0))
    process.hcalNoiseFilter = process.beamScrapingFilter.clone()
    process.beamHaloFilter = process.beamScrapingFilter.clone()
    process.filtersSeq = cms.Sequence(
        process.primaryVertexFilter * process.hcalLaserEventFilter +
        process.EcalDeadCellTriggerPrimitiveFilter +
        process.EcalDeadCellBoundaryEnergyFilter + process.eeBadScFilter +
        process.eeNoiseFilter + process.ecalLaserCorrFilter +
        process.goodVertices * process.trackingFailureFilter +
        process.inconsistentMuonPFCandidateFilter +
        process.greedyMuonPFCandidateFilter +
        process.noscraping * process.beamScrapingFilter +
        process.HBHENoiseFilter * process.hcalNoiseFilter +
        process.CSCTightHaloFilter * process.beamHaloFilter)
    process.metFilters = cms.Path(process.filtersSeq)

    # MET correction ----------------------------------------------------------
    process.load("JetMETCorrections.Type1MET.pfMETCorrections_cff")
    process.pfchsMETcorr.src = cms.InputTag('goodOfflinePrimaryVertices')
    # Type-0
    process.pfMETCHS = process.pfType1CorrectedMet.clone(
        applyType1Corrections=cms.bool(False),
        applyType0Corrections=cms.bool(True))
    # MET Path
    process.metCorrections = cms.Path(process.producePFMETCorrections *
                                      process.pfMETCHS)

    # Require two good muons --------------------------------------------------
    process.goodMuons = cms.EDFilter(
        'CandViewSelector',
        src=cms.InputTag('muons'),
        cut=cms.string("pt > 12.0 & abs(eta) < 8.0 & isGlobalMuon()"),
    )
    process.twoGoodMuons = cms.EDFilter(
        'CandViewCountFilter',
        src=cms.InputTag('goodMuons'),
        minNumber=cms.uint32(2),
    )

    # Configure tuple generation ----------------------------------------------
    process.load('Kappa.Producers.KTuple_cff')
    process.kappatuple = cms.EDAnalyzer(
        'KTuple',
        process.kappaTupleDefaultsBlock,
        outputFile=cms.string("skim.root"),
        PFTaggedJets=cms.PSet(
            process.kappaNoCut,
            process.kappaNoRegEx,
            taggers=cms.vstring("QGlikelihood", "QGmlp",
                                "CombinedSecondaryVertexBJetTags",
                                "CombinedSecondaryVertexMVABJetTags",
                                "puJetIDFullLoose", "puJetIDFullMedium",
                                "puJetIDFullTight", "puJetIDCutbasedLoose",
                                "puJetIDCutbasedMedium",
                                "puJetIDCutbasedTight", "puJetIDMET"),
            AK5PFTaggedJets=cms.PSet(
                src=cms.InputTag("ak5PFJets"),
                QGtagger=cms.InputTag("AK5PFJetsQGTagger"),
                Btagger=cms.InputTag("ak5PF"),
                PUJetID=cms.InputTag("ak5PFPuJetMva"),
                PUJetID_full=cms.InputTag("full"),
            ),
            AK5PFTaggedJetsCHS=cms.PSet(
                src=cms.InputTag("ak5PFJetsCHS"),
                QGtagger=cms.InputTag("AK5PFJetsCHSQGTagger"),
                Btagger=cms.InputTag("ak5PFCHS"),
                PUJetID=cms.InputTag("ak5PFCHSPuJetMva"),
                PUJetID_full=cms.InputTag("full"),
            ),
            AK7PFTaggedJets=cms.PSet(
                src=cms.InputTag("ak7PFJets"),
                QGtagger=cms.InputTag("AK7PFJetsQGTagger"),
                Btagger=cms.InputTag("ak7PF"),
                PUJetID=cms.InputTag("ak7PFPuJetMva"),
                PUJetID_full=cms.InputTag("full"),
            ),
            AK7PFTaggedJetsCHS=cms.PSet(
                src=cms.InputTag("ak7PFJetsCHS"),
                QGtagger=cms.InputTag("AK7PFJetsCHSQGTagger"),
                Btagger=cms.InputTag("ak7PFCHS"),
                PUJetID=cms.InputTag("ak7PFCHSPuJetMva"),
                PUJetID_full=cms.InputTag("full"),
            ),
        ),
    )

    process.kappatuple.verbose = cms.int32(0)
    process.kappatuple.active = cms.vstring(
        'LV',
        'Muons',
        'TrackSummary',
        'VertexSummary',
        'BeamSpot',
        'JetArea',
        'PFMET',
        'PFJets',
        'FilterSummary',
        'PFTaggedJets',
    )
    if data:
        additional_actives = ['DataMetadata']
    else:
        additional_actives = ['GenMetadata', 'GenParticles']
    for active in additional_actives:
        process.kappatuple.active.append(active)

    process.kappatuple.LV.blacklist += cms.vstring("AK5TrackJets", ".*KT.*")
    process.kappatuple.PFMET.blacklist = cms.vstring("pfType1.*CorrectedMet")

    process.pathKappa = cms.Path(process.goodMuons * process.twoGoodMuons *
                                 process.kappatuple)

    # Process schedule --------------------------------------------------------
    process.schedule = cms.Schedule(
        process.metFilters,
        process.pfCHS,
        process.jetsRedo,
        process.BTagging,
        process.QGTagging,
        process.PUJetID,
        process.pfMuonIso,
        process.metCorrections,
        process.pathKappa,
    )
    if not data:
        process.schedule.insert(0, process.NoNuGenJets)

    return process
def addMuPFIsolation(process, patSequence):
    muons = 'muons'
    process.muPFIsoDepositAll     = isoDepositReplace(
        muons,cms.InputTag("pfNoPileUp"))
    process.muPFIsoDepositCharged = isoDepositReplace(
        muons,"pfAllChargedHadrons")
    process.muPFIsoDepositNeutral = isoDepositReplace(
        muons,"pfAllNeutralHadrons")
    process.muPFIsoDepositGamma = isoDepositReplace(
        muons,"pfAllPhotons")
    #Isodeposit from PileUp- For Vertex subtraction!!!!
    process.muPFIsoDepositPU = isoDepositReplace(
        muons,cms.InputTag("pileUpHadrons"))

    process.muPFIsoDeposits = cms.Sequence(
        process.muPFIsoDepositAll*
        process.muPFIsoDepositCharged*
        process.muPFIsoDepositPU*
        process.muPFIsoDepositNeutral*
        process.muPFIsoDepositGamma
    )
    #And Values
    process.muPFIsoValueAll = cms.EDProducer(
        "CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("muPFIsoDepositAll"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring('0.001','Threshold(0.5)'),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )
    process.muPFIsoValueCharged = cms.EDProducer(
        "CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("muPFIsoDepositCharged"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring('0.0001','Threshold(0.0)'),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )
    process.muPFIsoValueNeutral = cms.EDProducer(
        "CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("muPFIsoDepositNeutral"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring('0.01','Threshold(0.5)'),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )
    process.muPFIsoValueGamma = cms.EDProducer(
        "CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("muPFIsoDepositGamma"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring('0.01','Threshold(0.5)'),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )
    process.muPFIsoValuePU = cms.EDProducer(
        "CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("muPFIsoDepositPU"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring('0.0001','Threshold(0.5)'),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )
    process.muPFIsoValuePULow = cms.EDProducer(
        "CandIsolatorFromDeposits",
        deposits = cms.VPSet(
            cms.PSet(
                src = cms.InputTag("muPFIsoDepositPU"),
                deltaR = cms.double(0.4),
                weight = cms.string('1'),
                vetos = cms.vstring('0.0001','Threshold(0.0)'),
                skipDefaultVeto = cms.bool(True),
                mode = cms.string('sum')
            )
        )
    )
    process.muPFIsoValues =  cms.Sequence(
        process.muPFIsoValueAll
        * process.muPFIsoValueCharged
        * process.muPFIsoValueNeutral
        * process.muPFIsoValueGamma
        * process.muPFIsoValuePU
        * process.muPFIsoValuePULow
    )
    process.patMuons.isoDeposits = cms.PSet(
        particle         = cms.InputTag("muPFIsoDepositAll"),
        pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged"),
        pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral"),
        pfPhotons        = cms.InputTag("muPFIsoDepositGamma")
    )
    process.patMuons.isolationValues = cms.PSet(
        particle         = cms.InputTag("muPFIsoValueAll"),
        pfChargedHadrons = cms.InputTag("muPFIsoValueCharged"),
        pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral"),
        pfPhotons        = cms.InputTag("muPFIsoValueGamma"),
        user = cms.VInputTag(
            cms.InputTag("muPFIsoValuePU"),
            cms.InputTag("muPFIsoValuePULow")
        )
    )
    # Inject into the sequence
    process.muPFIsolation = cms.Sequence(
        process.muPFIsoDeposits*
        process.muPFIsoValues*
        process.patMuons
    )
    inserted = patSequence.replace(process.patMuons, process.muPFIsolation)
    assert(inserted)
Example #12
0
def getBaseConfig(globaltag, testfile="", maxevents=0, datatype="data"):
    """Default config for Z+jet skims with Kappa

       This is used in a cmssw config file via:
       import skim_base
       process = skim_base.getBaseConfig('START53_V12', "testfile.root")
    """
    # Set the globalt tag and datatype for testing or by grid-control ---------
    data = datatype == "data"
    if data:
        testfile = "file:/storage/8/dhaitz/testfiles/data_AOD_2012A.root"
        if "@" in globaltag:
            globaltag = "FT53_V21A_AN6"
        maxevents = maxevents or 100
    else:
        testfile = "file:/storage/8/dhaitz/testfiles/mc-2014.root"
        if "@" in globaltag:
            globaltag = "START53_V19F"
        maxevents = maxevents or 100
        datatype = "mc"
    print "GT:", globaltag, "| TYPE:", datatype, "| maxevents:", maxevents, "| file:", testfile

    # Basic process setup -----------------------------------------------------
    process = cms.Process("kappaSkim")
    process.source = cms.Source("PoolSource", fileNames=cms.untracked.vstring(testfile))
    process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(maxevents))

    # Includes + Global Tag ---------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.load("Configuration.StandardSequences.Services_cff")
    process.load("Configuration.StandardSequences.MagneticField_38T_cff")
    process.load("Configuration.Geometry.GeometryIdeal_cff")
    process.load("Configuration.Geometry.GeometryPilot2_cff")
    process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi")
    process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi")
    process.load("TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi")
    process.load("RecoMuon.DetLayers.muonDetLayerGeometry_cfi")
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    process.load("Configuration.StandardSequences.Reconstruction_cff")
    process.GlobalTag.globaltag = globaltag + "::All"

    # Reduce amount of messages -----------------------------------------------
    process.MessageLogger.default = cms.untracked.PSet(ERROR=cms.untracked.PSet(limit=cms.untracked.int32(5)))
    process.MessageLogger.cerr.FwkReport.reportEvery = 40

    # Produce PF muon isolation -----------------------------------------------
    from CommonTools.ParticleFlow.Isolation.tools_cfi import isoDepositReplace

    process.pfmuIsoDepositPFCandidates = isoDepositReplace("muons", "particleFlow")
    process.pfMuonIso = cms.Path(process.pfmuIsoDepositPFCandidates)

    # Create good primary vertices to be used for PF association --------------
    from PhysicsTools.SelectorUtils.pvSelector_cfi import pvSelector

    process.goodOfflinePrimaryVertices = cms.EDFilter(
        "PrimaryVertexObjectFilter",
        filterParams=pvSelector.clone(minNdof=cms.double(4.0), maxZ=cms.double(24.0)),
        src=cms.InputTag("offlinePrimaryVertices"),
    )
    process.ak5PFJets.srcPVs = cms.InputTag("goodOfflinePrimaryVertices")
    process.ak7PFJets.srcPVs = cms.InputTag("goodOfflinePrimaryVertices")
    process.kt4PFJets.srcPVs = cms.InputTag("goodOfflinePrimaryVertices")
    process.kt6PFJets.srcPVs = cms.InputTag("goodOfflinePrimaryVertices")

    # CHS Jets with the NoPU sequence -----------------------------------------
    process.load("CommonTools.ParticleFlow.PFBRECO_cff")
    process.pfPileUp.Vertices = cms.InputTag("goodOfflinePrimaryVertices")
    process.pfPileUp.checkClosestZVertex = cms.bool(False)
    process.pfCHS = cms.Path(process.goodOfflinePrimaryVertices * process.PFBRECO)
    process.ak5PFJetsCHS = process.ak5PFJets.clone(src=cms.InputTag("pfNoPileUp"))
    process.ak7PFJetsCHS = process.ak7PFJets.clone(src=cms.InputTag("pfNoPileUp"))
    process.kt4PFJetsCHS = process.kt4PFJets.clone(src=cms.InputTag("pfNoPileUp"))
    process.kt6PFJetsCHS = process.kt6PFJets.clone(src=cms.InputTag("pfNoPileUp"))

    # Gen Jets without neutrinos ----------------------------------------------
    if datatype == "mc":
        process.load("RecoJets.JetProducers.ak5GenJets_cfi")
        process.NoNuGenJets = cms.Path(
            process.genParticlesForJetsNoNu
            * process.genParticlesForJets
            * process.ak5GenJetsNoNu
            * process.ak7GenJetsNoNu
            * process.kt4GenJetsNoNu
            * process.kt4GenJets
            * process.kt6GenJetsNoNu
            * process.kt6GenJets
        )

    # Path to Redo all Jets ---------------------------------------------------
    process.jetsRedo = cms.Path(
        process.ak5PFJets
        * process.ak7PFJets
        * process.kt4PFJets
        * process.kt6PFJets
        * process.ak5PFJetsCHS
        * process.ak7PFJetsCHS
        * process.kt4PFJetsCHS
        * process.kt6PFJetsCHS
    )

    # QG TAGGER ----------------------------------------------------------------
    process.load("QuarkGluonTagger.EightTeV.QGTagger_RecoJets_cff")
    process.QGTagger.srcJets = cms.InputTag("ak5PFJets")

    process.AK5PFJetsQGTagger = process.QGTagger
    process.AK5PFJetsCHSQGTagger = process.QGTagger.clone(
        srcJets=cms.InputTag("ak5PFJetsCHS"), useCHS=cms.untracked.bool(True)
    )

    process.AK7PFJetsQGTagger = process.QGTagger.clone(srcJets=cms.InputTag("ak7PFJets"))
    process.AK7PFJetsCHSQGTagger = process.QGTagger.clone(
        srcJets=cms.InputTag("ak7PFJetsCHS"), useCHS=cms.untracked.bool(True)
    )

    process.QGTagging = cms.Path(
        process.QuarkGluonTagger
        * process.AK5PFJetsQGTagger
        * process.AK5PFJetsCHSQGTagger
        * process.AK7PFJetsQGTagger
        * process.AK7PFJetsCHSQGTagger
    )

    # B-Tagging ----------------------------------------------------------------
    # b-tagging general configuration
    process.load("RecoJets.JetAssociationProducers.ic5JetTracksAssociatorAtVertex_cfi")
    process.load("RecoBTag.Configuration.RecoBTag_cff")

    ### AK5
    # create a ak5PF jets and tracks association
    process.ak5PFJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone()
    process.ak5PFJetTracksAssociatorAtVertex.jets = "ak5PFJets"
    process.ak5PFJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak5PFImpactParameterTagInfos = process.impactParameterTagInfos.clone()
    process.ak5PFImpactParameterTagInfos.jetTracks = "ak5PFJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak5PFSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone()
    process.ak5PFSecondaryVertexTagInfos.trackIPTagInfos = "ak5PFImpactParameterTagInfos"
    process.ak5PFSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone()
    process.ak5PFSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(cms.InputTag("ak5PFSecondaryVertexTagInfos"))
    process.ak5PFCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone()
    process.ak5PFCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFImpactParameterTagInfos"), cms.InputTag("ak5PFSecondaryVertexTagInfos")
    )
    process.ak5PFCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone()
    process.ak5PFCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFImpactParameterTagInfos"), cms.InputTag("ak5PFSecondaryVertexTagInfos")
    )

    # sequence for AK5 b-tagging
    process.ak5PFJetBtagging = cms.Sequence(
        process.ak5PFJetTracksAssociatorAtVertex
        * process.ak5PFImpactParameterTagInfos
        * process.ak5PFSecondaryVertexTagInfos
        * process.ak5PFSecondaryVertexTagInfos
        * (
            process.ak5PFSimpleSecondaryVertexBJetTags
            + process.ak5PFCombinedSecondaryVertexBJetTags
            + process.ak5PFCombinedSecondaryVertexMVABJetTags
        )
    )

    ### AK5 CHS
    # create a ak5PFCHS jets and tracks association
    process.ak5PFCHSJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone()
    process.ak5PFCHSJetTracksAssociatorAtVertex.jets = "ak5PFJetsCHS"
    process.ak5PFCHSJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak5PFCHSImpactParameterTagInfos = process.impactParameterTagInfos.clone()
    process.ak5PFCHSImpactParameterTagInfos.jetTracks = "ak5PFCHSJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak5PFCHSSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone()
    process.ak5PFCHSSecondaryVertexTagInfos.trackIPTagInfos = "ak5PFCHSImpactParameterTagInfos"
    process.ak5PFCHSSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone()
    process.ak5PFCHSSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSSecondaryVertexTagInfos")
    )
    process.ak5PFCHSCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone()
    process.ak5PFCHSCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSImpactParameterTagInfos"), cms.InputTag("ak5PFCHSSecondaryVertexTagInfos")
    )
    process.ak5PFCHSCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone()
    process.ak5PFCHSCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak5PFCHSImpactParameterTagInfos"), cms.InputTag("ak5PFCHSSecondaryVertexTagInfos")
    )

    # sequence for AK5CHS b-tagging
    process.ak5PFCHSJetBtagging = cms.Sequence(
        process.ak5PFCHSJetTracksAssociatorAtVertex
        * process.ak5PFCHSImpactParameterTagInfos
        * process.ak5PFCHSSecondaryVertexTagInfos
        * process.ak5PFCHSSecondaryVertexTagInfos
        * (
            process.ak5PFCHSSimpleSecondaryVertexBJetTags
            + process.ak5PFCHSCombinedSecondaryVertexBJetTags
            + process.ak5PFCHSCombinedSecondaryVertexMVABJetTags
        )
    )

    ### AK7
    # create a ak7PF jets and tracks association
    process.ak7PFJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone()
    process.ak7PFJetTracksAssociatorAtVertex.jets = "ak7PFJets"
    process.ak7PFJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak7PFImpactParameterTagInfos = process.impactParameterTagInfos.clone()
    process.ak7PFImpactParameterTagInfos.jetTracks = "ak7PFJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak7PFSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone()
    process.ak7PFSecondaryVertexTagInfos.trackIPTagInfos = "ak7PFImpactParameterTagInfos"
    process.ak7PFSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone()
    process.ak7PFSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(cms.InputTag("ak7PFSecondaryVertexTagInfos"))
    process.ak7PFCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone()
    process.ak7PFCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFImpactParameterTagInfos"), cms.InputTag("ak7PFSecondaryVertexTagInfos")
    )
    process.ak7PFCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone()
    process.ak7PFCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFImpactParameterTagInfos"), cms.InputTag("ak7PFSecondaryVertexTagInfos")
    )

    # sequence for AK7 b-tagging
    process.ak7PFJetBtagging = cms.Sequence(
        process.ak7PFJetTracksAssociatorAtVertex
        * process.ak7PFImpactParameterTagInfos
        * process.ak7PFSecondaryVertexTagInfos
        * process.ak7PFSecondaryVertexTagInfos
        * (
            process.ak7PFSimpleSecondaryVertexBJetTags
            + process.ak7PFCombinedSecondaryVertexBJetTags
            + process.ak7PFCombinedSecondaryVertexMVABJetTags
        )
    )

    ### AK7 CHS
    # create a ak7PFCHS jets and tracks association
    process.ak7PFCHSJetTracksAssociatorAtVertex = process.ic5JetTracksAssociatorAtVertex.clone()
    process.ak7PFCHSJetTracksAssociatorAtVertex.jets = "ak7PFJetsCHS"
    process.ak7PFCHSJetTracksAssociatorAtVertex.tracks = "generalTracks"

    process.ak7PFCHSImpactParameterTagInfos = process.impactParameterTagInfos.clone()
    process.ak7PFCHSImpactParameterTagInfos.jetTracks = "ak7PFCHSJetTracksAssociatorAtVertex"

    # secondary vertex b-tag
    process.ak7PFCHSSecondaryVertexTagInfos = process.secondaryVertexTagInfos.clone()
    process.ak7PFCHSSecondaryVertexTagInfos.trackIPTagInfos = "ak7PFCHSImpactParameterTagInfos"
    process.ak7PFCHSSimpleSecondaryVertexBJetTags = process.simpleSecondaryVertexBJetTags.clone()
    process.ak7PFCHSSimpleSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFCHSSecondaryVertexTagInfos")
    )
    process.ak7PFCHSCombinedSecondaryVertexBJetTags = process.combinedSecondaryVertexBJetTags.clone()
    process.ak7PFCHSCombinedSecondaryVertexBJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFCHSImpactParameterTagInfos"), cms.InputTag("ak7PFCHSSecondaryVertexTagInfos")
    )
    process.ak7PFCHSCombinedSecondaryVertexMVABJetTags = process.combinedSecondaryVertexMVABJetTags.clone()
    process.ak7PFCHSCombinedSecondaryVertexMVABJetTags.tagInfos = cms.VInputTag(
        cms.InputTag("ak7PFCHSImpactParameterTagInfos"), cms.InputTag("ak7PFCHSSecondaryVertexTagInfos")
    )

    # sequence for AK7CHS b-tagging
    process.ak7PFCHSJetBtagging = cms.Sequence(
        process.ak7PFCHSJetTracksAssociatorAtVertex
        * process.ak7PFCHSImpactParameterTagInfos
        * process.ak7PFCHSSecondaryVertexTagInfos
        * process.ak7PFCHSSecondaryVertexTagInfos
        * (
            process.ak7PFCHSSimpleSecondaryVertexBJetTags
            + process.ak7PFCHSCombinedSecondaryVertexBJetTags
            + process.ak7PFCHSCombinedSecondaryVertexMVABJetTags
        )
    )

    # Add the modules for all the jet collections to the path
    process.BTagging = cms.Path(
        process.ak5PFJetBtagging * process.ak5PFCHSJetBtagging * process.ak7PFJetBtagging * process.ak7PFCHSJetBtagging
    )

    # PU jet ID ---------------------------------------------------------------
    process.load("CMGTools.External.pujetidsequence_cff")

    # AK5
    process.ak5PFPuJetId = process.puJetId.clone(
        jets=cms.InputTag("ak5PFJets"), applyJec=cms.bool(True), inputIsCorrected=cms.bool(False)
    )

    process.ak5PFPuJetMva = process.puJetMva.clone(
        jets=cms.InputTag("ak5PFJets"),
        jetids=cms.InputTag("ak5PFPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
    )
    # AK5 CHS
    process.ak5PFCHSPuJetId = process.puJetIdChs.clone(
        jets=cms.InputTag("ak5PFJetsCHS"), applyJec=cms.bool(True), inputIsCorrected=cms.bool(False)
    )

    process.ak5PFCHSPuJetMva = process.puJetMvaChs.clone(
        jets=cms.InputTag("ak5PFJetsCHS"),
        jetids=cms.InputTag("ak5PFCHSPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
    )

    # ak7
    process.ak7PFPuJetId = process.puJetId.clone(
        jets=cms.InputTag("ak7PFJets"), applyJec=cms.bool(True), inputIsCorrected=cms.bool(False)
    )

    process.ak7PFPuJetMva = process.puJetMva.clone(
        jets=cms.InputTag("ak7PFJets"),
        jetids=cms.InputTag("ak7PFPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
    )
    # ak7 CHS
    process.ak7PFCHSPuJetId = process.puJetIdChs.clone(
        jets=cms.InputTag("ak7PFJetsCHS"), applyJec=cms.bool(True), inputIsCorrected=cms.bool(False)
    )

    process.ak7PFCHSPuJetMva = process.puJetMvaChs.clone(
        jets=cms.InputTag("ak7PFJetsCHS"),
        jetids=cms.InputTag("ak7PFCHSPuJetId"),
        applyJec=cms.bool(True),
        inputIsCorrected=cms.bool(False),
    )

    process.PUJetID = cms.Path(
        process.ak5PFPuJetId
        * process.ak5PFPuJetMva
        * process.ak5PFCHSPuJetId
        * process.ak5PFCHSPuJetMva
        * process.ak7PFPuJetId
        * process.ak7PFPuJetMva
        * process.ak7PFCHSPuJetId
        * process.ak7PFCHSPuJetMva
    )

    # MET filters -------------------------------------------------------------
    process.load("RecoMET.METFilters.ecalLaserCorrFilter_cfi")
    # Create good vertices for the trackingFailure MET filter
    process.goodVertices = cms.EDFilter(
        "VertexSelector",
        filter=cms.bool(False),
        src=cms.InputTag("offlinePrimaryVertices"),
        cut=cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.rho < 2"),
    )
    # The good primary vertex filter for other MET filters
    process.primaryVertexFilter = cms.EDFilter(
        "VertexSelector",
        filter=cms.bool(True),
        src=cms.InputTag("offlinePrimaryVertices"),
        cut=cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
    )
    process.noscraping = cms.EDFilter(
        "FilterOutScraping",
        applyfilter=cms.untracked.bool(True),
        debugOn=cms.untracked.bool(False),
        numtrack=cms.untracked.uint32(10),
        thresh=cms.untracked.double(0.25),
    )
    process.load("CommonTools.RecoAlgos.HBHENoiseFilter_cfi")
    process.load("RecoMET.METAnalyzers.CSCHaloFilter_cfi")
    process.load("RecoMET.METFilters.hcalLaserEventFilter_cfi")
    process.hcalLaserEventFilter.vetoByRunEventNumber = cms.untracked.bool(False)
    process.hcalLaserEventFilter.vetoByHBHEOccupancy = cms.untracked.bool(True)
    process.load("RecoMET.METFilters.EcalDeadCellTriggerPrimitiveFilter_cfi")
    process.EcalDeadCellTriggerPrimitiveFilter.tpDigiCollection = cms.InputTag("ecalTPSkimNA")
    process.load("RecoMET.METFilters.EcalDeadCellBoundaryEnergyFilter_cfi")
    process.load("RecoMET.METFilters.eeBadScFilter_cfi")
    process.load("RecoMET.METFilters.eeNoiseFilter_cfi")
    process.load("RecoMET.METFilters.ecalLaserCorrFilter_cfi")
    process.load("RecoMET.METFilters.trackingFailureFilter_cfi")
    process.load("RecoMET.METFilters.inconsistentMuonPFCandidateFilter_cfi")
    process.load("RecoMET.METFilters.greedyMuonPFCandidateFilter_cfi")

    process.hcalLaserEventFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellTriggerPrimitiveFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellBoundaryEnergyFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.eeBadScFilter.taggingMode = cms.bool(True)
    process.eeNoiseFilter.taggingMode = cms.bool(True)
    process.ecalLaserCorrFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.inconsistentMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.greedyMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.beamScrapingFilter = process.inconsistentMuonPFCandidateFilter.clone(ptMin=cms.double(5000.0))
    process.hcalNoiseFilter = process.beamScrapingFilter.clone()
    process.beamHaloFilter = process.beamScrapingFilter.clone()
    process.filtersSeq = cms.Sequence(
        process.primaryVertexFilter * process.hcalLaserEventFilter
        + process.EcalDeadCellTriggerPrimitiveFilter
        + process.EcalDeadCellBoundaryEnergyFilter
        + process.eeBadScFilter
        + process.eeNoiseFilter
        + process.ecalLaserCorrFilter
        + process.goodVertices * process.trackingFailureFilter
        + process.inconsistentMuonPFCandidateFilter
        + process.greedyMuonPFCandidateFilter
        + process.noscraping * process.beamScrapingFilter
        + process.HBHENoiseFilter * process.hcalNoiseFilter
        + process.CSCTightHaloFilter * process.beamHaloFilter
    )
    process.metFilters = cms.Path(process.filtersSeq)

    # MET correction ----------------------------------------------------------
    process.load("JetMETCorrections.Type1MET.pfMETCorrections_cff")
    process.pfchsMETcorr.src = cms.InputTag("goodOfflinePrimaryVertices")
    # Type-0
    process.pfMETCHS = process.pfType1CorrectedMet.clone(
        applyType1Corrections=cms.bool(False), applyType0Corrections=cms.bool(True)
    )
    # MET Path
    process.metCorrections = cms.Path(process.producePFMETCorrections * process.pfMETCHS)

    # Require two good muons --------------------------------------------------
    process.goodMuons = cms.EDFilter(
        "CandViewSelector", src=cms.InputTag("muons"), cut=cms.string("pt > 12.0 & abs(eta) < 8.0 & isGlobalMuon()")
    )
    process.twoGoodMuons = cms.EDFilter("CandViewCountFilter", src=cms.InputTag("goodMuons"), minNumber=cms.uint32(2))

    # Configure tuple generation ----------------------------------------------
    process.load("Kappa.Producers.KTuple_cff")
    process.kappatuple = cms.EDAnalyzer(
        "KTuple",
        process.kappaTupleDefaultsBlock,
        outputFile=cms.string("skim.root"),
        PFTaggedJets=cms.PSet(
            process.kappaNoCut,
            process.kappaNoRegEx,
            taggers=cms.vstring(
                "QGlikelihood",
                "QGmlp",
                "CombinedSecondaryVertexBJetTags",
                "CombinedSecondaryVertexMVABJetTags",
                "puJetIDFullLoose",
                "puJetIDFullMedium",
                "puJetIDFullTight",
                "puJetIDCutbasedLoose",
                "puJetIDCutbasedMedium",
                "puJetIDCutbasedTight",
            ),
            AK5PFTaggedJets=cms.PSet(
                src=cms.InputTag("ak5PFJets"),
                QGtagger=cms.InputTag("AK5PFJetsQGTagger"),
                Btagger=cms.InputTag("ak5PF"),
                PUJetID=cms.InputTag("ak5PFPuJetMva"),
                PUJetID_full=cms.InputTag("full53x"),
            ),
            AK5PFTaggedJetsCHS=cms.PSet(
                src=cms.InputTag("ak5PFJetsCHS"),
                QGtagger=cms.InputTag("AK5PFJetsCHSQGTagger"),
                Btagger=cms.InputTag("ak5PFCHS"),
                PUJetID=cms.InputTag("ak5PFCHSPuJetMva"),
                PUJetID_full=cms.InputTag("full"),
            ),
            AK7PFTaggedJets=cms.PSet(
                src=cms.InputTag("ak7PFJets"),
                QGtagger=cms.InputTag("AK7PFJetsQGTagger"),
                Btagger=cms.InputTag("ak7PF"),
                PUJetID=cms.InputTag("ak7PFPuJetMva"),
                PUJetID_full=cms.InputTag("full53x"),
            ),
            AK7PFTaggedJetsCHS=cms.PSet(
                src=cms.InputTag("ak7PFJetsCHS"),
                QGtagger=cms.InputTag("AK7PFJetsCHSQGTagger"),
                Btagger=cms.InputTag("ak7PFCHS"),
                PUJetID=cms.InputTag("ak7PFCHSPuJetMva"),
                PUJetID_full=cms.InputTag("full"),
            ),
        ),
    )

    process.kappatuple.verbose = cms.int32(0)
    process.kappatuple.active = cms.vstring(
        "LV",
        "Muons",
        "TrackSummary",
        "VertexSummary",
        "BeamSpot",
        "JetArea",
        "PFMET",
        "PFJets",
        "FilterSummary",
        "PFTaggedJets",
    )
    if data:
        additional_actives = ["DataMetadata"]
    else:
        additional_actives = ["GenMetadata", "GenParticles"]
    for active in additional_actives:
        process.kappatuple.active.append(active)

    # custom whitelist, otherwise the HLT trigger bits are not sufficient!
    process.kappatuple.Metadata.hltWhitelist = cms.vstring(
        # matches 'HLT_Mu17_Mu8_v7' etc.
        "^HLT_(Double)?Mu([0-9]+)_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",
        # matches 'HLT_DoubleMu7_v8' etc.
        "^HLT_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",
    )
    process.kappatuple.Metadata.tauDiscrProcessName = cms.untracked.string("XXXXXXXXX")
    process.kappatuple.GenParticles.genParticles.selectedStatus = cms.int32(31)

    # use the good objects not temporary ones
    process.kappatuple.VertexSummary.whitelist = cms.vstring(".*fflinePrimaryVertices")
    process.kappatuple.VertexSummary.blacklist += cms.vstring(".*QG.*")
    process.kappatuple.LV.whitelist += cms.vstring("recoCaloJets.*")
    process.kappatuple.LV.blacklist += cms.vstring("AK5TrackJets", ".*KT.*")
    process.kappatuple.PFJets.whitelist = cms.vstring("recoPFJets.*kappaSkim")
    process.kappatuple.PFMET.blacklist = cms.vstring("pfType1.*CorrectedMet")
    process.kappatuple.PFJets.blacklist = cms.vstring(
        ".*Tau.*", "recoPFJets_pfJets.*kappaSkim", ".*ak5.*", ".*ak7.*", ".*QG.*", ".*KT.*"
    )
    del process.kappatuple.GenParticles.genStableMuons

    process.pathKappa = cms.Path(process.goodMuons * process.twoGoodMuons * process.kappatuple)

    # Process schedule --------------------------------------------------------
    process.schedule = cms.Schedule(
        process.metFilters,
        process.pfCHS,
        process.jetsRedo,
        process.BTagging,
        process.QGTagging,
        process.PUJetID,
        process.pfMuonIso,
        process.metCorrections,
        process.pathKappa,
    )
    if not data:
        process.schedule.insert(0, process.NoNuGenJets)

    return process
def getBaseConfig(globaltag, testfile="", maxevents=0, datatype='data'):
    """Default config for Z+jet skims with Kappa

       This is used in a cmssw config file via:
       import skim_base
       process = skim_base.getBaseConfig('START53_V12', "testfile.root")
    """
    # Set the globalt tag and datatype for testing or by grid-control ---------
    data = (datatype == 'data')
    if data:
        testfile = 'file:/storage/8/dhaitz/testfiles/data_AOD_2012A.root'
        if '@' in globaltag: globaltag = 'FT53_V21A_AN6'
        maxevents = maxevents or 100
    else:
        testfile = 'file:/storage/8/dhaitz/testfiles/rundepMC.root'
        if '@' in globaltag: globaltag = 'START53_V19F'
        maxevents = maxevents or 100
        datatype = 'mc'
    print "GT:", globaltag, "| TYPE:", datatype, "| maxevents:", maxevents, "| file:", testfile

    # Basic process setup -----------------------------------------------------
    process = cms.Process('kappaSkim')
    process.source = cms.Source('PoolSource',
        fileNames = cms.untracked.vstring(testfile))
    process.maxEvents = cms.untracked.PSet(
        input = cms.untracked.int32(maxevents))

    # Includes + Global Tag ---------------------------------------------------
    process.load('FWCore.MessageService.MessageLogger_cfi')
    process.load('Configuration.StandardSequences.Services_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.Geometry.GeometryIdeal_cff')
    process.load('Configuration.Geometry.GeometryPilot2_cff')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi')
    process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi')
    process.load('RecoMuon.DetLayers.muonDetLayerGeometry_cfi')
    process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.GlobalTag.globaltag = globaltag + '::All'

    # Reduce amount of messages -----------------------------------------------
    process.MessageLogger.default = cms.untracked.PSet(
        ERROR = cms.untracked.PSet(limit = cms.untracked.int32(5)))
    process.MessageLogger.cerr.FwkReport.reportEvery = 40

    # Produce PF muon isolation -----------------------------------------------
    from CommonTools.ParticleFlow.Isolation.tools_cfi import isoDepositReplace
    process.pfmuIsoDepositPFCandidates = isoDepositReplace('muons', 'particleFlow')
    process.pfMuonIso = cms.Path(process.pfmuIsoDepositPFCandidates)

    # Create good primary vertices to be used for PF association --------------
    from PhysicsTools.SelectorUtils.pvSelector_cfi import pvSelector
    process.goodOfflinePrimaryVertices = cms.EDFilter("PrimaryVertexObjectFilter",
        filterParams = pvSelector.clone(minNdof = cms.double(4.0), maxZ = cms.double(24.0)),
        src=cms.InputTag('offlinePrimaryVertices')
    )
    process.ak5PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.ak7PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.kt4PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.kt6PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')


    # CHS Jets with the NoPU sequence -----------------------------------------
    process.load('CommonTools.ParticleFlow.PFBRECO_cff')
    process.pfPileUp.Vertices = cms.InputTag('goodOfflinePrimaryVertices')
    process.pfPileUp.checkClosestZVertex = cms.bool(False)
    process.pfCHS = cms.Path(process.goodOfflinePrimaryVertices * process.PFBRECO)
    process.ak5PFJetsCHS = process.ak5PFJets.clone(src = cms.InputTag('pfNoPileUp'))
    process.ak7PFJetsCHS = process.ak7PFJets.clone(src = cms.InputTag('pfNoPileUp'))
    process.kt4PFJetsCHS = process.kt4PFJets.clone(src = cms.InputTag('pfNoPileUp'))
    process.kt6PFJetsCHS = process.kt6PFJets.clone(src = cms.InputTag('pfNoPileUp'))

    # Gen Jets without neutrinos ----------------------------------------------
    if datatype == 'mc':
        process.load('RecoJets.JetProducers.ak5GenJets_cfi')
        process.NoNuGenJets = cms.Path(process.genParticlesForJetsNoNu *
            process.genParticlesForJets *
            process.ak5GenJetsNoNu * process.ak7GenJetsNoNu *
            process.kt4GenJetsNoNu * process.kt4GenJets *
            process.kt6GenJetsNoNu * process.kt6GenJets
        )

    # Path to Redo all Jets ---------------------------------------------------
    process.jetsRedo = cms.Path(
        process.ak5PFJets * process.ak7PFJets * process.kt4PFJets * process.kt6PFJets *
        process.ak5PFJetsCHS * process.ak7PFJetsCHS * process.kt4PFJetsCHS * process.kt6PFJetsCHS
    )

    # MET filters -------------------------------------------------------------
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    # Create good vertices for the trackingFailure MET filter
    process.goodVertices = cms.EDFilter("VertexSelector",
        filter = cms.bool(False),
        src = cms.InputTag("offlinePrimaryVertices"),
        cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.rho < 2"),
    )
    # The good primary vertex filter for other MET filters
    process.primaryVertexFilter = cms.EDFilter("VertexSelector",
        filter = cms.bool(True),
        src = cms.InputTag("offlinePrimaryVertices"),
        cut = cms.string("!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
    )
    process.noscraping = cms.EDFilter("FilterOutScraping",
        applyfilter = cms.untracked.bool(True),
        debugOn = cms.untracked.bool(False),
        numtrack = cms.untracked.uint32(10),
        thresh = cms.untracked.double(0.25)
    )
    process.load('CommonTools.RecoAlgos.HBHENoiseFilter_cfi')
    process.load('RecoMET.METAnalyzers.CSCHaloFilter_cfi')
    process.load('RecoMET.METFilters.hcalLaserEventFilter_cfi')
    process.hcalLaserEventFilter.vetoByRunEventNumber = cms.untracked.bool(False)
    process.hcalLaserEventFilter.vetoByHBHEOccupancy = cms.untracked.bool(True)
    process.load('RecoMET.METFilters.EcalDeadCellTriggerPrimitiveFilter_cfi')
    process.EcalDeadCellTriggerPrimitiveFilter.tpDigiCollection = cms.InputTag("ecalTPSkimNA")
    process.load('RecoMET.METFilters.EcalDeadCellBoundaryEnergyFilter_cfi')
    process.load('RecoMET.METFilters.eeBadScFilter_cfi')
    process.load('RecoMET.METFilters.eeNoiseFilter_cfi')
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    process.load('RecoMET.METFilters.trackingFailureFilter_cfi')
    process.load('RecoMET.METFilters.inconsistentMuonPFCandidateFilter_cfi')
    process.load('RecoMET.METFilters.greedyMuonPFCandidateFilter_cfi')

    process.hcalLaserEventFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellTriggerPrimitiveFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellBoundaryEnergyFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.eeBadScFilter.taggingMode = cms.bool(True)
    process.eeNoiseFilter.taggingMode = cms.bool(True)
    process.ecalLaserCorrFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.inconsistentMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.greedyMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.beamScrapingFilter = process.inconsistentMuonPFCandidateFilter.clone(
        ptMin = cms.double(5000.0)
    )
    process.hcalNoiseFilter = process.beamScrapingFilter.clone()
    process.beamHaloFilter = process.beamScrapingFilter.clone()
    process.filtersSeq = cms.Sequence(
        process.primaryVertexFilter *
        process.hcalLaserEventFilter +
        process.EcalDeadCellTriggerPrimitiveFilter +
        process.EcalDeadCellBoundaryEnergyFilter +
        process.eeBadScFilter +
        process.eeNoiseFilter +
        process.ecalLaserCorrFilter +
        process.goodVertices * process.trackingFailureFilter +
        process.inconsistentMuonPFCandidateFilter +
        process.greedyMuonPFCandidateFilter +
        process.noscraping * process.beamScrapingFilter +
        process.HBHENoiseFilter * process.hcalNoiseFilter +
        process.CSCTightHaloFilter * process.beamHaloFilter
    )
    process.metFilters = cms.Path(process.filtersSeq)

    # MET correction ----------------------------------------------------------
    process.load("JetMETCorrections.Type1MET.pfMETCorrections_cff")
    process.pfchsMETcorr.src = cms.InputTag('goodOfflinePrimaryVertices')
    # Type-0
    process.pfMETCHS = process.pfType1CorrectedMet.clone(
        applyType1Corrections = cms.bool(False),
        applyType0Corrections = cms.bool(True)
    )
    # MET Path
    process.metCorrections = cms.Path(
            process.producePFMETCorrections * process.pfMETCHS
    )

    # Require two good muons --------------------------------------------------
    process.goodMuons = cms.EDFilter('CandViewSelector',
        src = cms.InputTag('muons'),
        cut = cms.string("pt > 12.0 & abs(eta) < 8.0 & isGlobalMuon()"),
    )
    process.twoGoodMuons = cms.EDFilter('CandViewCountFilter',
        src = cms.InputTag('goodMuons'),
        minNumber = cms.uint32(2),
    )

    # Configure tuple generation ----------------------------------------------
    process.load('Kappa.Producers.KTuple_cff')
    process.kappatuple = cms.EDAnalyzer('KTuple',
        process.kappaTupleDefaultsBlock,
        outputFile = cms.string("skim_" + datatype + "_no-tagging.root"),
    )

    process.kappatuple.verbose = cms.int32(0)
    process.kappatuple.active = cms.vstring(
        'LV', 'Muons', 'TrackSummary', 'VertexSummary', 'BeamSpot',
        'JetArea', 'PFMET', 'PFJets',
        'FilterSummary',
    )
    if data:
        additional_actives = ['DataMetadata']
    else:
        additional_actives = ['GenMetadata', 'GenParticles']
    for active in additional_actives:
        process.kappatuple.active.append(active)

    # custom whitelist, otherwise the HLT trigger bits are not sufficient!
    process.kappatuple.Metadata.hltWhitelist = cms.vstring(
        # matches 'HLT_Mu17_Mu8_v7' etc.
        "^HLT_(Double)?Mu([0-9]+)_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",
        # matches 'HLT_DoubleMu7_v8' etc.
        "^HLT_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",
    )
    process.kappatuple.Metadata.tauDiscrProcessName = cms.untracked.string("XXXXXXXXX")
    process.kappatuple.GenParticles.genParticles.selectedStatus = cms.int32(31)

    # use the good objects not temporary ones
    process.kappatuple.VertexSummary.whitelist = cms.vstring(".*fflinePrimaryVertices")
    process.kappatuple.VertexSummary.blacklist += cms.vstring(".*QG.*")
    process.kappatuple.LV.whitelist += cms.vstring("recoCaloJets.*")
    process.kappatuple.LV.blacklist += cms.vstring("AK5TrackJets", ".*KT.*")
    process.kappatuple.PFJets.whitelist = cms.vstring("recoPFJets.*kappaSkim")
    process.kappatuple.PFMET.blacklist = cms.vstring("pfType1.*CorrectedMet")
    process.kappatuple.PFJets.blacklist = cms.vstring(".*Tau.*", "recoPFJets_pfJets.*kappaSkim", ".*QG.*", ".*KT.*")
    del process.kappatuple.GenParticles.genStableMuons

    process.pathKappa = cms.Path(
        process.goodMuons * process.twoGoodMuons * process.kappatuple
    )

    # Process schedule --------------------------------------------------------
    process.schedule = cms.Schedule(
        process.metFilters,
        process.pfCHS,
        process.jetsRedo,
        process.pfMuonIso,
        process.metCorrections,
        process.pathKappa,
    )
    if not data:
        process.schedule.insert(0, process.NoNuGenJets)

    return process
def getBaseConfig(globaltag, testfile="", maxevents=0, datatype='data'):
    """Default config for Z+jet skims with Kappa

       This is used in a cmssw config file via:
       import skim_base
       process = skim_base.getBaseConfig('START53_V12', "testfile.root")
    """
    # Set the globalt tag and datatype for testing or by grid-control ---------
    data = (datatype == 'data')
    if data:
        testfile = 'file:/storage/8/dhaitz/testfiles/data_AOD_2012A.root'
        if '@' in globaltag: globaltag = 'FT53_V21A_AN6'
        maxevents = maxevents or 100
    else:
        testfile = 'file:/storage/8/dhaitz/testfiles/rundepMC.root'
        if '@' in globaltag: globaltag = 'START53_V19F'
        maxevents = maxevents or 100
        datatype = 'mc'
    print "GT:", globaltag, "| TYPE:", datatype, "| maxevents:", maxevents, "| file:", testfile

    # Basic process setup -----------------------------------------------------
    process = cms.Process('kappaSkim')
    process.source = cms.Source('PoolSource',
                                fileNames=cms.untracked.vstring(testfile))
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(maxevents))

    # Includes + Global Tag ---------------------------------------------------
    process.load('FWCore.MessageService.MessageLogger_cfi')
    process.load('Configuration.StandardSequences.Services_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.Geometry.GeometryIdeal_cff')
    process.load('Configuration.Geometry.GeometryPilot2_cff')
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi'
    )
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi'
    )
    process.load(
        'TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi'
    )
    process.load('RecoMuon.DetLayers.muonDetLayerGeometry_cfi')
    process.load(
        'Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.GlobalTag.globaltag = globaltag + '::All'

    # Reduce amount of messages -----------------------------------------------
    process.MessageLogger.default = cms.untracked.PSet(
        ERROR=cms.untracked.PSet(limit=cms.untracked.int32(5)))
    process.MessageLogger.cerr.FwkReport.reportEvery = 40

    # Produce PF muon isolation -----------------------------------------------
    from CommonTools.ParticleFlow.Isolation.tools_cfi import isoDepositReplace
    process.pfmuIsoDepositPFCandidates = isoDepositReplace(
        'muons', 'particleFlow')
    process.pfMuonIso = cms.Path(process.pfmuIsoDepositPFCandidates)

    # Create good primary vertices to be used for PF association --------------
    from PhysicsTools.SelectorUtils.pvSelector_cfi import pvSelector
    process.goodOfflinePrimaryVertices = cms.EDFilter(
        "PrimaryVertexObjectFilter",
        filterParams=pvSelector.clone(minNdof=cms.double(4.0),
                                      maxZ=cms.double(24.0)),
        src=cms.InputTag('offlinePrimaryVertices'))
    process.ak5PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.ak7PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.kt4PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')
    process.kt6PFJets.srcPVs = cms.InputTag('goodOfflinePrimaryVertices')

    # CHS Jets with the NoPU sequence -----------------------------------------
    process.load('CommonTools.ParticleFlow.PFBRECO_cff')
    process.pfPileUp.Vertices = cms.InputTag('goodOfflinePrimaryVertices')
    process.pfPileUp.checkClosestZVertex = cms.bool(False)
    process.pfCHS = cms.Path(process.goodOfflinePrimaryVertices *
                             process.PFBRECO)
    process.ak5PFJetsCHS = process.ak5PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))
    process.ak7PFJetsCHS = process.ak7PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))
    process.kt4PFJetsCHS = process.kt4PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))
    process.kt6PFJetsCHS = process.kt6PFJets.clone(
        src=cms.InputTag('pfNoPileUp'))

    # Gen Jets without neutrinos ----------------------------------------------
    if datatype == 'mc':
        process.load('RecoJets.JetProducers.ak5GenJets_cfi')
        process.NoNuGenJets = cms.Path(
            process.genParticlesForJetsNoNu * process.genParticlesForJets *
            process.ak5GenJetsNoNu * process.ak7GenJetsNoNu *
            process.kt4GenJetsNoNu * process.kt4GenJets *
            process.kt6GenJetsNoNu * process.kt6GenJets)

    # Path to Redo all Jets ---------------------------------------------------
    process.jetsRedo = cms.Path(process.ak5PFJets * process.ak7PFJets *
                                process.kt4PFJets * process.kt6PFJets *
                                process.ak5PFJetsCHS * process.ak7PFJetsCHS *
                                process.kt4PFJetsCHS * process.kt6PFJetsCHS)

    # MET filters -------------------------------------------------------------
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    # Create good vertices for the trackingFailure MET filter
    process.goodVertices = cms.EDFilter(
        "VertexSelector",
        filter=cms.bool(False),
        src=cms.InputTag("offlinePrimaryVertices"),
        cut=cms.string(
            "!isFake && ndof > 4 && abs(z) <= 24 && position.rho < 2"),
    )
    # The good primary vertex filter for other MET filters
    process.primaryVertexFilter = cms.EDFilter(
        "VertexSelector",
        filter=cms.bool(True),
        src=cms.InputTag("offlinePrimaryVertices"),
        cut=cms.string(
            "!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2"),
    )
    process.noscraping = cms.EDFilter("FilterOutScraping",
                                      applyfilter=cms.untracked.bool(True),
                                      debugOn=cms.untracked.bool(False),
                                      numtrack=cms.untracked.uint32(10),
                                      thresh=cms.untracked.double(0.25))
    process.load('CommonTools.RecoAlgos.HBHENoiseFilter_cfi')
    process.load('RecoMET.METAnalyzers.CSCHaloFilter_cfi')
    process.load('RecoMET.METFilters.hcalLaserEventFilter_cfi')
    process.hcalLaserEventFilter.vetoByRunEventNumber = cms.untracked.bool(
        False)
    process.hcalLaserEventFilter.vetoByHBHEOccupancy = cms.untracked.bool(True)
    process.load('RecoMET.METFilters.EcalDeadCellTriggerPrimitiveFilter_cfi')
    process.EcalDeadCellTriggerPrimitiveFilter.tpDigiCollection = cms.InputTag(
        "ecalTPSkimNA")
    process.load('RecoMET.METFilters.EcalDeadCellBoundaryEnergyFilter_cfi')
    process.load('RecoMET.METFilters.eeBadScFilter_cfi')
    process.load('RecoMET.METFilters.eeNoiseFilter_cfi')
    process.load('RecoMET.METFilters.ecalLaserCorrFilter_cfi')
    process.load('RecoMET.METFilters.trackingFailureFilter_cfi')
    process.load('RecoMET.METFilters.inconsistentMuonPFCandidateFilter_cfi')
    process.load('RecoMET.METFilters.greedyMuonPFCandidateFilter_cfi')

    process.hcalLaserEventFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellTriggerPrimitiveFilter.taggingMode = cms.bool(True)
    process.EcalDeadCellBoundaryEnergyFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.eeBadScFilter.taggingMode = cms.bool(True)
    process.eeNoiseFilter.taggingMode = cms.bool(True)
    process.ecalLaserCorrFilter.taggingMode = cms.bool(True)
    process.trackingFailureFilter.taggingMode = cms.bool(True)
    process.inconsistentMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.greedyMuonPFCandidateFilter.taggingMode = cms.bool(True)
    process.beamScrapingFilter = process.inconsistentMuonPFCandidateFilter.clone(
        ptMin=cms.double(5000.0))
    process.hcalNoiseFilter = process.beamScrapingFilter.clone()
    process.beamHaloFilter = process.beamScrapingFilter.clone()
    process.filtersSeq = cms.Sequence(
        process.primaryVertexFilter * process.hcalLaserEventFilter +
        process.EcalDeadCellTriggerPrimitiveFilter +
        process.EcalDeadCellBoundaryEnergyFilter + process.eeBadScFilter +
        process.eeNoiseFilter + process.ecalLaserCorrFilter +
        process.goodVertices * process.trackingFailureFilter +
        process.inconsistentMuonPFCandidateFilter +
        process.greedyMuonPFCandidateFilter +
        process.noscraping * process.beamScrapingFilter +
        process.HBHENoiseFilter * process.hcalNoiseFilter +
        process.CSCTightHaloFilter * process.beamHaloFilter)
    process.metFilters = cms.Path(process.filtersSeq)

    # MET correction ----------------------------------------------------------
    process.load("JetMETCorrections.Type1MET.pfMETCorrections_cff")
    process.pfchsMETcorr.src = cms.InputTag('goodOfflinePrimaryVertices')
    # Type-0
    process.pfMETCHS = process.pfType1CorrectedMet.clone(
        applyType1Corrections=cms.bool(False),
        applyType0Corrections=cms.bool(True))
    # MET Path
    process.metCorrections = cms.Path(process.producePFMETCorrections *
                                      process.pfMETCHS)

    # Require two good muons --------------------------------------------------
    process.goodMuons = cms.EDFilter(
        'CandViewSelector',
        src=cms.InputTag('muons'),
        cut=cms.string("pt > 12.0 & abs(eta) < 8.0 & isGlobalMuon()"),
    )
    process.twoGoodMuons = cms.EDFilter(
        'CandViewCountFilter',
        src=cms.InputTag('goodMuons'),
        minNumber=cms.uint32(2),
    )

    # Configure tuple generation ----------------------------------------------
    process.load('Kappa.Producers.KTuple_cff')
    process.kappatuple = cms.EDAnalyzer(
        'KTuple',
        process.kappaTupleDefaultsBlock,
        outputFile=cms.string("skim_" + datatype + "_no-tagging.root"),
    )

    process.kappatuple.verbose = cms.int32(0)
    process.kappatuple.active = cms.vstring(
        'LV',
        'Muons',
        'TrackSummary',
        'VertexSummary',
        'BeamSpot',
        'JetArea',
        'PFMET',
        'PFJets',
        'FilterSummary',
    )
    if data:
        additional_actives = ['DataMetadata']
    else:
        additional_actives = ['GenMetadata', 'GenParticles']
    for active in additional_actives:
        process.kappatuple.active.append(active)

    # custom whitelist, otherwise the HLT trigger bits are not sufficient!
    process.kappatuple.Metadata.hltWhitelist = cms.vstring(
        # matches 'HLT_Mu17_Mu8_v7' etc.
        "^HLT_(Double)?Mu([0-9]+)_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",
        # matches 'HLT_DoubleMu7_v8' etc.
        "^HLT_(Double)?Mu([0-9]+)(_v[[:digit:]]+)?$",
    )
    process.kappatuple.Metadata.tauDiscrProcessName = cms.untracked.string(
        "XXXXXXXXX")
    process.kappatuple.GenParticles.genParticles.selectedStatus = cms.int32(31)

    # use the good objects not temporary ones
    process.kappatuple.VertexSummary.whitelist = cms.vstring(
        ".*fflinePrimaryVertices")
    process.kappatuple.VertexSummary.blacklist += cms.vstring(".*QG.*")
    process.kappatuple.LV.whitelist += cms.vstring("recoCaloJets.*")
    process.kappatuple.LV.blacklist += cms.vstring("AK5TrackJets", ".*KT.*")
    process.kappatuple.PFJets.whitelist = cms.vstring("recoPFJets.*kappaSkim")
    process.kappatuple.PFMET.blacklist = cms.vstring("pfType1.*CorrectedMet")
    process.kappatuple.PFJets.blacklist = cms.vstring(
        ".*Tau.*", "recoPFJets_pfJets.*kappaSkim", ".*QG.*", ".*KT.*")
    del process.kappatuple.GenParticles.genStableMuons

    process.pathKappa = cms.Path(process.goodMuons * process.twoGoodMuons *
                                 process.kappatuple)

    # Process schedule --------------------------------------------------------
    process.schedule = cms.Schedule(
        process.metFilters,
        process.pfCHS,
        process.jetsRedo,
        process.pfMuonIso,
        process.metCorrections,
        process.pathKappa,
    )
    if not data:
        process.schedule.insert(0, process.NoNuGenJets)

    return process
def load_muonPFiso_sequence(
    proc,
    seq_name,
    algo,
    coneR,
    src,
    src_charged_hadron="",
    src_neutral_hadron="",
    src_photon="",
    src_charged_pileup="",
    veto_charged_hadron="Threshold(0.0)",
    veto_neutral_hadron="Threshold(0.5)",
    veto_photon="Threshold(0.5)",
    veto_charged_pileup="Threshold(0.5)",
):

    doCH, doNH, doPh, doPU = False, False, False, False
    if src_charged_hadron != "":
        doCH = True
    if src_neutral_hadron != "":
        doNH = True
    if src_photon != "":
        doPh = True
    if src_charged_pileup != "":
        doPU = True

    iso_seq = cms.Sequence()

    if doCH:
        setattr(proc, "muPFIsoDepositCH" + algo, isoDepositReplace(src, src_charged_hadron))
        iso_seq += getattr(proc, "muPFIsoDepositCH" + algo)

    if doNH:
        setattr(proc, "muPFIsoDepositNH" + algo, isoDepositReplace(src, src_neutral_hadron))
        iso_seq += getattr(proc, "muPFIsoDepositNH" + algo)

    if doPh:
        setattr(proc, "muPFIsoDepositPh" + algo, isoDepositReplace(src, src_photon))
        iso_seq += getattr(proc, "muPFIsoDepositPh" + algo)

    if doPU:
        setattr(proc, "muPFIsoDepositPU" + algo, isoDepositReplace(src, src_charged_pileup))
        iso_seq += getattr(proc, "muPFIsoDepositPU" + algo)

    iso_vals_seq = cms.Sequence()

    if doCH:
        setattr(
            proc,
            "muPFIsoValueCH" + algo,
            cms.EDProducer(
                "CandIsolatorFromDeposits",
                deposits=cms.VPSet(
                    cms.PSet(
                        src=cms.InputTag("muPFIsoDepositCH" + algo),
                        deltaR=cms.double(coneR),
                        weight=cms.string("1"),
                        vetos=cms.vstring("0.0001", veto_charged_hadron),
                        skipDefaultVeto=cms.bool(True),
                        mode=cms.string("sum"),
                    )
                ),
            ),
        )
        iso_vals_seq += getattr(proc, "muPFIsoValueCH" + algo)

    if doNH:
        setattr(
            proc,
            "muPFIsoValueNH" + algo,
            cms.EDProducer(
                "CandIsolatorFromDeposits",
                deposits=cms.VPSet(
                    cms.PSet(
                        src=cms.InputTag("muPFIsoDepositNH" + algo),
                        deltaR=cms.double(coneR),
                        weight=cms.string("1"),
                        vetos=cms.vstring("0.01", veto_neutral_hadron),
                        skipDefaultVeto=cms.bool(True),
                        mode=cms.string("sum"),
                    )
                ),
            ),
        )
        iso_vals_seq += getattr(proc, "muPFIsoValueNH" + algo)

    if doPh:
        setattr(
            proc,
            "muPFIsoValuePh" + algo,
            cms.EDProducer(
                "CandIsolatorFromDeposits",
                deposits=cms.VPSet(
                    cms.PSet(
                        src=cms.InputTag("muPFIsoDepositPh" + algo),
                        deltaR=cms.double(coneR),
                        weight=cms.string("1"),
                        vetos=cms.vstring("0.01", veto_photon),
                        skipDefaultVeto=cms.bool(True),
                        mode=cms.string("sum"),
                    )
                ),
            ),
        )
        iso_vals_seq += getattr(proc, "muPFIsoValuePh" + algo)

    if doPU:
        setattr(
            proc,
            "muPFIsoValuePU" + algo,
            cms.EDProducer(
                "CandIsolatorFromDeposits",
                deposits=cms.VPSet(
                    cms.PSet(
                        src=cms.InputTag("muPFIsoDepositPU" + algo),
                        deltaR=cms.double(coneR),
                        weight=cms.string("1"),
                        vetos=cms.vstring("0.01", veto_charged_pileup),
                        skipDefaultVeto=cms.bool(True),
                        mode=cms.string("sum"),
                    )
                ),
            ),
        )
        iso_vals_seq += getattr(proc, "muPFIsoValuePU" + algo)

    iso_seq *= iso_vals_seq

    setattr(proc, seq_name, iso_seq)