Belle II Software development
BoxDivisionHoughTree< AItemPtr, AHoughBox, divisions > Class Template Reference

A fast hough algorithm with rectangular boxes, which are split linearly by a fixed number of divisions in each coordinate up to a maximal level. More...

#include <BoxDivisionHoughTree.h>

Inheritance diagram for BoxDivisionHoughTree< AItemPtr, AHoughBox, divisions >:
SimpleBoxDivisionHoughTree< AHitPointerType, AHitDecisionAlgorithm, divisionX, divisionY > SimpleBoxDivisionHoughTree3D< AHitPointerType, AHitDecisionAlgorithm, 2, 2, 2 >

Public Types

using HoughBox = AHoughBox
 Type of the box in the hough space.
 
using BoxDivision = SectoredLinearDivision< HoughBox, divisions... >
 Type of the box division strategy.
 
using HoughTree = WeightedFastHoughTree< AItemPtr, HoughBox, BoxDivision >
 Type of the fast hough tree structure.
 
template<size_t I>
using Type = typename HoughBox::template Type< I >
 Type of the coordinate I.
 
template<class T >
using HasType = typename HoughBox::template HasType< T >
 Predicate that the given type is indeed a coordinate of the hough space.
 
template<class T >
using TypeIndex = typename HoughBox::template TypeIndex< T >
 Function to get the coordinate index from its type.
 
template<size_t I>
using Width = typename HoughBox::template Width< I >
 Type of the width in coordinate I.
 
using Node = typename HoughTree::Node
 Type of the nodes used in the tree for the search.
 

Public Member Functions

 BoxDivisionHoughTree (int maxLevel, int sectorLevelSkip=0)
 Constructor using the given maximal level.
 
size_t getDivision (size_t i) const
 Getter the number of divisions at each level for coordinate index I.
 
template<size_t I>
void constructArray (double lowerBound, double upperBound, Width< I > nBinOverlap=0, Width< I > nBinWidth=0)
 Construct the discrete value array at coordinate index I.
 
template<size_t I>
void assignArray (Array< I > array, Width< I > overlap=0)
 Provide an externally constructed array by coordinate index.
 
template<class T >
std::enable_if_t< HasType< T >::value, void > assignArray (Array< TypeIndex< T >::value > array, Width< TypeIndex< T >::value > overlap=0)
 Provide an externally constructed array by coordinate type.
 
void initialize ()
 Initialise the algorithm by constructing the hough tree from the parameters.
 
template<class AItemPtrs >
void seed (const AItemPtrs &items)
 Prepare the leave finding by filling the top node with given hits.
 
void fell ()
 Terminates the processing by striping all hit information from the tree.
 
void raze ()
 Release all memory that the tree acquired during the runs.
 
HoughTreegetTree () const
 Getter for the tree used in the search in the hough plane.
 
int getMaxLevel () const
 Getter for the currently set maximal level.
 
void setMaxLevel (int maxLevel)
 Setter maximal level of the hough tree.
 
int getSectorLevelSkip () const
 Getter for number of levels to skip in first level to form a finer sectored hough space.
 
void setSectorLevelSkip (int sectorLevelSkip)
 Setter for number of levels to skip in first level to form a finer sectored hough space.
 
template<size_t I>
const Array< I > & getArray () const
 Getter for the array of discrete value for coordinate I.
 

Private Types

template<size_t I>
using Array = typename Type< I >::Array
 Type of the discrete value array to coordinate index I.
 
using Arrays = TupleGenerateN< Array, sizeof...(divisions)>
 Tuple type of the discrete value arrays.
 

Private Member Functions

template<size_t... Is>
HoughBox constructHoughPlaneImpl (const std::index_sequence< Is... > &is)
 Construct the box of the top node of the tree. Implementation unroling the indices.
 
HoughBox constructHoughPlane ()
 Construct the box of the top node of the tree.
 

Private Attributes

int m_maxLevel
 Number of the maximum tree level.
 
int m_sectorLevelSkip
 Number of levels to skip in first level to form a finer sectored hough space.
 
const std::array< size_t, sizeof ...(divisions)> m_divisions = {{divisions ...}}
 Array of the number of divisions at each level.
 
