Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDataPoint.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: C. Gumpert 09/2011
3/**********************************************************************
4 * *
5 * Copyright (c) 2011 , LCG ROOT MathLib Team *
6 * *
7 * *
8 **********************************************************************/
9//
10// Header file for TDataPointclass
11//
12
13#ifndef ROOT_Math_TDataPoint
14#define ROOT_Math_TDataPoint
15
16// ROOT include(s)
17#include "RtypesCore.h"
18
19#include <cassert>
20#include <math.h>
21
22namespace ROOT {
23namespace Math {
24
25/// \brief class representing a data point
26///
27/// This class can be used for describing data points in a high-dimensional space.
28/// The (positive) dimension is specified by the first template parameter. The second
29/// template parameter can be used to tweak the precision of the stored coordinates. By
30/// default all coordinates are stored with 4 byte float precision. In addition to the
31/// coordinates a weight can be assigned to each data point allowing the representation
32/// of fields in high dimensions.
33/// Basic functionality for accessing/modifying the coordinates/weight are provided
34/// as well as a comparison method and the basic euclidean metric.
35template <unsigned int K, typename _val_type = float>
37public:
39 enum {
40 kDimension = K // the dimensionality of this data point
41 };
42 static UInt_t Dimension() { return kDimension; }
43 /// standard constructor
44 /// sets the weight to 1 and initialises all coordinates with 0
46 {
47 // at least one dimension
48 assert(kDimension > 0);
49
50 for (UInt_t k = 0; k < K; ++k)
51 m_vCoordinates[k] = 0;
52 }
53#ifndef __MAKECINT__
54 /// constructor initialising the data point from an array
55 ///
56 /// Input: pData - array with kDimension coordinates
57 /// fWeight - weight (default = 1)
58 template <typename _coord_typ>
59 TDataPoint(const _coord_typ *pData, _val_type fWeight = 1)
60 {
61 // at least one dimension
62 assert(kDimension > 0);
63 // fill coordinates
64 for (unsigned int i = 0; i < kDimension; ++i)
65 m_vCoordinates[i] = pData[i];
66 m_fWeight = fWeight;
67 }
68 /// euclidean distance
69 ///
70 /// returns the euclidean distance to the given data point
71 ///
72 /// Input: rPoint - data point of same dimensionality
73 template <typename _val>
75 {
76 _val_type fDist2 = 0;
77 for (unsigned int i = 0; i < kDimension; ++i)
78 fDist2 += pow(GetCoordinate(i) - rPoint.GetCoordinate(i), 2);
79
80 return sqrt(fDist2);
81 }
82#endif
83 /// returns the coordinate at the given axis
84 ///
85 /// Input: iAxis - axis in the range of [0...kDimension-1]
86 value_type GetCoordinate(unsigned int iAxis) const
87 {
89 return m_vCoordinates[iAxis];
90 }
91 value_type GetWeight() const { return m_fWeight; }
92 /// compares two points at a given axis
93 ///
94 /// returns: this_point.at(iAxis) < rPoint.at(iAxis)
95 ///
96 /// Input: rPoint - second point to compare to (of same dimensionality)
97 /// iAxis - axis in the range of [0...kDimension-1]
98 Bool_t Less(TDataPoint &rPoint, unsigned int iAxis) const
99 {
101 return (m_vCoordinates[iAxis] < rPoint.GetCoordinate(iAxis));
102 }
103 /// sets the coordinate along one axis
104 ///
105 /// Input: iAxis - axis in the range of [0...kDimension-1]
106 /// fValue - new coordinate
107 void SetCoordinate(unsigned int iAxis, _val_type fValue)
108 {
110 m_vCoordinates[iAxis] = fValue;
111 }
112 void SetWeight(float fWeight) { m_fWeight = fWeight; }
113
114private:
115 value_type m_vCoordinates[K]; ///< coordinates
116 value_type m_fWeight = 1; ///< weight at this point
117};
118
119// some typedef definitions
126
127} // namespace Math
128} // namespace ROOT
129
130#endif // ROOT_Math_TDataPoint
Basic types used by ROOT and required by TInterpreter.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
class representing a data point
Definition TDataPoint.h:36
Bool_t Less(TDataPoint &rPoint, unsigned int iAxis) const
compares two points at a given axis
Definition TDataPoint.h:98
static UInt_t Dimension()
Definition TDataPoint.h:42
value_type Distance(const TDataPoint< K, _val > &rPoint) const
euclidean distance
Definition TDataPoint.h:74
TDataPoint()
standard constructor sets the weight to 1 and initialises all coordinates with 0
Definition TDataPoint.h:45
TDataPoint(const _coord_typ *pData, _val_type fWeight=1)
constructor initialising the data point from an array
Definition TDataPoint.h:59
void SetCoordinate(unsigned int iAxis, _val_type fValue)
sets the coordinate along one axis
Definition TDataPoint.h:107
void SetWeight(float fWeight)
Definition TDataPoint.h:112
value_type m_vCoordinates[K]
coordinates
Definition TDataPoint.h:115
value_type GetCoordinate(unsigned int iAxis) const
returns the coordinate at the given axis
Definition TDataPoint.h:86
value_type m_fWeight
weight at this point
Definition TDataPoint.h:116
value_type GetWeight() const
Definition TDataPoint.h:91
Namespace for new Math classes and functions.
TDataPoint< 2, Float_t > TDataPoint2F
Definition TDataPoint.h:121
TDataPoint< 3, Double_t > TDataPoint3D
Definition TDataPoint.h:125
TDataPoint< 3, Float_t > TDataPoint3F
Definition TDataPoint.h:122
TDataPoint< 1, Double_t > TDataPoint1D
Definition TDataPoint.h:123
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
TDataPoint< 2, Double_t > TDataPoint2D
Definition TDataPoint.h:124
TDataPoint< 1, Float_t > TDataPoint1F
Definition TDataPoint.h:120
Namespace for new ROOT classes and functions.