Small interface modification
[u/mrichter/AliRoot.git] / STAT / TKDInterpolator.h
1 #ifndef ROOT_TKDInterpolator
2 #define ROOT_TKDInterpolator
3
4 #ifndef ROOT_TKDTree
5 #include "TKDTree.h"
6 #endif
7
8 class TTree;
9 class TLinearFitter;
10 class TKDInterpolator : public TKDTreeIF
11 {
12 public:
13         TKDInterpolator();
14         TKDInterpolator(TTree *t, const Char_t *var, const Char_t *cut = 0, UInt_t bsize = 100);
15         TKDInterpolator(Int_t npoints, Int_t ndim, UInt_t bsize, Float_t **data);
16         ~TKDInterpolator();
17
18                 TKDTreeIF* GetHelper() {return fKDhelper;}
19         inline Bool_t     GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const ;
20         inline Bool_t     GetDataPoint(Int_t n, Float_t *p) const;
21                 Double_t   Eval(const Double_t *point, Int_t npoints = 12);
22                 void       DrawNodes(UInt_t ax1 = 0, UInt_t ax2 = 1, Int_t depth = -1);
23                 void       DrawNode(Int_t tnode, UInt_t ax1 = 0, UInt_t ax2 = 1);
24
25 private:
26         TKDInterpolator(const TKDInterpolator &);
27         TKDInterpolator& operator=(const TKDInterpolator &);    
28                 void       Build();
29         
30 protected:
31         Int_t     fNTNodes;        //Number of evaluation data points
32         Float_t   **fRefPoints;    //[fNDim][fNTNodes]
33         Float_t   *fRefValues;     //[fNTNodes]
34
35 private:
36         Int_t                   fDepth;        //! depth of the KD Tree structure used
37         Double_t        *fTmpPoint;    //! temporary storage for one data point
38         TKDTreeIF *fKDhelper;    //! kNN finder
39         TLinearFitter *fFitter;  //! linear fitter      
40
41         ClassDef(TKDInterpolator, 1)   // data interpolator based on KD tree
42 };
43
44 //__________________________________________________________________
45 Bool_t  TKDInterpolator::GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const
46 {
47         if(node < 0 || node > fNTNodes) return kFALSE;
48
49         for(int idim=0; idim<fNDim; idim++) coord[idim] = fRefPoints[idim][node];
50         val   = fRefValues[node];
51         error = fRefValues[node]; // to be implemented
52         return kTRUE;
53 }
54
55 //__________________________________________________________________
56 Bool_t  TKDInterpolator::GetDataPoint(Int_t n, Float_t *p) const
57 {
58         if(n < 0 || n >= fNpoints) return kFALSE;
59         
60         for(int i=0; i<fNDim; i++) p[i] = fData[i][n];
61         return kTRUE;
62 }
63
64
65 #endif
66