AliRoot Core  3dc7879 (3dc7879)
TKDNodeInfo.h
Go to the documentation of this file.
1 #ifndef ROOT_TKDNodeInfo
2 #define ROOT_TKDNodeInfo
3 
5 //
6 // Bucket representation for TKDInterpolator(Base)
7 //
8 // Author Alexandru Bercuci <A.Bercuci@gsi.de>
9 //
11 
12 #ifndef ROOT_TObject
13 #include "TObject.h"
14 #endif
15 
16 #ifndef ROOT_TBox
17 #include "TBox.h"
18 #endif
19 
20 #ifndef ROOT_TMarker
21 #include "TMarker.h"
22 #endif
23 
24 #include <TVectorD.h>
25 #include <TMatrixD.h>
26 
27 class TKDNodeInfo : public TObject
28 {
29 public:
30  friend class TKDPDF;
31  friend class TKDInterpolatorBase;
32  class TKDNodeDraw : public TBox {
33  public:
34  TKDNodeDraw();
36  void Draw(Option_t* option = "");
37  void Print(const Option_t* option = "") const; // *MENU*
38  void SetNode(TKDNodeInfo*, UChar_t s, UChar_t ax1=0, UChar_t ax2=1);
39  private:
40  TKDNodeDraw(const TKDNodeDraw & ref);
41  TKDNodeDraw& operator=(const TKDNodeDraw & ref);
42 
43  TMarker fCOG; // COG of the node
45  ClassDef(TKDNodeDraw, 1) // graphical representation of TKDNodeInfo
46  };
47 
48  TKDNodeInfo(Int_t ndim = 0);
49  TKDNodeInfo(const TKDNodeInfo & ref);
50  TKDNodeInfo& operator=(const TKDNodeInfo & ref);
51  virtual ~TKDNodeInfo();
52  Bool_t CookPDF(const Double_t *point, Double_t &result, Double_t &error) const;
53  inline void GetBoundary(Int_t ax, Float_t &min, Float_t &max) const;
54  inline void GetCOG(Float_t* &p) const;
55  Int_t GetDimension() const { return fNDim/3; }
56  void GetPDF(Float_t &pdf, Float_t &error) const {pdf=fVal[0]; error=fVal[1];}
57  Int_t GetSize() const { return fNDim; }
58  Int_t GetNcov() const { return fNcov; }
59  Int_t GetNpar() const { return fNpar; }
60  inline Bool_t Has(const Float_t *p) const;
61  void Print(const Option_t * = "") const;
62  void Store(TVectorD const *par, TMatrixD const *cov=NULL);
63 
64  Double_t* Cov() const { return fCov; }
65  Double_t* Par() const { return fPar; }
66 
67  void SetNode(Int_t ndim, Float_t *data, Float_t *pdf);
68 protected:
69  void Bootstrap();
70  void Build(Int_t ndim);
71  void SetNcov() { fNcov=Int_t(.5*fNpar*(fNpar+1.));}
72  void SetNpar() { Int_t dim=Int_t(fNDim/3); fNpar=Int_t(1 + dim + .5*dim*(dim+1));}
73  Float_t* Data() { return fData;}
74  Float_t* Val() { return &fVal[0]; }
75 
76 
77 private:
78  Int_t fNDim;
79  Float_t *fData;
80  Float_t fVal[2];
81  Int_t fNpar; //number of parameters
82  Int_t fNcov; //number of covarince elements
83  Double_t *fPar; //[fNpar] interpolator parameters
84  Double_t *fCov; //[fNcov] interpolator covariance matrix
85 
86 
87  ClassDef(TKDNodeInfo, 2) // node info for interpolator
88 };
89 
90 //_____________________________________________________________________
91 inline Bool_t TKDNodeInfo::Has(const Float_t *p) const
92 {
93  Int_t ndim = fNDim/3;
94 
95  Float_t *it = &fData[ndim]; Int_t n(0);
96  for(int id=0; id<ndim; id++, it+=2)
97  if(p[id]>=it[0] && p[id]<it[1]) n++;
98  if(n==ndim) return kTRUE;
99  return kFALSE;
100 }
101 
102 //_____________________________________________________________________
103 inline void TKDNodeInfo::GetBoundary(Int_t ax, Float_t &min, Float_t &max) const
104 {
105  Int_t ndim = fNDim/3;
106  if(ax<0 || ax>=ndim){
107  min=0.; max=0.;
108  return;
109  }
110  Float_t *it = &fData[ndim+(ax<<1)];
111  min = it[0]; max = it[1];
112 }
113 
114 //_____________________________________________________________________
115 inline void TKDNodeInfo::GetCOG(Float_t* &p) const
116 {
117  Int_t ndim = fNDim/3;
118  memcpy(p, fData, ndim*sizeof(Float_t));
119 }
120 
121 #endif
122 
void SetNode(TKDNodeInfo *, UChar_t s, UChar_t ax1=0, UChar_t ax2=1)
Int_t GetNcov() const
Definition: TKDNodeInfo.h:58
void SetNcov()
Definition: TKDNodeInfo.h:71
void Build(Int_t ndim)
Int_t GetNpar() const
Definition: TKDNodeInfo.h:59
Bool_t Has(const Float_t *p) const
Definition: TKDNodeInfo.h:91
void SetNpar()
Definition: TKDNodeInfo.h:72
void GetBoundary(Int_t ax, Float_t &min, Float_t &max) const
Definition: TKDNodeInfo.h:103
Float_t p[]
Definition: kNNTest.C:133
Int_t GetSize() const
Definition: TKDNodeInfo.h:57
TKDNodeDraw & operator=(const TKDNodeDraw &ref)
Definition: TKDPDF.h:20
void Bootstrap()
Double_t * Cov() const
Definition: TKDNodeInfo.h:64
void GetCOG(Float_t *&p) const
Definition: TKDNodeInfo.h:115
Int_t fNDim
Definition: TKDNodeInfo.h:78
Float_t * Val()
Definition: TKDNodeInfo.h:74
Float_t fVal[2]
[fNDim] node&#39;s data
Definition: TKDNodeInfo.h:80
TKDNodeInfo(Int_t ndim=0)
Definition: TKDNodeInfo.cxx:32
Float_t * fData
3 times data dimension
Definition: TKDNodeInfo.h:79
Double_t * Par() const
Definition: TKDNodeInfo.h:65
void Print(const Option_t *option="") const
Float_t * Data()
Definition: TKDNodeInfo.h:73
Int_t GetDimension() const
Definition: TKDNodeInfo.h:55
virtual ~TKDNodeInfo()
Definition: TKDNodeInfo.cxx:77
Double_t * fPar
Definition: TKDNodeInfo.h:83
Double_t * fCov
Definition: TKDNodeInfo.h:84
void Store(TVectorD const *par, TMatrixD const *cov=NULL)
Int_t fNpar
measured value for node
Definition: TKDNodeInfo.h:81
Bool_t CookPDF(const Double_t *point, Double_t &result, Double_t &error) const
void GetPDF(Float_t &pdf, Float_t &error) const
Definition: TKDNodeInfo.h:56
void Draw(Option_t *option="")
Int_t fNcov
Definition: TKDNodeInfo.h:82