Manual:Random numbers
Offline Documentation: [Offline Category] [FAQ] [Howto] [Reference] [Manual] |
Offline Documentation |
This article is part of the Offline Documentation |
Other pages... |
Offline Category |
See also... |
Pseudo-random number streams are managed implicitly by nuwa.py
.
Random Number Systems
We use CLHEP's random number system though the layer that Gaudi provides. Geant4 uses the same system. It is allowed to use ROOT's TRandom system but never set its seed from user code. The ROOT seed is set at the same time as the CLHEP one, and to the same value. All other random number system, including Pythons should not be used as doing so may lead to irreproducible results.
Managing the Random Seeds
The random stream is initialized once per execution cycle. The seed is built from the run number, execution cycle number, and hostid. Just after initialization some number of randoms are drawn ("burnt") as it was found there were otherwise correlations.
The user can achieve reproducibility by specifying the run number, execution cycle number and host id in
nuwa.py -R runnumber -N execcycle -H hostid
The algorithm that manages this is DybAlg/DybShuffle. This algorithm saves a record of the seeds for each execution cycle in:
/Event/Random/RandomHeader
The object is at this location is a RandomHeader
Consuming Random Numbers
If your code needs to consume/use random numbers it should use Gaudi's random facilities. These are best accessed through Rndm::Numbers
objects. When writing an algorithm make a Rndm::Numbers
object for each distribution you need. Here is an example from GenTools/GtPositionerTool:
// declare inside class definition in the .h file: private: Rndm::Numbers m_uni, m_gauss;
// initialize inside initialize() IRndmGenSvc *rgs = 0; if (service("RndmGenSvc",rgs,true).isFailure()) { fatal() << "Failed to get random service" << endreq; return StatusCode::FAILURE; } if (m_uni.initialize(rgs, Rndm::Flat(0,1)).isFailure()) { fatal() << "Failed to initialize uniform random numbers" << endreq; return StatusCode::FAILURE; } if (m_gauss.initialize(rgs, Rndm::Gauss(0,1)).isFailure()) { fatal() << "Failed to initialize Gaussian random numbers" << endreq; return StatusCode::FAILURE; }
// Consume: x = m_gauss() * rms + mean; t = m_uni() * (max-min) + min;
Offline Software Documentation: [Offline Categories] [FAQ] [Offline Manual Category] |