00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_Fit_UnBinData
00014 #define ROOT_Fit_UnBinData
00015
00016 #ifndef ROOT_Fit_DataVector
00017 #include "Fit/DataVector.h"
00018 #endif
00019
00020 #ifndef ROOT_Math_Error
00021 #include "Math/Error.h"
00022 #endif
00023
00024
00025
00026 namespace ROOT {
00027
00028 namespace Fit {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class UnBinData : public FitData {
00048
00049 public :
00050
00051
00052
00053
00054
00055 explicit UnBinData(unsigned int maxpoints = 0, unsigned int dim = 1 );
00056
00057
00058
00059
00060
00061 explicit UnBinData (const DataRange & range, unsigned int maxpoints = 0, unsigned int dim = 1);
00062
00063
00064
00065
00066 UnBinData (const DataOptions & opt, const DataRange & range, unsigned int maxpoints = 0, unsigned int dim = 1 );
00067
00068
00069
00070
00071 UnBinData(unsigned int n, const double * dataX );
00072
00073
00074
00075
00076 UnBinData(unsigned int n, const double * dataX, const double * dataY );
00077
00078
00079
00080
00081 UnBinData(unsigned int n, const double * dataX, const double * dataY, const double * dataZ );
00082
00083
00084
00085
00086
00087
00088 template<class Iterator>
00089 UnBinData(unsigned int n, unsigned int dim, Iterator dataItr ) :
00090 FitData( ),
00091 fDim(dim),
00092 fNPoints(n),
00093 fDataVector(0)
00094 {
00095 fDataWrapper = new DataWrapper(dim, dataItr);
00096 }
00097
00098
00099
00100
00101 UnBinData(unsigned int maxpoints, const double * dataX, const DataRange & range);
00102
00103
00104
00105
00106 UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY, const DataRange & range);
00107
00108
00109
00110
00111 UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY, const double * dataZ, const DataRange & range);
00112
00113
00114
00115
00116
00117
00118 template<class Iterator>
00119 UnBinData(unsigned int maxpoints, unsigned int dim, Iterator dataItr, const DataRange & range ) :
00120 FitData( ),
00121 fDim(dim),
00122 fNPoints(0),
00123 fDataVector(0),
00124 fDataWrapper(0)
00125 {
00126 unsigned int n = dim*maxpoints;
00127 if ( n > MaxSize() ) {
00128 MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n );
00129 }
00130 else if (n > 0) {
00131 fDataVector = new DataVector(n);
00132
00133
00134 ROOT::Fit::DataWrapper wdata(dim, dataItr);
00135 for (unsigned int i = 0; i < maxpoints; ++i) {
00136 bool isInside = true;
00137 for (unsigned int icoord = 0; icoord < dim; ++icoord)
00138 isInside &= range.IsInside( wdata.Coords(i)[icoord], icoord );
00139 if ( isInside ) Add(wdata.Coords(i));
00140 }
00141 if (fNPoints < maxpoints) (fDataVector->Data()).resize(fDim*fNPoints);
00142 }
00143 }
00144
00145
00146 private:
00147
00148 UnBinData(const UnBinData &) : FitData() {}
00149
00150 UnBinData & operator= (const UnBinData &) { return *this; }
00151
00152 public:
00153
00154 #ifdef LATER
00155
00156
00157
00158
00159 UnBinData (const UnBinData & data , const DataOptions & opt, const DataRange & range) :
00160 DataVector(opt,range, data.DataSize() ),
00161 fDim(data.fDim),
00162 fNPoints(data.fNPoints)
00163 {
00164
00165
00166
00167 }
00168 #endif
00169
00170
00171
00172
00173 virtual ~UnBinData() {
00174 if (fDataVector) delete fDataVector;
00175 if (fDataWrapper) delete fDataWrapper;
00176 }
00177
00178
00179
00180
00181
00182
00183 void Initialize(unsigned int maxpoints, unsigned int dim = 1);
00184
00185
00186
00187
00188
00189 unsigned int PointSize() const {
00190 return fDim;
00191 }
00192
00193
00194
00195
00196 unsigned int DataSize() const {
00197 return (fDataVector) ? fDataVector->Size() : 0;
00198 }
00199
00200
00201
00202
00203 void Add(double x) {
00204 int index = fNPoints*PointSize();
00205 assert(fDataVector != 0);
00206 assert(PointSize() == 1);
00207 assert (index + PointSize() <= DataSize() );
00208
00209 (fDataVector->Data())[ index ] = x;
00210
00211 fNPoints++;
00212 }
00213
00214
00215
00216
00217 void Add(double x, double y) {
00218 int index = fNPoints*PointSize();
00219 assert(fDataVector != 0);
00220 assert(PointSize() == 2);
00221 assert (index + PointSize() <= DataSize() );
00222
00223 (fDataVector->Data())[ index ] = x;
00224 (fDataVector->Data())[ index+1 ] = y;
00225
00226 fNPoints++;
00227 }
00228
00229
00230
00231
00232 void Add(double x, double y, double z) {
00233 int index = fNPoints*PointSize();
00234 assert(fDataVector != 0);
00235 assert(PointSize() == 3);
00236 assert (index + PointSize() <= DataSize() );
00237
00238 (fDataVector->Data())[ index ] = x;
00239 (fDataVector->Data())[ index+1 ] = y;
00240 (fDataVector->Data())[ index+2 ] = z;
00241
00242 fNPoints++;
00243 }
00244
00245
00246
00247
00248 void Add(const double *x) {
00249 int index = fNPoints*PointSize();
00250
00251 assert(fDataVector != 0);
00252 assert (index + PointSize() <= DataSize() );
00253
00254 double * itr = &( (fDataVector->Data()) [ index ]);
00255
00256 for (unsigned int i = 0; i < fDim; ++i)
00257 *itr++ = x[i];
00258
00259 fNPoints++;
00260 }
00261
00262
00263
00264
00265 const double * Coords(unsigned int ipoint) const {
00266 if (fDataVector)
00267 return &( (fDataVector->Data()) [ ipoint*PointSize() ] );
00268 else
00269 return fDataWrapper->Coords(ipoint);
00270 }
00271
00272
00273
00274
00275
00276 void Resize (unsigned int npoints);
00277
00278
00279
00280
00281
00282 unsigned int NPoints() const { return fNPoints; }
00283
00284
00285
00286
00287 unsigned int Size() const { return fNPoints; }
00288
00289
00290
00291
00292 unsigned int NDim() const { return fDim; }
00293
00294 protected:
00295
00296 void SetNPoints(unsigned int n) { fNPoints = n; }
00297
00298 private:
00299
00300 unsigned int fDim;
00301 unsigned int fNPoints;
00302
00303 DataVector * fDataVector;
00304 DataWrapper * fDataWrapper;
00305
00306 };
00307
00308
00309 }
00310
00311 }
00312
00313
00314
00315 #endif