コード例 #1
0
def configureMVAMET(process, jetCollectionPF, isData):
    runMVAMET(process, jetCollectionPF=jetCollectionPF)
    process.MVAMET.srcLeptons = cms.VInputTag("slimmedMuons",
                                              "slimmedElectrons",
                                              "slimmedTaus")
    process.MVAMET.requireOS = cms.bool(False)

    process.icMvaMetSequence = cms.Sequence(
        process.tauDecayProducts + process.egmGsfElectronIDs +
        process.electronMVAValueMapProducer +
        process.electronRegressionValueMapProducer +
        process.photonIDValueMapProducer + process.photonMVAValueMapProducer +
        process.slimmedElectronsTight + process.slimmedMuonsTight +
        process.slimmedTausLoose + process.slimmedTausLooseCleaned +
        process.selectedUpdatedPatJetsUpdatedJECCleaned + process.pfNeutrals +
        process.neutralInJets + process.pfChargedPV + process.pfChs +
        process.pfChargedPU + process.pfMETCands + process.pfTrackMETCands +
        process.pfNoPUMETCands + process.pfPUMETCands +
        process.pfChargedPUMETCands + process.pfNeutralPUMETCands +
        process.pfNeutralPVMETCands + process.pfNeutralUnclusteredMETCands +
        process.pfPUCorrectedMETCands + process.ak4PFCHSL1FastjetCorrector +
        process.ak4PFCHSL2RelativeCorrector +
        process.ak4PFCHSL3AbsoluteCorrector +
        process.ak4PFCHSL1FastL2L3Corrector +
        process.ak4PFCHSResidualCorrector +
        process.ak4PFCHSL1FastL2L3ResidualCorrector + process.ak4JetsForpfMET +
        process.ak4JetsForpfTrackMET + process.ak4JetsForpfPUMET +
        process.ak4JetsForpfChargedPUMET + process.ak4JetsForpfNeutralPUMET +
        process.ak4JetsForpfNeutralPVMET +
        process.ak4JetsForpfNeutralUnclusteredMET +
        process.ak4JetsForpfPUCorrectedMET + process.ak4JetsForpfNoPUMET +
        process.corrpfMET + process.corrpfTrackMET + process.corrpfPUMET +
        process.corrpfChargedPUMET + process.corrpfNeutralPVMET +
        process.corrpfNeutralUnclusteredMET + process.corrpfNeutralPUMET +
        process.corrpfPUCorrectedMET + process.corrpfNoPUMET + process.pfMET +
        process.pfMETT1 + process.patpfMET + process.pfTrackMET +
        process.patpfTrackMET + process.pfTrackMETT1 +
        process.patpfTrackMETT1 + process.pfPUCorrectedMET + process.pfPUMET +
        process.pfChargedPUMET + process.pfNeutralPUMET + process.patpfPUMET +
        process.patpfChargedPUMET + process.patpfNeutralPUMET +
        process.pfNeutralPVMET + process.pfNeutralUnclusteredMET +
        process.patpfNeutralPVMET + process.patpfNeutralUnclusteredMET +
        process.patpfPUCorrectedMET + process.pfPUMETT1 +
        process.patpfPUMETT1 + process.pfChargedPUMETT1 +
        process.pfNeutralPUMETT1 + process.patpfChargedPUMETT1 +
        process.patpfNeutralPUMETT1 + process.pfPUCorrectedMETT1 +
        process.patpfPUCorrectedMETT1 + process.pfNoPUMET +
        process.patpfNoPUMET + process.pfNoPUMETT1 + process.patpfNoPUMETT1 +
        process.patpfMETT1 + process.allDecayProducts + process.tauPFMET +
        process.tauMET + process.tausSignificance + process.MVAMET)

    if not isData:
        process.icMvaMetSequence.remove(process.ak4PFCHSResidualCorrector)
        process.icMvaMetSequence.remove(
            process.ak4PFCHSL1FastL2L3ResidualCorrector)
コード例 #2
0
def mvaMet2(process, isData):

    from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET

    runMVAMET(process, jetCollectionPF="patJetsReapplyJEC")
    process.tauMET.srcPFCands = cms.InputTag("packedPFCandidates")
    process.MVAMET.srcLeptons = cms.VInputTag("slimmedMuons",
                                              "slimmedElectrons",
                                              "slimmedTaus")
    process.MVAMET.requireOS = cms.bool(False)
    process.MVAMET.debug = cms.bool(False)

    process.analysisSequence = cms.Sequence(process.analysisSequence *
                                            process.MVAMET)
コード例 #3
0
if options.reapplyPUJetID:
    from RecoMET.METPUSubtraction.jet_recorrections import reapplyPUJetID
    reapplyPUJetID(process)

if options.reapplyJEC:
    from RecoMET.METPUSubtraction.jet_recorrections import recorrectJets
    recorrectJets(process, options.isData)
    jetCollection = "patJetsReapplyJEC"

if options.reapplyPUJetID:
    getattr(process, jetCollection).userData.userFloats.src += [
        'pileupJetIdUpdated:fullDiscriminant'
    ]

# configure MVA MET
runMVAMET(process, jetCollectionPF=jetCollection)

## set input files
process.source = cms.Source("PoolSource")
process.source.fileNames = cms.untracked.vstring(options.inputFile)
## logger
process.load('FWCore.MessageLogger.MessageLogger_cfi')
process.MessageLogger.cerr.FwkReport.reportEvery = 50

#! Output and Log
process.options = cms.untracked.PSet(wantSummary=cms.untracked.bool(True))
process.options.allowUnscheduled = cms.untracked.bool(True)

process.maxEvents = cms.untracked.PSet(
    input=cms.untracked.int32(options.maxEvents))
コード例 #4
0
if config["USENOHF"]: METS = "slimmedMETsNoHF"

##___________________ MET significance and covariance matrix ______________________##

if config["DOMETSVFIT"]:
    print "Using event pfMET covariance for SVfit"
    process.load("RecoMET.METProducers.METSignificance_cfi")
    process.load("RecoMET.METProducers.METSignificanceParams_cfi")
    process.METSequence = cms.Sequence(process.METSignificance)

if config["DOMVAMET"]:
    from RecoMET.METPUSubtraction.jet_recorrections import recorrectJets
    recorrectJets(process, isData=True)

    from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
    runMVAMET(process, jetCollectionPF="patJetsReapplyJEC")
    process.MVAMET.srcLeptons = cms.VInputTag("slimmedMuons",
                                              "slimmedElectrons",
                                              "slimmedTaus")
    process.MVAMET.requireOS = cms.bool(False)

##___________________ taus ______________________##

TAUS = ""
BOOSTEDTAUS = ""
genAK8 = ""

if config["ADDAK8GENJETS"]:
    genAK8 = 'selectedGenJetsAK8'

if config["DOAK8RECLUSTERING"]:
コード例 #5
0
#    decayStringTauDown="softLeptonsTauDown@+ softLeptonsTauDown@-"
#    checkcharge=True
#process.barellCandTauDown = cms.EDProducer("CandViewShallowCloneCombiner",
#                                    decay = cms.string(decayStringTauDown),
#                                    cut = cms.string(LLCUT),
#                                    checkCharge = cms.bool(checkcharge)
#)

## ----------------------------------------------------------------------
## MVA MET
## ----------------------------------------------------------------------

if USEPAIRMET:
    print "Using pair MET (MVA MET)"
    from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
    runMVAMET(process, jetCollectionPF = "patJetsReapplyJEC")
    process.MVAMET.srcLeptons = cms.VInputTag("slimmedMuons", "slimmedElectrons", "slimmedTaus")
    process.MVAMET.requireOS = cms.bool(False)

    process.MVAMETInputs = cms.Sequence(
        process.pfCHS + process.pfChargedPV + process.pfChargedPU + process.pfNeutrals + process.neutralInJets +
        process.pfMETCands + process.pfTrackMETCands + process.pfNoPUMETCands + process.pfPUCorrectedMETCands + process.pfPUMETCands +
        ##process.pfChargedPUMETCands + process.pfNeutralPUMETCands + process.pfNeutralPVMETCands + process.pfNeutralUnclusteredMETCands +
        process.pfChs
    )
    for met in ["pfMET", "pfTrackMET", "pfNoPUMET", "pfPUCorrectedMET", "pfPUMET", "pfChargedPUMET", "pfNeutralPUMET", "pfNeutralPVMET", "pfNeutralUnclusteredMET"]:
        process.MVAMETInputs += getattr(process, met)
        process.MVAMETInputs += getattr(process, "ak4JetsFor"+met)
        process.MVAMETInputs += getattr(process, "corr"+met)
        process.MVAMETInputs += getattr(process, met+"T1")
        process.MVAMETInputs += getattr(process, "pat"+met)
コード例 #6
0
    process.METSignificance.srcPfJets = cms.InputTag('patJetsReapplyJEC', '',
                                                     processName)
    process.METSignificance.srcMet = cms.InputTag('patpfMETT1', '',
                                                  processName)

    process.JECsequence = cms.Sequence(process.patJetCorrFactorsReapplyJEC *
                                       process.patJetsReapplyJEC)
    JetCollectionName = 'patJetsReapplyJEC'
    #JetCollectionName = cms.InputTag('patJetsReapplyJEC', '', processName)
else:
    process.JECsequence = cms.Sequence()
    JetCollectionName = 'slimmedJets'
    #JetCollectionTag = cms.InputTag('slimmedJets')

from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
runMVAMET(process, jetCollectionPF=JetCollectionName)
process.MVAMET.srcLeptons = cms.VInputTag('slimmedMuons', 'slimmedElectrons',
                                          'slimmedTaus')
process.MVAMET.requireOS = cms.bool(False)

## Load module for Electron MVA ID
## It will append a value maps the miniAOD, that it's accesible throught a well Handle
## Example code here:
##  https://github.com/ikrav/EgammaWork/blob/ntupler_and_VID_demos_7.4.12/ElectronNtupler/plugins/ElectronNtuplerVIDwithMVADemo.cc#L99
## process.load('RecoEgamma.ElectronIdentification.ElectronMVAValueMapProducer_cfi')
##-------------
from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
# turn on VID producer, indicate data format  to be
# DataFormat.AOD or DataFormat.MiniAOD, as appropriate
switchOnVIDElectronIdProducer(
    process, DataFormat.MiniAOD
コード例 #7
0
def configureMVAMET(process, jetCollectionPF, isData):
    runMVAMET(process, jetCollectionPF=jetCollectionPF)
    process.MVAMET.srcLeptons = cms.VInputTag("slimmedMuons", "slimmedElectrons", "slimmedTaus")
    process.MVAMET.requireOS = cms.bool(False)

    process.icMvaMetSequence = cms.Sequence(
        process.tauDecayProducts+
        process.egmGsfElectronIDs+
        process.electronMVAValueMapProducer+
        process.electronRegressionValueMapProducer+
        process.photonIDValueMapProducer+
        process.photonMVAValueMapProducer+
        process.slimmedElectronsTight+
        process.slimmedMuonsTight+
        process.slimmedTausLoose+
        process.slimmedTausLooseCleaned+
        process.selectedUpdatedPatJetsUpdatedJECCleaned+
        process.pfNeutrals+
        process.neutralInJets+
        process.pfChargedPV+
        process.pfChs+
        process.pfChargedPU+
        process.pfMETCands+
        process.pfTrackMETCands+
        process.pfNoPUMETCands+
        process.pfPUMETCands+
        process.pfChargedPUMETCands+
        process.pfNeutralPUMETCands+
        process.pfNeutralPVMETCands+
        process.pfNeutralUnclusteredMETCands+
        process.pfPUCorrectedMETCands+
        process.ak4PFCHSL1FastjetCorrector+
        process.ak4PFCHSL2RelativeCorrector+
        process.ak4PFCHSL3AbsoluteCorrector+
        process.ak4PFCHSL1FastL2L3Corrector+
        process.ak4PFCHSResidualCorrector+
        process.ak4PFCHSL1FastL2L3ResidualCorrector+
        process.ak4JetsForpfMET+
        process.ak4JetsForpfTrackMET+
        process.ak4JetsForpfPUMET+
        process.ak4JetsForpfChargedPUMET+
        process.ak4JetsForpfNeutralPUMET+
        process.ak4JetsForpfNeutralPVMET+
        process.ak4JetsForpfNeutralUnclusteredMET+
        process.ak4JetsForpfPUCorrectedMET+
        process.ak4JetsForpfNoPUMET+
        process.corrpfMET+
        process.corrpfTrackMET+
        process.corrpfPUMET+
        process.corrpfChargedPUMET+
        process.corrpfNeutralPVMET+
        process.corrpfNeutralUnclusteredMET+
        process.corrpfNeutralPUMET+
        process.corrpfPUCorrectedMET+
        process.corrpfNoPUMET+
        process.pfMET+
        process.pfMETT1+
        process.patpfMET+
        process.pfTrackMET+
        process.patpfTrackMET+
        process.pfTrackMETT1+
        process.patpfTrackMETT1+
        process.pfPUCorrectedMET+
        process.pfPUMET+
        process.pfChargedPUMET+
        process.pfNeutralPUMET+
        process.patpfPUMET+
        process.patpfChargedPUMET+
        process.patpfNeutralPUMET+
        process.pfNeutralPVMET+
        process.pfNeutralUnclusteredMET+
        process.patpfNeutralPVMET+
        process.patpfNeutralUnclusteredMET+
        process.patpfPUCorrectedMET+
        process.pfPUMETT1+
        process.patpfPUMETT1+
        process.pfChargedPUMETT1+
        process.pfNeutralPUMETT1+
        process.patpfChargedPUMETT1+
        process.patpfNeutralPUMETT1+
        process.pfPUCorrectedMETT1+
        process.patpfPUCorrectedMETT1+
        process.pfNoPUMET+
        process.patpfNoPUMET+
        process.pfNoPUMETT1+
        process.patpfNoPUMETT1+
        process.patpfMETT1+
        process.allDecayProducts+
        process.tauPFMET+
        process.tauMET+
        process.tausSignificance+
        process.MVAMET
    )

    if not isData:
        process.icMvaMetSequence.remove(process.ak4PFCHSResidualCorrector)
        process.icMvaMetSequence.remove(process.ak4PFCHSL1FastL2L3ResidualCorrector)
コード例 #8
0
        jetCorrFactorsSource = cms.VInputTag(cms.InputTag('patJetCorrFactorsReapplyJEC'))
    )

    process.METSignificance.srcPfJets = cms.InputTag('patJetsReapplyJEC', '', processName)
    process.METSignificance.srcMet = cms.InputTag('patpfMETT1', '', processName)

    process.JECsequence = cms.Sequence(process.patJetCorrFactorsReapplyJEC * process.patJetsReapplyJEC)
    JetCollectionName = 'patJetsReapplyJEC'
    #JetCollectionName = cms.InputTag('patJetsReapplyJEC', '', processName)
else:
   process.JECsequence = cms.Sequence()
   JetCollectionName = 'slimmedJets'
   #JetCollectionTag = cms.InputTag('slimmedJets')

from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
runMVAMET( process, jetCollectionPF = JetCollectionName )
process.MVAMET.srcLeptons  = cms.VInputTag('slimmedMuons', 'slimmedElectrons', 'slimmedTaus')
process.MVAMET.requireOS = cms.bool(False)

