yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
YODA::PointBase< N > Class Template Reference

The base for an N-dimensional data point to be contained in a Scatter<N> More...

#include <Point.h>

Inheritance diagram for YODA::PointBase< N >:
YODA::Point YODA::PointND< N >

Public Types

using NdVal = typename Utils::ndarray< double, N >
 
using NdValPair = typename Utils::ndarray< std::pair< double, double >, N >
 
using DataSize = std::integral_constant< size_t, 3 *N >
 
- Public Types inherited from YODA::Point
using ValuePair = std::pair< double, double >
 

Public Member Functions

size_t dim () const
 Space dimension of the point.
 
Constructors
 PointBase ()
 
template<typename ValRange = ValList, typename = isIterable<ValRange>>
 PointBase (ValRange &&val)
 Constructor from position values without errors.
 
template<typename ValRange = ValList, typename PairRange = PairList, typename = isIterableWithPair<ValRange,PairRange>>
 PointBase (ValRange &&val, PairRange &&errs)
 Constructor from values and a set of asymmetric errors.
 
template<typename ValRange = ValList, typename = isIterable<ValRange>>
 PointBase (ValRange &&val, ValRange &&errs)
 Constructor from values and a set of symmetric errors.
 
template<typename ValRange = ValList, typename = isIterable<ValRange>>
 PointBase (ValRange &&val, ValRange &&errsdn, ValRange &&errsup)
 Constructor from values and a set of asymmetric errors.
 
 PointBase (const PointBase &p)
 
 PointBase (PointBase &&p)
 
Modifiers
void clear ()
 Clear the point values and errors.
 
PointBaseoperator= (const PointBase &p)
 Assignment operator.
 
PointBaseoperator= (PointBase &&p)
 Assignment operator.
 
Coordinate accessors
Todo:
addError, addErrors, setErrors
NdValvals ()
 Get the coordinate vector.
 
const NdValvals () const
 Get the coordinate vector (const version)
 
double val (size_t i) const
 Get the value along direction i.
 
void setVal (const NdVal &val)
 Set the coordinate vector.
 
void setVal (const size_t i, const double val)
 Set a specific coordinate.
 
Error accessors
NdValPairerrs ()
 Get error values.
 
const NdValPairerrs () const
 Get error values (const version)
 
Pair errs (const size_t i) const
 Get error values along axis i.
 
double errMinus (const size_t i) const
 Get the minus error along axis i.
 
double errPlus (const size_t i) const
 Get the plus error along axis i.
 
double errAvg (const size_t i) const
 
double min (const size_t i) const
 Get value minus negative error along axis i.
 
double max (const size_t i) const
 Get value plus positive error along axis i.
 
void setErr (const size_t i, const double e)
 Set a symmetric error pair along axis i.
 
void setErrs (const size_t i, const double eminus, const double eplus)
 Set an asymmetric 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.
 
void setErrMinus (const size_t i, const double eminus)
 Set a specific minus error along axis i.
 
void setErrPlus (const size_t i, const double eplus)
 Set a specific plus error along axis i.
 
Combined value and error setters
void set (const size_t i, const double val, const double e)
 Set value and symmetric error for direction i.
 
void set (const size_t i, const double val, const double eminus, const double eplus)
 Set value and asymmetric error for direction i.
 
void set (const size_t i, const double val, const std::pair< double, double > &e)
 Set value and asymmetric error for direction i.
 
Scaling and transformations
void scale (const size_t i, const double scale)
 Scaling along direction i.
 
void scale (const NdVal &scales)
 Uniform scaling.
 
void scale (const Trf< N > &trf)
 Generalised transformations with functors.
 
void scale (const size_t i, const Trf< N > &trf)
 
void transform (const size_t i, const Trf< N > &trf)
 
- Public Member Functions inherited from YODA::Point
virtual ~Point ()
 Virtual destructor for inheritance.
 

Protected Types

using Pair = std::pair< double, double >
 
using ValList = std::initializer_list< double >
 
using PairList = std::initializer_list< Pair >
 
