Esempio n. 1
0
def SingleTopStep2Preselection():
    Config.doMuon = False
    Config.doElectron = False
    #Whether to filter the HLT
    Config.filterHLT = False

    #Whether to use the cross-strigger or the single lepton trigger
    Config.useXTrigger = False

    #Either running over MC or Data
    Config.isMC = True
    if not Config.onGrid:
        options = VarParsing('analysis')
        options.register('subChannel', 'T_t',
                         VarParsing.multiplicity.singleton,
                         VarParsing.varType.string,
                         "The sample that you are running on")
        options.register('doDebug', False, VarParsing.multiplicity.singleton,
                         VarParsing.varType.bool, "Turn on debugging messages")
        options.register('compHep', False, VarParsing.multiplicity.singleton,
                         VarParsing.varType.bool, "Turn on debugging messages")
        options.register('globalTag', Config.globalTagMC,
                         VarParsing.multiplicity.singleton,
                         VarParsing.varType.string, "Global tag")
        options.register('srcPUDistribution', "S10",
                         VarParsing.multiplicity.singleton,
                         VarParsing.varType.string,
                         "Source pile-up distribution")
        options.register(
            'doGenParticlePath', True, VarParsing.multiplicity.singleton,
            VarParsing.varType.bool,
            "Run the gen particle paths (only works on specific MC)")
        options.register('destPUDistribution', "data",
                         VarParsing.multiplicity.singleton,
                         VarParsing.varType.string,
                         "destination pile-up distribution")
        options.parseArguments()

        Config.channel = Config.Channel.signal
        Config.srcPUDistribution = pileUpDistributions.distributions[
            options.srcPUDistribution]
        Config.destPUDistribution = pileUpDistributions.distributions[
            options.destPUDistribution]

        Config.subChannel = options.subChannel
        Config.doDebug = options.doDebug
        Config.isMC = True
        Config.isCompHep = options.compHep
        Config.dataRun = "RunABCD"

    print "Configuration"
    print Config._toStr()

    print Config.Jets._toStr()
    print Config.Muons._toStr()
    print Config.Electrons._toStr()
    print ""

    process = cms.Process("STPOLSEL2")
    eventCounting.countProcessed(process)

    process.load("Configuration.Geometry.GeometryIdeal_cff")
    process.load(
        "Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    from Configuration.AlCa.autoCond import autoCond
    process.GlobalTag.globaltag = cms.string(options.globalTag)
    process.load("Configuration.StandardSequences.MagneticField_cff")

    if Config.doDebug:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger = cms.Service(
            "MessageLogger",
            destinations=cms.untracked.vstring('cout', 'debug'),
            debugModules=cms.untracked.vstring('*'),
            cout=cms.untracked.PSet(threshold=cms.untracked.string('INFO')),
            debug=cms.untracked.PSet(threshold=cms.untracked.string('DEBUG')),
        )
        logging.basicConfig(level=logging.DEBUG)
    else:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger.cerr.FwkReport.reportEvery = 1000
        process.MessageLogger.cerr.threshold = cms.untracked.string("INFO")
        logging.basicConfig(level=logging.DEBUG)

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

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

    process.source = cms.Source(
        "PoolSource",
        # replace 'myfile.root' with the source file you want to use
        fileNames=cms.untracked.vstring(""),
        cacheSize=cms.untracked.uint32(10 * 1024 * 1024),
    )

    process.decayTreeProducerMu = cms.EDProducer(
        'GenParticleDecayTreeProducer', src=cms.InputTag(Config.Muons.source))

    process.decayTreeProducerEle = cms.EDProducer(
        'GenParticleDecayTreeProducer',
        src=cms.untracked.InputTag(Config.Electrons.source))

    def treeCollection(collection_, maxElems_, varlist):
        varVPSet = cms.untracked.VPSet()
        for v in varlist:
            pset = cms.untracked.PSet(
                tag=cms.untracked.string(v[0]),
                expr=cms.untracked.string(v[1]),
            )
            varVPSet.append(pset)
        ret = cms.untracked.PSet(collection=collection_,
                                 maxElems=cms.untracked.int32(maxElems_),
                                 variables=varVPSet)
        return ret

    def ntupleCollection(items):
        varVPSet = cms.VPSet()
        for item in items:
            pset = cms.untracked.PSet(tag=cms.untracked.string(item[0]),
                                      quantity=cms.untracked.string(item[1]))
            varVPSet.append(pset)
        return varVPSet

    process.recoTopNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("recoTop"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection([
            ["Pt", "pt"],
            ["Eta", "eta"],
            ["Phi", "phi"],
            ["Mass", "mass"],
        ]))
    process.recoNuNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("recoNu"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection([
            ["Pt", "pt"],
            ["Eta", "eta"],
            ["Phi", "phi"],
            ["Px", "p4().Px()"],
            ["Py", "p4().Py()"],
            ["Pz", "p4().Pz()"],
        ]))

    process.trueNuNTupleProducer = process.recoNuNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueNeutrino", "STPOLSEL2"), )
    if Config.isCompHep:
        process.trueTopNTupleProducer = process.recoTopNTupleProducer.clone(
            src=cms.InputTag("recoTrueTop"), )
    else:
        process.trueTopNTupleProducer = process.recoTopNTupleProducer.clone(
            src=cms.InputTag("genParticleSelector", "trueTop", "STPOLSEL2"), )
    process.patMETNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag(Config.metSource), )
    process.trueLeptonNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2"), )

    process.trueLightJetNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLightJet", "STPOLSEL2"), )

    process.trueMuonsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag(Config.Muons.source),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection([
            ["Pt", "pt"],
            ["Eta", "eta"],
            ["Phi", "phi"],
            #["relIso", "userFloat('%s')" % Config.Muons.relIsoType],
            ["Charge", "charge"],
            [
                "genPdgId",
                "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"
            ],
            [
                "motherGenPdgId",
                "? genParticlesSize() > 0 ? genParticle(0).mother(0).pdgId() : 0"
            ],
        ]))

    process.puWeightProducer = cms.EDProducer(
        'PUWeightProducer',
        maxVertices=cms.uint32(50),
        srcDistribution=cms.vdouble(Config.srcPUDistribution),
        destDistribution=cms.vdouble(Config.destPUDistribution))

    process.muonWeightsProducer = cms.EDProducer(
        "MuonEfficiencyProducer",
        src=cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2"),
        dataRun=cms.string(Config.dataRun))

    process.electronWeightsProducer = cms.EDProducer(
        "ElectronEfficiencyProducer",
        src=cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2"))

    process.elePathPreCount = cms.EDProducer("EventCountProducer")
    process.muPathPreCount = cms.EDProducer("EventCountProducer")

    process.treeSequenceNew = cms.Sequence(
        process.muPathPreCount * process.elePathPreCount *
        process.trueTopNTupleProducer * process.trueNuNTupleProducer *
        process.trueLeptonNTupleProducer * process.trueLightJetNTupleProducer *
        process.trueMuonsNTupleProducer * process.puWeightProducer  #*
        #process.muonWeightsProducer *
        #process.electronWeightsProducer
    )

    if Config.isCompHep:
        from SingleTopPolarization.Analysis.partonStudy_comphep_step2_cfi import PartonStudySetup
    else:
        from SingleTopPolarization.Analysis.partonStudy_step2_cfi import PartonStudySetup
    PartonStudySetup(process)
    process.partonPath = cms.Path()
    process.partonPath += process.partonStudyTrueSequence
    process.treePath = cms.Path(process.treeSequenceNew)

    #-----------------------------------------------
    # Outpath
    #-----------------------------------------------

    if not Config.skipPatTupleOutput:
        process.out = cms.OutputModule(
            "PoolOutputModule",
            dropMetaData=cms.untracked.string("DROPPED"),
            splitLevel=cms.untracked.int32(99),
            fileName=cms.untracked.string('out_step2.root'),
            SelectEvents=cms.untracked.PSet(SelectEvents=cms.vstring(["*"])),
            outputCommands=cms.untracked.vstring(
                #'drop *',
                'drop *',
                'keep edmMergeableCounter_*__*',
                'keep edmTriggerResults_TriggerResults__*',
                'keep floats_trueTopNTupleProducer_*_STPOLSEL2',
                'keep floats_trueNuNTupleProducer_*_STPOLSEL2',
                'keep floats_trueLeptonNTupleProducer_*_STPOLSEL2',
                #'keep floats_goodSignalMuonsNTupleProducer_*_STPOLSEL2',
                #'keep floats_goodSignalElectronsNTupleProducer_*_STPOLSEL2',
                #'keep floats_goodJetsNTupleProducer_*_STPOLSEL2',
                #'keep floats_lowestBTagJetNTupleProducer_*_STPOLSEL2',
                #'keep floats_highestBTagJetNTupleProducer_*_STPOLSEL2',
                'keep double_*__STPOLSEL2',
                'keep float_*__STPOLSEL2',
                'keep double_*_*_STPOLSEL2',
                'keep float_*_*_STPOLSEL2',
                #'keep double_cosTheta_*_STPOLSEL2',
                'keep double_cosThetaProducerTrueAll_*_STPOLSEL2',
                #'keep double_cosThetaProducerTrueTop_*_STPOLSEL2',
                #'keep double_cosThetaProducerTrueLepton_*_STPOLSEL2',
                #'keep double_cosThetaProducerTrueJet_*_STPOLSEL2',
                #'keep *_bTagWeightProducerNJMT_*_STPOLSEL2',
                'keep int_*__STPOLSEL2',
                'keep int_*_*_STPOLSEL2',
                'keep String_*_*_*',  #the decay trees
                #'keep *_pdfInfo1_*_STPOLSEL2',
                #'keep *_pdfInfo2_*_STPOLSEL2',
                #'keep *_pdfInfo3_*_STPOLSEL2',
                #'keep *_pdfInfo4_*_STPOLSEL2',
                #'keep *_pdfInfo5_*_STPOLSEL2',
                #'keep *',
                #'keep *_recoTop_*_*',
                #'keep *_goodSignalMuons_*_*',
                #'keep *_goodSignalElectrons_*_*',
                #'keep *_goodJets_*_*',
                #'keep *_bTaggedJets_*_*',
                #'keep *_untaggedJets_*_*',
            ))
        process.outpath = cms.EndPath(process.out)
        #if Config.doElectron:
        #    process.out.SelectEvents.SelectEvents.append("elePath")
        #if Config.doMuon:
        #    process.out.SelectEvents.SelectEvents.append("muPath")

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

    #Command-line arguments
    if not Config.onGrid:
        process.source.fileNames = cms.untracked.vstring(options.inputFiles)
        process.maxEvents = cms.untracked.PSet(
            input=cms.untracked.int32(options.maxEvents))
        if hasattr(process, "out"):
            process.out.fileName = cms.untracked.string(options.outputFile)
        outFile = options.outputFile
        #from SingleTopPolarization.Analysis.cmdlineParsing import enableCommandLineArguments
        #(inFiles, outFile) = enableCommandLineArguments(process)
    else:
        outFile = "step2.root"

    #process.TFileService = cms.Service(
    #    "TFileService",
    #    fileName=cms.string(outFile.replace(".root", "_trees.root")),
    #)

    #print "Output trees: %s" % process.TFileService.fileName.value()
    if hasattr(process, "out"):
        print "Output patTuples: %s" % process.out.fileName.value()
    print 80 * "-"
    print "Step2 configured"

    return process
Esempio n. 2
0
def SingleTopStep2Preselection():
    Config.doMuon = False
    Config.doElectron = False
    #Whether to filter the HLT
    Config.filterHLT = False

    #Whether to use the cross-strigger or the single lepton trigger
    Config.useXTrigger = False

    #Either running over MC or Data
    Config.isMC = True
    if not Config.onGrid:
        options = VarParsing('analysis')
        options.register ('subChannel', 'T_t',
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "The sample that you are running on")
        options.register ('doDebug', False,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Turn on debugging messages")
        options.register ('compHep', False,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Turn on debugging messages")
        options.register ('globalTag', Config.globalTagMC,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "Global tag"
        )
        options.register ('srcPUDistribution', "S10",
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "Source pile-up distribution"
        )
        options.register ('doGenParticlePath', True,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Run the gen particle paths (only works on specific MC)"
        )
        options.register ('destPUDistribution', "data",
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "destination pile-up distribution"
        )
        options.parseArguments()

        Config.channel = Config.Channel.signal
        Config.srcPUDistribution = pileUpDistributions.distributions[options.srcPUDistribution]
        Config.destPUDistribution = pileUpDistributions.distributions[options.destPUDistribution]


        Config.subChannel = options.subChannel
        Config.doDebug = options.doDebug
        Config.isMC = True
        Config.isCompHep = options.compHep
        Config.dataRun = "RunABCD"

    print "Configuration"
    print Config._toStr()

    print Config.Jets._toStr()
    print Config.Muons._toStr()
    print Config.Electrons._toStr()
    print ""

    process = cms.Process("STPOLSEL2")
    eventCounting.countProcessed(process)

    process.load("Configuration.Geometry.GeometryIdeal_cff")
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    from Configuration.AlCa.autoCond import autoCond
    process.GlobalTag.globaltag = cms.string(options.globalTag)
    process.load("Configuration.StandardSequences.MagneticField_cff")

    if Config.doDebug:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger = cms.Service("MessageLogger",
               destinations=cms.untracked.vstring('cout', 'debug'),
               debugModules=cms.untracked.vstring('*'),
               cout=cms.untracked.PSet(threshold=cms.untracked.string('INFO')),
               debug=cms.untracked.PSet(threshold=cms.untracked.string('DEBUG')),
        )
        logging.basicConfig(level=logging.DEBUG)
    else:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger.cerr.FwkReport.reportEvery = 1000
        process.MessageLogger.cerr.threshold = cms.untracked.string("INFO")
        logging.basicConfig(level=logging.DEBUG)

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

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

    process.source = cms.Source("PoolSource",
        # replace 'myfile.root' with the source file you want to use
        fileNames=cms.untracked.vstring(""),
        cacheSize = cms.untracked.uint32(10*1024*1024),
    )

    process.decayTreeProducerMu = cms.EDProducer(
        'GenParticleDecayTreeProducer',
        src=cms.InputTag(Config.Muons.source)
    )

    process.decayTreeProducerEle = cms.EDProducer(
        'GenParticleDecayTreeProducer',
        src=cms.untracked.InputTag(Config.Electrons.source)
    )

    def treeCollection(collection_, maxElems_, varlist):
        varVPSet = cms.untracked.VPSet()
        for v in varlist:
            pset = cms.untracked.PSet(tag=cms.untracked.string(v[0]), expr=cms.untracked.string(v[1]), )
            varVPSet.append(pset)
        ret = cms.untracked.PSet(
            collection=collection_,
            maxElems=cms.untracked.int32(maxElems_),
            variables=varVPSet
        )
        return ret

    def ntupleCollection(items):
        varVPSet = cms.VPSet()
        for item in items:
            pset = cms.untracked.PSet(
                tag=cms.untracked.string(item[0]),
                quantity=cms.untracked.string(item[1])
            )
            varVPSet.append(pset)
        return varVPSet


    process.recoTopNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag("recoTop"),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables = ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["Mass", "mass"],
            ]
      )
    )
    process.recoNuNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag("recoNu"),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables = ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["Px", "p4().Px()"],
                ["Py", "p4().Py()"],
                ["Pz", "p4().Pz()"],
            ]
      )
    )

    process.trueNuNTupleProducer = process.recoNuNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueNeutrino", "STPOLSEL2"),
    )
    if Config.isCompHep:
        process.trueTopNTupleProducer = process.recoTopNTupleProducer.clone(
            src=cms.InputTag("recoTrueTop"),
        )
    else:
        process.trueTopNTupleProducer = process.recoTopNTupleProducer.clone(
            src=cms.InputTag("genParticleSelector", "trueTop", "STPOLSEL2"),
        )
    process.patMETNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag(Config.metSource),
    )
    process.trueLeptonNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2"),
    )

    process.trueLightJetNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLightJet", "STPOLSEL2"),
    )

    process.trueMuonsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag(Config.Muons.source),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables = ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                #["relIso", "userFloat('%s')" % Config.Muons.relIsoType],
                ["Charge", "charge"],
                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"],
                ["motherGenPdgId", "? genParticlesSize() > 0 ? genParticle(0).mother(0).pdgId() : 0"],
            ]
      )
    )

    process.puWeightProducer = cms.EDProducer('PUWeightProducer'
            , maxVertices = cms.uint32(50)
            , srcDistribution = cms.vdouble(Config.srcPUDistribution)
            , destDistribution = cms.vdouble(Config.destPUDistribution)
        )

    process.muonWeightsProducer = cms.EDProducer("MuonEfficiencyProducer",
        src=cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2"),
        dataRun=cms.string(Config.dataRun)
    )

    process.electronWeightsProducer = cms.EDProducer("ElectronEfficiencyProducer",
        src = cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2")
    )

    process.elePathPreCount = cms.EDProducer("EventCountProducer")
    process.muPathPreCount = cms.EDProducer("EventCountProducer")

    process.treeSequenceNew = cms.Sequence(
        process.muPathPreCount *
        process.elePathPreCount *
        process.trueTopNTupleProducer *
        process.trueNuNTupleProducer *
        process.trueLeptonNTupleProducer *
        process.trueLightJetNTupleProducer *
        process.trueMuonsNTupleProducer *
        process.puWeightProducer #*
        #process.muonWeightsProducer *
        #process.electronWeightsProducer
    )

    if Config.isCompHep:
        from SingleTopPolarization.Analysis.partonStudy_comphep_step2_cfi import PartonStudySetup
    else:
        from SingleTopPolarization.Analysis.partonStudy_step2_cfi import PartonStudySetup
    PartonStudySetup(process)
    process.partonPath = cms.Path()
    process.partonPath += process.partonStudyTrueSequence
    process.treePath = cms.Path(
        process.treeSequenceNew
    )

    #-----------------------------------------------
    # Outpath
    #-----------------------------------------------

    if not Config.skipPatTupleOutput:
        process.out = cms.OutputModule("PoolOutputModule",
            dropMetaData=cms.untracked.string("DROPPED"),
            splitLevel=cms.untracked.int32(99),
            fileName=cms.untracked.string('out_step2.root'),
             SelectEvents=cms.untracked.PSet(
                 SelectEvents=cms.vstring(["*"])
             ),
            outputCommands=cms.untracked.vstring(
                #'drop *',
                'drop *',
                'keep edmMergeableCounter_*__*',
                'keep edmTriggerResults_TriggerResults__*',
                'keep floats_trueTopNTupleProducer_*_STPOLSEL2',
                'keep floats_trueNuNTupleProducer_*_STPOLSEL2',
                'keep floats_trueLeptonNTupleProducer_*_STPOLSEL2',
                #'keep floats_goodSignalMuonsNTupleProducer_*_STPOLSEL2',
                #'keep floats_goodSignalElectronsNTupleProducer_*_STPOLSEL2',
                #'keep floats_goodJetsNTupleProducer_*_STPOLSEL2',
                #'keep floats_lowestBTagJetNTupleProducer_*_STPOLSEL2',
                #'keep floats_highestBTagJetNTupleProducer_*_STPOLSEL2',
                'keep double_*__STPOLSEL2',
                'keep float_*__STPOLSEL2',
                'keep double_*_*_STPOLSEL2',
                'keep float_*_*_STPOLSEL2',
                #'keep double_cosTheta_*_STPOLSEL2',
                'keep double_cosThetaProducerTrueAll_*_STPOLSEL2',
                #'keep double_cosThetaProducerTrueTop_*_STPOLSEL2',
                #'keep double_cosThetaProducerTrueLepton_*_STPOLSEL2',
                #'keep double_cosThetaProducerTrueJet_*_STPOLSEL2',
                #'keep *_bTagWeightProducerNJMT_*_STPOLSEL2',
                'keep int_*__STPOLSEL2',
                'keep int_*_*_STPOLSEL2',
                'keep String_*_*_*', #the decay trees
                #'keep *_pdfInfo1_*_STPOLSEL2',
                #'keep *_pdfInfo2_*_STPOLSEL2',
                #'keep *_pdfInfo3_*_STPOLSEL2',
                #'keep *_pdfInfo4_*_STPOLSEL2',
                #'keep *_pdfInfo5_*_STPOLSEL2',
                #'keep *',
                #'keep *_recoTop_*_*',
                #'keep *_goodSignalMuons_*_*',
                #'keep *_goodSignalElectrons_*_*',
                #'keep *_goodJets_*_*',
                #'keep *_bTaggedJets_*_*',
                #'keep *_untaggedJets_*_*',
            )
        )
        process.outpath = cms.EndPath(process.out)
        #if Config.doElectron:
        #    process.out.SelectEvents.SelectEvents.append("elePath")
        #if Config.doMuon:
        #    process.out.SelectEvents.SelectEvents.append("muPath")

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

    #Command-line arguments
    if not Config.onGrid:
        process.source.fileNames = cms.untracked.vstring(options.inputFiles)
        process.maxEvents = cms.untracked.PSet(
          input = cms.untracked.int32(options.maxEvents)
        )
        if hasattr(process, "out"):
            process.out.fileName = cms.untracked.string(options.outputFile)
        outFile = options.outputFile
        #from SingleTopPolarization.Analysis.cmdlineParsing import enableCommandLineArguments
        #(inFiles, outFile) = enableCommandLineArguments(process)
    else:
        outFile = "step2.root"

    #process.TFileService = cms.Service(
    #    "TFileService",
    #    fileName=cms.string(outFile.replace(".root", "_trees.root")),
    #)

    #print "Output trees: %s" % process.TFileService.fileName.value()
    if hasattr(process, "out"):
        print "Output patTuples: %s" % process.out.fileName.value()
    print 80*"-"
    print "Step2 configured"

    return process