## Load module for Electron MVA ID
## It will append a value maps the miniAOD, that it's accesible throught a well Handle
## Example code here:
##  https://github.com/ikrav/EgammaWork/blob/ntupler_and_VID_demos_7.4.12/ElectronNtupler/plugins/ElectronNtuplerVIDwithMVADemo.cc#L99
## process.load('RecoEgamma.ElectronIdentification.ElectronMVAValueMapProducer_cfi')
##-------------
from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
# turn on VID producer, indicate data format  to be
# DataFormat.AOD or DataFormat.MiniAOD, as appropriate
switchOnVIDElectronIdProducer(process, DataFormat.MiniAOD) ##also compute a maps with the electrons that pass an MVA cut
switchOnVIDElectronIdProducer(process, DataFormat.AOD)
コード例 #9
0
def getBaseConfig(
        nickname,
        testfile=False,  # false if not given, string otherwise
        maxevents=-1,
        outputfilename='kappaTuple.root'):

    from Kappa.Skimming.KSkimming_template_cfg import process
    ## ------------------------------------------------------------------------

    # count number of events before doing anything else
    process.p *= process.nEventsTotal
    process.p *= process.nNegEventsTotal

    muons = "slimmedMuons"
    electrons = "slimmedElectrons"

    # new tau id only available for 8_0_20 (I believe) and above
    if tools.is_above_cmssw_version([8, 0, 20]):
        taus = "NewTauIDsEmbedded"
    else:
        taus = "slimmedTaus"
    isSignal = datasetsHelper.isSignal(nickname)

    # produce selected collections and filter events with not even one Lepton
    if options.preselect and not isSignal:
        from Kappa.Skimming.KSkimming_preselection import do_preselection

        do_preselection(process)
        process.p *= process.goodEventFilter

        process.selectedKappaTaus.cut = cms.string('pt > 15 && abs(eta) < 2.5')
        process.selectedKappaMuons.cut = cms.string('pt > 8 && abs(eta) < 2.6')
        process.selectedKappaElectrons.cut = cms.string(
            'pt > 8 && abs(eta) < 2.7')
        muons = "selectedKappaMuons"
        electrons = "selectedKappaElectrons"
        taus = "selectedKappaTaus"
        process.goodEventFilter.minNumber = cms.uint32(2)

    ## ------------------------------------------------------------------------

    # possibility to write out edmDump. Be careful when using unsceduled mode
    process.load("Kappa.Skimming.edmOut")
    process.ep = cms.EndPath()
    #process.ep *= process.edmOut

    ## ------------------------------------------------------------------------

    # Configure Kappa
    if testfile:
        process.source.fileNames = cms.untracked.vstring("%s" % testfile)
    else:
        process.source = cms.Source('PoolSource',
                                    fileNames=cms.untracked.vstring())
    process.maxEvents.input = maxevents
    process.kappaTuple.verbose = cms.int32(0)
    # uncomment the following option to select only running on certain luminosity blocks. Use only for debugging
    # process.source.lumisToProcess  = cms.untracked.VLuminosityBlockRange("1:500-1:1000")
    # process.source.eventsToProcess  = cms.untracked.VEventRange("299368:56418140-299368:56418140")
    process.kappaTuple.profile = cms.bool(True)

    globaltag = datasetsHelper.getGlobalTag(nickname)
    print "Global Tag:", globaltag
    process.GlobalTag.globaltag = globaltag

    ## ------------------------------------------------------------------------

    # Configure Metadata describing the file
    # Important to be evaluated correctly for the following steps
    # data, isEmbedded, miniaod, process.kappaTuple.TreeInfo.parameters = datasetsHelper.getTreeInfo(nickname, globaltag, kappaTag)
    process.kappaTuple.active = cms.vstring('TreeInfo')

    data = datasetsHelper.isData(nickname)
    isEmbedded = datasetsHelper.isEmbedded(nickname)
    print "nickname:", nickname

    #####miniaod = datasetsHelper.isMiniaod(nickname) not used anymore, since everything is MiniAOD now
    process.kappaTuple.TreeInfo.parameters = datasetsHelper.getTreeInfo(
        nickname)

    ## ------------------------------------------------------------------------

    # General configuration
    if tools.is_above_cmssw_version([7, 4]) and not data and not isEmbedded:
        process.kappaTuple.Info.pileUpInfoSource = cms.InputTag(
            "slimmedAddPileupInfo", "", "PAT")
    if not tools.is_above_cmssw_version([9]):
        if isSignal:
            process.kappaTuple.Info.lheSource = cms.InputTag("source")

    # save primary vertex
    process.kappaTuple.active += cms.vstring(
        'VertexSummary')  # save VertexSummary

    process.kappaTuple.VertexSummary.whitelist = cms.vstring(
        'offlineSlimmedPrimaryVertices')  # save VertexSummary
    process.kappaTuple.VertexSummary.rename = cms.vstring(
        'offlineSlimmedPrimaryVertices => goodOfflinePrimaryVerticesSummary')

    if tools.is_above_cmssw_version([7, 6]):
        process.kappaTuple.VertexSummary.goodOfflinePrimaryVerticesSummary = cms.PSet(
            src=cms.InputTag("offlineSlimmedPrimaryVertices"))

    process.kappaTuple.active += cms.vstring('TriggerObjectStandalone')

    # setup BadPFMuonFilter and BadChargedCandidateFilter
    if tools.is_above_cmssw_version(
        [8]) and not tools.is_above_cmssw_version([9]):
        process.load('RecoMET.METFilters.BadPFMuonFilter_cfi')
        process.BadPFMuonFilter.muons = cms.InputTag("slimmedMuons")
        process.BadPFMuonFilter.PFCandidates = cms.InputTag(
            "packedPFCandidates")
        process.BadPFMuonFilter.taggingMode = cms.bool(True)

        process.load('RecoMET.METFilters.BadChargedCandidateFilter_cfi')
        process.BadChargedCandidateFilter.muons = cms.InputTag("slimmedMuons")
        process.BadChargedCandidateFilter.PFCandidates = cms.InputTag(
            "packedPFCandidates")
        process.BadChargedCandidateFilter.taggingMode = cms.bool(True)

        # in reMiniAOD data these filters are already present; only need to run the dedicated module for MC and older data
        if not "03Feb2017" in str(
                process.kappaTuple.TreeInfo.parameters.scenario):
            process.load('RecoMET.METFilters.badGlobalMuonTaggersMiniAOD_cff')
            #switch on tagging mode:
            process.badGlobalMuonTaggerMAOD.taggingMode = cms.bool(True)
            process.cloneGlobalMuonTaggerMAOD.taggingMode = cms.bool(True)
            process.kappaTuple.TriggerObjectStandalone.metfilterbitslist = cms.vstring(
                "BadChargedCandidateFilter", "BadPFMuonFilter",
                "badGlobalMuonTaggerMAOD", "cloneGlobalMuonTaggerMAOD")
        else:
            process.kappaTuple.TriggerObjectStandalone.metfilterbitslist = cms.vstring(
                "BadChargedCandidateFilter", "BadPFMuonFilter")

    process.kappaTuple.Info.hltSource = cms.InputTag("TriggerResults", "",
                                                     "HLT")
    if isEmbedded:
        process.kappaTuple.TriggerObjectStandalone.bits = cms.InputTag(
            "TriggerResults", "", "SIMembedding")
        process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag(
            "TriggerResults", "", "MERGE")
        process.kappaTuple.Info.hltSource = cms.InputTag(
            "TriggerResults", "", "SIMembedding")
    elif data:
        if tools.is_above_cmssw_version([9]):
            process.kappaTuple.Info.hltSource = cms.InputTag(
                "TriggerResults", "", "HLT")
            process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag(
                "TriggerResults", "",
                "RECO")  # take last process used in production for data
        elif "03Feb2017" in str(
                process.kappaTuple.TreeInfo.parameters.scenario):
            process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag(
                "TriggerResults", "", "PAT")
        else:
            process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag(
                "TriggerResults", "", "RECO")
            process.kappaTuple.Info.hltSource = cms.InputTag(
                "TriggerResults", "", "RECO")
    else:
        process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag(
            "TriggerResults", "",
            "PAT")  # take last process used in production for mc

    if not isEmbedded and "Spring16" in str(
            process.kappaTuple.TreeInfo.parameters.campaign):
        # adds for each HLT Trigger wich contains "Tau" or "tau" in the name a Filter object named "l1extratauccolltection"
        process.kappaTuple.TriggerObjectStandalone.l1extratauJetSource = cms.untracked.InputTag(
            "l1extraParticles", "IsoTau", "RECO")

    if not tools.is_above_cmssw_version([9]):
        process.kappaTuple.TriggerObjectStandalone.triggerObjects = cms.PSet(
            src=cms.InputTag("selectedPatTrigger"))
        process.kappaTuple.TriggerObjectStandalone.bits = cms.InputTag(
            "TriggerResults", "", "HLT")

    process.kappaTuple.active += cms.vstring('BeamSpot')
    if tools.is_above_cmssw_version([7, 6]):
        process.kappaTuple.BeamSpot.offlineBeamSpot = cms.PSet(
            src=cms.InputTag("offlineBeamSpot"))

    if not isEmbedded and data:
        process.kappaTuple.active += cms.vstring(
            'DataInfo')  # produce Metadata for data,

    if not isEmbedded and not data:
        process.kappaTuple.active += cms.vstring(
            'GenInfo')  # produce Metadata for MC,
        process.kappaTuple.active += cms.vstring(
            'GenParticles')  # save GenParticles,
        process.kappaTuple.active += cms.vstring(
            'GenTaus')  # save GenParticles,
        process.kappaTuple.GenParticles.genParticles.src = cms.InputTag(
            "prunedGenParticles")
        process.kappaTuple.GenTaus.genTaus.src = cms.InputTag(
            "prunedGenParticles")

    # write out for all processes where available
    process.kappaTuple.Info.lheWeightNames = cms.vstring(".*")

    # save Flag
    process.kappaTuple.Info.isEmbedded = cms.bool(isEmbedded)

    if isEmbedded:
        #process.load('RecoBTag/Configuration/RecoBTag_cff')
        #process.load('RecoJets/JetAssociationProducers/ak5JTA_cff')
        #process.ak5PFJetNewTracksAssociatorAtVertex.tracks = "tmfTracks"
        #process.ak5PFCHSNewJetTracksAssociatorAtVertex.tracks = "tmfTracks"
        #process.p *= process.btagging
        # disable overrideHLTCheck for embedded samples, since it triggers an Kappa error
        process.kappaTuple.Info.overrideHLTCheck = cms.untracked.bool(True)
        process.kappaTuple.active += cms.vstring('GenInfo')
        process.kappaTuple.active += cms.vstring(
            'GenParticles')  # save GenParticles,
        process.kappaTuple.GenParticles.genParticles.src = cms.InputTag(
            "prunedGenParticles")
        process.kappaTuple.active += cms.vstring('GenTaus')
        process.kappaTuple.GenTaus.genTaus.src = cms.InputTag(
            "prunedGenParticles")

        #process.kappaTuple.active += cms.vstring('GenTaus') # save GenParticles,
        #process.kappaTuple.GenParticles.genParticles.src = cms.InputTag("genParticles","","EmbeddedRECO")

    ## ------------------------------------------------------------------------

    # Trigger
    from Kappa.Skimming.hlt_run2 import hltBlacklist, hltWhitelist
    process.kappaTuple.Info.hltWhitelist = hltWhitelist
    process.kappaTuple.Info.hltBlacklist = hltBlacklist

    ## ------------------------------------------------------------------------

    # should not be the default, it blows up the skim a lot
    #process.kappaTuple.active += cms.vstring('packedPFCandidates')
    #process.kappaTuple.packedPFCandidates.packedPFCandidates = cms.PSet(src = cms.InputTag("packedPFCandidates"))

    jetCollectionPuppi = "slimmedJetsPuppi"
    if tools.is_above_cmssw_version([9]):
        jetCollection = "slimmedJets"
    elif tools.is_above_cmssw_version([8]):
        from RecoMET.METPUSubtraction.jet_recorrections import recorrectJets
        #from RecoMET.METPUSubtraction.jet_recorrections import loadLocalSqlite
        #loadLocalSqlite(process, sqliteFilename = "Spring16_25nsV6_DATA.db" if data else "Spring16_25nsV6_MC.db",
        #                         tag = 'JetCorrectorParametersCollection_Spring16_25nsV6_DATA_AK4PF' if data else 'JetCorrectorParametersCollection_Spring16_25nsV6_MC_AK4PF')
        recorrectJets(process, isData=data)
        jetCollection = "patJetsReapplyJEC"
    else:
        from RecoMET.METPUSubtraction.localSqlite import recorrectJets
        recorrectJets(process, isData=data)
        jetCollection = "patJetsReapplyJEC"

    ## ------------------------------------------------------------------------

    # Configure Muons
    process.load("Kappa.Skimming.KMuons_miniAOD_cff")
    process.kappaTuple.Muons.muons.src = cms.InputTag(muons)
    process.kappaTuple.Muons.muons.vertexcollection = cms.InputTag(
        "offlineSlimmedPrimaryVertices")
    process.kappaTuple.Muons.use03ConeForPfIso = cms.bool(True)
    process.kappaTuple.Muons.doPfIsolation = cms.bool(False)
    for src in [
            "muPFIsoDepositCharged", "muPFIsoDepositChargedAll",
            "muPFIsoDepositNeutral", "muPFIsoDepositGamma", "muPFIsoDepositPU"
    ]:
        setattr(getattr(process, src), "src", cms.InputTag(muons))

    process.kappaTuple.active += cms.vstring('Muons')
    process.kappaTuple.Muons.noPropagation = cms.bool(True)
    process.p *= (process.makeKappaMuons)

    ## ------------------------------------------------------------------------

    # Configure Electrons
    process.kappaTuple.active += cms.vstring('Electrons')
    process.load("Kappa.Skimming.KElectrons_miniAOD_cff")
    process.kappaTuple.Electrons.electrons.src = cms.InputTag(
        "slimmedElectrons")
    process.kappaTuple.Electrons.electrons.vertexcollection = cms.InputTag(
        "offlineSlimmedPrimaryVertices")
    process.kappaTuple.Electrons.electrons.rhoIsoInputTag = cms.InputTag(
        "slimmedJets", "rho")
    process.kappaTuple.Electrons.electrons.allConversions = cms.InputTag(
        "reducedEgamma", "reducedConversions")
    from Kappa.Skimming.KElectrons_miniAOD_cff import setupElectrons
    process.kappaTuple.Electrons.srcIds = cms.string("standalone")

    if tools.is_above_cmssw_version([9, 4]):
        process.kappaTuple.Electrons.ids = cms.VInputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-veto",
            "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-loose",
            "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-medium",
            "egmGsfElectronIDs:cutBasedElectronID-Fall17-94X-V1-tight",
            "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp90",
            "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp80",
            "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wpLoose",
            "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp90",
            "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp80",
            "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wpLoose",
            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Values",
            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV1Values",
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto",
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose",
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium",
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight",
            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values"
        )
    elif tools.is_above_cmssw_version([8]):
        process.kappaTuple.Electrons.ids = cms.VInputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto",
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose",
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium",
            "egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight",
            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values"
        )
    else:
        process.kappaTuple.Electrons.ids = cms.VInputTag(
            "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto",
            "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose",
            "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium",
            "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight",
            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values"
        )

    setupElectrons(process, electrons)
    process.p *= (process.makeKappaElectrons)

    ## ------------------------------------------------------------------------

    # new tau id only available for 8_0_20 (I believe) and above
    if tools.is_above_cmssw_version([8, 0, 20]):
        process.load(
            'RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi')
        process.load("Kappa.Skimming.KPatTaus_run2_cff")
        process.p *= (process.makeKappaTaus)

        # embed new id's into new tau collection
        embedID = cms.EDProducer(
            "PATTauIDEmbedder",
            src=cms.InputTag('slimmedTaus'),
            tauIDSources=cms.PSet(
                rerunDiscriminationByIsolationMVAOldDMrun2v1raw=cms.InputTag(
                    'rerunDiscriminationByIsolationMVAOldDMrun2v1raw'),
                rerunDiscriminationByIsolationMVAOldDMrun2v1VLoose=cms.
                InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1VLoose'),
                rerunDiscriminationByIsolationMVAOldDMrun2v1Loose=cms.InputTag(
                    'rerunDiscriminationByIsolationMVAOldDMrun2v1Loose'),
                rerunDiscriminationByIsolationMVAOldDMrun2v1Medium=cms.
                InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1Medium'),
                rerunDiscriminationByIsolationMVAOldDMrun2v1Tight=cms.InputTag(
                    'rerunDiscriminationByIsolationMVAOldDMrun2v1Tight'),
                rerunDiscriminationByIsolationMVAOldDMrun2v1VTight=cms.
                InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1VTight'),
                rerunDiscriminationByIsolationMVAOldDMrun2v1VVTight=cms.
                InputTag(
                    'rerunDiscriminationByIsolationMVAOldDMrun2v1VVTight'),
                rerunDiscriminationByIsolationMVANewDMrun2v1raw=cms.InputTag(
                    'rerunDiscriminationByIsolationMVANewDMrun2v1raw'),
                rerunDiscriminationByIsolationMVANewDMrun2v1VLoose=cms.
                InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1VLoose'),
                rerunDiscriminationByIsolationMVANewDMrun2v1Loose=cms.InputTag(
                    'rerunDiscriminationByIsolationMVANewDMrun2v1Loose'),
                rerunDiscriminationByIsolationMVANewDMrun2v1Medium=cms.
                InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1Medium'),
                rerunDiscriminationByIsolationMVANewDMrun2v1Tight=cms.InputTag(
                    'rerunDiscriminationByIsolationMVANewDMrun2v1Tight'),
                rerunDiscriminationByIsolationMVANewDMrun2v1VTight=cms.
                InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1VTight'),
                rerunDiscriminationByIsolationMVANewDMrun2v1VVTight=cms.
                InputTag(
                    'rerunDiscriminationByIsolationMVANewDMrun2v1VVTight')),
        )
        setattr(process, taus, embedID)
        process.p *= getattr(process, taus)

    process.kappaTuple.active += cms.vstring('PatTaus')
    process.kappaTuple.PatTaus.taus.binaryDiscrBlacklist = cms.vstring()
    process.kappaTuple.PatTaus.taus.src = cms.InputTag(taus)
    process.kappaTuple.PatTaus.taus.floatDiscrBlacklist = cms.vstring()
    # just took everything from https://twiki.cern.ch/twiki/bin/viewauth/CMS/TauIDRecommendation13TeV
    process.kappaTuple.PatTaus.taus.preselectOnDiscriminators = cms.vstring()
    process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist = cms.vstring(
        "decayModeFinding",
        "decayModeFindingNewDMs",
        "byLooseCombinedIsolationDeltaBetaCorr3Hits",
        "byMediumCombinedIsolationDeltaBetaCorr3Hits",
        "byTightCombinedIsolationDeltaBetaCorr3Hits",
        "byCombinedIsolationDeltaBetaCorrRaw3Hits",
        "chargedIsoPtSum",
        "neutralIsoPtSum",
        "neutralIsoPtSumWeight",
        "puCorrPtSum",
        "footprintCorrection",
        "photonPtSumOutsideSignalCone",
        "byIsolationMVArun2v1DBoldDMwLTraw",
        "byVLooseIsolationMVArun2v1DBoldDMwLT",
        "byLooseIsolationMVArun2v1DBoldDMwLT",
        "byMediumIsolationMVArun2v1DBoldDMwLT",
        "byTightIsolationMVArun2v1DBoldDMwLT",
        "byVTightIsolationMVArun2v1DBoldDMwLT",
        "byVVTightIsolationMVArun2v1DBoldDMwLT",
        #"byIsolationMVArun2v1DBnewDMwLTraw",
        #"byVLooseIsolationMVArun2v1DBnewDMwLT",
        #"byLooseIsolationMVArun2v1DBnewDMwLT",
        #"byMediumIsolationMVArun2v1DBnewDMwLT",
        #"byTightIsolationMVArun2v1DBnewDMwLT",
        #"byVTightIsolationMVArun2v1DBnewDMwLT",
        #"byVVTightIsolationMVArun2v1DBnewDMwLT",
        "againstMuonLoose3",
        "againstMuonTight3",
        "againstElectronMVA6category",
        "againstElectronMVA6raw",
        "againstElectronVLooseMVA6",
        "againstElectronLooseMVA6",
        "againstElectronMediumMVA6",
        "againstElectronTightMVA6",
        "againstElectronVTightMVA6"  #,
        #"chargedIsoPtSumdR03",
        #"neutralIsoPtSumdR03",
        #"neutralIsoPtSumWeightdR03",
        #"footprintCorrectiondR03",
        #"photonPtSumOutsideSignalConedR03",
        #"byLooseCombinedIsolationDeltaBetaCorr3HitsdR03",
        #"byMediumCombinedIsolationDeltaBetaCorr3HitsdR03",
        #"byTightCombinedIsolationDeltaBetaCorr3HitsdR03",
        #"byIsolationMVArun2v1DBdR03oldDMwLTraw",
        #"byVLooseIsolationMVArun2v1DBdR03oldDMwLT",
        #"byLooseIsolationMVArun2v1DBdR03oldDMwLT",
        #"byMediumIsolationMVArun2v1DBdR03oldDMwLT",
        #"byTightIsolationMVArun2v1DBdR03oldDMwLT",
        #"byVTightIsolationMVArun2v1DBdR03oldDMwLT",
        #"byVVTightIsolationMVArun2v1DBdR03oldDMwLT",
    )
    if tools.is_above_cmssw_version([8, 0, 20]):
        process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist += cms.vstring(
            "rerunDiscriminationByIsolationMVAOldDMrun2v1raw",
            "rerunDiscriminationByIsolationMVAOldDMrun2v1VLoose",
            "rerunDiscriminationByIsolationMVAOldDMrun2v1Loose",
            "rerunDiscriminationByIsolationMVAOldDMrun2v1Medium",
            "rerunDiscriminationByIsolationMVAOldDMrun2v1Tight",
            "rerunDiscriminationByIsolationMVAOldDMrun2v1VTight",
            "rerunDiscriminationByIsolationMVAOldDMrun2v1VVTight",
            "rerunDiscriminationByIsolationMVANewDMrun2v1raw",
            "rerunDiscriminationByIsolationMVANewDMrun2v1VLoose",
            "rerunDiscriminationByIsolationMVANewDMrun2v1Loose",
            "rerunDiscriminationByIsolationMVANewDMrun2v1Medium",
            "rerunDiscriminationByIsolationMVANewDMrun2v1Tight",
            "rerunDiscriminationByIsolationMVANewDMrun2v1VTight",
            "rerunDiscriminationByIsolationMVANewDMrun2v1VVTight")
    ## now also possible to save all MVA isolation inputs for taus # turn of per default

    process.kappaTuple.PatTaus.taus.extrafloatDiscrlist = cms.untracked.vstring(
        "decayDistX", "decayDistY", "decayDistZ", "decayDistM", "nPhoton",
        "ptWeightedDetaStrip", "ptWeightedDphiStrip", "ptWeightedDrSignal",
        "ptWeightedDrIsolation", "leadingTrackChi2", "eRatio")

    process.kappaTuple.PatTaus.taus.floatDiscrWhitelist = process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist
    process.kappaTuple.PatTaus.verbose = cms.int32(1)

    ## ------------------------------------------------------------------------

    ## Configure Jets
    process.kappaTuple.active += cms.vstring('PileupDensity')
    process.kappaTuple.PileupDensity.whitelist = cms.vstring(
        "fixedGridRhoFastjetAll")
    process.kappaTuple.PileupDensity.rename = cms.vstring(
        "fixedGridRhoFastjetAll => pileupDensity")
    if tools.is_above_cmssw_version([7, 6]):
        process.kappaTuple.PileupDensity.pileupDensity = cms.PSet(
            src=cms.InputTag("fixedGridRhoFastjetAll"))
    process.kappaTuple.active += cms.vstring('PatJets')
    if tools.is_above_cmssw_version([7, 6]):
        process.kappaTuple.PatJets.ak4PF = cms.PSet(
            src=cms.InputTag(jetCollection))
        process.kappaTuple.PatJets.puppiJets = cms.PSet(
            src=cms.InputTag(jetCollectionPuppi))

    ## Standard MET and GenMet from pat::MET
    process.kappaTuple.active += cms.vstring('PatMET')
    process.kappaTuple.PatMET.met = cms.PSet(src=cms.InputTag("slimmedMETs"))
    if tools.is_above_cmssw_version([9]):
        pass
    elif tools.is_above_cmssw_version([8, 0, 14]):
        from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
        runMetCorAndUncFromMiniAOD(process, isData=data)
        process.kappaTuple.PatMET.met = cms.PSet(
            src=cms.InputTag("slimmedMETs", "", "KAPPA"))

    #process.kappaTuple.PatMET.pfmetT1 = cms.PSet(src=cms.InputTag("patpfMETT1"))
    process.kappaTuple.PatMET.metPuppi = cms.PSet(
        src=cms.InputTag("slimmedMETsPuppi"))

    if not tools.is_above_cmssw_version([9]):
        ## Write MVA MET to KMETs
        process.kappaTuple.active += cms.vstring('PatMETs')
        # new MVA MET
        from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
        runMVAMET(process, jetCollectionPF=jetCollection)
        process.kappaTuple.PatMETs.MVAMET = cms.PSet(
            src=cms.InputTag("MVAMET", "MVAMET"))
        process.MVAMET.srcLeptons = cms.VInputTag(
            muons, electrons, taus)  # to produce all possible combinations
        process.MVAMET.requireOS = cms.bool(False)
        if tools.is_above_cmssw_version([8, 0]) and isEmbedded:
            process.MVAMET.srcMETs = cms.VInputTag(
                cms.InputTag("slimmedMETs", "", "MERGE"),
                cms.InputTag("patpfTrackMET"), cms.InputTag("patpfNoPUMET"),
                cms.InputTag("patpfPUCorrectedMET"),
                cms.InputTag("patpfPUMET"),
                cms.InputTag("slimmedMETsPuppi", "", "MERGE"))

    ## ------------------------------------------------------------------------

    ## GenJets
    if not data or isEmbedded:
        process.load('PhysicsTools/JetMCAlgos/TauGenJets_cfi')
        process.load(
            'PhysicsTools/JetMCAlgos/TauGenJetsDecayModeSelectorAllHadrons_cfi'
        )
        process.tauGenJets.GenParticles = cms.InputTag("prunedGenParticles")
        process.p *= (process.tauGenJets +
                      process.tauGenJetsSelectorAllHadrons)
        if isSignal:
            process.kappaTuple.GenJets.whitelist = cms.vstring(
                "tauGenJets", "slimmedGenJets")
        else:
            process.kappaTuple.GenJets.whitelist = cms.vstring("tauGenJets")
        process.kappaTuple.active += cms.vstring('GenJets')
        if tools.is_above_cmssw_version([7, 6]):
            if isSignal:
                process.kappaTuple.GenJets.genJets = cms.PSet(
                    src=cms.InputTag("slimmedGenJets"))
            process.kappaTuple.GenJets.tauGenJets = cms.PSet(
                src=cms.InputTag("tauGenJets"))
            process.kappaTuple.GenJets.tauGenJetsSelectorAllHadrons = cms.PSet(
                src=cms.InputTag("tauGenJetsSelectorAllHadrons"))

    # add repository revisions to TreeInfo
    for repo, rev in tools.get_repository_revisions().iteritems():
        setattr(process.kappaTuple.TreeInfo.parameters, repo, cms.string(rev))

    ## ------------------------------------------------------------------------

    ## Count Events after running all filters
    if not data:
        process.nEventsTotal.isMC = cms.bool(True)
        process.nNegEventsTotal.isMC = cms.bool(True)
        process.nEventsFiltered.isMC = cms.bool(True)
        process.nNegEventsFiltered.isMC = cms.bool(True)

    process.p *= process.nEventsFiltered
    process.p *= process.nNegEventsFiltered
    process.kappaTuple.active += cms.vstring('FilterSummary')

    ## ------------------------------------------------------------------------

    ## if needed adapt output filename
    process.ep *= process.kappaOut
    if outputfilename != '':
        process.kappaTuple.outputFile = cms.string('%s' % outputfilename)

    ## ------------------------------------------------------------------------

    ## Further information saved to Kappa output
    if options.dumpPython:
        f = open("dumpPython.py", "w")
        f.write(process.dumpPython())
        f.close()

    # add python config to TreeInfo
    process.kappaTuple.TreeInfo.parameters.config = cms.string(
        process.dumpPython())

    return process
