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