HoughBox::Delta m_overlaps
 An tuple of division overlaps in each coordinate.
 
Arrays m_arrays
 A tuple of value arrays providing the memory for the discrete bin bounds.
 
std::unique_ptr< HoughTreem_houghTree = nullptr
 Dynamic hough tree structure traversed in the leaf search.
 

Detailed Description

template<class AItemPtr, class AHoughBox, size_t ... divisions>
class Belle2::TrackFindingCDC::BoxDivisionHoughTree< AItemPtr, AHoughBox, divisions >

A fast hough algorithm with rectangular boxes, which are split linearly by a fixed number of divisions in each coordinate up to a maximal level.

Definition at line 34 of file BoxDivisionHoughTree.h.

Member Typedef Documentation

◆ Array

using Array = typename Type<I>::Array
private

Type of the discrete value array to coordinate index I.

Definition at line 77 of file BoxDivisionHoughTree.h.

◆ Arrays

using Arrays = TupleGenerateN<Array, sizeof...(divisions)>
private

Tuple type of the discrete value arrays.

Definition at line 80 of file BoxDivisionHoughTree.h.

◆ BoxDivision

Type of the box division strategy.

Definition at line 41 of file BoxDivisionHoughTree.h.

◆ HasType

using HasType = typename HoughBox::template HasType<T>

Predicate that the given type is indeed a coordinate of the hough space.

Definition at line 52 of file BoxDivisionHoughTree.h.

◆ HoughBox

using HoughBox = AHoughBox

Type of the box in the hough space.

Definition at line 38 of file BoxDivisionHoughTree.h.

◆ HoughTree

Type of the fast hough tree structure.

Definition at line 44 of file BoxDivisionHoughTree.h.

◆ Node

using Node = typename HoughTree::Node

Type of the nodes used in the tree for the search.

Definition at line 63 of file BoxDivisionHoughTree.h.

◆ Type

using Type = typename HoughBox::template Type<I>

Type of the coordinate I.

Definition at line 48 of file BoxDivisionHoughTree.h.

◆ TypeIndex

using TypeIndex = typename HoughBox::template TypeIndex<T>

Function to get the coordinate index from its type.

Definition at line 56 of file BoxDivisionHoughTree.h.

◆ Width

using Width = typename HoughBox::template Width<I>

Type of the width in coordinate I.

Definition at line 60 of file BoxDivisionHoughTree.h.

Constructor & Destructor Documentation

◆ BoxDivisionHoughTree()

BoxDivisionHoughTree ( int  maxLevel,
int  sectorLevelSkip = 0 
)
inlineexplicit

Constructor using the given maximal level.

Definition at line 67 of file BoxDivisionHoughTree.h.

68 : m_maxLevel(maxLevel)
69 , m_sectorLevelSkip(sectorLevelSkip)
70 , m_overlaps((divisions * 0)...)
71 {
72 }
int m_sectorLevelSkip
Number of levels to skip in first level to form a finer sectored hough space.
int m_maxLevel
Number of the maximum tree level.
HoughBox::Delta m_overlaps
An tuple of division overlaps in each coordinate.

Member Function Documentation

◆ assignArray() [1/2]

void assignArray ( Array< I >  array,
Width< I >  overlap = 0 
)
inline

Provide an externally constructed array by coordinate index.

Definition at line 128 of file BoxDivisionHoughTree.h.

129 {
130 std::get<I>(m_arrays) = std::move(array);
131 std::get<I>(m_overlaps) = overlap;
132
133 // In case of a discrete axes, check whether the size of the array is sensible
134 // such that the bin width at the highest granularity level is a whole number given the overlap.
135 if (std::is_integral<Width<I> >::value) {
136 const int division = getDivision(I);
137 const int granularityLevel = m_maxLevel + m_sectorLevelSkip;
138 const long int nBins = std::pow(division, granularityLevel);
139 const long int nPositions = std::get<I>(m_arrays).size();
140 const long int nWidthTimeNBins = nPositions - 1 + (nBins - 1) * overlap;
141
142 B2ASSERT("Not enough positions in array to cover all bins.\n"
143 "Expected: positions = " << nBins - (nBins - 1) * overlap + 1 << " at least.\n"
144 "Actual: positions = " << nPositions << " (overlap = " << overlap << ", bins = " << nBins << ")\n",
145 nWidthTimeNBins >= nBins);
146
147 B2ASSERT("Number of positions in array introduces inhomogeneous width at the highest granularity level.\n"
148 "Expected: positions = 'width * bins - (bins - 1) * overlap + 1'\n"
149 "Actual: positions = " << nPositions << " (overlap = " << overlap << ", bins = " << nBins << ")\n",
150 nWidthTimeNBins % nBins == 0);
151 }
152 }
Arrays m_arrays
A tuple of value arrays providing the memory for the discrete bin bounds.
size_t getDivision(size_t i) const
Getter the number of divisions at each level for coordinate index I.