コード例 #10
0
ファイル: kSkimming_run2_cfg.py プロジェクト: rcaspart/Kappa
def getBaseConfig( globaltag= 'START70_V7::All',
                   testfile=cms.untracked.vstring(""),
                   maxevents=100, ## -1 = all in file
                   nickname = 'SUSYGluGluToHToTauTauM160_RunIIFall15MiniAODv2_PU25nsData2015v1_13TeV_MINIAOD_pythia8',
                   kappaTag = 'Kappa_2_0_0',
				   outputfilename = ''):

	from Kappa.Skimming.KSkimming_template_cfg import process
	## ------------------------------------------------------------------------
	# count number of events before doing anything elese
	process.p *= process.nEventsTotal
	process.p *= process.nNegEventsTotal

	muons = "slimmedMuons"
	electrons = "slimmedElectrons"
	taus = "slimmedTaus"
	# produce selected collections and filter events with not even one Lepton
	if(options.preselect):
		from Kappa.Skimming.KSkimming_preselection import do_preselection
		do_preselection(process)
		process.p *= process.goodEventFilter

		process.selectedKappaTaus.cut = cms.string('pt > 15 && abs(eta) < 2.5') 
		process.selectedKappaMuons.cut = cms.string('pt > 8 && abs(eta) < 2.6')
		process.selectedKappaElectrons.cut = cms.string('pt > 8 && abs(eta) < 2.7')
		process.goodEventFilter.minNumber = cms.uint32(2)
		muons = "selectedKappaMuons"
		electrons = "selectedKappaElectrons"
		taus = "selectedKappaTaus"
	## ------------------------------------------------------------------------
		# possibility to write out edmDump. Be careful when using unsceduled mode
	process.load("Kappa.Skimming.edmOut")
	process.ep = cms.EndPath()
	#process.ep *= process.edmOut

	## ------------------------------------------------------------------------
	# Configure Kappa
	if testfile:
		process.source.fileNames      = testfile
	else:
		process.source 			  = cms.Source('PoolSource', fileNames=cms.untracked.vstring())
	process.maxEvents.input	      = maxevents
	process.kappaTuple.verbose    = cms.int32(0)
	process.kappaTuple.profile    = cms.bool(True)
	if not globaltag.lower() == 'auto' :
		process.GlobalTag.globaltag   = globaltag
		print "GT (overwritten):", process.GlobalTag.globaltag
	## ------------------------------------------------------------------------
	# Configure Metadata describing the file
	# Important to be evaluated correctly for the following steps
	process.kappaTuple.active = cms.vstring('TreeInfo')
	data, isEmbedded, miniaod, process.kappaTuple.TreeInfo.parameters = datasetsHelper.getTreeInfo(nickname, globaltag, kappaTag)

	## ------------------------------------------------------------------------
	# General configuration
	if ((cmssw_version_number.startswith("7_4") and split_cmssw_version[2] >= 14) or (cmssw_version_number.startswith("7_6"))):
		process.kappaTuple.Info.pileUpInfoSource = cms.InputTag("slimmedAddPileupInfo")

	process.kappaTuple.active += cms.vstring('VertexSummary')            # save VertexSummary,

	process.load("Kappa.Skimming.KVertices_cff")
	process.goodOfflinePrimaryVertices.src = cms.InputTag('offlineSlimmedPrimaryVertices')
	process.p *= ( process.makeVertexes )
	process.kappaTuple.VertexSummary.whitelist = cms.vstring('offlineSlimmedPrimaryVertices')  # save VertexSummary,
	process.kappaTuple.VertexSummary.rename = cms.vstring('offlineSlimmedPrimaryVertices => goodOfflinePrimaryVerticesSummary')
	if (cmssw_version_number.startswith("7_6")):
		process.kappaTuple.VertexSummary.goodOfflinePrimaryVerticesSummary = cms.PSet(src=cms.InputTag("offlineSlimmedPrimaryVertices"))

	process.kappaTuple.active += cms.vstring('TriggerObjectStandalone')
	if(data and ("Run2015" in nickname)):
		process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag("TriggerResults", "", "RECO")
	# Adds for each HLT Trigger wich contains "Tau" or "tau" in the name a Filter object named "l1extratauccolltection" 
	process.kappaTuple.TriggerObjectStandalone.l1extratauJetSource = cms.untracked.InputTag("l1extraParticles","IsoTau","RECO")
	
	process.kappaTuple.active += cms.vstring('BeamSpot')                 # save Beamspot,
	if (cmssw_version_number.startswith("7_6")):
		process.kappaTuple.BeamSpot.offlineBeamSpot = cms.PSet(src = cms.InputTag("offlineBeamSpot"))

	if not isEmbedded and data:
			process.kappaTuple.active+= cms.vstring('DataInfo')          # produce Metadata for data,

	if not isEmbedded and not data:
			process.kappaTuple.active+= cms.vstring('GenInfo')           # produce Metadata for MC,
			process.kappaTuple.active+= cms.vstring('GenParticles')      # save GenParticles,
			process.kappaTuple.active+= cms.vstring('GenTaus')           # save GenParticles,

			process.kappaTuple.GenParticles.genParticles.src = cms.InputTag("prunedGenParticles")
			process.kappaTuple.GenTaus.genTaus.src = cms.InputTag("prunedGenParticles")

	if isEmbedded:
		#process.load('RecoBTag/Configuration/RecoBTag_cff')
		#process.load('RecoJets/JetAssociationProducers/ak5JTA_cff')
		#process.ak5PFJetNewTracksAssociatorAtVertex.tracks = "tmfTracks"
		#process.ak5PFCHSNewJetTracksAssociatorAtVertex.tracks = "tmfTracks"
		#process.p *= process.btagging
		# disable overrideHLTCheck for embedded samples, since it triggers an Kappa error
		process.kappaTuple.Info.overrideHLTCheck = cms.untracked.bool(True)
		process.kappaTuple.active += cms.vstring('DataInfo')
		process.kappaTuple.active += cms.vstring('GenParticles') # save GenParticles,
		process.kappaTuple.active += cms.vstring('GenTaus') # save GenParticles,
		process.kappaTuple.GenParticles.genParticles.src = cms.InputTag("genParticles","","EmbeddedRECO")

	## ------------------------------------------------------------------------
	# Trigger
	from Kappa.Skimming.hlt_run2 import hltBlacklist, hltWhitelist
	process.kappaTuple.Info.hltWhitelist = hltWhitelist
	process.kappaTuple.Info.hltBlacklist = hltBlacklist

	## ------------------------------------------------------------------------

	#process.kappaTuple.active += cms.vstring('packedPFCandidates') # save PFCandidates. Not sure for what, because might not be usefull for isolation
	#process.kappaTuple.packedPFCandidates.packedPFCandidates = cms.PSet(src = cms.InputTag("packedPFCandidates"))


	from RecoMET.METPUSubtraction.localSqlite import recorrectJets
	recorrectJets(process, isData=data)
	jetCollection = "patJetsReapplyJEC"


	## ------------------------------------------------------------------------
	# Configure Muons
	process.load("Kappa.Skimming.KMuons_miniAOD_cff")
	process.kappaTuple.Muons.muons.src = cms.InputTag(muons)
	process.kappaTuple.Muons.muons.vertexcollection = cms.InputTag("offlineSlimmedPrimaryVertices")
	process.kappaTuple.Muons.muons.srcMuonIsolationPF = cms.InputTag("")
	process.kappaTuple.Muons.use03ConeForPfIso = cms.bool(True)
	for src in [ "muPFIsoDepositCharged", "muPFIsoDepositChargedAll", "muPFIsoDepositNeutral", "muPFIsoDepositGamma", "muPFIsoDepositPU"]:
		setattr(getattr(process, src), "src", cms.InputTag(muons))

	process.kappaTuple.active += cms.vstring('Muons')
	process.kappaTuple.Muons.noPropagation = cms.bool(True)
	process.p *= ( process.makeKappaMuons )

	## ------------------------------------------------------------------------
	# Configure Electrons
	process.kappaTuple.active += cms.vstring('Electrons')
	process.load("Kappa.Skimming.KElectrons_miniAOD_cff")
	process.kappaTuple.Electrons.electrons.src = cms.InputTag("slimmedElectrons")
	process.kappaTuple.Electrons.electrons.vertexcollection = cms.InputTag("offlineSlimmedPrimaryVertices")
	process.kappaTuple.Electrons.electrons.rhoIsoInputTag = cms.InputTag("slimmedJets", "rho")
	process.kappaTuple.Electrons.electrons.allConversions = cms.InputTag("reducedEgamma", "reducedConversions")
	from Kappa.Skimming.KElectrons_miniAOD_cff import setupElectrons
	process.kappaTuple.Electrons.srcIds = cms.string("standalone");

	process.kappaTuple.Electrons.ids = cms.vstring("egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto",
					"egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose",
					"egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium",
					"egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight",
					"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values")


	setupElectrons(process, electrons)
	process.p *= ( process.makeKappaElectrons )
	## ------------------------------------------------------------------------
	process.kappaTuple.active += cms.vstring('PatTaus')
	process.kappaTuple.PatTaus.taus.binaryDiscrBlacklist = cms.vstring()
	process.kappaTuple.PatTaus.taus.floatDiscrBlacklist = cms.vstring()
	# just took everything from https://twiki.cern.ch/twiki/bin/viewauth/CMS/TauIDRecommendation13TeV
	process.kappaTuple.PatTaus.taus.preselectOnDiscriminators = cms.vstring ()
	process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist = cms.vstring(
	                                                                       "decayModeFinding",
	                                                                       "decayModeFindingNewDMs",
	                                                                       "byLooseCombinedIsolationDeltaBetaCorr3Hits",
	                                                                       "byMediumCombinedIsolationDeltaBetaCorr3Hits",
	                                                                       "byTightCombinedIsolationDeltaBetaCorr3Hits",
	                                                                       "byCombinedIsolationDeltaBetaCorrRaw3Hits",
	                                                                       "chargedIsoPtSum",
	                                                                       "neutralIsoPtSum",
	                                                                       "puCorrPtSum",
	                                                                       "footprintCorrection",
	                                                                       "photonPtSumOutsideSignalCone",
	                                                                       "byIsolationMVArun2v1DBoldDMwLTraw",
	                                                                       "byLooseIsolationMVArun2v1DBoldDMwLT",
	                                                                       "byMediumIsolationMVArun2v1DBoldDMwLT",
	                                                                       "byTightIsolationMVArun2v1DBoldDMwLT",
	                                                                       "byVTightIsolationMVArun2v1DBoldDMwLT",
	                                                                       "byIsolationMVArun2v1DBnewDMwLTraw",
	                                                                       "byLooseIsolationMVArun2v1DBnewDMwLT",
	                                                                       "byMediumIsolationMVArun2v1DBnewDMwLT",
	                                                                       "byTightIsolationMVArun2v1DBnewDMwLT",
	                                                                       "byVTightIsolationMVArun2v1DBnewDMwLT",
	                                                                       "againstMuonLoose3",
	                                                                       "againstMuonTight3",
	                                                                       "againstElectronMVA5category",
	                                                                       "againstElectronMVA5raw",
	                                                                       "againstElectronVLooseMVA5",
	                                                                       "againstElectronLooseMVA5",
	                                                                       "againstElectronMediumMVA5",
	                                                                       "againstElectronTightMVA5",
	                                                                       "againstElectronVTightMVA5",
	                                                                       "againstElectronMVA6category",
	                                                                       "againstElectronMVA6raw",
	                                                                       "againstElectronVLooseMVA6",
	                                                                       "againstElectronLooseMVA6",
	                                                                       "againstElectronMediumMVA6",
	                                                                       "againstElectronTightMVA6",
	                                                                       "againstElectronVTightMVA6",
	                                                                       "byLooseCombinedIsolationDeltaBetaCorr3HitsdR03",
	                                                                       "byMediumCombinedIsolationDeltaBetaCorr3HitsdR03",
	                                                                       "byTightCombinedIsolationDeltaBetaCorr3HitsdR03",
	                                                                       "byLooseIsolationMVArun2v1DBdR03oldDMwLT",
	                                                                       "byMediumIsolationMVArun2v1DBdR03oldDMwLT",
	                                                                       "byTightIsolationMVArun2v1DBdR03oldDMwLT",
	                                                                       "byVTightIsolationMVArun2v1DBdR03oldDMwLT"
	)
	process.kappaTuple.PatTaus.taus.floatDiscrWhitelist = process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist
	## ------------------------------------------------------------------------
	## Configure Jets
	process.kappaTuple.active += cms.vstring('PileupDensity')
	process.kappaTuple.PileupDensity.whitelist = cms.vstring("fixedGridRhoFastjetAll")
	process.kappaTuple.PileupDensity.rename = cms.vstring("fixedGridRhoFastjetAll => pileupDensity")
	if (cmssw_version_number.startswith("7_6")):
		process.kappaTuple.PileupDensity.pileupDensity = cms.PSet(src=cms.InputTag("fixedGridRhoFastjetAll"))
	process.kappaTuple.active += cms.vstring('PatJets')
	if (cmssw_version_number.startswith("7_6")):
		process.kappaTuple.PatJets.ak4PF = cms.PSet(src=cms.InputTag(jetCollection))
	#from Kappa.Skimming.KMET_run2_cff import configureMVAMetForMiniAOD
	#configureMVAMetForMiniAOD(process)

	## Standard MET and GenMet from pat::MET
	process.kappaTuple.active += cms.vstring('PatMET')
	process.kappaTuple.PatMET.met = cms.PSet(src=cms.InputTag("slimmedMETs"))
	process.kappaTuple.PatMET.pfmetT1 = cms.PSet(src=cms.InputTag("patpfMETT1"))
	process.kappaTuple.PatMET.metPuppi = cms.PSet(src=cms.InputTag("slimmedMETsPuppi"))

	## Write MVA MET to KMETs
	process.kappaTuple.active += cms.vstring('PatMETs')
	# new MVA MET
	from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
	runMVAMET( process, jetCollectionPF = jetCollection)
	process.kappaTuple.PatMETs.MVAMET = cms.PSet(src=cms.InputTag("MVAMET", "MVAMET"))
	process.MVAMET.srcLeptons  = cms.VInputTag(muons, electrons, taus) # to produce all possible combinations
	process.MVAMET.requireOS = cms.bool(False)


	## ------------------------------------------------------------------------
	## GenJets 
	if not data:
		process.load('PhysicsTools/JetMCAlgos/TauGenJets_cfi')
		process.load('PhysicsTools/JetMCAlgos/TauGenJetsDecayModeSelectorAllHadrons_cfi')
		process.tauGenJets.GenParticles = cms.InputTag("prunedGenParticles")
		process.p *= ( 
			process.tauGenJets +
			process.tauGenJetsSelectorAllHadrons
			)
		process.kappaTuple.GenJets.whitelist = cms.vstring("tauGenJets")
		process.kappaTuple.active += cms.vstring('GenJets')
		if (cmssw_version_number.startswith("7_6")):
			process.kappaTuple.GenJets.tauGenJets = cms.PSet(src=cms.InputTag("tauGenJets"))
			process.kappaTuple.GenJets.tauGenJetsSelectorAllHadrons = cms.PSet(src=cms.InputTag("tauGenJetsSelectorAllHadrons"))

	## ------------------------------------------------------------------------
	## Further information saved to Kappa output 
	# add python config to TreeInfo
	process.kappaTuple.TreeInfo.parameters.config = cms.string(process.dumpPython())

	# add repository revisions to TreeInfo
	for repo, rev in tools.get_repository_revisions().iteritems():
			setattr(process.kappaTuple.TreeInfo.parameters, repo, cms.string(rev))


	## ------------------------------------------------------------------------
	## Count Events after running all filters 
	if not data:
		process.nEventsTotal.isMC = cms.bool(True)
		process.nNegEventsTotal.isMC = cms.bool(True)
		process.nEventsFiltered.isMC = cms.bool(True)
		process.nNegEventsFiltered.isMC = cms.bool(True)

	process.p *= process.nEventsFiltered
	process.p *= process.nNegEventsFiltered
	process.kappaTuple.active += cms.vstring('FilterSummary')

	## ------------------------------------------------------------------------
	## if needed adapt output filename
	process.p *= process.kappaOut
	if outputfilename != '':
		process.kappaTuple.outputFile = cms.string('%s'%outputfilename)

	return process
