Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:01

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