1 #ifndef KDTreeLinkerAlgoTemplated_h
2 #define KDTreeLinkerAlgoTemplated_h
12 template <
typename DATA,
unsigned DIM=2>
84 template <
typename DATA,
unsigned DIM >
90 initialEltList = &eltList;
92 size_t size = initialEltList->size();
93 nodePoolSize_ = size * 2 - 1;
97 root_ = recBuild(0, size, 0, region);
104 template <
typename DATA,
unsigned DIM >
113 const int nbrElts = high - low;
114 int median = nbrElts/2 - ( 1 - 1*(nbrElts&1) );
128 const unsigned thedim = treeDepth %
DIM;
129 while( (*initialEltList)[
i].dims[thedim] < elt.
dims[thedim] ) ++i;
130 while( (*initialEltList)[
j].dims[thedim] > elt.
dims[thedim] ) --j;
133 std::swap((*initialEltList)[i], (*initialEltList)[j]);
138 if (j < median) l =
i;
139 if (i > median) m =
j;
147 template <
typename DATA,
unsigned DIM >
154 recSearch(
root_, trackBox);
155 closestNeighbour = 0;
160 template <
typename DATA,
unsigned DIM >
174 if ((current->
left == 0) && (current->
right == 0)) {
177 bool isInside =
true;
178 for(
unsigned i = 0;
i <
DIM; ++
i ) {
179 const auto thedim = current->
info.dims[
i];
180 isInside *= thedim >= trackBox.
dimmin[
i] && thedim <= trackBox.
dimmax[
i];
182 if( isInside ) closestNeighbour->push_back(current->
info);
186 bool isFullyContained =
true;
187 bool hasIntersection =
true;
189 for(
unsigned i = 0;
i <
DIM; ++
i ) {
190 const auto regionmin = current->
left->region.dimmin[
i];
191 const auto regionmax = current->
left->region.dimmax[
i];
192 isFullyContained *= ( regionmin >= trackBox.
dimmin[
i] &&
193 regionmax <= trackBox.
dimmax[
i] );
194 hasIntersection *= ( regionmin < trackBox.
dimmax[
i] && regionmax > trackBox.
dimmin[
i]);
196 if( isFullyContained ) {
197 addSubtree(current->
left);
198 }
else if ( hasIntersection ) {
199 recSearch(current->
left, trackBox);
202 isFullyContained =
true;
203 hasIntersection =
true;
205 for(
unsigned i = 0;
i <
DIM; ++
i ) {
206 const auto regionmin = current->
right->region.dimmin[
i];
207 const auto regionmax = current->
right->region.dimmax[
i];
208 isFullyContained *= ( regionmin >= trackBox.
dimmin[
i] &&
209 regionmax <= trackBox.
dimmax[
i] );
210 hasIntersection *= ( regionmin < trackBox.
dimmax[
i] && regionmax > trackBox.
dimmin[
i]);
212 if( isFullyContained ) {
213 addSubtree(current->
right);
214 }
else if ( hasIntersection ) {
215 recSearch(current->
right, trackBox);
220 template <
typename DATA,
unsigned DIM >
227 if ((current->
left == 0) && (current->
right == 0))
228 closestNeighbour->push_back(current->
info);
230 addSubtree(current->
left);
231 addSubtree(current->
right);
238 template <
typename DATA,
unsigned DIM>
247 template <
typename DATA,
unsigned DIM>
254 template <
typename DATA,
unsigned DIM>
265 template <
typename DATA,
unsigned DIM>
274 template <
typename DATA,
unsigned DIM>
284 return &(nodePool_[nodePoolPos_]);
288 template <
typename DATA,
unsigned DIM>
295 int portionSize = high - low;
300 if (portionSize == 1) {
310 int medianId = medianSearch(low, high, depth);
320 unsigned thedim = depth %
DIM;
321 auto medianVal = (*initialEltList)[medianId].dims[thedim];
322 leftRegion.
dimmax[thedim] = medianVal;
323 rightRegion.
dimmin[thedim] = medianVal;
329 node->
left = recBuild(low, medianId, depth, leftRegion);
330 node->
right = recBuild(medianId, high, depth, rightRegion);
KDTreeNodeT< DATA, DIM > * right
KDTreeNodeT< DATA, DIM > * left
std::array< float, DIM > dimmin
int medianSearch(int low, int high, int treeDepth)
void build(std::vector< KDTreeNodeInfoT< DATA, DIM > > &eltList, const KDTreeBoxT< DIM > ®ion)
KDTreeNodeT< DATA, DIM > * recBuild(int low, int hight, int depth, const KDTreeBoxT< DIM > ®ion)
void search(const KDTreeBoxT< DIM > &searchBox, std::vector< KDTreeNodeInfoT< DATA, DIM > > &resRecHitList)
void addSubtree(const KDTreeNodeT< DATA, DIM > *current)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
KDTreeNodeT< DATA, DIM > * nodePool_
KDTreeNodeT< DATA, DIM > * root_
KDTreeNodeT< DATA, DIM > * getNextNode()
std::array< float, DIM > dims
KDTreeNodeInfoT< DATA, DIM > info
std::vector< KDTreeNodeInfoT< DATA, DIM > > * closestNeighbour
static const char root_[]
void recSearch(const KDTreeNodeT< DATA, DIM > *current, const KDTreeBoxT< DIM > &trackBox)
std::array< float, DIM > dimmax
void setAttributs(const KDTreeBoxT< DIM > ®ionBox, const KDTreeNodeInfoT< DATA, DIM > &infoToStore)
std::vector< KDTreeNodeInfoT< DATA, DIM > > * initialEltList
tuple size
Write out results.