1 #include "TKDNodeInfo.h"
10 //_________________________________________________________________
11 TKDNodeInfo::TKDNodeInfo(Int_t dim):
18 // Default constructor
19 fVal[0] = 0.; fVal[1] = 0.;
23 //_________________________________________________________________
24 TKDNodeInfo::TKDNodeInfo(const TKDNodeInfo &ref):
25 TObject((TObject&) ref)
34 memcpy(fData, ref.fData, fNDim*sizeof(Float_t));
35 fVal[0] = ref.fVal[0];
36 fVal[1] = ref.fVal[1];
37 if(ref.fCov) (*fCov) = (*ref.fCov);
38 if(ref.fPar) (*fPar) = (*ref.fPar);
42 //_________________________________________________________________
43 TKDNodeInfo::~TKDNodeInfo()
46 if(fData) delete [] fData;
53 //_________________________________________________________________
54 TKDNodeInfo& TKDNodeInfo::operator=(const TKDNodeInfo & ref)
56 // Info("operator==()", "...");
59 if(fNDim != ref.fNDim){
63 memcpy(fData, ref.fData, fNDim*sizeof(Float_t));
64 fVal[0] = ref.fVal[0];
65 fVal[1] = ref.fVal[1];
66 if(ref.fCov) (*fCov) = (*ref.fCov);
67 if(ref.fPar) (*fPar) = (*ref.fPar);
72 //_________________________________________________________________
73 void TKDNodeInfo::Build(Int_t dim)
75 // Allocate/Reallocate space for this node.
77 // Info("Build()", "...");
81 Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1));
82 if(fData) delete [] fData;
83 fData = new Float_t[fNDim];
85 fCov->ResizeTo(lambda, lambda);
86 fPar->ResizeTo(lambda);
91 //_________________________________________________________________
92 void TKDNodeInfo::Print(const Option_t *) const
94 // Print the content of the node
97 for(int idim=0; idim<dim; idim++) printf("%f ", fData[idim]);
98 printf("] f = [%f +- %f]\n", fVal[0], fVal[1]);
100 // Float_t *bounds = &fData[dim];
102 for(int idim=0; idim<dim; idim++) printf("(%f %f) ", fData[2*idim], fData[2*idim+1]);
105 printf("Fit parameters : ");
107 printf("Not defined.\n");
111 // Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1));
112 for(int ip=0; ip<3; ip++) printf("p%d[%f] ", ip, (*fPar)(ip));
116 //_________________________________________________________________
117 void TKDNodeInfo::Store(const TVectorD &par, const TMatrixD &cov)
119 // Store the parameters and the covariance in the node
121 fCov = new TMatrixD(cov.GetNrows(), cov.GetNrows());
122 fPar = new TVectorD(par.GetNrows());
128 //_________________________________________________________________
129 Double_t TKDNodeInfo::CookPDF(const Double_t *point, Double_t &result, Double_t &error)
131 // Recalculate the PDF for one node from the results of interpolation (parameters and covariance matrix)
133 Int_t ndim = fNDim/3;
134 if(ndim>10) return 0.; // support only up to 10 dimensions
136 Int_t lambda = 1 + ndim + (ndim*(ndim+1)>>1);
140 for(int idim=0; idim<ndim; idim++){
141 fdfdp[ipar++] = point[idim];
142 for(int jdim=idim; jdim<ndim; jdim++) fdfdp[ipar++] = point[idim]*point[jdim];
145 // calculate estimation
146 result =0.; error = 0.;
147 for(int i=0; i<lambda; i++){
148 result += fdfdp[i]*(*fPar)(i);
149 for(int j=0; j<lambda; j++) error += fdfdp[i]*fdfdp[j]*(*fCov)(i,j);
151 error = TMath::Sqrt(error);
153 //printf("TKDNodeInfo::CookPDF() : %6.3f +- %6.3f\n", result, error);