ROOT  6.06/09
Reference Guide
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ROOT::Math::DistSampler Class Referenceabstract

Interface class for generic sampling of a distribution, i.e.

generating random numbers according to arbitrary distributions

Definition at line 61 of file DistSampler.h.

Public Member Functions

 DistSampler ()
 default constructor More...
 
virtual ~DistSampler ()
 virtual destructor More...
 
template<class Function >
void SetFunction (Function &func, unsigned int dim)
 set the parent function distribution to use for sampling (generic case) More...
 
virtual void SetFunction (const ROOT::Math::IGenFunction &func)
 set the parent function distribution to use for random sampling (one dim case) More...
 
virtual void SetFunction (const ROOT::Math::IMultiGenFunction &func)
 set the parent function distribution to use for random sampling (multi-dim case) More...
 
unsigned int NDim () const
 return the dimension of the parent distribution (and the data) More...
 
virtual bool Init (const char *="")
 initialize the generators with the given algorithm Implemented by derived classes who needs it (like UnuranSampler) If nothing is specified use default algorithm from DistSamplerOptions::SetDefaultAlgorithm More...
 
virtual bool Init (const DistSamplerOptions &opt)
 initialize the generators with the given option which my include the algorithm but also more if the method is re-impelmented by derived class The default implementation calls the above method passing just the algorithm name More...
 
virtual void SetRandom (TRandom *)
 Set the random engine to be used To be implemented by the derived classes who provides random sampling. More...
 
virtual void SetSeed (unsigned int)
 Set the random seed for the TRandom instances used by the sampler classes To be implemented by the derived classes who provides random sampling. More...
 
virtual TRandomGetRandom ()
 Get the random engine used by the sampler To be implemented by the derived classes who needs it Returns zero by default. More...
 
void SetRange (double xmin, double xmax, int icoord=0)
 set range in a given dimension More...
 
void SetRange (const double *xmin, const double *xmax)
 set range for all dimensions More...
 
void SetRange (const ROOT::Fit::DataRange &range)
 set range using DataRange class More...
 
virtual void SetMode (double)
 set the mode of the distribution (could be useful to some methods) implemented by derived classes if needed More...
 
virtual void SetArea (double)
 set the normalization area of distribution implemented by derived classes if needed More...
 
const ROOT::Math::IMultiGenFunctionParentPdf () const
 get the parent distribution function (must be called after setting the function) More...
 
virtual double Sample1D ()
 sample one event in one dimension better implementation could be provided by the derived classes More...
 
const doubleSample ()
 sample one event and rerturning array x with coordinates More...
 
virtual bool Sample (double *x)=0
 sample one event in multi-dimension by filling the given array return false if sampling failed More...
 
virtual bool SampleBin (double prob, double &value, double *error=0)
 sample one bin given an estimated of the pdf in the bin (this can be function value at the center or its integral in the bin divided by the bin width) By default do not do random sample, just return the function values Typically Poisson statistics will be used More...
 
virtual bool SampleBins (unsigned int n, const double *prob, double *values, double *errors=0)
 sample a set of bins given a vector of probabilities Typically multinomial statistics will be used and the sum of the probabilities will be equal to the total number of events to be generated For sampling the bins indipendently, SampleBin should be used More...
 
virtual bool Generate (unsigned int nevt, ROOT::Fit::UnBinData &data)
 generate a un-binned data sets (fill the given data set) if dataset has already data append to it More...
 
virtual bool Generate (unsigned int nevt, const int *nbins, ROOT::Fit::BinData &data, bool extend=true)
 generate a bin data set . More...
 
bool Generate (unsigned int nevt, int nbins, double xmin, double xmax, ROOT::Fit::BinData &data, bool extend=true)
 same as before but passing the range in case of 1 dim data More...
 

Protected Member Functions

virtual void DoSetFunction (const ROOT::Math::IMultiGenFunction &func, bool copy)
 
bool IsInitialized ()
 
const ROOT::Fit::DataRangePdfRange () const
 return the data range of the Pdf . Must be called after setting the function More...
 

Private Attributes

bool fOwnFunc
 
std::vector< doublefData
 
ROOT::Fit::DataRangefRange
 
const ROOT::Math::IMultiGenFunctionfFunc
 

#include <Math/DistSampler.h>

+ Inheritance diagram for ROOT::Math::DistSampler:
+ Collaboration diagram for ROOT::Math::DistSampler:

Constructor & Destructor Documentation

ROOT::Math::DistSampler::DistSampler ( )
inline

default constructor

Definition at line 66 of file DistSampler.h.