template<typename Arr >
using containedType = std::decay_t< decltype(*std::declval< Arr >().begin())>
 
template<typename Arr >
using containsPair = typename std::is_same< containedType< Arr >, Pair >
 
template<typename T >
using isIterable = std::enable_if_t< Iterable< T >::value >
 
template<typename T , typename U >
using isIterableWithPair = std::enable_if_t<(Iterable< T >::value &&Iterable< U >::value &&containsPair< U >::value)>
 

Detailed Description

template<size_t N>
class YODA::PointBase< N >

The base for an N-dimensional data point to be contained in a Scatter<N>

Definition at line 120 of file Point.h.

Member Typedef Documentation

◆ containedType

template<size_t N>
template<typename Arr >
using YODA::PointBase< N >::containedType = std::decay_t<decltype(*std::declval<Arr>().begin())>
protected

Definition at line 130 of file Point.h.

◆ containsPair

template<size_t N>
template<typename Arr >
using YODA::PointBase< N >::containsPair = typename std::is_same<containedType<Arr>, Pair>
protected

Definition at line 134 of file Point.h.

◆ DataSize

template<size_t N>
using YODA::PointBase< N >::DataSize = std::integral_constant<size_t, 3*N>

Definition at line 149 of file Point.h.

◆ isIterable

template<size_t N>
template<typename T >
using YODA::PointBase< N >::isIterable = std::enable_if_t<Iterable<T>::value>
protected

Definition at line 138 of file Point.h.

◆ isIterableWithPair

template<size_t N>
template<typename T , typename U >
using YODA::PointBase< N >::isIterableWithPair = std::enable_if_t<(Iterable<T>::value && Iterable<U>::value && containsPair<U>::value)>
protected

Definition at line 142 of file Point.h.

◆ NdVal

template<size_t N>
using YODA::PointBase< N >::NdVal = typename Utils::ndarray<double, N>

Definition at line 147 of file Point.h.

◆ NdValPair

template<size_t N>
using YODA::PointBase< N >::NdValPair = typename Utils::ndarray<std::pair<double,double>, N>

Definition at line 148 of file Point.h.

◆ Pair

template<size_t N>
using YODA::PointBase< N >::Pair = std::pair<double,double>
protected

Definition at line 124 of file Point.h.

◆ PairList

template<size_t N>
using YODA::PointBase< N >::PairList = std::initializer_list<Pair>
protected

Definition at line 126 of file Point.h.

◆ ValList

template<size_t N>
using YODA::PointBase< N >::ValList = std::initializer_list<double>
protected

Definition at line 125 of file Point.h.

Constructor & Destructor Documentation

◆ PointBase() [1/7]

template<size_t N>
YODA::PointBase< N >::PointBase ( )
inline

Definition at line 156 of file Point.h.

156 {
157 clear();
158 }
void clear()
Clear the point values and errors.
Definition Point.h:232

References YODA::PointBase< N >::clear().

◆ PointBase() [2/7]

template<size_t N>
template<typename ValRange = ValList, typename = isIterable<ValRange>>
YODA::PointBase< N >::PointBase ( ValRange &&  val)
inline

Constructor from position values without errors.

Definition at line 163 of file Point.h.

163: _val(std::forward<ValRange>(val)) { }
double val(size_t i) const
Get the value along direction i.
Definition Point.h:274

◆ PointBase() [3/7]

template<size_t N>
template<typename ValRange = ValList, typename PairRange = PairList, typename = isIterableWithPair<ValRange,PairRange>>
YODA::PointBase< N >::PointBase ( ValRange &&  val,
PairRange &&  errs 
)
inline

Constructor from values and a set of asymmetric errors.

Definition at line 170 of file Point.h.

171 : _val(std::forward<ValRange>(val)), _errs(std::forward<PairRange>(errs)) { }
NdValPair & errs()
Get error values.
Definition Point.h:297

◆ PointBase() [4/7]

template<size_t N>
template<typename ValRange = ValList, typename = isIterable<ValRange>>
YODA::PointBase< N >::PointBase ( ValRange &&  val,
ValRange &&  errs 
)
inline

