Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TFoamSampler Class Reference

class implementing the ROOT::Math::DistSampler interface using FOAM for sampling arbitrary distributions.

Definition at line 39 of file TFoamSampler.h.

Public Member Functions

 TFoamSampler ()
 default constructor
 ~TFoamSampler () override
 virtual destructor
virtual bool Generate (unsigned int nevt, const int *nbins, ROOT::Fit::BinData &data, bool extend=true, bool expErr=true)
 Generate a binned data set.
virtual bool Generate (unsigned int nevt, double *data, bool eventRow=false)
 Generate a vector of events by filling the passed data vector.
bool Generate (unsigned int nevt, int nbins, double xmin, double xmax, ROOT::Fit::BinData &data, bool extend=true, bool expErr=true)
 Same as before but passing the range in case of 1 dim data.
virtual bool Generate (unsigned int nevt, ROOT::Fit::UnBinData &data)
 Generate a un-binned data set by filling the given data set object.
TRandomGetRandom () override
 Get the random engine used by the sampler.
bool HasParentPdf () const
 Check if there is a parent distribution defined.
bool Init (const char *="") override
 initialize the generators with the default options
bool Init (const ROOT::Math::DistSamplerOptions &opt) override
 initialize the generators with the given options
unsigned int NDim () const
 return the dimension of the parent distribution (and the data)
const ROOT::Math::IMultiGenFunctionParentPdf () const
 Get the parent distribution function (must be called after setting the function).
const doubleSample ()
 Sample one event and return an array x with sample coordinates values.
bool Sample (double *x) override
 sample one event in multi-dimension by filling the given array return false if sampling failed
virtual double Sample1D ()
 Sample one event in one dimension.
bool SampleBin (double prob, double &value, double *error=nullptr) override
 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
virtual bool SampleBins (unsigned int n, const double *prob, double *values, double *errors=nullptr)
 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 independently, SampleBin should be used.
virtual void SetArea (double)
 Set the normalization area of distribution.
virtual void SetCdf (const ROOT::Math::IGenFunction &)
 Set usage of Cumulative of PDF.
virtual void SetDPdf (const ROOT::Math::IGenFunction &)
 Set usage of Derivative of PDF.
virtual void SetFunction (const ROOT::Math::IMultiGenFunction &func)
 set the parent function distribution to use for random sampling (multi-dim case)
template<class Function>
void SetFunction (Function &func, unsigned int dim)
 set the parent function distribution to use for sampling (generic case)
void SetFunction (const ROOT::Math::IGenFunction &func) override
 set the parent function distribution to use for random sampling (one dim case)
void SetFunction (TF1 *pdf)
 set the Function using a TF1 pointer
virtual void SetMode (const std::vector< double > &)
 Set the mode of the distribution (Multi-dim case).
virtual void SetMode (double)
 Set the mode of the distribution (1D case).
void SetRandom (TRandom *r) override
 Set the random engine to be used Needs to be called before Init to have effect.
void SetRange (const double *xmin, const double *xmax)
 Set the range for all dimensions.
void SetRange (const ROOT::Fit::DataRange &range)
 Set the range using the ROOT::Fit::DataRange class.
void SetRange (const std::vector< double > &xmin, const std::vector< double > &xmax)
 Set the range for all dimensions (use std::vector).
void SetRange (double xmin, double xmax, int icoord=0)
 Set the range in a given dimension.
void SetSeed (unsigned int seed) override
 Set the random seed for the TRandom instances used by the sampler classes Needs to be called before Init to have effect.
virtual void SetUseLogPdf (bool=true)
 Use the log of the provided pdf.

Protected Member Functions

virtual void DoSetDimension (unsigned int ndim)
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

Private Attributes

std::vector< doublefData
 ! internal array used to cached the sample data
TFoamfFoam
TFoamIntegrandfFoamDist
const ROOT::Math::IMultiGenFunctionfFunc
 internal function (ND)
const ROOT::Math::IGenFunctionfFunc1D
bool fOwnFunc
 flag to indicate if the function is owned
ROOT::Fit::DataRangefRange
 data range

#include <TFoamSampler.h>

Inheritance diagram for TFoamSampler:
ROOT::Math::DistSampler

Constructor & Destructor Documentation

◆ TFoamSampler()