◆ assignArray() [2/2]

std::enable_if_t< HasType< T >::value, void > assignArray ( Array< TypeIndex< T >::value >  array,
Width< TypeIndex< T >::value >  overlap = 0 
)
inline

Provide an externally constructed array by coordinate type.

Definition at line 157 of file BoxDivisionHoughTree.h.

158 {
159 assignArray<TypeIndex<T>::value>(std::move(array), overlap);
160 }

◆ constructArray()

void constructArray ( double  lowerBound,
double  upperBound,
Width< I >  nBinOverlap = 0,
Width< I >  nBinWidth = 0 
)
inline

Construct the discrete value array at coordinate index I.

This function is only applicable for discrete axes. For continuous axes assignArray should be call with an array containing only the lower and upper bound of the axes range and an optional overlap.

Parameters
lowerBoundLower bound of the value range
upperBoundUpper bound of the value range
nBinOverlapOverlap of neighboring bins. Default is no overlap. Usually this is counted in number of discrete values
nBinWidthWidth of the bins at lowest level. Default is width of 1. Usually this is counted in numbers of discrete values

Definition at line 104 of file BoxDivisionHoughTree.h.

108 {
109 static_assert(std::is_integral<Width<I> >::value, "Method only applicable to discrete axes");
110 const size_t division = getDivision(I);
111 const int granularityLevel = m_maxLevel + m_sectorLevelSkip;
112 const size_t nBins = std::pow(division, granularityLevel);
113
114 if (nBinWidth == 0) {
115 nBinWidth = nBinOverlap + 1;
116 }
117
118 B2ASSERT("Width " << nBinWidth << "is not bigger than overlap " << nBinOverlap,
119 nBinOverlap < nBinWidth);
120
121 const auto nPositions = (nBinWidth - nBinOverlap) * nBins + nBinOverlap + 1;
122 std::get<I>(m_arrays) = linspace<float>(lowerBound, upperBound, nPositions);
123 std::get<I>(m_overlaps) = nBinOverlap;
124 }

◆ constructHoughPlane()

HoughBox constructHoughPlane ( )
inlineprivate

Construct the box of the top node of the tree.

Definition at line 239 of file BoxDivisionHoughTree.h.

240 {
241 return constructHoughPlaneImpl(std::make_index_sequence<sizeof...(divisions)>());
242 }
HoughBox constructHoughPlaneImpl(const std::index_sequence< Is... > &is)
Construct the box of the top node of the tree. Implementation unroling the indices.

◆ constructHoughPlaneImpl()

HoughBox constructHoughPlaneImpl ( const std::index_sequence< Is... > &  is)
inlineprivate

Construct the box of the top node of the tree. Implementation unroling the indices.

Definition at line 233 of file BoxDivisionHoughTree.h.

234 {
235 return HoughBox(Type<Is>::getRange(std::get<Is>(m_arrays))...);
236 }
AHoughBox HoughBox
Type of the box in the hough space.

◆ fell()

void fell ( )
inline

Terminates the processing by striping all hit information from the tree.

Definition at line 181 of file BoxDivisionHoughTree.h.

182 {
183 m_houghTree->fell();
184 }
std::unique_ptr< HoughTree > m_houghTree
Dynamic hough tree structure traversed in the leaf search.

◆ getArray()

const Array< I > & getArray ( ) const
inline

Getter for the array of discrete value for coordinate I.

Definition at line 225 of file BoxDivisionHoughTree.h.