ROOT::Math::DistSampler::~DistSampler ( )
virtual

virtual destructor

Definition at line 28 of file DistSampler.cxx.

Member Function Documentation

void ROOT::Math::DistSampler::DoSetFunction ( const ROOT::Math::IMultiGenFunction func,
bool  copy 
)
protectedvirtual

Definition at line 62 of file DistSampler.cxx.

Referenced by SetFunction().

bool ROOT::Math::DistSampler::Generate ( unsigned int  nevt,
ROOT::Fit::UnBinData data 
)
virtual

generate a un-binned data sets (fill the given data set) if dataset has already data append to it

Definition at line 94 of file DistSampler.cxx.

Referenced by Generate().

bool ROOT::Math::DistSampler::Generate ( unsigned int  nevt,
const int *  nbins,
ROOT::Fit::BinData data,
bool  extend = true 
)
virtual

generate a bin data set .

A range must have been set before (otherwise inf is returned) and the bins are equidinstant in the previously defined range bin center values must be present in given data set If the sampler is implemented by a random one, the entries will be binned according to the Poisson distribution It is assumed the distribution is normalized, otherwise the nevt must be scaled accordingly. The expected value/bin nexp = f(x_i) * binArea/ nevt Extend control if use a fixed (i.e. multinomial statistics) or floating total number of events

Definition at line 118 of file DistSampler.cxx.

bool ROOT::Math::DistSampler::Generate ( unsigned int  nevt,
int  nbins,
double  xmin,
double  xmax,
ROOT::Fit::BinData data,
bool  extend = true 
)
inline

same as before but passing the range in case of 1 dim data

Definition at line 231 of file DistSampler.h.

virtual TRandom* ROOT::Math::DistSampler::GetRandom ( )
inlinevirtual

Get the random engine used by the sampler To be implemented by the derived classes who needs it Returns zero by default.

Reimplemented in TUnuranSampler, and TFoamSampler.

Definition at line 136 of file DistSampler.h.

virtual bool ROOT::Math::DistSampler::Init ( const char *  = "")
inlinevirtual

initialize the generators with the given algorithm Implemented by derived classes who needs it (like UnuranSampler) If nothing is specified use default algorithm from DistSamplerOptions::SetDefaultAlgorithm

Reimplemented in TUnuranSampler, and TFoamSampler.

Definition at line 105 of file DistSampler.h.

Referenced by Init(), testCont1D(), and testDisc1D().

bool ROOT::Math::DistSampler::Init ( const DistSamplerOptions opt)
virtual

initialize the generators with the given option which my include the algorithm but also more if the method is re-impelmented by derived class The default implementation calls the above method passing just the algorithm name

Reimplemented in TUnuranSampler, and TFoamSampler.

Definition at line 34 of file DistSampler.cxx.

bool ROOT::Math::DistSampler::IsInitialized ( )
protected

Definition at line 83 of file DistSampler.cxx.

Referenced by Generate().

unsigned int ROOT::Math::DistSampler::NDim ( ) const
inline

return the dimension of the parent distribution (and the data)

Definition at line 95 of file DistSampler.h.

Referenced by Generate(), TUnuranSampler::Init(), TFoamSampler::Init(), IsInitialized(), TFoamSampler::Sample(), and SetRange().

const ROOT::Math::IMultiGenFunction& ROOT::Math::DistSampler::ParentPdf ( ) const
inline

get the parent distribution function (must be called after setting the function)

Definition at line 156 of file DistSampler.h.

Referenced by TUnuranSampler::DoInit1D(), TUnuranSampler::DoInitDiscrete1D(), TUnuranSampler::DoInitND(), Generate(), and TFoamSampler::Init().

const ROOT::Fit::DataRange& ROOT::Math::DistSampler::PdfRange ( ) const
inlineprotected

return the data range of the Pdf . Must be called after setting the function

Definition at line 245 of file DistSampler.h.

Referenced by TUnuranSampler::DoInit1D(), TUnuranSampler::DoInitDiscrete1D(), TUnuranSampler::DoInitND(), and TFoamSampler::Init().

const double* ROOT::Math::DistSampler::Sample ( )
inline

sample one event and rerturning array x with coordinates

Definition at line 173 of file DistSampler.h.

Referenced by Generate(), IsInitialized(), and Sample1D().

virtual bool ROOT::Math::DistSampler::Sample ( double x)
pure virtual

sample one event in multi-dimension by filling the given array return false if sampling failed

Implemented in TUnuranSampler, and TFoamSampler.

virtual double ROOT::Math::DistSampler::Sample1D ( )
inlinevirtual

