Belle II Software development
SimpleHitBasedHoughTree< AHitPtr, InBox, divisions > Class Template Reference

A convenience class based on a BoxDivisionHoughTree for "hit-like" classes. More...

#include <SimpleHitBasedHoughTree.h>

Inheritance diagram for SimpleHitBasedHoughTree< AHitPtr, InBox, divisions >:
BoxDivisionHoughTree< AHitPtr, InBox::HoughBox, divisions... >

Public Types

using Node = typename Super::Node
 Type of the node in the hough tree.
 
using HoughBox = typename InBox::HoughBox
 Type of the hough box.
 
using BoxDivision
 Type of the box division strategy.
 
using HoughTree
 Type of the fast hough tree structure.
 
using Type
 Type of the coordinate I.
 
using HasType
 Predicate that the given type is indeed a coordinate of the hough space.
 
using TypeIndex
 Function to get the coordinate index from its type.
 
using Width
 Type of the width in coordinate I.
 

Public Member Functions

 SimpleHitBasedHoughTree (size_t maxLevel, float curlCurv=NAN)
 Constructor using the given maximal level.
 
std::vector< std::pair< HoughBox, std::vector< AHitPtr > > > find (const TrackingUtilities::Weight &minWeight, const double maxCurv=NAN)
 Find disjoint leaves heavier than minWeight.
 
std::vector< std::pair< HoughBox, std::vector< AHitPtr > > > findBest (const TrackingUtilities::Weight &minWeight, const double maxCurv=NAN)
 Find the best trajectory and repeat the process until no bin heavier than minWeight can be found.
 
std::vector< std::pair< HoughBox, std::vector< AHitPtr > > > findSingleBest (const TrackingUtilities::Weight &minWeight, const double maxCurv=NAN)
 Find the best trajectory from the single heaviest bin heavier than minWeight.
 
template<class ALeafProcessor>
void findUsing (ALeafProcessor &leafProcessor)
 Fill and walk the tree using invoking the leaf processor on each encountered node.
 
size_t getDivision (size_t i) const
 Getter the number of divisions at each level for coordinate index I.
 
void constructArray (double lowerBound, double upperBound, Width< I > nBinOverlap=0, Width< I > nBinWidth=0)
 Construct the discrete value array at coordinate index I.
 
void assignArray (Array< I > array, Width< I > overlap=0)
 Provide an externally constructed array by coordinate index.
 
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.
 
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.
 
const Array< I > & getArray () const
 Getter for the array of discrete value for coordinate I.
 

Private Types

using Super = BoxDivisionHoughTree<AHitPtr, typename InBox::HoughBox, divisions...>
 Type of the base class.
 
using Array
 Type of the discrete value array to coordinate index I.
 
using Arrays
 Tuple type of the discrete value arrays.
 

Private Member Functions

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

double m_curlCurv = 0.018
 Curvature below which a trajectory is considered non curling.
 
StereoHitContained< InBox > m_stereoHitContainedInBox
 Predicate checking if a hit is in the realm of the sweeped object.
 
const std::array< size_t, sizeof ...(divisions)> m_divisions
 Array of the number of divisions at each level.
 
std::unique_ptr< HoughTreem_houghTree
 Dynamic hough tree structure traversed in the leaf search.
 
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.
 
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.
 

Detailed Description

template<class AHitPtr, class InBox, size_t ... divisions>
class Belle2::TrackFindingCDC::SimpleHitBasedHoughTree< AHitPtr, InBox, divisions >

A convenience class based on a BoxDivisionHoughTree for "hit-like" classes.

You still have to implement the box and the division by yourself, but the typical search functions are implemented in this class.

Definition at line 31 of file SimpleHitBasedHoughTree.h.

Member Typedef Documentation

◆ Array

using Array
privateinherited

Type of the discrete value array to coordinate index I.

Definition at line 78 of file BoxDivisionHoughTree.h.

◆ Arrays

using Arrays
privateinherited

Tuple type of the discrete value arrays.

Definition at line 81 of file BoxDivisionHoughTree.h.

◆ BoxDivision

using BoxDivision
inherited

Type of the box division strategy.

Definition at line 41 of file BoxDivisionHoughTree.h.

◆ HasType

using HasType
inherited

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

Definition at line 52 of file BoxDivisionHoughTree.h.

◆ HoughBox

template<class AHitPtr, class InBox, size_t ... divisions>
using HoughBox = typename InBox::HoughBox

Type of the hough box.

Definition at line 43 of file SimpleHitBasedHoughTree.h.

◆ HoughTree

using HoughTree
inherited

Type of the fast hough tree structure.

Definition at line 44 of file BoxDivisionHoughTree.h.

◆ Node

template<class AHitPtr, class InBox, size_t ... divisions>
using Node = typename Super::Node

Type of the node in the hough tree.

Definition at line 40 of file SimpleHitBasedHoughTree.h.

◆ Super

template<class AHitPtr, class InBox, size_t ... divisions>
using Super = BoxDivisionHoughTree<AHitPtr, typename InBox::HoughBox, divisions...>
private

