Logo ROOT   6.18/05
Reference Guide
TDataPoint.icc
Go to the documentation of this file.
1// @(#)root/mathcore:$Id: IFunction.h 24537 2008-06-25 11:01:23Z moneta $
2// Authors: C. Gumpert 09/2011
3/**********************************************************************
4 * *
5 * Copyright (c) 2011 , LCG ROOT MathLib Team *
6 * *
7 * *
8 **********************************************************************/
9//
10// Implementation of template functions for TDataPoint class
11//
12
13
14#ifndef ROOT_TDataPoint_ICC
15#define ROOT_TDataPoint_ICC
16
17#ifndef ROOT_Math_TDataPoint
18#error "Do not use TDataPoint.icc directly. #include \"TDataPoint.h\" instead."
19#endif // ROOT_Math_TDataPoint
20
21#include <cassert>
22#include <math.h>
23
24namespace ROOT
25{
26namespace Math
27{
28
29
30//______________________________________________________________________________
31// Begin_Html
32// <center><h2>TDataPoint - class representing a data point</h2></center>
33//
34// This class can be used for describing data points in a high-dimensional space.
35// The (positive) dimension is specified by the first template parameter. The second
36// template paramter can be used to tweak the precision of the stored coordinates. By
37// default all coordinates are stored with 4 byte float precision. In addition to the
38// coordinates a weight can be assigned to each data point allowing the representation
39// of fields in high dimensions.
40// Basic functionality for accessing/modifying the coordinates/weight are provided
41// as well as a comparison method and the basic euclidian metric.
42// End_Html
43
44//______________________________________________________________________________
45template<unsigned int K,typename _val_type>
47 m_fWeight(1)
48{
49 //standard constructor
50 //
51 //sets the weight to 1 and initialises all coordinates with 0
52
53 // at least one dimension
54 assert(kDimension > 0);
55
56 for(UInt_t k = 0; k < K; ++k)
57 m_vCoordinates[k] = 0;
58}
59
60#ifndef __MAKECINT__
61//______________________________________________________________________________
62template<unsigned int K,typename _val_type>
63template<typename _coord_type>
64TDataPoint<K,_val_type>::TDataPoint(const _coord_type* pData,_val_type fWeight):
65 m_fWeight(fWeight)
66{
67 //constructor initialising the data point from an array
68 //
69 //Input: pData - arrray with kDimension coordinates
70 // fWeight - weight (default = 1)
71
72 // at least one dimension
73 assert(kDimension > 0);
74 // fill coordinates
75 for(unsigned int i = 0; i < kDimension; ++i)
76 m_vCoordinates[i] = pData[i];
77}
78
79//______________________________________________________________________________
80template<unsigned int K,typename _val_type>
81template<typename _val>
83{
84 //euclidian distance
85 //
86 //returns the euclidian distance to the given data point
87 //
88 //Input: rPoint - data point of same dimensionality
89
90 _val_type fDist2 = 0;
91 for(unsigned int i = 0; i < kDimension; ++i)
92 fDist2 += pow(GetCoordinate(i) - rPoint.GetCoordinate(i),2);
93
94 return sqrt(fDist2);
95}
96#endif
97
98//______________________________________________________________________________
99template<unsigned int K,typename _val_type>
100inline _val_type TDataPoint<K,_val_type>::GetCoordinate(unsigned int iAxis) const
101{
102 //returns the coordinate at the given axis
103 //
104 //Input: iAxis - axis in the range of [0...kDimension-1]
105
106 assert(iAxis < kDimension);
107 return m_vCoordinates[iAxis];
108}
109
110//______________________________________________________________________________
111template<unsigned int K,typename _val_type>
112inline void TDataPoint<K,_val_type>::SetCoordinate(unsigned int iAxis,_val_type fValue)
113{
114 //sets the coordinate along one axis
115 //
116 //Input: iAxis - axis in the range of [0...kDimension-1]
117 // fValue - new coordinate
118
119 assert(iAxis < kDimension);
120 m_vCoordinates[iAxis] = fValue;
121}
122
123//______________________________________________________________________________
124template<unsigned int K,typename _val_type>
125inline Bool_t TDataPoint<K,_val_type>::Less(TDataPoint<K,_val_type>& rPoint,unsigned int iAxis) const
126{
127 //compares two points at a given axis
128 //
129 // returns: this_point.at(iAxis) < rPoint.at(iAxis)
130 //
131 //Input: rPoint - second point to compare to (of same dimensionality)
132 // iAxis - axis in the range of [0...kDimension-1]
133
134 assert(iAxis < kDimension);
135 return (m_vCoordinates[iAxis] < rPoint.GetCoordinate(iAxis));
136}
137
138}//namespace Math
139}//namespace ROOT
140
141
142#endif //ROOT_TDataPoint_ICC
PyObject * fValue
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
double pow(double, double)
constexpr Int_t kDimension
Bool_t Less(TDataPoint &rPoint, unsigned int iAxis) const
Definition: TDataPoint.icc:125
value_type Distance(const TDataPoint< K, _val > &rPoint) const
void SetCoordinate(unsigned int iAxis, _val_type fValue)
Definition: TDataPoint.icc:112
value_type m_vCoordinates[K]
Definition: TDataPoint.h:52
value_type GetCoordinate(unsigned int iAxis) const
Definition: TDataPoint.icc:100
Namespace for new Math classes and functions.
static const uint32_t K[64]
Definition: RSha256.hxx:148
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21