LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::KDTreeLinkerAlgo< DATA, DIM > Class Template Reference

Class that implements the KDTree partition of 2D space and a closest point search algorithm. More...

#include "PreProcessingAlgorithm.h"

Public Member Functions

 KDTreeLinkerAlgo ()
 Default constructor. More...
 
 ~KDTreeLinkerAlgo ()
 Destructor calls clear. More...
 
void build (std::vector< KDTreeNodeInfoT< DATA, DIM > > &eltList, const KDTreeBoxT< DIM > &region)
 Build the KD tree from the "eltList" in the space define by "region". More...
 
void search (const KDTreeBoxT< DIM > &searchBox, std::vector< KDTreeNodeInfoT< DATA, DIM > > &resRecHitList)
 Search in the KDTree for all points that would be contained in the given searchbox The founded points are stored in resRecHitList. More...
 
void findNearestNeighbour (const KDTreeNodeInfoT< DATA, DIM > &point, const KDTreeNodeInfoT< DATA, DIM > *&result, float &distance)
 findNearestNeighbour More...
 
bool empty ()
 Whether the tree is empty. More...
 
int size ()
 Return the number of nodes + leaves in the tree (nElements should be (size() +1) / 2) More...
 
void clear ()
 Clear all allocated structures. More...
 

Private Member Functions

KDTreeNodeT< DATA, DIM > * getNextNode ()
 Get the next node from the node pool. More...
 
int medianSearch (int low, int high, int treeDepth)
 Fast median search with Wirth algorithm in eltList between low and high indexes. More...
 
KDTreeNodeT< DATA, DIM > * recBuild (int low, int high, int depth, const KDTreeBoxT< DIM > &region)
 Recursive kdtree builder. Is called by build() More...
 
void recSearch (const KDTreeNodeT< DATA, DIM > *current, const KDTreeBoxT< DIM > &trackBox)
 Recursive kdtree search. Is called by search() More...
 
void recNearestNeighbour (unsigned depth, const KDTreeNodeT< DATA, DIM > *current, const KDTreeNodeInfoT< DATA, DIM > &point, const KDTreeNodeT< DATA, DIM > *&best_match, float &best_dist)
 Recursive nearest neighbour search. Is called by findNearestNeighbour() More...
 
void addSubtree (const KDTreeNodeT< DATA, DIM > *current)
 Add all elements of an subtree to the closest elements. Used during the recSearch(). More...
 
float dist2 (const KDTreeNodeInfoT< DATA, DIM > &a, const KDTreeNodeInfoT< DATA, DIM > &b) const
 dist2 More...
 
void clearTree ()
 Frees the KDTree. More...
 

Private Attributes

KDTreeNodeT< DATA, DIM > * root_
 The KDTree root. More...
 
KDTreeNodeT< DATA, DIM > * nodePool_
 Node pool allows us to do just 1 call to new for each tree building. More...
 
int nodePoolSize_
 The node pool size. More...
 
int nodePoolPos_
 The node pool position. More...
 
std::vector< KDTreeNodeInfoT< DATA, DIM > > * closestNeighbour
 The closest neighbour. More...
 
std::vector< KDTreeNodeInfoT< DATA, DIM > > * initialEltList
 The initial element list. More...
 

Detailed Description

template<typename DATA, unsigned DIM = 2>
class lar_content::KDTreeLinkerAlgo< DATA, DIM >

Class that implements the KDTree partition of 2D space and a closest point search algorithm.

Definition at line 16 of file PreProcessingAlgorithm.h.

Constructor & Destructor Documentation

template<typename DATA , unsigned DIM>
lar_content::KDTreeLinkerAlgo< DATA, DIM >::KDTreeLinkerAlgo ( )
inline

Default constructor.

Definition at line 162 of file KDTreeLinkerAlgoT.h.

