|
YODA - Yet more Objects for Data Analysis 2.0.2
|
Go to the documentation of this file.
40 virtual size_t dim() const = 0;
43 virtual double val( size_t i) const = 0;
46 virtual void setVal( const size_t i, const double val) = 0;
57 virtual void setErr( const size_t i, const double e) = 0;
60 virtual void setErrs( const size_t i, const double eminus, const double eplus) = 0;
63 virtual void setErrs( const size_t i, const std::pair<double,double>& e) = 0;
68 virtual void setErrMinus( const size_t i, const double eminus) = 0;
73 virtual void setErrPlus( const size_t i, const double eplus) = 0;
90 virtual void set( const size_t i, const double val, const double e) = 0;
93 virtual void set( const size_t i, const double val, const double eminus, const double eplus) = 0;
96 virtual void set( const size_t i, const double val, const std::pair<double,double>& e) = 0;
124 using Pair = std::pair<double,double>;
125 using ValList = std::initializer_list<double>;
129 template< typename Arr>
133 template< typename Arr>
141 template< typename T, typename U>
147 using NdVal = typename Utils::ndarray<double, N>;
148 using NdValPair = typename Utils::ndarray<std::pair<double,double>, N>;
149 using DataSize = std::integral_constant<size_t, 3*N>;
162 template < typename ValRange = ValList, typename = isIterable<ValRange>>
167 template < typename ValRange = ValList,
169 typename = isIterableWithPair<ValRange,PairRange>>
171 : _val(std::forward<ValRange>( val)), _errs(std::forward<PairRange>( errs)) { }
174 template < typename ValRange = ValList, typename = isIterable<ValRange>>
176 : _val(std::forward<ValRange>( val)) {
177 if ( val.size() != N || errs.size() != N)
178 throw RangeError( "Expected " + std::to_string(N) + " dimensions.");
180 auto it = std::begin( errs);
181 const auto& itEnd = std::end( errs);
182 for (; it != itEnd; ++it) {
183 _errs[i++] = std::make_pair(*it, *it);
189 template < typename ValRange = ValList, typename = isIterable<ValRange>>
191 : _val(std::forward<ValRange>( val)) {
192 if ( val.size() != N || errsdn.size() != N || errsup.size() != N)
193 throw RangeError( "Expected " + std::to_string(N) + " dimensions.");
195 auto itdn = std::begin(errsdn);
196 auto itup = std::begin(errsup);
197 const auto& itEnd = std::end(errsdn);
198 for (; itdn != itEnd; ) {
199 _errs[i++] = std::make_pair(*itdn++, *itup++);
210 size_t dim() const { return N; }
215 void _renderYODA(std::ostream& os, const int width = 13) const noexcept {
217 for ( size_t i = 0; i < N; ++i) {
218 os << std::setw(width) << std::left << _val[i] << "\t"
219 << std::setw(width) << std::left << _errs[i].first << "\t"
220 << std::setw(width) << std::left << _errs[i].second << "\t";
233 for ( size_t i = 0; i < N; ++i) {
251 _val = std::move(p._val);
252 _errs = std::move(p._errs);
274 double val( size_t i) const {
275 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
286 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
308 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
314 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
315 return _errs[i].first;
320 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
321 return _errs[i].second;
330 double min( const size_t i) const {
331 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
332 return _val[i] - _errs[i].first;
336 double max( const size_t i) const {
337 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
338 return _val[i] + _errs[i].second;
342 void setErr( const size_t i, const double e) {
343 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
344 const double err = fabs(e);
345 _errs[i] = { err, err};
349 void setErrs( const size_t i, const double eminus, const double eplus) {
350 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
351 _errs[i] = { eminus, eplus};
355 void setErrs( const size_t i, const std::pair<double,double>& e) {
356 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
362 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
363 _errs[i].first = eminus;
368 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
369 _errs[i].second = eplus;
377 void set( const size_t i, const double val, const double e) {
378 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
379 const double err = fabs(e);
381 _errs[i] = {err,err};
384 void set( const size_t i, const double val, const double eminus, const double eplus) {
385 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
387 _errs[i].first = eminus;
388 _errs[i].second = eplus;
391 void set( const size_t i, const double val, const std::pair<double,double>& e) {
392 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
404 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
410 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
411 _errs[i].first *= scale;
412 _errs[i].second *= scale;
423 for ( size_t i = 0; i < N; ++i) {
436 if (i >= N) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
449 std::vector<double> _serializeContent() const noexcept {
450 std::vector<double> rtn;
451 rtn.reserve(DataSize::value);
452 rtn.insert(rtn.end(), _val.begin(), _val.end());
453 for ( auto err : _errs) {
454 rtn.push_back(std::move(err.first));
455 rtn.push_back(std::move(err.second));
460 void _deserializeContent( const std::vector<double>& data) {
462 if (data.size() != DataSize::value)
463 throw UserError( "Length of serialized data should be "+std::to_string(DataSize::value)+ "!");
465 for ( size_t i = 0; i < N; ++i) {
467 _errs[i] = { data[N+i], data[2*N+i] };
495 for ( size_t i = 0; i < N; ++i) {
513 #define LT_IF_NOT_EQ(a,b) { if (!fuzzyEquals(a, b)) return a < b; }
514 for ( size_t i = 0; i < N; ++i) {
526 if (a == b) return true;
566 : BaseT({x}, {{ex, ex}}) { }
570 PointND( double x, double exminus, double explus)
571 : BaseT({x}, {{exminus, explus}}) { }
575 PointND( double x, const std::pair<double,double>& ex)
576 : BaseT( {x}, {ex}) { }
592 double val( size_t i=0) const {
593 if (i >= 1) throw RangeError( "Invalid axis int, must be in range 0..dim-1");
617 PointND( double x, double y, double ex=0.0, double ey=0.0)
618 : BaseT( {x,y}, {{ex,ex}, {ey,ey}}) { }
623 double exminus, double explus,
624 double eyminus, double eyplus)
625 : BaseT({x,y}, {{exminus,explus}, {eyminus,eyplus}}) { }
629 PointND( double x, double y, const std::pair<double,double>& ex, const std::pair<double,double>& ey)
630 : BaseT({x,y}, {ex, ey}) { }
672 PointND( double x, double y, double z, double ex=0.0, double ey=0.0, double ez=0.0)
673 : BaseT({x,y,z}, {{ex,ex}, {ey,ey}, {ez,ez}}) { }
678 double exminus, double explus,
679 double eyminus, double eyplus,
680 double ezminus, double ezplus)
681 : BaseT({x,y,z}, {{exminus,explus}, {eyminus,eyplus}, {ezminus,ezplus}}) { }
685 const std::pair<double,double>& ex,
686 const std::pair<double,double>& ey,
687 const std::pair<double,double>& ez)
688 : BaseT({x,y,z}, {ex,ey,ez}) { }
703 void scaleXYZ( double scalex, double scaley, double scalez) {
#define LT_IF_NOT_EQ(a, b)
The base for an N-dimensional data point to be contained in a Scatter<N>
PointBase(ValRange &&val, PairRange &&errs) Constructor from values and a set of asymmetric errors.
double val(size_t i) const Get the value along direction i.
void scale(const size_t i, const Trf< N > &trf)
typename std::is_same< containedType< Arr >, Pair > containsPair
void scale(const Trf< N > &trf) Generalised transformations with functors.
std::enable_if_t<(Iterable< T >::value &&Iterable< U >::value &&containsPair< U >::value)> isIterableWithPair
void setErr(const size_t i, const double e) Set a symmetric error pair along axis i.
void setErrs(const size_t i, const std::pair< double, double > &e) Set a specific error pair along axis i.
PointBase & operator=(const PointBase &p) Assignment operator.
PointBase(ValRange &&val) Constructor from position values without errors.
NdValPair & errs() Get error values.
double errMinus(const size_t i) const Get the minus error along axis i.
size_t dim() const Space dimension of the point.
std::pair< double, double > Pair
std::decay_t< decltype(*std::declval< Arr >().begin())> containedType
typename Utils::ndarray< double, N > NdVal
void setVal(const NdVal &val) Set the coordinate vector.
void setVal(const size_t i, const double val) Set a specific coordinate.
double errPlus(const size_t i) const Get the plus error along axis i.
std::integral_constant< size_t, 3 *N > DataSize
void set(const size_t i, const double val, const std::pair< double, double > &e) Set value and asymmetric error for direction i.
std::initializer_list< double > ValList
void scaleErr(const size_t i, const double scale) Scaling error along direction i.
void set(const size_t i, const double val, const double e) Set value and symmetric error for direction i.
std::initializer_list< Pair > PairList
PointBase(ValRange &&val, ValRange &&errs) Constructor from values and a set of symmetric errors.
const NdValPair & errs() const Get error values (const version)
PointBase(const PointBase &p)
double errAvg(const size_t i) const
void setErrMinus(const size_t i, const double eminus) Set a specific minus error along axis i.
std::enable_if_t< Iterable< T >::value > isIterable
void setErrs(const size_t i, const double eminus, const double eplus) Set an asymmetric error pair along axis i.
NdVal & vals() Get the coordinate vector.
void set(const size_t i, const double val, const double eminus, const double eplus) Set value and asymmetric error for direction i.
void transform(const size_t i, const Trf< N > &trf)
void scale(const NdVal &scales) Uniform scaling.
void setErrPlus(const size_t i, const double eplus) Set a specific plus error along axis i.
typename Utils::ndarray< std::pair< double, double >, N > NdValPair
Pair errs(const size_t i) const Get error values along axis i.
const NdVal & vals() const Get the coordinate vector (const version)
double min(const size_t i) const Get value minus negative error along axis i.
void scale(const size_t i, const double scale) Scaling along direction i.
void scaleVal(const size_t i, const double scale) Scaling value along direction i.
PointBase(ValRange &&val, ValRange &&errsdn, ValRange &&errsup) Constructor from values and a set of asymmetric errors.
double max(const size_t i) const Get value plus positive error along axis i.
void clear() Clear the point values and errors.
A 1D data point to be contained in a Scatter1D.
PointND(BaseT &&other) Move constructor.
PointND(double x, double ex=0.0) Constructor from values with optional symmetric errors.
PointND(double x, double exminus, double explus) Constructor from values with explicit asymmetric errors.
PointND(double x, const std::pair< double, double > &ex) Constructor from values with asymmetric errors.
double val(size_t i=0) const Get the value along direction i.
PointND(const BaseT &other) Copy constructor.
A 2D data point to be contained in a Scatter2D.
PointND(double x, double y, const std::pair< double, double > &ex, const std::pair< double, double > &ey) Constructor from values with asymmetric errors on both x and y.
PointND(double x, double y, double exminus, double explus, double eyminus, double eyplus) Constructor from values with explicit asymmetric errors.
PointND(const BaseT &other) Copy constructor.
PointND(BaseT &&other) Move constructor.
void scaleXY(double scalex, double scaley) Scaling of both axes.
PointND(double x, double y, double ex=0.0, double ey=0.0) Constructor from values with optional symmetric errors.
A 3D data point to be contained in a Scatter3D.
PointND(BaseT &&other) Move constructor.
PointND(double x, double y, double z, double exminus, double explus, double eyminus, double eyplus, double ezminus, double ezplus) Constructor from values with explicit asymmetric errors.
PointND(const BaseT &other) Copy constructor.
PointND(double x, double y, double z, double ex=0.0, double ey=0.0, double ez=0.0) Constructor from values with optional symmetric errors.
PointND(double x, double y, double z, const std::pair< double, double > &ex, const std::pair< double, double > &ey, const std::pair< double, double > &ez) Constructor from asymmetric errors given as vectors.
void scaleXYZ(double scalex, double scaley, double scalez) Scaling of both axes.
Base class for all Point*Ds, providing generic access to their numerical properties.
virtual void setErrMinus(const size_t i, const double eminus)=0 Get negative error value for direction i.
virtual void set(const size_t i, const double val, const double e)=0 Set value and symmetric error for direction i.
virtual void setErrs(const size_t i, const std::pair< double, double > &e)=0 Set error pair for direction i.
virtual void scale(const size_t i, const double scale)=0
virtual void setErrPlus(const size_t i, const double eplus)=0 Get positive error value for direction i.
std::pair< double, double > ValuePair
virtual void setVal(const size_t i, const double val)=0 Set the point value for direction i.
virtual void setErr(const size_t i, const double e)=0 Get error values for direction i.
virtual void set(const size_t i, const double val, const double eminus, const double eplus)=0 Set value and asymmetric error for direction i.
virtual void set(const size_t i, const double val, const std::pair< double, double > &e)=0 Set value and asymmetric error for direction i.
virtual void setErrs(const size_t i, const double eminus, const double eplus)=0 Set asymmetric error for direction i.
virtual ~Point() Virtual destructor for inheritance.
virtual double val(size_t i) const =0 Get the point value for direction i.
virtual size_t dim() const =0 Space dimension of the point.
Error for e.g. use of invalid bin ranges.
Anonymous namespace to limit visibility.
bool operator<=(const PointBase< N > &a, const PointBase< N > &b) Less-than-or-equals operator used to sort points.
bool operator>=(const PointBase< N > &a, const PointBase< N > &b) Greater-than-or-equals operator used to sort points.
bool operator<(const PointBase< N > &a, const PointBase< N > &b) Less-than operator used to sort points.
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 > &&(std::is_floating_point_v< N1 >||std::is_floating_point_v< N2 >), bool > fuzzyEquals(N1 a, N2 b, double tolerance=1e-5) Compare two numbers for equality with a degree of fuzziness.
bool operator>(const PointBase< N > &a, const PointBase< N > &b) Greater-than operator used to sort points.
bool operator==(const PointBase< N > &a, const PointBase< N > &b) Equality test.
bool operator!=(const PointBase< N > &a, const PointBase< N > &b) Inequality test.
CRTP mixin introducing convenience aliases along X axis.
CRTP mixin introducing convenience aliases along Y axis.
CRTP mixin introducing convenience aliases along Z axis.
|