00001 // @(#)root/mathcore:$Id: TFoamSampler.h 37419 2010-12-08 21:19:45Z moneta $ 00002 // Author: L. Moneta Fri Sep 22 15:06:47 2006 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT * 00007 * * 00008 * * 00009 **********************************************************************/ 00010 // Header file for class TFoamSampler 00011 00012 #ifndef ROOT_TFoamSampler 00013 #define ROOT_TFoamSampler 00014 00015 00016 #ifndef ROOT_Math_DistSampler 00017 #include "Math/DistSampler.h" 00018 #endif 00019 00020 00021 namespace ROOT { 00022 00023 namespace Fit { 00024 00025 class DataRange; 00026 class BinData; 00027 class UnBinData; 00028 } 00029 00030 namespace Math { 00031 } 00032 } 00033 00034 class TFoamIntegrand; 00035 00036 00037 class TRandom; 00038 class TF1; 00039 class TFoam; 00040 00041 00042 //_______________________________________________________________________________ 00043 /** 00044 TFoamSampler class 00045 class implementing the ROOT::Math::DistSampler interface using FOAM 00046 for sampling arbitrary distributions. 00047 00048 00049 */ 00050 class TFoamSampler : public ROOT::Math::DistSampler { 00051 00052 public: 00053 00054 /// default constructor 00055 TFoamSampler(); 00056 00057 00058 /// virtual destructor 00059 virtual ~TFoamSampler(); 00060 00061 00062 using DistSampler::SetFunction; 00063 00064 /// set the parent function distribution to use for random sampling (one dim case) 00065 void SetFunction(const ROOT::Math::IGenFunction & func) { 00066 fFunc1D = &func; 00067 SetFunction<const ROOT::Math::IGenFunction>(func, 1); 00068 } 00069 00070 /// set the Function using a TF1 pointer 00071 void SetFunction(TF1 * pdf); 00072 00073 00074 /** 00075 initialize the generators with the default options 00076 */ 00077 bool Init(const char * = ""); 00078 00079 /** 00080 initialize the generators with the fiven options 00081 */ 00082 bool Init(const ROOT::Math::DistSamplerOptions & opt ); 00083 00084 /** 00085 Set the random engine to be used 00086 Needs to be called before Init to have effect 00087 */ 00088 void SetRandom(TRandom * r); 00089 00090 /** 00091 Set the random seed for the TRandom instances used by the sampler 00092 classes 00093 Needs to be called before Init to have effect 00094 */ 00095 void SetSeed(unsigned int seed); 00096 00097 00098 /** 00099 Get the random engine used by the sampler 00100 */ 00101 TRandom * GetRandom(); 00102 00103 00104 /** 00105 sample one event in multi-dimension by filling the given array 00106 return false if sampling failed 00107 */ 00108 bool Sample(double * x); 00109 00110 /** 00111 sample one bin given an estimated of the pdf in the bin 00112 (this can be function value at the center or its integral in the bin 00113 divided by the bin width) 00114 By default do not do random sample, just return the function values 00115 */ 00116 bool SampleBin(double prob, double & value, double *error = 0); 00117 00118 00119 00120 protected: 00121 00122 00123 private: 00124 00125 // private member 00126 bool fOneDim; // flag to indicate if the function is 1 dimension 00127 // bool fHasMode; // flag to indicate if a mode is set 00128 // bool fHasArea; // flag to indicate if a area is set 00129 // double fMode; // mode of dist 00130 // double fArea; // area of dist 00131 const ROOT::Math::IGenFunction * fFunc1D; // 1D function pointer 00132 TFoam * fFoam; // foam engine class 00133 TFoamIntegrand * fFoamDist; // foam distribution interface 00134 00135 //ClassDef(TFoamSampler,1) //Distribution sampler class based on FOAM 00136 00137 }; 00138 00139 00140 00141 #endif /* ROOT_TFoamSampler */