162  :
163  root_(nullptr),
164  nodePool_(nullptr),
165  nodePoolSize_(-1),
166  nodePoolPos_(-1),
167  closestNeighbour(nullptr),
168  initialEltList(nullptr)
169 {
170 }
int nodePoolPos_
The node pool position.
KDTreeNodeT< DATA, DIM > * root_
The KDTree root.
std::vector< KDTreeNodeInfoT< DATA, DIM > > * initialEltList
The initial element list.
int nodePoolSize_
The node pool size.
KDTreeNodeT< DATA, DIM > * nodePool_
Node pool allows us to do just 1 call to new for each tree building.
std::vector< KDTreeNodeInfoT< DATA, DIM > > * closestNeighbour
The closest neighbour.
template<typename DATA , unsigned DIM>
lar_content::KDTreeLinkerAlgo< DATA, DIM >::~KDTreeLinkerAlgo ( )
inline

Destructor calls clear.

Definition at line 175 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::clear().

176 {
177  this->clear();
178 }
void clear()
Clear all allocated structures.

Member Function Documentation

template<typename DATA , unsigned DIM>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::addSubtree ( const KDTreeNodeT< DATA, DIM > *  current)
inlineprivate

Add all elements of an subtree to the closest elements. Used during the recSearch().

Parameters
current

Definition at line 418 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::closestNeighbour, lar_content::KDTreeNodeT< DATA, DIM >::info, lar_content::KDTreeNodeT< DATA, DIM >::left, and lar_content::KDTreeNodeT< DATA, DIM >::right.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::recSearch().

419 {
420  // By construction, current can't be null
421  //assert(current != 0);
422 
423  if ((current->left == nullptr) && (current->right == nullptr))
424  {
425  // Leaf case
426  closestNeighbour->push_back(current->info);
427  }
428  else
429  {
430  // Node case
431  this->addSubtree(current->left);
432  this->addSubtree(current->right);
433  }
434 }
void addSubtree(const KDTreeNodeT< DATA, DIM > *current)
Add all elements of an subtree to the closest elements. Used during the recSearch().
std::vector< KDTreeNodeInfoT< DATA, DIM > > * closestNeighbour
The closest neighbour.
template<typename DATA , unsigned DIM>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::build ( std::vector< KDTreeNodeInfoT< DATA, DIM > > &  eltList,
const KDTreeBoxT< DIM > &  region 
)
inline

Build the KD tree from the "eltList" in the space define by "region".

Parameters
eltList
region

Definition at line 183 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::initialEltList, lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePool_, lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePoolSize_, lar_content::KDTreeLinkerAlgo< DATA, DIM >::recBuild(), and lar_content::KDTreeLinkerAlgo< DATA, DIM >::root_.

Referenced by lar_content::EventSlicingTool::AssignRemainingHitsToSlices(), lar_content::IsolatedClusterMopUpAlgorithm::GetCaloHitToClusterMap(), lar_content::PreProcessingAlgorithm::GetFilteredCaloHitList(), lar_content::TransverseAssociationAlgorithm::GetNearbyClusterMap(), lar_content::VertexSelectionBaseAlgorithm::InitializeKDTrees(), lar_content::DeltaRayMatchingAlgorithm::InitializeNearbyClusterMap(), lar_content::SvmVertexSelectionAlgorithm::PopulateKdTree(), and lar_content::CrossedTrackSplittingAlgorithm::PreparationStep().

184 {
185  if (eltList.size())
186  {
187  initialEltList = &eltList;
188  const size_t mysize = initialEltList->size();
189 
190  nodePoolSize_ = mysize * 2 - 1;
191  nodePool_ = new KDTreeNodeT<DATA, DIM>[nodePoolSize_];
192 
193  // Here we build the KDTree
194  root_ = this->recBuild(0, mysize, 0, region);
195  initialEltList = nullptr;
196  }
197 }
KDTreeNodeT< DATA, DIM > * root_
The KDTree root.
std::vector< KDTreeNodeInfoT< DATA, DIM > > * initialEltList
The initial element list.
int nodePoolSize_
The node pool size.
KDTreeNodeT< DATA, DIM > * nodePool_
Node pool allows us to do just 1 call to new for each tree building.
KDTreeNodeT< DATA, DIM > * recBuild(int low, int high, int depth, const KDTreeBoxT< DIM > &region)
Recursive kdtree builder. Is called by build()
template<typename DATA , unsigned DIM>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::clear ( )
inline

