def useTreesAsOutput(process):
    from PhysicsTools.PatAlgos.tools.helpers import listModules
    for mod in listModules(process.analyseFullHadronicSelection):
        if(hasattr(mod, 'analyze')):
            if(hasattr(mod.analyze, 'useTree')):
                mod.analyze.useTree = True
            if(hasattr(mod, 'useTree')):
                mod.useTree = True
Exemple #2
0
def applySelection( process, collection, cut, selectorTemplate, filter=False):
    result = []
    modules = [collection] # in case we got a single module
    if "visit" in dir(collection): #in case we got a sequence or the like
        modules = listModules(collection)
    for module in modules:
        #make sure selectornames are unique
        i = 0
        while "selection%s%i"%(module.label(), i) in  process.filterNames().split(): i+= 1
        selectorLabel="selection%s%i"%(module.label(), i)
        #add selector NOTE: different names than "src" and "cut" not supported yet...
        # NOTE2: this supposes that the source for the nTupler is called "InputTag" which is consitantly the case. However some more intelligent things are possible, if needed.
        process.__setattr__(selectorLabel, selectorTemplate.clone(
                src = deepcopy(module.InputTag),
                cut = cut,
                filter = cms.bool(filter) #need cms.bool here because PAT _cfi.py do not include it :\
                )
                            )
        module.InputTag = selectorLabel
        result.append(process.__getattribute__(selectorLabel))
    return result
Exemple #3
0
    'keep recoTracks_generalTracks_*_TANC',
    'keep recoTracks_electronGsfTracks_*_TANC',
    'keep *_genParticles_*_*',  # this product is okay, since we dont' need it in bkg
    'keep *_selectedTrueHadronicTaus_*_*',
    'keep *_preselectedSignalJets_*_*',
    #'keep *_signalJetsRecoTauPiZeros_*_*',
    # These two products are needed to make signal content a superset
    'keep *_preselectedBackgroundJets_*_*',
    'keep *_eventSampleFlag_*_*'
    #'keep *_backgroundJetsRecoTauPiZeros_*_*',
)

# Make a list of all the tau products (skipping combinatoric stuff to save
# space)
tau_products = [
    m.label() for m in configtools.listModules(process.buildTaus)
    if 'combinatoric' not in m.label()
]
# Add all our tau products
for product in tau_products:
    poolOutputCommands.append('keep *_%s_*_TANC' % product)

# Write output
process.write = cms.OutputModule(
    "PoolOutputModule",
    fileName=cms.untracked.string("signal_training_%s.root" % sampleName),
    SelectEvents=cms.untracked.PSet(
        SelectEvents=cms.vstring("selectSignal"), ),
    outputCommands=poolOutputCommands)
process.out = cms.EndPath(process.write)
    'keep *_particleFlow_*_TANC',
    #'keep recoTracks_generalTracks_*_TANC',
    #'keep recoTracks_electronGsfTracks_*_TANC',
    'keep *_genParticles_*_*', # this product is okay, since we dont' need it in bkg
    'keep *_selectedTrueHadronicTaus_*_*',
    'keep *_preselectedSignalJets_*_*',
    #'keep *_signalJetsRecoTauPiZeros_*_*',
    # These two products are needed to make signal content a superset
    'keep *_preselectedBackgroundJets_*_*',
    'keep *_eventSampleFlag_*_*'
    #'keep *_backgroundJetsRecoTauPiZeros_*_*',
)

# Make a list of all the tau products (skipping combinatoric stuff to save
# space)
tau_products = [m.label() for m in configtools.listModules(process.buildTaus)
                if 'combinatoric' not in m.label()]
# Add all our tau products
for product in tau_products:
    poolOutputCommands.append('keep *_%s_*_TANC' % product)

