TabulatedPDF.h
Go to the documentation of this file.
1 #ifndef h_TabulatedPDF
2 #define h_TabulatedPDF
3 
4 #include <vector>
5 #include <cfloat>
6 
7 namespace tls {
8 
9  class TabulatedPDF {
10  public:
11  typedef std::vector<double> Array;
12 
13  TabulatedPDF();
14  TabulatedPDF(const TabulatedPDF& src);
15  TabulatedPDF(double xmin, double xstep, const std::vector< double > &yValues);
16  virtual ~TabulatedPDF() {}
17 
18  TabulatedPDF& operator=(const TabulatedPDF& src);
19 
20  void SetScale(double xmin, double xstep) { fXMin = xmin; fXStep = xstep; }
21 
22  void PushBack(double y);
23 
24  void Clear();
25 
26  void Normalise();
27 
28  double Density(double x) const;
29  double Integral(double xmin=-DBL_MAX, double xmax=DBL_MAX) const;
30  double Moment(unsigned short order, double xmin=-DBL_MAX, double xmax=DBL_MAX) const;
31  double Variance(double xmin=-DBL_MAX, double xmax=DBL_MAX) const;
32  double Quantile(double psum) const; // inverse of cdf
33  inline double Median() const { return Quantile(0.5); }
34 
35  unsigned int Size() const { return fY.size(); }
36 
37  // get the idx-th value of the Xs
38  double GetX(unsigned int idx) const { return fXMin + idx*fXStep; }
39 
40  // get/set the idx-th value of the Ys
41  const double& GetY(unsigned int idx) const { return fY[idx]; }
42  double& GetY(unsigned int idx) { return fY[idx]; }
43 
44  // get/set the idx-th value of the Ys
45  const double& GetYSum(unsigned int idx) const { return fYSum[idx]; }
46  double& GetYSum(unsigned int idx) { return fYSum[idx]; }
47 
48  protected:
49  void FillTable(double xmin, double dx, const Array& yValues);
50 
51  double fXMin;
52  double fXStep;
55  };
56 
57 } // NS tls
58 #endif
double Median() const
Definition: TabulatedPDF.h:33
const double & GetY(unsigned int idx) const
Definition: TabulatedPDF.h:41
const double & GetYSum(unsigned int idx) const
Definition: TabulatedPDF.h:45
double Moment(unsigned short order, double xmin=-DBL_MAX, double xmax=DBL_MAX) const
unsigned int Size() const
Definition: TabulatedPDF.h:35
TabulatedPDF & operator=(const TabulatedPDF &src)
Definition: TabulatedPDF.cc:31
double Integral(double xmin=-DBL_MAX, double xmax=DBL_MAX) const
void PushBack(double y)
Definition: TabulatedPDF.cc:55
double & GetY(unsigned int idx)
Definition: TabulatedPDF.h:42
double Variance(double xmin=-DBL_MAX, double xmax=DBL_MAX) const
double & GetYSum(unsigned int idx)
Definition: TabulatedPDF.h:46
void SetScale(double xmin, double xstep)
Definition: TabulatedPDF.h:20
double GetX(unsigned int idx) const
Definition: TabulatedPDF.h:38
TabulatedPDF::Array Array
Definition: TabulatedPDF.cc:15
std::vector< double > Array
Definition: TabulatedPDF.h:11
double Quantile(double psum) const
void FillTable(double xmin, double dx, const Array &yValues)
Definition: TabulatedPDF.cc:41
virtual ~TabulatedPDF()
Definition: TabulatedPDF.h:16
double Density(double x) const

, generated on Tue Sep 26 2023.