UnBinData.cxx

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: UnBinData.cxx 31763 2009-12-10 10:40:21Z moneta $
00002 // Author: L. Moneta Wed Aug 30 11:10:03 2006
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Implementation file for class UnBinData
00012 
00013 #include "Fit/UnBinData.h"
00014 #include "Math/Error.h"
00015 
00016 #include <cassert> 
00017 #include <cmath>
00018 
00019 namespace ROOT { 
00020 
00021    namespace Fit { 
00022 
00023 UnBinData::UnBinData(unsigned int maxpoints, unsigned int dim ) : 
00024    FitData(),
00025    fDim(dim),
00026    fNPoints(0),
00027    fDataVector(0), 
00028    fDataWrapper(0)
00029 { 
00030    // constructor with default option and range
00031    unsigned int n = dim*maxpoints; 
00032    if ( n > MaxSize() ) 
00033       MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n )
00034    else if (n > 0) 
00035       fDataVector = new DataVector(n);
00036 } 
00037 
00038 UnBinData::UnBinData (const DataRange & range,  unsigned int maxpoints , unsigned int dim ) : 
00039    FitData(range), 
00040    fDim(dim),
00041    fNPoints(0), 
00042    fDataVector(0), 
00043    fDataWrapper(0)
00044 {
00045    // constructor from option and default range
00046    unsigned int n = dim*maxpoints; 
00047    if ( n > MaxSize() ) 
00048       MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n )
00049    else if (n > 0) 
00050       fDataVector = new DataVector(n);
00051 } 
00052 
00053 UnBinData::UnBinData (const DataOptions & opt, const DataRange & range,  unsigned int maxpoints, unsigned int dim ) : 
00054    FitData( opt, range), 
00055    fDim(dim),
00056    fNPoints(0),
00057    fDataVector(0), 
00058    fDataWrapper(0)
00059 {
00060    // constructor from options and range
00061    unsigned int n = dim*maxpoints; 
00062    if ( n > MaxSize() ) 
00063       MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n )
00064    else if (n > 0) 
00065       fDataVector = new DataVector(n);
00066 } 
00067       
00068 UnBinData::UnBinData(unsigned int n, const double * dataX ) : 
00069    FitData( ), 
00070    fDim(1), 
00071    fNPoints(n),
00072    fDataVector(0)
00073 { 
00074    // constructor for 1D external data
00075    fDataWrapper = new DataWrapper(dataX);
00076 } 
00077       
00078 UnBinData::UnBinData(unsigned int n, const double * dataX, const double * dataY ) : 
00079    FitData( ), 
00080    fDim(2), 
00081    fNPoints(n),
00082    fDataVector(0),
00083    fDataWrapper(0)
00084 { 
00085    //    constructor for 2D external data
00086    fDataWrapper = new DataWrapper(dataX, dataY, 0, 0, 0, 0);
00087 } 
00088 
00089 UnBinData::UnBinData(unsigned int n, const double * dataX, const double * dataY, const double * dataZ ) : 
00090    FitData( ), 
00091    fDim(3), 
00092    fNPoints(n),
00093    fDataVector(0)
00094 { 
00095    //   constructor for 3D external data
00096    fDataWrapper = new DataWrapper(dataX, dataY, dataZ, 0, 0, 0, 0, 0);
00097 } 
00098 
00099 UnBinData::UnBinData(unsigned int n, const double * dataX, const DataRange & range ) : 
00100    FitData(range), 
00101    fDim(1), 
00102    fNPoints(0),
00103    fDataVector(0),
00104    fDataWrapper(0)
00105 { 
00106    // constructor for 1D array data using a range to select the data
00107    if ( n > MaxSize() ) 
00108       MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n )
00109    else if (n > 0) {
00110       fDataVector = new DataVector(n);
00111 
00112       for (unsigned int i = 0; i < n; ++i)  
00113          if ( range.IsInside(dataX[i]) ) Add(dataX[i] ); 
00114       
00115       if (fNPoints < n) (fDataVector->Data()).resize(fNPoints); 
00116    } 
00117 }
00118       
00119 UnBinData::UnBinData(unsigned int n, const double * dataX, const double * dataY, const DataRange & range ) : 
00120    FitData(range), 
00121    fDim(2), 
00122    fNPoints(0),
00123    fDataVector(0),
00124    fDataWrapper(0)
00125 { 
00126    // constructor for 2D array data using a range to select the data
00127    if ( n > MaxSize() ) 
00128       MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n )
00129    else if (n > 0) {
00130       fDataVector = new DataVector(2*n);
00131 
00132       for (unsigned int i = 0; i < n; ++i)  
00133          if ( range.IsInside(dataX[i],0) && 
00134               range.IsInside(dataY[i],1) )
00135             Add(dataX[i], dataY[i] ); 
00136       
00137       if (fNPoints < n) (fDataVector->Data()).resize(2*fNPoints); 
00138    } 
00139 } 
00140 
00141 UnBinData::UnBinData(unsigned int n, const double * dataX, const double * dataY, const double * dataZ, 
00142                      const DataRange & range ) : 
00143    FitData(range ), 
00144    fDim(3), 
00145    fNPoints(0),
00146    fDataVector(0),
00147    fDataWrapper(0)
00148 { 
00149    // constructor for 3D array data using a range to select the data
00150    if ( n > MaxSize() ) 
00151       MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n )
00152    else if (n > 0) {
00153       fDataVector = new DataVector(3*n);
00154 
00155       for (unsigned int i = 0; i < n; ++i)  
00156          if ( range.IsInside(dataX[i],0) && 
00157               range.IsInside(dataY[i],1) &&
00158               range.IsInside(dataZ[i],2) )
00159             Add(dataX[i], dataY[i], dataZ[i] ); 
00160       
00161       if (fNPoints < n) (fDataVector->Data()).resize(3*fNPoints); 
00162    } 
00163 } 
00164 
00165 void UnBinData::Initialize(unsigned int maxpoints, unsigned int dim ) { 
00166    //   preallocate a data set given size and dimension
00167    if ( dim != fDim && fDataVector) { 
00168 //       MATH_INFO_MSGVAL("BinData::Initialize"," Reset amd re-initialize with a new fit point size of ",
00169 //                        dim);
00170       delete fDataVector; 
00171       fDataVector = 0; 
00172    }
00173    fDim = dim;
00174    unsigned int n = fDim*maxpoints; 
00175    if ( n > MaxSize() ) { 
00176       MATH_ERROR_MSGVAL("UnBinData::Initialize","Invalid data size", n );
00177       return; 
00178    }
00179    if (fDataVector) 
00180       (fDataVector->Data()).resize( fDataVector->Size() + n );
00181    else 
00182       fDataVector = new DataVector( n);
00183 }
00184 
00185 void UnBinData::Resize(unsigned int npoints) { 
00186    // resize vector to new points 
00187    if (fDim == 0) return; 
00188    if ( npoints > MaxSize() ) { 
00189       MATH_ERROR_MSGVAL("BinData::Resize"," Invalid data size  ", npoints );
00190       return; 
00191    }
00192    if (fDataVector != 0)  { 
00193       int nextraPoints = npoints -  fDataVector->Size()/fDim; 
00194       if  (nextraPoints < 0) {
00195          // delete extra points
00196          (fDataVector->Data()).resize( npoints * fDim);
00197       }
00198       else if (nextraPoints > 0) { 
00199          // add extra points 
00200          Initialize(nextraPoints, fDim ); 
00201       }
00202       else // nextraPoints == 0
00203          return; 
00204    }
00205    else // no DataVector create
00206       fDataVector = new DataVector( npoints*fDim);      
00207 }
00208 
00209 
00210 
00211    } // end namespace Fit
00212 
00213 } // end namespace ROOT
00214 

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