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