Logo ROOT  
Reference Guide
TUnuranDiscrDist Class Reference

TUnuranDiscrDist class for one dimensional discrete distribution.

It is used by TUnuran to generate integer random numbers according to this distribution via TUnuran::SampleDiscr().

The class can be constructed from a one-dimensional function (TF1 pointer) representing the discrete distribution (probability mesh function) (for example a TF1("f","TMath::PoissonI(x,[0])") ) or from a vector of probability, used by passing an iterator specifying the begin and the end of the vector. In the latter case the domain of the distribution will be defined by the vector, while in the first case is by default (0,+inf). a Method to set the domain of the distribution ( SetDomain ) is provided and it defines the range of the generated random numbers.

The derivatives of the pdf which are used by some UNURAN methods are estimated numerically in the Derivative() method. Some extra information (like distribution mode, cdf function, probability sum, etc..) can be set as well otherwise will be estimated internally if required.

Definition at line 51 of file TUnuranDiscrDist.h.

Public Member Functions

 TUnuranDiscrDist (const ROOT::Math::IGenFunction &func, bool copyFunc=false)
 Constructor from a generic function object specifying the pdf. More...
 
 TUnuranDiscrDist (const TUnuranDiscrDist &)
 Copy constructor. More...
 
template<class Iterator >
 TUnuranDiscrDist (Iterator *begin, Iterator *end)
 Constructor from a vector of probability. More...
 
 TUnuranDiscrDist (TF1 *func)
 Constructor from a TF1 objects specifying the pdf. More...
 
 ~TUnuranDiscrDist () override
 Destructor. More...
 
double Cdf (int x) const
 evaluate the integral (cdf) on the given domain More...
 
TUnuranDiscrDistClone () const override
 Clone (required by base class) More...
 
bool GetDomain (int &xmin, int &xmax) const
 check if distribution has domain and return in case its domain More...
 
bool HasCdf () const
 flag to control if distribution provides also a Cdf More...
 
bool HasMode () const
 flag to control if distribution provides the mode More...
 
bool HasProbSum () const
 flag to control if distribution provides the total area of the probability function More...
 
TClassIsA () const override
 
int Mode () const
 get the mode (x location of function maximum) More...
 
TUnuranDiscrDistoperator= (const TUnuranDiscrDist &rhs)
 Assignment operator. More...
 
double Pmf (int x) const
 evaluate the distribution (probability mesh function) at the integer value x. More...
 
double ProbSum () const
 return area of the pdf More...
 
