#ifndef ROOT_Fit_BinData
#define ROOT_Fit_BinData
#ifndef ROOT_Fit_DataVector
#include "Fit/DataVector.h"
#endif
#ifdef USE_BINPOINT_CLASS
#ifndef ROOT_Fit_BinPoint
#include "Fit/BinPoint.h"
#endif
#endif
namespace ROOT {
namespace Fit {
class BinData : public FitData {
public :
enum ErrorType { kNoError, kValueError, kCoordError, kAsymError };
static unsigned int GetPointSize(ErrorType err, unsigned int dim) {
if (err == kNoError) return dim + 1;
if (err == kValueError) return dim + 2;
if (err == kCoordError) return 2 * dim + 2 ;
return 2 * dim + 3;
}
ErrorType GetErrorType() const {
if (fPointSize == fDim + 1) return kNoError;
if (fPointSize == fDim + 2) return kValueError;
if (fPointSize == 2 * fDim + 2) return kCoordError;
assert( fPointSize == 2 * fDim + 3 ) ;
return kAsymError;
}
explicit BinData(unsigned int maxpoints = 0, unsigned int dim = 1, ErrorType err = kValueError);
explicit BinData (const DataOptions & opt, unsigned int maxpoints = 0, unsigned int dim = 1, ErrorType err = kValueError);
BinData (const DataOptions & opt, const DataRange & range, unsigned int maxpoints = 0, unsigned int dim = 1, ErrorType err = kValueError );
BinData(unsigned int n, const double * dataX, const double * val, const double * ex , const double * eval );
BinData(unsigned int n, const double * dataX, const double * dataY, const double * val, const double * ex , const double * ey, const double * eval );
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 );
BinData(const BinData &);
BinData & operator= (const BinData &);
virtual ~BinData();
void Initialize(unsigned int maxpoints, unsigned int dim = 1, ErrorType err = kValueError );
unsigned int PointSize() const {
return fPointSize;
}
unsigned int DataSize() const {
if (fDataVector) return fDataVector->Size();
return 0;
}
bool HaveCoordErrors() const {
if (fPointSize > fDim +2) return true;
return false;
}
bool HaveAsymErrors() const {
if (fPointSize > 2 * fDim +2) return true;
return false;
}
void Add(double x, double y );
void Add(double x, double y, double ey);
void Add(double x, double y, double ex, double ey);
void Add(double x, double y, double ex, double eyl , double eyh);
void Add(const double *x, double val);
void Add(const double *x, double val, double eval);
void Add(const double *x, double val, const double * ex, double eval);
const double * Coords(unsigned int ipoint) const {
if (fDataVector)
return &((fDataVector->Data())[ ipoint*fPointSize ] );
return fDataWrapper->Coords(ipoint);
}
double Value(unsigned int ipoint) const {
if (fDataVector)
return (fDataVector->Data())[ ipoint*fPointSize + fDim ];
return fDataWrapper->Value(ipoint);
}
double Error(unsigned int ipoint) const {
if (fDataVector) {
ErrorType type = GetErrorType();
if (type == kNoError ) return 1;
double eval = (fDataVector->Data())[ (ipoint+1)*fPointSize - 1];
if (type == kValueError )
return eval != 0 ? 1.0/eval : 0;
else if (type == kAsymError) {
double el = (fDataVector->Data())[ (ipoint+1)*fPointSize - 2];
return 0.5 * (el+eval);
}
return eval;
}
return fDataWrapper->Error(ipoint);
}
double InvError(unsigned int ipoint) const {
if (fDataVector) {
double eval = (fDataVector->Data())[ (ipoint+1)*fPointSize - 1];
return eval;
}
double eval = fDataWrapper->Error(ipoint);
return eval != 0 ? 1.0/eval : 0;
}
const double * CoordErrors(unsigned int ipoint) const {
if (fDataVector) {
return &(fDataVector->Data())[ (ipoint)*fPointSize + fDim + 1];
}
return fDataWrapper->CoordErrors(ipoint);
}
const double * GetPoint(unsigned int ipoint, double & value) const {
if (fDataVector) {
unsigned int j = ipoint*fPointSize;
const std::vector<double> & v = (fDataVector->Data());
const double * x = &v[j];
value = v[j+fDim];
return x;
}
value = fDataWrapper->Value(ipoint);
return fDataWrapper->Coords(ipoint);
}
const double * GetPoint(unsigned int ipoint, double & value, double & invError) const {
if (fDataVector) {
const std::vector<double> & v = (fDataVector->Data());
unsigned int j = ipoint*fPointSize;
const double * x = &v[j];
j += fDim;
value = v[j];
if (fPointSize == fDim +1)
invError = 1;
else if (fPointSize == fDim +2)
invError = v[j+1];
else
assert(0);
return x;
}
value = fDataWrapper->Value(ipoint);
double e = fDataWrapper->Error(ipoint);
invError = ( e > 0 ) ? 1.0/e : 1.0;
return fDataWrapper->Coords(ipoint);
}
const double * GetPointError(unsigned int ipoint, double & errvalue) const {
if (fDataVector) {
assert(fPointSize > fDim + 2);
unsigned int j = ipoint*fPointSize;
const std::vector<double> & v = (fDataVector->Data());
const double * ex = &v[j+fDim+1];
errvalue = v[j + 2*fDim +1];
return ex;
}
errvalue = fDataWrapper->Error(ipoint);
return fDataWrapper->CoordErrors(ipoint);
}
const double * GetPointError(unsigned int ipoint, double & errlow, double & errhigh) const {
assert(fDataVector);
assert(fPointSize > 2 * fDim + 2);
unsigned int j = ipoint*fPointSize;
const std::vector<double> & v = (fDataVector->Data());
const double * ex = &v[j+fDim+1];
errlow = v[j + 2*fDim +1];
errhigh = v[j + 2*fDim +2];
return ex;
}
#ifdef USE_BINPOINT_CLASS
const BinPoint & GetPoint(unsigned int ipoint) const {
if (fDataVector) {
unsigned int j = ipoint*fPointSize;
const std::vector<double> & v = (fDataVector->Data());
const double * x = &v[j];
double value = v[j+fDim];
if (fPointSize > fDim + 2) {
const double * ex = &v[j+fDim+1];
double err = v[j + 2*fDim +1];
fPoint.Set(x,value,ex,err);
}
else {
double invError = v[j+fDim+1];
fPoint.Set(x,value,invError);
}
}
else {
double value = fDataWrapper->Value(ipoint);
double e = fDataWrapper->Error(ipoint);
if (fPointSize > fDim + 2) {
fPoint.Set(fDataWrapper->Coords(ipoint), value, fDataWrapper->CoordErrors(ipoint), e);
} else {
double invError = ( e != 0 ) ? 1.0/e : 0;
fPoint.Set(fDataWrapper->Coords(ipoint), value, invError);
}
}
return fPoint;
}
const BinPoint & GetPointError(unsigned int ipoint) const {
if (fDataVector) {
unsigned int j = ipoint*fPointSize;
const std::vector<double> & v = (fDataVector->Data());
const double * x = &v[j];
double value = v[j+fDim];
double invError = v[j+fDim+1];
fPoint.Set(x,value,invError);
}
else {
double value = fDataWrapper->Value(ipoint);
double e = fDataWrapper->Error(ipoint);
double invError = ( e != 0 ) ? 1.0/e : 0;
fPoint.Set(fDataWrapper->Coords(ipoint), value, invError);
}
return fPoint;
}
#endif
void Resize (unsigned int npoints) {
fNPoints = npoints;
(fDataVector->Data()).resize(PointSize() *npoints);
}
unsigned int NPoints() const { return fNPoints; }
unsigned int Size() const {
return (Opt().fIntegral && fNPoints > 0) ? fNPoints-1 : fNPoints;
}
unsigned int NDim() const { return fDim; }
BinData & LogTransform();
protected:
void SetNPoints(unsigned int n) { fNPoints = n; }
private:
unsigned int fDim;
unsigned int fPointSize;
unsigned int fNPoints;
DataVector * fDataVector;
DataWrapper * fDataWrapper;
#ifdef USE_BINPOINT_CLASS
mutable BinPoint fPoint;
#endif
};
}
}
#endif /* ROOT_Fit_BinData */
Last change: Mon Oct 20 13:14:36 2008
Last generated: 2008-10-20 13:14
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.