First version of kdtree (Alexander, Marian)
[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         inline Bool_t   GetEstimate(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const ;
19         Double_t Eval(Float_t *point);
20         void            DrawNodes(Int_t depth = -1, Int_t ax1 = 0, Int_t ax2 = 1);
21         void            DrawNode(Int_t node, Int_t ax1 = 0, Int_t ax2 = 1);
22 private:
23         void            Build();
24         
25 protected:
26         Int_t     fNTNodes;        //Number of evaluation data points
27         Float_t   **fRefPoints;    //[fNDim][fNTNodes]
28         Float_t   *fRefValues;     //[fNTNodes]
29
30 private:
31         Int_t                   fDepth;        //! depth of the KD Tree structure used
32         Double_t        *fTmpPoint;    //! temporary storage for one data point
33         TKDTreeIF *fKDhelper;    //! kNN finder
34         TLinearFitter *fFitter;  //! linear fitter      
35
36         ClassDef(TKDInterpolator, 1)   // data interpolator based on KD tree
37 };
38
39 //__________________________________________________________________
40 Bool_t  TKDInterpolator::GetEstimate(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const
41 {
42         if(node < 0 || node > GetNTerminalNodes()) return kFALSE;
43
44         for(int idim=0; idim<fNDim; idim++) coord[idim] = fRefPoints[idim][node];
45         val   = fRefValues[node];
46         //error = ...;
47         return kTRUE;
48 }
49
50 #endif
51