コード例 #11
0
def createProcess(
        runOnMC=True,
        channel='tau-mu',
        runSVFit=False,
        p4TransferFunctionFile='CMGTools/SVfitStandalone/data/svFitVisMassAndPtResolutionPDF.root',  # Christians's default. If not touched, it would default to this anyways
        integrateOverP4=False,
        scaleTau=0.):
    '''Set up CMSSW process to run MVA MET and SVFit.

    Args:
        runOnMC (bool): run on MC (access to gen-level products) or data
        channel (string): choose from 'tau-mu' 'di-tau' 'tau-ele' 'mu-ele' 
                          'all-separate' 'all'
        runSVFit (bool): enables the svfit mass reconstruction used for the 
                         H->tau tau analysis.
    '''

    sep_line = '-' * 70

    process = cms.Process("H2TAUTAU")

    # Adding jet collection
    process.load(
        'Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff'
    )
    process.GlobalTag.globaltag = '76X_mcRun2_asymptotic_RunIIFall15DR76_v1'
    if not runOnMC:
        process.GlobalTag.globaltag = '76X_dataRun2_16Dec2015_v0'

    process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')

    runMVAMET(process, jetCollectionPF="patJetsReapplyJEC")

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import patJetCorrFactorsUpdated
    process.patJetCorrFactorsReapplyJEC = patJetCorrFactorsUpdated.clone(
        src=cms.InputTag("slimmedJets"),
        levels=['L1FastJet', 'L2Relative', 'L3Absolute'],
        payload='AK4PFchs'
    )  # Make sure to choose the appropriate levels and payload here!

    if not runOnMC:
        process.patJetCorrFactorsReapplyJEC.levels += ['L2L3Residual']

    from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import patJetsUpdated
    process.patJetsReapplyJEC = patJetsUpdated.clone(
        jetSource=cms.InputTag("slimmedJets"),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag("patJetCorrFactorsReapplyJEC")))

    process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(-1))

    numberOfFilesToProcess = -1
    numberOfFilesToProcess = 1
    debugEventContent = False

    # increase to 1000 before running on the batch, to reduce size of log files
    # on your account
    reportInterval = 100

    print sep_line
    print 'channel', channel
    print 'runSVFit', runSVFit

    # Input & JSON             -------------------------------------------------

    # dataset_user = '******'
    # dataset_name = '/VBF_HToTauTau_M-125_13TeV-powheg-pythia6/Spring14dr-PU20bx25_POSTLS170_V5-v1/AODSIM/SS14/'
    # dataset_files = 'miniAOD-prod_PAT_.*root'

    if runOnMC:
        from CMGTools.H2TauTau.proto.samples.fall15.higgs_susy import HiggsSUSYGG160 as ggh160
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(ggh160.files))
    else:
        # from CMGTools.RootTools.samples.samples_13TeV_DATA2015 import SingleMuon_Run2015D_Promptv4
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(
                'root://eoscms.cern.ch//eos/cms/store/data/Run2015D/SingleMuon/MINIAOD/16Dec2015-v1/10000/FEA1FD2B-B5A8-E511-85F7-0025907B5048.root'
            )  # mu-tau
            #             fileNames = cms.untracked.vstring('root://eoscms.cern.ch//eos/cms/store/data/Run2015D/Tau/MINIAOD/16Dec2015-v1/00000/F8B6DB5A-69B0-E511-96D4-20CF305B0590.root') # tau-tau
        )

    if runOnMC:
        process.genEvtWeightsCounter = cms.EDProducer(
            'GenEvtWeightCounter', verbose=cms.untracked.bool(False))

    if numberOfFilesToProcess > 0:
        process.source.fileNames = process.source.fileNames[:
                                                            numberOfFilesToProcess]

    print 'Run on MC?', runOnMC, process.source.fileNames[0]

    if not runOnMC:
        print 'Running on data, setting up JSON file'
        json = setupJSON(process)

    # Message logger setup.
    process.load("FWCore.MessageLogger.MessageLogger_cfi")
    process.MessageLogger.cerr.FwkReport.reportEvery = reportInterval
    process.options = cms.untracked.PSet(wantSummary=cms.untracked.bool(True))

    process.options = cms.untracked.PSet(
        allowUnscheduled=cms.untracked.bool(True))

    pickEvents = False

    if pickEvents:
        process.pickEvents = cms.EDFilter(
            "PickEvents",
            # the original format to input run/event -based selection is described in :
            # DPGAnalysis/Skims/data/listrunev
            # and kept as default, for historical reasons
            RunEventList=cms.untracked.string(
                "CMGTools/H2TauTau/data/eventList.txt"),

            # run/lumiSection @json -based input of selection can be toggled (but not used in THIS example)
            IsRunLsBased=cms.bool(False),

            # json is not used in this example -> list of LS left empty
            LuminositySectionsBlockRange=cms.untracked.VLuminosityBlockRange(
                ()))

    # process.load('JetMETCorrections.Configuration.DefaultJEC_cff')
    # process.load('JetMETCorrections.Configuration.JetCorrectors_cff')

    # # if '25ns' in process.source.fileNames[0] or 'mcRun2_asymptotic_v2' in process.source.fileNames[0]:
    # print 'Using 25 ns MVA MET training'
    # for mvaMETCfg in [process.mvaMETTauMu, process.mvaMETTauEle, process.mvaMETDiMu, process.mvaMETDiTau, process.mvaMETMuEle]:
    #     mvaMETCfg.inputFileNames = cms.PSet(
    #     U     = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru_7_4_X_miniAOD_25NS_July2015.root'),
    #     DPhi  = cms.FileInPath('RecoMET/METPUSubtraction/data/gbrphi_7_4_X_miniAOD_25NS_July2015.root'),
    #     CovU1 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru1cov_7_4_X_miniAOD_25NS_July2015.root'),
    #     CovU2 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru2cov_7_4_X_miniAOD_25NS_July2015.root')
    # )

    # load the channel paths -------------------------------------------

    process.MVAMET.requireOS = cms.bool(False)

    if channel == 'tau-mu':
        process.load('CMGTools.H2TauTau.objects.tauMuObjectsMVAMET_cff')
        if pickEvents:
            process.tauMuPath.insert(0, process.pickEvents)
        process.mvaMETTauMu = process.MVAMET.clone()
        process.mvaMETTauMu.srcLeptons = cms.VInputTag(
            "tauPreSelectionTauMu", "muonPreSelectionTauMu")
        process.mvaMETTauMu.MVAMETLabel = cms.string('mvaMETTauMu')
        process.cmgTauMu.metCollection = cms.InputTag('mvaMETTauMu',
                                                      'mvaMETTauMu')
        if not runSVFit:
            process.cmgTauMuCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgTauMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgTauMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
        if scaleTau:
            process.cmgTauMuCor.nSigma = scaleTau

    elif channel == 'tau-ele':
        process.load('CMGTools.H2TauTau.objects.tauEleObjectsMVAMET_cff')
        process.mvaMETTauEle = process.MVAMET.clone()
        process.mvaMETTauEle.srcLeptons = cms.VInputTag(
            "tauPreSelectionTauEle", "electronPreSelectionTauEle")
        process.mvaMETTauEle.MVAMETLabel = cms.string('mvaMETTauEle')
        process.cmgTauEle.metCollection = cms.InputTag('mvaMETTauEle',
                                                       'mvaMETTauEle')
        if not runSVFit:
            process.cmgTauEleCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgTauEleCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgTauEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    elif channel == 'mu-ele':
        process.load('CMGTools.H2TauTau.objects.muEleObjectsMVAMET_cff')
        process.mvaMETMuEle = process.MVAMET.clone()
        process.mvaMETMuEle.srcLeptons = cms.VInputTag(
            "muonPreSelectionMuEle", "electronPreSelectionMuEle")
        process.mvaMETMuEle.MVAMETLabel = cms.string('mvaMETMuEle')
        process.cmgMuEle.metCollection = cms.InputTag('mvaMETMuEle',
                                                      'mvaMETMuEle')
        if not runSVFit:
            process.cmgMuEleCorSVFitPreSel.SVFitVersion = 0
        else:
            process.cmgMuEleCorSVFitPreSel.SVFitVersion = 2

    # elif channel == 'mu-ele':
    #     process.MVAMET.srcLeptons = cms.VInputTag("electronPreSelectionMuEle", "muonPreSelectionMuEle")
    #     # process.muEleSequence.insert(4, process.MVAMET)
    elif channel == 'di-tau':
        process.load('CMGTools.H2TauTau.objects.diTauObjectsMVAMET_cff')
        process.mvaMETDiTau = process.MVAMET.clone()
        process.mvaMETDiTau.srcLeptons = cms.VInputTag("tauPreSelectionDiTau",
                                                       "tauPreSelectionDiTau")
        process.mvaMETDiTau.MVAMETLabel = cms.string('mvaMETDiTau')
        process.cmgDiTau.metCollection = cms.InputTag('mvaMETDiTau',
                                                      'mvaMETDiTau')
        if not runSVFit:
            process.cmgDiTauCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgDiTauCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgDiTauCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    # elif channel == 'di-mu':
    #     process.MVAMET.srcLeptons = cms.VInputTag("muonPreSelectionDiMu", "muonPreSelectionDiMu")
    #     # process.diMuSequence.insert(2, process.MVAMET)

    # OUTPUT definition ----------------------------------------------------------
    process.outpath = cms.EndPath()

    if runOnMC:
        #        pass
        process.genEvtWeightsCounterPath = cms.Path(
            process.genEvtWeightsCounter)
