ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include <cassert>
18 
19 namespace ROOT
20 {
21 namespace Math
22 {
23 
24 
25 //______________________________________________________________________________
26 // Begin_Html
27 // <center><h2>TDataPoint - class representing a data point</h2></center>
28 //
29 // This class can be used for describing data points in a high-dimensional space.
30 // The (positive) dimension is specified by the first template parameter. The second
31 // template paramter can be used to tweak the precision of the stored coordinates. By
32 // default all coordinates are stored with 4 byte float precision. In addition to the
33 // coordinates a weight can be assigned to each data point allowing the representation
34 // of fields in high dimensions.
35 // Basic functionality for accessing/modifying the coordinates/weight are provided
36 // as well as a comparison method and the basic euclidian metric.
37 // End_Html
38 
39 //______________________________________________________________________________
40 template<unsigned int K,typename _val_type>
42  m_fWeight(1)
43 {
44  //standard constructor
45  //
46  //sets the weight to 1 and initialises all coordinates with 0
47 
48  // at least one dimension
49  assert(kDimension > 0);
50 
51  for(UInt_t k = 0; k < K; ++k)
52  m_vCoordinates[k] = 0;
53 }
54 
55 #ifndef __MAKECINT__
56 //______________________________________________________________________________
57 template<unsigned int K,typename _val_type>
58 template<typename _coord_type>
59 TDataPoint<K,_val_type>::TDataPoint(const _coord_type* pData,_val_type fWeight):
60  m_fWeight(fWeight)
61 {
62  //constructor initialising the data point from an array
63  //
64  //Input: pData - arrray with kDimension coordinates
65  // fWeight - weight (default = 1)
66 
67  // at least one dimension
68  assert(kDimension > 0);
69  // fill coordinates
70  for(unsigned int i = 0; i < kDimension; ++i)
71  m_vCoordinates[i] = pData[i];
72 }
73 
74 //______________________________________________________________________________
75 template<unsigned int K,typename _val_type>
76 template<typename _val>
78 {
79  //euclidian distance
80  //
81  //returns the euclidian distance to the given data point
82  //
83  //Input: rPoint - data point of same dimensionality
84 
85  _val_type fDist2 = 0;
86  for(unsigned int i = 0; i < kDimension; ++i)
87  fDist2 += pow(GetCoordinate(i) - rPoint.GetCoordinate(i),2);
88 
89  return sqrt(fDist2);
90 }
91 #endif
92 
93 //______________________________________________________________________________
94 template<unsigned int K,typename _val_type>
95 inline _val_type TDataPoint<K,_val_type>::GetCoordinate(unsigned int iAxis) const
96 {
97  //returns the coordinate at the given axis
98  //
99  //Input: iAxis - axis in the range of [0...kDimension-1]
100 
101  assert(iAxis < kDimension);
102  return m_vCoordinates[iAxis];
103 }
104 
105 //______________________________________________________________________________
106 template<unsigned int K,typename _val_type>
107 inline void TDataPoint<K,_val_type>::SetCoordinate(unsigned int iAxis,_val_type fValue)
108 {
109  //sets the coordinate along one axis
110  //
111  //Input: iAxis - axis in the range of [0...kDimension-1]
112  // fValue - new coordinate
113 
114  assert(iAxis < kDimension);
115  m_vCoordinates[iAxis] = fValue;
116 }
117 
118 //______________________________________________________________________________
119 template<unsigned int K,typename _val_type>
120 inline Bool_t TDataPoint<K,_val_type>::Less(TDataPoint<K,_val_type>& rPoint,unsigned int iAxis) const
121 {
122  //compares two points at a given axis
123  //
124  // returns: this_point.at(iAxis) < rPoint.at(iAxis)
125  //
126  //Input: rPoint - second point to compare to (of same dimensionality)
127  // iAxis - axis in the range of [0...kDimension-1]
128 
129  assert(iAxis < kDimension);
130  return (m_vCoordinates[iAxis] < rPoint.GetCoordinate(iAxis));
131 }
132 
133 }//namespace Math
134 }//namespace ROOT
135 
136 
137 #endif //ROOT_TDataPoint_ICC
Bool_t Less(TDataPoint &rPoint, unsigned int iAxis) const
Definition: TDataPoint.icc:120
#define assert(cond)
Definition: unittest.h:542
bool Bool_t
Definition: RtypesCore.h:59
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
value_type Distance(const TDataPoint< K, _val > &rPoint) const
double pow(double, double)
void SetCoordinate(unsigned int iAxis, _val_type fValue)
Definition: TDataPoint.icc:107
PyObject * fValue
unsigned int UInt_t
Definition: RtypesCore.h:42
Double_t K()
Definition: TMath.h:95
const Int_t kDimension
value_type GetCoordinate(unsigned int iAxis) const
Definition: TDataPoint.icc:95
value_type m_vCoordinates[K]
Definition: TDataPoint.h:52