Type of the base class.

Definition at line 36 of file SimpleHitBasedHoughTree.h.

◆ Type

using Type
inherited

Type of the coordinate I.

Definition at line 48 of file BoxDivisionHoughTree.h.

◆ TypeIndex

using TypeIndex
inherited

Function to get the coordinate index from its type.

Definition at line 56 of file BoxDivisionHoughTree.h.

◆ Width

using Width
inherited

Type of the width in coordinate I.

Definition at line 60 of file BoxDivisionHoughTree.h.

Constructor & Destructor Documentation

◆ SimpleHitBasedHoughTree()

template<class AHitPtr, class InBox, size_t ... divisions>
SimpleHitBasedHoughTree ( size_t maxLevel,
float curlCurv = NAN )
inlineexplicit

Constructor using the given maximal level.

Definition at line 47 of file SimpleHitBasedHoughTree.h.

47 :
48 Super(maxLevel),
49 m_curlCurv(curlCurv),
50 m_stereoHitContainedInBox(curlCurv)
51 {}

Member Function Documentation

◆ assignArray() [1/2]

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

Provide an externally constructed array by coordinate index.

Definition at line 129 of file BoxDivisionHoughTree.h.

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

◆ assignArray() [2/2]

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

Provide an externally constructed array by coordinate type.

Definition at line 158 of file BoxDivisionHoughTree.h.

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

◆ constructArray()

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

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 105 of file BoxDivisionHoughTree.h.

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

◆ constructHoughPlane()

HoughBox constructHoughPlane ( )
inlineprivateinherited

Construct the box of the top node of the tree.

Definition at line 246 of file BoxDivisionHoughTree.h.

247 {
248 return constructHoughPlaneImpl(std::make_index_sequence<sizeof...(divisions)>());
249 }

◆ constructHoughPlaneImpl()

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

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

Definition at line 240 of file BoxDivisionHoughTree.h.

241 {
242 return HoughBox(Type<Is>::getRange(std::get<Is>(m_arrays))...);
243 }

◆ fell()

void fell ( )
inlineinherited

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

Definition at line 182 of file BoxDivisionHoughTree.h.

183 {
184 HoughTree* const tree = this->m_houghTree.get();
185 if (tree != nullptr) {
186 tree->fell();
187 }
188 }

◆ find()

template<class AHitPtr, class InBox, size_t ... divisions>
std::vector< std::pair< HoughBox, std::vector< AHitPtr > > > find ( const TrackingUtilities::Weight & minWeight,
const double maxCurv = NAN )
inline

Find disjoint leaves heavier than minWeight.

Definition at line 56 of file SimpleHitBasedHoughTree.h.

57 {
58 auto skipHighCurvatureAndLowWeightNode = [minWeight, maxCurv](const Node * node) {
59 const HoughBox& houghBox = *node;
60 return not(node->getWeight() >= minWeight and not(getLowerCurv(houghBox) > maxCurv));
61 };
62 return this->getTree()->findLeavesDisjoint(m_stereoHitContainedInBox,
63 this->getMaxLevel(),
64 skipHighCurvatureAndLowWeightNode);
65 }

◆ findBest()

template<class AHitPtr, class InBox, size_t ... divisions>
std::vector< std::pair< HoughBox, std::vector< AHitPtr > > > findBest ( const TrackingUtilities::Weight & minWeight,
const double maxCurv = NAN )
inline

Find the best trajectory and repeat the process until no bin heavier than minWeight can be found.

Definition at line 69 of file SimpleHitBasedHoughTree.h.

70 {
71 auto skipHighCurvatureAndLowWeightNode = [minWeight, maxCurv](const Node * node) {
72 const HoughBox& houghBox = *node;
73 return not(node->getWeight() >= minWeight and not(getLowerCurv(houghBox) > maxCurv));
74 };
75 return this->getTree()->findHeaviestLeafRepeated(m_stereoHitContainedInBox,
76 this->getMaxLevel(),
77 skipHighCurvatureAndLowWeightNode);
78 }

◆ findSingleBest()

template<class AHitPtr, class InBox, size_t ... divisions>
std::vector< std::pair< HoughBox, std::vector< AHitPtr > > > findSingleBest ( const TrackingUtilities::Weight & minWeight,
const double maxCurv = NAN )
inline

Find the best trajectory from the single heaviest bin heavier than minWeight.

Definition at line 82 of file SimpleHitBasedHoughTree.h.

83 {
84 auto skipHighCurvatureAndLowWeightNode = [minWeight, maxCurv](const Node * node) {
85 const HoughBox& houghBox = *node;
86 return not(node->getWeight() >= minWeight and not(getLowerCurv(houghBox) > maxCurv));
87 };
88 std::unique_ptr<std::pair<HoughBox, std::vector<AHitPtr> > > found =
89 this->getTree()->findHeaviestLeafSingle(m_stereoHitContainedInBox,
90 this->getMaxLevel(),
91 skipHighCurvatureAndLowWeightNode);
92
93 std::vector<std::pair<HoughBox, std::vector<AHitPtr> > > result;
94 if (found) {
95 // Move the found content over. unique_ptr still destroys the left overs.
96 result.push_back(std::move(*found));
97 }
98 return result;
99 }