Constructor from values and a set of symmetric errors.

Definition at line 175 of file Point.h.

176 : _val(std::forward<ValRange>(val)) {
177 if (val.size() != N || errs.size() != N)
178 throw RangeError("Expected " + std::to_string(N) + " dimensions.");
179 size_t i = 0;
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);
184 }
185 }

References YODA::PointBase< N >::errs(), and YODA::PointBase< N >::val().

◆ PointBase() [5/7]

template<size_t N>
template<typename ValRange = ValList, typename = isIterable<ValRange>>
YODA::PointBase< N >::PointBase ( ValRange &&  val,
ValRange &&  errsdn,
ValRange &&  errsup 
)
inline

Constructor from values and a set of asymmetric errors.

Definition at line 190 of file Point.h.

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.");
194 size_t i = 0;
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++);
200 }
201 }

References YODA::PointBase< N >::val().

◆ PointBase() [6/7]

template<size_t N>
YODA::PointBase< N >::PointBase ( const PointBase< N > &  p)
inline

Definition at line 203 of file Point.h.

203: _val(p._val), _errs(p._errs) { }

◆ PointBase() [7/7]

template<size_t N>
YODA::PointBase< N >::PointBase ( PointBase< N > &&  p)
inline

Definition at line 205 of file Point.h.

205: _val(std::move(p._val)), _errs(std::move(p._errs)) { }

Member Function Documentation

◆ clear()

template<size_t N>
void YODA::PointBase< N >::clear ( )
inline

Clear the point values and errors.

Definition at line 232 of file Point.h.

232 {
233 for (size_t i = 0; i < N; ++i) {
234 _val[i] = 0;
235 _errs[i] = {0.,0.};
236 }
237 }

Referenced by YODA::PointBase< N >::PointBase().

◆ dim()

template<size_t N>
size_t YODA::PointBase< N >::dim ( ) const
inlinevirtual

Space dimension of the point.

Implements YODA::Point.

Definition at line 210 of file Point.h.

210{ return N; }

◆ errAvg()

template<size_t N>
double YODA::PointBase< N >::errAvg ( const size_t  i) const
inline

Definition at line 325 of file Point.h.

325 {
326 return 0.5*(errMinus(i) + errPlus(i));
327 }
double errMinus(const size_t i) const
Get the minus error along axis i.
Definition Point.h:313
double errPlus(const size_t i) const
Get the plus error along axis i.
Definition Point.h:319

References YODA::PointBase< N >::errMinus(), and YODA::PointBase< N >::errPlus().

◆ errMinus()

template<size_t N>
double YODA::PointBase< N >::errMinus ( const size_t  i) const
inline

Get the minus error along axis i.

Definition at line 313 of file Point.h.

313 {
314 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
315 return _errs[i].first;
316 }

Referenced by YODA::PointBase< N >::errAvg().

◆ errPlus()

template<size_t N>
double YODA::PointBase< N >::errPlus ( const size_t  i) const
inline

Get the plus error along axis i.

Definition at line 319 of file Point.h.

319 {
320 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
321 return _errs[i].second;
322 }

Referenced by YODA::PointBase< N >::errAvg().

◆ errs() [1/3]

template<size_t N>
NdValPair & YODA::PointBase< N >::errs ( )
inline

Get error values.

Definition at line 297 of file Point.h.

297 {
298 return _errs;
299 }

Referenced by YODA::operator<(), YODA::operator==(), and YODA::PointBase< N >::PointBase().

◆ errs() [2/3]

template<size_t N>
const NdValPair & YODA::PointBase< N >::errs ( ) const
inline

Get error values (const version)

Definition at line 302 of file Point.h.

302 {
303 return _errs;
304 }

◆ errs() [3/3]

template<size_t N>
Pair YODA::PointBase< N >::errs ( const size_t  i) const
inline

Get error values along axis i.

Definition at line 307 of file Point.h.

307 {
308 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
309 return _errs[i];
310 }