TFoamSampler::TFoamSampler ( )

default constructor

Definition at line 81 of file TFoamSampler.cxx.

◆ ~TFoamSampler()

TFoamSampler::~TFoamSampler ( )
override

virtual destructor

Definition at line 91 of file TFoamSampler.cxx.

Member Function Documentation

◆ DoSetDimension()

void ROOT::Math::DistSampler::DoSetDimension ( unsigned int ndim)
protectedvirtualinherited

Definition at line 78 of file DistSampler.cxx.

◆ DoSetFunction()

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

Definition at line 63 of file DistSampler.cxx.

◆ Generate() [1/4]

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

Generate a binned data set.

A range must have been set before (otherwise inf is returned) and the bins are equidistant 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 135 of file DistSampler.cxx.

◆ Generate() [2/4]

bool ROOT::Math::DistSampler::Generate ( unsigned int nevt,
double * data,
bool eventRow = false )
virtualinherited

Generate a vector of events by filling the passed data vector.

The flag eventRow indicates how the events are arranged in the multi-dim case. The can be arranged in rows or in columns. With eventRow=false events are the columns in data: {x1,x2,.....,xn},{y1,....yn} With eventRow=true events are rows in data: {x1,y1},{x2,y2},.....{xn,yn}

Definition at line 115 of file DistSampler.cxx.

◆ Generate() [3/4]

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

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

Definition at line 261 of file DistSampler.h.

◆ Generate() [4/4]

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

Generate a un-binned data set by filling the given data set object.

If the data set object is not empty, the new generated data will be appended to the existing one.

Definition at line 99 of file DistSampler.cxx.

◆ GetRandom()

TRandom * TFoamSampler::GetRandom ( )
overridevirtual

Get the random engine used by the sampler.

Reimplemented from ROOT::Math::DistSampler.

Definition at line 171 of file TFoamSampler.cxx.

◆ HasParentPdf()

bool ROOT::Math::DistSampler::HasParentPdf ( ) const
inlineinherited

Check if there is a parent distribution defined.

Definition at line 179 of file DistSampler.h.

◆ Init() [1/2]

bool TFoamSampler::Init ( const char * = "")
overridevirtual

initialize the generators with the default options

Reimplemented from ROOT::Math::DistSampler.

Definition at line 97 of file TFoamSampler.cxx.

◆ Init() [2/2]

bool TFoamSampler::Init ( const ROOT::Math::DistSamplerOptions & opt)
overridevirtual

initialize the generators with the given options

Reimplemented from ROOT::Math::DistSampler.

Definition at line 106 of file TFoamSampler.cxx.

◆ IsInitialized()

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

Definition at line 89 of file DistSampler.cxx.

◆ NDim()

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

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

Definition at line 92 of file DistSampler.h.

◆ ParentPdf()

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

Get the parent distribution function (must be called after setting the function).

Definition at line 174 of file DistSampler.h.

◆ PdfRange()

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

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

Definition at line 277 of file DistSampler.h.

◆ Sample() [1/2]

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

Sample one event and return an array x with sample coordinates values.

Definition at line 194 of file DistSampler.h.

◆ Sample() [2/2]

bool TFoamSampler::Sample ( double * x)
overridevirtual

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

Implements ROOT::Math::DistSampler.

Definition at line 181 of file TFoamSampler.cxx.

◆ Sample1D()

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

Sample one event in one dimension.

Specialized implementation could be provided by the derived classes

Reimplemented in TUnuranSampler.

Definition at line 185 of file DistSampler.h.

◆ SampleBin()

bool TFoamSampler::SampleBin ( double prob,
double & value,
double * error = nullptr )
overridevirtual

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

Reimplemented from ROOT::Math::DistSampler.

Definition at line 194 of file TFoamSampler.cxx.

◆ SampleBins()

virtual bool ROOT::Math::DistSampler::SampleBins ( unsigned int n,
const double * prob,
double * values,
double * errors = nullptr )
inlinevirtualinherited

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 independently, SampleBin should be used.

Definition at line 224 of file DistSampler.h.

◆ SetArea()

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

Set the normalization area of distribution.

Implemented by derived classes if needed

Reimplemented in TUnuranSampler.

Definition at line 159 of file DistSampler.h.

◆ SetCdf()