◆ findUsing()

template<class AHitPtr, class InBox, size_t ... divisions>
template<class ALeafProcessor>
void findUsing ( ALeafProcessor & leafProcessor)
inline

Fill and walk the tree using invoking the leaf processor on each encountered node.

Definition at line 103 of file SimpleHitBasedHoughTree.h.

104 {
105 return this->getTree()->fillWalk(m_stereoHitContainedInBox,
106 leafProcessor);
107 }

◆ getArray()

const Array< I > & getArray ( ) const
inlineinherited

Getter for the array of discrete value for coordinate I.

Definition at line 232 of file BoxDivisionHoughTree.h.

233 {
234 return std::get<I>(m_arrays);
235 }

◆ getDivision()

size_t getDivision ( size_t i) const
inlineinherited

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

Definition at line 85 of file BoxDivisionHoughTree.h.

86 {
87 return m_divisions[i];
88 }

◆ getMaxLevel()

int getMaxLevel ( ) const
inlineinherited

Getter for the currently set maximal level.

Definition at line 207 of file BoxDivisionHoughTree.h.

208 {
209 return m_maxLevel;
210 }

◆ getSectorLevelSkip()

int getSectorLevelSkip ( ) const
inlineinherited

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

Definition at line 219 of file BoxDivisionHoughTree.h.

220 {
221 return m_sectorLevelSkip;
222 }

◆ getTree()

HoughTree * getTree ( ) const
inlineinherited

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

Definition at line 201 of file BoxDivisionHoughTree.h.

202 {
203 return m_houghTree.get();
204 }

◆ initialize()

void initialize ( )
inlineinherited

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

Definition at line 165 of file BoxDivisionHoughTree.h.

166 {
167 // Compose the hough space
168 HoughBox houghPlane = constructHoughPlane();
169 BoxDivision boxDivision(m_overlaps, m_sectorLevelSkip);
170 m_houghTree.reset(new HoughTree(std::move(houghPlane), std::move(boxDivision)));
171 }

◆ raze()

void raze ( )
inlineinherited

Release all memory that the tree acquired during the runs.

Definition at line 191 of file BoxDivisionHoughTree.h.

192 {
193 HoughTree* const tree = this->m_houghTree.get();
194 if (tree != nullptr) {
195 tree->raze();
196 }
197 }

◆ seed()

void seed ( const AItemPtrs & items)
inlineinherited

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

Definition at line 175 of file BoxDivisionHoughTree.h.

176 {
177 if (not m_houghTree) initialize();
178 m_houghTree->seed(items);
179 }

◆ setMaxLevel()

void setMaxLevel ( int maxLevel)
inlineinherited

Setter maximal level of the hough tree.

Definition at line 213 of file BoxDivisionHoughTree.h.

214 {
215 m_maxLevel = maxLevel;
216 }

◆ setSectorLevelSkip()

void setSectorLevelSkip ( int sectorLevelSkip)
inlineinherited

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

Definition at line 225 of file BoxDivisionHoughTree.h.

226 {
227 m_sectorLevelSkip = sectorLevelSkip;
228 }

Member Data Documentation

◆ m_arrays

Arrays m_arrays
privateinherited

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

Definition at line 268 of file BoxDivisionHoughTree.h.

◆ m_curlCurv

template<class AHitPtr, class InBox, size_t ... divisions>
double m_curlCurv = 0.018
private

Curvature below which a trajectory is considered non curling.

Definition at line 111 of file SimpleHitBasedHoughTree.h.

◆ m_divisions

const std::array<size_t, sizeof ...(divisions)> m_divisions
privateinherited

Array of the number of divisions at each level.

Definition at line 253 of file BoxDivisionHoughTree.h.

253{{divisions ...}};

◆ m_houghTree

std::unique_ptr<HoughTree> m_houghTree
privateinherited

Dynamic hough tree structure traversed in the leaf search.

Definition at line 256 of file BoxDivisionHoughTree.h.

◆ m_maxLevel

int m_maxLevel
privateinherited

Number of the maximum tree level.

Definition at line 259 of file BoxDivisionHoughTree.h.

◆ m_overlaps

HoughBox::Delta m_overlaps
privateinherited

An tuple of division overlaps in each coordinate.

Definition at line 265 of file BoxDivisionHoughTree.h.

◆ m_sectorLevelSkip

int m_sectorLevelSkip
privateinherited

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

Definition at line 262 of file BoxDivisionHoughTree.h.

◆ m_stereoHitContainedInBox

template<class AHitPtr, class InBox, size_t ... divisions>
StereoHitContained<InBox> m_stereoHitContainedInBox
private

Predicate checking if a hit is in the realm of the sweeped object.

Definition at line 114 of file SimpleHitBasedHoughTree.h.


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