Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:27

0001 #!/usr/bin/env cmsRun
0002 
0003 ## Original Author: Andrea Carlo Marini
0004 ## Porting to 92X HepMC 2 Gen 
0005 ## Date of porting: Mon Jul  3 11:52:22 CEST 2017
0006 ## Example of hepmc -> gen file
0007 
0008 import os,sys
0009 from FWCore.ParameterSet.VarParsing import VarParsing
0010 options = VarParsing ('analysis')
0011 options.parseArguments()
0012 
0013 if True:
0014     print('-> You are using a 2 process file to unzip/untar events on the fly')
0015     #cmd = "mkfifo /tmp/amarini/hepmc10K.dat"
0016     #cmd = "cat hepmc10K.dat.gz | gunzip -c > /tmp/amarini/hepmc10K.dat"
0017     from subprocess import call, check_output
0018     import threading
0019     import time
0020     def call_exe(cmd):
0021         print("-> Executing cmd: '"+cmd+"'")
0022         st=call(cmd,shell=True)
0023         print("-> End cmd: status=",st)
0024         return
0025     cmd="rm /tmp/"+os.environ['USER']+"/hepmc10K.dat"
0026     call(cmd,shell=True)
0027     cmd="mkfifo /tmp/"+os.environ['USER']+"/hepmc10K.dat"
0028     call(cmd,shell=True)
0029     exe="cat /tmp/"+os.environ['USER']+"/hepmc.dat.tgz | gunzip -c > /tmp/"+os.environ['USER']+"/hepmc10K.dat &"
0030     t = threading.Thread(target=call_exe, args= ( [exe] )  )
0031     t.start()
0032     print("(sleep 1s to allow start of pipes)")
0033     time.sleep(1)
0034 
0035 
0036 import FWCore.ParameterSet.Config as cms
0037 
0038 process = cms.Process("GEN")
0039 
0040 
0041 process.source = cms.Source("MCFileSource",
0042             #fileNames = cms.untracked.vstring('file:hepmc100.dat'),
0043             fileNames = cms.untracked.vstring('file:/tmp/'+os.environ['USER']+'/hepmc10K.dat'),
0044             )
0045 
0046 maxEvents=options.maxEvents
0047 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(maxEvents))
0048 
0049 
0050 process.load("FWCore.MessageService.MessageLogger_cfi")
0051 process.MessageLogger.cerr.threshold = 'INFO'
0052 
0053 process.GEN = cms.OutputModule("PoolOutputModule",
0054                 fileName = cms.untracked.string('HepMC_GEN.root')
0055             )
0056 
0057 
0058 process.load('Configuration.StandardSequences.Services_cff')
0059 process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi')
0060 process.load('GeneratorInterface.Core.genFilterSummary_cff')
0061 process.load('Configuration.StandardSequences.Generator_cff')
0062 process.genParticles.src= cms.InputTag("source","generator")
0063 
0064 
0065 ######### Smearing Vertex example
0066 
0067 from IOMC.EventVertexGenerators.VtxSmearedParameters_cfi import GaussVtxSmearingParameters,VtxSmearedCommon
0068 VtxSmearedCommon.src=cms.InputTag("source","generator")
0069 process.generatorSmeared = cms.EDProducer("GaussEvtVtxGenerator",
0070     GaussVtxSmearingParameters,
0071     VtxSmearedCommon
0072     )
0073 process.load('Configuration.StandardSequences.Services_cff')
0074 process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
0075         generatorSmeared  = cms.PSet( initialSeed = cms.untracked.uint32(1243987),
0076             engineName = cms.untracked.string('TRandom3'),
0077             ),
0078         )
0079 
0080 
0081 ###################
0082 process.p = cms.Path(process.genParticles * process.generatorSmeared)
0083 process.outpath = cms.EndPath(process.GEN)
0084 
0085 ### TO DO: add the following
0086 # (amarini/hepmc_portTo9X)
0087 # add the following line after the sim and digi loading
0088 # generator needs to be smeared if you want vertex smearing, you'll have:
0089 #       Type                                  Module               Label         Process   
0090 #       -----------------------------------------------------------------------------------
0091 #       GenEventInfoProduct                   "source"             "generator"   "GEN"     
0092 #       edm::HepMCProduct                     "generatorSmeared"   ""            "GEN"     
0093 #       edm::HepMCProduct                     "source"             "generator"   "GEN"   
0094 # NOT needed to be changed if you smear the generator
0095 #process.g4SimHits.HepMCProductLabel = cms.InputTag("source","generator","GEN")
0096 #process.g4SimHits.Generator.HepMCProductLabel = cms.InputTag("source","generator","GEN")
0097 #process.genParticles.src=  cms.InputTag("source","generator","GEN")
0098 
0099 
0100 ### ADD in the different step the following  (always!)
0101 #
0102 #process.AODSIMoutput.outputCommands.extend([
0103 #       'keep GenRunInfoProduct_*_*_*',
0104 #           'keep GenLumiInfoProduct_*_*_*',
0105 #       'keep GenEventInfoProduct_*_*_*',
0106 #       ])
0107 #
0108 #process.MINIAODSIMoutput.outputcommands.extend([
0109 #       'keep GenRunInfoProduct_*_*_*',
0110 #       'keep GenLumiInfoProduct_*_*_*',
0111 #       'keep GenEventInfoProduct_*_*_*',
0112 #   ])
0113 #
0114 # and finally in the ntuples
0115 #process.myanalyzer.generator = cms.InputTag("source","generator")