]>
Commit | Line | Data |
---|---|---|
f2040a8f | 1 | #ifndef ROOT_TKDInterpolator |
2 | #define ROOT_TKDInterpolator | |
3 | ||
4 | #ifndef ROOT_TKDTree | |
5 | #include "TKDTree.h" | |
6 | #endif | |
316a7f5a | 7 | #ifndef ROOT_TVectorD |
8 | #include "TVectorD.h" | |
9 | #endif | |
10 | #ifndef ROOT_TMatrixD | |
11 | #include "TMatrixD.h" | |
12 | #endif | |
13 | ||
f2040a8f | 14 | |
15 | class TTree; | |
16 | class TLinearFitter; | |
17 | class TKDInterpolator : public TKDTreeIF | |
18 | { | |
316a7f5a | 19 | public: |
20 | struct TKDNodeInfo | |
21 | { | |
5f38a39d | 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 | |
316a7f5a | 32 | |
33 | ClassDef(TKDNodeInfo, 1) // node info for interpolator | |
34 | }; | |
f2040a8f | 35 | public: |
36 | TKDInterpolator(); | |
316a7f5a | 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); |
f2040a8f | 38 | TKDInterpolator(Int_t npoints, Int_t ndim, UInt_t bsize, Float_t **data); |
39 | ~TKDInterpolator(); | |
e0b38166 | 40 | |
316a7f5a | 41 | Double_t Eval(const Double_t *point, Double_t &result, Double_t &error); |
e0b38166 | 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; | |
316a7f5a | 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); | |
e0b38166 | 50 | void DrawNode(Int_t tnode, UInt_t ax1 = 0, UInt_t ax2 = 1); |
316a7f5a | 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 | ||
f2040a8f | 56 | private: |
a9c20b1f | 57 | TKDInterpolator(const TKDInterpolator &); |
58 | TKDInterpolator& operator=(const TKDInterpolator &); | |
e0b38166 | 59 | void Build(); |
316a7f5a | 60 | Double_t CookPDF(const Double_t *point, const Int_t node, Double_t &result, Double_t &error); |
61 | ||
f2040a8f | 62 | protected: |
63 | Int_t fNTNodes; //Number of evaluation data points | |
5f38a39d | 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 | |
f2040a8f | 69 | |
70 | private: | |
316a7f5a | 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 | |
5f38a39d | 74 | Float_t **fRefPoints; //! temporary storage of COG data |
316a7f5a | 75 | Double_t *fBuffer; //! working space [2*fLambda] |
76 | TKDTreeIF *fKDhelper; //! kNN finder | |
77 | TLinearFitter *fFitter; //! linear fitter | |
f2040a8f | 78 | |
79 | ClassDef(TKDInterpolator, 1) // data interpolator based on KD tree | |
80 | }; | |
81 | ||
82 | //__________________________________________________________________ | |
5f38a39d | 83 | Bool_t TKDInterpolator::GetCOGPoint(Int_t node, Float_t *coord, Float_t &val, Float_t &err) const |
f2040a8f | 84 | { |
e0b38166 | 85 | if(node < 0 || node > fNTNodes) return kFALSE; |
f2040a8f | 86 | |
5f38a39d | 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); | |
f2040a8f | 90 | return kTRUE; |
91 | } | |
92 | ||
e0b38166 | 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 | ||
f2040a8f | 103 | #endif |
104 |