#        process.schedule.insert(0, process.genEvtWeightsCounterPath)

# Enable printouts like this:
# process.cmgTauMuCorSVFitPreSel.verbose = True

    oneFile = (channel == 'all')

    if channel == 'tau-mu' or 'all' in channel:
        addTauMuOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)
    if channel == 'tau-ele' or 'all' in channel:
        addTauEleOutput(process,
                        debugEventContent,
                        addPreSel=False,
                        oneFile=oneFile)
    if channel == 'mu-ele' or 'all' in channel:
        addMuEleOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)
    if channel == 'di-mu' or 'all' in channel:
        addDiMuOutput(process,
                      debugEventContent,
                      addPreSel=False,
                      oneFile=oneFile)
    if channel == 'di-tau' or 'all' in channel:
        addDiTauOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)

    if not runOnMC:
        if channel == 'tau-mu' or 'all' in channel:
            process.tauMuSequence.remove(process.cmgTauMuCor)
            process.cmgTauMuTauPtSel.src = 'cmgTauMu'
        if channel == 'tau-ele' or 'all' in channel:
            process.tauEleSequence.remove(process.cmgTauEleCor)
            process.cmgTauEleTauPtSel.src = 'cmgTauEle'
        if channel == 'di-tau' or 'all' in channel:
            process.diTauSequence.remove(process.cmgDiTauCor)
            process.cmgDiTauTauPtSel.src = 'cmgDiTau'

    # if runSVFit:
    #     process.cmgTauMuCorSVFitPreSel.SVFitVersion = 2
    # process.cmgTauEleCorSVFitPreSel.SVFitVersion = 2
    # process.cmgDiTauCorSVFitPreSel.SVFitVersion = 2
    # process.cmgMuEleCorSVFitPreSel.SVFitVersion = 2
    # process.cmgDiMuCorSVFitPreSel.SVFitVersion = 2

    # else:
    #     process.cmgTauMuCorSVFitPreSel.SVFitVersion = 0
    # process.cmgTauEleCorSVFitPreSel.SVFitVersion = 0
    # process.cmgDiTauCorSVFitPreSel.SVFitVersion = 0
    # process.cmgMuEleCorSVFitPreSel.SVFitVersion = 0
    # process.cmgDiMuCorSVFitPreSel.SVFitVersion = 0

    # if integrateOverP4:
    #     process.cmgTauMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgTauEleCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgDiTauCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgMuEleCorSVFitPreSel.integrateOverP4 = integrateOverP4

    # if p4TransferFunctionFile:
    #     process.cmgTauMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgTauEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgDiTauCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgMuEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    print sep_line
    print 'INPUT:'
    print sep_line
    print process.source.fileNames
    print
    if not runOnMC:
        print 'json:', json
    print
    print sep_line
    print 'PROCESSING'
    print sep_line
    print 'runOnMC:', runOnMC
    print

    # from FWCore.ParameterSet.Utilities import convertToUnscheduled
    # convertToUnscheduled(process)

    return process
コード例 #12
0
def createProcess(
        runOnMC=True,
        channel='tau-mu',
        runSVFit=False,
        runMVAETmiss=False,
        # Christians's default. If not touched, it would default to this anyways
        p4TransferFunctionFile='CMGTools/SVfitStandalone/data/svFitVisMassAndPtResolutionPDF.root',
        integrateOverP4=False,
        scaleTau=0.,
        recorrectJets=True,
        verbose=False):
    '''Set up CMSSW process to run MVA MET and SVFit.

    Args:
        runOnMC (bool): run on MC (access to gen-level products) or data
        channel (string): choose from 'tau-mu' 'di-tau' 'tau-ele' 'mu-ele' 
                          'all-separate' 'all'
        runSVFit (bool): enables the svfit mass reconstruction used for the 
                         H->tau tau analysis.
    '''

    sep_line = '-' * 70

    process = cms.Process("H2TAUTAU")

    addNewTauID(process)
    addMETFilters(process)

    if recorrectJets:
        # Adding jet collection
        process.load(
            'Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff'
        )

        # Global tags from https://twiki.cern.ch/twiki/bin/view/CMS/JECDataMC 07 Feb 2017
        process.GlobalTag.globaltag = '94X_mc2017_realistic_v14'
        if not runOnMC:
            process.GlobalTag.globaltag = '94X_mc2017_realistic_v14'

        process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
        process.load('Configuration.StandardSequences.MagneticField_38T_cff')

        from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJetCorrFactors
        process.patJetCorrFactorsReapplyJEC = updatedPatJetCorrFactors.clone(
            src=cms.InputTag("slimmedJets"),
            levels=['L1FastJet', 'L2Relative', 'L3Absolute'],
            payload='AK4PFchs'
        )  # Make sure to choose the appropriate levels and payload here!

        if not runOnMC:
            process.patJetCorrFactorsReapplyJEC.levels += ['L2L3Residual']

        from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import updatedPatJets
        process.patJetsReapplyJEC = updatedPatJets.clone(
            jetSource=cms.InputTag("slimmedJets"),
            jetCorrFactorsSource=cms.VInputTag(
                cms.InputTag("patJetCorrFactorsReapplyJEC")))

    if runMVAETmiss:
        if recorrectJets:
            runMVAMET(process, jetCollectionPF="patJetsReapplyJEC")
        else:
            runMVAMET(process)

    # We always need this
    runMetCorAndUncFromMiniAOD(process, isData=not runOnMC)

    process.selectedVerticesForPFMEtCorrType0.src = cms.InputTag(
        "offlineSlimmedPrimaryVertices")

    # loadLocalSqlite(process, 'Spring16_25nsV3_DATA.db') #os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/jec/'

    process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(-1))

    numberOfFilesToProcess = -1
    numberOfFilesToProcess = 1
    debugEventContent = False

    # increase to 1000 before running on the batch, to reduce size of log files
    # on your account
    reportInterval = 100

    print sep_line
    print 'channel', channel
    print 'runSVFit', runSVFit

    # Input & JSON             -------------------------------------------------

    # dataset_user = '******'
    # dataset_name = '/VBF_HToTauTau_M-125_13TeV-powheg-pythia6/Spring14dr-PU20bx25_POSTLS170_V5-v1/AODSIM/SS14/'
    # dataset_files = 'miniAOD-prod_PAT_.*root'

    if runOnMC:
        from CMGTools.H2TauTau.proto.samples.summer16.higgs_susy import HiggsSUSYGG160 as ggh160
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(ggh160.files))
    else:
        # from CMGTools.RootTools.samples.samples_13TeV_DATA2015 import SingleMuon_Run2015D_Promptv4
        from CMGTools.H2TauTau.proto.samples.summer16.htt_common import data_single_muon
        process.source = cms.Source(
            "PoolSource",
            noEventSort=cms.untracked.bool(True),
            duplicateCheckMode=cms.untracked.string("noDuplicateCheck"),
            fileNames=cms.untracked.vstring(
                data_single_muon[1].files)  # mu-tau
        )

    if runOnMC:
        process.genEvtWeightsCounter = cms.EDProducer(
            'GenEvtWeightCounter', verbose=cms.untracked.bool(False))

    if numberOfFilesToProcess > 0:
        process.source.fileNames = process.source.fileNames[:
                                                            numberOfFilesToProcess]

    print 'Run on MC?', runOnMC  #, process.source.fileNames[0]

    # if not runOnMC:
    #     from CMGTools.H2TauTau.proto.samples.spring16.htt_common import json
    #     # print 'Running on data, setting up JSON file'
    #     # json = setupJSON(process)

    # Message logger setup.
    process.load("FWCore.MessageLogger.MessageLogger_cfi")
    process.MessageLogger.cerr.FwkReport.reportEvery = reportInterval
    process.MessageLogger.suppressWarning = cms.untracked.vstring('cmgDiTau')
    process.options = cms.untracked.PSet(wantSummary=cms.untracked.bool(True))

    process.options = cms.untracked.PSet(
        allowUnscheduled=cms.untracked.bool(True))

    pickEvents = False

    if pickEvents:
        process.pickEvents = cms.EDFilter(
            "PickEvents",
            # the original format to input run/event -based selection is described in :
            # DPGAnalysis/Skims/data/listrunev
            # and kept as default, for historical reasons
            RunEventList=cms.untracked.string(
                "CMGTools/H2TauTau/data/eventList.txt"),

            # run/lumiSection @json -based input of selection can be toggled (but not used in THIS example)
            IsRunLsBased=cms.bool(False),

            # json is not used in this example -> list of LS left empty
            LuminositySectionsBlockRange=cms.untracked.VLuminosityBlockRange(
                ()))

    # process.load('JetMETCorrections.Configuration.DefaultJEC_cff')
    # process.load('JetMETCorrections.Configuration.JetCorrectors_cff')

    # # if '25ns' in process.source.fileNames[0] or 'mcRun2_asymptotic_v2' in process.source.fileNames[0]:
    # print 'Using 25 ns MVA MET training'
    # for mvaMETCfg in [process.mvaMETTauMu, process.mvaMETTauEle, process.mvaMETDiMu, process.mvaMETDiTau, process.mvaMETMuEle]:
    #     mvaMETCfg.inputFileNames = cms.PSet(
    #     U     = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru_7_4_X_miniAOD_25NS_July2015.root'),
    #     DPhi  = cms.FileInPath('RecoMET/METPUSubtraction/data/gbrphi_7_4_X_miniAOD_25NS_July2015.root'),
    #     CovU1 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru1cov_7_4_X_miniAOD_25NS_July2015.root'),
    #     CovU2 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru2cov_7_4_X_miniAOD_25NS_July2015.root')
    # )

    # load the channel paths -------------------------------------------

    if runMVAETmiss:
        process.MVAMET.requireOS = cms.bool(False)
        process.MVAMET.srcMETs = cms.VInputTag(
            cms.InputTag("slimmedMETs", "", "PAT" if runOnMC else "RECO"),
            cms.InputTag("patpfMET"), cms.InputTag("patpfMETT1"),
            cms.InputTag("patpfTrackMET"), cms.InputTag("patpfNoPUMET"),
            cms.InputTag("patpfPUCorrectedMET"), cms.InputTag("patpfPUMET"),
            cms.InputTag("slimmedMETsPuppi", "", "PAT" if runOnMC else "RECO"))

    if channel == 'tau-mu':
        process.load('CMGTools.H2TauTau.objects.tauMuObjectsMVAMET_cff')
        if pickEvents:
            process.tauMuPath.insert(0, process.pickEvents)

        if runMVAETmiss:
            process.mvaMETTauMu = process.MVAMET.clone()
            process.mvaMETTauMu.srcLeptons = cms.VInputTag(
                "tauPreSelectionTauMu", "muonPreSelectionTauMu")
            process.mvaMETTauMu.MVAMETLabel = cms.string('mvaMETTauMu')
            process.cmgTauMu.metCollection = cms.InputTag(
                'mvaMETTauMu', 'mvaMETTauMu')
        else:
            process.cmgTauMu.metCollection = cms.InputTag('slimmedMETs')
        if not runSVFit:
            process.cmgTauMuCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgTauMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgTauMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
        if scaleTau:
            process.cmgTauMuCor.nSigma = scaleTau

    elif channel == 'tau-ele':
        process.load('CMGTools.H2TauTau.objects.tauEleObjectsMVAMET_cff')
        if runMVAETmiss:
            process.mvaMETTauEle = process.MVAMET.clone()
            process.mvaMETTauEle.srcLeptons = cms.VInputTag(
                "tauPreSelectionTauEle", "electronPreSelectionTauEle")
            process.mvaMETTauEle.MVAMETLabel = cms.string('mvaMETTauEle')
            process.cmgTauEle.metCollection = cms.InputTag(
                'mvaMETTauEle', 'mvaMETTauEle')
        else:
            process.cmgTauEle.metCollection = cms.InputTag('slimmedMETs')
        if not runSVFit:
            process.cmgTauEleCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgTauEleCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgTauEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    elif channel == 'mu-ele':
        process.load('CMGTools.H2TauTau.objects.muEleObjectsMVAMET_cff')
        if runMVAETmiss:
            process.mvaMETMuEle = process.MVAMET.clone()
            process.mvaMETMuEle.srcLeptons = cms.VInputTag(
                "muonPreSelectionMuEle", "electronPreSelectionMuEle")
            process.mvaMETMuEle.MVAMETLabel = cms.string('mvaMETMuEle')
            process.cmgMuEle.metCollection = cms.InputTag(
                'mvaMETMuEle', 'mvaMETMuEle')
        else:
            process.cmgMuEle.metCollection = cms.InputTag('slimmedMETs')
        if not runSVFit:
            process.cmgMuEleCorSVFitPreSel.SVFitVersion = 0
        else:
            process.cmgMuEleCorSVFitPreSel.SVFitVersion = 2

    # elif channel == 'mu-ele':
    #     process.MVAMET.srcLeptons = cms.VInputTag("electronPreSelectionMuEle", "muonPreSelectionMuEle")
    #     # process.muEleSequence.insert(4, process.MVAMET)
    elif channel == 'di-tau':
        process.load('CMGTools.H2TauTau.objects.diTauObjectsMVAMET_cff')
        if runMVAETmiss:
            process.mvaMETDiTau = process.MVAMET.clone()
            process.mvaMETDiTau.srcLeptons = cms.VInputTag(
                "tauPreSelectionDiTau", "tauPreSelectionDiTau")
            process.mvaMETDiTau.MVAMETLabel = cms.string('mvaMETDiTau')
            process.cmgDiTau.metCollection = cms.InputTag(
                'mvaMETDiTau', 'mvaMETDiTau')
        else:
            process.cmgDiTau.metCollection = cms.InputTag('slimmedMETs')
        if not runSVFit:
            process.cmgDiTauCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgDiTauCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgDiTauCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    elif channel == 'di-mu':
        process.load('CMGTools.H2TauTau.objects.diMuObjectsMVAMET_cff')
        if runMVAETmiss:
            process.mvaMETDiMu = process.MVAMET.clone()
            process.mvaMETDiMu.srcLeptons = cms.VInputTag(
                "muonPreSelectionDiMu", "muonPreSelectionDiMu")
            process.mvaMETDiMu.MVAMETLabel = cms.string('mvaMETDiMu')
            process.cmgDiMu.metCollection = cms.InputTag(
                'mvaMETDiMu', 'mvaMETDiMu')
        else:
            process.cmgDiMu.metCollection = cms.InputTag('slimmedMETs')
        if not runSVFit:
            process.cmgDiMuCorSVFitPreSel.SVFitVersion = 0
        if integrateOverP4:
            process.cmgDiMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
        if p4TransferFunctionFile:
            process.cmgDiMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    # OUTPUT definition ----------------------------------------------------------
    process.outpath = cms.EndPath()

    if runOnMC:
        #        pass
        process.genEvtWeightsCounterPath = cms.Path(
            process.genEvtWeightsCounter)


#        process.schedule.insert(0, process.genEvtWeightsCounterPath)

