Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:37

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 ## Define the process
0010 process = cms.Process("Filter")
0011 patAlgosToolsTask = getPatAlgosToolsTask(process)
0012 process.options = cms.untracked.PSet(
0013     wantSummary = cms.untracked.bool(True)
0014 )
0015 ## Set up command line options
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 ## Configure message logger
0023 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0024 process.MessageLogger.cerr.threshold = 'INFO'
0025 process.MessageLogger.cerr.FwkReport.reportEvery = 100
0026 
0027 ## Define input
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 ## Define maximum number of events to loop over
0035 if options.maxEvents is -1: # maxEvents is set in VarParsing class by default to -1
0036     options.maxEvents = 1000 # reset for testing
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 ## Set input particle collections to be used by the tools
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 ## Supplies PDG ID to real name resolution of MC particles
0057 process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
0058 ## producing a subset of particles to be used for jet clustering
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 ## Produce own jets (re-clustering in miniAOD needed at present to avoid crash)
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 ## Ghost particle collection used for Hadron-Jet association
0076 # MUST use proper input particle collection
0077 from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
0078 process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
0079     particles = genParticleCollection,
0080 )
0081 patAlgosToolsTask.add(process.selectedHadronsAndPartons)
0082 #Input particle collection for matching to gen jets (partons + leptons)
0083 # MUST use use proper input jet collection: the jets to which hadrons should be associated
0084 # rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
0085 # More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
0086 from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
0087 process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
0088     jets = genJetCollection,
0089 )
0090 patAlgosToolsTask.add(process.genJetFlavourInfos)
0091 
0092 # Plugin for analysing B hadrons
0093 # MUST use the same particle collection as in selectedHadronsAndPartons
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 # Plugin for analysing C hadrons
0102 # MUST use the same particle collection as in selectedHadronsAndPartons
0103 #from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
0104 #process.matchGenCHadron = matchGenCHadron.clone(
0105 #    genParticles = genParticleCollection,
0106 #    jetFlavourInfos = "genJetFlavourInfos"
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 ## configuring the testing analyzer that produces output tree
0121 #process.matchGenHFHadrons = cms.EDAnalyzer("matchGenHFHadrons",
0122 #    # phase space of jets to be stored
0123 #    genJetPtMin = cms.double(15),
0124 #    genJetAbsEtaMax = cms.double(2.4),
0125 #    # input tags holding information about matching
0126 #    genJets = cms.InputTag(genJetCollection),
0127 #    genBHadJetIndex = cms.InputTag("matchGenBHadron", "genBHadJetIndex"),
0128 #    genBHadFlavour = cms.InputTag("matchGenBHadron", "genBHadFlavour"),
0129 #    genBHadFromTopWeakDecay = cms.InputTag("matchGenBHadron", "genBHadFromTopWeakDecay"),
0130 #    genBHadPlusMothers = cms.InputTag("matchGenBHadron", "genBHadPlusMothers"),
0131 #    genBHadPlusMothersIndices = cms.InputTag("matchGenBHadron", "genBHadPlusMothersIndices"),
0132 #    genBHadIndex = cms.InputTag("matchGenBHadron", "genBHadIndex"),
0133 #    genBHadLeptonHadronIndex = cms.InputTag("matchGenBHadron", "genBHadLeptonHadronIndex"),
0134 #    genBHadLeptonViaTau = cms.InputTag("matchGenBHadron", "genBHadLeptonViaTau"),
0135 #    genCHadJetIndex = cms.InputTag("matchGenCHadron", "genCHadJetIndex"),
0136 #    genCHadFlavour = cms.InputTag("matchGenCHadron", "genCHadFlavour"),
0137 #    genCHadFromTopWeakDecay = cms.InputTag("matchGenCHadron", "genCHadFromTopWeakDecay"),
0138 #    genCHadBHadronId = cms.InputTag("matchGenCHadron", "genCHadBHadronId"),
0139 #    genCHadPlusMothers = cms.InputTag("matchGenCHadron", "genCHadPlusMothers"),
0140 #    genCHadPlusMothersIndices = cms.InputTag("matchGenCHadron", "genCHadPlusMothersIndices"),
0141 #    genCHadIndex = cms.InputTag("matchGenCHadron", "genCHadIndex"),
0142 #    genCHadLeptonHadronIndex = cms.InputTag("matchGenCHadron", "genCHadLeptonHadronIndex"),
0143 #    genCHadLeptonViaTau = cms.InputTag("matchGenCHadron", "genCHadLeptonViaTau"),
0144 #)
0145 
0146 ## Configure test filter
0147 #process.ttHFGenFilter = cms.EDFilter("ttHFGenFilter",
0148 #    genBHadFlavour = cms.InputTag("matchGenBHadron", "genBHadFlavour"),
0149 #    genBHadFromTopWeakDecay = cms.InputTag("matchGenBHadron", "genBHadFromTopWeakDecay"),
0150 #    genBHadPlusMothers = cms.InputTag("matchGenBHadron", "genBHadPlusMothers"),
0151 #    genBHadPlusMothersIndices = cms.InputTag("matchGenBHadron", "genBHadPlusMothersIndices"),
0152 #    genBHadIndex = cms.InputTag("matchGenBHadron", "genBHadIndex"),
0153 #    filter = cms.bool(True)
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 ## Output root file
0162 #process.TFileService = cms.Service("TFileService",
0163 #    fileName = cms.string("genHFHadronMatcherOutput.root")
0164 #)
0165 
0166 ## Path
0167 process.p1 = cms.Path(
0168     process.matchGenBHadron*
0169     process.ttHFGenFilter
0170 )
0171 
0172 process.endpath = cms.EndPath(process.USER, patAlgosToolsTask)