Clear all allocated structures.

Definition at line 483 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::clearTree(), and lar_content::KDTreeLinkerAlgo< DATA, DIM >::root_.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::~KDTreeLinkerAlgo().

484 {
485  if (root_)
486  this->clearTree();
487 }
KDTreeNodeT< DATA, DIM > * root_
The KDTree root.
void clearTree()
Frees the KDTree.
template<typename DATA , unsigned DIM>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::clearTree ( )
inlineprivate

Frees the KDTree.

Definition at line 455 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePool_, lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePoolPos_, lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePoolSize_, and lar_content::KDTreeLinkerAlgo< DATA, DIM >::root_.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::clear().

456 {
457  delete[] nodePool_;
458  nodePool_ = nullptr;
459  root_ = nullptr;
460  nodePoolSize_ = -1;
461  nodePoolPos_ = -1;
462 }
int nodePoolPos_
The node pool position.
KDTreeNodeT< DATA, DIM > * root_
The KDTree root.
int nodePoolSize_
The node pool size.
KDTreeNodeT< DATA, DIM > * nodePool_
Node pool allows us to do just 1 call to new for each tree building.
template<typename DATA , unsigned DIM>
float lar_content::KDTreeLinkerAlgo< DATA, DIM >::dist2 ( const KDTreeNodeInfoT< DATA, DIM > &  a,
const KDTreeNodeInfoT< DATA, DIM > &  b 
) const
inlineprivate

dist2

Parameters
a
b
Returns
dist2

Definition at line 439 of file KDTreeLinkerAlgoT.h.

References d, and lar_content::KDTreeNodeInfoT< DATA, DIM >::dims.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::recNearestNeighbour().

440 {
441  double d = 0.;
442 
443  for (unsigned i = 0 ; i < DIM; ++i)
444  {
445  const double diff = a.dims[i] - b.dims[i];
446  d += diff * diff;
447  }
448 
449  return (float)d;
450 }
Float_t d
Definition: plot.C:237
template<typename DATA , unsigned DIM>
bool lar_content::KDTreeLinkerAlgo< DATA, DIM >::empty ( )
inline

Whether the tree is empty.

Returns
boolean

Definition at line 467 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePoolPos_.

Referenced by lar_content::VertexSelectionBaseAlgorithm::FilterVertexList(), and lar_content::VertexSelectionBaseAlgorithm::InitializeKDTrees().

468 {
469  return (nodePoolPos_ == -1);
470 }
int nodePoolPos_
The node pool position.
template<typename DATA , unsigned DIM>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::findNearestNeighbour ( const KDTreeNodeInfoT< DATA, DIM > &  point,
const KDTreeNodeInfoT< DATA, DIM > *&  result,
float &  distance 
)
inline

findNearestNeighbour

Parameters
point
result
distance

Definition at line 331 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeNodeT< DATA, DIM >::info, max, lar_content::KDTreeLinkerAlgo< DATA, DIM >::recNearestNeighbour(), and lar_content::KDTreeLinkerAlgo< DATA, DIM >::root_.

Referenced by lar_content::IsolatedClusterMopUpAlgorithm::GetCaloHitToClusterMap(), and lar_content::EventSlicingTool::MatchClusterToSlice().

