Logo ROOT   6.12/07
Reference Guide
TUnuranSampler.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 TUnuranSampler
11 
12 #ifndef ROOT_TUnuranSampler
13 #define ROOT_TUnuranSampler
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 
33 
34 //_______________________________________________________________________________
35 /**
36  \class TUnuranSampler
37  \ingroup Unuran
38 
39  TUnuranSampler class
40  class implementing the ROOT::Math::DistSampler interface using the UNU.RAN
41  package for sampling distributions.
42 
43 */
44 
45 class TRandom;
46 class TF1;
47 class TUnuran;
48 
50 
51 public:
52 
53  /// default constructor
55 
56 
57  /// virtual destructor
58  virtual ~TUnuranSampler();
59 
60 
61  using DistSampler::SetFunction;
62 
63  /// set the parent function distribution to use for random sampling (one dim case)
65  fFunc1D = &func;
66  SetFunction<const ROOT::Math::IGenFunction>(func, 1);
67  }
68 
69  /// set the Function using a TF1 pointer
70  void SetFunction(TF1 * pdf);
71 
72 
73  /**
74  initialize the generators with the given algorithm
75  If no algorithm is passed used the default one for the type of distribution
76  */
77  bool Init(const char * algo ="");
78 
79 
80  /**
81  initialize the generators with the given algorithm
82  If no algorithm is passed used the default one for the type of distribution
83  */
84  bool Init(const ROOT::Math::DistSamplerOptions & opt );
85 
86  /**
87  Set the random engine to be used
88  Needs to be called before Init to have effect
89  */
90  void SetRandom(TRandom * r);
91 
92  /**
93  Set the random seed for the TRandom instances used by the sampler
94  classes
95  Needs to be called before Init to have effect
96  */
97  void SetSeed(unsigned int seed);
98 
99  /**
100  Set the print level
101  (if level=-1 use default)
102  */
103  void SetPrintLevel(int level) {fLevel = level;}
104 
105  /*
106  set the mode
107  */
108  void SetMode(double mode) {
109  fMode = mode;
110  fHasMode = true;
111  }
112 
113  /*
114  set the area
115  */
116  void SetArea(double area) {
117  fArea = area;
118  fHasArea = true;
119  }
120 
121  /**
122  Get the random engine used by the sampler
123  */
124  TRandom * GetRandom();
125 
126  /**
127  sample one event in one dimension
128  better implementation could be provided by the derived classes
129  */
130  double Sample1D();// {
131 // return fUnuran->Sample();
132 // }
133 
134  /**
135  sample one event in multi-dimension by filling the given array
136  return false if sampling failed
137  */
138  bool Sample(double * x);
139 // {
140 // if (!fOneDim) return fUnuran->SampleMulti(x);
141 // x[0] = Sample1D();
142 // return true;
143 // }
144 
145  /**
146  sample one bin given an estimated of the pdf in the bin
147  (this can be function value at the center or its integral in the bin
148  divided by the bin width)
149  By default do not do random sample, just return the function values
150  */
151  bool SampleBin(double prob, double & value, double *error = 0);
152 
153 
154 
155 protected:
156 
157  //initialization for 1D distributions
158  bool DoInit1D(const char * algo);
159  //initialization for 1D discrete distributions
160  bool DoInitDiscrete1D(const char * algo);
161  //initialization for multi-dim distributions
162  bool DoInitND(const char * algo);
163 
164 
165 private:
166 
167  // private member
168  bool fOneDim; // flag to indicate if the function is 1 dimension
169  bool fDiscrete; // flag to indicate if the function is discrete
170  bool fHasMode; // flag to indicate if a mode is set
171  bool fHasArea; // flag to indicate if a area is set
172  int fLevel; // debug level
173  double fMode; // mode of dist
174  double fArea; // area of dist
175  const ROOT::Math::IGenFunction * fFunc1D; // 1D function pointer
176  TUnuran * fUnuran; // unuran engine class
177 
178  //ClassDef(TUnuranSampler,1) //Distribution sampler class based on UNU.RAN
179 
180 };
181 
182 
183 
184 #endif /* ROOT_TUnuranSampler */
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
void SetArea(double area)
set the normalization area of distribution implemented by derived classes if needed ...
void SetPrintLevel(int level)
Set the print level (if level=-1 use default)
void SetFunction(const ROOT::Math::IGenFunction &func)
set the parent function distribution to use for random sampling (one dim case)
Double_t x[n]
Definition: legend1.C:17
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
ROOT::R::TRInterface & r
Definition: Object.C:4
DistSampler options class.
TUnuran * fUnuran
TUnuran class.
Definition: TUnuran.h:79
Interface class for generic sampling of a distribution, i.e.
Definition: DistSampler.h:57
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
Namespace for new Math classes and functions.
1-Dim function class
Definition: TF1.h:211
TUnuranSampler class class implementing the ROOT::Math::DistSampler interface using the UNU...
const ROOT::Math::IGenFunction * fFunc1D
void SetMode(double mode)
set the mode of the distribution (could be useful to some methods) implemented by derived classes if ...