17 template<
class _DataPo
int>
18 void CreatePseudoData(
const unsigned long int nPoints,std::vector<const _DataPoint*>& vDataPoints)
20 _DataPoint* pData = 0;
21 for(
unsigned long int i = 0; i < nPoints; ++i)
23 pData =
new _DataPoint();
24 for(
unsigned int k = 0; k < _DataPoint::Dimension(); ++k)
25 pData->SetCoordinate(k,rand() % 1000);
26 pData->SetWeight(rand() % 1000);
27 vDataPoints.push_back(pData);
31 template<
class _DataPo
int>
34 for(
typename std::vector<const _DataPoint*>::iterator it = vDataPoints.begin();
35 it != vDataPoints.end(); ++it)
41 template<
class _DataPo
int>
50 for(
typename std::vector<const _DataPoint*>::const_iterator it = vDataPoints.begin(); it != vDataPoints.end(); ++it)
53 catch (std::exception& e)
55 std::cerr <<
"exception caught: " << e.what() << std::endl;
65 template<
class _DataPo
int>
70 std::cout <<
" --> wrong number of data points in tree: " << pTree->
GetEntries() <<
" != " << vDataPoints.size() << std::endl;
76 for(
typename std::vector<const _DataPoint*>::const_iterator it = vDataPoints.begin();
77 it != vDataPoints.end(); ++it)
79 fSumw += (*it)->GetWeight();
80 fSumw2 +=
pow((*it)->GetWeight(),2);
85 std::cout <<
" --> inconsistent Sum weights^2 in tree: " << pTree->
GetTotalSumw2() <<
" != " << fSumw2 << std::endl;
91 std::cout <<
" --> inconsistent Sum weights in tree: " << pTree->
GetTotalSumw() <<
" != " << fSumw << std::endl;
97 std::cout <<
" --> inconsistent effective entries in tree: " << pTree->
GetEffectiveEntries() <<
" != " <<
pow(fSumw,2)/fSumw2 << std::endl;
104 template<
class _DataPo
int>
107 typedef std::pair<typename _DataPoint::value_type,typename _DataPoint::value_type> tBoundary;
109 std::cout <<
" --> checking " << pTree->
GetNBins() <<
" bins" << std::endl;
111 unsigned int iBin = 0;
114 const std::vector<const _DataPoint*> vDataPoints = it.TN()->GetPoints();
115 assert(vDataPoints.size() == it->GetEntries());
117 std::vector<tBoundary> vBoundaries = it->GetBoundaries();
118 assert(_DataPoint::Dimension() == vBoundaries.size());
121 for(
typename std::vector<const _DataPoint*>::const_iterator pit = vDataPoints.begin();
122 pit != vDataPoints.end(); ++pit)
124 for(
unsigned int k = 0; k < _DataPoint::Dimension(); ++k)
126 if(((*pit)->GetCoordinate(k) < vBoundaries.at(k).first) || ((*pit)->GetCoordinate(k) > vBoundaries.at(k).second))
128 std::cout <<
" --> boundaries of bin " << iBin <<
" in " << k <<
". dimension are inconsistent with data point in bucket" << std::endl;
138 template<
class _DataPo
int>
145 std::cout <<
" --> found bin with " << it->GetEffectiveEntries() <<
" while the bucketsize is " << pTree->
GetBucketSize() << std::endl;
153 template<
class _DataPo
int>
156 typedef std::pair<typename _DataPoint::value_type,typename _DataPoint::value_type> tBoundary;
159 std::cout <<
" --> test reference point at (";
160 for(
unsigned int k = 0; k < _DataPoint::Dimension(); ++k)
162 test.SetCoordinate(k,rand() % 1000);
163 std::cout << test.GetCoordinate(k);
164 if(k < _DataPoint::Dimension()-1)
167 std::cout <<
")" << std::endl;
174 assert(_DataPoint::Dimension() == vBoundaries.size());
176 for(
unsigned int k = 0; k < _DataPoint::Dimension(); ++k)
178 if((test.GetCoordinate(k) < vBoundaries.at(k).first) || (test.GetCoordinate(k) > vBoundaries.at(k).second))
182 std::cout <<
" --> " << test.GetCoordinate(k) <<
" is not within (" << vBoundaries.at(k).first <<
"," << vBoundaries.at(k).second <<
")" << std::endl;
191 template<
class _DataPo
int>
195 std::cout <<
" --> test with reference point at (";
196 for(
unsigned int k = 0; k < _DataPoint::Dimension(); ++k)
198 test.SetCoordinate(k,rand() % 1000);
199 std::cout << test.GetCoordinate(k);
200 if(k < _DataPoint::Dimension()-1)
203 std::cout <<
")" << std::endl;
205 std::vector<const _DataPoint*> vFoundPoints;
206 std::vector<const _DataPoint*> vFoundPointsCheck;
208 double fDist = rand() % 500;
209 std::cout <<
" --> look for points within in distance of " << fDist << std::endl;
213 for(
typename std::vector<const _DataPoint*>::const_iterator it = vDataPoints.begin();
214 it != vDataPoints.end(); ++it)
216 if((*it)->Distance(test) <= fDist)
218 vFoundPointsCheck.push_back(*it);
220 bool bChecked =
false;
221 for(
unsigned int i = 0; i < vFoundPoints.size(); ++i)
223 if(vFoundPoints.at(i) == *it)
232 std::cout <<
" --> point (";
233 for(
unsigned int k = 0; k < _DataPoint::Dimension(); ++k)
235 std::cout << (*it)->GetCoordinate(k);
236 if(k < _DataPoint::Dimension()-1)
239 std::cout <<
") was not found by the algorithm while its distance to the reference point is " << (*it)->Distance(test) << std::endl;
246 if(vFoundPointsCheck.size() != vFoundPoints.size())
248 std::cout <<
" --> GetPointsWithinDist returns wrong number of found points (" << vFoundPointsCheck.size() <<
" expected/ " << vFoundPoints.size() <<
" found)" << std::endl;
252 const int nNeighbors = (int)(rand() % 100/1000.0 * pTree->
GetEntries() + 1);
253 std::cout <<
" --> look for " << nNeighbors <<
" nearest neighbors" << std::endl;
255 std::vector<std::pair<const _DataPoint*,double> > vFoundNeighbors;
256 std::vector<std::pair<const _DataPoint*,double> > vFoundNeighborsCheck;
257 typename std::vector<std::pair<const _DataPoint*,double> >::iterator nit;
260 fDist = vFoundNeighbors.back().second;
263 for(
typename std::vector<const _DataPoint*>::const_iterator it = vDataPoints.begin();
264 it != vDataPoints.end(); ++it)
266 if((*it)->Distance(test) <= fDist)
267 vFoundNeighborsCheck.push_back(std::make_pair(*it,(*it)->Distance(test)));
271 if(vFoundNeighborsCheck.size() < vFoundNeighbors.size())
273 std::cout <<
" --> GetClosestPoints returns wrong number of found points (" << vFoundNeighborsCheck.size() <<
" expected/ " << vFoundNeighbors.size() <<
" found)" << std::endl;
278 bool bChecked =
false;
279 for(
unsigned int i = 0; i < vFoundNeighbors.size(); ++i)
282 for(
unsigned int j = 0; j < vFoundNeighborsCheck.size(); ++j)
284 if(vFoundNeighbors.at(i).first == vFoundNeighborsCheck.at(j).first)
286 if(
fabs(vFoundNeighbors.at(i).second - vFoundNeighborsCheck.at(j).second)/vFoundNeighbors.at(i).second < 1e-2)
300 template<
class _DataPo
int>
306 std::cout <<
" --> tree contains still " << pTree->
GetEntries() <<
" data points after calling Clear()" << std::endl;
311 std::cout <<
" --> tree contains more than one bin after calling Clear()" << std::endl;
316 std::cout <<
" --> tree contains still " << pTree->
GetEffectiveEntries() <<
" effective entries after calling Clear()" << std::endl;
323 for(
typename std::vector<const _DataPoint*>::const_iterator it = vDataPoints.begin(); it != vDataPoints.end(); ++it)
326 catch (std::exception& e)
328 std::cout <<
" --> unable to fill tree after calling Clear()" << std::endl;
329 std::cerr <<
"exception caught: " << e.what() << std::endl;
339 std::cout <<
"\nunit test for class KDTree" << std::endl;
340 std::cout <<
"==========================\n" << std::endl;
343 std::cout <<
"using random seed: " << iSeed << std::endl;
347 const unsigned long int NPOINTS = 1e5;
348 const unsigned int BUCKETSIZE = 1e2;
349 const unsigned int DIM = 5;
353 std::cout <<
"using " << NPOINTS <<
" data points in " << DIM <<
" dimensions" << std::endl;
354 std::cout <<
"bucket size: " << BUCKETSIZE << std::endl;
356 std::vector<const DP*> vDataPoints;
362 std::cerr <<
"basic tree properties...DONE" << std::endl;
364 std::cerr <<
"basic tree properties...FAILED" << std::endl;
367 std::cerr <<
"consistency check of bin boundaries...DONE" << std::endl;
369 std::cerr <<
"consistency check of bin boundaries...FAILED" << std::endl;
372 std::cerr <<
"check effective entries per bin...DONE" << std::endl;
374 std::cerr <<
"check effective entries per bin...FAILED" << std::endl;
377 std::cerr <<
"check FindBin...DONE" << std::endl;
379 std::cerr <<
"check FindBin...FAILED" << std::endl;
382 std::cerr <<
"check nearest neighbor searches...DONE" << std::endl;
384 std::cerr <<
"check nearest neighbor searches...FAILED" << std::endl;
387 std::cerr <<
"check KDTree::Clear...DONE" << std::endl;
389 std::cerr <<
"check KDTree:Clear...FAILED" << std::endl;
void DeletePseudoData(std::vector< const _DataPoint * > &vDataPoints)
Bool_t Insert(const point_type &rData)
bool CheckNearestNeighborSearches(const ROOT::Math::KDTree< _DataPoint > *pTree, const std::vector< const _DataPoint * > &vDataPoints)
Double_t GetEffectiveEntries() const
bool CheckTreeClear(ROOT::Math::KDTree< _DataPoint > *pTree, const std::vector< const _DataPoint * > &vDataPoints)
bool CheckBasicTreeProperties(const ROOT::Math::KDTree< _DataPoint > *pTree, const std::vector< const _DataPoint * > &vDataPoints)
double pow(double, double)
ROOT::Math::KDTree< _DataPoint > * BuildTree(const std::vector< const _DataPoint * > &vDataPoints, const unsigned int iBucketSize)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
bool CheckFindBin(const ROOT::Math::KDTree< _DataPoint > *pTree)
Double_t GetTotalSumw2() const
void GetClosestPoints(const point_type &rRef, UInt_t nPoints, std::vector< std::pair< const _DataPoint *, Double_t > > &vFoundPoints) const
Double_t GetTotalSumw() const
Double_t GetBucketSize() const
void CreatePseudoData(const unsigned long int nPoints, std::vector< const _DataPoint * > &vDataPoints)
const Bin * FindBin(const point_type &rPoint) const
bool CheckEffectiveBinEntries(const ROOT::Math::KDTree< _DataPoint > *pTree)
KDTree< _DataPoint > * GetFrozenCopy()
virtual const std::vector< tBoundary > & GetBoundaries() const
bool CheckBinBoundaries(const ROOT::Math::KDTree< _DataPoint > *pTree)
UInt_t GetEntries() const
void GetPointsWithinDist(const point_type &rRef, value_type fDist, std::vector< const point_type * > &vFoundPoints) const