const std::vector< double > & ProbVec () const
 retrieve a reference to the vector of the probabilities : Prob(i) If the distribution is defined from a function (i.e. More...
 
void SetCdf (const ROOT::Math::IGenFunction &cdf)
 set cdf distribution from a generic function interface. More...
 
void SetCdf (TF1 *cdf)
 set cdf distribution from a TF1 pointer. More...
 
void SetDomain (int xmin, int xmax)
 Set the distribution domain, by default the domain is [0,INT_MAX] If xmin >= xmax a domain is removed. More...
 
void SetMode (int mode)
 set the mode of the distribution (location of maximum probability) More...
 
void SetProbSum (double sum)
 set the value of the sum of the probabilities in the given domain More...
 
void Streamer (TBuffer &) override
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TUnuranBaseDist
virtual ~TUnuranBaseDist ()
 Destructor (no operations) More...
 
virtual TUnuranBaseDistClone () const =0
 Abstract clone method for a deep copy of the derived classes. More...
 
virtual TClassIsA () const
 
virtual void Streamer (TBuffer &)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TUnuranBaseDist
static TClassClass ()
 
static const char * Class_Name ()
 
static Version_t Class_Version ()
 
static const char * DeclFileName ()
 

Private Attributes

const ROOT::Math::IGenFunctionfCdf
 pointer to the cumulative distribution function More...
 
bool fHasDomain
 flag to control if distribution has a defined domain (otherwise is [0,INT_MAX]) More...
 
bool fHasMode
 flag to control if distribution has a pre-computed mode More...
 
bool fHasSum
 flag to control if distribution has a pre-computed sum of the probabilities More...
 
int fMode
 mode of the distribution More...
 
bool fOwnFunc
 flag to control if distribution owns the function pointers More...
 
const ROOT::Math::IGenFunctionfPmf
 pointer to a function calculating the probability More...
 
std::vector< doublefPVec
 Vector of the probabilities. More...
 
std::vector< doublefPVecSum
 Vector of the sum of the probabilities. More...
 
double fSum
 total sum of the probabilities in the given domain More...
 
int fXmax
 upper value of the domain More...
 
int fXmin
 lower value of the domain More...
 

#include <TUnuranDiscrDist.h>

Inheritance diagram for TUnuranDiscrDist:
[legend]

Constructor & Destructor Documentation

◆ TUnuranDiscrDist() [1/4]

TUnuranDiscrDist::TUnuranDiscrDist ( const ROOT::Math::IGenFunction func,
bool  copyFunc = false 
)

Constructor from a generic function object specifying the pdf.

Definition at line 23 of file TUnuranDiscrDist.cxx.

◆ TUnuranDiscrDist() [2/4]

TUnuranDiscrDist::TUnuranDiscrDist ( TF1 func)

Constructor from a TF1 objects specifying the pdf.

Definition at line 43 of file TUnuranDiscrDist.cxx.

◆ TUnuranDiscrDist() [3/4]

template<class Iterator >
TUnuranDiscrDist::TUnuranDiscrDist ( Iterator *  begin,
Iterator *  end 
)
inline

Constructor from a vector of probability.

Definition at line 69 of file TUnuranDiscrDist.h.

◆ ~TUnuranDiscrDist()

TUnuranDiscrDist::~TUnuranDiscrDist ( )
override

Destructor.

Definition at line 96 of file TUnuranDiscrDist.cxx.

◆ TUnuranDiscrDist() [4/4]

TUnuranDiscrDist::TUnuranDiscrDist ( const TUnuranDiscrDist rhs)

Copy constructor.

Definition at line 59 of file TUnuranDiscrDist.cxx.

Member Function Documentation

◆ Cdf()

double TUnuranDiscrDist::Cdf ( int  x) const

evaluate the integral (cdf) on the given domain

Definition at line 131 of file TUnuranDiscrDist.cxx.

◆ Class()

static TClass * TUnuranDiscrDist::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * TUnuranDiscrDist::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static Version_t TUnuranDiscrDist::Class_Version ( )
inlinestatic
Returns
Version of this class

Definition at line 216 of file TUnuranDiscrDist.h.

◆ Clone()

TUnuranDiscrDist * TUnuranDiscrDist::Clone ( ) const
inlineoverridevirtual

Clone (required by base class)

Implements TUnuranBaseDist.

Definition at line 101 of file TUnuranDiscrDist.h.

◆ DeclFileName()

static const char * TUnuranDiscrDist::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 216 of file TUnuranDiscrDist.h.

◆ GetDomain()

bool TUnuranDiscrDist::GetDomain ( int xmin,
int xmax 
) const
inline

check if distribution has domain and return in case its domain

Definition at line 143 of file TUnuranDiscrDist.h.

◆ HasCdf()

bool TUnuranDiscrDist::HasCdf ( ) const
inline

flag to control if distribution provides also a Cdf

Definition at line 174 of file TUnuranDiscrDist.h.

◆ HasMode()

bool TUnuranDiscrDist::HasMode ( ) const
inline

flag to control if distribution provides the mode

Definition at line 163 of file TUnuranDiscrDist.h.

◆ HasProbSum()

bool TUnuranDiscrDist::HasProbSum ( ) const
inline

flag to control if distribution provides the total area of the probability function

Definition at line 169 of file TUnuranDiscrDist.h.

◆ IsA()

TClass * TUnuranDiscrDist::IsA ( ) const
inlineoverridevirtual
Returns
TClass describing current object

Reimplemented from TUnuranBaseDist.

Definition at line 216 of file TUnuranDiscrDist.h.

◆ Mode()

int TUnuranDiscrDist::Mode ( ) const
inline

get the mode (x location of function maximum)

Definition at line 152 of file TUnuranDiscrDist.h.

◆ operator=()

TUnuranDiscrDist & TUnuranDiscrDist::operator= ( const TUnuranDiscrDist rhs)

Assignment operator.

Definition at line 68 of file TUnuranDiscrDist.cxx.

◆ Pmf()

double TUnuranDiscrDist::Pmf ( int  x) const

evaluate the distribution (probability mesh function) at the integer value x.

Used internally by UnuRan For integer values outside the domain the function must return 0.0

Definition at line 122 of file TUnuranDiscrDist.cxx.

◆ ProbSum()

double TUnuranDiscrDist::ProbSum ( ) const
inline

return area of the pdf

Definition at line 157 of file TUnuranDiscrDist.h.

◆ ProbVec()

const std::vector< double > & TUnuranDiscrDist::ProbVec ( ) const
inline

retrieve a reference to the vector of the probabilities : Prob(i) If the distribution is defined from a function (i.e.

for distribution with undefined domain) the vector is empty.

Definition at line 182 of file TUnuranDiscrDist.h.

◆ SetCdf() [1/2]

void TUnuranDiscrDist::SetCdf ( const ROOT::Math::IGenFunction cdf)

set cdf distribution from a generic function interface.

If a method requires it and is not set it is estimated numerically

Definition at line 104 of file TUnuranDiscrDist.cxx.

◆ SetCdf() [2/2]

void TUnuranDiscrDist::SetCdf ( TF1 cdf)

set cdf distribution from a TF1 pointer.

If a method requires it and is not set it is estimated numerically

Definition at line 109 of file TUnuranDiscrDist.cxx.

◆ SetDomain()

void TUnuranDiscrDist::SetDomain ( int  xmin,
int  xmax 
)
inline

Set the distribution domain, by default the domain is [0,INT_MAX] If xmin >= xmax a domain is removed.

Definition at line 120 of file TUnuranDiscrDist.h.

◆ SetMode()

void TUnuranDiscrDist::SetMode ( int  mode)
inline

set the mode of the distribution (location of maximum probability)

Definition at line 133 of file TUnuranDiscrDist.h.

◆ SetProbSum()

void TUnuranDiscrDist::SetProbSum ( double  sum)
inline

set the value of the sum of the probabilities in the given domain

Definition at line 138 of file TUnuranDiscrDist.h.

◆ Streamer()

void TUnuranDiscrDist::Streamer ( TBuffer )
overridevirtual

Reimplemented from TUnuranBaseDist.

◆ StreamerNVirtual()

void TUnuranDiscrDist::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 216 of file TUnuranDiscrDist.h.

Member Data Documentation

◆ fCdf

const ROOT::Math::IGenFunction* TUnuranDiscrDist::fCdf
private

pointer to the cumulative distribution function

Definition at line 205 of file TUnuranDiscrDist.h.

◆ fHasDomain

bool TUnuranDiscrDist::fHasDomain
private

flag to control if distribution has a defined domain (otherwise is [0,INT_MAX])

Definition at line 211 of file TUnuranDiscrDist.h.

◆ fHasMode

bool TUnuranDiscrDist::fHasMode
private

flag to control if distribution has a pre-computed mode

Definition at line 212 of file TUnuranDiscrDist.h.

◆ fHasSum

bool TUnuranDiscrDist::fHasSum
private

flag to control if distribution has a pre-computed sum of the probabilities

Definition at line 213 of file TUnuranDiscrDist.h.

◆ fMode

int TUnuranDiscrDist::fMode
private

mode of the distribution

Definition at line 208 of file TUnuranDiscrDist.h.

◆ fOwnFunc

bool TUnuranDiscrDist::fOwnFunc
private

flag to control if distribution owns the function pointers

Definition at line 214 of file TUnuranDiscrDist.h.

◆ fPmf

const ROOT::Math::IGenFunction* TUnuranDiscrDist::fPmf
private

pointer to a function calculating the probability

Definition at line 204 of file TUnuranDiscrDist.h.

◆ fPVec

std::vector<double> TUnuranDiscrDist::fPVec
private

Vector of the probabilities.

Definition at line 202 of file TUnuranDiscrDist.h.

◆ fPVecSum

std::vector<double> TUnuranDiscrDist::fPVecSum
mutableprivate

Vector of the sum of the probabilities.

Definition at line 203 of file TUnuranDiscrDist.h.

◆ fSum

double TUnuranDiscrDist::fSum
private

total sum of the probabilities in the given domain

Definition at line 209 of file TUnuranDiscrDist.h.

◆ fXmax

int TUnuranDiscrDist::fXmax
private

upper value of the domain

Definition at line 207 of file TUnuranDiscrDist.h.

◆ fXmin

int TUnuranDiscrDist::fXmin
private

lower value of the domain

Definition at line 206 of file TUnuranDiscrDist.h.

Libraries for TUnuranDiscrDist:
[legend]

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