# Enable printouts like this:
# process.cmgTauMuCorSVFitPreSel.verbose = True

    oneFile = (channel == 'all')

    if channel == 'tau-mu' or 'all' in channel:
        addTauMuOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)
    if channel == 'tau-ele' or 'all' in channel:
        addTauEleOutput(process,
                        debugEventContent,
                        addPreSel=False,
                        oneFile=oneFile)
    if channel == 'mu-ele' or 'all' in channel:
        addMuEleOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)
    if channel == 'di-mu' or 'all' in channel:
        addDiMuOutput(process,
                      debugEventContent,
                      addPreSel=False,
                      oneFile=oneFile)
    if channel == 'di-tau' or 'all' in channel:
        addDiTauOutput(process,
                       debugEventContent,
                       addPreSel=False,
                       oneFile=oneFile)

    if not runOnMC:
        if channel == 'tau-mu' or 'all' in channel:
            process.tauMuSequence.remove(process.cmgTauMuCor)
            process.cmgTauMuTauPtSel.src = 'cmgTauMu'
        if channel == 'tau-ele' or 'all' in channel:
            process.tauEleSequence.remove(process.cmgTauEleCor)
            process.cmgTauEleTauPtSel.src = 'cmgTauEle'
        if channel == 'di-tau' or 'all' in channel:
            process.diTauSequence.remove(process.cmgDiTauCor)
            process.cmgDiTauTauPtSel.src = 'cmgDiTau'

    # if runSVFit:
    #     process.cmgTauMuCorSVFitPreSel.SVFitVersion = 2
    # process.cmgTauEleCorSVFitPreSel.SVFitVersion = 2
    # process.cmgDiTauCorSVFitPreSel.SVFitVersion = 2
    # process.cmgMuEleCorSVFitPreSel.SVFitVersion = 2
    # process.cmgDiMuCorSVFitPreSel.SVFitVersion = 2

    # else:
    #     process.cmgTauMuCorSVFitPreSel.SVFitVersion = 0
    # process.cmgTauEleCorSVFitPreSel.SVFitVersion = 0
    # process.cmgDiTauCorSVFitPreSel.SVFitVersion = 0
    # process.cmgMuEleCorSVFitPreSel.SVFitVersion = 0
    # process.cmgDiMuCorSVFitPreSel.SVFitVersion = 0

    # if integrateOverP4:
    #     process.cmgTauMuCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgTauEleCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgDiTauCorSVFitPreSel.integrateOverP4 = integrateOverP4
    #     process.cmgMuEleCorSVFitPreSel.integrateOverP4 = integrateOverP4

    # if p4TransferFunctionFile:
    #     process.cmgTauMuCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgTauEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgDiTauCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile
    #     process.cmgMuEleCorSVFitPreSel.p4TransferFunctionFile = p4TransferFunctionFile

    if verbose:
        print sep_line
        print 'INPUT:'
        print sep_line
        print process.source.fileNames
        print
        # if not runOnMC:
        #     print 'json:', json
        print
        print sep_line
        print 'PROCESSING'
        print sep_line
        print 'runOnMC:', runOnMC
        print

    return process
コード例 #13
0
    loadLocalSqlite(process, options.localSqlite) 

if options.reapplyPUJetID:
    from RecoMET.METPUSubtraction.jet_recorrections import reapplyPUJetID
    reapplyPUJetID(process)

if options.reapplyJEC:
    from RecoMET.METPUSubtraction.jet_recorrections import recorrectJets
    recorrectJets(process, options.isData)
    jetCollection = "patJetsReapplyJEC"

if options.reapplyPUJetID:
    getattr(process, jetCollection).userData.userFloats.src += ['pileupJetIdUpdated:fullDiscriminant']

# configure MVA MET
runMVAMET( process, jetCollectionPF = jetCollection)

## set input files
process.source = cms.Source("PoolSource")
process.source.fileNames = cms.untracked.vstring(options.inputFile)
## logger
process.load('FWCore.MessageLogger.MessageLogger_cfi')
process.MessageLogger.cerr.FwkReport.reportEvery = 50

#! Output and Log                                                                                                                                                            
process.options   = cms.untracked.PSet(wantSummary = cms.untracked.bool(True))
process.options.allowUnscheduled = cms.untracked.bool(True)

