Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 import FWCore.ParameterSet.Config as cms
0002 import FWCore.ParameterSet.VarParsing as VarParsing
0003 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask
0004 import sys
0005 
0006 process = cms.Process("Analyzer")
0007 
0008 patAlgosToolsTask = getPatAlgosToolsTask(process)
0009 
0010 ## defining command line options
0011 options = VarParsing.VarParsing ('standard')
0012 options.register('runOnAOD', True, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.bool, "run on AOD")
0013 
0014 ## processing provided options
0015 if( hasattr(sys, "argv") ):
0016     for args in sys.argv :
0017         arg = args.split(',')
0018         for val in arg:
0019              val = val.split('=')
0020              if(len(val)==2):
0021                  setattr(options,val[0], val[1])
0022 
0023 ## enabling unscheduled mode for modules
0024 process.options = cms.untracked.PSet(
0025     wantSummary = cms.untracked.bool(False)
0026 )
0027 
0028 ## configure message logger
0029 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0030 process.MessageLogger.cerr.threshold = 'INFO'
0031 process.MessageLogger.cerr.FwkReport.reportEvery = 100
0032 
0033 ## define input
0034 if options.runOnAOD:
0035     process.source = cms.Source("PoolSource",
0036         fileNames = cms.untracked.vstring(    
0037           ## add your favourite AOD files here (1000+ events in each file defined below)
0038       '/store/mc/RunIISpring15DR74/ttHTobb_M125_13TeV_powheg_pythia8/AODSIM/Asympt25ns_MCRUN2_74_V9-v1/00000/02203C96-2108-E511-B5C1-00266CFCC214.root',
0039       '/store/mc/RunIISpring15DR74/ttHTobb_M125_13TeV_powheg_pythia8/AODSIM/Asympt25ns_MCRUN2_74_V9-v1/00000/02332898-9808-E511-81E8-3417EBE34BFD.root',
0040       '/store/mc/RunIISpring15DR74/ttHTobb_M125_13TeV_powheg_pythia8/AODSIM/Asympt25ns_MCRUN2_74_V9-v1/00000/060177B4-2E08-E511-83AD-3417EBE644DA.root',
0041       ## other AOD samples
0042 #     '/store/mc/RunIISpring15DR74/TT_TuneCUETP8M1_13TeV-powheg-pythia8/AODSIM/Asympt50ns_MCRUN2_74_V9A-v4/10000/00199A75-540F-E511-8277-0002C92DB464.root',
0043 #     '/store/mc/RunIISpring15DR74/TT_TuneCUETP8M1_13TeV-powheg-pythia8/AODSIM/Asympt50ns_MCRUN2_74_V9A-v4/10000/001B27B8-550F-E511-85CF-0025905A609A.root',
0044 #     '/store/mc/RunIISpring15DR74/TT_TuneCUETP8M1_13TeV-powheg-pythia8/AODSIM/Asympt50ns_MCRUN2_74_V9A-v4/10000/007E116A-510F-E511-8D40-F04DA275C007.root',
0045         ),
0046     skipEvents = cms.untracked.uint32(0)
0047     )
0048 else:
0049     process.source = cms.Source("PoolSource",
0050         fileNames = cms.untracked.vstring(    
0051       # add your favourite miniAOD files here (1000+ events in each file defined below)
0052       '/store/mc/RunIISpring15DR74/ttHTobb_M125_13TeV_powheg_pythia8/MINIAODSIM/Asympt25ns_MCRUN2_74_V9-v1/00000/141B9915-1F08-E511-B9FF-001E675A6AB3.root',
0053 #     '/store/mc/RunIISpring15DR74/TT_TuneCUETP8M1_13TeV-powheg-pythia8/MINIAODSIM/Asympt50ns_MCRUN2_74_V9A-v4/10000/00D2A247-2910-E511-9F3D-0CC47A4DEDD2.root',
0054     ),
0055     skipEvents = cms.untracked.uint32(0)
0056     )
0057 
0058 ## define maximal number of events to loop over
0059 process.maxEvents = cms.untracked.PSet(
0060     input = cms.untracked.int32(1000)
0061 )
0062 
0063 # Setting input particle/jet collections to be used by the tools
0064 genParticleCollection = ''
0065 genJetCollection = 'ak4GenJetsCustom'
0066 
0067 if options.runOnAOD:
0068     genParticleCollection = 'genParticles'
0069     ## producing a subset of genParticles to be used for jet reclustering
0070     from RecoJets.Configuration.GenJetParticles_cff import genParticlesForJetsNoNu
0071     process.genParticlesForJetsCustom = genParticlesForJetsNoNu.clone(
0072         src = genParticleCollection
0073     )
0074     patAlgosToolsTask.add(process.genParticlesForJetsCustom)
0075     # Producing own jets for testing purposes
0076     from RecoJets.JetProducers.ak4GenJets_cfi import ak4GenJets
0077     process.ak4GenJetsCustom = ak4GenJets.clone(
0078         src = 'genParticlesForJetsCustom',
0079         rParam = cms.double(0.4),
0080         jetAlgorithm = cms.string("AntiKt")
0081     )
0082     patAlgosToolsTask.add(process.ak4GenJetsCustom)
0083 else:
0084     genParticleCollection = 'prunedGenParticles'
0085     genJetCollection = 'slimmedGenJets'
0086 
0087 # Supplies PDG ID to real name resolution of MC particles
0088 process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
0089 
0090 # Ghost particle collection used for Hadron-Jet association 
0091 # MUST use proper input particle collection
0092 from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
0093 process.selectedHadronsAndPartons = selectedHadronsAndPartons.clone(
0094     particles = genParticleCollection
0095 )
0096 patAlgosToolsTask.add(process.selectedHadronsAndPartons)
0097 
0098 # Input particle collection for matching to gen jets (partons + leptons) 
0099 # MUST use use proper input jet collection: the jets to which hadrons should be associated
0100 # rParam and jetAlgorithm MUST match those used for jets to be associated with hadrons
0101 # More details on the tool: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideBTagMCTools#New_jet_flavour_definition
0102 from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
0103 process.genJetFlavourInfos = ak4JetFlavourInfos.clone(
0104     jets = genJetCollection,
0105 )
0106 patAlgosToolsTask.add(process.genJetFlavourInfos)
0107 
0108 # Plugin for analysing B hadrons
0109 # MUST use the same particle collection as in selectedHadronsAndPartons
0110 from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenBHadron
0111 process.matchGenBHadron = matchGenBHadron.clone(
0112     genParticles = genParticleCollection,
0113     jetFlavourInfos = "genJetFlavourInfos"
0114 )
0115 patAlgosToolsTask.add(process.matchGenBHadron)
0116 
0117 # Plugin for analysing C hadrons
0118 # MUST use the same particle collection as in selectedHadronsAndPartons
0119 from PhysicsTools.JetMCAlgos.GenHFHadronMatcher_cff import matchGenCHadron
0120 process.matchGenCHadron = matchGenCHadron.clone(
0121     genParticles = genParticleCollection,
0122     jetFlavourInfos = "genJetFlavourInfos"
0123 )
0124 patAlgosToolsTask.add(process.matchGenCHadron)
0125 
0126 ## configuring the testing analyzer that produces output tree
0127 process.matchGenHFHadrons = cms.EDAnalyzer("matchGenHFHadrons",
0128     # phase space of jets to be stored
0129     genJetPtMin = cms.double(20),
0130     genJetAbsEtaMax = cms.double(2.4),
0131     # input tags holding information about matching
0132     genJets = cms.InputTag(genJetCollection),
0133     genBHadJetIndex = cms.InputTag("matchGenBHadron", "genBHadJetIndex"),
0134     genBHadFlavour = cms.InputTag("matchGenBHadron", "genBHadFlavour"),
0135     genBHadFromTopWeakDecay = cms.InputTag("matchGenBHadron", "genBHadFromTopWeakDecay"),
0136     genBHadPlusMothers = cms.InputTag("matchGenBHadron", "genBHadPlusMothers"),
0137     genBHadPlusMothersIndices = cms.InputTag("matchGenBHadron", "genBHadPlusMothersIndices"),
0138     genBHadIndex = cms.InputTag("matchGenBHadron", "genBHadIndex"),
0139     genBHadLeptonHadronIndex = cms.InputTag("matchGenBHadron", "genBHadLeptonHadronIndex"),
0140     genBHadLeptonViaTau = cms.InputTag("matchGenBHadron", "genBHadLeptonViaTau"),
0141     genCHadJetIndex = cms.InputTag("matchGenCHadron", "genCHadJetIndex"),
0142     genCHadFlavour = cms.InputTag("matchGenCHadron", "genCHadFlavour"),
0143     genCHadFromTopWeakDecay = cms.InputTag("matchGenCHadron", "genCHadFromTopWeakDecay"),
0144     genCHadBHadronId = cms.InputTag("matchGenCHadron", "genCHadBHadronId"),
0145     genCHadPlusMothers = cms.InputTag("matchGenCHadron", "genCHadPlusMothers"),
0146     genCHadPlusMothersIndices = cms.InputTag("matchGenCHadron", "genCHadPlusMothersIndices"),
0147     genCHadIndex = cms.InputTag("matchGenCHadron", "genCHadIndex"),
0148     genCHadLeptonHadronIndex = cms.InputTag("matchGenCHadron", "genCHadLeptonHadronIndex"),
0149     genCHadLeptonViaTau = cms.InputTag("matchGenCHadron", "genCHadLeptonViaTau"),
0150 )
0151 
0152 ## setting up output root file
0153 process.TFileService = cms.Service("TFileService",
0154     fileName = cms.string("matchGenHFHadrons_trees.root")
0155 )
0156 
0157 
0158 
0159 ## defining only the final modules to run: dependencies will be run automatically [allowUnscheduled = True]
0160 process.p1 = cms.Path(
0161     process.matchGenHFHadrons
0162 )
0163 
0164 ## module to store raw output from the processed modules into the ROOT file
0165 process.out = cms.OutputModule("PoolOutputModule",
0166     fileName = cms.untracked.string('matchGenHFHadrons_out.root'),
0167     outputCommands = cms.untracked.vstring('drop *', 'keep *_matchGen*_*_*')
0168     )
0169 process.outpath = cms.EndPath(process.out, patAlgosToolsTask)