Logo ROOT   6.10/09
Reference Guide
TFoamSampler.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Fri Sep 22 15:06:47 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 // Header file for class TFoamSampler
11 
12 #ifndef ROOT_TFoamSampler
13 #define ROOT_TFoamSampler
14 
15 
16 #include "Math/DistSampler.h"
17 
18 
19 namespace ROOT {
20 
21  namespace Fit {
22 
23  class DataRange;
24  class BinData;
25  class UnBinData;
26  }
27 
28  namespace Math {
29  }
30 }
31 
32 class TFoamIntegrand;
33 
34 
35 class TRandom;
36 class TF1;
37 class TFoam;
38 
39 
40 //_______________________________________________________________________________
41 /**
42  TFoamSampler class
43  class implementing the ROOT::Math::DistSampler interface using FOAM
44  for sampling arbitrary distributions.
45 
46 
47 */
49 
50 public:
51 
52  /// default constructor
53  TFoamSampler();
54 
55 
56  /// virtual destructor
57  virtual ~TFoamSampler();
58 
59 
60  using DistSampler::SetFunction;
61 
62  /// set the parent function distribution to use for random sampling (one dim case)
64  fFunc1D = &func;
65  SetFunction<const ROOT::Math::IGenFunction>(func, 1);
66  }
67 
68  /// set the Function using a TF1 pointer
69  void SetFunction(TF1 * pdf);
70 
71 
72  /**
73  initialize the generators with the default options
74  */
75  bool Init(const char * = "");
76 
77  /**
78  initialize the generators with the fiven options
79  */
80  bool Init(const ROOT::Math::DistSamplerOptions & opt );
81 
82  /**
83  Set the random engine to be used
84  Needs to be called before Init to have effect
85  */
86  void SetRandom(TRandom * r);
87 
88  /**
89  Set the random seed for the TRandom instances used by the sampler
90  classes
91  Needs to be called before Init to have effect
92  */
93  void SetSeed(unsigned int seed);
94 
95 
96  /**
97  Get the random engine used by the sampler
98  */
99  TRandom * GetRandom();
100 
101 
102  /**
103  sample one event in multi-dimension by filling the given array
104  return false if sampling failed
105  */
106  bool Sample(double * x);
107 
108  /**
109  sample one bin given an estimated of the pdf in the bin
110  (this can be function value at the center or its integral in the bin
111  divided by the bin width)
112  By default do not do random sample, just return the function values
113  */
114  bool SampleBin(double prob, double & value, double *error = 0);
115 
116 
117 
118 protected:
119 
120 
121 private:
122 
123  // private member
124 // bool fOneDim; // flag to indicate if the function is 1 dimension
125 // bool fHasMode; // flag to indicate if a mode is set
126 // bool fHasArea; // flag to indicate if a area is set
127 // double fMode; // mode of dist
128 // double fArea; // area of dist
129  const ROOT::Math::IGenFunction * fFunc1D; // 1D function pointer
130  TFoam * fFoam; // foam engine class
131  TFoamIntegrand * fFoamDist; // foam distribution interface
132 
133  //ClassDef(TFoamSampler,1) //Distribution sampler class based on FOAM
134 
135 };
136 
137 
138 
139 #endif /* ROOT_TFoamSampler */
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:134
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
void SetFunction(const ROOT::Math::IGenFunction &func)
set the parent function distribution to use for random sampling (one dim case)
Definition: TFoamSampler.h:63
TFoamIntegrand * fFoamDist
Definition: TFoamSampler.h:131
Double_t x[n]
Definition: legend1.C:17
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
TFoam * fFoam
Definition: TFoamSampler.h:130
TRandom2 r(17)
DistSampler options class.
Interface class for generic sampling of a distribution, i.e.
Definition: DistSampler.h:57
const ROOT::Math::IGenFunction * fFunc1D
Definition: TFoamSampler.h:129
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
double func(double *x, double *p)
Definition: stressTF1.cxx:213
Namespace for new Math classes and functions.
1-Dim function class
Definition: TF1.h:150
Definition: TFoam.h:27
TFoamSampler class class implementing the ROOT::Math::DistSampler interface using FOAM for sampling a...
Definition: TFoamSampler.h:48