Esempio n. 3
0
def SingleTopStep2():

    options = VarParsing("analysis")
    options.register(
        "subChannel",
        "T_t",
        VarParsing.multiplicity.singleton,
        VarParsing.varType.string,
        "The sample that you are running on",
    )
    options.register(
        "reverseIsoCut",
        False,
        VarParsing.multiplicity.singleton,
        VarParsing.varType.bool,
        "Consider anti-isolated region",
    )
    options.register(
        "doDebug", False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "Turn on debugging messages"
    )
    options.register("isMC", True, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "Run on MC")
    options.register(
        "doGenParticlePath",
        True,
        VarParsing.multiplicity.singleton,
        VarParsing.varType.bool,
        "Run the gen particle paths (only works on specific MC)",
    )
    options.register(
        "globalTag", Config.globalTagMC, VarParsing.multiplicity.singleton, VarParsing.varType.string, "Global tag"
    )
    options.register(
        "srcPUDistribution",
        "S10",
        VarParsing.multiplicity.singleton,
        VarParsing.varType.string,
        "Source pile-up distribution",
    )
    options.register(
        "destPUDistribution",
        "data",
        VarParsing.multiplicity.singleton,
        VarParsing.varType.string,
        "destination pile-up distribution",
    )

    options.register(
        "isComphep",
        False,
        VarParsing.multiplicity.singleton,
        VarParsing.varType.bool,
        "Use CompHep-specific processing",
    )

    options.register(
        "isAMCatNLO",
        False,
        VarParsing.multiplicity.singleton,
        VarParsing.varType.bool,
        "Use aMC@NLO-specific processing",
    )

    options.register(
        "isSherpa", False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "Use sherpa-specific processing"
    )

    options.register(
        "systematic", "", VarParsing.multiplicity.singleton, VarParsing.varType.string, "Apply Systematic variation"
    )

    options.register(
        "dataRun",
        "RunABCD",
        VarParsing.multiplicity.singleton,
        VarParsing.varType.string,
        "A string Run{A,B,C,D} to specify the data period",
    )

    options.register(
        "doSync", False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "Synchronization exercise"
    )

    options.parseArguments()

    if options.isMC:
        Config.srcPUDistribution = pileUpDistributions.distributions[options.srcPUDistribution]

    Config.Leptons.reverseIsoCut = options.reverseIsoCut
    Config.subChannel = options.subChannel
    Config.doDebug = options.doDebug
    Config.isMC = options.isMC
    Config.doSkim = options.doSync or not sample_types.is_signal(Config.subChannel)
    Config.isCompHep = options.isComphep or "comphep" in Config.subChannel
    Config.isAMCatNLO = Config.isAMCatNLO or options.isAMCatNLO or "aMCatNLO" in Config.subChannel
    Config.isSherpa = options.isSherpa or "sherpa" in Config.subChannel
    Config.systematic = options.systematic
    Config.doSync = options.doSync

    print "Systematic: ", Config.systematic

    if Config.isMC and not Config.doSync:
        logging.info("Changing jet source from %s to smearedPatJetsWithOwnRef" % Config.Jets.source)
        Config.Jets.source = "smearedPatJetsWithOwnRef"

        if Config.systematic in ["ResUp", "ResDown"]:
            logging.info(
                "Changing jet source from %s to smearedPatJetsWithOwnRef%s" % (Config.Jets.source, Config.systematic)
            )
            Config.Jets.source = "smearedPatJetsWithOwnRef" + Config.systematic
            logging.info(
                "Changing MET source from %s to patType1CorrectedPFMetJet%s" % (Config.metSource, Config.systematic)
            )
            Config.metSource = "patType1CorrectedPFMetJet" + Config.systematic
        elif Config.systematic in ["EnUp", "EnDown"]:
            logging.info(
                "Changing jet source from %s to shiftedPatJetsWithOwnRef%sForCorrMEt"
                % (Config.Jets.source, Config.systematic)
            )
            Config.Jets.source = "shiftedPatJetsWithOwnRef" + Config.systematic + "ForCorrMEt"
            logging.info(
                "Changing MET source from %s to patType1CorrectedPFMetJet%s" % (Config.metSource, Config.systematic)
            )
            Config.metSource = "patType1CorrectedPFMetJet" + Config.systematic
        elif Config.systematic in ["UnclusteredEnUp", "UnclusteredEnDown"]:
            logging.info(
                "Changing MET source from %s to patType1CorrectedPFMet%s" % (Config.metSource, Config.systematic)
            )
            Config.metSource = "patType1CorrectedPFMet" + Config.systematic

    print "Configuration"
    print Config._toStr()

    print Config.Jets._toStr()
    print Config.Muons._toStr()
    print Config.Electrons._toStr()
    print ""

    process = cms.Process("STPOLSEL2")
    eventCounting.countProcessed(process)

    process.load("Configuration.Geometry.GeometryIdeal_cff")
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    from Configuration.AlCa.autoCond import autoCond

    process.GlobalTag.globaltag = cms.string(options.globalTag)
    process.load("Configuration.StandardSequences.MagneticField_cff")

    if Config.doDebug:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger = cms.Service(
            "MessageLogger",
            destinations=cms.untracked.vstring("cout", "debug"),
            debugModules=cms.untracked.vstring("*"),
            cout=cms.untracked.PSet(threshold=cms.untracked.string("INFO")),
            debug=cms.untracked.PSet(threshold=cms.untracked.string("DEBUG")),
        )
        logging.basicConfig(level=logging.DEBUG)
    else:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger.cerr.FwkReport.reportEvery = 1000
        process.MessageLogger.cerr.threshold = cms.untracked.string("INFO")
        logging.basicConfig(level=logging.DEBUG)

    process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(options.maxEvents))

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

    import os
    from FWCore.PythonUtilities.LumiList import LumiList

    if not Config.isMC:
        ll1 = LumiList(
            os.environ["CMSSW_BASE"] + "/../crabs/lumis/Cert_190456-208686_8TeV_22Jan2013ReReco_Collisions12_JSON.txt"
        )

    process.source = cms.Source(
        "PoolSource",
        fileNames=cms.untracked.vstring(options.inputFiles),
        cacheSize=cms.untracked.uint32(50 * 1024 * 1024),
        lumisToProcess=ll1.getVLuminosityBlockRange() if not Config.isMC else cms.untracked.VLuminosityBlockRange(),
    )

    print options

    # -------------------------------------------------
    # Jets
    # -------------------------------------------------

    from SingleTopPolarization.Analysis.jets_step2_cfi import JetSetup

    JetSetup(process, Config)

    # -------------------------------------------------
    # Leptons
    # -------------------------------------------------

    from SingleTopPolarization.Analysis.muons_step2_cfi import MuonSetup

    MuonSetup(process, Config)

    from SingleTopPolarization.Analysis.electrons_step2_cfi import ElectronSetup

    ElectronSetup(process, Config)

    process.looseVetoMuCount = cms.EDProducer(
        "CollectionSizeProducer<reco::Candidate>", src=cms.InputTag("looseVetoMuons")
    )

    process.looseVetoEleCount = cms.EDProducer(
        "CollectionSizeProducer<reco::Candidate>", src=cms.InputTag("looseVetoElectrons")
    )

    process.decayTreeProducerMu = cms.EDProducer(
        "GenParticleDecayTreeProducer", src=cms.untracked.InputTag("singleIsoMu")
    )
    process.decayTreeProducerEle = cms.EDProducer(
        "GenParticleDecayTreeProducer", src=cms.untracked.InputTag("singleIsoEle")
    )

    # -----------------------------------------------
    # Top reco and cosine calcs
    # -----------------------------------------------

    from SingleTopPolarization.Analysis.top_step2_cfi import TopRecoSetup

    TopRecoSetup(process, Config)

    process.allEventObjects = cms.EDProducer(
        "CandRefCombiner",
        sources=cms.vstring(["goodJets", "goodSignalLeptons", Config.metSource]),
        maxOut=cms.uint32(9999),
        minOut=cms.uint32(0),
        logErrors=cms.bool(False),
    )

    process.hadronicEventObjects = cms.EDProducer(
        "CandRefCombiner",
        sources=cms.vstring(["goodJets"]),
        maxOut=cms.uint32(9999),
        minOut=cms.uint32(0),
        logErrors=cms.bool(False),
    )

    process.allEventObjectsWithNu = cms.EDProducer(
        "CandRefCombiner",
        sources=cms.vstring(["goodJets", "goodSignalLeptons", Config.metSource, "recoNuProducer"]),
        maxOut=cms.uint32(9999),
        minOut=cms.uint32(0),
        logErrors=cms.bool(False),
    )

    process.eventShapeVars = cms.EDProducer("EventShapeVarsProducer", src=cms.InputTag("allEventObjects"))

    process.eventShapeVarsWithNu = cms.EDProducer("EventShapeVarsProducer", src=cms.InputTag("allEventObjectsWithNu"))

    # Vector sum of all reconstructed objects
    process.shat = cms.EDProducer("SimpleCompositeCandProducer", sources=cms.VInputTag(["allEventObjects"]))

    # Hadronic final state
    process.ht = cms.EDProducer("SimpleCompositeCandProducer", sources=cms.VInputTag(["hadronicEventObjects"]))

    process.shatNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("shat"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        # eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection([["Pt", "pt"], ["Eta", "eta"], ["Phi", "phi"], ["Mass", "mass"]]),
    )

    process.htNTupleProducer = process.shatNTupleProducer.clone(src=cms.InputTag("ht"))

    process.eventShapeSequence = cms.Sequence(
        process.allEventObjects
        * process.hadronicEventObjects
        * process.eventShapeVars
        * process.allEventObjectsWithNu
        * process.eventShapeVarsWithNu
        * process.shat
        * process.ht
        * process.shatNTupleProducer
        * process.htNTupleProducer
    )

    # -----------------------------------------------
    # Treemaking
    # -----------------------------------------------

    process.recoTopNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("recoTop"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        # eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection([["Pt", "pt"], ["Eta", "eta"], ["Phi", "phi"], ["Mass", "mass"]]),
    )
    process.recoNuNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("recoNu"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        # eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["Px", "p4().Px()"],
                ["Py", "p4().Py()"],
                ["Pz", "p4().Pz()"],
            ]
        ),
    )

    process.recoWNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("recoW"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        variables=ntupleCollection([["Pt", "pt"], ["Eta", "eta"], ["Phi", "phi"], ["Mass", "mass"]]),
    )

    process.trueNuNTupleProducer = process.recoNuNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueNeutrino", "STPOLSEL2")
    )
    process.trueWNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueWboson", "STPOLSEL2")
    )
    process.trueTopNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueTop", "STPOLSEL2")
    )

    process.patMETDeltaRProducer = cms.EDProducer(
        "DeltaRProducerMET",
        muonSrc=cms.InputTag("goodSignalMuons"),
        electronSrc=cms.InputTag("goodSignalElectrons"),
        metSrc=cms.InputTag(Config.metSource),
    )

    process.patMETNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag(Config.metSource),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        variables=ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["Px", "p4().Px()"],
                ["Py", "p4().Py()"],
                ["Pz", "p4().Pz()"],
            ]
        ),
    )

    process.trueLeptonNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2")
    )

    process.trueLightJetNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLightJet", "STPOLSEL2")
    )

    def userfloat(key):
        return "? hasUserFloat('{0}') ? userFloat('{0}') : {1}".format(key, nanval)

    def userint(key):
        return "? hasUserInt('{0}') ? userInt('{0}') : {1}".format(key, nanval)

    process.goodSignalMuonsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("patMETDeltaRProducer", "muons"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        # eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["relIso", userfloat(Config.Muons.relIsoType)],
                ["Charge", "charge"],
                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : {0}".format(nanval)],
                ["motherGenPdgId", "? genParticlesSize() > 0 ? genParticle(0).mother(0).pdgId() : {0}".format(nanval)],
                ["normChi2", "? globalTrack().isNonnull() ? normChi2 : {0}".format(nanval)],
                [
                    "trackhitPatterntrackerLayersWithMeasurement",
                    userfloat("track_hitPattern_trackerLayersWithMeasurement"),
                ],
                [
                    "globalTrackhitPatternnumberOfValidMuonHits",
                    userfloat("globalTrack_hitPattern_numberOfValidMuonHits"),
                ],
                [
                    "innerTrackhitPatternnumberOfValidPixelHits",
                    userfloat("innerTrack_hitPattern_numberOfValidPixelHits"),
                ],
                ["db", "dB"],
                ["dz", userfloat("dz")],
                ["numberOfMatchedStations", "numberOfMatchedStations"],
                [
                    "triggerMatch",
                    "? triggerObjectMatchesByPath('{0}').size()==1 ? triggerObjectMatchByPath('{0}').hasPathLastFilterAccepted() : {1}".format(
                        Config.Muons.triggerPath, nanval
                    ),
                ],
                ["deltaRMET", userfloat("deltaRMET")],
                ["deltaPhiMET", userfloat("deltaPhiMET")],
            ]
        ),
    )

    process.isoMuonsNTP = process.goodSignalMuonsNTupleProducer.clone(src=cms.InputTag("muonsWithIso"))

    process.allMuonsNTP = process.goodSignalMuonsNTupleProducer.clone(src=cms.InputTag("muonsWithIDAll"))

    process.goodSignalElectronsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("patMETDeltaRProducer", "electrons"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        # eventInfo = cms.untracked.bool(True),
        variables=ntupleCollection(
            [
                ["Pt", "%s" % Config.Electrons.pt],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["relIso", userfloat(Config.Electrons.relIsoType)],
                ["mvaID", "electronID('mvaTrigV0')"],
                ["Charge", "charge"],
                ["superClustereta", "superCluster.eta"],
                ["passConversionVeto", "passConversionVeto()"],
                [
                    "gsfTracktrackerExpectedHitsInnernumberOfHits",
                    userint("gsfTrack_trackerExpectedHitsInner_numberOfHits"),
                ],
                [
                    "triggerMatch",
                    "? triggerObjectMatchesByPath('{0}').size()==1 ? triggerObjectMatchByPath('{0}').hasPathLastFilterAccepted() : {1}".format(
                        Config.Electrons.triggerPath, nanval
                    ),
                ],
                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : {0}".format(nanval)],
                ["motherGenPdgId", "? genParticlesSize() > 0 ? genParticle(0).mother(0).pdgId() : {0}".format(nanval)],
                ["deltaRMET", userfloat("deltaRMET")],
                ["deltaPhiMET", userfloat("deltaPhiMET")],
            ]
        ),
    )

    process.isoElectronsNTP = process.goodSignalElectronsNTupleProducer.clone(src=cms.InputTag("electronsWithIso"))

    process.allElectronsNTP = process.goodSignalElectronsNTupleProducer.clone(src=cms.InputTag("electronsWithIDAll"))

    process.goodJetsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src=cms.InputTag("goodJets"),
        lazyParser=cms.untracked.bool(True),
        prefix=cms.untracked.string(""),
        eventInfo=cms.untracked.bool(False),
        variables=ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["Mass", "mass"],
                # ["bDiscriminator", "bDiscriminator('%s')" % Config.Jets.bTagDiscriminant],
                ["bDiscriminatorTCHP", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.TCHP],
                ["bDiscriminatorCSV", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.CSV],
                ["rms", userfloat("rms")],
                ["partonFlavour", "partonFlavour()"],
                ["area", "jetArea()"],
                # These require PFCandidates to be present (huge collection)
                # ["n90", "n90()"],
                # ["n60", "n60()"],
                # ["genJetFlavour", "? genJet()>0 ? (genJet()->pdgId()) : 0"], #FIXME
                ["deltaR", userfloat("deltaR")],
                ["deltaPhi", userfloat("deltaPhi")],
                ["numberOfDaughters", "numberOfDaughters"],
                ["neutralHadronEnergy", "neutralHadronEnergy"],
                ["HFHadronEnergy", "HFHadronEnergy"],
                ["chargedEmEnergyFraction", "chargedEmEnergyFraction"],
                ["neutralEmEnergyFraction", "neutralEmEnergyFraction"],
                ["chargedHadronEnergyFraction", "chargedHadronEnergyFraction"],
                ["chargedMultiplicity", "chargedMultiplicity"],
                ["nParticles", userfloat("nParticles")],
                ["puMva", userfloat("mva")],
                ["nCharged", userfloat("nCharged")],
                ["nNeutral", userfloat("nNeutral")],
                ["deltaRMET", userfloat("deltaRMET")],
                ["deltaPhiMET", userfloat("deltaPhiMET")],
            ]
        ),
    )
    process.lowestBTagJetNTupleProducer = process.goodJetsNTupleProducer.clone(src=cms.InputTag("lowestBTagJet"))
    process.highestBTagJetNTupleProducer = process.goodJetsNTupleProducer.clone(src=cms.InputTag("highestBTagJet"))

    process.treeSequenceNew = cms.Sequence(
        process.patMETNTupleProducer
        * process.recoTopNTupleProducer
        * process.recoNuNTupleProducer
        * process.recoWNTupleProducer
        * process.trueTopNTupleProducer
        * process.trueNuNTupleProducer
        * process.trueWNTupleProducer
        * process.trueLeptonNTupleProducer
        * process.trueLightJetNTupleProducer
        * process.goodJetsNTupleProducer
        * process.lowestBTagJetNTupleProducer
        * process.highestBTagJetNTupleProducer
        * process.goodSignalMuonsNTupleProducer
        * process.goodSignalElectronsNTupleProducer
        * process.isoMuonsNTP
        * process.isoElectronsNTP
    )
    # -----------------------------------------------
    # Flavour analyzer
    # -----------------------------------------------

    Config.doWJetsFlavour = Config.isMC and sample_types.is_wjets(Config.subChannel) and not Config.isSherpa
    if Config.doWJetsFlavour:
        process.flavourAnalyzer = cms.EDProducer(
            "FlavourAnalyzer",
            genParticles=cms.InputTag("genParticles"),
            generator=cms.InputTag("generator"),
            genJets=cms.InputTag("selectedPatJets", "genJets"),
            saveGenJets=cms.bool(False),
            savePDFInfo=cms.bool(True),
        )

    # -----------------------------------------------
    # Paths
    # -----------------------------------------------

    from SingleTopPolarization.Analysis.hlt_step2_cfi import HLTSetup

    HLTSetup(process, Config)

    from SingleTopPolarization.Analysis.leptons_cfg import LeptonSetup

    LeptonSetup(process, Config)

    if Config.isMC:
        WeightSetup(process, Config)

    if Config.isMC and options.doGenParticlePath:
        if Config.isCompHep:
            from SingleTopPolarization.Analysis.partonStudy_comphep_step2_cfi import PartonStudySetup
        elif Config.isAMCatNLO:
            from SingleTopPolarization.Analysis.partonStudy_aMCatNLO_step2_cfi import PartonStudySetup
        else:
            from SingleTopPolarization.Analysis.partonStudy_step2_cfi import PartonStudySetup
        PartonStudySetup(process)
        process.partonPath = cms.Path()

        # NOTE: this path will REJECT events not having a true t-channel lepton
        if sample_types.is_signal(Config.subChannel):
            logging.warning(
                "Using signal-only sequence 'process.partonStudyTrueSequence' on subChannel=%s" % Config.subChannel
            )
            process.partonPath += process.partonStudyTrueSequence

    from SingleTopPolarization.Analysis.muons_step2_cfi import MuonPath

    MuonPath(process, Config)

    from SingleTopPolarization.Analysis.electrons_step2_cfi import ElectronPath

    ElectronPath(process, Config)

    if Config.isMC:
        process.muPath += process.weightSequence
        process.elePath += process.weightSequence

    if Config.isMC and sample_types.is_signal(Config.subChannel):
        process.muPath += process.partonStudyCompareSequence
        process.elePath += process.partonStudyCompareSequence

    process.treePath = cms.Path(process.treeSequenceNew)

    process.eventVarsPath = cms.Path(process.eventShapeSequence)

    # enable embedding the gen-level weight, which is relevant for the Sherpa sample
    if Config.isMC:
        process.genWeightProducer = cms.EDProducer("GenWeightProducer")
        process.eventVarsPath += process.genWeightProducer
        if Config.isAMCatNLO:
            process.lheWeightProducer = cms.EDProducer("LHEWeightProducer")
            process.eventVarsPath += process.lheWeightProducer

    if Config.doWJetsFlavour:
        process.treePath += process.flavourAnalyzer

    if Config.isMC:
        if not Config.isSherpa:
            process.meWeightProducer = cms.EDProducer("MEWeightProducer")
            process.eventVarsPath += process.meWeightProducer

        process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
        process.prunedGenParticles = cms.EDProducer(
            "GenParticlePruner",
            src=cms.InputTag("genParticles"),
            select=cms.vstring(
                "drop  *",
                "keep status = 3",  # keeps all particles from the hard matrix element
                "+keep abs(pdgId) = 15 & status = 1",  # keeps intermediate decaying tau
            ),
        )

        """process.pat2pxlio=cms.EDAnalyzer('EDM2PXLIO',
            SelectEventsFromProcess=cms.vstring("USER"),  
            SelectEventsFromPath = cms.vstring("p0"),
            OutFileName=cms.untracked.string("wjets.pxlio"),
            process=cms.untracked.string("test"),
    
            genCollection = cms.PSet(
                type=cms.string("GenParticle2Pxlio"),
                srcs=cms.VInputTag(cms.InputTag("prunedGenParticles")),
                EventInfo=cms.InputTag('generator')
            ),
            
            genJets = cms.PSet(
                type=cms.string("GenJet2Pxlio"),
                srcs=cms.VInputTag("ak5GenJets","kt4GenJets","kt6GenJets"),
                names=cms.vstring("AK5GenJets","KT4GenJets","KT6GenJets")
            ),
            
            q2weights = cms.PSet(
                type=cms.string("ValueList2Pxlio"),
                srcs=cms.VInputTag(
                    cms.InputTag("extraPartons","nExtraPartons"),
                ),
                names = cms.vstring("nExtraPartons")
            )
            
            
        )"""

        process.extraPartons = cms.EDProducer("ExtraPartonCounter", isTTJets=cms.bool("TTJets" in Config.subChannel))

        process.extraPartonSequence = cms.Sequence(process.prunedGenParticles * process.extraPartons)
        # process.pxlioOut=cms.EndPath(process.out*process.pat2pxlio)

        process.eventVarsPath += process.extraPartonSequence

    # -----------------------------------------------
    # Outpath
    # -----------------------------------------------
    process.out = cms.OutputModule(
        "PoolOutputModule",
        dropMetaData=cms.untracked.string("DROPPED"),
        splitLevel=cms.untracked.int32(99),
        fileName=cms.untracked.string(options.outputFile),
        SelectEvents=cms.untracked.PSet(SelectEvents=cms.vstring(["*"])),
        outputCommands=cms.untracked.vstring(
            "drop *",
            #'keep *',
            "keep edmMergeableCounter_*__*",
            "keep *_generator__*",
            #'keep *_genParticles__*', #hack for powheg PDF sets
            "keep edmTriggerResults_TriggerResults__*",
            "keep *_flavourAnalyzer_*_STPOLSEL2",
            "keep floats_*_*_STPOLSEL2",
            "keep double_*__STPOLSEL2",
            "keep float_*__STPOLSEL2",
            "keep double_*_*_STPOLSEL2",
            "keep float_*_*_STPOLSEL2",
            "keep int_*__STPOLSEL2",
            "keep int_*_*_STPOLSEL2",
            "keep int_*_*_*",
            "keep String_*_*_*",  # the decay trees
            "keep *_pdfInfo1_*_STPOLSEL2",
            "keep *_pdfInfo2_*_STPOLSEL2",
            "keep *_pdfInfo3_*_STPOLSEL2",
            "keep *_pdfInfo4_*_STPOLSEL2",
            "keep *_pdfInfo5_*_STPOLSEL2",
            #'keep *',
            #'keep *_recoTop_*_*',
            #'keep *_goodSignalMuons_*_*',
            #'keep *_goodSignalElectrons_*_*',
            #'keep *_goodJets_*_*',
            #'keep *_bTaggedJets_*_*',
            #'keep *_untaggedJets_*_*',
        ),
    )
    if Config.doDebug:
        process.out.outputCommands.append("keep *")
        process.debugpath = cms.Path(
            process.muAnalyzer * process.eleAnalyzer * process.jetAnalyzer * process.metAnalyzer
        )
    process.outpath = cms.EndPath(process.out)
    if Config.doSkim:
        process.out.SelectEvents.SelectEvents = []
    process.out.SelectEvents.SelectEvents.append("elePath")
    process.out.SelectEvents.SelectEvents.append("muPath")

    # -----------------------------------------------
    # Final printout
    # -----------------------------------------------

    if hasattr(process, "out"):
        print "Output patTuples: %s" % process.out.fileName.value()
    print 80 * "-"
    print "Step2 configured"

    return process