sample one event in one dimension better implementation could be provided by the derived classes

Reimplemented in TUnuranSampler.

Definition at line 165 of file DistSampler.h.

Referenced by testCont1D(), and testDisc1D().

virtual bool ROOT::Math::DistSampler::SampleBin ( double  prob,
double value,
double error = 0 
)
inlinevirtual

sample one bin given an estimated of the pdf in the bin (this can be function value at the center or its integral in the bin divided by the bin width) By default do not do random sample, just return the function values Typically Poisson statistics will be used

Reimplemented in TUnuranSampler, and TFoamSampler.

Definition at line 191 of file DistSampler.h.

Referenced by Generate().

virtual bool ROOT::Math::DistSampler::SampleBins ( unsigned int  n,
const double prob,
double values,
double errors = 0 
)
inlinevirtual

sample a set of bins given a vector of probabilities Typically multinomial statistics will be used and the sum of the probabilities will be equal to the total number of events to be generated For sampling the bins indipendently, SampleBin should be used

Definition at line 202 of file DistSampler.h.

virtual void ROOT::Math::DistSampler::SetArea ( double  )
inlinevirtual

set the normalization area of distribution implemented by derived classes if needed

Reimplemented in TUnuranSampler.

Definition at line 153 of file DistSampler.h.

Referenced by testDisc1D().

template<class Function >
void ROOT::Math::DistSampler::SetFunction ( Function func,
unsigned int  dim 
)
inline

set the parent function distribution to use for sampling (generic case)

Definition at line 76 of file DistSampler.h.

Referenced by testCont1D(), and testDisc1D().

virtual void ROOT::Math::DistSampler::SetFunction ( const ROOT::Math::IGenFunction func)
inlinevirtual

set the parent function distribution to use for random sampling (one dim case)

Reimplemented in TUnuranSampler, and TFoamSampler.

Definition at line 84 of file DistSampler.h.

virtual void ROOT::Math::DistSampler::SetFunction ( const ROOT::Math::IMultiGenFunction func)
inlinevirtual

set the parent function distribution to use for random sampling (multi-dim case)

Definition at line 90 of file DistSampler.h.

virtual void ROOT::Math::DistSampler::SetMode ( double  )
inlinevirtual

set the mode of the distribution (could be useful to some methods) implemented by derived classes if needed

Reimplemented in TUnuranSampler.

Definition at line 149 of file DistSampler.h.

Referenced by testDisc1D().

virtual void ROOT::Math::DistSampler::SetRandom ( TRandom )
inlinevirtual

Set the random engine to be used To be implemented by the derived classes who provides random sampling.

Reimplemented in TUnuranSampler, and TFoamSampler.

Definition at line 122 of file DistSampler.h.

void ROOT::Math::DistSampler::SetRange ( double  xmin,
double  xmax,
int  icoord = 0 
)

set range in a given dimension

Definition at line 39 of file DistSampler.cxx.

Referenced by Generate().

void ROOT::Math::DistSampler::SetRange ( const double xmin,
const double xmax 
)

set range for all dimensions

Definition at line 47 of file DistSampler.cxx.

void ROOT::Math::DistSampler::SetRange ( const ROOT::Fit::DataRange range)

set range using DataRange class

Definition at line 57 of file DistSampler.cxx.

virtual void ROOT::Math::DistSampler::SetSeed ( unsigned int  )
inlinevirtual

Set the random seed for the TRandom instances used by the sampler classes To be implemented by the derived classes who provides random sampling.

Reimplemented in TUnuranSampler, and TFoamSampler.

Definition at line 129 of file DistSampler.h.

Member Data Documentation

std::vector<double> ROOT::Math::DistSampler::fData
mutableprivate

Definition at line 258 of file DistSampler.h.

Referenced by DoSetFunction(), IsInitialized(), NDim(), Sample(), Sample1D(), and SetFunction().

const ROOT::Math::IMultiGenFunction* ROOT::Math::DistSampler::fFunc
private

Definition at line 260 of file DistSampler.h.

Referenced by DoSetFunction(), Generate(), IsInitialized(), ParentPdf(), and ~DistSampler().

bool ROOT::Math::DistSampler::fOwnFunc
private

Definition at line 257 of file DistSampler.h.

Referenced by DoSetFunction(), and ~DistSampler().

ROOT::Fit::DataRange* ROOT::Math::DistSampler::fRange
private

Definition at line 259 of file DistSampler.h.

Referenced by DoSetFunction(), Generate(), PdfRange(), SetRange(), and ~DistSampler().


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