process.maxEvents = cms.untracked.PSet(
    input = cms.untracked.int32(options.maxEvents)
) 
コード例 #14
0
def getBaseConfig( globaltag= 'START70_V7::All',
	testfile=cms.untracked.vstring(""),
	maxevents=50,
	nickname = 'SUSYGluGluToHToTauTauM160_RunIIFall15MiniAODv2_PU25nsData2015v1_13TeV_MINIAOD_pythia8',
	kappaTag = 'Kappa_2_0_0',
	outputfilename = ''):

	from Kappa.Skimming.KSkimming_template_cfg import process
	## ------------------------------------------------------------------------

	# count number of events before doing anything else
	process.p *= process.nEventsTotal
	process.p *= process.nNegEventsTotal

	muons = "slimmedMuons"
	electrons = "slimmedElectrons"

	# new tau id only available for 8_0_20 (I believe) and above
	if tools.is_above_cmssw_version([8,0,20]):
		taus = "NewTauIDsEmbedded"
	else:
		taus = "slimmedTaus"
	isSignal = datasetsHelper.isSignal(nickname)

	# produce selected collections and filter events with not even one Lepton
	if options.preselect and not isSignal:
		from Kappa.Skimming.KSkimming_preselection import do_preselection

		do_preselection(process)
		process.p *= process.goodEventFilter

		process.selectedKappaTaus.cut = cms.string('pt > 15 && abs(eta) < 2.5')
		process.selectedKappaMuons.cut = cms.string('pt > 8 && abs(eta) < 2.6')
		process.selectedKappaElectrons.cut = cms.string('pt > 8 && abs(eta) < 2.7')
		muons = "selectedKappaMuons"
		electrons = "selectedKappaElectrons"
		taus = "selectedKappaTaus"
		process.goodEventFilter.minNumber = cms.uint32(2)

	## ------------------------------------------------------------------------

	# possibility to write out edmDump. Be careful when using unsceduled mode
	process.load("Kappa.Skimming.edmOut")
	process.ep = cms.EndPath()
	#process.ep *= process.edmOut

	## ------------------------------------------------------------------------

	# Configure Kappa
	if testfile:
		process.source            = cms.Source('PoolSource', fileNames=cms.untracked.vstring(testfile))
		# uncomment the following option to select only running on certain luminosity blocks. Use only for debugging
		# in this example 1 - is run and after semicolon - the LumiSection
		# process.source.lumisToProcess  = cms.untracked.VLuminosityBlockRange("1:62090-1:63091")
		#process.source.eventsToProcess = cms.untracked.VEventRange('1:917:1719279', '1:1022:1915188')
		#process.source.skipEvents = cms.untracked.uint32(539)
	else:
		process.source 			  = cms.Source('PoolSource', fileNames=cms.untracked.vstring())
	process.maxEvents.input	      = maxevents
	process.kappaTuple.verbose    = cms.int32(0)

	process.kappaTuple.profile    = cms.bool(True)
	if not globaltag.lower() == 'auto' :
		process.GlobalTag.globaltag   = globaltag

		# Auto alternative
		#from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag
		#process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '')

		print "GT (overwritten):", process.GlobalTag.globaltag
	## ------------------------------------------------------------------------

	# Configure Metadata describing the file
	# Important to be evaluated correctly for the following steps
	# data, isEmbedded, miniaod, process.kappaTuple.TreeInfo.parameters = datasetsHelper.getTreeInfo(nickname, globaltag, kappaTag)
	process.kappaTuple.active = cms.vstring('TreeInfo')

	data = datasetsHelper.isData(nickname)
	isEmbedded = datasetsHelper.isEmbedded(nickname)
	print "nicknane:", nickname

	#####miniaod = datasetsHelper.isMiniaod(nickname) not used anymore, since everything is MiniAOD now
	process.kappaTuple.TreeInfo.parameters= datasetsHelper.getTreeInfo(nickname, globaltag, kappaTag)

	## ------------------------------------------------------------------------

	# General configuration
	if tools.is_above_cmssw_version([7,4]) and not data and not isEmbedded:
		process.kappaTuple.Info.pileUpInfoSource = cms.InputTag("slimmedAddPileupInfo", "", "PAT")

	# save primary vertex
	process.kappaTuple.active += cms.vstring('VertexSummary') # save VertexSummary

	process.load("Kappa.Skimming.KVertices_cff")
	process.goodOfflinePrimaryVertices.src = cms.InputTag('offlineSlimmedPrimaryVertices')
	process.p *= ( process.makeVertexes )

	process.kappaTuple.VertexSummary.whitelist = cms.vstring('offlineSlimmedPrimaryVertices')  # save VertexSummary
	process.kappaTuple.VertexSummary.rename = cms.vstring('offlineSlimmedPrimaryVertices => goodOfflinePrimaryVerticesSummary')

	if tools.is_above_cmssw_version([7,6]):
		process.kappaTuple.VertexSummary.goodOfflinePrimaryVerticesSummary = cms.PSet(src=cms.InputTag("offlineSlimmedPrimaryVertices"))

	process.kappaTuple.active += cms.vstring('TriggerObjectStandalone')

	# setup BadPFMuonFilter and BadChargedCandidateFilter
	if tools.is_above_cmssw_version([8]) and not tools.is_above_cmssw_version([9]):
		process.load('RecoMET.METFilters.BadPFMuonFilter_cfi')
		process.BadPFMuonFilter.muons = cms.InputTag("slimmedMuons")
		process.BadPFMuonFilter.PFCandidates = cms.InputTag("packedPFCandidates")
		process.BadPFMuonFilter.taggingMode = cms.bool(True)

		process.load('RecoMET.METFilters.BadChargedCandidateFilter_cfi')
		process.BadChargedCandidateFilter.muons = cms.InputTag("slimmedMuons")
		process.BadChargedCandidateFilter.PFCandidates = cms.InputTag("packedPFCandidates")
		process.BadChargedCandidateFilter.taggingMode = cms.bool(True)

		# in reMiniAOD data these filters are already present; only need to run the dedicated module for MC and older data
		if not "03Feb2017" in str(process.kappaTuple.TreeInfo.parameters.scenario):
			process.load('RecoMET.METFilters.badGlobalMuonTaggersMiniAOD_cff')
			#switch on tagging mode:
			process.badGlobalMuonTaggerMAOD.taggingMode = cms.bool(True)
			process.cloneGlobalMuonTaggerMAOD.taggingMode = cms.bool(True)

			process.kappaTuple.TriggerObjectStandalone.metfilterbitslist = cms.vstring("BadChargedCandidateFilter", "BadPFMuonFilter", "badGlobalMuonTaggerMAOD", "cloneGlobalMuonTaggerMAOD")
		else:
			process.kappaTuple.TriggerObjectStandalone.metfilterbitslist = cms.vstring("BadChargedCandidateFilter","BadPFMuonFilter")

	process.kappaTuple.Info.hltSource = cms.InputTag("TriggerResults", "", "HLT")
	if isEmbedded:
		process.kappaTuple.TriggerObjectStandalone.bits = cms.InputTag("TriggerResults", "", "SIMembedding")
		process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag("TriggerResults", "", "MERGE")
		process.kappaTuple.Info.hltSource = cms.InputTag("TriggerResults", "", "SIMembedding")
	elif data:
		if tools.is_above_cmssw_version([9]):
			process.kappaTuple.Info.hltSource = cms.InputTag("TriggerResults", "", "HLT")
			#process.kappaTuple.TriggerObjectStandalone.bits = cms.InputTag("TriggerResults", "", "RECO")
		elif "03Feb2017" in str(process.kappaTuple.TreeInfo.parameters.scenario):
			process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag("TriggerResults", "", "PAT")
		else:
			process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag("TriggerResults", "", "RECO")
			process.kappaTuple.Info.hltSource = cms.InputTag("TriggerResults", "", "RECO")
	if not isEmbedded:
		if "reHLT" in str(process.kappaTuple.TreeInfo.parameters.campaign):
			process.kappaTuple.Info.hltSource = cms.InputTag("TriggerResults", "", "HLT2")
			process.kappaTuple.TriggerObjectStandalone.bits = cms.InputTag("TriggerResults", "", "HLT2")
			process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag("TriggerResults", "", "HLT2")
		elif "Spring16" in str(process.kappaTuple.TreeInfo.parameters.campaign):
			# adds for each HLT Trigger wich contains "Tau" or "tau" in the name a Filter object named "l1extratauccolltection"
			process.kappaTuple.TriggerObjectStandalone.l1extratauJetSource = cms.untracked.InputTag("l1extraParticles","IsoTau","RECO")

	process.kappaTuple.active += cms.vstring('BeamSpot')
	if tools.is_above_cmssw_version([7,6]):
		process.kappaTuple.BeamSpot.offlineBeamSpot = cms.PSet(src = cms.InputTag("offlineBeamSpot"))

	if not isEmbedded and data:
		process.kappaTuple.active+= cms.vstring('DataInfo')          # produce Metadata for data,

	if not isEmbedded and not data:
		process.kappaTuple.active+= cms.vstring('GenInfo')           # produce Metadata for MC,
		process.kappaTuple.active+= cms.vstring('GenParticles')      # save GenParticles,
		process.kappaTuple.active+= cms.vstring('GenTaus')           # save GenParticles,
		process.kappaTuple.GenParticles.genParticles.src = cms.InputTag("prunedGenParticles")
		process.kappaTuple.GenTaus.genTaus.src = cms.InputTag("prunedGenParticles")

		process.kappaTuple.Info.lheSource = cms.InputTag("externalLHEProducer")
		process.kappaTuple.Info.lheWeightNames = cms.vstring(".*")

		if any([pattern in nickname for pattern in ["HToTauTau", "H2JetsToTauTau", "Higgs", "DY", "LFV"]]):
			process.kappaTuple.active += cms.vstring("LHE")
			process.kappaTuple.LHE.whitelist = cms.vstring("source")
			process.kappaTuple.LHE.rename = cms.vstring("source => LHEafter")
			if tools.is_above_cmssw_version([7, 6]):
				if "jhugen" in nickname.lower():
					process.kappaTuple.LHE.LHEafter = cms.PSet(src=cms.InputTag("source"))
				else:
					process.kappaTuple.LHE.LHEafter = cms.PSet(src=cms.InputTag("externalLHEProducer"))

	# save Flag
	process.kappaTuple.Info.isEmbedded = cms.bool(isEmbedded)

	if isEmbedded:
		#process.load('RecoBTag/Configuration/RecoBTag_cff')
		#process.load('RecoJets/JetAssociationProducers/ak5JTA_cff')
		#process.ak5PFJetNewTracksAssociatorAtVertex.tracks = "tmfTracks"
		#process.ak5PFCHSNewJetTracksAssociatorAtVertex.tracks = "tmfTracks"
		#process.p *= process.btagging
		# disable overrideHLTCheck for embedded samples, since it triggers an Kappa error
		process.kappaTuple.Info.overrideHLTCheck = cms.untracked.bool(True)
		process.kappaTuple.active += cms.vstring('GenInfo')
		process.kappaTuple.active += cms.vstring('GenParticles') # save GenParticles,
		process.kappaTuple.GenParticles.genParticles.src = cms.InputTag("prunedGenParticles")
		process.kappaTuple.active += cms.vstring('GenTaus')
		process.kappaTuple.GenTaus.genTaus.src = cms.InputTag("prunedGenParticles")

		#process.kappaTuple.active += cms.vstring('GenTaus') # save GenParticles,
		#process.kappaTuple.GenParticles.genParticles.src = cms.InputTag("genParticles","","EmbeddedRECO")

	## ------------------------------------------------------------------------

	# Trigger
	from Kappa.Skimming.hlt_run2 import hltBlacklist, hltWhitelist
	process.kappaTuple.Info.hltWhitelist = hltWhitelist
	process.kappaTuple.Info.hltBlacklist = hltBlacklist

	## ------------------------------------------------------------------------

	# should not be the default, it blows up the skim a lot
	#process.kappaTuple.active += cms.vstring('packedPFCandidates')
	#process.kappaTuple.packedPFCandidates.packedPFCandidates = cms.PSet(src = cms.InputTag("packedPFCandidates"))

	jetCollectionPuppi = "slimmedJetsPuppi"
	if tools.is_above_cmssw_version([9]):
		jetCollection = "slimmedJets"
	elif tools.is_above_cmssw_version([8]):
		from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
		updateJetCollection(
			process,
			jetSource = cms.InputTag('slimmedJets'),
			labelName = 'UpdatedJEC',
			jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual']), 'None'),
		)
		jetCollection = "updatedPatJetsUpdatedJEC"
		"""
		from RecoMET.METPUSubtraction.jet_recorrections import recorrectJets
		#from RecoMET.METPUSubtraction.jet_recorrections import loadLocalSqlite
		#loadLocalSqlite(process, sqliteFilename = "Spring16_25nsV6_DATA.db" if data else "Spring16_25nsV6_MC.db",
		#                         tag = 'JetCorrectorParametersCollection_Spring16_25nsV6_DATA_AK4PF' if data else 'JetCorrectorParametersCollection_Spring16_25nsV6_MC_AK4PF')
		recorrectJets(process, isData=data)
		jetCollection = "patJetsReapplyJEC"
		"""
	else:
		from RecoMET.METPUSubtraction.localSqlite import recorrectJets
		recorrectJets(process, isData=data)
		jetCollection = "patJetsReapplyJEC"

	## ------------------------------------------------------------------------

	# Configure Muons
	process.load("Kappa.Skimming.KMuons_miniAOD_cff")
	process.kappaTuple.Muons.muons.src = cms.InputTag(muons)
	process.kappaTuple.Muons.vertexcollection = cms.InputTag("offlineSlimmedPrimaryVertices")
	process.kappaTuple.Muons.srcMuonIsolationPF = cms.InputTag("")
	process.kappaTuple.Muons.use03ConeForPfIso = cms.bool(True)
	process.kappaTuple.Muons.doPfIsolation = cms.bool(False)
	for src in [ "muPFIsoDepositCharged", "muPFIsoDepositChargedAll", "muPFIsoDepositNeutral", "muPFIsoDepositGamma", "muPFIsoDepositPU"]:
		setattr(getattr(process, src), "src", cms.InputTag(muons))

	process.kappaTuple.active += cms.vstring('Muons')
	process.kappaTuple.Muons.noPropagation = cms.bool(True)
	process.p *= ( process.makeKappaMuons )

	## ------------------------------------------------------------------------

	# Configure Electrons
	process.kappaTuple.active += cms.vstring('Electrons')
	process.load("Kappa.Skimming.KElectrons_miniAOD_cff")
	process.kappaTuple.Electrons.electrons.src = cms.InputTag("slimmedElectrons")
	process.kappaTuple.Electrons.vertexcollection = cms.InputTag("offlineSlimmedPrimaryVertices")
	process.kappaTuple.Electrons.rhoIsoInputTag = cms.InputTag("slimmedJets", "rho")
	process.kappaTuple.Electrons.allConversions = cms.InputTag("reducedEgamma", "reducedConversions")
	from Kappa.Skimming.KElectrons_miniAOD_cff import setupElectrons
	process.kappaTuple.Electrons.srcIds = cms.string("standalone")

	if tools.is_above_cmssw_version([8]):
		process.kappaTuple.Electrons.ids = cms.vstring(
			"egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-veto",
			"egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose",
			"egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium",
			"egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight",
			"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values"
			)
	else:
		process.kappaTuple.Electrons.ids = cms.vstring(
			"egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto",
			"egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose",
			"egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium",
			"egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight",
			"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values"
			)

	setupElectrons(process, electrons)
	process.p *= (process.makeKappaElectrons)

	## ------------------------------------------------------------------------

	# new tau id only available for 8_0_20 (I believe) and above
	if tools.is_above_cmssw_version([8,0,20]):
		process.load('RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi')
		process.load("Kappa.Skimming.KPatTaus_run2_cff")
		process.p *= ( process.makeKappaTaus )

		# embed new id's into new tau collection
		embedID = cms.EDProducer("PATTauIDEmbedder",
			src = cms.InputTag('slimmedTaus'),
			tauIDSources = cms.PSet(
				rerunDiscriminationByIsolationMVAOldDMrun2v1raw = cms.InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1raw'),
				rerunDiscriminationByIsolationMVAOldDMrun2v1VLoose = cms.InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1VLoose'),
				rerunDiscriminationByIsolationMVAOldDMrun2v1Loose = cms.InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1Loose'),
				rerunDiscriminationByIsolationMVAOldDMrun2v1Medium = cms.InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1Medium'),
				rerunDiscriminationByIsolationMVAOldDMrun2v1Tight = cms.InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1Tight'),
				rerunDiscriminationByIsolationMVAOldDMrun2v1VTight = cms.InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1VTight'),
				rerunDiscriminationByIsolationMVAOldDMrun2v1VVTight = cms.InputTag('rerunDiscriminationByIsolationMVAOldDMrun2v1VVTight'),
				rerunDiscriminationByIsolationMVANewDMrun2v1raw = cms.InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1raw'),
				rerunDiscriminationByIsolationMVANewDMrun2v1VLoose = cms.InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1VLoose'),
				rerunDiscriminationByIsolationMVANewDMrun2v1Loose = cms.InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1Loose'),
				rerunDiscriminationByIsolationMVANewDMrun2v1Medium = cms.InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1Medium'),
				rerunDiscriminationByIsolationMVANewDMrun2v1Tight = cms.InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1Tight'),
				rerunDiscriminationByIsolationMVANewDMrun2v1VTight = cms.InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1VTight'),
				rerunDiscriminationByIsolationMVANewDMrun2v1VVTight = cms.InputTag('rerunDiscriminationByIsolationMVANewDMrun2v1VVTight')
			),
		)
		setattr(process, taus, embedID)
		process.p *= getattr(process, taus)

	process.kappaTuple.active += cms.vstring('PatTaus')
	process.kappaTuple.PatTaus.vertexcollection = cms.InputTag("offlineSlimmedPrimaryVertices")
	process.kappaTuple.PatTaus.offlineBeamSpot = cms.InputTag("offlineBeamSpot")
	process.kappaTuple.PatTaus.taus.binaryDiscrBlacklist = cms.vstring()
	process.kappaTuple.PatTaus.taus.src = cms.InputTag(taus)
	process.kappaTuple.PatTaus.taus.floatDiscrBlacklist = cms.vstring()
	# just took everything from https://twiki.cern.ch/twiki/bin/viewauth/CMS/TauIDRecommendation13TeV
	process.kappaTuple.PatTaus.taus.preselectOnDiscriminators = cms.vstring ()
	process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist = cms.vstring(
		"decayModeFinding",
		"decayModeFindingNewDMs",
		"byLooseCombinedIsolationDeltaBetaCorr3Hits",
		"byMediumCombinedIsolationDeltaBetaCorr3Hits",
		"byTightCombinedIsolationDeltaBetaCorr3Hits",
		"byCombinedIsolationDeltaBetaCorrRaw3Hits",
		"chargedIsoPtSum",
		"neutralIsoPtSum",
		"neutralIsoPtSumWeight",
		"puCorrPtSum",
		"footprintCorrection",
		"photonPtSumOutsideSignalCone",
		"byIsolationMVArun2v1DBoldDMwLTraw",
		"byVLooseIsolationMVArun2v1DBoldDMwLT",
		"byLooseIsolationMVArun2v1DBoldDMwLT",
		"byMediumIsolationMVArun2v1DBoldDMwLT",
		"byTightIsolationMVArun2v1DBoldDMwLT",
		"byVTightIsolationMVArun2v1DBoldDMwLT",
		"byVVTightIsolationMVArun2v1DBoldDMwLT",
		#"byIsolationMVArun2v1DBnewDMwLTraw",
		#"byVLooseIsolationMVArun2v1DBnewDMwLT",
		#"byLooseIsolationMVArun2v1DBnewDMwLT",
		#"byMediumIsolationMVArun2v1DBnewDMwLT",
		#"byTightIsolationMVArun2v1DBnewDMwLT",
		#"byVTightIsolationMVArun2v1DBnewDMwLT",
		#"byVVTightIsolationMVArun2v1DBnewDMwLT",
		"againstMuonLoose3",
		"againstMuonTight3",
		"againstElectronMVA6category",
		"againstElectronMVA6raw",
		"againstElectronVLooseMVA6",
		"againstElectronLooseMVA6",
		"againstElectronMediumMVA6",
		"againstElectronTightMVA6",
		"againstElectronVTightMVA6"#,
		#"chargedIsoPtSumdR03",
		#"neutralIsoPtSumdR03",
		#"neutralIsoPtSumWeightdR03",
		#"footprintCorrectiondR03",
		#"photonPtSumOutsideSignalConedR03",
		#"byLooseCombinedIsolationDeltaBetaCorr3HitsdR03",
		#"byMediumCombinedIsolationDeltaBetaCorr3HitsdR03",
		#"byTightCombinedIsolationDeltaBetaCorr3HitsdR03",
		#"byIsolationMVArun2v1DBdR03oldDMwLTraw",
		#"byVLooseIsolationMVArun2v1DBdR03oldDMwLT",
		#"byLooseIsolationMVArun2v1DBdR03oldDMwLT",
		#"byMediumIsolationMVArun2v1DBdR03oldDMwLT",
		#"byTightIsolationMVArun2v1DBdR03oldDMwLT",
		#"byVTightIsolationMVArun2v1DBdR03oldDMwLT",
		#"byVVTightIsolationMVArun2v1DBdR03oldDMwLT",
		)
	if tools.is_above_cmssw_version([8,0,20]):
		process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist += cms.vstring(
			"rerunDiscriminationByIsolationMVAOldDMrun2v1raw",
			"rerunDiscriminationByIsolationMVAOldDMrun2v1VLoose",
			"rerunDiscriminationByIsolationMVAOldDMrun2v1Loose",
			"rerunDiscriminationByIsolationMVAOldDMrun2v1Medium",
			"rerunDiscriminationByIsolationMVAOldDMrun2v1Tight",
			"rerunDiscriminationByIsolationMVAOldDMrun2v1VTight",
			"rerunDiscriminationByIsolationMVAOldDMrun2v1VVTight",
			"rerunDiscriminationByIsolationMVANewDMrun2v1raw",
			"rerunDiscriminationByIsolationMVANewDMrun2v1VLoose",
			"rerunDiscriminationByIsolationMVANewDMrun2v1Loose",
			"rerunDiscriminationByIsolationMVANewDMrun2v1Medium",
			"rerunDiscriminationByIsolationMVANewDMrun2v1Tight",
			"rerunDiscriminationByIsolationMVANewDMrun2v1VTight",
			"rerunDiscriminationByIsolationMVANewDMrun2v1VVTight"
			)
	## now also possible to save all MVA isolation inputs for taus # turn of per default

	process.kappaTuple.PatTaus.taus.extrafloatDiscrlist = cms.untracked.vstring(
		"decayDistX",
		"decayDistY",
		"decayDistZ",
		"decayDistM",
		"nPhoton",
		"ptWeightedDetaStrip",
		"ptWeightedDphiStrip",
		"ptWeightedDrSignal",
		"ptWeightedDrIsolation",
		"leadingTrackChi2",
		"eRatio"
		)

	process.kappaTuple.PatTaus.taus.floatDiscrWhitelist = process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist
	process.kappaTuple.PatTaus.verbose = cms.int32(1)

	## ------------------------------------------------------------------------

	## Configure Jets
	process.kappaTuple.active += cms.vstring('PileupDensity')
	process.kappaTuple.PileupDensity.whitelist = cms.vstring("fixedGridRhoFastjetAll")
	process.kappaTuple.PileupDensity.rename = cms.vstring("fixedGridRhoFastjetAll => pileupDensity")
	if tools.is_above_cmssw_version([7,6]):
		process.kappaTuple.PileupDensity.pileupDensity = cms.PSet(src=cms.InputTag("fixedGridRhoFastjetAll"))
	process.kappaTuple.active += cms.vstring('PatJets')
	if tools.is_above_cmssw_version([7,6]):
		process.kappaTuple.PatJets.ak4PF = cms.PSet(src=cms.InputTag(jetCollection))
		process.kappaTuple.PatJets.puppiJets = cms.PSet(src=cms.InputTag(jetCollectionPuppi))
	elif tools.is_above_cmssw_version([8,0]):
		process.jecSequence = cms.Sequence(process.patJetCorrFactorsUpdatedJEC * process.updatedPatJetsUpdatedJEC)
		process.p *= process.jecSequence

	# process.load("Configuration.StandardSequences.Reconstruction_cff") or process.load("Configuration.Geometry.GeometryRecoDB_cff")
	process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")

	## Refitted Vertices collection
	if not tools.is_above_cmssw_version([9]):
		process.kappaTuple.active += cms.vstring('RefitVertex')
		process.load("VertexRefit.TauRefit.AdvancedRefitVertexProducer_cfi")

		if tools.is_above_cmssw_version([7,6]) and not tools.is_above_cmssw_version([9]):
			process.AdvancedRefitVertexBSProducer.srcElectrons = cms.InputTag(electrons)
			process.AdvancedRefitVertexBSProducer.srcMuons = cms.InputTag(muons)
			process.AdvancedRefitVertexBSProducer.srcTaus = cms.InputTag(taus)
			process.AdvancedRefitVertexBSProducer.srcLeptons = cms.VInputTag(electrons, muons, taus)
			process.p *= (process.AdvancedRefitVertexBS)

		process.AdvancedRefitVertexNoBSProducer.srcElectrons = cms.InputTag(electrons)
		process.AdvancedRefitVertexNoBSProducer.srcMuons = cms.InputTag(muons)
		process.AdvancedRefitVertexNoBSProducer.srcTaus = cms.InputTag(taus)
		process.AdvancedRefitVertexNoBSProducer.srcLeptons = cms.VInputTag(electrons, muons, taus)
		process.p *= (process.AdvancedRefitVertexNoBS)

		process.kappaTuple.RefitVertex.whitelist = cms.vstring('AdvancedRefitVertexBS', 'AdvancedRefitVertexNoBS')

		if tools.is_above_cmssw_version([7,6]) and not tools.is_above_cmssw_version([9]):
			process.kappaTuple.RefitVertex.AdvancedRefittedVerticesBS = cms.PSet(src=cms.InputTag("AdvancedRefitVertexBSProducer"))
			process.AdvancedRefitVertexBSProducer.srcElectrons = cms.InputTag(electrons)
			process.AdvancedRefitVertexBSProducer.srcMuons = cms.InputTag(muons)
			process.AdvancedRefitVertexBSProducer.srcTaus = cms.InputTag(taus)
			process.AdvancedRefitVertexBSProducer.srcLeptons = cms.VInputTag(electrons, muons, taus)

		if tools.is_above_cmssw_version([7,6]):
			process.kappaTuple.RefitVertex.AdvancedRefittedVerticesNoBS = cms.PSet(src=cms.InputTag("AdvancedRefitVertexNoBSProducer"))
			process.AdvancedRefitVertexNoBSProducer.srcElectrons = cms.InputTag(electrons)
			process.AdvancedRefitVertexNoBSProducer.srcMuons = cms.InputTag(muons)
			process.AdvancedRefitVertexNoBSProducer.srcTaus = cms.InputTag(taus)
			process.AdvancedRefitVertexNoBSProducer.srcLeptons = cms.VInputTag(electrons, muons, taus)

	## calculate IP info wrt refitted PV
	process.kappaTuple.Electrons.refitvertexcollection = cms.InputTag("AdvancedRefitVertexNoBSProducer")
	process.kappaTuple.Muons.refitvertexcollection = cms.InputTag("AdvancedRefitVertexNoBSProducer")
	process.kappaTuple.PatTaus.refitvertexcollection = cms.InputTag("AdvancedRefitVertexNoBSProducer")

	## Standard MET and GenMet from pat::MET
	process.kappaTuple.active += cms.vstring('PatMET')
	process.kappaTuple.PatMET.met = cms.PSet(src=cms.InputTag("slimmedMETs"))
	if tools.is_above_cmssw_version([9]):
		pass
	elif tools.is_above_cmssw_version([8,0,14]):
		from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
		runMetCorAndUncFromMiniAOD(process, isData=data  )
		process.kappaTuple.PatMET.met = cms.PSet(src=cms.InputTag("slimmedMETs", "", "KAPPA"))

	#process.kappaTuple.PatMET.pfmetT1 = cms.PSet(src=cms.InputTag("patpfMETT1"))
	process.kappaTuple.PatMET.metPuppi = cms.PSet(src=cms.InputTag("slimmedMETsPuppi"))

	if not tools.is_above_cmssw_version([8]):
		## Write MVA MET to KMETs
		process.kappaTuple.active += cms.vstring('PatMETs')
		# new MVA MET
		from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
		runMVAMET( process, jetCollectionPF = jetCollection)
		process.kappaTuple.PatMETs.MVAMET = cms.PSet(src=cms.InputTag("MVAMET", "MVAMET"))
		process.MVAMET.srcLeptons  = cms.VInputTag(muons, electrons, taus) # to produce all possible combinations
		process.MVAMET.requireOS = cms.bool(False)
		if tools.is_above_cmssw_version([8,0]) and isEmbedded:
			process.MVAMET.srcMETs = cms.VInputTag(
				cms.InputTag("slimmedMETs", "", "MERGE"),
				cms.InputTag("patpfTrackMET"),
				cms.InputTag("patpfNoPUMET"),
				cms.InputTag("patpfPUCorrectedMET"),
				cms.InputTag("patpfPUMET"),
				cms.InputTag("slimmedMETsPuppi", "", "MERGE")
				)

	## ------------------------------------------------------------------------

	## GenJets
	if not data or isEmbedded:
		process.load('PhysicsTools/JetMCAlgos/TauGenJets_cfi')
		process.load('PhysicsTools/JetMCAlgos/TauGenJetsDecayModeSelectorAllHadrons_cfi')
		process.tauGenJets.GenParticles = cms.InputTag("prunedGenParticles")
		process.p *= (
			process.tauGenJets +
			process.tauGenJetsSelectorAllHadrons
			)
		if isSignal:
			process.kappaTuple.GenJets.whitelist = cms.vstring("tauGenJets", "slimmedGenJets")
		else:
			process.kappaTuple.GenJets.whitelist = cms.vstring("tauGenJets")
		process.kappaTuple.active += cms.vstring('GenJets')
		if tools.is_above_cmssw_version([7,6]):
			if isSignal:
				process.kappaTuple.GenJets.genJets = cms.PSet(src=cms.InputTag("slimmedGenJets"))
			process.kappaTuple.GenJets.tauGenJets = cms.PSet(src=cms.InputTag("tauGenJets"))
			process.kappaTuple.GenJets.tauGenJetsSelectorAllHadrons = cms.PSet(src=cms.InputTag("tauGenJetsSelectorAllHadrons"))

	# add repository revisions to TreeInfo
	for repo, rev in tools.get_repository_revisions().iteritems():
		setattr(process.kappaTuple.TreeInfo.parameters, repo, cms.string(rev))

	## ------------------------------------------------------------------------

	## Count Events after running all filters
	if not data:
		process.nEventsTotal.isMC = cms.bool(True)
		process.nNegEventsTotal.isMC = cms.bool(True)
		process.nEventsFiltered.isMC = cms.bool(True)
		process.nNegEventsFiltered.isMC = cms.bool(True)

	process.p *= process.nEventsFiltered
	process.p *= process.nNegEventsFiltered
	process.kappaTuple.active += cms.vstring('FilterSummary')

	## ------------------------------------------------------------------------

	## if needed adapt output filename
	process.ep *= process.kappaOut
	if outputfilename != '':
		process.kappaTuple.outputFile = cms.string('%s'%outputfilename)

	## ------------------------------------------------------------------------

	## Further information saved to Kappa output
	if options.dumpPython:
		f = open("dumpPython.py", "w")
		f.write(process.dumpPython())
		f.close()

	# add python config to TreeInfo
	process.kappaTuple.TreeInfo.parameters.config = cms.string(process.dumpPython())

	print "process.p:", process.p
	return process
