DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
dd4hep::sim::Geant4Random Class Reference

Mini interface to THE random generator of the application. More...

#include <Geant4Random.h>

Inheritance diagram for dd4hep::sim::Geant4Random:
dd4hep::sim::Geant4Action

Public Member Functions

 Geant4Random (Geant4Context *context, const std::string &name)
 Standard constructor. More...
 
virtual ~Geant4Random ()
 Default destructor. More...
 
void initialize ()
 Initialize the instance. More...
 
CLHEP::HepRandomEngine * engine ()
 CLHEP random number engine (valid after initialization only) More...
 
virtual void setSeed (long seed)
 Should initialise the status of the algorithm according to seed. More...
 
virtual void setSeeds (const long *seeds, int size)
 Should initialise the status of the algorithm. More...
 
virtual void saveStatus (const char filename[]="Config.conf") const
 Should save on a file specific to the instantiated engine in use the current status. More...
 
virtual void restoreStatus (const char filename[]="Config.conf")
 Should read from a file and restore the last saved engine configuration. More...
 
virtual void showStatus () const
 Should dump the current engine status on the screen. More...
 
double rndm_clhep ()
 Create flat distributed random numbers in the interval ]0,1] calling CLHEP. More...
 
double rndm (int i=0)
 Create flat distributed random numbers in the interval ]0,1]. More...
 
void rndmArray (int n, float *array)
 Create a float array of flat distributed random numbers in the interval ]0,1]. More...
 
void rndmArray (int n, double *array)
 Create a double array of flat distributed random numbers in the interval ]0,1]. More...
 
double uniform (double x1=1)
 Create uniformly disributed random numbers in the interval ]0,x1]. More...
 
double uniform (double x1, double x2)
 Create uniformly disributed random numbers in the interval ]x1,x2]. More...
 
double exp (double tau)
 Create exponentially distributed random numbers. More...
 
double gauss (double mean=0, double sigma=1)
 Create gaussian distributed random numbers. More...
 
double gamma (double k, double lambda)
 Create gamma distributed random numbers. More...
 
double landau (double mean=0, double sigma=1)
 Create landau distributed random numbers. More...
 
void circle (double &x, double &y, double r)
 Create tuple of randum number around a circle with radius r. More...
 
void sphere (double &x, double &y, double &z, double r)
 Create tuple of randum number on a sphere with radius r. More...
 
double poisson (double mean=1e0)
 Create poisson distributed random numbers. More...
 
double breit_wigner (double mean=0e0, double gamma=1e0)
 Create breit wigner distributed random numbers. More...
 
- Public Member Functions inherited from dd4hep::sim::Geant4Action
 Geant4Action (Geant4Context *context, const std::string &nam)
 Standard constructor. More...
 
long addRef ()
 Increase reference count. More...
 
long release ()
 Decrease reference count. Implicit destruction. More...
 
Geant4Contextcontext () const
 Access the context. More...
 
virtual void updateContext (Geant4Context *ctxt)
 Set or update client context. More...
 
virtual void configureFiber (Geant4Context *thread_context)
 Set or update client for the use in a new thread fiber. More...
 
const std::string & name () const
 Access name of the action. More...
 
const char * c_name () const
 Access name of the action. More...
 
void setName (const std::string &new_name)
 Set the object name. More...
 
PropertyManagerproperties ()
 Access to the properties of the object. More...
 
PrintLevel outputLevel () const
 Access the output level. More...
 
PrintLevel setOutputLevel (PrintLevel new_level)
 Set the output level; returns previous value. More...
 
Geant4UIMessengercontrol () const
 Access to the UI messenger. More...
 
virtual void enableUI ()
 Enable and install UI messenger. More...
 
template<typename T >
Geant4ActiondeclareProperty (const std::string &nam, T &val)
 Declare property. More...
 
template<typename T >
Geant4ActiondeclareProperty (const char *nam, T &val)
 Declare property. More...
 
bool hasProperty (const std::string &name) const
 Check property for existence. More...
 
Propertyproperty (const std::string &name)
 Access single property. More...
 
virtual void installMessengers ()
 Install property control messenger if wanted. More...
 
