File indexing completed on 2025-12-23 10:02:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_Math_TDataPoint
0014 #define ROOT_Math_TDataPoint
0015
0016
0017 #include "RtypesCore.h"
0018
0019 #include <cassert>
0020 #include <cmath>
0021
0022 namespace ROOT {
0023 namespace Math {
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 template <unsigned int K, typename _val_type = float>
0036 class TDataPoint {
0037 public:
0038 typedef _val_type value_type;
0039 enum {
0040 kDimension = K
0041 };
0042 static UInt_t Dimension() { return kDimension; }
0043
0044
0045 TDataPoint()
0046 {
0047
0048 assert(kDimension > 0);
0049
0050 for (UInt_t k = 0; k < K; ++k)
0051 m_vCoordinates[k] = 0;
0052 }
0053 #ifndef __MAKECINT__
0054
0055
0056
0057
0058 template <typename _coord_typ>
0059 TDataPoint(const _coord_typ *pData, _val_type fWeight = 1)
0060 {
0061
0062 assert(kDimension > 0);
0063
0064 for (unsigned int i = 0; i < kDimension; ++i)
0065 m_vCoordinates[i] = pData[i];
0066 m_fWeight = fWeight;
0067 }
0068
0069
0070
0071
0072
0073 template <typename _val>
0074 value_type Distance(const TDataPoint<K, _val> &rPoint) const
0075 {
0076 _val_type fDist2 = 0;
0077 for (unsigned int i = 0; i < kDimension; ++i)
0078 fDist2 += pow(GetCoordinate(i) - rPoint.GetCoordinate(i), 2);
0079
0080 return sqrt(fDist2);
0081 }
0082 #endif
0083
0084
0085
0086 value_type GetCoordinate(unsigned int iAxis) const
0087 {
0088 assert(iAxis < kDimension);
0089 return m_vCoordinates[iAxis];
0090 }
0091 value_type GetWeight() const { return m_fWeight; }
0092
0093
0094
0095
0096
0097
0098 Bool_t Less(TDataPoint &rPoint, unsigned int iAxis) const
0099 {
0100 assert(iAxis < kDimension);
0101 return (m_vCoordinates[iAxis] < rPoint.GetCoordinate(iAxis));
0102 }
0103
0104
0105
0106
0107 void SetCoordinate(unsigned int iAxis, _val_type fValue)
0108 {
0109 assert(iAxis < kDimension);
0110 m_vCoordinates[iAxis] = fValue;
0111 }
0112 void SetWeight(float fWeight) { m_fWeight = fWeight; }
0113
0114 private:
0115 value_type m_vCoordinates[K];
0116 value_type m_fWeight = 1;
0117 };
0118
0119
0120 typedef TDataPoint<1, Float_t> TDataPoint1F;
0121 typedef TDataPoint<2, Float_t> TDataPoint2F;
0122 typedef TDataPoint<3, Float_t> TDataPoint3F;
0123 typedef TDataPoint<1, Double_t> TDataPoint1D;
0124 typedef TDataPoint<2, Double_t> TDataPoint2D;
0125 typedef TDataPoint<3, Double_t> TDataPoint3D;
0126
0127 }
0128 }
0129
0130 #endif