6 #include "TClonesArray.h" 7 #include "TLinearFitter.h" 10 #include "TObjArray.h" 11 #include "TObjString.h" 36 ,fLambda(1 + dim + (dim*(dim+1)>>1))
54 Error(
"TKDInterpolatorBase::Build()",
"Minimum number of points [%d] needed for interpolation exceeds number of evaluation points [%d]. Please increase granularity.", Int_t((1.+
fAlpha)*fLambda), n);
59 Warning(
"TKDInterpolatorBase::Build()",
"Data already allocated.");
62 fNodes =
new TClonesArray(
"TKDNodeInfo", n);
75 Error(
"TKDInterpolatorBase::Bootstrap()",
"Nodes missing. Nothing to bootstrap from.");
81 Error(
"TKDInterpolatorBase::Bootstrap()",
"Node @ %d missing.", in);
110 if((h2 = (TH2S*)
gROOT->FindObject(
"hKDnodes")))
delete h2;
117 if(inode < 0 || inode >
GetNTNodes())
return kFALSE;
120 coord = &(node->
Data()[0]);
121 val = node->
Val()[0];
122 err = node->
Val()[1];
142 if(!
fNodes)
return kFALSE;
144 if(ax<0 || ax>=ndim){
148 min=1.e10; max=-1.e10;
149 Float_t axmin, axmax;
153 if(axmin<min) min = axmin;
154 if(axmax>max) max = axmax;
171 if(strcmp(opt,
"all") != 0 )
return;
190 for(
int idim=0; idim<
fNSize; idim++) pointF[idim] = (Float_t)point[idim];
193 Error(
"TKDInterpolatorBase::Eval()",
"Can not retrive node for data point.");
199 if(node->
Par() && !force){
201 return node->
CookPDF(point, result, error);
208 for(
int id=0;
id<
fNSize;
id++){
212 Info(
"TKDInterpolatorBase::Eval()",
"Build TKDTree(%d, %d, %d)",
GetNTNodes(), fNSize,
kNhelper);
228 Int_t *index =
new Int_t[2*npoints_new];
229 Float_t *dist =
new Float_t[2*npoints_new],
234 Bool_t kDOWN = kFALSE;
237 Info(
"TKDInterpolatorBase::Eval()",
"Interpolation failed. Trying to increase the number of interpolation points from %d to %d.",
npoints, npoints_new);
240 Error(
"TKDInterpolatorBase::Eval()",
"Interpolation failed and number of interpolation points (%d) Can not be increased further.",
npoints);
244 delete [] dist;
delete [] index;
248 Warning(
"TKDInterpolatorBase::Eval()",
"The number of interpolation points requested (%d) exceeds number of PDF values (%d). Downscale.",
npoints,
GetNTNodes());
254 for(
int idim=0; idim<
fNSize; idim++) pointF[idim] = (Float_t)point[idim];
260 for(
int in=0; in<
npoints; in++){
264 Float_t *
p = &(tnode->
Data()[0]);
266 for(
int idim=0; idim<
fNSize; idim++){
268 for(
int jdim=idim; jdim<
fNSize; jdim++)
fBuffer[ipar++] = p[idim]*p[jdim];
273 for(
int idim=0; idim<
fNSize; idim++){
274 fBuffer[ipar++] = .5*(bounds[2*idim] + bounds[2*idim+1]);
275 fBuffer[ipar++] = (bounds[2*idim]*bounds[2*idim] + bounds[2*idim] * bounds[2*idim+1] + bounds[2*idim+1] * bounds[2*idim+1])/3.;
276 for(
int jdim=idim+1; jdim<
fNSize; jdim++)
fBuffer[ipar++] = (bounds[2*idim] + bounds[2*idim+1]) * (bounds[2*jdim] + bounds[2*jdim+1]) * .25;
283 w0 = (1. - d*d*d); w = w0*w0*w0;
284 if(w<1.e-30)
continue;
292 npoints_new = npoints+ (kDOWN ? 0 :
kdN);
298 TMatrixD cov(fLambda, fLambda);
299 TVectorD par(fLambda);
300 fFitter->GetCovarianceMatrix(cov);
311 for(
int idim=0; idim<
fNSize; idim++){
312 fdfdp[ipar++] = point[idim];
313 for(
int jdim=idim; jdim<
fNSize; jdim++) fdfdp[ipar++] = point[idim]*point[jdim];
317 result =0.; error = 0.;
319 result += fdfdp[i]*par(i);
320 for(
int j=0; j<
fLambda; j++) error += fdfdp[i]*fdfdp[j]*cov(i,j);
322 error = TMath::Sqrt(error);
334 Float_t ax1min, ax1max, ax2min, ax2max;
338 if(!(h2 = (TH2S*)
gROOT->FindObject(
"hKDnodes"))){
339 h2 =
new TH2S(
"hKDnodes",
"", 100, ax1min, ax1max, 100, ax2min, ax2max);
341 h2->GetXaxis()->SetRangeUser(ax1min, ax1max);
342 h2->GetXaxis()->SetTitle(Form(
"x_{%d}", ax1));
343 h2->GetYaxis()->SetRangeUser(ax2min, ax2max);
344 h2->GetYaxis()->SetTitle(Form(
"x_{%d}", ax2));
363 Warning(
"TKDInterpolatorBase::SetAlpha()",
"The scale parameter has to be larger than 0.5");
370 Warning(
"TKDInterpolatorBase::SetAlpha()",
"Interpolation neighborhood exceeds number of evaluation points. Downscale alpha to %f",
fAlpha);
void SetNode(TKDNodeInfo *, UChar_t s, UChar_t ax1=0, UChar_t ax2=1)
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
void DrawProjection(UInt_t ax1=0, UInt_t ax2=1)
virtual Int_t GetNodeIndex(const Float_t *p)=0
Bool_t GetCOGPoint(Int_t node, Float_t *&coord, Float_t &val, Float_t &error) const
void GetBoundary(Int_t ax, Float_t &min, Float_t &max) const
Bool_t UseWeights() const
TKDNodeInfo::TKDNodeDraw * fNodesDraw
UChar_t fStatus
graphical representation of interpolation nodes
virtual Bool_t Build(Int_t nnodes)
TKDTree< Int_t, Float_t > * fKDhelper
working space [2*fLambda]
TClonesArray * fNodes
data dimension
TLinearFitter * fFitter
kNN finder
void Print(const Option_t *="") const
Bool_t GetRange(Int_t ax, Float_t &min, Float_t &max) const
TKDNodeInfo * GetNodeInfo(Int_t inode) const
void GetStatus(Option_t *opt="")
Float_t fAlpha
depth of the KD Tree structure used
Int_t GetDimension() const
virtual ~TKDInterpolatorBase()
class TKDTree< Int_t, Float_t > TKDTreeIF
Double_t * fBuffer
temporary storage of COG data
void Store(TVectorD const *par, TMatrixD const *cov=NULL)
Double_t Eval(const Double_t *point, Double_t &result, Double_t &error, Bool_t force=kFALSE)
Bool_t CookPDF(const Double_t *point, Double_t &result, Double_t &error) const
void Draw(Option_t *option="")