◆ max()

template<size_t N>
double YODA::PointBase< N >::max ( const size_t  i) const
inline

Get value plus positive error along axis i.

Definition at line 336 of file Point.h.

336 {
337 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
338 return _val[i] + _errs[i].second;
339 }

◆ min()

template<size_t N>
double YODA::PointBase< N >::min ( const size_t  i) const
inline

Get value minus negative error along axis i.

Definition at line 330 of file Point.h.

330 {
331 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
332 return _val[i] - _errs[i].first;
333 }

◆ operator=() [1/2]

template<size_t N>
PointBase & YODA::PointBase< N >::operator= ( const PointBase< N > &  p)
inline

Assignment operator.

Definition at line 240 of file Point.h.

240 {
241 if (this != &p) {
242 _val = p._val;
243 _errs = p._errs;
244 }
245 return *this;
246 }

◆ operator=() [2/2]

template<size_t N>
PointBase & YODA::PointBase< N >::operator= ( PointBase< N > &&  p)
inline

Assignment operator.

Definition at line 249 of file Point.h.

249 {
250 if (this != &p) {
251 _val = std::move(p._val);
252 _errs = std::move(p._errs);
253 }
254 return *this;
255 }

◆ scale() [1/4]

template<size_t N>
void YODA::PointBase< N >::scale ( const NdVal scales)
inline

Uniform scaling.

Definition at line 411 of file Point.h.

411 {
412 for (size_t i = 0; i < N; ++i) {
413 scale(i, scales[i]);
414 }
415 }
void scale(const size_t i, const double scale)
Scaling along direction i.
Definition Point.h:403

References YODA::PointBase< N >::scale().

◆ scale() [2/4]

template<size_t N>
void YODA::PointBase< N >::scale ( const size_t  i,
const double  scale 
)
inlinevirtual

Scaling along direction i.

Implements YODA::Point.

Definition at line 403 of file Point.h.

403 {
404 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
405 _val[i] *= scale;
406 _errs[i].first *= scale;
407 _errs[i].second *= scale;
408 }

References YODA::PointBase< N >::scale().

Referenced by YODA::PointBase< N >::scale(), YODA::PointBase< N >::scale(), and YODA::PointBase< N >::transform().

◆ scale() [3/4]

template<size_t N>
void YODA::PointBase< N >::scale ( const size_t  i,
const Trf< N > &  trf 
)
inline

Generalised transformations with functors along axis i

Definition at line 424 of file Point.h.

424 {
425 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
426 trf.transform(_val[i], _errs[i]);
427 }

References YODA::Transformation< N, Args >::transform().

◆ scale() [4/4]

template<size_t N>
void YODA::PointBase< N >::scale ( const Trf< N > &  trf)
inline

Generalised transformations with functors.

Definition at line 418 of file Point.h.

418 {
419 trf.transform(_val, _errs);
420 }

References YODA::Transformation< N, Args >::transform().

◆ set() [1/3]

template<size_t N>
void YODA::PointBase< N >::set ( const size_t  i,
const double  val,
const double  e 
)
inlinevirtual

Set value and symmetric error for direction i.

Implements YODA::Point.

Definition at line 377 of file Point.h.

377 {
378 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
379 const double err = fabs(e);
380 _val[i] = val;
381 _errs[i] = {err,err};
382 }

References YODA::PointBase< N >::val().

◆ set() [2/3]

template<size_t N>
void YODA::PointBase< N >::set ( const size_t  i,
const double  val,
const double  eminus,
const double  eplus 
)
inlinevirtual

Set value and asymmetric error for direction i.

Implements YODA::Point.

Definition at line 384 of file Point.h.

384 {
385 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
386 _val[i] = val;
387 _errs[i].first = eminus;
388 _errs[i].second = eplus;
389 }

References YODA::PointBase< N >::val().

◆ set() [3/3]

template<size_t N>
void YODA::PointBase< N >::set ( const size_t  i,
const double  val,
const std::pair< double, double > &  e 
)
inlinevirtual

Set value and asymmetric error for direction i.

