All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RandomNumberAlg.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/SmartIF.h"
5 #include "GaudiKernel/IRndmGen.h"
11 
12 #include "AIDA/IHistogram1D.h"
13 #include "AIDA/IHistogram2D.h"
14 
15 // Example related include files
16 #include "RandomNumberAlg.h"
17 
19 
20 
23 RandomNumberAlg::RandomNumberAlg(const std::string& name, ISvcLocator* pSvcLocator)
24 : Algorithm(name, pSvcLocator) {
25 }
26 
27 // Standard destructor
29 }
30 
31 // The "functional" part of the class: For the EmptyAlgorithm example they do
32 // nothing apart from print out info messages.
34  MsgStream log(msgSvc(), name());
35  StatusCode sc;
36 
37  // Initilize random number generators
39  if ( sc.isFailure() ) return sc;
40  sc = m_gaussNumbers.initialize(randSvc(), Rndm::Gauss(0.5,0.2));
41  if ( sc.isFailure() ) return sc;
43  if ( sc.isFailure() ) return sc;
44 
45 
46  // Initiatize Histograms
47  m_gaussHisto = histoSvc()->book( "simple/1", "Gauss", 40, 0., 3.);
48  m_gauss2Histo = histoSvc()->book( "simple/2", "Gauss 2D", 40, 0., 3., 50, 0., 3.);
49  m_expHisto = histoSvc()->book( "simple/3", "Exponential", 40, 0., 3.);
50  m_poissonHisto = histoSvc()->book( "simple/4", "Poisson", 40, 0., 3.);
51 
52  return sc;
53 }
54 
56  MsgStream log(msgSvc(), name());
57  StatusCode sc;
58 
59  m_gaussHisto->fill(m_gaussNumbers(), 1.0 );
61  m_poissonHisto->fill(m_poissonNumbers(), 1.0 );
62  m_expHisto->fill(m_expNumbers(), 1.0 );
63  return sc;
64 }
65 
67  return StatusCode::SUCCESS;
68 }
69 
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual ~RandomNumberAlg()
Standard Destructor.
Rndm::Numbers m_expNumbers
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
AIDA::IHistogram1D * m_poissonHisto
SmartIF< IHistogramSvc > & histoSvc() const
The standard histogram service.
Parameters for the Poisson distributed random number generation with a given mean.
Parameters for the Gauss random number generation.
virtual StatusCode execute()
Event callback.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
Rndm::Numbers m_poissonNumbers
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
AIDA::IHistogram2D * m_gauss2Histo
virtual const std::string & name() const
The identifying name of the algorithm object.
Definition: Algorithm.cpp:837
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:896
SmartIF< IRndmGenSvc > & randSvc() const
AIDA-based NTuple service Returns a pointer to the AIDATuple service if present.
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:61
virtual StatusCode initialize()
Customized initialisation.
AIDA::IHistogram1D * m_expHisto
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Rndm::Numbers m_gaussNumbers
Allocate wrapper for random number generator.
virtual StatusCode finalize()
Customized finalisation.
A small algorithm class using the random number service.
Parameters for the Gauss random number generation.
AIDA::IHistogram1D * m_gaussHisto