virtual void installCommandMessenger ()
 Install command control messenger if wanted. More...
 
virtual void installPropertyMessenger ()
 Install property control messenger if wanted. More...
 
void print (const char *fmt,...) const
 Support for messages with variable output level using output level. More...
 
void printM1 (const char *fmt,...) const
 Support for messages with variable output level using output level-1. More...
 
void printM2 (const char *fmt,...) const
 Support for messages with variable output level using output level-2. More...
 
void printP1 (const char *fmt,...) const
 Support for messages with variable output level using output level+1. More...
 
void printP2 (const char *fmt,...) const
 Support for messages with variable output level using output level+2. More...
 
void always (const char *fmt,...) const
 Support of always printed messages. More...
 
void debug (const char *fmt,...) const
 Support of debug messages. More...
 
void info (const char *fmt,...) const
 Support of info messages. More...
 
void warning (const char *fmt,...) const
 Support of warning messages. More...
 
void error (const char *fmt,...) const
 Support of error messages. More...
 
bool return_error (bool return_value, const char *fmt,...) const
 Action to support error messages. More...
 
void fatal (const char *fmt,...) const
 Support of fatal messages. Throws exception. More...
 
void except (const char *fmt,...) const
 Support of exceptions: Print fatal message and throw runtime_error. More...
 
void abortRun (const std::string &exception, const char *fmt,...) const
 Abort Geant4 Run by throwing a G4Exception with type RunMustBeAborted. More...
 
Geant4RunActionSequencerunAction () const
 Access to the main run action sequence from the kernel object. More...
 
Geant4EventActionSequenceeventAction () const
 Access to the main event action sequence from the kernel object. More...
 
Geant4SteppingActionSequencesteppingAction () const
 Access to the main stepping action sequence from the kernel object. More...
 
Geant4TrackingActionSequencetrackingAction () const
 Access to the main tracking action sequence from the kernel object. More...
 
Geant4StackingActionSequencestackingAction () const
 Access to the main stacking action sequence from the kernel object. More...
 
Geant4GeneratorActionSequencegeneratorAction () const
 Access to the main generator action sequence from the kernel object. More...
 

Static Public Member Functions

static Geant4Randominstance (bool throw_exception=true)
 Access the main Geant4 random generator instance. Must be created before used! More...
 
static Geant4RandomsetMainInstance (Geant4Random *ptr)
 Make this random generator instance the one used by Geant4. More...
 

Protected Attributes

std::string m_file
 Property: File name if initialized from file. If set, engine name and seeds are ignored. More...
 
std::string m_engineType
 Property: Engine type. default: "HepJamesRandom". More...
 
long m_seed
 Property: Initial random seed. Default: 123456789. More...
 
long m_luxury
 
bool m_replace
 Property: Indicator to replace the ROOT gRandom instance. More...
 
CLHEP::HepRandomEngine * m_engine
 Reference to the CLHEP random number engine (valid only after initialization) More...
 
TRandom * m_rootRandom
 Reference to ROOT random instance. More...
 
TRandom * m_rootOLD
 
bool m_inited
 Flag to remember initialization. More...
 
- Protected Attributes inherited from dd4hep::sim::Geant4Action
Geant4Contextm_context { nullptr }
 Reference to the Geant4 context. More...
 
Geant4UIMessengerm_control { nullptr }
 Control directory of this action. More...
 
int m_outputLevel { 3 }
 Default property: Output level. More...
 
bool m_needsControl { false }
 Default property: Flag to create control instance. More...
 
std::string m_name { }
 Action name. More...
 
PropertyManager m_properties { }
 Property pool. More...
 
long m_refCount { 1 }
 Reference count. Initial value: 1. More...
 

Friends

class Geant4Exec
 

Additional Inherited Members

- Protected Member Functions inherited from dd4hep::sim::Geant4Action
 DDG4_DEFINE_ACTION_CONSTRUCTORS (Geant4Action)
 Define standard assignments and constructors. More...
 
virtual ~Geant4Action ()
 Default destructor. More...
 

Detailed Description

Mini interface to THE random generator of the application.

Mini interface to THE random generator of the application. Necessary, that on every object creates its own instance, but accesses the main instance avaible throu the Geant4Context.

