6 gSystem->AddIncludePath("-I$ALICE_ROOT/STAT")
7 gSystem->Load("$ALICE_ROOT/lib/tgt_linux/libSTAT.so");
8 .L $ALICE_ROOT/STAT/Macros/kDTreeTest.C+
11 TestBuild(); // test build function of kdTree for memory leaks
12 TestSpeed(); // test the CPU consumption to build kdTree
13 TestkdtreeIF(); // test functionality of the kdTree
14 TestSizeIF(); // test the size of kdtree - search application - Alice TPC tracker situation
23 #include "TStopwatch.h"
29 void TestBuild(const Int_t npoints = 1000000, const Int_t bsize = 100);
30 void TestSpeed(const Int_t npower2 = 20, const Int_t bsize = 10);
32 void TestkdtreeIF(Int_t npoints=1000, Int_t bsize=9, Int_t nloop=1000, Int_t mode = 2);
33 void TestSizeIF(Int_t nsec=36, Int_t nrows=159, Int_t npoints=1000, Int_t bsize=10, Int_t mode=1);
41 gSystem->GetProcInfo(&procInfo);
42 return procInfo.fMemVirtual;
45 //______________________________________________________________________
51 printf("\n\tTesting kDTree memory usage ...\n");
53 printf("\n\tTesting kDTree speed ...\n");
57 //______________________________________________________________________
58 void TestBuild(const Int_t npoints, const Int_t bsize){
60 // Test kdTree for memory leaks
62 Float_t *data0 = new Float_t[npoints*2];
65 data[1] = &data0[npoints];
66 for (Int_t i=0;i<npoints;i++) {
67 data[1][i]= gRandom->Rndm();
68 data[0][i]= gRandom->Rndm();
70 Float_t before =Mem();
71 TKDTreeIF *kdtree = new TKDTreeIF(npoints, 2, bsize, data);
72 Float_t after = Mem();
73 printf("Memory usage %f KB\n",after-before);
76 printf("Memory leak %f KB\n", end-before);
80 //______________________________________________________________________
81 void TestSpeed(const Int_t npower2, const Int_t bsize)
84 // Test of building time of kdTree
87 printf("Please specify a power of 2 greater than 10\n");
91 Int_t npoints = Int_t(pow(2., npower2))*bsize;
92 Float_t *data0 = new Float_t[npoints*2];
95 data[1] = &data0[npoints];
96 for (Int_t i=0;i<npoints;i++) {
97 data[1][i]= gRandom->Rndm();
98 data[0][i]= gRandom->Rndm();
101 TGraph *g = new TGraph(npower2-10);
102 g->SetMarkerStyle(7);
105 TKDTreeIF *kdtree = 0x0;
106 for(int i=10; i<npower2; i++){
107 tpoints = Int_t(pow(2., i))*bsize;
109 kdtree = new TKDTreeIF(tpoints, 2, bsize, data);
111 g->SetPoint(i-10, i, timer.CpuTime());
112 printf("npoints [%d] nodes [%d] cpu time %f [s]\n", tpoints, kdtree->GetNNodes(), timer.CpuTime());
120 //______________________________________________________________________
121 void TestSizeIF(Int_t nsec, Int_t nrows, Int_t npoints, Int_t bsize, Int_t mode)
124 // Test size to build kdtree
126 Float_t before =Mem();
127 for (Int_t isec=0; isec<nsec;isec++)
128 for (Int_t irow=0;irow<nrows;irow++){
129 TestkdtreeIF(npoints,1,mode,bsize);
131 Float_t after = Mem();
132 printf("Memory usage %f\n",after-before);
138 void TestkdtreeIF(Int_t npoints, Int_t bsize, Int_t nloop, Int_t mode)
141 // Test speed and functionality of 2D kdtree.
143 // npoints - number of data points
144 // bsize - bucket size
145 // nloop - number of loops
146 // mode - tasks to be performed by the kdTree
147 // - 0 : time building the tree
151 Float_t rangey = 100;
152 Float_t rangez = 100;
153 Float_t drangey = 0.1;
154 Float_t drangez = 0.1;
157 Float_t *data0 = new Float_t[npoints*2];
160 data[1] = &data0[npoints];
162 for (i=0; i<npoints; i++){
163 data[0][i] = gRandom->Uniform(-rangey, rangey);
164 data[1][i] = gRandom->Uniform(-rangez, rangez);
169 printf("building kdTree ...\n");
171 TKDTreeIF *kdtree = new TKDTreeIF(npoints, 2, bsize, data);
174 if(mode == 0) return;
177 Float_t counteriter = 0;
178 Float_t counterfound = 0;
181 if (nloop) timer.Start(kTRUE);
184 for (Int_t kloop = 0;kloop<nloop;kloop++){
190 for (Int_t i=0;i<npoints;i++){
191 Float_t point[2]={data[0][i],data[1][i]};
192 Float_t delta[2]={drangey,drangez};
196 //kdtree->FindBNode(point,delta, bnode);
198 kdtree->FindInRangeA(point,delta,res,nfound,iter,bnode);
200 //Bool_t isOK = kTRUE;
201 Bool_t isOK = kFALSE;
202 for (Int_t ipoint=0;ipoint<nfound;ipoint++)
203 if (res[ipoint]==i) isOK =kTRUE;
205 counterfound+=nfound;
222 counteriter/=npoints;
223 counterfound/=npoints;
224 if (nloop) printf("Find nearest point:\t%f\t%f\t%f\n",countern, counteriter, counterfound);