f73c1e15e3007a8774e1238937839ba27bf94efe
[u/mrichter/AliRoot.git] / STAT / Macros / TestBuild.C
1 Int_t npoints = 301;
2 Int_t bsize = 10;
3
4 Float_t *data0 =  new Float_t[npoints*2];
5 Float_t *data[2];
6 data[0] = &data0[0];
7 data[1] = &data0[npoints];
8 Float_t dataf[] = {.54, .54};
9 TKDTreeIF* TestBuild(Int_t k = 5)
10 {
11         gStyle->SetOptStat(0);
12         
13         for (Int_t i=0;i<npoints;i++) {
14                 data[1][i]= gRandom->Gaus(.5, .1);
15                 data[0][i]= gRandom->Gaus(.5, .1);
16                 //data[1][i]= gRandom->Rndm();
17                 //data[0][i]= gRandom->Rndm();
18         }
19         //TKDTreeIF *tree = new TKDTreeIF(npoints, 2, bsize, data);
20         //TKDSpline *spline = new TKDSpline(npoints, 2, bsize, data);
21         //spline->DrawNodes(0, 1, depth);
22         TKDInterpolator *s = new TKDInterpolator(npoints, 2, bsize, data);
23         s->DrawNodes(-1);
24         TMarker *m = new TMarker(dataf[0], dataf[1], 20);
25         m->Draw();
26         TGraph *g=new TGraph(npoints);
27         g->SetMarkerStyle(7);
28         for(int ip=0; ip<npoints; ip++) g->SetPoint(ip, data[0][ip], data[1][ip]);
29         g->Draw("p");
30         
31         Int_t *index = 0x0;
32         Float_t dist;
33         s->FindNearestNeighbors(dataf, k, index, dist);
34         
35         TGraph *gNN=new TGraph(k);
36         gNN->SetMarkerStyle(24);
37         gNN->SetMarkerColor(2);
38         for(int i=0; i<k; i++){
39                 //printf("%d x %d y %d\n", i, index[i], index[i]);
40                 gNN->SetPoint(i, data[0][index[i]], data[1][index[i]]);
41         }
42         gNN->Draw("p");
43
44         return s;       
45 }