TUnuranEmpDist.h

Go to the documentation of this file.
00001 // @(#)root/unuran:$Id: TUnuranEmpDist.h 21526 2007-12-20 10:42:41Z moneta $
00002 // Authors: L. Moneta, J. Leydold Wed Feb 28 2007
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Header file for class TUnuranEmpDist
00012 
00013 
00014 #ifndef ROOT_Math_TUnuranEmpDist
00015 #define ROOT_Math_TUnuranEmpDist
00016 
00017 
00018 #ifndef ROOT_Math_TUnuranBaseDist
00019 #include "TUnuranBaseDist.h"
00020 #endif
00021 
00022 #include <vector>
00023 
00024 class TH1;
00025 
00026 //_______________________________________________________________________________
00027 /** 
00028    TUnuranEmpDist class for describing empiral  distributions. It is used by TUnuran 
00029    to generate double random number according to this distribution via TUnuran::Sample() or 
00030    TUnuran::Sample(double *) in case of multi-dimensional empirical distributions. 
00031    
00032    An empirical distribution can be one or multi-dimension constructed from a set of unbinned data, 
00033    (the class can be constructed from an iterator to a vector of data) or by using an histogram 
00034    (with apointer to the TH1 class). If the histogram contains a buffer with the original data they are used by 
00035    default to estimate the empirical distribution, othewise the bins information is used. In this binned case 
00036    only one dimension is now supported.  
00037 
00038    In the case of unbinned data the density distribution is estimated by UNURAN using kernel smoothing and 
00039    then random numbers are generated. In the case of bin data (which can only be one dimension) 
00040    the probability density is estimated directly from the histograms and the random numbers are generated according 
00041    to the histogram (like in TH1::GetRandom). This method requires some initialization time but it is faster 
00042    in generating the random numbers than TH1::GetRandom and it becomes convenient to use when generating 
00043    a large amount of data. 
00044 
00045 */ 
00046 ///////////////////////////////////////////////////////////////////////
00047 
00048 class TUnuranEmpDist : public TUnuranBaseDist {
00049 
00050 public: 
00051 
00052 
00053    /** 
00054       Constructor from a TH1 objects.  
00055       If the histogram has a buffer by default the unbinned data are used 
00056    */ 
00057    TUnuranEmpDist (const TH1 * h1 = 0, bool useBuffer = true );
00058 
00059    /** 
00060       Constructor from a set of data using an iterator to specify begin/end of the data
00061       In the case of multi-dimension the data are assumed to be passed in this order 
00062       x0,y0,...x1,y1,..x2,y2,...
00063    */ 
00064    template<class Iterator>
00065    TUnuranEmpDist (Iterator begin, Iterator end, unsigned int dim = 1) : 
00066       fData(std::vector<double>(begin,end) ), 
00067       fDim(dim), 
00068       fMin(0), fMax(0),
00069       fBinned(0)  {}
00070 
00071    /** 
00072       Constructor from a set of 1D data
00073    */ 
00074    TUnuranEmpDist (unsigned int n, double * x); 
00075 
00076    /** 
00077       Constructor from a set of 2D data
00078    */ 
00079    TUnuranEmpDist (unsigned int n, double * x, double * y); 
00080 
00081    /** 
00082       Constructor from a set of 3D data
00083    */ 
00084    TUnuranEmpDist (unsigned int n, double * x, double * y, double * z); 
00085 
00086 
00087    /** 
00088       Destructor (no operations)
00089    */ 
00090    virtual ~TUnuranEmpDist () {}
00091 
00092 
00093    /** 
00094       Copy constructor
00095    */ 
00096    TUnuranEmpDist(const TUnuranEmpDist &);
00097    
00098 
00099    /** 
00100       Assignment operator
00101    */ 
00102    TUnuranEmpDist & operator = (const TUnuranEmpDist & rhs); 
00103 
00104    /**
00105       Clone (required by base class)
00106     */
00107    TUnuranEmpDist * Clone() const { return new TUnuranEmpDist(*this); } 
00108 
00109 
00110    /**
00111       Return reference to data vector (unbinned or binned data)
00112     */
00113    const std::vector<double> & Data() const { return fData; }
00114 
00115    /**
00116       Flag to control if data are binned 
00117     */ 
00118    bool IsBinned() const { return fBinned; }
00119 
00120    /**
00121       Min value of binned data 
00122       (return 0 for unbinned data)
00123     */
00124    double LowerBin() const { return fMin; }
00125 
00126    /**
00127       upper value of binned data 
00128       (return 0 for unbinned data)
00129     */
00130    double UpperBin() const { return fMax; }
00131 
00132    /**
00133       Number of data dimensions
00134     */
00135    unsigned int NDim() const { return fDim; }
00136    
00137 
00138 private: 
00139 
00140    std::vector<double>  fData;       //pointer to the data vector (used for generation from un-binned data)
00141    unsigned int fDim;                 //data dimensionality
00142    double fMin;                       // min values (used in the binned case)
00143    double fMax;                       // max values (used in the binned case)
00144    bool   fBinned;                    // flag for binned/unbinned data 
00145 
00146    ClassDef(TUnuranEmpDist,1)         //Wrapper class for empirical distribution 
00147 
00148 
00149 }; 
00150 
00151 
00152 
00153 #endif /* ROOT_Math_TUnuranEmpDist */

Generated on Tue Jul 5 14:43:39 2011 for ROOT_528-00b_version by  doxygen 1.5.1