Logo ROOT  
Reference Guide
TUnuranSampler Class Reference

TUnuranSampler class class implementing the ROOT::Math::DistSampler interface using the UNU.RAN package for sampling distributions.

Definition at line 51 of file TUnuranSampler.h.

Public Member Functions

 TUnuranSampler ()
 default constructor More...
 
 ~TUnuranSampler () override
 virtual destructor More...
 
TRandomGetRandom () override
 Get the random engine used by the sampler. More...
 
bool Init (const char *algo="") override
 initialize the generators with the given algorithm If no algorithm is passed used the default one for the type of distribution More...
 
bool Init (const ROOT::Math::DistSamplerOptions &opt) override
 initialize the generators with the given algorithm If no algorithm is passed used the default one for the type of distribution More...
 
virtual TClassIsA () const
 
bool Sample (double *x) override
 sample one event in multi-dimension by filling the given array return false if sampling failed More...
 
double Sample1D () override
 sample one event in one dimension better implementation could be provided by the derived classes More...
 
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 More...
 
void SetArea (double area) override
 Set the normalization area of distribution. More...
 
void SetCdf (const ROOT::Math::IGenFunction &cdf) override
 set the cumulative distribution function of the PDF used for random sampling (one dim case) More...
 
void SetDPdf (const ROOT::Math::IGenFunction &dpdf) override
 set the Derivative of the PDF used for random sampling (one dim continuous case) More...
 
void SetFunction (const ROOT::Math::IGenFunction &func) override
 Set the parent function distribution to use for random sampling (one dim case). More...
 
void SetFunction (TF1 *pdf)
 Set the Function using a TF1 pointer. More...
 
void SetMode (const std::vector< double > &modes) override
 Set the mode of the distribution (Multi-dim case). More...
 
void SetMode (double mode) override
 Set the mode of the distribution (1D case). More...
 
void SetPrintLevel (int level)
 Set the print level (if level=-1 use default) More...
 
void SetRandom (TRandom *r) override
 Set the random engine to be used Needs to be called before Init to have effect. More...
 
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. More...
 
void SetUseLogPdf (bool on=true) override
 Set using of logarithm of PDF (only for 1D continuous case) More...
 
virtual void Streamer (TBuffer &)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from ROOT::Math::DistSampler
 DistSampler ()
 default constructor More...
 
virtual ~DistSampler ()
 virtual destructor More...
 
virtual bool Generate (unsigned int nevt, const int *nbins, ROOT::Fit::BinData &data, bool extend=true, bool expErr=true)
 Generate a binned data set. More...
 
virtual bool Generate (unsigned int nevt, double *data, bool eventRow=false)
 Generate a vector of events by filling the passed data vector. More...
 
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. More...
 
virtual bool Generate (unsigned int nevt, ROOT::Fit::UnBinData &data)
 Generate a un-binned data set by filling the given data set object. More...
 
virtual TRandomGetRandom ()
 Get the random engine used by the sampler. More...
 
bool HasParentPdf () const
 Check if there is a parent distribution defined. More...
 
virtual bool Init (const char *="")
 Initialize the sampling generator with the given algorithm. More...
 
virtual bool Init (const DistSamplerOptions &opt)
 Initialize the generators with the given DistSamplerOption object. More...
 
unsigned int NDim () const
 return the dimension of the parent distribution (and the data) More...
 
const ROOT::Math::IMultiGenFunctionParentPdf () const
 Get the parent distribution function (must be called after setting the function). More...
 
const doubleSample ()
 Sample one event and return an array x with sample coordinates values. More...
 
virtual bool Sample (double *x)=0
 Sample one event in multi-dimension by filling the given array. More...
 
virtual double Sample1D ()
 Sample one event in one dimension. More...
 
virtual bool SampleBin (double prob, double &value, double *error=nullptr)
 Sample one bin given an estimate of the pdf in the bin. More...
 
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. More...
 
virtual void SetArea (double)
 Set the normalization area of distribution. More...
 
virtual void SetCdf (const ROOT::Math::IGenFunction &)
 Set usage of Cumulative of PDF. More...
 
virtual void SetDPdf (const ROOT::Math::IGenFunction &)
 Set usage of Derivative of PDF. 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...
 
template<class Function >
void SetFunction (Function &func, unsigned int dim)
 set the parent function distribution to use for sampling (generic case) More...
 
virtual void SetMode (const std::vector< double > &)
 Set the mode of the distribution (Multi-dim case). More...
 
virtual void SetMode (double)
 Set the mode of the distribution (1D case). More...
 
virtual void SetRandom (TRandom *)
 Set the random engine to be used. More...
 
void SetRange (const double *xmin, const double *xmax)
 Set the range for all dimensions. More...
 
void SetRange (const ROOT::Fit::DataRange &range)
 Set the range using the ROOT::Fit::DataRange class. More...
 
