File indexing completed on 2023-03-17 11:15:56
0001 from __future__ import print_function
0002 import FWCore.ParameterSet.Config as cms
0003 from FWCore.ParameterSet.VarParsing import VarParsing
0004 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask
0005 import sys
0006 import os
0007
0008
0009
0010 process = cms.Process("Filter")
0011 patAlgosToolsTask = getPatAlgosToolsTask(process)
0012 process.options = cms.untracked.PSet(
0013 wantSummary = cms.untracked.bool(True)
0014 )
0015
0016 options = VarParsing ('analysis')
0017 options.register('runOnGenOrAODsim', False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "GEN SIM")
0018 options.register( "skipEvents", 0, VarParsing.multiplicity.singleton, VarParsing.varType.int, "Number of events to skip" )
0019 options.parseArguments()
0020
0021
0022
0023 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0024 process.MessageLogger.cerr.threshold = 'INFO'
0025 process.MessageLogger.cerr.FwkReport.reportEvery = 100
0026
0027
0028 if not options.inputFiles:
0029 if options.runOnGenOrAODsim:
0030 options.inputFiles=['/store/mc/RunIISummer15GS/TTToSemiLeptonic_TuneCUETP8M1_alphaS01273_13TeV-powheg-scaledown-pythia8/GEN-SIM/MCRUN2_71_V1-v2/40000/DE7952A2-6E2F-E611-A803-001E673D1B21.root']
0031 else:
0032 options.inputFiles=['/store/mc/RunIIFall17MiniAOD/TTToSemiLeptonic_TuneCP5_PSweights_13TeV-powheg-pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/50000/DC5D3109-F2E1-E711-A26E-A0369FC5FC9C.root']
0033
0034
0035 if options.maxEvents is -1:
0036 options.maxEvents = 1000
0037
0038 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(int(options.maxEvents)))
0039 process.source = cms.Source( "PoolSource",
0040 fileNames = cms.untracked.vstring(options.inputFiles),
0041 skipEvents=cms.untracked.uint32(int(options.skipEvents)),
0042 )
0043
0044
0045 genParticleCollection = ''
0046 genJetInputParticleCollection = ''
0047 genJetCollection = 'ak4GenJetsCustom'
0048
0049 if options.runOnGenOrAODsim:
0050 genParticleCollection = 'genParticles'
0051 genJetInputParticleCollection = genParticleCollection
0052 else:
0053 genParticleCollection = 'prunedGenParticles'
0054 genJetInputParticleCollection = 'packedGenParticles'
0055
0056
0057 process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
0058
0059
0060 from RecoJets.Configuration.GenJetParticles_cff import genParticlesForJetsNoNu
0061 process.genParticlesForJetsNoNu = genParticlesForJetsNoNu.clone(
0062 src = genJetInputParticleCollection
0063 )
0064 patAlgosToolsTask.add(process.genParticlesForJetsNoNu)
0065
0066
0067 from RecoJets.JetProducers.ak4GenJets_cfi import ak4GenJets
0068 process.ak4GenJetsCustom = ak4GenJets.clone(
0069 src = 'genParticlesForJetsNoNu',
0070 rParam = cms.double(0.4),
0071 jetAlgorithm = cms.string("AntiKt")
0072 )
0073 patAlgosToolsTask.add(process.ak4GenJetsCustom)
0074
0075
0076
0077 from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
0078 process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
0079 particles = genParticleCollection,
0080 )
0081 patAlgosToolsTask.add(process.selectedHadronsAndPartons)
0082
0083
0084
0085
0086 from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
0087 process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
0088 jets = genJetCollection,
0089 )
0090 patAlgosToolsTask.add(process.genJetFlavourInfos)
0091
0092
0093
0094 from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
0095 process.matchGenBHadron = matchGenBHadron.clone(
0096 genParticles = genParticleCollection,
0097 jetFlavourInfos = "genJetFlavourInfos",
0098 onlyJetClusteredHadrons = cms.bool(False)
0099 )
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 process.load("PhysicsTools/JetMCAlgos/ttHFGenFilter_cfi")
0110 from PhysicsTools.JetMCAlgos.ttHFGenFilter_cfi import ttHFGenFilter
0111 process.ttHFGenFilter = ttHFGenFilter.clone(
0112 genParticles = genParticleCollection,
0113 taggingMode = cms.bool(True),
0114 )
0115 print("If taggingMode is set to true, the filter will write a branch into the tree instead of filtering the events")
0116 print("taggingMode is set to ", process.ttHFGenFilter.taggingMode)
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 process.USER = cms.OutputModule("PoolOutputModule",
0156 SelectEvents = cms.untracked.PSet(
0157 SelectEvents = cms.vstring('p1')
0158 ),
0159 fileName = cms.untracked.string('Filtered_Events.root')
0160 )
0161
0162
0163
0164
0165
0166
0167 process.p1 = cms.Path(
0168 process.matchGenBHadron*
0169 process.ttHFGenFilter
0170 )
0171
0172 process.endpath = cms.EndPath(process.USER, patAlgosToolsTask)