Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 class TFoamSampler : public ROOT::Math::DistSampler {
40 
41 public:
42 
43  /// default constructor
44  TFoamSampler();
45 
46 
47  /// virtual destructor
48  virtual ~TFoamSampler();
49 
50 
51  using DistSampler::SetFunction;
52 
53  /// set the parent function distribution to use for random sampling (one dim case)
54  void SetFunction(const ROOT::Math::IGenFunction & func) {
55  fFunc1D = &func;
56  SetFunction<const ROOT::Math::IGenFunction>(func, 1);
57  }
58 
59  /// set the Function using a TF1 pointer
60  void SetFunction(TF1 * pdf);
61 
62 
63  /**
64  initialize the generators with the default options
65  */
66  bool Init(const char * = "");
67 
68  /**
69  initialize the generators with the given options
70  */
71  bool Init(const ROOT::Math::DistSamplerOptions & opt );
72 
73  /**
74  Set the random engine to be used
75  Needs to be called before Init to have effect
76  */
77  void SetRandom(TRandom * r);
78 
79  /**
80  Set the random seed for the TRandom instances used by the sampler
81  classes
82  Needs to be called before Init to have effect
83  */
84  void SetSeed(unsigned int seed);
85 
86 
87  /**
88  Get the random engine used by the sampler
89  */
90  TRandom * GetRandom();
91 
92 
93  /**
94  sample one event in multi-dimension by filling the given array
95  return false if sampling failed
96  */
97  bool Sample(double * x);
98 
99  /**
100  sample one bin given an estimated of the pdf in the bin
101  (this can be function value at the center or its integral in the bin
102  divided by the bin width)
103  By default do not do random sample, just return the function values
104  */
105  bool SampleBin(double prob, double & value, double *error = 0);
106 
107 
108 
109 protected:
110 
111 
112 private:
113 
114 // bool fOneDim; // flag to indicate if the function is 1 dimension
115 // bool fHasMode; // flag to indicate if a mode is set
116 // bool fHasArea; // flag to indicate if a area is set
117 // double fMode; // mode of dist
118 // double fArea; // area of dist
119  const ROOT::Math::IGenFunction * fFunc1D; // 1D function pointer
120  TFoam * fFoam; // foam engine class
121  TFoamIntegrand * fFoamDist; // foam distribution interface
122 
123  //ClassDef(TFoamSampler,1) //Distribution sampler class based on FOAM
124 
125 };
126 
127 
128 
129 #endif /* ROOT_TFoamSampler */