]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STAT/TKDInterpolator.h
Process codes corrected/completed.
[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 #ifndef ROOT_TVectorD
8 #include "TVectorD.h"
9 #endif
10 #ifndef ROOT_TMatrixD
11 #include "TMatrixD.h"
12 #endif
13
14
15 class TTree;
16 class TLinearFitter;
17 class TKDInterpolator : public TKDTreeIF
18 {
19 public:
20         struct TKDNodeInfo
21         {
22                 TKDNodeInfo(const Int_t ndim = 0);
23                 ~TKDNodeInfo();
24                 void                    Build(const Int_t ndim);
25
26                 Int_t     fNDim;         // data dimension
27                 Float_t   *fRefPoint;    //[fNDim] node's COG
28                 Float_t   fRefValue;     // measured value for node 
29                 TMatrixD  fCov;          // interpolator covariance matrix
30                 TVectorD  fPar;          // interpolator parameters
31                 Bool_t    fPDFstatus;    // status bit for node's PDF
32
33                 ClassDef(TKDNodeInfo, 1) // node info for interpolator
34         };
35 public:
36         TKDInterpolator();
37         TKDInterpolator(TTree *t, const Char_t *var, const Char_t *cut = 0, UInt_t bsize = 100, Long64_t nentries = 1000000000, Long64_t firstentry = 0);
38         TKDInterpolator(Int_t npoints, Int_t ndim, UInt_t bsize, Float_t **data);
39         ~TKDInterpolator();
40
41                 Double_t   Eval(const Double_t *point, Double_t &result, Double_t &error);
42         inline Bool_t     GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const ;
43         inline Bool_t     GetDataPoint(Int_t n, Float_t *p) const;
44                 TKDTreeIF* GetHelper() {return fKDhelper;}
45         inline Bool_t     GetIntInterpolation() const {return fStatus&1;}
46         inline Bool_t     GetSetStore() const {return fStatus&2;}
47         inline Bool_t     GetUseWeights() const {return fStatus&4;}
48                                         
49                                         void       DrawNodes(UInt_t ax1 = 0, UInt_t ax2 = 1, Int_t depth = -1);
50                 void       DrawNode(Int_t tnode, UInt_t ax1 = 0, UInt_t ax2 = 1);
51                 void       GetStatus();
52                 void       SetIntInterpolation(const Bool_t on = kTRUE);
53                 void       SetSetStore(const Bool_t on = kTRUE);
54                 void       SetUseWeights(const Bool_t on = kTRUE);
55         
56 private:
57         TKDInterpolator(const TKDInterpolator &);
58         TKDInterpolator& operator=(const TKDInterpolator &);    
59                 void       Build();
60                 Double_t   CookPDF(const Double_t *point, const Int_t node, Double_t &result, Double_t &error);
61                                         
62 protected:
63         Int_t     fNTNodes;        //Number of evaluation data points
64         TKDNodeInfo *fTNodes;      //[fNTNodes] interpolation node
65 //      Float_t   *fRefValues;     //[fNTNodes]
66 //      TMatrixD  *fCov;           //[fNTNodes] cov matrix array for nodes
67 //      TVectorD  *fPar;           //[fNTNodes] parameters array for nodes
68 //      Bool_t    *fPDFstatus;     //[fNTNodes] status bit for node's PDF
69
70 private:
71         UChar_t   fStatus;         // status of the interpolator
72         Int_t     fLambda;         // number of parameters in polynom
73         Int_t                   fDepth;          //! depth of the KD Tree structure used
74         Float_t   **fRefPoints;    //! temporary storage of COG data
75         Double_t        *fBuffer;        //! working space [2*fLambda]
76         TKDTreeIF *fKDhelper;      //! kNN finder
77         TLinearFitter *fFitter;    //! linear fitter    
78
79         ClassDef(TKDInterpolator, 1)   // data interpolator based on KD tree
80 };
81
82 //__________________________________________________________________
83 Bool_t  TKDInterpolator::GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &err) const
84 {
85         if(node < 0 || node > fNTNodes) return kFALSE;
86
87         for(int idim=0; idim<fNDim; idim++) coord[idim] = fTNodes[node].fRefPoint[idim];
88         val = fTNodes[node].fRefValue;
89         err = fTNodes[node].fRefValue/TMath::Sqrt(fBucketSize);
90         return kTRUE;
91 }
92
93 //__________________________________________________________________
94 Bool_t  TKDInterpolator::GetDataPoint(Int_t n, Float_t *p) const
95 {
96         if(n < 0 || n >= fNpoints) return kFALSE;
97         
98         for(int i=0; i<fNDim; i++) p[i] = fData[i][n];
99         return kTRUE;
100 }
101
102
103 #endif
104