# Write output
process.write = cms.OutputModule(
    "PoolOutputModule",
    fileName = cms.untracked.string("signal_training_%s.root" % sampleName),
    SelectEvents = cms.untracked.PSet(
        SelectEvents = cms.vstring("selectSignal"),
    ),
    outputCommands = poolOutputCommands
)
process.out = cms.EndPath(process.write)
# M. Bluj
# September 2017
##########

#useRun1FixedStrips=False
useRun1FixedStrips = True

print 'Production of MiniAOD+PFTau, with a custom tau setup'

######### Add PFTau ReReco and cloned patTaus with original PFTaus
#Add PFTau modules to patTausTaks
#A bit complicated logic due to lack of tasks in tauReco sequences
#add PFTau reco modules to cloned makePatTauTask
process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
from PhysicsTools.PatAlgos.tools.helpers import listModules
for module in listModules(process.PFTau):
    process.makePatTausTask.add(module)
# when the sequences migrated to tasks (CMSSW>=940pre1) it will be simple as that (uncomment)
#_makePatTausTaskWithTauReReco
#process.makePatTausTask.add(process.PFTauTask)

# Modified output to produce and store modified and original PFTaus
# Can be omitted in final prod??
for prod in process.RecoTauTagAOD.outputCommands:
    process.MINIAODSIMoutput.outputCommands.append(prod)

# Clone PAT to use original collections from AOD
# Modified taus (fixed strips) will be stored as slimmedTaus
# while original ones as slimmedTausOrg
orgProcess = 'RECO'
process.makePatTausOrgTask = cms.Task()
def backupJetsSecondStep(process, sequences, badMuons, verbose=False):
    """Deploy the snapshots after the change of PFCandidates"""

    task = getPatAlgosToolsTask(process)

    # put back the old input tags and copy in task
    for sequence in six.itervalues(sequences):
        massSearchReplaceAnyInputTag(sequence, "pfCandidatesBadMuonsCleaned",
                                     "particleFlow")
        massSearchReplaceAnyInputTag(sequence, "muonsCleaned", "muons")
        for mod in listModules(sequence):
            task.add(mod)
    # gate the input collections to avoid re-running most of PAT on good events
    reduceInputJetCollection(process, process.ak4PFJetsCHSBackup, badMuons)
    reduceInputJetCollection(process, process.ak4PFJetsPuppiBackup, badMuons)
    # fix names in the valuemaps
    process.patJetsBackup.userData.userInts.labelPostfixesToStrip = cms.vstring(
        "Backup", )
    process.patJetsBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring(
        "Backup", )
    process.patJetsAK8Backup.userData.userFloats.labelPostfixesToStrip = cms.vstring(
        "Backup", )
    process.patJetsAK8PuppiBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring(
        "Backup", )
    #
    # now deal with daughter links
    # for these we can keep the daughters
    if hasattr(process, "slimmedJetsBackup"):
        process.slimmedJetsBackup.mixedDaughters = True
        process.slimmedJetsBackup.packedPFCandidates = cms.InputTag(
            "oldPFCandToPackedOrDiscarded")
        process.packedPatJetsAK8Backup.fixDaughters = False
        #for this one the link is broken using oldPFCandToPackedOrDiscarded...
        #not sure why, but result is the same
        process.slimmedJetsAK8Backup.rekeyDaughters = '1'
        process.slimmedJetsAK8Backup.mixedDaughters = False
        process.slimmedJetsAK8Backup.packedPFCandidates = cms.InputTag(
            "packedPFCandidatesBackup")  #oldPFCandToPackedOrDiscarded
        reduceFinalJetCollection(process, process.slimmedJetsBackup, badMuons)

    if hasattr(process, "slimmedJetsAK8PFCHSSoftDropSubjetsBackup"):
        process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.mixedDaughters = True
        process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.packedPFCandidates = cms.InputTag(
            "oldPFCandToPackedOrDiscarded")
        reduceFinalJetCollection(process, process.slimmedJetsAK8Backup,
                                 badMuons)
        #for this one the link is broken using oldPFCandToPackedOrDiscarded...
        #not sure why, but result is the same
        process.slimmedJetsAK8BackupAllEvents.packedPFCandidates = cms.InpuTag(
            "packedPFCandidatesBackup")

    # for these we can't
    if hasattr(process, "slimmedJetsPuppiBackup"):
        process.slimmedJetsPuppiBackup.dropDaughters = '1'
        process.slimmedJetsAK8PFPuppiSoftDropSubjetsBackup.dropDaughters = '1'
        reduceFinalJetCollection(process, process.slimmedJetsPuppiBackup,
                                 badMuons)

    #
    addKeepStatement(process,
                     "keep *_slimmedJets_*_*",
                     ["keep *_slimmedJetsBackup_*_*"],
                     verbose=verbose)
    addKeepStatement(process,
                     "keep *_slimmedJetsPuppi_*_*",
                     ["keep *_slimmedJetsPuppiBackup_*_*"],
                     verbose=verbose)
    addKeepStatement(process,
                     "keep *_slimmedJetsAK8_*_*",
                     ["keep *_slimmedJetsAK8Backup_*_*"],
                     verbose=verbose)
    addKeepStatement(
        process,
        "keep *_slimmedJetsAK8PFCHSSoftDropPacked_SubJets_*",
        ["keep *_slimmedJetsAK8PFCHSSoftDropPackedBackup_SubJets_*"],
        verbose=verbose)
    addKeepStatement(
        process,
        "keep *_slimmedJetsAK8PFPuppiSoftDropPacked_SubJets_*",
        ["keep *_slimmedJetsAK8PFPuppiSoftDropPackedBackup_SubJets_*"],
        verbose=verbose)
