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