virtual void ROOT::Math::DistSampler::SetCdf ( const ROOT::Math::IGenFunction & )
inlinevirtualinherited

Set usage of Cumulative of PDF.

Can be implemented by derived class

Reimplemented in TUnuranSampler.

Definition at line 171 of file DistSampler.h.

◆ SetDPdf()

virtual void ROOT::Math::DistSampler::SetDPdf ( const ROOT::Math::IGenFunction & )
inlinevirtualinherited

Set usage of Derivative of PDF.

Can be implemented by derived class

Reimplemented in TUnuranSampler.

Definition at line 167 of file DistSampler.h.

◆ SetFunction() [1/4]

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

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

Definition at line 87 of file DistSampler.h.

◆ SetFunction() [2/4]

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

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

Definition at line 73 of file DistSampler.h.

◆ SetFunction() [3/4]

void TFoamSampler::SetFunction ( const ROOT::Math::IGenFunction & func)
inlineoverridevirtual

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

Reimplemented from ROOT::Math::DistSampler.

Definition at line 54 of file TFoamSampler.h.

◆ SetFunction() [4/4]

void TFoamSampler::SetFunction ( TF1 * pdf)

set the Function using a TF1 pointer

Definition at line 155 of file TFoamSampler.cxx.

◆ SetMode() [1/2]

virtual void ROOT::Math::DistSampler::SetMode ( const std::vector< double > & )
inlinevirtualinherited

Set the mode of the distribution (Multi-dim case).

Reimplemented in TUnuranSampler.

Definition at line 155 of file DistSampler.h.

◆ SetMode() [2/2]

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

Set the mode of the distribution (1D case).

It could be useful or needed by some sampling methods. It is implemented by derived classes if needed (e.g. TUnuranSampler)

Reimplemented in TUnuranSampler.

Definition at line 152 of file DistSampler.h.

◆ SetRandom()

void TFoamSampler::SetRandom ( TRandom * r)
overridevirtual

Set the random engine to be used Needs to be called before Init to have effect.

Reimplemented from ROOT::Math::DistSampler.

Definition at line 160 of file TFoamSampler.cxx.

◆ SetRange() [1/4]

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

Set the range for all dimensions.

Definition at line 48 of file DistSampler.cxx.

◆ SetRange() [2/4]

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

Set the range using the ROOT::Fit::DataRange class.

Definition at line 58 of file DistSampler.cxx.

◆ SetRange() [3/4]

void ROOT::Math::DistSampler::SetRange ( const std::vector< double > & xmin,
const std::vector< double > & xmax )
inlineinherited

Set the range for all dimensions (use std::vector).

Definition at line 141 of file DistSampler.h.

◆ SetRange() [4/4]

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

Set the range in a given dimension.

Definition at line 40 of file DistSampler.cxx.

◆ SetSeed()

void TFoamSampler::SetSeed ( unsigned int seed)
overridevirtual

Set the random seed for the TRandom instances used by the sampler classes Needs to be called before Init to have effect.

Reimplemented from ROOT::Math::DistSampler.

Definition at line 165 of file TFoamSampler.cxx.

◆ SetUseLogPdf()

virtual void ROOT::Math::DistSampler::SetUseLogPdf ( bool = true)
inlinevirtualinherited

Use the log of the provided pdf.

Implemented by the derived classes

Reimplemented in TUnuranSampler.

Definition at line 163 of file DistSampler.h.

Member Data Documentation

◆ fData

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

! internal array used to cached the sample data

Definition at line 287 of file DistSampler.h.

◆ fFoam

TFoam* TFoamSampler::fFoam
private

Definition at line 120 of file TFoamSampler.h.

◆ fFoamDist

TFoamIntegrand* TFoamSampler::fFoamDist
private

Definition at line 121 of file TFoamSampler.h.

◆ fFunc

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

internal function (ND)

Definition at line 289 of file DistSampler.h.

◆ fFunc1D

const ROOT::Math::IGenFunction* TFoamSampler::fFunc1D
private

Definition at line 119 of file TFoamSampler.h.

◆ fOwnFunc

bool ROOT::Math::DistSampler::fOwnFunc
privateinherited

flag to indicate if the function is owned

Definition at line 286 of file DistSampler.h.

◆ fRange

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

data range

Definition at line 288 of file DistSampler.h.


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