Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:11

0001 # Test pseudorandom number generation.
0002 # In this process random numbers are generated
0003 # in the TestRandomNumberServiceAnalyzer.  The
0004 # state of the random number engines is saved in
0005 # two places.  The states are saved in a text file
0006 # that gets overwritten before modules process each
0007 # event. The states are also saved into every event
0008 # and luminosity block.
0009 
0010 # The analyzer also writes each generated random number
0011 # to a text file named testRandomService.txt, which
0012 # can be examined to determine that the expected
0013 # sequence of numbers has been generated.
0014 
0015 import FWCore.ParameterSet.Config as cms
0016 
0017 process = cms.Process("PROD")
0018 
0019 process.options = cms.untracked.PSet(
0020     numberOfStreams = cms.untracked.uint32(1)
0021 )
0022 
0023 process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
0024 
0025     # Tell the service to save the state of all engines
0026     # to a separate text file which is overwritten before
0027     # modules begin processing on each event.
0028     saveFileName = cms.untracked.string('StashState1.data'),
0029 
0030     # Next we specify a seed or seeds for each module that
0031     # uses random numbers.
0032 
0033     # Optionally, one can specify different types
0034     # of engines.  Currently the only three types
0035     # implemented are HepJamesRandom, RanecuEngine, and
0036     # TRandom3.  If you do not specify the engine, it
0037     # defaults to HepJamesRandom.
0038 
0039     # Use the parameter initialSeed for engines requiring
0040     # only one seed and initialSeedSet for the other ones.
0041     # HepJamesRandom requires one seed between 0 and 900000000
0042     # RanecuEngine requires two seeds between 0 and 2147483647
0043     # TRandom3 will take any 32 bit unsigned integer.
0044 
0045     t1 = cms.PSet(
0046         initialSeed = cms.untracked.uint32(81)
0047     ),
0048     t2 = cms.PSet(
0049         engineName = cms.untracked.string('RanecuEngine'),
0050         initialSeedSet = cms.untracked.vuint32(1, 2)
0051     ),
0052     t3 = cms.PSet(
0053         initialSeed = cms.untracked.uint32(83),
0054         engineName = cms.untracked.string('TRandom3')
0055     ),
0056     t4 = cms.PSet(
0057         engineName = cms.untracked.string('HepJamesRandom'),
0058         initialSeed = cms.untracked.uint32(84)
0059     ),
0060     t6 = cms.PSet(
0061         initialSeed = cms.untracked.uint32(85),
0062         engineName = cms.untracked.string('MixMaxRng')
0063     ),
0064     enableChecking = cms.untracked.bool(True),
0065     verbose = cms.untracked.bool(True)
0066 )
0067 
0068 process.maxEvents = cms.untracked.PSet(
0069     input = cms.untracked.int32(5)
0070 )
0071 
0072 # The RandomNumberGeneratorService should work with
0073 # any kind of source
0074 process.source = cms.Source("EmptySource",
0075     firstRun = cms.untracked.uint32(1),
0076     firstLuminosityBlock = cms.untracked.uint32(1),
0077     firstEvent = cms.untracked.uint32(1),
0078     numberEventsInRun = cms.untracked.uint32(100),
0079     numberEventsInLuminosityBlock = cms.untracked.uint32(3)
0080 )
0081 
0082 process.t1 = cms.EDAnalyzer("TestRandomNumberServiceGlobal",
0083                             # information enough that the test module can calculate
0084                             # the random numbers it should be getting from the service
0085                             engineName = cms.untracked.string('HepJamesRandom'),
0086                             seeds = cms.untracked.vuint32(81),
0087                             offset = cms.untracked.uint32(0),
0088                             maxEvents = cms.untracked.uint32(5),
0089                             dump = cms.untracked.bool(True),
0090                             nStreams = cms.untracked.uint32(1)
0091 )
0092 process.t2 = cms.EDAnalyzer("TestRandomNumberServiceGlobal",
0093                             engineName = cms.untracked.string('RanecuEngine'),
0094                             seeds = cms.untracked.vuint32(1, 2),
0095                             offset = cms.untracked.uint32(0),
0096                             maxEvents = cms.untracked.uint32(5),
0097                             dump = cms.untracked.bool(True),
0098                             nStreams = cms.untracked.uint32(1)
0099 )
0100 process.t3 = cms.EDAnalyzer("TestRandomNumberServiceGlobal",
0101                             engineName = cms.untracked.string('TRandom3'),
0102                             seeds = cms.untracked.vuint32(83),
0103                             offset = cms.untracked.uint32(0),
0104                             maxEvents = cms.untracked.uint32(5),
0105                             nStreams = cms.untracked.uint32(1),
0106                             # only turn on dump for one module otherwise the
0107                             # time order of module execution may affect the diffs
0108                             # For a similar reason only use in processes with 1 stream.
0109                             dump = cms.untracked.bool(True)
0110 )
0111 process.t4 = cms.EDAnalyzer("TestRandomNumberServiceGlobal",
0112                             engineName = cms.untracked.string('HepJamesRandom'),
0113                             seeds = cms.untracked.vuint32(84),
0114                             offset = cms.untracked.uint32(0),
0115                             maxEvents = cms.untracked.uint32(5),
0116                             dump = cms.untracked.bool(True),
0117                             nStreams = cms.untracked.uint32(1)
0118 )
0119 
0120 process.t6 = cms.EDAnalyzer("TestRandomNumberServiceGlobal",
0121                             engineName = cms.untracked.string('MixMaxRng'),
0122                             seeds = cms.untracked.vuint32(85),
0123                             offset = cms.untracked.uint32(0),
0124                             maxEvents = cms.untracked.uint32(5),
0125                             dump = cms.untracked.bool(True),
0126                             nStreams = cms.untracked.uint32(1)
0127 )
0128 
0129 # If you do not want to save the state of the random engines
0130 # leave this line out.
0131 # Including this producer causes the states to be stored
0132 # in the event and luminosity block.  The label used here
0133 # must be referenced in a later process to restore the state
0134 # of the engines.
0135 process.randomEngineStateProducer = cms.EDProducer("RandomEngineStateProducer")
0136 
0137 process.out = cms.OutputModule("PoolOutputModule",
0138     fileName = cms.untracked.string('testRandomService1.root')
0139 )
0140 
0141 process.p = cms.Path(process.t1+process.t2+process.t3+process.t4+process.t6+process.randomEngineStateProducer)
0142 process.o = cms.EndPath(process.out)