This is mandatory to ensure reproducability of the event generation process. Particular objects may use a dependent generator from an experiment framework like GAUDI.

This main interface is supposed to be stable. Unclear however is if the generation functions will have to become virtual.... Future will tell us.

The first instance of the random action is automatically set to be the Geant4 instance. If another instance should be used by Geant4, use setMainInstance(Geant4Random* ptr).

Author
M.Frank
Version
1.0

Definition at line 59 of file Geant4Random.h.

Constructor & Destructor Documentation

◆ Geant4Random()

Geant4Random::Geant4Random ( Geant4Context context,
const std::string &  name 
)

Standard constructor.

Default constructor.

Please Note: Should be used only for initialization of the main instance. Subsequent usage should be invoked using the class member Geant4Random::instance().

Parameters
contextGeant4 context for this action.
nameName of the action object

Definition at line 82 of file Geant4Random.cpp.

◆ ~Geant4Random()

Geant4Random::~Geant4Random ( )
virtual

Default destructor.

Definition at line 97 of file Geant4Random.cpp.

Member Function Documentation

◆ breit_wigner()

double Geant4Random::breit_wigner ( double  mean = 0e0,
double  gamma = 1e0 
)

Create breit wigner distributed random numbers.

Definition at line 334 of file Geant4Random.cpp.

◆ circle()

void Geant4Random::circle ( double &  x,
double &  y,
double  r 
)

Create tuple of randum number around a circle with radius r.

Definition at line 316 of file Geant4Random.cpp.

◆ engine()

CLHEP::HepRandomEngine* dd4hep::sim::Geant4Random::engine ( )
inline

CLHEP random number engine (valid after initialization only)

Access to the CLHEP random number engine. For further doc see CLHEP/Random/RandomEngine.h

Definition at line 116 of file Geant4Random.h.

◆ exp()

double Geant4Random::exp ( double  tau)

Create exponentially distributed random numbers.

Definition at line 298 of file Geant4Random.cpp.

◆ gamma()

double Geant4Random::gamma ( double  k,
double  lambda 
)

Create gamma distributed random numbers.

Definition at line 340 of file Geant4Random.cpp.

◆ gauss()

double Geant4Random::gauss ( double  mean = 0,
double  sigma = 1 
)

Create gaussian distributed random numbers.

Generates random vectors, uniformly distributed over a circle of given radius.

Definition at line 304 of file Geant4Random.cpp.

◆ initialize()

void Geant4Random::initialize ( )

Initialize the instance.

Called either by user or on request of the first random number. To propagate the engine to Geant4, initialize MUST be called by the user.

Create new engine if a type is specified

Definition at line 158 of file Geant4Random.cpp.

◆ instance()

Geant4Random * Geant4Random::instance ( bool  throw_exception = true)
static

Access the main Geant4 random generator instance. Must be created before used!

Definition at line 113 of file Geant4Random.cpp.

◆ landau()

double Geant4Random::landau ( double  mean = 0,
double  sigma = 1 
)

Create landau distributed random numbers.

Definition at line 310 of file Geant4Random.cpp.

◆ poisson()

double Geant4Random::poisson ( double  mean = 1e0)

Create poisson distributed random numbers.

Definition at line 328 of file Geant4Random.cpp.

◆ restoreStatus()

void Geant4Random::restoreStatus ( const char  filename[] = "Config.conf")
virtual

Should read from a file and restore the last saved engine configuration.

Definition at line 224 of file Geant4Random.cpp.

◆ rndm()

double Geant4Random::rndm ( int  i = 0)

Create flat distributed random numbers in the interval ]0,1].

Definition at line 268 of file Geant4Random.cpp.

◆ rndm_clhep()

double Geant4Random::rndm_clhep ( )

Create flat distributed random numbers in the interval ]0,1] calling CLHEP.

Create flat distributed random numbers in the interval ]0,1].

Basic random generator functions
This is more or less a test function, since the result should be identical to calling rndm.

Definition at line 262 of file Geant4Random.cpp.

◆ rndmArray() [1/2]

void Geant4Random::rndmArray ( int  n,
double *  array 
)

