13 #ifndef ROOT_Math_DistSampler
14 #define ROOT_Math_DistSampler
36 class DistSamplerOptions;
62 DistSampler() : fOwnFunc(false), fRange(0), fFunc(0) {}
66 virtual ~DistSampler();
71 template<
class Function>
72 void SetFunction(Function & func,
unsigned int dim) {
73 WrappedMultiFunction<Function &> wf(func, dim);
76 DoSetFunction(wf,
true);
80 virtual void SetFunction(
const ROOT::Math::IGenFunction & func) {
81 SetFunction<const ROOT::Math::IGenFunction>(func, 1);
86 virtual void SetFunction(
const ROOT::Math::IMultiGenFunction & func) {
87 DoSetFunction(func,
false);
91 unsigned int NDim()
const {
return fData.size(); }
101 virtual bool Init(
const char * =
"") {
return true;}
110 virtual bool Init(
const DistSamplerOptions & opt );
118 virtual void SetRandom(TRandom * ) {}
125 virtual void SetSeed(
unsigned int ) {}
132 virtual TRandom * GetRandom() {
return 0; }
135 void SetRange(
double xmin,
double xmax,
int icoord = 0);
138 void SetRange(
const double * xmin,
const double * xmax);
141 void SetRange(
const ROOT::Fit::DataRange & range);
145 virtual void SetMode(
double ) {}
149 virtual void SetArea(
double) {}
152 const ROOT::Math::IMultiGenFunction & ParentPdf()
const {
161 virtual double Sample1D() {
169 const double * Sample() {
171 return &fData.front();
178 virtual bool Sample(
double * x) = 0;
187 virtual bool SampleBin(
double prob,
double & value,
double * error = 0) {
189 if (error) *error = 0;
198 virtual bool SampleBins(
unsigned int n,
const double * prob,
double * values,
double * errors = 0) {
199 std::copy(prob,prob+n, values);
200 if (errors) std::fill(errors,errors+n,0);
209 virtual bool Generate(
unsigned int nevt, ROOT::Fit::UnBinData & data);
223 virtual bool Generate(
unsigned int nevt,
const int * nbins, ROOT::Fit::BinData & data,
bool extend =
true);
227 bool Generate(
unsigned int nevt,
int nbins,
double xmin,
double xmax, ROOT::Fit::BinData & data,
bool extend =
true) {
229 int nbs[1]; nbs[0] = nbins;
230 return Generate(nevt, nbs, data, extend);
237 virtual void DoSetFunction(
const ROOT::Math::IMultiGenFunction & func,
bool copy);
239 bool IsInitialized() ;
241 const ROOT::Fit::DataRange & PdfRange()
const {
254 mutable std::vector<double> fData;
255 ROOT::Fit::DataRange * fRange;
256 const ROOT::Math::IMultiGenFunction * fFunc;