00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00025
00026
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
00044
00045 int n = h1->GetBufferLength();
00046 const double * bf = h1->GetBuffer();
00047 fData.reserve(n);
00048
00049
00050
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
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
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
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
00100 operator=(rhs);
00101 }
00102
00103 TUnuranEmpDist & TUnuranEmpDist::operator = (const TUnuranEmpDist &rhs)
00104 {
00105
00106 if (this == &rhs) return *this;
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