Interface class for generic sampling of a distribution, i.e.
generating random numbers according to arbitrary distributions
Definition at line 57 of file DistSampler.h.
Public Member Functions | |
DistSampler () | |
default constructor | |
virtual | ~DistSampler () |
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 fillling 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. | |
virtual TRandom * | GetRandom () |
Get the random engine used by the sampler. | |
bool | HasParentPdf () const |
Check if there is a parent distribution defined. | |
virtual bool | Init (const char *="") |
Initialize the sampling generator with the given algorithm. | |
virtual bool | Init (const DistSamplerOptions &opt) |
Initialize the generators with the given DistSamplerOption object. | |
unsigned int | NDim () const |
return the dimension of the parent distribution (and the data) | |
const ROOT::Math::IMultiGenFunction & | ParentPdf () const |
Get the parent distribution function (must be called after setting the function). | |
const double * | Sample () |
Sample one event and return an array x with sample coordinates values. | |
virtual bool | Sample (double *x)=0 |
Sample one event in multi-dimension by filling the given array. | |
virtual double | Sample1D () |
Sample one event in one dimension. | |
virtual bool | SampleBin (double prob, double &value, double *error=0) |
Sample one bin given an estimate of the pdf in the bin. | |
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. | |
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::IGenFunction &func) |
set the parent function distribution to use for random sampling (one dim case) | |
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) | |
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). | |
virtual void | SetRandom (TRandom *) |
Set the random engine to be used. | |
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. | |
virtual void | SetSeed (unsigned int) |
Set the random seed for the TRandom instances used by the sampler classes. | |
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::DataRange & | PdfRange () const |
return the data range of the Pdf . Must be called after setting the function | |
Private Attributes | |
std::vector< double > | fData |
flag to indicate if the function is owned | |
const ROOT::Math::IMultiGenFunction * | fFunc |
data range | |
bool | fOwnFunc |
ROOT::Fit::DataRange * | fRange |
! internal array used to cached the sample data | |
#include <Math/DistSampler.h>
|
inline |
default constructor
Definition at line 62 of file DistSampler.h.
|
virtual |
virtual destructor
Definition at line 29 of file DistSampler.cxx.
Definition at line 78 of file DistSampler.cxx.
|
protectedvirtual |
Definition at line 63 of file DistSampler.cxx.
|
virtual |
Generate a binned 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 135 of file DistSampler.cxx.
|
virtual |
Generate a vector of events by fillling the passed data vector.
The flag eventRow indicates how the events are arrenged 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.
|
inline |
Same as before but passing the range in case of 1 dim data.
Definition at line 260 of file DistSampler.h.
|
virtual |
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.
|
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 TFoamSampler, and TUnuranSampler.
Definition at line 132 of file DistSampler.h.
|
inline |
Check if there is a parent distribution defined.
Definition at line 178 of file DistSampler.h.
|
inlinevirtual |
Initialize the sampling generator with the given algorithm.
Implemented by the derived classes who needs it (like UnuranSampler). If nothing is specified use default algorithm from DistSamplerOptions::SetDefaultAlgorithm
Reimplemented in TFoamSampler, and TUnuranSampler.
Definition at line 101 of file DistSampler.h.
|
virtual |
Initialize the generators with the given DistSamplerOption object.
The string will include the algorithm and in case additional options which can be interpreted by a re-implemented method in the derived class. The default implementation just calls the above method passing just the algorithm name
Reimplemented in TFoamSampler, and TUnuranSampler.
Definition at line 35 of file DistSampler.cxx.
|
protected |
Definition at line 89 of file DistSampler.cxx.
|
inline |
return the dimension of the parent distribution (and the data)
Definition at line 91 of file DistSampler.h.
|
inline |
Get the parent distribution function (must be called after setting the function).
Definition at line 173 of file DistSampler.h.
|
inlineprotected |
return the data range of the Pdf . Must be called after setting the function
Definition at line 276 of file DistSampler.h.
|
inline |
Sample one event and return an array x with sample coordinates values.
Definition at line 193 of file DistSampler.h.
Sample one event in multi-dimension by filling the given array.
Return false if the sampling failed. Abstract method to be re-implmented by the derived classes
Implemented in TFoamSampler, and TUnuranSampler.
|
inlinevirtual |
Sample one event in one dimension.
Specialized implementation could be provided by the derived classes
Reimplemented in TUnuranSampler.
Definition at line 184 of file DistSampler.h.
|
inlinevirtual |
Sample one bin given an estimate 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 TFoamSampler, and TUnuranSampler.
Definition at line 212 of file DistSampler.h.
|
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 223 of file DistSampler.h.
Set the normalization area of distribution.
Implemented by derived classes if needed
Reimplemented in TUnuranSampler.
Definition at line 158 of file DistSampler.h.
|
inlinevirtual |
Set usage of Cumulative of PDF.
Can be implemented by derived class
Reimplemented in TUnuranSampler.
Definition at line 170 of file DistSampler.h.
|
inlinevirtual |
Set usage of Derivative of PDF.
Can be implemented by derived class
Reimplemented in TUnuranSampler.
Definition at line 166 of file DistSampler.h.
|
inlinevirtual |
set the parent function distribution to use for random sampling (one dim case)
Reimplemented in TFoamSampler, and TUnuranSampler.
Definition at line 80 of file DistSampler.h.
|
inlinevirtual |
set the parent function distribution to use for random sampling (multi-dim case)
Definition at line 86 of file DistSampler.h.
|
inline |
set the parent function distribution to use for sampling (generic case)
Definition at line 72 of file DistSampler.h.
Set the mode of the distribution (Multi-dim case).
Reimplemented in TUnuranSampler.
Definition at line 154 of file DistSampler.h.
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 151 of file DistSampler.h.
Set the random engine to be used.
To be implemented by the derived classes who provides random sampling
Reimplemented in TFoamSampler, and TUnuranSampler.
Definition at line 118 of file DistSampler.h.
Set the range for all dimensions.
Definition at line 48 of file DistSampler.cxx.
void ROOT::Math::DistSampler::SetRange | ( | const ROOT::Fit::DataRange & | range | ) |
Set the range using the ROOT::Fit::DataRange class.
Definition at line 58 of file DistSampler.cxx.
|
inline |
Set the range for all dimensions (use std::vector)
Definition at line 140 of file DistSampler.h.
Set the range in a given dimension.
Definition at line 40 of file DistSampler.cxx.
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 TFoamSampler, and TUnuranSampler.
Definition at line 125 of file DistSampler.h.
Use the log of the provided pdf.
Implemented by the derived classes
Reimplemented in TUnuranSampler.
Definition at line 162 of file DistSampler.h.
|
mutableprivate |
flag to indicate if the function is owned
Definition at line 286 of file DistSampler.h.
|
private |
data range
Definition at line 288 of file DistSampler.h.
|
private |
Definition at line 285 of file DistSampler.h.
|
private |
! internal array used to cached the sample data
Definition at line 287 of file DistSampler.h.