1 #ifndef COMMONTOOLS_RECOALGOS_FKDTREE_H
2 #define COMMONTOOLS_RECOALGOS_FKDTREE_H
21 const std::array<unsigned int, 32> MultiplyDeBruijnBitPosition{{0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16,
22 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17,
23 24, 7, 19, 27, 23, 6, 26, 5, 4, 31}};
24 unsigned int ilog2(
unsigned int v) {
30 return MultiplyDeBruijnBitPosition[(
unsigned int)(v * 0x07C4ACDDU) >> 27];
34 template <
class TYPE,
unsigned int numberOfDimensions>
52 std::vector<unsigned int>& foundPoints) {
64 unsigned int numberOfindicesToVisitThisDepth;
65 unsigned int numberOfSonsToVisitNext;
66 unsigned int firstSonToVisitNext;
71 dimension =
depth % numberOfDimensions;
72 numberOfindicesToVisitThisDepth = indicesToVisit.
size();
74 for (
unsigned int visitedindicesThisDepth = 0; visitedindicesThisDepth < numberOfindicesToVisitThisDepth;
75 visitedindicesThisDepth++) {
76 index = indicesToVisit[visitedindicesThisDepth];
78 intersection =
intersects(index, minPoint, maxPoint, dimension);
84 foundPoints.emplace_back(
theIds[index]);
87 numberOfSonsToVisitNext =
93 numberOfSonsToVisitNext =
98 for (
unsigned int whichSon = 0; whichSon < numberOfSonsToVisitNext; ++whichSon) {
99 indicesToVisit.
push_back(firstSonToVisitNext + whichSon);
103 indicesToVisit.
pop_front(numberOfindicesToVisitThisDepth);
115 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
129 dimension =
depth % numberOfDimensions;
130 unsigned int firstIndexInDepth = (1 <<
depth) - 1;
132 for (
unsigned int indexInDepth = 0; indexInDepth <
maxDepth; ++indexInDepth) {
133 unsigned int indexInArray = firstIndexInDepth + indexInDepth;
134 unsigned int leftSonIndexInArray = 2 * indexInArray + 1;
135 unsigned int rightSonIndexInArray = leftSonIndexInArray + 1;
143 points.begin() +
theIntervalMin[indexInArray] + whichElementInInterval,
147 if (a[dimension] ==
b[dimension])
148 return a.getId() <
b.getId();
157 theIntervalLength[leftSonIndexInArray] = whichElementInInterval;
162 theIntervalLength[rightSonIndexInArray] = (theIntervalLength[indexInArray] - 1 - whichElementInInterval);
167 dimension = theDepth % numberOfDimensions;
168 unsigned int firstIndexInDepth = (1 <<
theDepth) - 1;
169 for (
unsigned int indexInArray = firstIndexInDepth; indexInArray <
theNumberOfPoints; ++indexInArray) {
192 if ((index / 2) - 1 <= length -
index)
195 return length - index / 2;
208 return (
theDimensions[dimension][index] <= maxPoint[dimension] &&
216 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i) {
225 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
231 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