12.07.2015 Views

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Toolkit Fundamentals1. Using the static generator defined in the HepRandom class: random values are shot using static methodsshoot() defined <strong>for</strong> each distribution class. The static generator will use, as default engine, a HepJamesRandomobject, and the user can set its properties or change it with a new instantiated engine object by using thestatic methods defined in the HepRandom class.2. Skipping the static generator and specifying an engine object: random values are shot using static methodsshoot(*HepRandomEngine) defined <strong>for</strong> each distribution class. The user must instantiate an engine objectand give it as argument to the shoot method. The generator mechanism will then be by-passed by using thebasic flat() method of the specified engine. The user must take care of the engine objects he/she instantiates.3. Skipping the static generator and instantiating a distribution object: random values are shot using fire()methods (NOT static) defined <strong>for</strong> each distribution class. The user must instantiate a distribution object givingas argument to the constructor an engine by pointer or by reference. By doing so, the engine will be associatedto the distribution object and the generator mechanism will be by-passed by using the basic flat() methodof that engine.In this guide, we'll only focus on the static generator (point 1.), since the static interface of HEPRandom is theonly one used within the <strong>Geant4</strong> toolkit.3.2.2.1. HEPRandom enginesThe class HepRandomEngine is the abstract class defining the interface <strong>for</strong> each random engine. It implementsthe getSeed() and getSeeds() methods which return the `initial seed' value and the initial array of seeds(if any) respectively. Many concrete random engines can be defined and added to the structure, simply makingthem inheriting from HepRandomEngine. Several different engines are currently implemented in HepRandom, wedescribe here five of them:• HepJamesRandomIt implements the algorithm described in ``F.James, Comp. Phys. Comm. 60 (1990) 329'' <strong>for</strong> pseudo-randomnumber generation. This is the default random engine <strong>for</strong> the static generator; it will be invoked by each distributionclass unless the user sets a different one.• DRand48EngineRandom engine using the drand48() and srand48() system functions from C standard library to implementthe flat() basic distribution and <strong>for</strong> setting seeds respectively. DRand48Engine uses the seed48()function from C standard library to retrieve the current internal status of the generator, which is represented by3 short values. DRand48Engine is the only engine defined in HEPRandom which intrinsically works in 32 bitsprecision. Copies of an object of this kind are not allowed.• RandEngineSimple random engine using the rand() and srand() system functions from the C standard library to implementthe flat() basic distribution and <strong>for</strong> setting seeds respectively. Please note that it's well known thatthe spectral properties of rand() leave a great deal to be desired, there<strong>for</strong>e the usage of this engine is notrecommended if a good randomness quality or a long period is required in your code. Copies of an object ofthis kind are not allowed.• RanluxEngineThe algorithm <strong>for</strong> RanluxEngine has been taken from the original implementation in FORTRAN77 by FredJames, part of the MATHLIB HEP library. The initialisation is carried out using a Multiplicative Congruentialgenerator using <strong>for</strong>mula constants of L'Ecuyer as described in ``F.James, Comp. Phys. Comm. 60 (1990)329-344''. The engine provides five different luxury levels <strong>for</strong> quality of random generation. When instantiatinga RanluxEngine, the user can specify the luxury level to the constructor (if not, the default value 3 is taken).For example:RanluxEngine theRanluxEngine(seed,4);// instantiates an engine with `seed' and the best luxury-level... orRanluxEngine theRanluxEngine;// instantiates an engine with default seed value and luxury-level...36

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!