void SetRange (const std::vector< double > &xmin, const std::vector< double > &xmax)
 Set the range for all dimensions (use std::vector) More...
 
void SetRange (double xmin, double xmax, int icoord=0)
 Set the range in a given dimension. More...
 
virtual void SetSeed (unsigned int)
 Set the random seed for the TRandom instances used by the sampler classes. More...
 
virtual void SetUseLogPdf (bool=true)
 Use the log of the provided pdf. More...
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static Version_t Class_Version ()
 
static const char * DeclFileName ()
 

Protected Member Functions

bool DoInit1D (const char *algo)
 Initialization for 1D distributions. More...
 
bool DoInitDiscrete1D (const char *algo)
 Initialization for 1D discrete distributions. More...
 
bool DoInitND (const char *algo)
 Initialization for multi-dim distributions. More...
 
- Protected Member Functions inherited from ROOT::Math::DistSampler
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 More...
 

Private Attributes

double fArea
 area of dist More...
 
const ROOT::Math::IGenFunctionfCDF = nullptr
 CDF function pointer. More...
 
bool fDiscrete = false
 flag to indicate if the function is discrete More...
 
const ROOT::Math::IGenFunctionfDPDF = nullptr
 1D Derivative function pointer More...
 
const ROOT::Math::IGenFunctionfFunc1D = nullptr
 1D function pointer (pdf) More...
 
bool fHasArea = false
 flag to indicate if a area is set More...
 
bool fHasMode = false
 flag to indicate if a mode is set More...
 
int fLevel
 debug level More...
 
double fMode
 mode of dist (1D) More...
 
std::vector< doublefNDMode
 mode of the multi-dim distribution More...
 
bool fOneDim = false
 flag to indicate if the function is 1 dimension More...
 
TUnuranfUnuran = nullptr
 unuran engine class More...
 
bool fUseLogPdf = false
 flag to indicate if we use the log of the PDF More...
 

#include <TUnuranSampler.h>

Inheritance diagram for TUnuranSampler:
[legend]

Constructor & Destructor Documentation

◆ TUnuranSampler()

TUnuranSampler::TUnuranSampler ( )

default constructor

Definition at line 33 of file TUnuranSampler.cxx.

◆ ~TUnuranSampler()

TUnuranSampler::~TUnuranSampler ( )
override

virtual destructor

Definition at line 43 of file TUnuranSampler.cxx.

Member Function Documentation

◆ Class()

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

◆ Class_Name()

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

◆ Class_Version()

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

Definition at line 198 of file TUnuranSampler.h.

◆ DeclFileName()

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

Definition at line 198 of file TUnuranSampler.h.

◆ DoInit1D()

bool TUnuranSampler::DoInit1D ( const char *  algo)
protected

Initialization for 1D distributions.

Definition at line 143 of file TUnuranSampler.cxx.

◆ DoInitDiscrete1D()

bool TUnuranSampler::DoInitDiscrete1D ( const char *  algo)
protected

Initialization for 1D discrete distributions.

Definition at line 183 of file TUnuranSampler.cxx.

◆ DoInitND()

bool TUnuranSampler::DoInitND ( const char *  algo)
protected

Initialization for multi-dim distributions.

Definition at line 224 of file TUnuranSampler.cxx.

◆ GetRandom()

TRandom * TUnuranSampler::GetRandom ( )
overridevirtual

Get the random engine used by the sampler.

Reimplemented from ROOT::Math::DistSampler.

Definition at line 267 of file TUnuranSampler.cxx.

◆ Init() [1/2]

bool TUnuranSampler::Init ( const char *  algo = "")
overridevirtual

initialize the generators with the given algorithm If no algorithm is passed used the default one for the type of distribution

Reimplemented from ROOT::Math::DistSampler.

Definition at line 48 of file TUnuranSampler.cxx.

◆ Init() [2/2]

bool TUnuranSampler::Init ( const ROOT::Math::DistSamplerOptions opt)
overridevirtual

initialize the generators with the given algorithm If no algorithm is passed used the default one for the type of distribution

Reimplemented from ROOT::Math::DistSampler.

Definition at line 106 of file TUnuranSampler.cxx.

◆ IsA()

virtual TClass * TUnuranSampler::IsA ( ) const
inlinevirtual
Returns
TClass describing current object

Definition at line 198 of file TUnuranSampler.h.

◆ Sample()

bool TUnuranSampler::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 277 of file TUnuranSampler.cxx.

◆ Sample1D()

double TUnuranSampler::Sample1D ( )
overridevirtual

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

Reimplemented from ROOT::Math::DistSampler.

Definition at line 272 of file TUnuranSampler.cxx.

◆ SampleBin()

bool TUnuranSampler::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 285 of file TUnuranSampler.cxx.

◆ SetArea()

