1 #ifndef COMMONTOOLS_RECOALGOS_FKDTREE_H 2 #define COMMONTOOLS_RECOALGOS_FKDTREE_H 22 const std::array<unsigned int, 32> MultiplyDeBruijnBitPosition
24 { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27,
25 23, 6, 26, 5, 4, 31 } };
26 unsigned int ilog2(
unsigned int v)
33 return MultiplyDeBruijnBitPosition[(
unsigned int) (v * 0x07C4ACDDU) >> 27];
37 template<
class TYPE,
unsigned int numberOfDimensions>
62 std::vector<unsigned int>& foundPoints)
75 unsigned int numberOfindicesToVisitThisDepth;
76 unsigned int numberOfSonsToVisitNext;
77 unsigned int firstSonToVisitNext;
83 dimension =
depth % numberOfDimensions;
84 numberOfindicesToVisitThisDepth = indicesToVisit.
size();
86 for (
unsigned int visitedindicesThisDepth = 0;
87 visitedindicesThisDepth < numberOfindicesToVisitThisDepth;
88 visitedindicesThisDepth++)
91 index = indicesToVisit[visitedindicesThisDepth];
93 intersection =
intersects(index, minPoint, maxPoint, dimension);
102 foundPoints.emplace_back(
theIds[index]);
120 for (
unsigned int whichSon = 0; whichSon < numberOfSonsToVisitNext; ++whichSon)
122 indicesToVisit.
push_back(firstSonToVisitNext + whichSon);
126 indicesToVisit.
pop_front(numberOfindicesToVisitThisDepth);
140 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
155 dimension =
depth % numberOfDimensions;
156 unsigned int firstIndexInDepth = (1 <<
depth) - 1;
158 for (
unsigned int indexInDepth = 0; indexInDepth <
maxDepth; ++indexInDepth)
160 unsigned int indexInArray = firstIndexInDepth + indexInDepth;
161 unsigned int leftSonIndexInArray = 2 * indexInArray + 1;
162 unsigned int rightSonIndexInArray = leftSonIndexInArray + 1;
177 if(a[dimension] ==
b[dimension])
178 return a.getId() <
b.getId();
189 theIntervalLength[leftSonIndexInArray] = whichElementInInterval;
195 + whichElementInInterval + 1;
196 theIntervalLength[rightSonIndexInArray] = (theIntervalLength[indexInArray]
197 - 1 - whichElementInInterval);
202 dimension = theDepth % numberOfDimensions;
203 unsigned int firstIndexInDepth = (1 <<
theDepth) - 1;
204 for (
unsigned int indexInArray = firstIndexInDepth; indexInArray <
theNumberOfPoints;
232 unsigned int index = 1 << (ilog2(length));
234 if ((index / 2) - 1 <= length -
index)
237 return length - index / 2;
243 return 2 * index + 1;
248 return 2 * index + 2;
255 return (
theDimensions[dimension][index] <= maxPoint[dimension]
263 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
276 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
284 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
std::array< std::vector< TYPE >, numberOfDimensions > theDimensions
bool intersects(unsigned int index, const FKDPoint< TYPE, numberOfDimensions > &minPoint, const FKDPoint< TYPE, numberOfDimensions > &maxPoint, int dimension) const
unsigned int getId() const
std::vector< unsigned int > theIds
std::vector< unsigned int > theIntervalMin
unsigned int rightSonIndex(unsigned int index) const
double intersection(double r12)
unsigned int partition_complete_kdtree(unsigned int length)
unsigned int size() const
void search(const FKDPoint< TYPE, numberOfDimensions > &minPoint, const FKDPoint< TYPE, numberOfDimensions > &maxPoint, std::vector< unsigned int > &foundPoints)
bool is_in_the_box(unsigned int index, const FKDPoint< TYPE, numberOfDimensions > &minPoint, const FKDPoint< TYPE, numberOfDimensions > &maxPoint) const
void build(std::vector< FKDPoint< TYPE, numberOfDimensions > > &points)
void push_back(const T &value)
unsigned int theNumberOfPoints
void add_at_position(const FKDPoint< TYPE, numberOfDimensions > &point, const unsigned int position)
void add_at_position(FKDPoint< TYPE, numberOfDimensions > &&point, const unsigned int position)
unsigned int leftSonIndex(unsigned int index) const
static int position[264][3]
std::vector< unsigned int > theIntervalLength
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point