333 {
334  if (nullptr != result || distance != std::numeric_limits<float>::max())
335  {
336  result = nullptr;
337  distance = std::numeric_limits<float>::max();
338  }
339 
340  if (root_)
341  {
342  const KDTreeNodeT<DATA, DIM> *best_match = nullptr;
343  this->recNearestNeighbour(0, root_, point, best_match, distance);
344 
345  if (distance != std::numeric_limits<float>::max())
346  {
347  result = &(best_match->info);
348  distance = std::sqrt(distance);
349  }
350  }
351 }
KDTreeNodeT< DATA, DIM > * root_
The KDTree root.
void recNearestNeighbour(unsigned depth, const KDTreeNodeT< DATA, DIM > *current, const KDTreeNodeInfoT< DATA, DIM > &point, const KDTreeNodeT< DATA, DIM > *&best_match, float &best_dist)
Recursive nearest neighbour search. Is called by findNearestNeighbour()
Int_t max
Definition: plot.C:27
template<typename DATA , unsigned DIM>
KDTreeNodeT< DATA, DIM > * lar_content::KDTreeLinkerAlgo< DATA, DIM >::getNextNode ( )
inlineprivate

Get the next node from the node pool.

Returns
the next node from the node pool

Definition at line 492 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePool_, and lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePoolPos_.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::recBuild().

493 {
494  ++nodePoolPos_;
495 
496  // The tree size is exactly 2 * nbrElts - 1 and this is the total allocated memory.
497  // If we have used more than that....there is a big problem.
498  //assert(nodePoolPos_ < nodePoolSize_);
499 
500  return &(nodePool_[nodePoolPos_]);
501 }
int nodePoolPos_
The node pool position.
KDTreeNodeT< DATA, DIM > * nodePool_
Node pool allows us to do just 1 call to new for each tree building.
template<typename DATA , unsigned DIM>
int lar_content::KDTreeLinkerAlgo< DATA, DIM >::medianSearch ( int  low,
int  high,
int  treeDepth 
)
inlineprivate

Fast median search with Wirth algorithm in eltList between low and high indexes.

Parameters
low
high
treeDepth

Definition at line 202 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeNodeInfoT< DATA, DIM >::dims, and lar_content::KDTreeLinkerAlgo< DATA, DIM >::initialEltList.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::recBuild().

203 {
204  // We should have at least 1 element to calculate the median...
205  //assert(low < high);
206 
207  const int nbrElts = high - low;
208  int median = nbrElts / 2 - (1 - 1 * (nbrElts & 1));
209  median += low;
210 
211  int l = low;
212  int m = high - 1;
213 
214  while (l < m)
215  {
216  KDTreeNodeInfoT<DATA, DIM> elt = (*initialEltList)[median];
217  int i = l;
218  int j = m;
219 
220  do
221  {
222  // The even depth is associated to dim1 dimension, the odd one to dim2 dimension
223  const unsigned thedim = treeDepth % DIM;
224  while ((*initialEltList)[i].dims[thedim] < elt.dims[thedim]) ++i;
225  while ((*initialEltList)[j].dims[thedim] > elt.dims[thedim]) --j;
226 
227  if (i <= j)
228  {
230  i++;
231  j--;
232  }
233  }
234  while (i <= j);
235 
236  if (j < median) l = i;
237  if (i > median) m = j;
238  }
239 
240  return median;
241 }
std::vector< KDTreeNodeInfoT< DATA, DIM > > * initialEltList
The initial element list.
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
template<typename DATA , unsigned DIM>
KDTreeNodeT< DATA, DIM > * lar_content::KDTreeLinkerAlgo< DATA, DIM >::recBuild ( int  low,
int  high,
int  depth,
const KDTreeBoxT< DIM > &  region 
)
inlineprivate

Recursive kdtree builder. Is called by build()

Parameters
low
high
depth
region

Definition at line 506 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeBoxT< DIM >::dimmax, lar_content::KDTreeBoxT< DIM >::dimmin, lar_content::KDTreeLinkerAlgo< DATA, DIM >::getNextNode(), lar_content::KDTreeNodeT< DATA, DIM >::info, lar_content::KDTreeLinkerAlgo< DATA, DIM >::initialEltList, lar_content::KDTreeNodeT< DATA, DIM >::left, lar_content::KDTreeLinkerAlgo< DATA, DIM >::medianSearch(), lar_content::KDTreeNodeT< DATA, DIM >::right, and lar_content::KDTreeNodeT< DATA, DIM >::setAttributs().

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::build().

