ROOT  6.06/09
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 namespace ROOT
18 {
19 namespace Math
20 {
21 
22 
23 //______________________________________________________________________________
24 // Begin_Html
25 // <center><h2>TDataPoint - class representing a data point</h2></center>
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 paramter 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 euclidian metric.
35 // End_Html
36 
37 //______________________________________________________________________________
38 template<unsigned int K,typename _val_type>
40  m_fWeight(1)
41 {
42  //standard constructor
43  //
44  //sets the weight to 1 and initialises all coordinates with 0
45 
46  // at least one dimension
47  assert(kDimension > 0);
48 
49  for(UInt_t k = 0; k < K; ++k)
50  m_vCoordinates[k] = 0;
51 }
52 
53 #ifndef __MAKECINT__
54 //______________________________________________________________________________
55 template<unsigned int K,typename _val_type>
56 template<typename _coord_type>
57 TDataPoint<K,_val_type>::TDataPoint(const _coord_type* pData,_val_type fWeight):
58  m_fWeight(fWeight)
59 {
60  //constructor initialising the data point from an array
61  //
62  //Input: pData - arrray with kDimension coordinates
63  // fWeight - weight (default = 1)
64 
65  // at least one dimension
66  assert(kDimension > 0);
67  // fill coordinates
68  for(unsigned int i = 0; i < kDimension; ++i)
69  m_vCoordinates[i] = pData[i];
70 }
71 
72 //______________________________________________________________________________
73 template<unsigned int K,typename _val_type>
74 template<typename _val>
76 {
77  //euclidian distance
78  //
79  //returns the euclidian distance to the given data point
80  //
81  //Input: rPoint - data point of same dimensionality
82 
83  _val_type fDist2 = 0;
84  for(unsigned int i = 0; i < kDimension; ++i)
85  fDist2 += pow(GetCoordinate(i) - rPoint.GetCoordinate(i),2);
86 
87  return sqrt(fDist2);
88 }
89 #endif
90 
91 //______________________________________________________________________________
92 template<unsigned int K,typename _val_type>
93 inline _val_type TDataPoint<K,_val_type>::GetCoordinate(unsigned int iAxis) const
94 {
95  //returns the coordinate at the given axis
96  //
97  //Input: iAxis - axis in the range of [0...kDimension-1]
98 
99  assert(iAxis < kDimension);
100  return m_vCoordinates[iAxis];
101 }
102 
103 //______________________________________________________________________________
104 template<unsigned int K,typename _val_type>
105 inline void TDataPoint<K,_val_type>::SetCoordinate(unsigned int iAxis,_val_type fValue)
106 {
107  //sets the coordinate along one axis
108  //
109  //Input: iAxis - axis in the range of [0...kDimension-1]
110  // fValue - new coordinate
111 
112  assert(iAxis < kDimension);
113  m_vCoordinates[iAxis] = fValue;
114 }
115 
116 //______________________________________________________________________________
117 template<unsigned int K,typename _val_type>
118 inline Bool_t TDataPoint<K,_val_type>::Less(TDataPoint<K,_val_type>& rPoint,unsigned int iAxis) const
119 {
120  //compares two points at a given axis
121  //
122  // returns: this_point.at(iAxis) < rPoint.at(iAxis)
123  //
124  //Input: rPoint - second point to compare to (of same dimensionality)
125  // iAxis - axis in the range of [0...kDimension-1]
126 
127  assert(iAxis < kDimension);
128  return (m_vCoordinates[iAxis] < rPoint.GetCoordinate(iAxis));
129 }
130 
131 }//namespace Math
132 }//namespace ROOT
133 
134 
135 #endif //ROOT_TDataPoint_ICC
Bool_t Less(TDataPoint &rPoint, unsigned int iAxis) const
Definition: TDataPoint.icc:118
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
#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:105
PyObject * fValue
unsigned int UInt_t
Definition: RtypesCore.h:42
Double_t K()
Definition: TMath.h:95
const Int_t kDimension
Namespace for new Math classes and functions.
value_type GetCoordinate(unsigned int iAxis) const
Definition: TDataPoint.icc:93
value_type m_vCoordinates[K]
Definition: TDataPoint.h:52