#ifndef ROOT_Fit_UnBinData
#define ROOT_Fit_UnBinData
#ifndef ROOT_Fit_DataVector
#include "Fit/DataVector.h"
#endif
#ifndef ROOT_Math_Error
#include "Math/Error.h"
#endif
namespace ROOT {
namespace Fit {
class UnBinData : public FitData {
public :
explicit UnBinData(unsigned int maxpoints = 0, unsigned int dim = 1, bool isWeighted = false );
explicit UnBinData (const DataRange & range, unsigned int maxpoints = 0, unsigned int dim = 1, bool isWeighted = false);
UnBinData (const DataOptions & opt, const DataRange & range, unsigned int maxpoints = 0, unsigned int dim = 1, bool isWeighted = false );
UnBinData(unsigned int n, const double * dataX );
UnBinData(unsigned int n, const double * dataX, const double * dataY, bool isWeighted = false );
UnBinData(unsigned int n, const double * dataX, const double * dataY, const double * dataZ, bool isWeighted = false );
template<class Iterator>
UnBinData(unsigned int n, unsigned int dim, Iterator dataItr, bool isWeighted = false ) :
FitData( ),
fDim(dim),
fPointSize( (isWeighted) ? dim +1 : dim),
fNPoints(n),
fDataVector(0)
{
fDataWrapper = new DataWrapper(fPointSize, dataItr);
}
UnBinData(unsigned int maxpoints, const double * dataX, const DataRange & range);
UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY, const DataRange & range, bool isWeighted = false);
UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY, const double * dataZ, const DataRange & range, bool isWeighted = false);
template<class Iterator>
UnBinData(unsigned int maxpoints, unsigned int dim, Iterator dataItr, const DataRange & range, bool isWeighted = false ) :
FitData( ),
fDim(dim),
fPointSize( (isWeighted) ? dim +1 : dim),
fNPoints(0),
fDataVector(0),
fDataWrapper(0)
{
unsigned int n = fPointSize*maxpoints;
if ( n > MaxSize() ) {
MATH_ERROR_MSGVAL("UnBinData","Invalid data size n - no allocation done", n );
}
else if (n > 0) {
fDataVector = new DataVector(n);
ROOT::Fit::DataWrapper wdata(fPointSize, dataItr);
for (unsigned int i = 0; i < maxpoints; ++i) {
bool isInside = true;
for (unsigned int icoord = 0; icoord < dim; ++icoord)
isInside &= range.IsInside( wdata.Coords(i)[icoord], icoord );
if ( isInside ) Add(wdata.Coords(i));
}
if (fNPoints < maxpoints) (fDataVector->Data()).resize(fPointSize*fNPoints);
}
}
private:
UnBinData(const UnBinData &) : FitData() {}
UnBinData & operator= (const UnBinData &) { return *this; }
public:
#ifdef LATER
UnBinData (const UnBinData & data , const DataOptions & opt, const DataRange & range) :
DataVector(opt,range, data.DataSize() ),
fDim(data.fDim),
fPointSize(data.fPointSize),
fNPoints(data.fNPoints)
{
}
#endif
virtual ~UnBinData() {
if (fDataVector) delete fDataVector;
if (fDataWrapper) delete fDataWrapper;
}
void Initialize(unsigned int maxpoints, unsigned int dim = 1, bool isWeighted = false);
void Add(double x) {
int index = fNPoints*PointSize();
assert(fDataVector != 0);
assert(PointSize() == 1);
assert (index + PointSize() <= DataSize() );
(fDataVector->Data())[ index ] = x;
fNPoints++;
}
void Add(double x, double y) {
int index = fNPoints*PointSize();
assert(fDataVector != 0);
assert(PointSize() == 2);
assert (index + PointSize() <= DataSize() );
(fDataVector->Data())[ index ] = x;
(fDataVector->Data())[ index+1 ] = y;
fNPoints++;
}
void Add(double x, double y, double z) {
int index = fNPoints*PointSize();
assert(fDataVector != 0);
assert(PointSize() == 3);
assert (index + PointSize() <= DataSize() );
(fDataVector->Data())[ index ] = x;
(fDataVector->Data())[ index+1 ] = y;
(fDataVector->Data())[ index+2 ] = z;
fNPoints++;
}
void Add(const double *x) {
int index = fNPoints*fPointSize;
assert(fDataVector != 0);
assert (index + PointSize() <= DataSize() );
double * itr = &( (fDataVector->Data()) [ index ]);
for (unsigned int i = 0; i < fDim; ++i)
*itr++ = x[i];
fNPoints++;
}
void Add(const double *x, double w) {
int index = fNPoints*fPointSize;
assert(fDataVector != 0);
assert (index + PointSize() <= DataSize() );
double * itr = &( (fDataVector->Data()) [ index ]);
for (unsigned int i = 0; i < fDim; ++i)
*itr++ = x[i];
*itr = w;
fNPoints++;
}
const double * Coords(unsigned int ipoint) const {
if (fDataVector)
return &( (fDataVector->Data()) [ ipoint*fPointSize ] );
else
return fDataWrapper->Coords(ipoint);
}
bool IsWeighted() const {
return (fPointSize == fDim+1);
}
double Weight(unsigned int ipoint) const {
if (fPointSize == fDim) return 1;
if (fDataVector )
return (fDataVector->Data()) [ ipoint*fPointSize + 1 ] ;
else
return 0;
}
void Resize (unsigned int npoints);
unsigned int NPoints() const { return fNPoints; }
unsigned int Size() const { return fNPoints; }
unsigned int NDim() const { return fDim; }
unsigned int PointSize() const {
return fPointSize;
}
unsigned int DataSize() const {
return (fDataVector) ? fDataVector->Size() : 0;
}
protected:
void SetNPoints(unsigned int n) { fNPoints = n; }
private:
unsigned int fDim;
unsigned int fPointSize;
unsigned int fNPoints;
DataVector * fDataVector;
DataWrapper * fDataWrapper;
};
}
}
#endif /* ROOT_Fit_UnBinData */