def makeSplittedPaths4L(process, name, triggerFilterName=None, doThreePathLogic=True):
    from PhysicsTools.PatAlgos.tools.helpers import listModules, cloneProcessingSnippet
    path = getattr(process, name)
    modules = listModules(path)
    seq4E   = cms.Sequence(sum(modules[1:], modules[0]))
    seq4M   = cms.Sequence(sum(modules[1:], modules[0]))
    seq2E2M = cms.Sequence(sum(modules[1:], modules[0]))
    if process.bestZ in modules:
        seq4E.replace(process.bestZ, process.bestZ + process.z1EE)
        seq4M.replace(process.bestZ, process.bestZ + process.z1MM)
    if process.countGoodLep3 in modules:
        seq4E.replace(process.countGoodLep3, process.countGoodLep3E)
        seq4M.replace(process.countGoodLep3, process.countGoodLep3M)
        seq2E2M.replace(process.countGoodLep3, process.countGoodLep3 + countGoodLep3EM)
    if process.countGoodLep in modules:
        seq4E.replace(process.countGoodLep, process.countGoodLep4E)
        seq4M.replace(process.countGoodLep, process.countGoodLep4M)
        seq2E2M.replace(process.countGoodLep, process.countGoodLep2E2M)
    if process.countLooseLep3 in modules:
        seq4E.replace(process.countLooseLep3, process.countLooseLep3E)
        seq4M.replace(process.countLooseLep3, process.countLooseLep3M)
        seq2E2M.replace(process.countLooseLep3, process.countLooseLep3 + countLooseLep3EM)
    if process.countLooseLep in modules:
        seq4E.replace(process.countLooseLep, process.countLooseLep4E)
        seq4M.replace(process.countLooseLep, process.countLooseLep4M)
        seq2E2M.replace(process.countLooseLep, process.countLooseLep2E2M)
    if process.best4L in modules:
        seq4E.replace(process.best4L, process.best4L + process.zz4E)
        seq4M.replace(process.best4L, process.best4L + process.zz4M)
        seq2E2M.replace(process.best4L, process.best4L + process.zz2E2M)
    setattr(process, name+"_4E", cms.Path(seq4E))
    setattr(process, name+"_4M", cms.Path(seq4M))
    setattr(process, name+"_2E2M", cms.Path(seq2E2M))
    ## ---------- the three-path logic comes here ----------------------
    if doThreePathLogic:
        modules4E = listModules(getattr(process, name+"_4E"))
        modules4M = listModules(getattr(process, name+"_4M"))
        seq4E_3P = cms.Sequence(sum(modules4E[1:], modules4E[0]))
        seq4M_3P = cms.Sequence(sum(modules4M[1:], modules4M[0]))
        ## ---- Change trigger filter ----
        if triggerFilterName:
            seq4E_3P.replace(getattr(process,triggerFilterName), getattr(process,triggerFilterName+"_El"))
            seq4M_3P.replace(getattr(process,triggerFilterName), getattr(process,triggerFilterName+"_Mu"))
        ## ---- Change Z1 definition -----
        if process.oneZ in modules:
            seq4E_3P.replace(process.oneZ, process.oneZEE + process.bestZEE + process.selectedZEE)
            seq4M_3P.replace(process.oneZ, process.oneZMM + process.bestZMM + process.selectedZMM)
        for m in [process.bestZ, process.selectedZ1]: 
            if m in modules4E: seq4E_3P.remove(m)
            if m in modules4M: seq4M_3P.remove(m)
        ## ---- Change combinatoric -----
        process.zz3pathLogic4M = process.zz.clone(decay = "selectedZMM oneZMM" if process.zz.decay.value() == "selectedZ1 zll" else "oneZMM oneZMM")
        process.zz3pathLogic4E = process.zz.clone(decay = "selectedZEE oneZEE" if process.zz.decay.value() == "selectedZ1 zll" else "oneZEE oneZEE")
        process.oneZZ3pathLogic4E = process.oneZZ.clone(src = "zz3pathLogic4E")
        process.oneZZ3pathLogic4M = process.oneZZ.clone(src = "zz3pathLogic4M")
        seq4E_3P.replace(process.zz, process.zz3pathLogic4E)
        seq4M_3P.replace(process.zz, process.zz3pathLogic4M)
        seq4E_3P.replace(process.oneZZ, process.oneZZ3pathLogic4E)
        seq4M_3P.replace(process.oneZZ, process.oneZZ3pathLogic4M)
        process.skimEvent4LNoArb3pathLogic4E = process.skimEvent4LNoArb.clone(src = "zz3pathLogic4E")
        process.skimEvent4LNoArb3pathLogic4M = process.skimEvent4LNoArb.clone(src = "zz3pathLogic4M")
        process.zzCombinatoric_4E = cloneProcessingSnippet(process,process.zzCombinatoric,"3pathLogic4E")
        process.zzCombinatoric_4M = cloneProcessingSnippet(process,process.zzCombinatoric,"3pathLogic4M")
        modulesZZC = [process.skimEvent4LNoArb] + listModules(process.zzCombinatoric)
        for m in modulesZZC:
            if m in modules4E: seq4E_3P.replace(m, getattr(process,m.label_() + "3pathLogic4E"))
            if m in modules4M: seq4M_3P.replace(m, getattr(process,m.label_() + "3pathLogic4M"))
        if process.best4Lpass1.src.value() == "skimEvent4LNoArb":
            process.best4Lpass13pathLogic4M.src = "skimEvent4LNoArb3pathLogic4M"
            process.best4Lpass13pathLogic4E.src = "skimEvent4LNoArb3pathLogic4E"
        if process.selectedZZs1.src.value() == "skimEvent4LNoArb":
            process.selectedZZs13pathLogic4M.src = "skimEvent4LNoArb3pathLogic4M"
            process.selectedZZs13pathLogic4E.src = "skimEvent4LNoArb3pathLogic4E"
        for m in [process.z1EE, process.z1MM, process.zz4E, process.zz4M, process.zz4lTree, process.zz4lTreeNoArb]: 
            if m in modules4E: seq4E_3P.remove(m)
            if m in modules4M: seq4M_3P.remove(m)
        setattr(process, name+"_4E_3Path", cms.Path(seq4E_3P))
        setattr(process, name+"_4M_3Path", cms.Path(seq4M_3P))
