ROOT  6.06/09
Reference Guide
TUnuranEmpDist.h
Go to the documentation of this file.
1 // @(#)root/unuran:$Id$
2 // Authors: L. Moneta, J. Leydold Wed Feb 28 2007
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class TUnuranEmpDist
12 
13 
14 #ifndef ROOT_Math_TUnuranEmpDist
15 #define ROOT_Math_TUnuranEmpDist
16 
17 
18 #ifndef ROOT_Math_TUnuranBaseDist
19 #include "TUnuranBaseDist.h"
20 #endif
21 
22 #include <vector>
23 
24 class TH1;
25 
26 
27 /**
28  \class TUnuranEmpDist
29  \ingroup Unuran
30 
31  TUnuranEmpDist class for describing empiral distributions. It is used by TUnuran
32  to generate double random number according to this distribution via TUnuran::Sample() or
33  TUnuran::Sample(double *) in case of multi-dimensional empirical distributions.
34 
35  An empirical distribution can be one or multi-dimension constructed from a set of unbinned data,
36  (the class can be constructed from an iterator to a vector of data) or by using an histogram
37  (with apointer to the TH1 class). If the histogram contains a buffer with the original data they are used by
38  default to estimate the empirical distribution, othewise the bins information is used. In this binned case
39  only one dimension is now supported.
40 
41  In the case of unbinned data the density distribution is estimated by UNURAN using kernel smoothing and
42  then random numbers are generated. In the case of bin data (which can only be one dimension)
43  the probability density is estimated directly from the histograms and the random numbers are generated according
44  to the histogram (like in TH1::GetRandom). This method requires some initialization time but it is faster
45  in generating the random numbers than TH1::GetRandom and it becomes convenient to use when generating
46  a large amount of data.
47 
48 */
49 
50 
52 
53 public:
54 
55 
56  /**
57  Constructor from a TH1 objects.
58  If the histogram has a buffer by default the unbinned data are used
59  */
60  TUnuranEmpDist (const TH1 * h1 = 0, bool useBuffer = true );
61 
62  /**
63  Constructor from a set of data using an iterator to specify begin/end of the data
64  In the case of multi-dimension the data are assumed to be passed in this order
65  x0,y0,...x1,y1,..x2,y2,...
66  */
67  template<class Iterator>
68  TUnuranEmpDist (Iterator begin, Iterator end, unsigned int dim = 1) :
69  fData(std::vector<double>(begin,end) ),
70  fDim(dim),
71  fMin(0), fMax(0),
72  fBinned(0) {}
73 
74  /**
75  Constructor from a set of 1D data
76  */
77  TUnuranEmpDist (unsigned int n, double * x);
78 
79  /**
80  Constructor from a set of 2D data
81  */
82  TUnuranEmpDist (unsigned int n, double * x, double * y);
83 
84  /**
85  Constructor from a set of 3D data
86  */
87  TUnuranEmpDist (unsigned int n, double * x, double * y, double * z);
88 
89 
90  /**
91  Destructor (no operations)
92  */
93  virtual ~TUnuranEmpDist () {}
94 
95 
96  /**
97  Copy constructor
98  */
100 
101 
102  /**
103  Assignment operator
104  */
106 
107  /**
108  Clone (required by base class)
109  */
110  TUnuranEmpDist * Clone() const { return new TUnuranEmpDist(*this); }
111 
112 
113  /**
114  Return reference to data vector (unbinned or binned data)
115  */
116  const std::vector<double> & Data() const { return fData; }
117 
118  /**
119  Flag to control if data are binned
120  */
121  bool IsBinned() const { return fBinned; }
122 
123  /**
124  Min value of binned data
125  (return 0 for unbinned data)
126  */
127  double LowerBin() const { return fMin; }
128 
129  /**
130  upper value of binned data
131  (return 0 for unbinned data)
132  */
133  double UpperBin() const { return fMax; }
134 
135  /**
136  Number of data dimensions
137  */
138  unsigned int NDim() const { return fDim; }
139 
140 
141 private:
142 
143  std::vector<double> fData; //pointer to the data vector (used for generation from un-binned data)
144  unsigned int fDim; //data dimensionality
145  double fMin; // min values (used in the binned case)
146  double fMax; // max values (used in the binned case)
147  bool fBinned; // flag for binned/unbinned data
148 
149  ClassDef(TUnuranEmpDist,1) //Wrapper class for empirical distribution
150 
151 
152 };
153 
154 
155 
156 #endif /* ROOT_Math_TUnuranEmpDist */
TUnuranBaseDist, base class for Unuran distribution classees such as TUnuranContDist (for one-dimensi...
TUnuranEmpDist(Iterator begin, Iterator end, unsigned int dim=1)
Constructor from a set of data using an iterator to specify begin/end of the data In the case of mult...
TUnuranEmpDist & operator=(const TUnuranEmpDist &rhs)
Assignment operator.
const std::vector< double > & Data() const
Return reference to data vector (unbinned or binned data)
STL namespace.
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual ~TUnuranEmpDist()
Destructor (no operations)
TH1F * h1
Definition: legend1.C:5
TUnuranEmpDist class for describing empiral distributions.
TUnuranEmpDist * Clone() const
Clone (required by base class)
std::vector< double > fData
double LowerBin() const
Min value of binned data (return 0 for unbinned data)
bool IsBinned() const
Flag to control if data are binned.
TUnuranEmpDist(const TH1 *h1=0, bool useBuffer=true)
Constructor from a TH1 objects.
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:80
double UpperBin() const
upper value of binned data (return 0 for unbinned data)
unsigned int NDim() const
Number of data dimensions.
const Int_t n
Definition: legend1.C:16
unsigned int fDim