#ifndef ROOT_Fit_DataVector
#define ROOT_Fit_DataVector
#ifndef ROOT_Fit_DataOptions
#include "Fit/DataOptions.h"
#endif
#ifndef ROOT_Fit_DataRange
#include "Fit/DataRange.h"
#endif
#include <vector>
#include <cassert>
#include <iostream>
namespace ROOT {
namespace Fit {
class FitData {
public:
FitData() {}
virtual ~FitData() {}
FitData(const DataOptions & opt) :
fOptions(opt)
{}
FitData(const DataRange & range) :
fRange(range)
{}
FitData (const DataOptions & opt, const DataRange & range) :
fOptions(opt),
fRange(range)
{}
const DataOptions & Opt() const { return fOptions; }
DataOptions & Opt() { return fOptions; }
const DataRange & Range() const { return fRange; }
static unsigned int MaxSize() {
return (unsigned int) (-1) / sizeof (double);
}
private:
DataOptions fOptions;
DataRange fRange;
};
class DataVector {
public:
typedef std::vector<double> FData;
explicit DataVector (size_t n ) :
fData(std::vector<double>(n))
{
}
~DataVector () {}
const FData & Data() const { return fData; }
FData & Data() { return fData; }
#ifndef __CINT__
typedef FData::const_iterator const_iterator;
typedef FData::iterator iterator;
const_iterator begin() const { return fData.begin(); }
const_iterator end() const { return fData.begin()+fData.size(); }
iterator begin() { return fData.begin(); }
iterator end() { return fData.end(); }
#endif
const double & operator[] (unsigned int i) const { return fData[i]; }
double & operator[] (unsigned int i) { return fData[i]; }
size_t Size() const { return fData.size(); }
private:
FData fData;
};
class DataWrapper {
public:
explicit DataWrapper(const double * dataX ) :
fDim(1),
fValues(0),
fErrors(0),
fCoords(std::vector<const double * >(1) ),
fX(std::vector<double>(1) )
{
fCoords[0] = dataX;
}
DataWrapper(const double * dataX, const double * val, const double * eval , const double * ex ) :
fDim(1),
fValues(val),
fErrors(eval),
fCoords(std::vector<const double * >(1) ),
fErrCoords(std::vector<const double * >(1) ),
fX(std::vector<double>(1) ),
fErr(std::vector<double>(1) )
{
fCoords[0] = dataX;
fErrCoords[0] = ex;
}
DataWrapper(const double * dataX, const double * dataY, const double * val, const double * eval, const double * ex , const double * ey ) :
fDim(2),
fValues(val),
fErrors(eval),
fCoords(std::vector<const double * >(2) ),
fErrCoords(std::vector<const double * >(2) ),
fX(std::vector<double>(2) ),
fErr(std::vector<double>(2) )
{
fCoords[0] = dataX;
fCoords[1] = dataY;
fErrCoords[0] = ex;
fErrCoords[1] = ey;
}
DataWrapper(const double * dataX, const double * dataY, const double * dataZ, const double * val, const double * eval, const double * ex , const double * ey, const double * ez ) :
fDim(3),
fValues(val),
fErrors(eval),
fCoords(std::vector<const double * >(3) ),
fErrCoords(std::vector<const double * >(3) ),
fX(std::vector<double>(3) ),
fErr(std::vector<double>(3) )
{
fCoords[0] = dataX;
fCoords[1] = dataY;
fCoords[2] = dataZ;
fErrCoords[0] = ex;
fErrCoords[1] = ey;
fErrCoords[2] = ez;
}
template<class Iterator>
DataWrapper(unsigned int dim, Iterator coordItr ) :
fDim(dim),
fValues(0),
fErrors(0),
fCoords(std::vector<const double * >(coordItr, coordItr+dim) ),
fX(std::vector<double>(dim) )
{ }
template<class Iterator>
DataWrapper(size_t dim, Iterator coordItr, const double * val, const double * eval, Iterator errItr ) :
fDim(dim),
fValues(val),
fErrors(eval),
fCoords(std::vector<const double * >(coordItr, coordItr+dim) ),
fErrCoords(std::vector<const double * >(errItr, errItr+dim) ),
fX(std::vector<double>(dim) ),
fErr(std::vector<double>(dim) )
{ }
~DataWrapper() {
}
const double * Coords(unsigned int ipoint) const {
for (unsigned int i = 0; i < fDim; ++i) {
const double * x = fCoords[i];
assert (x != 0);
fX[i] = x[ipoint];
}
return &fX.front();
}
double Coord(unsigned int ipoint, unsigned int icoord) const {
const double * x = fCoords[icoord];
assert (x != 0);
return x[ipoint];
}
const double * CoordErrors(unsigned int ipoint) const {
for (unsigned int i = 0; i < fDim; ++i) {
const double * err = fErrCoords[i];
if (err == 0) return 0;
fErr[i] = err[ipoint];
}
return &fErr.front();
}
double CoordError(unsigned int ipoint, unsigned int icoord) const {
const double * err = fErrCoords[icoord];
return (err != 0) ? err[ipoint] : 0;
}
double Value(unsigned int ipoint) const {
return fValues[ipoint];
}
double Error(unsigned int ipoint) const {
return (fErrors) ? fErrors[ipoint] : 0. ;
}
private:
unsigned int fDim;
const double * fValues;
const double * fErrors;
std::vector<const double *> fCoords;
std::vector<const double *> fErrCoords;
mutable std::vector<double> fX;
mutable std::vector<double> fErr;
};
}
}
#endif /* ROOT_Fit_DataVector */