507 {
508  const int portionSize = high - low;
509 
510  // By construction, portionSize > 0 can't happen.
511  //assert(portionSize > 0);
512 
513  if (portionSize == 1)
514  {
515  // Leaf case
516  KDTreeNodeT<DATA, DIM> *leaf = this->getNextNode();
517  leaf->setAttributs(region, (*initialEltList)[low]);
518  return leaf;
519  }
520  else
521  {
522  // The even depth is associated to dim1 dimension, the odd one to dim2 dimension
523  int medianId = this->medianSearch(low, high, depth);
524 
525  // We create the node
526  KDTreeNodeT<DATA, DIM> *node = this->getNextNode();
527  node->setAttributs(region);
528  node->info = (*initialEltList)[medianId];
529 
530  // Here we split into 2 halfplanes the current plane
531  KDTreeBoxT<DIM> leftRegion = region;
532  KDTreeBoxT<DIM> rightRegion = region;
533 
534  const unsigned thedim = depth % DIM;
535  auto medianVal = (*initialEltList)[medianId].dims[thedim];
536  leftRegion.dimmax[thedim] = medianVal;
537  rightRegion.dimmin[thedim] = medianVal;
538 
539  ++depth;
540  ++medianId;
541 
542  // We recursively build the son nodes
543  node->left = this->recBuild(low, medianId, depth, leftRegion);
544  node->right = this->recBuild(medianId, high, depth, rightRegion);
545  return node;
546  }
547 }
std::vector< KDTreeNodeInfoT< DATA, DIM > > * initialEltList
The initial element list.
KDTreeNodeT< DATA, DIM > * getNextNode()
Get the next node from the node pool.
KDTreeNodeT< DATA, DIM > * recBuild(int low, int high, int depth, const KDTreeBoxT< DIM > &region)
Recursive kdtree builder. Is called by build()
int medianSearch(int low, int high, int treeDepth)
Fast median search with Wirth algorithm in eltList between low and high indexes.
template<typename DATA , unsigned DIM = 2>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::recNearestNeighbour ( unsigned  depth,
const KDTreeNodeT< DATA, DIM > *  current,
const KDTreeNodeInfoT< DATA, DIM > &  point,
const KDTreeNodeT< DATA, DIM > *&  best_match,
float &  best_dist 
)
inlineprivate

Recursive nearest neighbour search. Is called by findNearestNeighbour()

Parameters
depth
current
point
best_match
best_dist

Definition at line 356 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeNodeInfoT< DATA, DIM >::dims, lar_content::KDTreeLinkerAlgo< DATA, DIM >::dist2(), f, lar_content::KDTreeNodeT< DATA, DIM >::info, lar_content::KDTreeNodeT< DATA, DIM >::left, and lar_content::KDTreeNodeT< DATA, DIM >::right.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::findNearestNeighbour().

