TUnuranEmpDist.cxx

Go to the documentation of this file.
00001 // @(#)root/unuran:$Id: TUnuranEmpDist.cxx 30749 2009-10-15 16:33:04Z brun $
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 // Implementation file for class TUnuranEmpDist
00012 
00013 #include "TUnuranEmpDist.h"
00014 
00015 #include "TH1.h"
00016 
00017 #include <cassert>
00018 
00019 
00020 TUnuranEmpDist::TUnuranEmpDist (const TH1 * h1, bool useBuffer) : 
00021    fMin(0),
00022    fMax(0)
00023 {
00024    //Constructor from a TH1 objects. 
00025    //The buffer of the histo, if available, can be used for 
00026    // the estimation of the parent distribution using smoothing
00027 
00028    fDim = h1->GetDimension();
00029 
00030    bool unbin = useBuffer &&  h1->GetBufferLength() > 0 ;
00031    fBinned = !unbin;
00032 
00033    if (fBinned ) { 
00034       int nbins = h1->GetNbinsX(); 
00035       fData.reserve(nbins);
00036       for (int i =0; i < nbins; ++i) 
00037          fData.push_back( h1->GetBinContent(i+1) );
00038       
00039       fMin = h1->GetXaxis()->GetXmin();
00040       fMax = h1->GetXaxis()->GetXmax();
00041    }
00042    else { 
00043       //std::cout << "use kernel smoothing method" << std::endl;
00044 
00045       int n = h1->GetBufferLength(); 
00046       const double * bf = h1->GetBuffer(); 
00047       fData.reserve(n);
00048       // fill buffer (assume weights are equal to 1)
00049       // bugger is : [n,w0,x0,y0,..,w1,x1,y1,...wn,xn,yn]
00050       // buffer contains size
00051       for (int i = 0; i < n; ++i) {
00052          int index = (fDim+1)*i + fDim + 1;
00053          fData.push_back(  bf[index] );         
00054       }
00055    }
00056 } 
00057 
00058 TUnuranEmpDist::TUnuranEmpDist (unsigned int n, double * x) : 
00059    fData(std::vector<double>(x,x+n) ),
00060    fDim(1),
00061    fMin(0), fMax(0),
00062    fBinned(0)  
00063 {
00064    // constructor for 1D unbinned data
00065 }
00066 
00067 TUnuranEmpDist::TUnuranEmpDist (unsigned int n, double * x, double * y) : 
00068    fData(std::vector<double>(2*n) ),
00069    fDim(2),
00070    fMin(0), fMax(0),
00071    fBinned(0)  
00072 {
00073    // constructor for 2D unbinned data
00074    for (unsigned int i = 0; i < n; ++i) { 
00075       fData[i*2]   = x[i];
00076       fData[i*2+1] = y[i];
00077    }
00078 }
00079 
00080 TUnuranEmpDist::TUnuranEmpDist (unsigned int n, double * x, double * y, double *z) : 
00081    fData(std::vector<double>(3*n) ),
00082    fDim(3),
00083    fMin(0), fMax(0),
00084    fBinned(0)  
00085 {
00086    // constructor for 3D unbinned data
00087    for (unsigned int i = 0; i < n; ++i) { 
00088       fData[i*3]   = x[i];
00089       fData[i*3+1] = y[i];
00090       fData[i*3+2] = z[i];
00091    }
00092 }
00093 
00094 
00095 
00096 TUnuranEmpDist::TUnuranEmpDist(const TUnuranEmpDist & rhs) :
00097    TUnuranBaseDist()
00098 {
00099    // Implementation of copy ctor using aassignment operator
00100    operator=(rhs);
00101 }
00102 
00103 TUnuranEmpDist & TUnuranEmpDist::operator = (const TUnuranEmpDist &rhs) 
00104 {
00105    // Implementation of assignment operator (copy only the function pointer not the function itself)
00106    if (this == &rhs) return *this;  // time saving self-test
00107    fData  = rhs.fData;
00108    fDim   = rhs.fDim;
00109    fMin   = rhs.fMin;
00110    fMax   = rhs.fMax;
00111    fBinned = rhs.fBinned;
00112    return *this;
00113 }
00114 
00115 
00116 
00117 
00118 
00119 

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