CbmRoot
Loading...
Searching...
No Matches
cbm::algo::ca::Random Class Reference

A class, providing ROOT-free access to randomly generated variables. More...

#include <CaAlgoRandom.h>

Public Member Functions

 Random ()
 Default constructor.
 
 Random (int seed)
 Constructor.
 
 ~Random ()=default
 Destructor.
 
 Random (const Random &other)=delete
 Copy constructor.
 
 Random (Random &&other)=delete
 Move constructor.
 
Randomoperator= (const Random &)=delete
 Copy assignment operator.
 
Randomoperator= (Random &&)=delete
 Move assignment operator.
 
int GetSeed () const
 Gets seed of the random generator.
 
void SetSeed (int seed)
 Sets seed to the random generator.
 
template<typename T , std::enable_if_t< std::is_floating_point< T >::value, bool > = true>
BoundedGaus (const T &mean, const T &sigma, const T &nSigmas) const
 Returns a normally distributed random value, limited within a selected sigma range.
 
template<typename T , std::enable_if_t< std::is_floating_point< T >::value, bool > = true>
Uniform (const T &mean, const T &sigma) const
 Returns a random value, addressed with a continuous uniform distribution.
 

Private Types

using GeneratorType_t = std::mt19937_64
 

Private Attributes

GeneratorType_t fGenerator
 Random number generator.
 
unsigned int fSeed = 1
 Random number seed.
 

Detailed Description

A class, providing ROOT-free access to randomly generated variables.

Definition at line 22 of file CaAlgoRandom.h.

Member Typedef Documentation

◆ GeneratorType_t

using cbm::algo::ca::Random::GeneratorType_t = std::mt19937_64
private

Definition at line 23 of file CaAlgoRandom.h.

Constructor & Destructor Documentation

◆ Random() [1/4]

Random::Random ( )

Default constructor.

Sets seed equal to 1

Definition at line 17 of file CaAlgoRandom.cxx.

◆ Random() [2/4]

Random::Random ( int seed)

Constructor.

Parameters
seedA random seed

If 0 is selected for the random seed, the generator is seeded with std::random_device

Definition at line 21 of file CaAlgoRandom.cxx.

References SetSeed().

◆ ~Random()

cbm::algo::ca::Random::~Random ( )
default

Destructor.

◆ Random() [3/4]

cbm::algo::ca::Random::Random ( const Random & other)
delete

Copy constructor.

◆ Random() [4/4]

cbm::algo::ca::Random::Random ( Random && other)
delete

Move constructor.

Member Function Documentation

◆ BoundedGaus()

template<typename T , std::enable_if_t< std::is_floating_point< T >::value, bool > >
T cbm::algo::ca::Random::BoundedGaus ( const T & mean,
const T & sigma,
const T & nSigmas ) const

Returns a normally distributed random value, limited within a selected sigma range.

Template Parameters
TType of floating point numbers
Parameters
meanMean of the distribution
sigmaSigma of the distribution
nSigmasHalf-width of the generated numbers domain, expressed in number of sigmas

Definition at line 90 of file CaAlgoRandom.h.

References fGenerator.

◆ GetSeed()

int cbm::algo::ca::Random::GetSeed ( ) const
inline

Gets seed of the random generator.

Definition at line 53 of file CaAlgoRandom.h.

References fSeed.

◆ operator=() [1/2]

Random & cbm::algo::ca::Random::operator= ( const Random & )
delete

Copy assignment operator.

◆ operator=() [2/2]

Random & cbm::algo::ca::Random::operator= ( Random && )
delete

Move assignment operator.

◆ SetSeed()

void Random::SetSeed ( int seed)

Sets seed to the random generator.

Parameters
seedA random seed

If 0 is selected for the random seed, the generator is seeded with std::random_device

Definition at line 25 of file CaAlgoRandom.cxx.

References fGenerator, and fSeed.

Referenced by Random(), and cbm::ca::IdealHitProducerDet< DetID >::SetRandomSeed().

◆ Uniform()

template<typename T , std::enable_if_t< std::is_floating_point< T >::value, bool > >
T cbm::algo::ca::Random::Uniform ( const T & mean,
const T & sigma ) const

Returns a random value, addressed with a continuous uniform distribution.

Template Parameters
TType of floating point numbers
Parameters
meanMean of the distribution
sigmaSigma of the distribution

Definition at line 106 of file CaAlgoRandom.h.

References fGenerator.

Member Data Documentation

◆ fGenerator

GeneratorType_t cbm::algo::ca::Random::fGenerator
mutableprivate

Random number generator.

Definition at line 78 of file CaAlgoRandom.h.

Referenced by BoundedGaus(), SetSeed(), and Uniform().

◆ fSeed

unsigned int cbm::algo::ca::Random::fSeed = 1
private

Random number seed.

Definition at line 79 of file CaAlgoRandom.h.

Referenced by GetSeed(), and SetSeed().


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