X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=blobdiff_plain;f=STAT%2FTKDInterpolator.h;h=b073c7157d58be03472aafe9f46987831825c3ed;hp=bd91349987690430027ea072eb68517db9840030;hb=1adc956a952a783352b2a542fac74e75981885fa;hpb=5f38a39d82eb46a4ba4f082ba757c8259552df81 diff --git a/STAT/TKDInterpolator.h b/STAT/TKDInterpolator.h index bd913499876..b073c7157d5 100644 --- a/STAT/TKDInterpolator.h +++ b/STAT/TKDInterpolator.h @@ -4,6 +4,7 @@ #ifndef ROOT_TKDTree #include "TKDTree.h" #endif + #ifndef ROOT_TVectorD #include "TVectorD.h" #endif @@ -11,66 +12,81 @@ #include "TMatrixD.h" #endif +// Non parametric interpolation class based on local polinomial regression. +// The class can be used to approximate PDF together with TKDTree or for +// general regression when the data points are given. +// template class TVectorT; +// typedef struct TVectorT TVectorD; +// template class TMatrixT; +// typedef class TMatrixT TMatrixD; +// template class TKDTree; +// typedef class TKDTree TKDTreeIF; class TTree; class TLinearFitter; class TKDInterpolator : public TKDTreeIF { -public: - struct TKDNodeInfo - { - TKDNodeInfo(const Int_t ndim = 0); - ~TKDNodeInfo(); - void Build(const Int_t ndim); - - Int_t fNDim; // data dimension - Float_t *fRefPoint; //[fNDim] node's COG - Float_t fRefValue; // measured value for node - TMatrixD fCov; // interpolator covariance matrix - TVectorD fPar; // interpolator parameters - Bool_t fPDFstatus; // status bit for node's PDF - - ClassDef(TKDNodeInfo, 1) // node info for interpolator - }; public: TKDInterpolator(); TKDInterpolator(TTree *t, const Char_t *var, const Char_t *cut = 0, UInt_t bsize = 100, Long64_t nentries = 1000000000, Long64_t firstentry = 0); TKDInterpolator(Int_t npoints, Int_t ndim, UInt_t bsize, Float_t **data); ~TKDInterpolator(); - Double_t Eval(const Double_t *point, Double_t &result, Double_t &error); - inline Bool_t GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const ; + Double_t Eval(const Double_t *point, Double_t &result, Double_t &error, Bool_t force = kFALSE); + Float_t GetAlpha() const {return fAlpha;} + inline Bool_t GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &error) const; inline Bool_t GetDataPoint(Int_t n, Float_t *p) const; TKDTreeIF* GetHelper() {return fKDhelper;} - inline Bool_t GetIntInterpolation() const {return fStatus&1;} - inline Bool_t GetSetStore() const {return fStatus&2;} - inline Bool_t GetUseWeights() const {return fStatus&4;} + Bool_t GetInterpolationMethod() const {return fStatus&1;} + Int_t GetNTNodes() const {return fNTNodes;} + Bool_t GetStore() const {return fStatus&2;} + Bool_t GetWeights() const {return fStatus&4;} void DrawNodes(UInt_t ax1 = 0, UInt_t ax2 = 1, Int_t depth = -1); void DrawNode(Int_t tnode, UInt_t ax1 = 0, UInt_t ax2 = 1); void GetStatus(); - void SetIntInterpolation(const Bool_t on = kTRUE); - void SetSetStore(const Bool_t on = kTRUE); - void SetUseWeights(const Bool_t on = kTRUE); + void SetAlpha(const Float_t a){if(a>0.) fAlpha = a;} + void SetInterpolationMethod(const Bool_t on = kTRUE); + void SetStore(const Bool_t on = kTRUE); + void SetWeights(const Bool_t on = kTRUE); private: TKDInterpolator(const TKDInterpolator &); TKDInterpolator& operator=(const TKDInterpolator &); void Build(); - Double_t CookPDF(const Double_t *point, const Int_t node, Double_t &result, Double_t &error); +public: + class TKDNodeInfo + { + public: + TKDNodeInfo(const Int_t ndim = 0); + virtual ~TKDNodeInfo(); + void Build(const Int_t ndim); + Double_t CookPDF(const Double_t *point, Double_t &result, Double_t &error); + void Store(const TVectorD &par, const TMatrixD &cov); + + Int_t fNDim; // data dimension + Float_t *fRefPoint; //[fNDim] node's COG + Float_t fRefValue; // measured value for node + TMatrixD *fCov; // interpolator covariance matrix + TVectorD *fPar; // interpolator parameters + + private: + TKDNodeInfo(const TKDNodeInfo &); + TKDNodeInfo& operator=(const TKDNodeInfo &); + + ClassDef(TKDNodeInfo, 1) // node info for interpolator + }; + protected: Int_t fNTNodes; //Number of evaluation data points TKDNodeInfo *fTNodes; //[fNTNodes] interpolation node -// Float_t *fRefValues; //[fNTNodes] -// TMatrixD *fCov; //[fNTNodes] cov matrix array for nodes -// TVectorD *fPar; //[fNTNodes] parameters array for nodes -// Bool_t *fPDFstatus; //[fNTNodes] status bit for node's PDF private: UChar_t fStatus; // status of the interpolator - Int_t fLambda; // number of parameters in polynom - Int_t fDepth; //! depth of the KD Tree structure used + UChar_t fLambda; // number of parameters in polynom + Short_t fDepth; //! depth of the KD Tree structure used + Float_t fAlpha; // alpha parameter Float_t **fRefPoints; //! temporary storage of COG data Double_t *fBuffer; //! working space [2*fLambda] TKDTreeIF *fKDhelper; //! kNN finder @@ -94,7 +110,8 @@ Bool_t TKDInterpolator::GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Fl Bool_t TKDInterpolator::GetDataPoint(Int_t n, Float_t *p) const { if(n < 0 || n >= fNpoints) return kFALSE; - + if(!fData) return kFALSE; + for(int i=0; i