Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:30

0001 import FWCore.ParameterSet.Config as cms
0002 import FWCore.ParameterSet.VarParsing as VarParsing
0003 import sys
0004 
0005 ## Define the process
0006 process = cms.Process("Analyzer")
0007 process.options = cms.untracked.PSet(
0008     wantSummary = cms.untracked.bool(True)
0009 )
0010 
0011 ## Set up command line options
0012 options = VarParsing.VarParsing ('standard')
0013 options.register('runOnAOD', True, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "run on AOD")
0014 
0015 ## Get and parse command line options
0016 if( hasattr(sys, "argv") ):
0017     for args in sys.argv :
0018         arg = args.split(',')
0019         for val in arg:
0020              val = val.split('=')
0021              if(len(val)==2):
0022                  setattr(options,val[0], val[1])
0023 
0024 ## Configure message logger
0025 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0026 process.MessageLogger.cerr.threshold = 'INFO'
0027 process.MessageLogger.cerr.FwkReport.reportEvery = 100
0028 
0029 ## Define input
0030 if options.runOnAOD:
0031     process.source = cms.Source("PoolSource",
0032         fileNames = cms.untracked.vstring(    
0033             # add your favourite AOD files here
0034 #            '/store/relval/CMSSW_7_2_0_pre7/RelValTTbar_13/GEN-SIM-RECO/PU50ns_PRE_LS172_V12-v1/00000/1267B7ED-2F4E-E411-A0B9-0025905964A6.root',
0035             '/store/mc/Spring14dr/TTJets_MSDecaysCKM_central_Tune4C_13TeV-madgraph-tauola/AODSIM/PU_S14_POSTLS170_V6-v1/00000/00120F7A-84F5-E311-9FBE-002618943910.root',
0036 #            '/store/mc/Spring14dr/TT_Tune4C_13TeV-pythia8-tauola/AODSIM/Flat20to50_POSTLS170_V5-v1/00000/023E1847-ADDC-E311-91A2-003048FFD754.root',
0037 #            '/store/mc/Spring14dr/TTbarH_HToBB_M-125_13TeV_pythia6/AODSIM/PU20bx25_POSTLS170_V5-v1/00000/1CAB7E58-0BD0-E311-B688-00266CFFBC3C.root',
0038 #            '/store/mc/Spring14dr/TTbarH_M-125_13TeV_amcatnlo-pythia8-tauola/AODSIM/PU20bx25_POSTLS170_V5-v1/00000/0E3D08A9-C610-E411-A862-0025B3E0657E.root',
0039         ),
0040         skipEvents = cms.untracked.uint32(0)
0041     )
0042 else:
0043     process.source = cms.Source("PoolSource",
0044         fileNames = cms.untracked.vstring(    
0045             # add your favourite miniAOD files here
0046 #            '/store/mc/Phys14DR/TTJets_MSDecaysCKM_central_Tune4C_13TeV-madgraph-tauola/MINIAODSIM/PU20bx25_PHYS14_25_V1-v1/00000/FE26BEB8-D575-E411-A13E-00266CF2AE10.root',
0047 #            '/store/mc/RunIISpring15DR74/TTJets_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/MINIAODSIM/Asympt25ns_MCRUN2_74_V9-v1/00000/FE3EF0E9-9F02-E511-BA6F-549F35AE4FA2.root',
0048             '/store/mc/RunIISpring15DR74/TTJets_TuneCUETP8M1_13TeV-amcatnloFXFX-scaledown-pythia8/MINIAODSIM/Asympt50ns_MCRUN2_74_V9A-v2/50000/FEA9ADAC-FB0B-E511-9B8C-00266CF9AB9C.root',
0049 #            '/store/mc/RunIISpring15DR74/TT_TuneZ2star_13TeV-powheg-pythia6-tauola/MINIAODSIM/Asympt25ns_MCRUN2_74_V9-v1/50000/C6F89D57-640A-E511-8D41-549F35AD8BC9.root',
0050 #            '/store/mc/RunIISpring15DR74/TT_TuneZ2star_13TeV-powheg-pythia6-tauola/MINIAODSIM/Asympt50ns_MCRUN2_74_V9A-v3/00000/D4BE2E58-CE08-E511-9247-0025907DC9CC.root',
0051         ),
0052         skipEvents = cms.untracked.uint32(0)
0053     )
0054 
0055 ## Define maximum number of events to loop over
0056 process.maxEvents = cms.untracked.PSet(
0057     input = cms.untracked.int32(1000)
0058 )
0059 
0060 process.task = cms.Task()
0061 
0062 ## Set input particle collections to be used by the tools
0063 genParticleCollection = ''
0064 genJetCollection = ''
0065 if options.runOnAOD:
0066     genParticleCollection = 'genParticles'
0067     genJetCollection = 'ak4GenJetsCustom'
0068     ## producing a subset of genParticles to be used for jet clustering in AOD
0069     from RecoJets.Configuration.GenJetParticles_cff import genParticlesForJetsNoNu
0070     process.genParticlesForJetsCustom = genParticlesForJetsNoNu.clone()
0071     process.task.add(process.genParticlesForJetsCustom)
0072     ## Produce own jets (re-clustering in miniAOD needed at present to avoid crash)
0073     from RecoJets.JetProducers.ak4GenJets_cfi import ak4GenJets
0074     process.ak4GenJetsCustom = ak4GenJets.clone(
0075         src = 'genParticlesForJetsCustom',
0076         rParam = cms.double(0.4),
0077         jetAlgorithm = cms.string("AntiKt")
0078     )
0079     process.task.add(process.ak4GenJetsCustom)
0080 else:
0081     genParticleCollection = 'prunedGenParticles'
0082     genJetCollection = 'slimmedGenJets'
0083 
0084 ## Supplies PDG ID to real name resolution of MC particles
0085 process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
0086 
0087 
0088 ## Ghost particle collection used for Hadron-Jet association 
0089 # MUST use proper input particle collection
0090 from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
0091 process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
0092     particles = genParticleCollection
0093 )
0094 process.task.add(process.selectedHadronsAndPartons)
0095 
0096 ## Input particle collection for matching to gen jets (partons + leptons) 
0097 # MUST use use proper input jet collection: the jets to which hadrons should be associated
0098 # rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
0099 # More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
0100 from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
0101 process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
0102     jets = genJetCollection,
0103 )
0104 process.task.add(process.genJetFlavourInfos)
0105 
0106 ## Plugin for analysing B hadrons
0107 # MUST use the same particle collection as in selectedHadronsAndPartons
0108 from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
0109 process.matchGenBHadron = matchGenBHadron.clone(
0110     genParticles = genParticleCollection,
0111     jetFlavourInfos = "genJetFlavourInfos"
0112 )
0113 process.task.add(process.matchGenBHadron)
0114 
0115 ## Plugin for analysing C hadrons
0116 # MUST use the same particle collection as in selectedHadronsAndPartons
0117 from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
0118 process.matchGenCHadron = matchGenCHadron.clone(
0119     genParticles = genParticleCollection,
0120     jetFlavourInfos = "genJetFlavourInfos"
0121 )
0122 process.task.add(process.matchGenCHadron)
0123 
0124 ## Producer for ttbar categorisation ID
0125 # MUST use same genJetCollection as used for tools above
0126 from TopQuarkAnalysis.TopTools.categorizeGenTtbar_cfi import categorizeGenTtbar
0127 process.categorizeGenTtbar = categorizeGenTtbar.clone(
0128     genJetPtMin = 20.,
0129     genJetAbsEtaMax = 2.4,
0130     genJets = genJetCollection,
0131 )
0132 process.task.add(process.categorizeGenTtbar)
0133 
0134 ## Configure test analyzer
0135 process.testGenTtbarCategories = cms.EDAnalyzer("TestGenTtbarCategories",
0136     genTtbarId = cms.InputTag("categorizeGenTtbar", "genTtbarId")
0137 )
0138 
0139 ## Output root file
0140 process.TFileService = cms.Service("TFileService",
0141     fileName = cms.string("genTtbarId.root")
0142 )
0143 
0144 ## Path
0145 process.p1 = cms.Path(
0146     process.testGenTtbarCategories,
0147     process.task
0148 )