Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:22

0001 // @(#)root/mathcore:$Id: IFunction.h 24537 2008-06-25 11:01:23Z moneta $
0002 // Authors: C. Gumpert    09/2011
0003 /**********************************************************************
0004  *                                                                    *
0005  * Copyright (c) 2011 , LCG ROOT MathLib Team                         *
0006  *                                                                    *
0007  *                                                                    *
0008  **********************************************************************/
0009 //
0010 // Implementation of template functions for TDataPoint class
0011 //
0012 
0013 
0014 #ifndef ROOT_TDataPoint_ICC
0015 #define ROOT_TDataPoint_ICC
0016 
0017 #ifndef ROOT_Math_TDataPoint
0018 #error "Do not use TDataPoint.icc directly. #include \"TDataPoint.h\" instead."
0019 #endif // ROOT_Math_TDataPoint
0020 
0021 #include <cassert>
0022 #include <math.h>
0023 
0024 namespace ROOT
0025 {
0026 namespace Math
0027 {
0028 
0029 
0030 //______________________________________________________________________________
0031 // Begin_Html
0032 // <center><h2>TDataPoint - class representing a data point</h2></center>
0033 //
0034 // This class can be used for describing data points in a high-dimensional space.
0035 // The (positive) dimension is specified by the first template parameter. The second
0036 // template parameter can be used to tweak the precision of the stored coordinates. By
0037 // default all coordinates are stored with 4 byte float precision. In addition to the
0038 // coordinates a weight can be assigned to each data point allowing the representation
0039 // of fields in high dimensions.
0040 // Basic functionality for accessing/modifying the coordinates/weight are provided
0041 // as well as a comparison method and the basic euclidean metric.
0042 // End_Html
0043 
0044 //______________________________________________________________________________
0045 template<unsigned int K,typename _val_type>
0046 TDataPoint<K,_val_type>::TDataPoint():
0047    m_fWeight(1)
0048 {
0049    //standard constructor
0050    //
0051    //sets the weight to 1 and initialises all coordinates with 0
0052 
0053    // at least one dimension
0054    assert(kDimension > 0);
0055 
0056    for(UInt_t k = 0; k < K; ++k)
0057       m_vCoordinates[k] = 0;
0058 }
0059 
0060 #ifndef __MAKECINT__
0061 //______________________________________________________________________________
0062 template<unsigned int K,typename _val_type>
0063 template<typename _coord_type>
0064 TDataPoint<K,_val_type>::TDataPoint(const _coord_type* pData,_val_type fWeight):
0065   m_fWeight(fWeight)
0066 {
0067    //constructor initialising the data point from an array
0068    //
0069    //Input: pData   - array with kDimension coordinates
0070    //       fWeight - weight (default = 1)
0071 
0072    // at least one dimension
0073    assert(kDimension > 0);
0074    // fill coordinates
0075    for(unsigned int i = 0; i < kDimension; ++i)
0076       m_vCoordinates[i] = pData[i];
0077 }
0078 
0079 //______________________________________________________________________________
0080 template<unsigned int K,typename _val_type>
0081 template<typename _val>
0082 _val_type TDataPoint<K,_val_type>::Distance(const TDataPoint<K,_val>& rPoint) const
0083 {
0084    //euclidean distance
0085    //
0086    //returns the euclidean distance to the given data point
0087    //
0088    //Input: rPoint - data point of same dimensionality
0089 
0090    _val_type fDist2 = 0;
0091    for(unsigned int i = 0; i < kDimension; ++i)
0092       fDist2 += pow(GetCoordinate(i) - rPoint.GetCoordinate(i),2);
0093 
0094    return sqrt(fDist2);
0095 }
0096 #endif
0097 
0098 //______________________________________________________________________________
0099 template<unsigned int K,typename _val_type>
0100 inline _val_type TDataPoint<K,_val_type>::GetCoordinate(unsigned int iAxis) const
0101 {
0102    //returns the coordinate at the given axis
0103    //
0104    //Input: iAxis - axis in the range of [0...kDimension-1]
0105 
0106    assert(iAxis < kDimension);
0107    return m_vCoordinates[iAxis];
0108 }
0109 
0110 //______________________________________________________________________________
0111 template<unsigned int K,typename _val_type>
0112 inline void TDataPoint<K,_val_type>::SetCoordinate(unsigned int iAxis,_val_type fValue)
0113 {
0114    //sets the coordinate along one axis
0115    //
0116    //Input: iAxis  - axis in the range of [0...kDimension-1]
0117    //       fValue - new coordinate
0118 
0119    assert(iAxis < kDimension);
0120    m_vCoordinates[iAxis] = fValue;
0121 }
0122 
0123 //______________________________________________________________________________
0124 template<unsigned int K,typename _val_type>
0125 inline Bool_t TDataPoint<K,_val_type>::Less(TDataPoint<K,_val_type>& rPoint,unsigned int iAxis) const
0126 {
0127    //compares two points at a given axis
0128    //
0129    // returns: this_point.at(iAxis) < rPoint.at(iAxis)
0130    //
0131    //Input: rPoint - second point to compare to (of same dimensionality)
0132    //       iAxis  - axis in the range of [0...kDimension-1]
0133 
0134    assert(iAxis < kDimension);
0135    return (m_vCoordinates[iAxis] < rPoint.GetCoordinate(iAxis));
0136 }
0137 
0138 }//namespace Math
0139 }//namespace ROOT
0140 
0141 
0142 #endif //ROOT_TDataPoint_ICC