def backupJetsSecondStep(process, sequences, badMuons, verbose=False):
    """Deploy the snapshots after the change of PFCandidates"""

    task = getPatAlgosToolsTask(process)

    # put back the old input tags and copy in task
    for sequence in sequences.itervalues():
        massSearchReplaceAnyInputTag(sequence, "pfCandidatesBadMuonsCleaned", "particleFlow")
        massSearchReplaceAnyInputTag(sequence, "muonsCleaned", "muons")
        for mod in listModules(sequence):
            task.add(mod)
    # gate the input collections to avoid re-running most of PAT on good events
    reduceInputJetCollection(process, process.ak4PFJetsCHSBackup, badMuons)
    reduceInputJetCollection(process, process.ak4PFJetsPuppiBackup, badMuons)
    # fix names in the valuemaps
    process.patJetsBackup.userData.userInts.labelPostfixesToStrip = cms.vstring("Backup",)
    process.patJetsBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
    process.patJetsAK8Backup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
    process.patJetsAK8PuppiBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)    
    #
    # now deal with daughter links
    # for these we can keep the daughters
    if hasattr(process,"slimmedJetsBackup"):
        process.slimmedJetsBackup.mixedDaughters = True
        process.slimmedJetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
        process.packedPatJetsAK8Backup.fixDaughters = False
       #for this one the link is broken using oldPFCandToPackedOrDiscarded...
        #not sure why, but result is the same
        process.slimmedJetsAK8Backup.rekeyDaughters = '1'
        process.slimmedJetsAK8Backup.mixedDaughters = False
        process.slimmedJetsAK8Backup.packedPFCandidates = cms.InputTag("packedPFCandidatesBackup") #oldPFCandToPackedOrDiscarded
        reduceFinalJetCollection(process, process.slimmedJetsBackup, badMuons)

    if hasattr(process,"slimmedJetsAK8PFCHSSoftDropSubjetsBackup"):
        process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.mixedDaughters = True
        process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
        reduceFinalJetCollection(process, process.slimmedJetsAK8Backup, badMuons)
        #for this one the link is broken using oldPFCandToPackedOrDiscarded...
        #not sure why, but result is the same
        process.slimmedJetsAK8BackupAllEvents.packedPFCandidates = cms.InpuTag("packedPFCandidatesBackup")

    # for these we can't
    if hasattr(process,"slimmedJetsPuppiBackup"):
        process.slimmedJetsPuppiBackup.dropDaughters = '1'
        process.slimmedJetsAK8PFPuppiSoftDropSubjetsBackup.dropDaughters = '1'
        reduceFinalJetCollection(process, process.slimmedJetsPuppiBackup, badMuons)
  
    #
    addKeepStatement(process,
                     "keep *_slimmedJets_*_*",
                     ["keep *_slimmedJetsBackup_*_*"],
                     verbose=verbose)
    addKeepStatement(process, "keep *_slimmedJetsPuppi_*_*",
                     ["keep *_slimmedJetsPuppiBackup_*_*"],
                     verbose=verbose)
    addKeepStatement(process,
                     "keep *_slimmedJetsAK8_*_*",
                     ["keep *_slimmedJetsAK8Backup_*_*"],
                     verbose=verbose)
    addKeepStatement(process,"keep *_slimmedJetsAK8PFCHSSoftDropPacked_SubJets_*",
                     ["keep *_slimmedJetsAK8PFCHSSoftDropPackedBackup_SubJets_*"],
                     verbose=verbose)
    addKeepStatement(process,"keep *_slimmedJetsAK8PFPuppiSoftDropPacked_SubJets_*",
                     ["keep *_slimmedJetsAK8PFPuppiSoftDropPackedBackup_SubJets_*"],
                     verbose=verbose)