new macros for testing the STAT package
[u/mrichter/AliRoot.git] / STAT / TKDInterpolator.h
CommitLineData
f2040a8f 1#ifndef ROOT_TKDInterpolator
2#define ROOT_TKDInterpolator
3
4#ifndef ROOT_TKDTree
5#include "TKDTree.h"
6#endif
316a7f5a 7
117c62ab 8// Non parametric interpolation class based on local polinomial regression.
9// The class can be used to approximate PDF together with TKDTree or for
10// general regression when the data points are given.
f2040a8f 11
c0bfcd26 12template <typename Value> class TVectorT;
13typedef struct TVectorT<Double_t> TVectorD;
14template <typename Value> class TMatrixT;
15typedef class TMatrixT<Double_t> TMatrixD;
16template <typename Index, typename Value> class TKDTree;
17typedef class TKDTree<Int_t, Float_t> TKDTreeIF;
f2040a8f 18class TTree;
19class TLinearFitter;
20class TKDInterpolator : public TKDTreeIF
21{
22public:
23 TKDInterpolator();
316a7f5a 24 TKDInterpolator(TTree *t, const Char_t *var, const Char_t *cut = 0, UInt_t bsize = 100, Long64_t nentries = 1000000000, Long64_t firstentry = 0);
f2040a8f 25 TKDInterpolator(Int_t npoints, Int_t ndim, UInt_t bsize, Float_t **data);
26 ~TKDInterpolator();
e0b38166 27
117c62ab 28 Double_t Eval(const Double_t *point, Double_t &result, Double_t &error, Bool_t force = kFALSE);
29 Float_t GetAlpha() const {return fAlpha;}
30 inline Bool_t GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const;
e0b38166 31 inline Bool_t GetDataPoint(Int_t n, Float_t *p) const;
316a7f5a 32 TKDTreeIF* GetHelper() {return fKDhelper;}
117c62ab 33 Bool_t GetInterpolationMethod() const {return fStatus&1;}
34 Int_t GetNTNodes() const {return fNTNodes;}
35 Bool_t GetStore() const {return fStatus&2;}
36 Bool_t GetWeights() const {return fStatus&4;}
316a7f5a 37
38 void DrawNodes(UInt_t ax1 = 0, UInt_t ax2 = 1, Int_t depth = -1);
e0b38166 39 void DrawNode(Int_t tnode, UInt_t ax1 = 0, UInt_t ax2 = 1);
316a7f5a 40 void GetStatus();
117c62ab 41 void SetAlpha(const Float_t a){if(a>0.) fAlpha = a;}
42 void SetInterpolationMethod(const Bool_t on = kTRUE);
43 void SetStore(const Bool_t on = kTRUE);
44 void SetWeights(const Bool_t on = kTRUE);
316a7f5a 45
f2040a8f 46private:
a9c20b1f 47 TKDInterpolator(const TKDInterpolator &);
48 TKDInterpolator& operator=(const TKDInterpolator &);
e0b38166 49 void Build();
316a7f5a 50
117c62ab 51public:
52 class TKDNodeInfo
53 {
54 public:
55 TKDNodeInfo(const Int_t ndim = 0);
56 virtual ~TKDNodeInfo();
57 void Build(const Int_t ndim);
58 Double_t CookPDF(const Double_t *point, Double_t &result, Double_t &error);
59 void Store(const TVectorD &par, const TMatrixD &cov);
60
61 Int_t fNDim; // data dimension
62 Float_t *fRefPoint; //[fNDim] node's COG
63 Float_t fRefValue; // measured value for node
64 TMatrixD *fCov; // interpolator covariance matrix
65 TVectorD *fPar; // interpolator parameters
66
67 private:
68 TKDNodeInfo(const TKDNodeInfo &);
69 TKDNodeInfo& operator=(const TKDNodeInfo &);
70
71 ClassDef(TKDNodeInfo, 1) // node info for interpolator
72 };
73
f2040a8f 74protected:
75 Int_t fNTNodes; //Number of evaluation data points
5f38a39d 76 TKDNodeInfo *fTNodes; //[fNTNodes] interpolation node
f2040a8f 77
78private:
316a7f5a 79 UChar_t fStatus; // status of the interpolator
117c62ab 80 UChar_t fLambda; // number of parameters in polynom
81 Short_t fDepth; //! depth of the KD Tree structure used
82 Float_t fAlpha; // alpha parameter
5f38a39d 83 Float_t **fRefPoints; //! temporary storage of COG data
316a7f5a 84 Double_t *fBuffer; //! working space [2*fLambda]
85 TKDTreeIF *fKDhelper; //! kNN finder
86 TLinearFitter *fFitter; //! linear fitter
f2040a8f 87
88 ClassDef(TKDInterpolator, 1) // data interpolator based on KD tree
89};
90
91//__________________________________________________________________
5f38a39d 92Bool_t TKDInterpolator::GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &err) const
f2040a8f 93{
e0b38166 94 if(node < 0 || node > fNTNodes) return kFALSE;
f2040a8f 95
5f38a39d 96 for(int idim=0; idim<fNDim; idim++) coord[idim] = fTNodes[node].fRefPoint[idim];
97 val = fTNodes[node].fRefValue;
98 err = fTNodes[node].fRefValue/TMath::Sqrt(fBucketSize);
f2040a8f 99 return kTRUE;
100}
101
e0b38166 102//__________________________________________________________________
103Bool_t TKDInterpolator::GetDataPoint(Int_t n, Float_t *p) const
104{
105 if(n < 0 || n >= fNpoints) return kFALSE;
117c62ab 106 if(!fData) return kFALSE;
107
e0b38166 108 for(int i=0; i<fNDim; i++) p[i] = fData[i][n];
109 return kTRUE;
110}
111
112
f2040a8f 113#endif
114