Implements YODA::Point.

Definition at line 391 of file Point.h.

391 {
392 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
393 _val[i] = val;
394 _errs[i] = e;
395 }

References YODA::PointBase< N >::val().

◆ setErr()

template<size_t N>
void YODA::PointBase< N >::setErr ( const size_t  i,
const double  e 
)
inlinevirtual

Set a symmetric error pair along axis i.

Implements YODA::Point.

Definition at line 342 of file Point.h.

342 {
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};
346 }

◆ setErrMinus()

template<size_t N>
void YODA::PointBase< N >::setErrMinus ( const size_t  i,
const double  eminus 
)
inlinevirtual

Set a specific minus error along axis i.

Implements YODA::Point.

Definition at line 361 of file Point.h.

361 {
362 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
363 _errs[i].first = eminus;
364 }

◆ setErrPlus()

template<size_t N>
void YODA::PointBase< N >::setErrPlus ( const size_t  i,
const double  eplus 
)
inlinevirtual

Set a specific plus error along axis i.

Implements YODA::Point.

Definition at line 367 of file Point.h.

367 {
368 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
369 _errs[i].second = eplus;
370 }

◆ setErrs() [1/2]

template<size_t N>
void YODA::PointBase< N >::setErrs ( const size_t  i,
const double  eminus,
const double  eplus 
)
inlinevirtual

Set an asymmetric error pair along axis i.

Implements YODA::Point.

Definition at line 349 of file Point.h.

349 {
350 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
351 _errs[i] = { eminus, eplus};
352 }

◆ setErrs() [2/2]

template<size_t N>
void YODA::PointBase< N >::setErrs ( const size_t  i,
const std::pair< double, double > &  e 
)
inlinevirtual

Set a specific error pair along axis i.

Implements YODA::Point.

Definition at line 355 of file Point.h.

355 {
356 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
357 _errs[i] = e;
358 }

◆ setVal() [1/2]

template<size_t N>
void YODA::PointBase< N >::setVal ( const NdVal val)
inline

Set the coordinate vector.

Definition at line 280 of file Point.h.

280 {
281 _val = val;
282 }

References YODA::PointBase< N >::val().

◆ setVal() [2/2]

template<size_t N>
void YODA::PointBase< N >::setVal ( const size_t  i,
const double  val 
)
inlinevirtual

Set a specific coordinate.

Implements YODA::Point.

Definition at line 285 of file Point.h.

285 {
286 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
287 _val[i] = val;
288 }

References YODA::PointBase< N >::val().

◆ transform()

template<size_t N>
void YODA::PointBase< N >::transform ( const size_t  i,
const Trf< N > &  trf 
)
inline

Definition at line 429 of file Point.h.

429 {
430 scale(i, trf);
431 }

References YODA::PointBase< N >::scale().

◆ val()

template<size_t N>
double YODA::PointBase< N >::val ( size_t  i) const
inlinevirtual

Get the value along direction i.

Implements YODA::Point.

Reimplemented in YODA::PointND< 1 >.

Definition at line 274 of file Point.h.

274 {
275 if (i >= N) throw RangeError("Invalid axis int, must be in range 0..dim-1");
276 return _val[i];
277 }

Referenced by YODA::PointBase< N >::PointBase(), YODA::PointBase< N >::PointBase(), YODA::PointBase< N >::set(), YODA::PointBase< N >::set(), YODA::PointBase< N >::set(), YODA::PointBase< N >::setVal(), and YODA::PointBase< N >::setVal().

◆ vals() [1/2]

template<size_t N>
NdVal & YODA::PointBase< N >::vals ( )
inline

Get the coordinate vector.

Definition at line 268 of file Point.h.

268{ return _val; }

Referenced by YODA::operator<(), and YODA::operator==().

◆ vals() [2/2]

template<size_t N>
const NdVal & YODA::PointBase< N >::vals ( ) const
inline

Get the coordinate vector (const version)

Definition at line 271 of file Point.h.

271{ return _val; }

The documentation for this class was generated from the following file: