RandomSamplerFromPDF.h
Go to the documentation of this file.
1 #ifndef _utl_RandomSamplerFromPDF_h_
2 #define _utl_RandomSamplerFromPDF_h_
3 
4 #include <vector>
5 #include <map>
6 #include <string>
7 
8 #include <utl/VRandomSampler.h>
9 #include <utl/ShadowPtr.h>
10 
11 
12 namespace utl {
13 
14  class TabulatedFunction;
15  class RandomSamplerFromCDF;
16 
43 
44  public:
62  };
63 
65  RandomSamplerFromPDF(const std::vector<double>& x, const std::vector<double>& y,
66  const InterpolationType intType = eStep)
67  { Init(x, y, intType); }
68 
71  const InterpolationType intType = eStep);
72 
74  RandomSamplerFromPDF(const std::vector<double>& pdf,
75  const InterpolationType intType = eStep)
76  { Init(pdf, intType); }
77 
78  RandomSamplerFromPDF(const std::map<double, double>& pdf,
79  const InterpolationType intType = eDiscrete);
80 
82  RandomSamplerFromPDF(const std::string& function,
83  const std::string& independentVariableName,
84  const double min, const double max, const int bins = 100)
85  { SetFunction(function, independentVariableName, min, max, bins); }
86 
88  RandomSamplerFromPDF(const std::string& function,
89  const double min, const double max, const int bins = 100)
90  { SetFunction(function, "x", min, max, bins); }
91 
92  virtual ~RandomSamplerFromPDF();
93 
94  double GetInverseCDF(const double y) const;
95 
96  protected:
97  virtual double MapRandom(const double rand) const
98  { return GetInverseCDF(rand); }
99 
100  private:
101  void SetFunction(const std::string& function,
102  const std::string& independentVariableName,
103  const double min, const double max, const int bins);
104 
105  void Init(const std::vector<double>& x, const std::vector<double>& y,
106  const InterpolationType intType);
107 
108  void Init(const std::vector<double>& y,
109  const InterpolationType intType);
110 
111  void InitDiscrete(const std::vector<double>& x, const std::vector<double>& y);
112 
113  void InitStep(const std::vector<double>& x, const std::vector<double>& y);
114 
115  void InitLinear(const std::vector<double>& x, const std::vector<double>& y);
116 
119  };
120 
121 }
122 
123 
124 #endif
pointer with built-in initialization, deletion, deep copying
Definition: ShadowPtr.h:163
RandomSamplerFromCDF * fCDF
RandomSamplerFromPDF(const std::string &function, const double min, const double max, const int bins=100)
Construct the PDF from a function defined by a string.
Class to hold collection (x,y) points and provide interpolation between them.
void InitDiscrete(const std::vector< double > &x, const std::vector< double > &y)
RandomSamplerFromPDF(const std::vector< double > &x, const std::vector< double > &y, const InterpolationType intType=eStep)
Construct using a PDF defined by an X and Y vectors.
#define max(a, b)
double GetInverseCDF(const double y) const
void InitLinear(const std::vector< double > &x, const std::vector< double > &y)
void Init(const std::vector< double > &x, const std::vector< double > &y, const InterpolationType intType)
RandomSamplerFromPDF(const std::string &function, const std::string &independentVariableName, const double min, const double max, const int bins=100)
Construct the PDF from a function defined by a string.
RandomSamplerFromPDF(const std::vector< double > &pdf, const InterpolationType intType=eStep)
Construct using a PDF defined by an std::vector&lt;double&gt;, the old CLHEP behaviour. ...
void InitStep(const std::vector< double > &x, const std::vector< double > &y)
ShadowPtr< std::vector< double > > fPDF
void SetFunction(const std::string &function, const std::string &independentVariableName, const double min, const double max, const int bins)
Class to shoot random numbers given by a user-defined distribution function.
virtual double MapRandom(const double rand) const

, generated on Tue Sep 26 2023.