コード例 #15
0
ファイル: kSkimming_run2_cfg.py プロジェクト: rcaspart/Kappa
def getBaseConfig(
        globaltag='START70_V7::All',
        testfile=cms.untracked.vstring(""),
        maxevents=100,  ## -1 = all in file
        nickname='SUSYGluGluToHToTauTauM160_RunIIFall15MiniAODv2_PU25nsData2015v1_13TeV_MINIAOD_pythia8',
        kappaTag='Kappa_2_0_0',
        outputfilename=''):

    from Kappa.Skimming.KSkimming_template_cfg import process
    ## ------------------------------------------------------------------------
    # count number of events before doing anything elese
    process.p *= process.nEventsTotal
    process.p *= process.nNegEventsTotal

    muons = "slimmedMuons"
    electrons = "slimmedElectrons"
    taus = "slimmedTaus"
    # produce selected collections and filter events with not even one Lepton
    if (options.preselect):
        from Kappa.Skimming.KSkimming_preselection import do_preselection
        do_preselection(process)
        process.p *= process.goodEventFilter

        process.selectedKappaTaus.cut = cms.string('pt > 15 && abs(eta) < 2.5')
        process.selectedKappaMuons.cut = cms.string('pt > 8 && abs(eta) < 2.6')
        process.selectedKappaElectrons.cut = cms.string(
            'pt > 8 && abs(eta) < 2.7')
        process.goodEventFilter.minNumber = cms.uint32(2)
        muons = "selectedKappaMuons"
        electrons = "selectedKappaElectrons"
        taus = "selectedKappaTaus"
    ## ------------------------------------------------------------------------
    # possibility to write out edmDump. Be careful when using unsceduled mode
    process.load("Kappa.Skimming.edmOut")
    process.ep = cms.EndPath()
    #process.ep *= process.edmOut

    ## ------------------------------------------------------------------------
    # Configure Kappa
    if testfile:
        process.source.fileNames = testfile
    else:
        process.source = cms.Source('PoolSource',
                                    fileNames=cms.untracked.vstring())
    process.maxEvents.input = maxevents
    process.kappaTuple.verbose = cms.int32(0)
    process.kappaTuple.profile = cms.bool(True)
    if not globaltag.lower() == 'auto':
        process.GlobalTag.globaltag = globaltag
        print "GT (overwritten):", process.GlobalTag.globaltag
    ## ------------------------------------------------------------------------
    # Configure Metadata describing the file
    # Important to be evaluated correctly for the following steps
    process.kappaTuple.active = cms.vstring('TreeInfo')
    data, isEmbedded, miniaod, process.kappaTuple.TreeInfo.parameters = datasetsHelper.getTreeInfo(
        nickname, globaltag, kappaTag)

    ## ------------------------------------------------------------------------
    # General configuration
    if ((cmssw_version_number.startswith("7_4")
         and split_cmssw_version[2] >= 14)
            or (cmssw_version_number.startswith("7_6"))):
        process.kappaTuple.Info.pileUpInfoSource = cms.InputTag(
            "slimmedAddPileupInfo")

    process.kappaTuple.active += cms.vstring(
        'VertexSummary')  # save VertexSummary,

    process.load("Kappa.Skimming.KVertices_cff")
    process.goodOfflinePrimaryVertices.src = cms.InputTag(
        'offlineSlimmedPrimaryVertices')
    process.p *= (process.makeVertexes)
    process.kappaTuple.VertexSummary.whitelist = cms.vstring(
        'offlineSlimmedPrimaryVertices')  # save VertexSummary,
    process.kappaTuple.VertexSummary.rename = cms.vstring(
        'offlineSlimmedPrimaryVertices => goodOfflinePrimaryVerticesSummary')
    if (cmssw_version_number.startswith("7_6")):
        process.kappaTuple.VertexSummary.goodOfflinePrimaryVerticesSummary = cms.PSet(
            src=cms.InputTag("offlineSlimmedPrimaryVertices"))

    process.kappaTuple.active += cms.vstring('TriggerObjectStandalone')
    if (data and ("Run2015" in nickname)):
        process.kappaTuple.TriggerObjectStandalone.metfilterbits = cms.InputTag(
            "TriggerResults", "", "RECO")
    # Adds for each HLT Trigger wich contains "Tau" or "tau" in the name a Filter object named "l1extratauccolltection"
    process.kappaTuple.TriggerObjectStandalone.l1extratauJetSource = cms.untracked.InputTag(
        "l1extraParticles", "IsoTau", "RECO")

    process.kappaTuple.active += cms.vstring('BeamSpot')  # save Beamspot,
    if (cmssw_version_number.startswith("7_6")):
        process.kappaTuple.BeamSpot.offlineBeamSpot = cms.PSet(
            src=cms.InputTag("offlineBeamSpot"))

    if not isEmbedded and data:
        process.kappaTuple.active += cms.vstring(
            'DataInfo')  # produce Metadata for data,

    if not isEmbedded and not data:
        process.kappaTuple.active += cms.vstring(
            'GenInfo')  # produce Metadata for MC,
        process.kappaTuple.active += cms.vstring(
            'GenParticles')  # save GenParticles,
        process.kappaTuple.active += cms.vstring(
            'GenTaus')  # save GenParticles,

        process.kappaTuple.GenParticles.genParticles.src = cms.InputTag(
            "prunedGenParticles")
        process.kappaTuple.GenTaus.genTaus.src = cms.InputTag(
            "prunedGenParticles")

    if isEmbedded:
        #process.load('RecoBTag/Configuration/RecoBTag_cff')
        #process.load('RecoJets/JetAssociationProducers/ak5JTA_cff')
        #process.ak5PFJetNewTracksAssociatorAtVertex.tracks = "tmfTracks"
        #process.ak5PFCHSNewJetTracksAssociatorAtVertex.tracks = "tmfTracks"
        #process.p *= process.btagging
        # disable overrideHLTCheck for embedded samples, since it triggers an Kappa error
        process.kappaTuple.Info.overrideHLTCheck = cms.untracked.bool(True)
        process.kappaTuple.active += cms.vstring('DataInfo')
        process.kappaTuple.active += cms.vstring(
            'GenParticles')  # save GenParticles,
        process.kappaTuple.active += cms.vstring(
            'GenTaus')  # save GenParticles,
        process.kappaTuple.GenParticles.genParticles.src = cms.InputTag(
            "genParticles", "", "EmbeddedRECO")

    ## ------------------------------------------------------------------------
    # Trigger
    from Kappa.Skimming.hlt_run2 import hltBlacklist, hltWhitelist
    process.kappaTuple.Info.hltWhitelist = hltWhitelist
    process.kappaTuple.Info.hltBlacklist = hltBlacklist

    ## ------------------------------------------------------------------------

    #process.kappaTuple.active += cms.vstring('packedPFCandidates') # save PFCandidates. Not sure for what, because might not be usefull for isolation
    #process.kappaTuple.packedPFCandidates.packedPFCandidates = cms.PSet(src = cms.InputTag("packedPFCandidates"))

    from RecoMET.METPUSubtraction.localSqlite import recorrectJets
    recorrectJets(process, isData=data)
    jetCollection = "patJetsReapplyJEC"

    ## ------------------------------------------------------------------------
    # Configure Muons
    process.load("Kappa.Skimming.KMuons_miniAOD_cff")
    process.kappaTuple.Muons.muons.src = cms.InputTag(muons)
    process.kappaTuple.Muons.muons.vertexcollection = cms.InputTag(
        "offlineSlimmedPrimaryVertices")
    process.kappaTuple.Muons.muons.srcMuonIsolationPF = cms.InputTag("")
    process.kappaTuple.Muons.use03ConeForPfIso = cms.bool(True)
    for src in [
            "muPFIsoDepositCharged", "muPFIsoDepositChargedAll",
            "muPFIsoDepositNeutral", "muPFIsoDepositGamma", "muPFIsoDepositPU"
    ]:
        setattr(getattr(process, src), "src", cms.InputTag(muons))

    process.kappaTuple.active += cms.vstring('Muons')
    process.kappaTuple.Muons.noPropagation = cms.bool(True)
    process.p *= (process.makeKappaMuons)

    ## ------------------------------------------------------------------------
    # Configure Electrons
    process.kappaTuple.active += cms.vstring('Electrons')
    process.load("Kappa.Skimming.KElectrons_miniAOD_cff")
    process.kappaTuple.Electrons.electrons.src = cms.InputTag(
        "slimmedElectrons")
    process.kappaTuple.Electrons.electrons.vertexcollection = cms.InputTag(
        "offlineSlimmedPrimaryVertices")
    process.kappaTuple.Electrons.electrons.rhoIsoInputTag = cms.InputTag(
        "slimmedJets", "rho")
    process.kappaTuple.Electrons.electrons.allConversions = cms.InputTag(
        "reducedEgamma", "reducedConversions")
    from Kappa.Skimming.KElectrons_miniAOD_cff import setupElectrons
    process.kappaTuple.Electrons.srcIds = cms.string("standalone")

    process.kappaTuple.Electrons.ids = cms.vstring(
        "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-veto",
        "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-loose",
        "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-medium",
        "egmGsfElectronIDs:cutBasedElectronID-Spring15-25ns-V1-standalone-tight",
        "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values"
    )

    setupElectrons(process, electrons)
    process.p *= (process.makeKappaElectrons)
    ## ------------------------------------------------------------------------
    process.kappaTuple.active += cms.vstring('PatTaus')
    process.kappaTuple.PatTaus.taus.binaryDiscrBlacklist = cms.vstring()
    process.kappaTuple.PatTaus.taus.floatDiscrBlacklist = cms.vstring()
    # just took everything from https://twiki.cern.ch/twiki/bin/viewauth/CMS/TauIDRecommendation13TeV
    process.kappaTuple.PatTaus.taus.preselectOnDiscriminators = cms.vstring()
    process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist = cms.vstring(
        "decayModeFinding", "decayModeFindingNewDMs",
        "byLooseCombinedIsolationDeltaBetaCorr3Hits",
        "byMediumCombinedIsolationDeltaBetaCorr3Hits",
        "byTightCombinedIsolationDeltaBetaCorr3Hits",
        "byCombinedIsolationDeltaBetaCorrRaw3Hits", "chargedIsoPtSum",
        "neutralIsoPtSum", "puCorrPtSum", "footprintCorrection",
        "photonPtSumOutsideSignalCone", "byIsolationMVArun2v1DBoldDMwLTraw",
        "byLooseIsolationMVArun2v1DBoldDMwLT",
        "byMediumIsolationMVArun2v1DBoldDMwLT",
        "byTightIsolationMVArun2v1DBoldDMwLT",
        "byVTightIsolationMVArun2v1DBoldDMwLT",
        "byIsolationMVArun2v1DBnewDMwLTraw",
        "byLooseIsolationMVArun2v1DBnewDMwLT",
        "byMediumIsolationMVArun2v1DBnewDMwLT",
        "byTightIsolationMVArun2v1DBnewDMwLT",
        "byVTightIsolationMVArun2v1DBnewDMwLT", "againstMuonLoose3",
        "againstMuonTight3", "againstElectronMVA5category",
        "againstElectronMVA5raw", "againstElectronVLooseMVA5",
        "againstElectronLooseMVA5", "againstElectronMediumMVA5",
        "againstElectronTightMVA5", "againstElectronVTightMVA5",
        "againstElectronMVA6category", "againstElectronMVA6raw",
        "againstElectronVLooseMVA6", "againstElectronLooseMVA6",
        "againstElectronMediumMVA6", "againstElectronTightMVA6",
        "againstElectronVTightMVA6",
        "byLooseCombinedIsolationDeltaBetaCorr3HitsdR03",
        "byMediumCombinedIsolationDeltaBetaCorr3HitsdR03",
        "byTightCombinedIsolationDeltaBetaCorr3HitsdR03",
        "byLooseIsolationMVArun2v1DBdR03oldDMwLT",
        "byMediumIsolationMVArun2v1DBdR03oldDMwLT",
        "byTightIsolationMVArun2v1DBdR03oldDMwLT",
        "byVTightIsolationMVArun2v1DBdR03oldDMwLT")
    process.kappaTuple.PatTaus.taus.floatDiscrWhitelist = process.kappaTuple.PatTaus.taus.binaryDiscrWhitelist
    ## ------------------------------------------------------------------------
    ## Configure Jets
    process.kappaTuple.active += cms.vstring('PileupDensity')
    process.kappaTuple.PileupDensity.whitelist = cms.vstring(
        "fixedGridRhoFastjetAll")
    process.kappaTuple.PileupDensity.rename = cms.vstring(
        "fixedGridRhoFastjetAll => pileupDensity")
    if (cmssw_version_number.startswith("7_6")):
        process.kappaTuple.PileupDensity.pileupDensity = cms.PSet(
            src=cms.InputTag("fixedGridRhoFastjetAll"))
    process.kappaTuple.active += cms.vstring('PatJets')
    if (cmssw_version_number.startswith("7_6")):
        process.kappaTuple.PatJets.ak4PF = cms.PSet(
            src=cms.InputTag(jetCollection))
    #from Kappa.Skimming.KMET_run2_cff import configureMVAMetForMiniAOD
    #configureMVAMetForMiniAOD(process)

    ## Standard MET and GenMet from pat::MET
    process.kappaTuple.active += cms.vstring('PatMET')
    process.kappaTuple.PatMET.met = cms.PSet(src=cms.InputTag("slimmedMETs"))
    process.kappaTuple.PatMET.pfmetT1 = cms.PSet(
        src=cms.InputTag("patpfMETT1"))
    process.kappaTuple.PatMET.metPuppi = cms.PSet(
        src=cms.InputTag("slimmedMETsPuppi"))

    ## Write MVA MET to KMETs
    process.kappaTuple.active += cms.vstring('PatMETs')
    # new MVA MET
    from RecoMET.METPUSubtraction.MVAMETConfiguration_cff import runMVAMET
    runMVAMET(process, jetCollectionPF=jetCollection)
    process.kappaTuple.PatMETs.MVAMET = cms.PSet(
        src=cms.InputTag("MVAMET", "MVAMET"))
    process.MVAMET.srcLeptons = cms.VInputTag(
        muons, electrons, taus)  # to produce all possible combinations
    process.MVAMET.requireOS = cms.bool(False)

    ## ------------------------------------------------------------------------
    ## GenJets
    if not data:
        process.load('PhysicsTools/JetMCAlgos/TauGenJets_cfi')
        process.load(
            'PhysicsTools/JetMCAlgos/TauGenJetsDecayModeSelectorAllHadrons_cfi'
        )
        process.tauGenJets.GenParticles = cms.InputTag("prunedGenParticles")
        process.p *= (process.tauGenJets +
                      process.tauGenJetsSelectorAllHadrons)
        process.kappaTuple.GenJets.whitelist = cms.vstring("tauGenJets")
        process.kappaTuple.active += cms.vstring('GenJets')
        if (cmssw_version_number.startswith("7_6")):
            process.kappaTuple.GenJets.tauGenJets = cms.PSet(
                src=cms.InputTag("tauGenJets"))
            process.kappaTuple.GenJets.tauGenJetsSelectorAllHadrons = cms.PSet(
                src=cms.InputTag("tauGenJetsSelectorAllHadrons"))

    ## ------------------------------------------------------------------------
    ## Further information saved to Kappa output
    # add python config to TreeInfo
    process.kappaTuple.TreeInfo.parameters.config = cms.string(
        process.dumpPython())

    # add repository revisions to TreeInfo
    for repo, rev in tools.get_repository_revisions().iteritems():
        setattr(process.kappaTuple.TreeInfo.parameters, repo, cms.string(rev))

    ## ------------------------------------------------------------------------
    ## Count Events after running all filters
    if not data:
        process.nEventsTotal.isMC = cms.bool(True)
        process.nNegEventsTotal.isMC = cms.bool(True)
        process.nEventsFiltered.isMC = cms.bool(True)
        process.nNegEventsFiltered.isMC = cms.bool(True)

    process.p *= process.nEventsFiltered
    process.p *= process.nNegEventsFiltered
    process.kappaTuple.active += cms.vstring('FilterSummary')

    ## ------------------------------------------------------------------------
    ## if needed adapt output filename
    process.p *= process.kappaOut
    if outputfilename != '':
        process.kappaTuple.outputFile = cms.string('%s' % outputfilename)

    return process