Athena Developer Guide
Athena Developer Guide
Athena Developer Guide
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Athena</strong><br />
Chapter 13 Framework services Version/Issue: 2.0.0<br />
• Within the user code a series of numbers is required only once, i.e. not every event. In this<br />
case the object is used locally and resources are released immediately after use. This example<br />
is shown in Listing 13.5 .<br />
Listing 13.5 Example of the use of the random number generator to fill a histogram with a Gaussian<br />
distribution within a standard <strong>Athena</strong> algorithm<br />
1: Rndm::Numbers gauss(randSvc(), Rndm::Gauss(0.5,0.2));<br />
2: if ( gauss ) {<br />
3: IHistogram1D* his = histoSvc()->book("/stat/2","Gaussian",40,0.,3.);<br />
4: for ( long i = 0; i < 5000; i++ )<br />
5: his->fill(gauss(), 1.0);<br />
6: }<br />
• One or several random numbers are required for the processing of every event. An example is<br />
shown in Listing 13.6.<br />
Listing 13.6 Example of the use of the random number generator within a standard <strong>Athena</strong> algorithm, for use<br />
at every event. The wrapper to the generator is part of the Algorithm itself and must be initialized before being<br />
used. Afterwards the usage is identical to the example described in Listing 13.5<br />
1: #include "GaudiKernel/RndmGenerators.h"<br />
2:<br />
3: // Constructor<br />
4: class myAlgorithm : public Algorithm {<br />
5: Rndm::Numbers m_gaussDist;<br />
6: ...<br />
7: };<br />
8:<br />
9: // Initialisation<br />
10: StatusCode myAlgorithm::initialize() {<br />
11: ...<br />
1: StatusCode sc=m_gaussDist.initialize(randSvc(), Rndm::Gauss(0.5,0.2));<br />
2: if ( !status.isSuccess() ) {<br />
3: // put error handling code here...<br />
4: }<br />
5: ...<br />
6: }<br />
There are a few points to be mentioned in order to ensure the reproducibility:<br />
• Do not keep numbers across events. If you need a random number ask for it. Usually caching<br />
does more harm than good. If there is a performance penalty, it is better to find a more generic<br />
solution.<br />
• Do not access the RndmEngine directly.<br />
• Do not manipulate the engine. The random seeds should only be set by the framework on an<br />
event by event basis.<br />
page 117