void TUnuranSampler::SetArea ( double  )
inlineoverridevirtual

Set the normalization area of distribution.

Implemented by derived classes if needed

Reimplemented from ROOT::Math::DistSampler.

Definition at line 129 of file TUnuranSampler.h.

◆ SetCdf()

void TUnuranSampler::SetCdf ( const ROOT::Math::IGenFunction cdf)
overridevirtual

set the cumulative distribution function of the PDF used for random sampling (one dim case)

Reimplemented from ROOT::Math::DistSampler.

Definition at line 312 of file TUnuranSampler.cxx.

◆ SetDPdf()

void TUnuranSampler::SetDPdf ( const ROOT::Math::IGenFunction dpdf)
overridevirtual

set the Derivative of the PDF used for random sampling (one dim continuous case)

Reimplemented from ROOT::Math::DistSampler.

Definition at line 318 of file TUnuranSampler.cxx.

◆ SetFunction() [1/2]

void TUnuranSampler::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 66 of file TUnuranSampler.h.

◆ SetFunction() [2/2]

void TUnuranSampler::SetFunction ( TF1 pdf)

Set the Function using a TF1 pointer.

Definition at line 252 of file TUnuranSampler.cxx.

◆ SetMode() [1/2]

void TUnuranSampler::SetMode ( const std::vector< double > &  )
overridevirtual

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

Reimplemented from ROOT::Math::DistSampler.

Definition at line 294 of file TUnuranSampler.cxx.

◆ SetMode() [2/2]

void TUnuranSampler::SetMode ( double  )
inlineoverridevirtual

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 from ROOT::Math::DistSampler.

Definition at line 115 of file TUnuranSampler.h.

◆ SetPrintLevel()

void TUnuranSampler::SetPrintLevel ( int  level)
inline

Set the print level (if level=-1 use default)

Definition at line 110 of file TUnuranSampler.h.

◆ SetRandom()

void TUnuranSampler::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 257 of file TUnuranSampler.cxx.

◆ SetSeed()

void TUnuranSampler::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 262 of file TUnuranSampler.cxx.

◆ SetUseLogPdf()

void TUnuranSampler::SetUseLogPdf ( bool  on = true)
inlineoverridevirtual

Set using of logarithm of PDF (only for 1D continuous case)

Reimplemented from ROOT::Math::DistSampler.

Definition at line 135 of file TUnuranSampler.h.

◆ Streamer()

virtual void TUnuranSampler::Streamer ( TBuffer )
virtual

◆ StreamerNVirtual()

void TUnuranSampler::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 198 of file TUnuranSampler.h.

Member Data Documentation

◆ fArea

double TUnuranSampler::fArea
private

area of dist

Definition at line 191 of file TUnuranSampler.h.

◆ fCDF

const ROOT::Math::IGenFunction* TUnuranSampler::fCDF = nullptr
private

CDF function pointer.

Definition at line 194 of file TUnuranSampler.h.

◆ fDiscrete

bool TUnuranSampler::fDiscrete = false
private

flag to indicate if the function is discrete

Definition at line 185 of file TUnuranSampler.h.

◆ fDPDF

const ROOT::Math::IGenFunction* TUnuranSampler::fDPDF = nullptr
private

1D Derivative function pointer

Definition at line 195 of file TUnuranSampler.h.

◆ fFunc1D

const ROOT::Math::IGenFunction* TUnuranSampler::fFunc1D = nullptr
private

1D function pointer (pdf)

Definition at line 193 of file TUnuranSampler.h.

◆ fHasArea

bool TUnuranSampler::fHasArea = false
private

flag to indicate if a area is set

Definition at line 187 of file TUnuranSampler.h.

◆ fHasMode

bool TUnuranSampler::fHasMode = false
private

flag to indicate if a mode is set

Definition at line 186 of file TUnuranSampler.h.

◆ fLevel

int TUnuranSampler::fLevel
private

debug level

Definition at line 189 of file TUnuranSampler.h.

◆ fMode

double TUnuranSampler::fMode
private

mode of dist (1D)

Definition at line 190 of file TUnuranSampler.h.

◆ fNDMode

std::vector<double> TUnuranSampler::fNDMode
private

mode of the multi-dim distribution

Definition at line 192 of file TUnuranSampler.h.

◆ fOneDim

bool TUnuranSampler::fOneDim = false
private

flag to indicate if the function is 1 dimension

Definition at line 184 of file TUnuranSampler.h.

◆ fUnuran

TUnuran* TUnuranSampler::fUnuran = nullptr
private

unuran engine class

Definition at line 196 of file TUnuranSampler.h.

◆ fUseLogPdf

bool TUnuranSampler::fUseLogPdf = false
private

flag to indicate if we use the log of the PDF

Definition at line 188 of file TUnuranSampler.h.

Libraries for TUnuranSampler:
[legend]

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