Create a double array of flat distributed random numbers in the interval ]0,1].

Definition at line 280 of file Geant4Random.cpp.

◆ rndmArray() [2/2]

void Geant4Random::rndmArray ( int  n,
float *  array 
)

Create a float array of flat distributed random numbers in the interval ]0,1].

Definition at line 274 of file Geant4Random.cpp.

◆ saveStatus()

void Geant4Random::saveStatus ( const char  filename[] = "Config.conf") const
virtual

Should save on a file specific to the instantiated engine in use the current status.

Definition at line 216 of file Geant4Random.cpp.

◆ setMainInstance()

Geant4Random * Geant4Random::setMainInstance ( Geant4Random ptr)
static

Make this random generator instance the one used by Geant4.

Returns reference to previous instance. It is up to the user to manage the reference. Caveat: other code may hold references to this instance.

Parameters
ptrReference to main random number generator
Returns
Reference to previous random number generator instance

Definition at line 121 of file Geant4Random.cpp.

◆ setSeed()

void Geant4Random::setSeed ( long  seed)
virtual

Should initialise the status of the algorithm according to seed.

Definition at line 199 of file Geant4Random.cpp.

◆ setSeeds()

void Geant4Random::setSeeds ( const long *  seeds,
int  size 
)
virtual

Should initialise the status of the algorithm.

Initialization according to the zero terminated array of seeds. It is allowed to ignore one or many seeds in this array.

Definition at line 209 of file Geant4Random.cpp.

◆ showStatus()

void Geant4Random::showStatus ( ) const
virtual

Should dump the current engine status on the screen.

Definition at line 230 of file Geant4Random.cpp.

◆ sphere()

void Geant4Random::sphere ( double &  x,
double &  y,
double &  z,
double  r 
)

Create tuple of randum number on a sphere with radius r.

Definition at line 322 of file Geant4Random.cpp.

◆ uniform() [1/2]

double Geant4Random::uniform ( double  x1,
double  x2 
)

Create uniformly disributed random numbers in the interval ]x1,x2].

Definition at line 292 of file Geant4Random.cpp.

◆ uniform() [2/2]

double Geant4Random::uniform ( double  x1 = 1)

Create uniformly disributed random numbers in the interval ]0,x1].

Definition at line 286 of file Geant4Random.cpp.

Friends And Related Function Documentation

◆ Geant4Exec

friend class Geant4Exec
friend

Definition at line 60 of file Geant4Random.h.

Member Data Documentation

◆ m_engine

CLHEP::HepRandomEngine* dd4hep::sim::Geant4Random::m_engine
protected

Reference to the CLHEP random number engine (valid only after initialization)

Definition at line 73 of file Geant4Random.h.

◆ m_engineType

std::string dd4hep::sim::Geant4Random::m_engineType
protected

Property: Engine type. default: "HepJamesRandom".

Definition at line 66 of file Geant4Random.h.

◆ m_file

std::string dd4hep::sim::Geant4Random::m_file
protected

Property: File name if initialized from file. If set, engine name and seeds are ignored.

Definition at line 64 of file Geant4Random.h.

◆ m_inited

bool dd4hep::sim::Geant4Random::m_inited
protected

Flag to remember initialization.

Definition at line 78 of file Geant4Random.h.

◆ m_luxury

long dd4hep::sim::Geant4Random::m_luxury
protected

Definition at line 68 of file Geant4Random.h.

◆ m_replace

bool dd4hep::sim::Geant4Random::m_replace
protected

Property: Indicator to replace the ROOT gRandom instance.

Definition at line 70 of file Geant4Random.h.

◆ m_rootOLD

TRandom * dd4hep::sim::Geant4Random::m_rootOLD
protected

Definition at line 76 of file Geant4Random.h.

◆ m_rootRandom

TRandom* dd4hep::sim::Geant4Random::m_rootRandom
protected

Reference to ROOT random instance.

Definition at line 76 of file Geant4Random.h.

◆ m_seed

long dd4hep::sim::Geant4Random::m_seed
protected

Property: Initial random seed. Default: 123456789.

Definition at line 68 of file Geant4Random.h.


The documentation for this class was generated from the following files: