1 #include "TKDNodeInfo.h"
10 //_________________________________________________________________
11 TKDNodeInfo::TKDNodeInfo(const Int_t dim):
18 fVal[0] = 0.; fVal[1] = 0.;
22 //_________________________________________________________________
23 TKDNodeInfo::TKDNodeInfo(const TKDNodeInfo &ref):
24 TObject((TObject&) ref)
32 memcpy(fData, ref.fData, fNDim*sizeof(Float_t));
33 fVal[0] = ref.fVal[0];
34 fVal[1] = ref.fVal[1];
35 if(ref.fCov) (*fCov) = (*ref.fCov);
36 if(ref.fPar) (*fPar) = (*ref.fPar);
40 //_________________________________________________________________
41 TKDNodeInfo::~TKDNodeInfo()
43 if(fData) delete [] fData;
50 //_________________________________________________________________
51 TKDNodeInfo& TKDNodeInfo::operator=(const TKDNodeInfo & ref)
53 // Info("operator==()", "...");
56 if(fNDim != ref.fNDim){
60 memcpy(fData, ref.fData, fNDim*sizeof(Float_t));
61 fVal[0] = ref.fVal[0];
62 fVal[1] = ref.fVal[1];
63 if(ref.fCov) (*fCov) = (*ref.fCov);
64 if(ref.fPar) (*fPar) = (*ref.fPar);
69 //_________________________________________________________________
70 void TKDNodeInfo::Build(const Int_t dim)
72 // Allocate/Reallocate space for this node.
74 // Info("Build()", "...");
78 Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1));
79 if(fData) delete [] fData;
80 fData = new Float_t[fNDim];
82 fCov->ResizeTo(lambda, lambda);
83 fPar->ResizeTo(lambda);
88 //_________________________________________________________________
89 void TKDNodeInfo::Print()
93 for(int idim=0; idim<dim; idim++) printf("%f ", fData[idim]);
94 printf("] f = [%f +- %f]\n", fVal[0], fVal[1]);
96 Float_t *bounds = &fData[dim];
98 for(int idim=0; idim<dim; idim++) printf("(%f %f) ", fData[2*idim], fData[2*idim+1]);
101 printf("Fit parameters : ");
103 printf("Not defined.\n");
107 Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1));
108 for(int ip=0; ip<3; ip++) printf("p%d[%f] ", ip, (*fPar)(ip));
112 //_________________________________________________________________
113 void TKDNodeInfo::Store(const TVectorD &par, const TMatrixD &cov)
116 fCov = new TMatrixD(cov.GetNrows(), cov.GetNrows());
117 fPar = new TVectorD(par.GetNrows());
123 //_________________________________________________________________
124 Double_t TKDNodeInfo::CookPDF(const Double_t *point, Double_t &result, Double_t &error)
126 // Recalculate the PDF for one node from the results of interpolation (parameters and covariance matrix)
128 Int_t ndim = fNDim/3;
129 if(ndim>10) return 0.; // support only up to 10 dimensions
131 Int_t lambda = 1 + ndim + (ndim*(ndim+1)>>1);
135 for(int idim=0; idim<ndim; idim++){
136 fdfdp[ipar++] = point[idim];
137 for(int jdim=idim; jdim<ndim; jdim++) fdfdp[ipar++] = point[idim]*point[jdim];
140 // calculate estimation
141 result =0.; error = 0.;
142 for(int i=0; i<lambda; i++){
143 result += fdfdp[i]*(*fPar)(i);
144 for(int j=0; j<lambda; j++) error += fdfdp[i]*fdfdp[j]*(*fCov)(i,j);
146 error = TMath::Sqrt(error);
148 //printf("TKDNodeInfo::CookPDF() : %6.3f +- %6.3f\n", result, error);