Esempio n. 4
0
def SingleTopStep2():

    if not Config.onGrid:
        options = VarParsing('analysis')
        options.register ('subChannel', 'T_t',
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "The sample that you are running on")
        options.register ('channel', 'signal',
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "Signal or Background")
        options.register ('reverseIsoCut', False,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Consider anti-isolated region")
        options.register ('doDebug', False,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Turn on debugging messages")
        options.register ('isMC', True,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Run on MC"
        )
        options.register ('doGenParticlePath', True,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Run the gen particle paths (only works on specific MC)"
        )
        options.register ('globalTag', Config.globalTagMC,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "Global tag"
        )
        options.register ('srcPUDistribution', "S10",
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "Source pile-up distribution"
        )
        options.register ('destPUDistribution', "data",
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "destination pile-up distribution"
        )

        options.register ('compHep', False,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Use CompHep-specific processing")

        options.register ('sherpa', False,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Use sherpa-specific processing")

        options.register ('systematic', "",
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "Apply Systematic variation")

        options.register ('doPDFWeights', True,
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.bool,
                  "Run the PDF weight generation module")

        options.register ('dataRun', "RunABCD",
                  VarParsing.multiplicity.singleton,
                  VarParsing.varType.string,
                  "A string Run{A,B,C,D} to specify the data period")

        options.parseArguments()


        if options.isMC:
            if options.channel.lower() == "signal":
                Config.channel = Config.Channel.signal
            elif options.channel.lower() == "background":
                Config.channel = Config.Channel.background
            Config.srcPUDistribution = pileUpDistributions.distributions[options.srcPUDistribution]
            Config.destPUDistribution = pileUpDistributions.distributions[options.destPUDistribution]
        else:
            Config.channel = "data"
            Config.subChannel = None


        Config.Leptons.reverseIsoCut = options.reverseIsoCut
        Config.subChannel = options.subChannel
        Config.doDebug = options.doDebug
        Config.isMC = options.isMC
        Config.isCompHep = options.compHep
        Config.isSherpa = options.sherpa
        Config.systematic = options.systematic
        Config.dataRun = options.dataRun
        print "Systematic! ",Config.systematic

    if Config.isMC:
        logging.info("Changing jet source from %s to smearedPatJetsWithOwnRef" % Config.Jets.source)
        Config.Jets.source = "smearedPatJetsWithOwnRef"

        if Config.systematic in ["ResUp", "ResDown"]:
             logging.info("Changing jet source from %s to smearedPatJetsWithOwnRef%s" % (Config.Jets.source, Config.systematic))
             Config.Jets.source = "smearedPatJetsWithOwnRef"+Config.systematic
             logging.info("Changing MET source from %s to patType1CorrectedPFMetJet%s" % (Config.metSource, Config.systematic))
             Config.metSource = "patType1CorrectedPFMetJet"+Config.systematic
        elif Config.systematic in ["EnUp", "EnDown"]:
             logging.info("Changing jet source from %s to shiftedPatJetsWithOwnRef%sForCorrMEt" % (Config.Jets.source, Config.systematic))
             Config.Jets.source = "shiftedPatJetsWithOwnRef"+Config.systematic+"ForCorrMEt"
             logging.info("Changing MET source from %s to patType1CorrectedPFMetJet%s" % (Config.metSource, Config.systematic))
             Config.metSource = "patType1CorrectedPFMetJet"+Config.systematic
        elif Config.systematic in ["UnclusteredEnUp", "UnclusteredEnDown"]:
             logging.info("Changing MET source from %s to patType1CorrectedPFMet%s" % (Config.metSource, Config.systematic))
             Config.metSource = "patType1CorrectedPFMet"+Config.systematic

    print "Configuration"
    print Config._toStr()

    print Config.Jets._toStr()
    print Config.Muons._toStr()
    print Config.Electrons._toStr()
    print ""

    process = cms.Process("STPOLSEL2")
    eventCounting.countProcessed(process)

    process.load("Configuration.Geometry.GeometryIdeal_cff")
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    from Configuration.AlCa.autoCond import autoCond
    process.GlobalTag.globaltag = cms.string(options.globalTag)
    process.load("Configuration.StandardSequences.MagneticField_cff")

    if Config.doDebug:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger = cms.Service("MessageLogger",
               destinations=cms.untracked.vstring('cout', 'debug'),
               debugModules=cms.untracked.vstring('*'),
               cout=cms.untracked.PSet(threshold=cms.untracked.string('INFO')),
               debug=cms.untracked.PSet(threshold=cms.untracked.string('DEBUG')),
        )
        logging.basicConfig(level=logging.DEBUG)
    else:
        process.load("FWCore.MessageLogger.MessageLogger_cfi")
        process.MessageLogger.cerr.FwkReport.reportEvery = 1000
        process.MessageLogger.cerr.threshold = cms.untracked.string("INFO")
        logging.basicConfig(level=logging.DEBUG)

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

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

    process.source = cms.Source("PoolSource",
        # replace 'myfile.root' with the source file you want to use
        fileNames=cms.untracked.vstring(""),
        cacheSize = cms.untracked.uint32(10*1024*1024),
    )


    #-------------------------------------------------
    # Jets
    #-------------------------------------------------

    from SingleTopPolarization.Analysis.jets_step2_cfi import JetSetup
    JetSetup(process, Config)

    #-------------------------------------------------
    # Leptons
    #-------------------------------------------------

    #Embed the corrected isolations to the leptons
    #process.muonClones = cms.EDProducer("MuonShallowCloneProducer",
    #    src = cms.InputTag(Config.Muons.source)
    #)
    process.skimmedMuons = cms.EDFilter("PtMinCandViewCloneSelector",
      src=cms.InputTag(Config.Muons.source), ptMin=cms.double(20)
    )
    process.muonsWithIso = cms.EDProducer(
      'MuonIsolationProducer',
      leptonSrc = cms.InputTag("skimmedMuons"),
      rhoSrc = cms.InputTag("kt6PFJets", "rho"),
      dR = cms.double(0.4)
    )
    process.muIsoSequence = cms.Sequence(process.skimmedMuons*process.muonsWithIso)

    process.skimmedElectrons = cms.EDFilter("PtMinCandViewCloneSelector",
      src=cms.InputTag(Config.Electrons.source), ptMin=cms.double(20)
    )
    process.elesWithIso = cms.EDProducer(
      'ElectronIsolationProducer',
      leptonSrc = cms.InputTag("skimmedElectrons"),
      rhoSrc = cms.InputTag("kt6PFJets", "rho"),
      dR = cms.double(0.3)
    )
    process.eleIsoSequence = cms.Sequence(process.skimmedElectrons*process.elesWithIso)

    from SingleTopPolarization.Analysis.muons_step2_cfi import MuonSetup
    MuonSetup(process, Config)

    from SingleTopPolarization.Analysis.electrons_step2_cfi import ElectronSetup
    ElectronSetup(process, Config)

    process.looseVetoMuCount = cms.EDProducer(
        "CollectionSizeProducer<reco::Candidate>",
        src = cms.InputTag("looseVetoMuons")
    )

    process.looseVetoEleCount = cms.EDProducer(
        "CollectionSizeProducer<reco::Candidate>",
        src = cms.InputTag("looseVetoElectrons")
    )


    #Combine the found electron/muon to a single collection
    process.goodSignalLeptons = cms.EDProducer(
         'CandRefCombiner',
         sources=cms.untracked.vstring(["singleIsoMu", "singleIsoEle"]),
             maxOut=cms.untracked.uint32(1),
             minOut=cms.untracked.uint32(1)
    )

    process.decayTreeProducerMu = cms.EDProducer(
        'GenParticleDecayTreeProducer',
        src=cms.untracked.InputTag("singleIsoMu")
    )
    process.decayTreeProducerEle = cms.EDProducer(
        'GenParticleDecayTreeProducer',
        src=cms.untracked.InputTag("singleIsoEle")
    )

    #-----------------------------------------------
    # Top reco and cosine calcs
    #-----------------------------------------------

    from SingleTopPolarization.Analysis.top_step2_cfi import TopRecoSetup
    TopRecoSetup(process)

    #-----------------------------------------------
    # Treemaking
    #-----------------------------------------------


    def treeCollection(collection_, maxElems_, varlist):
        varVPSet = cms.untracked.VPSet()
        for v in varlist:
            pset = cms.untracked.PSet(tag=cms.untracked.string(v[0]), expr=cms.untracked.string(v[1]), )
            varVPSet.append(pset)
        ret = cms.untracked.PSet(
            collection=collection_,
            maxElems=cms.untracked.int32(maxElems_),
            variables=varVPSet
        )
        return ret

    def ntupleCollection(items):
        varVPSet = cms.VPSet()
        for item in items:
            pset = cms.untracked.PSet(
                tag=cms.untracked.string(item[0]),
                quantity=cms.untracked.string(item[1])
            )
            varVPSet.append(pset)
        return varVPSet

    #Following treemakers for reference only, not to be used. Use CandViewNtpProducer2 instead! --joosep
    #process.treesMu = cms.EDAnalyzer('MuonCandViewTreemakerAnalyzer',
    #    collections = cms.untracked.VPSet(
    #        treeCollection(
    #            cms.untracked.InputTag("muonsWithIso"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["relIso", "userFloat('%s')" % Config.Muons.relIsoType],
    #                ["Charge", "charge"],
    #                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"],
    #                ["normChi2", "? globalTrack().isNonnull() ? normChi2 : -1.0"],
    #                ["track_hitPattern_trackerLayersWithMeasurement", "userFloat('track_hitPattern_trackerLayersWithMeasurement')"],
    #                ["globalTrack_hitPattern_numberOfValidMuonHits", "userFloat('globalTrack_hitPattern_numberOfValidMuonHits')"],
    #                ["innerTrack_hitPattern_numberOfValidPixelHits", "userFloat('innerTrack_hitPattern_numberOfValidPixelHits')"],
    #                ["db", "dB"],
    #                ["dz", "userFloat('dz')"],
    #                ["numberOfMatchedStations", "numberOfMatchedStations"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("goodSignalMuons"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["relIso", "userFloat('%s')" % Config.Muons.relIsoType],
    #                ["Charge", "charge"],
    #                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("looseVetoMuons"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["relIso", "userFloat('%s')" % Config.Muons.relIsoType],
    #                ["Charge", "charge"],
    #                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"],
    #            ]
    #        )
    #    )
    #)

    #process.treesEle = cms.EDAnalyzer('ElectronCandViewTreemakerAnalyzer',
    #    collections = cms.untracked.VPSet(
    #        treeCollection(
    #            cms.untracked.InputTag("elesWithIso"), 1,
    #            [
    #                ["Pt", "%s" % Config.Electrons.pt],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["relIso", "userFloat('%s')" % Config.Electrons.relIsoType],
    #                ["mvaID", "electronID('mvaTrigV0')"],
    #                ["Charge", "charge"],
    #                ["superCluster_eta", "superCluster.eta"],
    #                ["passConversionVeto", "passConversionVeto()"],
    #                ["superCluster_eta", "superCluster.eta"],
    #                ["gsfTrack_trackerExpectedHitsInner_numberOfHits", "userInt('gsfTrack_trackerExpectedHitsInner_numberOfHits')"]
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("goodSignalElectrons"), 1,
    #            [
    #                ["Pt", "%s" % Config.Electrons.pt],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["relIso", "userFloat('%s')" % Config.Electrons.relIsoType],
    #                ["mvaID", "electronID('mvaTrigV0')"],
    #                ["Charge", "charge"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("looseVetoElectrons"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["relIso", "userFloat('%s')" % Config.Electrons.relIsoType],
    #                ["Charge", "charge"],
    #                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"],
    #            ]
    #        )
    #    )
    #)
    #process.treesJets = cms.EDAnalyzer('JetCandViewTreemakerAnalyzer',
    #        collections = cms.untracked.VPSet(
    #        #all the selected jets in events, passing the reference selection cuts, ordered pt-descending
    #        treeCollection(
    #            cms.untracked.InputTag("goodJets"), 5,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Mass", "mass"],
    #                ["bDiscriminator", "bDiscriminator('%s')" % Config.Jets.bTagDiscriminant],
    #                ["bDiscriminatorTCHP", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.TCHP],
    #                ["bDiscriminatorCSV_MVA", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.CSV_MVA],
    #                ["rms", "userFloat('rms')"],
    #                ["partonFlavour", "partonFlavour()"],
    #                ["deltaR", "userFloat('deltaR')"]
    #            ]
    #        ),
    #        # treeCollection(
    #        #     cms.untracked.InputTag("fwdMostLightJet"), 1,
    #        #     [
    #        #         ["Pt", "pt"],
    #        #         ["Eta", "eta"],
    #        #         ["Phi", "phi"],
    #        #         ["Mass", "mass"],
    #        #         ["bDiscriminator", "bDiscriminator('combinedSecondaryVertexBJetTags')"],
    #        #         ["rms", "userFloat('rms')"]
    #        #     ]
    #        # ),

    #        #the tagged jet with the highest b-discriminator value (== THE b-jet)
    #        treeCollection(
    #            cms.untracked.InputTag("highestBTagJet"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Mass", "mass"],
    #                ["bDiscriminator", "bDiscriminator('%s')" % Config.Jets.bTagDiscriminant],
    #                ["bDiscriminatorTCHP", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.TCHP],
    #                ["bDiscriminatorCSV_MVA", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.CSV_MVA],
    #                ["rms", "userFloat('rms')"],
    #                ["partonFlavour", "partonFlavour()"],
    #                ["deltaR", "userFloat('deltaR')"]
    #            ]
    #        ),

    #        #The jet with the lowest b-discriminator value (== THE light jet)
    #        treeCollection(
    #            cms.untracked.InputTag("lowestBTagJet"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Mass", "mass"],
    #                ["bDiscriminator", "bDiscriminator('%s')" % Config.Jets.bTagDiscriminant],
    #                ["bDiscriminatorTCHP", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.TCHP],
    #                ["bDiscriminatorCSV_MVA", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.CSV_MVA],
    #                ["rms", "userFloat('rms')"],
    #                ["partonFlavour", "partonFlavour()"],
    #                ["deltaR", "userFloat('deltaR')"]
    #            ]
    #        ),

    #    #all the b-tagged jets in the event, ordered pt-descending
    #        treeCollection(
    #            cms.untracked.InputTag("btaggedJets"), Config.Jets.nBTags,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Mass", "mass"],
    #                ["bDiscriminator", "bDiscriminator('%s')" % Config.Jets.bTagDiscriminant],
    #                ["bDiscriminatorTCHP", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.TCHP],
    #                ["bDiscriminatorCSV_MVA", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.CSV_MVA],
    #                ["rms", "userFloat('rms')"],
    #                ["partonFlavour", "partonFlavour()"],
    #                ["deltaR", "userFloat('deltaR')"]
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("untaggedJets"), Config.Jets.nJets-Config.Jets.nBTags,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Mass", "mass"],
    #                ["bDiscriminator", "bDiscriminator('%s')" % Config.Jets.bTagDiscriminant],
    #                ["bDiscriminatorTCHP", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.TCHP],
    #                ["bDiscriminatorCSV_MVA", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.CSV_MVA],
    #                ["rms", "userFloat('rms')"],
    #                ["partonFlavour", "partonFlavour()"],
    #                ["deltaR", "userFloat('deltaR')"]
    #            ]
    #        )
    #    )
    #)



    ##process.treesEle = cms.EDAnalyzer('ElectronCandViewTreemakerAnalyzer',
    ##        collections = cms.untracked.VPSet(treeCollection("goodSignalElectrons", 1,
    ##            [
    ##                ["Pt", "pt"],
    ##                ["Eta", "eta"],
    ##                ["Phi", "phi"],
    ##                ["rhoCorrRelIso", "userFloat('rhoCorrRelIso')"],
    ##            ]
    ##            )
    ##        )
    ##)

    #process.treesCands = cms.EDAnalyzer('CandViewTreemakerAnalyzer',
    #        collections = cms.untracked.VPSet(
    #        treeCollection(
    #            cms.untracked.InputTag("recoTop"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Mass", "mass"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("recoNu"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Px", "p4().Px()"],
    #                ["Py", "p4().Py()"],
    #                ["Pz", "p4().Pz()"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("genParticleSelector", "trueTop", "STPOLSEL2"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Mass", "mass"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("genParticleSelector", "trueNeutrino", "STPOLSEL2"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #                ["Px", "p4().Px()"],
    #                ["Py", "p4().Py()"],
    #                ["Pz", "p4().Pz()"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("genParticleSelector", "trueLightJet", "STPOLSEL2"), 1,
    #            [
    #                ["Pt", "pt"],
    #                ["Eta", "eta"],
    #                ["Phi", "phi"],
    #            ]
    #        ),
    #        treeCollection(
    #            cms.untracked.InputTag("patMETs"), 1,
    #            [
    #                ["Pt", "pt"],
    #            ]
    #        ),
    #    )
    #)

    #process.treesDouble = cms.EDAnalyzer("FloatTreemakerAnalyzer",
    #    collections = cms.VInputTag(
    #        #Merged cosTheta*
    #        cms.InputTag("cosTheta", "cosThetaLightJet"),

    #        #cosTheta* separately from mu and ele
    #        #cms.InputTag("cosThetaProducerEle", "cosThetaLightJet"),
    #        #cms.InputTag("cosThetaProducerMu", "cosThetaLightJet"),

    #        #cosTheta* from gen
    #        cms.InputTag("cosThetaProducerTrueTop", "cosThetaLightJet"),
    #        cms.InputTag("cosThetaProducerTrueLepton", "cosThetaLightJet"),
    #        cms.InputTag("cosThetaProducerTrueJet", "cosThetaLightJet"),
    #        cms.InputTag("cosThetaProducerTrueAll", "cosThetaLightJet"),

    #        cms.InputTag("puWeightProducer", "nVerticesTrue"),

    #        #Transverse mass of MET and lepton
    #        cms.InputTag("muAndMETMT", ""),
    #        cms.InputTag("eleAndMETMT", ""),

    #        ##B-tag systematics
    #        #cms.InputTag("bTagWeightProducer", "bTagWeight"),
    #        #cms.InputTag("bTagWeightProducer", "bTagWeightSystBCUp"),
    #        #cms.InputTag("bTagWeightProducer", "bTagWeightSystBCDown"),
    #        #cms.InputTag("bTagWeightProducer", "bTagWeightSystLUp"),
    #        #cms.InputTag("bTagWeightProducer", "bTagWeightSystLDown"),


    #        #Some debugging data
    #        #cms.InputTag("kt6PFJets", "rho", "RECO"),
    #        #cms.InputTag("recoNu", "Delta"),
    #    )
    #)

    #process.treesDoubleWeight = cms.EDAnalyzer("FloatTreemakerAnalyzer",
    #    defaultValue = cms.untracked.double(0),
    #    putNaNs = cms.untracked.bool(False),
    #    collections = cms.VInputTag(
    #        #B-tag systematics
    #        cms.InputTag("bTagWeightProducerNJMT", "bTagWeight"),
    #        cms.InputTag("bTagWeightProducerNJMT", "bTagWeightSystBCUp"),
    #        cms.InputTag("bTagWeightProducerNJMT", "bTagWeightSystBCDown"),
    #        cms.InputTag("bTagWeightProducerNJMT", "bTagWeightSystLUp"),
    #        cms.InputTag("bTagWeightProducerNJMT", "bTagWeightSystLDown"),

    #        #cms.InputTag("bTagWeightProducer2J1T", "bTagWeight"),
    #        #cms.InputTag("bTagWeightProducer2J1T", "bTagWeightSystBCUp"),
    #        #cms.InputTag("bTagWeightProducer2J1T", "bTagWeightSystBCDown"),
    #        #cms.InputTag("bTagWeightProducer2J1T", "bTagWeightSystLUp"),
    #        #cms.InputTag("bTagWeightProducer2J1T", "bTagWeightSystLDown"),

    #        #cms.InputTag("bTagWeightProducer2J0T", "bTagWeight"),
    #        #cms.InputTag("bTagWeightProducer2J0T", "bTagWeightSystBCUp"),
    #        #cms.InputTag("bTagWeightProducer2J0T", "bTagWeightSystBCDown"),
    #        #cms.InputTag("bTagWeightProducer2J0T", "bTagWeightSystLUp"),
    #        #cms.InputTag("bTagWeightProducer2J0T", "bTagWeightSystLDown"),

    #        #cms.InputTag("bTagWeightProducer3J0T", "bTagWeight"),
    #        #cms.InputTag("bTagWeightProducer3J0T", "bTagWeightSystBCUp"),
    #        #cms.InputTag("bTagWeightProducer3J0T", "bTagWeightSystBCDown"),
    #        #cms.InputTag("bTagWeightProducer3J0T", "bTagWeightSystLUp"),
    #        #cms.InputTag("bTagWeightProducer3J0T", "bTagWeightSystLDown"),

    #        #cms.InputTag("bTagWeightProducer3J1T", "bTagWeight"),
    #        #cms.InputTag("bTagWeightProducer3J1T", "bTagWeightSystBCUp"),
    #        #cms.InputTag("bTagWeightProducer3J1T", "bTagWeightSystBCDown"),
    #        #cms.InputTag("bTagWeightProducer3J1T", "bTagWeightSystLUp"),
    #        #cms.InputTag("bTagWeightProducer3J1T", "bTagWeightSystLDown"),

    #        #cms.InputTag("puWeightProducer", "PUWeightN0"),
    #        cms.InputTag("puWeightProducer", "PUWeightNtrue"),

    #        cms.InputTag("muonWeightsProducer", "muonIDWeight"),
    #        cms.InputTag("muonWeightsProducer", "muonIDWeightUp"),
    #        cms.InputTag("muonWeightsProducer", "muonIDWeightDown"),
    #        cms.InputTag("muonWeightsProducer", "muonIsoWeight"),
    #        cms.InputTag("muonWeightsProducer", "muonIsoWeightUp"),
    #        cms.InputTag("muonWeightsProducer", "muonIsoWeightDown")
    #    )
    #)

    #process.treesBool = cms.EDAnalyzer("BoolTreemakerAnalyzer",
    #    collections = cms.VInputTag(
    #        cms.InputTag("ecalLaserCorrFilter", "", "PAT"),
    #    )
    #)

    #process.treesInt = cms.EDAnalyzer("IntTreemakerAnalyzer",
    #    collections = cms.VInputTag(
    #        [
    #        #cms.InputTag("recoNuProducerMu", "solType"),
    #        #cms.InputTag("recoNuProducerEle ", "solType"),
    #        cms.InputTag("muonCount"),
    #        cms.InputTag("electronCount"),
    #        cms.InputTag("topCount"),
    #        cms.InputTag("bJetCount"),
    #        cms.InputTag("lightJetCount"),

    #        cms.InputTag("looseVetoMuCount"),
    #        cms.InputTag("looseVetoEleCount"),

    #        cms.InputTag("btaggedTrueBJetCount"),
    #        cms.InputTag("trueBJetCount"),
    #        cms.InputTag("btaggedTrueCJetCount"),
    #        cms.InputTag("trueCJetCount"),
    #        cms.InputTag("btaggedTrueLJetCount"),
    #        cms.InputTag("trueLJetCount"),

    #        cms.InputTag("eventIDProducer", "eventId"),
    #        cms.InputTag("eventIDProducer", "runId"),
    #        cms.InputTag("eventIDProducer", "lumiId"),

    #        cms.InputTag("offlinePVCount"),

    #        cms.InputTag("genLeptonsTCount"),
    #        cms.InputTag("trueLeptonPdgId")
    #        ]
    #    )
    #)

    #process.treeSequence = cms.Sequence(process.treesMu*process.treesEle*process.treesDouble*process.treesBool*process.treesCands*process.treesJets*process.treesInt*process.treesDoubleWeight)

    process.recoTopNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag("recoTop"),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables = ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["Mass", "mass"],
            ]
      )
    )
    process.recoNuNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag("recoNu"),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables = ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["Px", "p4().Px()"],
                ["Py", "p4().Py()"],
                ["Pz", "p4().Pz()"],
            ]
      )
    )

    process.trueNuNTupleProducer = process.recoNuNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueNeutrino", "STPOLSEL2"),
    )
    if Config.isCompHep:
        process.trueTopNTupleProducer = process.recoTopNTupleProducer.clone(
            src=cms.InputTag("recoTrueTop"),
        )
    else:
        process.trueTopNTupleProducer = process.recoTopNTupleProducer.clone(
            src=cms.InputTag("genParticleSelector", "trueTop", "STPOLSEL2"),
        )
    process.patMETNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag(Config.metSource),
    )
    process.trueLeptonNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLepton", "STPOLSEL2"),
    )

    process.trueLightJetNTupleProducer = process.recoTopNTupleProducer.clone(
        src=cms.InputTag("genParticleSelector", "trueLightJet", "STPOLSEL2"),
    )
    process.goodSignalMuonsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag("goodSignalMuons"),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables = ntupleCollection(
            [
                ["Pt", "pt"],
                ["Eta", "eta"],
                ["Phi", "phi"],
                ["relIso", "userFloat('%s')" % Config.Muons.relIsoType],
                ["Charge", "charge"],
                ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"],
                ["motherGenPdgId", "? genParticlesSize() > 0 ? genParticle(0).mother(0).pdgId() : 0"],
                ["normChi2", "? globalTrack().isNonnull() ? normChi2 : -1.0"],
                ["trackhitPatterntrackerLayersWithMeasurement", "userFloat('track_hitPattern_trackerLayersWithMeasurement')"],
                ["globalTrackhitPatternnumberOfValidMuonHits", "userFloat('globalTrack_hitPattern_numberOfValidMuonHits')"],
                ["innerTrackhitPatternnumberOfValidPixelHits", "userFloat('innerTrack_hitPattern_numberOfValidPixelHits')"],
                ["db", "dB"],
                ["dz", "userFloat('dz')"],
                ["numberOfMatchedStations", "numberOfMatchedStations"],
            ]
      )
    )
    process.goodSignalElectronsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag("goodSignalElectrons"),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        #eventInfo = cms.untracked.bool(True),
        variables = ntupleCollection(
                [
                    ["Pt", "%s" % Config.Electrons.pt],
                    ["Eta", "eta"],
                    ["Phi", "phi"],
                    ["relIso", "userFloat('%s')" % Config.Electrons.relIsoType],
                    ["mvaID", "electronID('mvaTrigV0')"],
                    ["Charge", "charge"],
                    ["superClustereta", "superCluster.eta"],
                    ["passConversionVeto", "passConversionVeto()"],
                    ["gsfTracktrackerExpectedHitsInnernumberOfHits", "userInt('gsfTrack_trackerExpectedHitsInner_numberOfHits')"],
                    ["genPdgId", "? genParticlesSize() > 0 ? genParticle(0).pdgId() : 0"],
                    ["motherGenPdgId", "? genParticlesSize() > 0 ? genParticle(0).mother(0).pdgId() : 0"],
                ]
      )
    )
    process.goodJetsNTupleProducer = cms.EDProducer(
        "CandViewNtpProducer2",
        src = cms.InputTag("goodJets"),
        lazyParser = cms.untracked.bool(True),
        prefix = cms.untracked.string(""),
        eventInfo = cms.untracked.bool(False),
        variables = ntupleCollection(
                [
                    ["Pt", "pt"],
                    ["Eta", "eta"],
                    ["Phi", "phi"],
                    ["Mass", "mass"],
                    #["bDiscriminator", "bDiscriminator('%s')" % Config.Jets.bTagDiscriminant],
                    ["bDiscriminatorTCHP", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.TCHP],
                    #["bDiscriminatorCSV_MVA", "bDiscriminator('%s')" % Config.Jets.BTagDiscriminant.CSV_MVA],
                    ["rms", "userFloat('rms')"],
                    ["partonFlavour", "partonFlavour()"],
                    ["area", "jetArea()"],

                    #These require PFCandidates to be present (huge collection)
                    #["n90", "n90()"],
                    #["n60", "n60()"],

                    #["genJetFlavour", "? genJet()>0 ? (genJet()->pdgId()) : 0"], #FIXME
                    ["deltaR", "userFloat('deltaR')"],

                    ["numberOfDaughters", "numberOfDaughters"],
                    ["neutralHadronEnergy", "neutralHadronEnergy"],
                    ["HFHadronEnergy", "HFHadronEnergy"],
                    ["chargedEmEnergyFraction", "chargedEmEnergyFraction"],
                    ["neutralEmEnergyFraction", "neutralEmEnergyFraction"],
                    ["chargedHadronEnergyFraction", "chargedHadronEnergyFraction"],
                    ["chargedMultiplicity", "chargedMultiplicity"],
                    ["nParticles", "userFloat('nParticles')"],
                    ["puMva", "userFloat('mva')"],
                    ["nCharged", "userFloat('nCharged')"],
                    ["nNeutral", "userFloat('nNeutral')"],
                ]
        )
    )
    process.lowestBTagJetNTupleProducer = process.goodJetsNTupleProducer.clone(src=cms.InputTag("lowestBTagJet"))
    process.highestBTagJetNTupleProducer = process.goodJetsNTupleProducer.clone(src=cms.InputTag("highestBTagJet"))

    process.treeSequenceNew = cms.Sequence(
        process.patMETNTupleProducer *
        process.recoTopNTupleProducer *
        process.recoNuNTupleProducer *
        process.trueTopNTupleProducer *
        process.trueNuNTupleProducer *
        process.trueLeptonNTupleProducer *
        process.trueLightJetNTupleProducer *
        process.goodJetsNTupleProducer *
        process.lowestBTagJetNTupleProducer *
        process.highestBTagJetNTupleProducer *
        process.goodSignalMuonsNTupleProducer *
        process.goodSignalElectronsNTupleProducer
    )
    #-----------------------------------------------
    # Flavour analyzer
    #-----------------------------------------------

    Config.doWJetsFlavour = Config.isMC and Config.subChannel.lower() == "wjets" and not Config.isSherpa
    if Config.doWJetsFlavour:
        process.flavourAnalyzer = cms.EDProducer('FlavourAnalyzer',
            genParticles = cms.InputTag('genParticles'),
            generator = cms.InputTag('generator'),
            genJets = cms.InputTag('selectedPatJets', 'genJets'),
            saveGenJets = cms.bool(False),
            savePDFInfo = cms.bool(True)
        )


    #-----------------------------------------------
    # Paths
    #-----------------------------------------------

    from SingleTopPolarization.Analysis.hlt_step2_cfi import HLTSetup
    HLTSetup(process, Config)

    if Config.isMC and options.doPDFWeights:
        process.PDFweights = cms.EDProducer('PDFweightsProducer')
        process.pdfPath = cms.Path(
              process.PDFweights
        )


    if Config.doDebug:
        from SingleTopPolarization.Analysis.debugAnalyzers_step2_cfi import DebugAnalyzerSetup
        DebugAnalyzerSetup(process)

    process.looseVetoMuCount = cms.EDProducer(
        "CollectionSizeProducer<reco::Candidate>",
        src = cms.InputTag("looseVetoMuons")
    )

    process.looseVetoElectronCount = cms.EDProducer(
        "CollectionSizeProducer<reco::Candidate>",
        src = cms.InputTag("looseVetoElectrons")
    )

    if Config.isMC and options.doGenParticlePath:
        if Config.isCompHep:
            from SingleTopPolarization.Analysis.partonStudy_comphep_step2_cfi import PartonStudySetup
        else:
            from SingleTopPolarization.Analysis.partonStudy_step2_cfi import PartonStudySetup
        PartonStudySetup(process)
        process.partonPath = cms.Path()
        #process.partonPath = cms.Path(process.commonPartonSequence)
        if Config.channel==Config.Channel.signal:
            process.partonPath += process.partonStudyTrueSequence

    if Config.doMuon:
        from SingleTopPolarization.Analysis.muons_step2_cfi import MuonPath
        MuonPath(process, Config)
        process.muPath.insert(process.muPath.index(process.singleIsoMu)+1, process.goodSignalLeptons)
        process.muPath.insert(process.muPath.index(process.looseVetoMuons)+1, process.looseVetoMuCount)
        process.muPath.insert(process.muPath.index(process.looseVetoElectrons)+1, process.looseVetoEleCount)

    if Config.doElectron:
        from SingleTopPolarization.Analysis.electrons_step2_cfi import ElectronPath
        ElectronPath(process, Config)
        process.elePath.insert(process.elePath.index(process.singleIsoEle)+1, process.goodSignalLeptons)
        process.elePath.insert(process.elePath.index(process.looseVetoMuons)+1, process.looseVetoMuCount)
        process.elePath.insert(process.elePath.index(process.looseVetoElectrons)+1, process.looseVetoEleCount)

    if Config.isMC:
        process.puWeightProducer = cms.EDProducer('PUWeightProducer'
            , maxVertices = cms.uint32(50)
            , srcDistribution = cms.vdouble(Config.srcPUDistribution)
            , destDistribution = cms.vdouble(Config.destPUDistribution)
        )
        if Config.doMuon:
             process.muPath.insert(0, process.puWeightProducer)
        if Config.doElectron:
             process.elePath.insert(0, process.puWeightProducer)