226 {
227 return std::get<I>(m_arrays);
228 }

◆ getDivision()

size_t getDivision ( size_t  i) const
inline

Getter the number of divisions at each level for coordinate index I.

Definition at line 84 of file BoxDivisionHoughTree.h.

85 {
86 return m_divisions[i];
87 }
const std::array< size_t, sizeof ...(divisions)> m_divisions
Array of the number of divisions at each level.

◆ getMaxLevel()

int getMaxLevel ( ) const
inline

Getter for the currently set maximal level.

Definition at line 200 of file BoxDivisionHoughTree.h.

201 {
202 return m_maxLevel;
203 }

◆ getSectorLevelSkip()

int getSectorLevelSkip ( ) const
inline

Getter for number of levels to skip in first level to form a finer sectored hough space.

Definition at line 212 of file BoxDivisionHoughTree.h.

213 {
214 return m_sectorLevelSkip;
215 }

◆ getTree()

HoughTree * getTree ( ) const
inline

Getter for the tree used in the search in the hough plane.

Definition at line 194 of file BoxDivisionHoughTree.h.

195 {
196 return m_houghTree.get();
197 }

◆ initialize()

void initialize ( )
inline

Initialise the algorithm by constructing the hough tree from the parameters.

Definition at line 164 of file BoxDivisionHoughTree.h.

165 {
166 // Compose the hough space
167 HoughBox houghPlane = constructHoughPlane();
169 m_houghTree.reset(new HoughTree(std::move(houghPlane), std::move(boxDivision)));
170 }
SectoredLinearDivision< HoughBox, divisions... > BoxDivision
Type of the box division strategy.
HoughBox constructHoughPlane()
Construct the box of the top node of the tree.
WeightedFastHoughTree< AItemPtr, HoughBox, BoxDivision > HoughTree
Type of the fast hough tree structure.

◆ raze()

void raze ( )
inline

Release all memory that the tree acquired during the runs.

Definition at line 187 of file BoxDivisionHoughTree.h.

188 {
189 m_houghTree->raze();
190 }

◆ seed()

void seed ( const AItemPtrs &  items)
inline

Prepare the leave finding by filling the top node with given hits.

Definition at line 174 of file BoxDivisionHoughTree.h.

175 {
176 if (not m_houghTree) initialize();
177 m_houghTree->seed(items);
178 }
void initialize()
Initialise the algorithm by constructing the hough tree from the parameters.

◆ setMaxLevel()

void setMaxLevel ( int  maxLevel)
inline

Setter maximal level of the hough tree.

Definition at line 206 of file BoxDivisionHoughTree.h.

207 {
208 m_maxLevel = maxLevel;
209 }

◆ setSectorLevelSkip()

void setSectorLevelSkip ( int  sectorLevelSkip)
inline

Setter for number of levels to skip in first level to form a finer sectored hough space.

Definition at line 218 of file BoxDivisionHoughTree.h.

219 {
220 m_sectorLevelSkip = sectorLevelSkip;
221 }

Member Data Documentation

◆ m_arrays

Arrays m_arrays
private

A tuple of value arrays providing the memory for the discrete bin bounds.

Definition at line 258 of file BoxDivisionHoughTree.h.

◆ m_divisions

const std::array<size_t, sizeof ...(divisions)> m_divisions = {{divisions ...}}
private

Array of the number of divisions at each level.

Definition at line 252 of file BoxDivisionHoughTree.h.

◆ m_houghTree

std::unique_ptr<HoughTree> m_houghTree = nullptr
private

Dynamic hough tree structure traversed in the leaf search.

Definition at line 261 of file BoxDivisionHoughTree.h.

◆ m_maxLevel

int m_maxLevel
private

Number of the maximum tree level.

Definition at line 246 of file BoxDivisionHoughTree.h.

◆ m_overlaps

HoughBox::Delta m_overlaps
private

An tuple of division overlaps in each coordinate.

Definition at line 255 of file BoxDivisionHoughTree.h.

◆ m_sectorLevelSkip

int m_sectorLevelSkip
private

Number of levels to skip in first level to form a finer sectored hough space.

Definition at line 249 of file BoxDivisionHoughTree.h.


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