35 fX(
std::vector<double>(f.NDim() ) ),
36 fMinX(
std::vector<double>(f.NDim() ) ),
37 fDeltaX(
std::vector<double>(f.NDim() ) )
41 for (
unsigned int i = 0; i < range.
NDim(); ++i) {
42 if (range.
Size(i) == 0)
43 Error(
"FoamDistribution",
"Range is not set for coordinate dim %d",i);
44 else if (range.
Size(i)>1)
45 Warning(
"FoamDistribution",
"Using only first range in coordinate dim %d",i);
47 std::pair<double,double>
r = range(i);
49 fDeltaX[i] = r.second - r.first;
54 virtual double Density(
int ndim,
double *
x) {
55 assert(ndim == (
int) fFunc.NDim() );
56 for (
int i = 0; i < ndim; ++i)
57 fX[i] = fMinX[i] + x[i] * fDeltaX[i];
59 return (fFunc)(&fX[0]);
62 double MinX(
unsigned int i) {
return fMinX[i]; }
63 double DeltaX(
unsigned int i) {
return fDeltaX[i]; }
68 std::vector<double> fX;
69 std::vector<double> fMinX;
70 std::vector<double> fDeltaX;
94 fFoam(new
TFoam("FOAM") ),
101 if (fFoamDist)
delete fFoamDist;
115 assert (fFoam != 0 );
117 Error(
"TFoamSampler::Init",
"Distribution function has not been set ! Need to call SetFunction first.");
122 fFoam->SetkDim(NDim() );
125 if (!GetRandom()) SetRandom(
gRandom);
128 if (fFoamDist)
delete fFoamDist;
129 fFoamDist =
new FoamDistribution(ParentPdf(),PdfRange());
131 fFoam->SetRho(fFoamDist);
140 if (fopt->
GetIntValue(
"nCells", nval) ) fFoam->SetnCells(nval);
141 if (fopt->
GetIntValue(
"nCell1D", nval) && NDim() ==1) fFoam->SetnCells(nval);
142 if (fopt->
GetIntValue(
"nCellND", nval) && NDim() >1) fFoam->SetnCells(nval);
143 if (fopt->
GetIntValue(
"nCell2D", nval) && NDim() ==2) fFoam->SetnCells(nval);
144 if (fopt->
GetIntValue(
"nCell3D", nval) && NDim() ==3) fFoam->SetnCells(nval);
146 if (fopt->
GetIntValue(
"nSample", nval) ) fFoam->SetnSampl(nval);
147 if (fopt->
GetIntValue(
"nBin", nval) ) fFoam->SetnBin(nval);
148 if (fopt->
GetIntValue(
"OptDrive",nval) ) fFoam->SetOptDrive(nval);
149 if (fopt->
GetIntValue(
"OptRej",nval) ) fFoam->SetOptRej(nval);
150 if (fopt->
GetRealValue(
"MaxWtRej",fval) ) fFoam->SetMaxWtRej(fval);
153 if (fopt->
GetIntValue(
"chatLevel", nval) ) fFoam->SetChat(nval);
164 SetFunction<TF1>(*pdf, pdf->
GetNdim());
180 return fFoam->GetPseRan();
194 for (
unsigned int i = 0; i < NDim(); ++i)
195 x[i] = ( (FoamDistribution*)fFoamDist)->MinX(i) + ( ( (FoamDistribution*) fFoamDist)->DeltaX(i))*x[i];
205 if (!r)
return false;
static ROOT::Math::IOptions * FindDefault(const char *name)
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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 ...
const double * Sample()
sample one event and rerturning array x with coordinates
void SetFunction(const ROOT::Math::IGenFunction &func)
set the parent function distribution to use for random sampling (one dim case)
virtual ~TFoamSampler()
virtual destructor
virtual bool GetRealValue(const char *, double &) const
TRandom * GetRandom()
Get the random engine used by the sampler.
This is the base class for the ROOT Random number generators.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
void Init(TClassEdit::TInterpreterLookupHelper *helper)
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
virtual Int_t GetNdim() const
int PrintLevel() const
non-static methods for retrivieng options
virtual Double_t Density(Int_t ndim, Double_t *)=0
DistSampler options class.
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
unsigned int Size(unsigned int icoord=0) const
return range size for coordinate icoord (starts from zero) Size == 0 indicates no range is present [-...
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
bool Init(const char *="")
initialize the generators with the default options
virtual bool GetIntValue(const char *, int &) const
R__EXTERN TRandom * gRandom
class describing the range in the coordinates it supports multiple range in a coordinate.
Namespace for new Math classes and functions.
Generic interface for defining configuration options of a numerical algorithm.
unsigned int NDim() const
get range dimension
IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
virtual Int_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
void SetRandom(TRandom *r)
Set the random engine to be used Needs to be called before Init to have effect.
Documentation for the abstract class IBaseFunctionMultiDim.
void SetSeed(unsigned int seed)
Set the random seed for the TRandom instances used by the sampler classes Needs to be called before I...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
TFoamSampler class class implementing the ROOT::Math::DistSampler interface using FOAM for sampling a...