#    process.offlinePVCount = cms.EDProducer(
#        "CollectionSizeProducer<reco::Vertex>",
#        src = cms.InputTag("offlinePrimaryVertices")
#    )

    process.eventIDProducer = cms.EDProducer('EventIDProducer'
    )
    process.treePath = cms.Path(
        process.eventIDProducer *
        #process.offlinePVCount *
       # process.treeSequence *
        process.treeSequenceNew
    )

    if Config.doWJetsFlavour:
        process.treePath += process.flavourAnalyzer


    #-----------------------------------------------
    # Outpath
    #-----------------------------------------------
    if not Config.skipPatTupleOutput:
        process.out = cms.OutputModule("PoolOutputModule",
            dropMetaData=cms.untracked.string("DROPPED"),
            splitLevel=cms.untracked.int32(99),
            fileName=cms.untracked.string('out_step2.root'),
             SelectEvents=cms.untracked.PSet(
                 SelectEvents=cms.vstring(["*"])
             ),
            outputCommands=cms.untracked.vstring(
                #'drop *',
                'drop *',
                'keep edmMergeableCounter_*__*',
                'keep *_generator__*',
                'keep edmTriggerResults_TriggerResults__*',
                'keep *_flavourAnalyzer_*_STPOLSEL2',
                'keep floats_patMETNTupleProducer_*_STPOLSEL2',
                'keep floats_recoTopNTupleProducer_*_STPOLSEL2',
                'keep floats_recoNuNTupleProducer_*_STPOLSEL2',
                'keep floats_trueTopNTupleProducer_*_STPOLSEL2',
                'keep floats_trueNuNTupleProducer_*_STPOLSEL2',
                'keep floats_trueLeptonNTupleProducer_*_STPOLSEL2',
                'keep floats_goodSignalMuonsNTupleProducer_*_STPOLSEL2',
                'keep floats_goodSignalElectronsNTupleProducer_*_STPOLSEL2',
                'keep floats_goodJetsNTupleProducer_*_STPOLSEL2',
                'keep floats_lowestBTagJetNTupleProducer_*_STPOLSEL2',
                'keep floats_highestBTagJetNTupleProducer_*_STPOLSEL2',
                'keep double_*__STPOLSEL2',
                'keep float_*__STPOLSEL2',
                'keep double_*_*_STPOLSEL2',
                'keep float_*_*_STPOLSEL2',
                'keep double_cosTheta_*_STPOLSEL2',
                'keep double_cosThetaProducerTrueAll_*_STPOLSEL2',
                'keep double_cosThetaProducerTrueTop_*_STPOLSEL2',
                'keep double_cosThetaProducerTrueLepton_*_STPOLSEL2',
                'keep double_cosThetaProducerTrueJet_*_STPOLSEL2',
                'keep *_bTagWeightProducerNJMT_*_STPOLSEL2',
                'keep int_*__STPOLSEL2',
                'keep int_*_*_STPOLSEL2',
                'keep int_*_*_*',
                'keep String_*_*_*', #the decay trees
                'keep *_pdfInfo1_*_STPOLSEL2',
                'keep *_pdfInfo2_*_STPOLSEL2',
                'keep *_pdfInfo3_*_STPOLSEL2',
                'keep *_pdfInfo4_*_STPOLSEL2',
                'keep *_pdfInfo5_*_STPOLSEL2',
                #'keep *',
                #'keep *_recoTop_*_*',
                #'keep *_goodSignalMuons_*_*',
                #'keep *_goodSignalElectrons_*_*',
                #'keep *_goodJets_*_*',
                #'keep *_bTaggedJets_*_*',
                #'keep *_untaggedJets_*_*',
            )
        )
        process.outpath = cms.EndPath(process.out)
        if Config.doElectron:
            process.out.SelectEvents.SelectEvents.append("elePath")
        if Config.doMuon:
            process.out.SelectEvents.SelectEvents.append("muPath")

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

    #Command-line arguments
    if not Config.onGrid:
        process.source.fileNames = cms.untracked.vstring(options.inputFiles)
        process.maxEvents = cms.untracked.PSet(
          input = cms.untracked.int32(options.maxEvents)
        )
        if hasattr(process, "out"):
            process.out.fileName = cms.untracked.string(options.outputFile)
        outFile = options.outputFile
        #from SingleTopPolarization.Analysis.cmdlineParsing import enableCommandLineArguments
        #(inFiles, outFile) = enableCommandLineArguments(process)
    else:
        outFile = "step2.root"

    #process.TFileService = cms.Service(
    #    "TFileService",
    #    fileName=cms.string(outFile.replace(".root", "_trees.root")),
    #)

    #print "Output trees: %s" % process.TFileService.fileName.value()
    if hasattr(process, "out"):
        print "Output patTuples: %s" % process.out.fileName.value()
    print 80*"-"
    print "Step2 configured"

    return process