00001
00018 #ifndef __RANDOMFUNS_H
00019 #define __RANDOMFUNS_H
00020
00021 #ifndef __INTFUNBASE_H
00022 #include "jbltools/sfh/IntFunBase.h"
00023 #endif
00024
00025 #ifndef __FLOATFUNBASE_H
00026 #include "jbltools/sfh/FloatFunBase.h"
00027 #endif
00028
00029 #include "jbltools/sfh/FloatFunPoR.h"
00030
00031 class TH1;
00032
00033
00035
00039 class RandomFun : public FloatFun {
00040 public:
00041
00042 explicit RandomFun (const IntFun& seed_,
00043 int index_,
00044 const char *name_ = 0
00045 );
00047 RandomFun (const IntFun& seed_,
00048 int index_,
00049 const std::string &name_
00050 );
00051 RandomFun (const IntFun& seed1_,
00052 const IntFun& seed2_,
00053 int index_,
00054 const char *name_ = 0
00055 );
00056 RandomFun (const IntFun& seed1_,
00057 const IntFun& seed2_,
00058 int index_,
00059 const std::string &name_
00060 );
00062 virtual Float_FF operator() () const;
00063
00065 virtual const FillIterator *getIterator() const;
00066
00067 static long long iterate (long long i) {
00068 return (i*a + c) % m;
00069 }
00070 static long long toInt (Float_FF d) {
00071 return static_cast<long long>((d*m));
00072 }
00073 static Float_FF toDouble (long long i) {
00074 return (Float_FF)(i)/(Float_FF)(m);
00075 }
00076 static Float_FF generateNext (Float_FF d) {
00077 return toDouble(iterate(toInt(d)));
00078 }
00079
00080 protected:
00081 const IntFun& seed;
00082 int index;
00083 bool cleanup;
00084
00085 virtual ~RandomFun();
00086 private:
00087
00088
00089
00090
00091 static const long long a;
00092 static const long long c;
00093 static const long long m;
00094 };
00095
00096
00098 class GaussRandomFun : public FloatFun {
00099 public:
00100
00101 explicit GaussRandomFun (const FloatFun& rnd_,
00102 double mean_,
00103 double sigma_,
00104 const char *name_ = 0
00105 );
00107 GaussRandomFun (const FloatFun& rnd_,
00108 double mean_,
00109 double sigma_,
00110 const std::string &name_
00111 );
00113 virtual Float_FF operator() () const;
00114
00116 virtual const FillIterator *getIterator() const;
00117
00118 protected:
00119 const FloatFun& rnd;
00120 double mean;
00121 double sigma;
00122
00123 virtual ~GaussRandomFun() {}
00124 };
00125
00126
00128 class Poisson1Fun : public IntFun {
00129 public:
00131 explicit Poisson1Fun (const FloatFun& rnd_,
00132 double mean_,
00133 const char *name_ = 0
00134 );
00135
00137 explicit Poisson1Fun (const FloatFun& rnd_,
00138 double mean_,
00139 const std::string& name_
00140 )
00141 : IntFun (name_),
00142 rnd(rnd_),
00143 mean (mean_)
00144 {}
00145
00147 virtual int operator() () const;
00148
00150 virtual const FillIterator *getIterator() const;
00151
00152 protected:
00153 const FloatFun& rnd;
00154 double mean;
00155
00156 virtual ~Poisson1Fun() {}
00157 };
00158
00159
00161 class Poisson2Fun : public IntFun {
00162 public:
00164 explicit Poisson2Fun (const FloatFun& rnd_,
00165 double mean_,
00166 const char *name_ = 0
00167 );
00168
00170 explicit Poisson2Fun (const FloatFun& rnd_,
00171 double mean_,
00172 const std::string& name_
00173 );
00174
00176 virtual int operator() () const;
00177
00179 virtual const FillIterator *getIterator() const;
00180
00181 protected:
00182 FloatFun& gaussrnd;
00183
00184 virtual ~Poisson2Fun();
00185 };
00186
00187
00188
00190 class HistoRandomFun : public FloatFun {
00191 public:
00193 explicit HistoRandomFun (const FloatFun& rnd_,
00194 const TH1& histo,
00195 const char *name_ = 0
00196 );
00197
00199 HistoRandomFun (const FloatFun& rnd_,
00200 const TH1& histo,
00201 const std::string& name_
00202 );
00203
00205 virtual Float_FF operator() () const;
00206
00208 virtual const FillIterator *getIterator() const;
00209
00210 protected:
00211 const FloatFun& rnd;
00212 int nbins;
00213 double *edges;
00214 double *values;
00215
00216 void init (const TH1& histo
00217 );
00219 virtual ~HistoRandomFun();
00220 };
00221
00222
00223
00225 class HistoRandomIntFun : public IntFun {
00226 public:
00228 explicit HistoRandomIntFun (const FloatFun& rnd_,
00229 const TH1& histo,
00230 const char *name_ = 0
00231 );
00232
00234 HistoRandomIntFun (const FloatFun& rnd_,
00235 const TH1& histo,
00236 const std::string& name_
00237 );
00238
00240 virtual int operator() () const;
00241
00243 virtual const FillIterator *getIterator() const;
00244
00245 protected:
00246 const FloatFun& rnd;
00247 int nbins;
00248 double *edges;
00249 double *values;
00250
00251 void init (const TH1& histo
00252 );
00254 virtual ~HistoRandomIntFun();
00255 };
00256
00257
00258
00259
00264 FloatFun& gauss (const FloatFunPoR& rnd,
00265 double mean,
00266 double sigma
00267 );
00268
00273 IntFun& poisson (const FloatFunPoR& rnd,
00274 double mean
00275 );
00276
00277 #endif