358 {
359  const unsigned int current_dim = depth % DIM;
360 
361  if (current->left == nullptr && current->right == nullptr)
362  {
363  best_match = current;
364  best_dist = this->dist2(point, best_match->info);
365  return;
366  }
367  else
368  {
369  const float dist_to_axis = point.dims[current_dim] - current->info.dims[current_dim];
370 
371  if (dist_to_axis < 0.f)
372  {
373  this->recNearestNeighbour(depth + 1, current->left, point, best_match, best_dist);
374  }
375  else
376  {
377  this->recNearestNeighbour(depth + 1, current->right, point, best_match, best_dist);
378  }
379 
380  // If we're here we're returned so best_dist is filled. Compare to this node and see if it's a better match. If it is, update result
381  const float dist_current = this->dist2(point, current->info);
382 
383  if (dist_current < best_dist)
384  {
385  best_dist = dist_current;
386  best_match = current;
387  }
388 
389  // Now we see if the radius to best crosses the splitting axis
390  if (best_dist > dist_to_axis * dist_to_axis)
391  {
392  // if it does we traverse the other side of the axis to check for a new best
393  const KDTreeNodeT<DATA, DIM> *check_best = best_match;
394  float check_dist = best_dist;
395 
396  if (dist_to_axis < 0.f)
397  {
398  this->recNearestNeighbour(depth + 1, current->right, point, check_best, check_dist);
399  }
400  else
401  {
402  this->recNearestNeighbour(depth + 1, current->left, point, check_best, check_dist);
403  }
404 
405  if (check_dist < best_dist)
406  {
407  best_dist = check_dist;
408  best_match = check_best;
409  }
410  }
411  return;
412  }
413 }
void recNearestNeighbour(unsigned depth, const KDTreeNodeT< DATA, DIM > *current, const KDTreeNodeInfoT< DATA, DIM > &point, const KDTreeNodeT< DATA, DIM > *&best_match, float &best_dist)
Recursive nearest neighbour search. Is called by findNearestNeighbour()
TFile f
Definition: plotHisto.C:6
float dist2(const KDTreeNodeInfoT< DATA, DIM > &a, const KDTreeNodeInfoT< DATA, DIM > &b) const
dist2
template<typename DATA , unsigned DIM>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::recSearch ( const KDTreeNodeT< DATA, DIM > *  current,
const KDTreeBoxT< DIM > &  trackBox 
)
inlineprivate

Recursive kdtree search. Is called by search()

Parameters
current
trackBox

Definition at line 259 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::addSubtree(), lar_content::KDTreeLinkerAlgo< DATA, DIM >::closestNeighbour, lar_content::KDTreeBoxT< DIM >::dimmax, lar_content::KDTreeBoxT< DIM >::dimmin, lar_content::KDTreeNodeT< DATA, DIM >::info, lar_content::KDTreeNodeT< DATA, DIM >::left, and lar_content::KDTreeNodeT< DATA, DIM >::right.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::search().

260 {
261  // By construction, current can't be null
262  //assert(current != 0);
263  // By Construction, a node can't have just 1 son.
264  //assert (!(((current->left == 0) && (current->right != 0)) || ((current->left != 0) && (current->right == 0))));
265 
266  if ((current->left == nullptr) && (current->right == nullptr))
267  {
268  // Leaf case
269  // If point inside the rectangle/area
270  bool isInside = true;
271 
272  for (unsigned i = 0; i < DIM; ++i)
273  {
274  const auto thedim = current->info.dims[i];
275  isInside *= thedim >= trackBox.dimmin[i] && thedim <= trackBox.dimmax[i];
276  }
277 
278  if (isInside)
279  closestNeighbour->push_back(current->info);
280  }
281  else
282  {
283  // Node case
284  // If region( v->left ) is fully contained in the rectangle
285  bool isFullyContained = true;
286  bool hasIntersection = true;
287 
288  for (unsigned i = 0; i < DIM; ++i)
289  {
290  const auto regionmin = current->left->region.dimmin[i];
291  const auto regionmax = current->left->region.dimmax[i];
292  isFullyContained *= (regionmin >= trackBox.dimmin[i] && regionmax <= trackBox.dimmax[i]);
293  hasIntersection *= (regionmin < trackBox.dimmax[i] && regionmax > trackBox.dimmin[i]);
294  }
295 
296  if (isFullyContained)
297  {
298  this->addSubtree(current->left);
299  }
300  else if (hasIntersection)
301  {
302  this->recSearch(current->left, trackBox);
303  }
304 
305  //if region( v->right ) is fully contained in the rectangle
306  isFullyContained = true;
307  hasIntersection = true;
308 
309  for (unsigned i = 0; i < DIM; ++i)
310  {
311  const auto regionmin = current->right->region.dimmin[i];
312  const auto regionmax = current->right->region.dimmax[i];
313  isFullyContained *= (regionmin >= trackBox.dimmin[i] && regionmax <= trackBox.dimmax[i]);
314  hasIntersection *= (regionmin < trackBox.dimmax[i] && regionmax > trackBox.dimmin[i]);
315  }
316 
317  if (isFullyContained)
318  {
319  this->addSubtree(current->right);
320  }
321  else if (hasIntersection)
322  {
323  this->recSearch(current->right, trackBox);
324  }
325  }
326 }
void addSubtree(const KDTreeNodeT< DATA, DIM > *current)
Add all elements of an subtree to the closest elements. Used during the recSearch().
std::vector< KDTreeNodeInfoT< DATA, DIM > > * closestNeighbour
The closest neighbour.
void recSearch(const KDTreeNodeT< DATA, DIM > *current, const KDTreeBoxT< DIM > &trackBox)
Recursive kdtree search. Is called by search()
template<typename DATA , unsigned DIM>
void lar_content::KDTreeLinkerAlgo< DATA, DIM >::search ( const KDTreeBoxT< DIM > &  searchBox,
std::vector< KDTreeNodeInfoT< DATA, DIM > > &  resRecHitList 
)
inline

