Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
19namespace 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
45class TRandom;
46class TF1;
47class TUnuran;
48
50
51public:
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
155protected:
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
165private:
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 */
ROOT::R::TRInterface & r
Definition Object.C:4
DistSampler options class.
Interface class for generic sampling of a distribution, i.e.
Definition DistSampler.h:57
const double * Sample()
sample one event and rerturning array x with coordinates
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition IFunction.h:135
1-Dim function class
Definition TF1.h:213
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
TUnuranSampler class class implementing the ROOT::Math::DistSampler interface using the UNU....
TRandom * GetRandom()
Get the random engine used by the sampler.
void SetRandom(TRandom *r)
Set the random engine to be used Needs to be called before Init to have effect.
virtual ~TUnuranSampler()
virtual destructor
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 ...
void SetPrintLevel(int level)
Set the print level (if level=-1 use default)
bool DoInitND(const char *algo)
void SetSeed(unsigned int seed)
Set the random seed for the TRandom instances used by the sampler classes Needs to be called before I...
const ROOT::Math::IGenFunction * fFunc1D
void SetArea(double area)
set the normalization area of distribution implemented by derived classes if needed
bool DoInit1D(const char *algo)
void SetMode(double mode)
set the mode of the distribution (could be useful to some methods) implemented by derived classes if ...
bool Init(const char *algo="")
initialize the generators with the given algorithm If no algorithm is passed used the default one for...
TUnuranSampler()
default constructor
void SetFunction(const ROOT::Math::IGenFunction &func)
set the parent function distribution to use for random sampling (one dim case)
double Sample1D()
sample one event in one dimension better implementation could be provided by the derived classes
bool DoInitDiscrete1D(const char *algo)
TUnuran class.
Definition TUnuran.h:79
Double_t x[n]
Definition legend1.C:17
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition HFitImpl.cxx:133
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...