00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_Fit_BinData
00014 #define ROOT_Fit_BinData
00015
00016 #ifndef ROOT_Fit_DataVector
00017 #include "Fit/DataVector.h"
00018 #endif
00019
00020
00021 #ifdef USE_BINPOINT_CLASS
00022
00023 #ifndef ROOT_Fit_BinPoint
00024 #include "Fit/BinPoint.h"
00025 #endif
00026
00027 #endif
00028
00029
00030 namespace ROOT {
00031
00032 namespace Fit {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class BinData : public FitData {
00062
00063 public :
00064
00065 enum ErrorType { kNoError, kValueError, kCoordError, kAsymError };
00066
00067 static unsigned int GetPointSize(ErrorType err, unsigned int dim) {
00068 if (dim == 0 || dim > MaxSize() ) return 0;
00069 if (err == kNoError) return dim + 1;
00070 if (err == kValueError) return dim + 2;
00071 if (err == kCoordError) return 2 * dim + 2 ;
00072 return 2 * dim + 3;
00073 }
00074
00075 ErrorType GetErrorType() const {
00076 if (fPointSize == fDim + 1) return kNoError;
00077 if (fPointSize == fDim + 2) return kValueError;
00078 if (fPointSize == 2 * fDim + 2) return kCoordError;
00079 assert( fPointSize == 2 * fDim + 3 ) ;
00080 return kAsymError;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090 explicit BinData(unsigned int maxpoints = 0, unsigned int dim = 1, ErrorType err = kValueError);
00091
00092
00093
00094
00095 explicit BinData (const DataOptions & opt, unsigned int maxpoints = 0, unsigned int dim = 1, ErrorType err = kValueError);
00096
00097
00098
00099
00100
00101 BinData (const DataOptions & opt, const DataRange & range, unsigned int maxpoints = 0, unsigned int dim = 1, ErrorType err = kValueError );
00102
00103
00104
00105
00106
00107
00108 BinData(unsigned int n, const double * dataX, const double * val, const double * ex , const double * eval );
00109
00110
00111
00112
00113 BinData(unsigned int n, const double * dataX, const double * dataY, const double * val, const double * ex , const double * ey, const double * eval );
00114
00115
00116
00117
00118 BinData(unsigned int n, const double * dataX, const double * dataY, const double * dataZ, const double * val, const double * ex , const double * ey , const double * ez , const double * eval );
00119
00120
00121
00122
00123 BinData(const BinData &);
00124
00125
00126
00127
00128 BinData & operator= (const BinData &);
00129
00130
00131
00132
00133
00134 virtual ~BinData();
00135
00136
00137
00138
00139
00140
00141
00142
00143 void Initialize(unsigned int maxpoints, unsigned int dim = 1, ErrorType err = kValueError );
00144
00145
00146
00147
00148
00149
00150 unsigned int PointSize() const {
00151 return fPointSize;
00152 }
00153
00154
00155
00156
00157
00158 unsigned int DataSize() const {
00159 if (fDataVector) return fDataVector->Size();
00160 return 0;
00161 }
00162
00163
00164
00165
00166 bool HaveCoordErrors() const {
00167 if (fPointSize > fDim +2) return true;
00168 return false;
00169 }
00170
00171
00172
00173
00174 bool HaveAsymErrors() const {
00175 if (fPointSize > 2 * fDim +2) return true;
00176 return false;
00177 }
00178
00179
00180
00181
00182
00183 void Add(double x, double y );
00184
00185
00186
00187
00188
00189 void Add(double x, double y, double ey);
00190
00191
00192
00193
00194
00195 void Add(double x, double y, double ex, double ey);
00196
00197
00198
00199
00200
00201 void Add(double x, double y, double ex, double eyl , double eyh);
00202
00203
00204
00205
00206 void Add(const double *x, double val);
00207
00208
00209
00210
00211 void Add(const double *x, double val, double eval);
00212
00213
00214
00215
00216 void Add(const double *x, double val, const double * ex, double eval);
00217
00218
00219
00220
00221 void Add(const double *x, double val, const double * ex, double elval, double ehval);
00222
00223
00224
00225
00226 const double * Coords(unsigned int ipoint) const {
00227 if (fDataVector)
00228 return &((fDataVector->Data())[ ipoint*fPointSize ] );
00229
00230 return fDataWrapper->Coords(ipoint);
00231 }
00232
00233
00234
00235
00236 double Value(unsigned int ipoint) const {
00237 if (fDataVector)
00238 return (fDataVector->Data())[ ipoint*fPointSize + fDim ];
00239
00240 return fDataWrapper->Value(ipoint);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 double Error(unsigned int ipoint) const {
00250 if (fDataVector) {
00251 ErrorType type = GetErrorType();
00252 if (type == kNoError ) return 1;
00253
00254 double eval = (fDataVector->Data())[ (ipoint+1)*fPointSize - 1];
00255 if (type == kValueError )
00256 return eval != 0 ? 1.0/eval : 0;
00257 else if (type == kAsymError) {
00258 double el = (fDataVector->Data())[ (ipoint+1)*fPointSize - 2];
00259 return 0.5 * (el+eval);
00260 }
00261 return eval;
00262 }
00263
00264 return fDataWrapper->Error(ipoint);
00265 }
00266
00267
00268
00269
00270
00271
00272 double InvError(unsigned int ipoint) const {
00273 if (fDataVector) {
00274
00275 double eval = (fDataVector->Data())[ (ipoint+1)*fPointSize - 1];
00276 return eval;
00277
00278
00279
00280 }
00281
00282
00283 double eval = fDataWrapper->Error(ipoint);
00284 return eval != 0 ? 1.0/eval : 0;
00285 }
00286
00287
00288
00289
00290
00291 const double * CoordErrors(unsigned int ipoint) const {
00292 if (fDataVector) {
00293
00294 return &(fDataVector->Data())[ (ipoint)*fPointSize + fDim + 1];
00295 }
00296
00297 return fDataWrapper->CoordErrors(ipoint);
00298 }
00299
00300
00301
00302
00303
00304 const double * GetPoint(unsigned int ipoint, double & value) const {
00305 if (fDataVector) {
00306 unsigned int j = ipoint*fPointSize;
00307 const std::vector<double> & v = (fDataVector->Data());
00308 const double * x = &v[j];
00309 value = v[j+fDim];
00310 return x;
00311 }
00312 value = fDataWrapper->Value(ipoint);
00313 return fDataWrapper->Coords(ipoint);
00314 }
00315
00316
00317
00318
00319
00320
00321
00322 const double * GetPoint(unsigned int ipoint, double & value, double & invError) const {
00323 if (fDataVector) {
00324 const std::vector<double> & v = (fDataVector->Data());
00325 unsigned int j = ipoint*fPointSize;
00326 const double * x = &v[j];
00327 j += fDim;
00328 value = v[j];
00329 if (fPointSize == fDim +1)
00330 invError = 1;
00331 else if (fPointSize == fDim +2)
00332 invError = v[j+1];
00333 else
00334 assert(0);
00335
00336 return x;
00337 }
00338 value = fDataWrapper->Value(ipoint);
00339 double e = fDataWrapper->Error(ipoint);
00340 invError = ( e > 0 ) ? 1.0/e : 1.0;
00341 return fDataWrapper->Coords(ipoint);
00342 }
00343
00344
00345
00346
00347
00348
00349 const double * GetPointError(unsigned int ipoint, double & errvalue) const {
00350 if (fDataVector) {
00351 assert(fPointSize > fDim + 2);
00352 unsigned int j = ipoint*fPointSize;
00353 const std::vector<double> & v = (fDataVector->Data());
00354 const double * ex = &v[j+fDim+1];
00355 errvalue = v[j + 2*fDim +1];
00356 return ex;
00357 }
00358 errvalue = fDataWrapper->Error(ipoint);
00359 return fDataWrapper->CoordErrors(ipoint);
00360 }
00361
00362
00363
00364
00365
00366
00367
00368 const double * GetPointError(unsigned int ipoint, double & errlow, double & errhigh) const {
00369
00370 assert(fDataVector);
00371
00372 assert(fPointSize > 2 * fDim + 2);
00373 unsigned int j = ipoint*fPointSize;
00374 const std::vector<double> & v = (fDataVector->Data());
00375 const double * ex = &v[j+fDim+1];
00376 errlow = v[j + 2*fDim +1];
00377 errhigh = v[j + 2*fDim +2];
00378 return ex;
00379 }
00380
00381
00382 #ifdef USE_BINPOINT_CLASS
00383 const BinPoint & GetPoint(unsigned int ipoint) const {
00384 if (fDataVector) {
00385 unsigned int j = ipoint*fPointSize;
00386 const std::vector<double> & v = (fDataVector->Data());
00387 const double * x = &v[j];
00388 double value = v[j+fDim];
00389 if (fPointSize > fDim + 2) {
00390 const double * ex = &v[j+fDim+1];
00391 double err = v[j + 2*fDim +1];
00392 fPoint.Set(x,value,ex,err);
00393 }
00394 else {
00395 double invError = v[j+fDim+1];
00396 fPoint.Set(x,value,invError);
00397 }
00398
00399 }
00400 else {
00401 double value = fDataWrapper->Value(ipoint);
00402 double e = fDataWrapper->Error(ipoint);
00403 if (fPointSize > fDim + 2) {
00404 fPoint.Set(fDataWrapper->Coords(ipoint), value, fDataWrapper->CoordErrors(ipoint), e);
00405 } else {
00406 double invError = ( e != 0 ) ? 1.0/e : 0;
00407 fPoint.Set(fDataWrapper->Coords(ipoint), value, invError);
00408 }
00409 }
00410 return fPoint;
00411 }
00412
00413
00414 const BinPoint & GetPointError(unsigned int ipoint) const {
00415 if (fDataVector) {
00416 unsigned int j = ipoint*fPointSize;
00417 const std::vector<double> & v = (fDataVector->Data());
00418 const double * x = &v[j];
00419 double value = v[j+fDim];
00420 double invError = v[j+fDim+1];
00421 fPoint.Set(x,value,invError);
00422 }
00423 else {
00424 double value = fDataWrapper->Value(ipoint);
00425 double e = fDataWrapper->Error(ipoint);
00426 double invError = ( e != 0 ) ? 1.0/e : 0;
00427 fPoint.Set(fDataWrapper->Coords(ipoint), value, invError);
00428 }
00429 return fPoint;
00430 }
00431 #endif
00432
00433
00434
00435
00436
00437 void Resize (unsigned int npoints);
00438
00439
00440
00441
00442 unsigned int NPoints() const { return fNPoints; }
00443
00444
00445
00446
00447 unsigned int Size() const { return fNPoints; }
00448
00449
00450
00451
00452 unsigned int NDim() const { return fDim; }
00453
00454
00455
00456
00457
00458
00459
00460
00461 BinData & LogTransform();
00462
00463
00464
00465
00466
00467
00468
00469 const double * BinUpEdge(unsigned int icoord) const {
00470 if (fBinEdge.size() == 0 || icoord*fDim > fBinEdge.size() ) return 0;
00471 return &fBinEdge[ icoord * fDim];
00472 }
00473
00474
00475
00476
00477 bool HasBinEdges() const {
00478 return fBinEdge.size() > 0 && fBinEdge.size() == fDim*fNPoints;
00479 }
00480
00481
00482
00483
00484
00485
00486
00487 void AddBinUpEdge(const double * xup);
00488
00489
00490
00491
00492 double RefVolume() const { return fRefVolume; }
00493
00494
00495
00496
00497 void SetRefVolume(double value) { fRefVolume = value; }
00498
00499 protected:
00500
00501 void SetNPoints(unsigned int n) { fNPoints = n; }
00502
00503 private:
00504
00505
00506 unsigned int fDim;
00507 unsigned int fPointSize;
00508 unsigned int fNPoints;
00509 double fRefVolume;
00510
00511 DataVector * fDataVector;
00512 DataWrapper * fDataWrapper;
00513
00514 std::vector<double> fBinEdge;
00515
00516
00517 #ifdef USE_BINPOINT_CLASS
00518 mutable BinPoint fPoint;
00519 #endif
00520
00521 };
00522
00523
00524 }
00525
00526 }
00527
00528
00529
00530 #endif
00531
00532