Search in the KDTree for all points that would be contained in the given searchbox The founded points are stored in resRecHitList.

Parameters
searchBox
resRecHitList

Definition at line 246 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::closestNeighbour, lar_content::KDTreeLinkerAlgo< DATA, DIM >::recSearch(), and lar_content::KDTreeLinkerAlgo< DATA, DIM >::root_.

Referenced by lar_content::RPhiFeatureTool::FillKernelEstimate(), lar_content::PreProcessingAlgorithm::GetFilteredCaloHitList(), lar_content::TransverseAssociationAlgorithm::GetNearbyClusterMap(), lar_content::DeltaRayMatchingAlgorithm::InitializeNearbyClusterMap(), lar_content::VertexSelectionBaseAlgorithm::IsVertexOnHit(), lar_content::SvmVertexSelectionAlgorithm::PopulateKdTree(), and lar_content::CrossedTrackSplittingAlgorithm::PreparationStep().

247 {
248  if (root_)
249  {
250  closestNeighbour = &recHits;
251  this->recSearch(root_, trackBox);
252  closestNeighbour = nullptr;
253  }
254 }
KDTreeNodeT< DATA, DIM > * root_
The KDTree root.
std::vector< KDTreeNodeInfoT< DATA, DIM > > * closestNeighbour
The closest neighbour.
void recSearch(const KDTreeNodeT< DATA, DIM > *current, const KDTreeBoxT< DIM > &trackBox)
Recursive kdtree search. Is called by search()
template<typename DATA , unsigned DIM>
int lar_content::KDTreeLinkerAlgo< DATA, DIM >::size ( )
inline

Return the number of nodes + leaves in the tree (nElements should be (size() +1) / 2)

Returns
the number of nodes + leaves in the tree

Definition at line 475 of file KDTreeLinkerAlgoT.h.

References lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePoolPos_.

476 {
477  return (nodePoolPos_ + 1);
478 }
int nodePoolPos_
The node pool position.

Member Data Documentation

template<typename DATA , unsigned DIM = 2>
std::vector<KDTreeNodeInfoT<DATA, DIM> >* lar_content::KDTreeLinkerAlgo< DATA, DIM >::closestNeighbour
private
template<typename DATA , unsigned DIM = 2>
std::vector<KDTreeNodeInfoT<DATA, DIM> >* lar_content::KDTreeLinkerAlgo< DATA, DIM >::initialEltList
private
template<typename DATA , unsigned DIM = 2>
KDTreeNodeT<DATA, DIM>* lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePool_
private

Node pool allows us to do just 1 call to new for each tree building.

Definition at line 150 of file KDTreeLinkerAlgoT.h.

Referenced by lar_content::KDTreeLinkerAlgo< DATA, DIM >::build(), lar_content::KDTreeLinkerAlgo< DATA, DIM >::clearTree(), and lar_content::KDTreeLinkerAlgo< DATA, DIM >::getNextNode().

template<typename DATA , unsigned DIM = 2>
int lar_content::KDTreeLinkerAlgo< DATA, DIM >::nodePoolSize_
private

The documentation for this class was generated from the following files: