Belle II Software development
QuadTreeNode.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10
11#include <framework/logging/Logger.h>
12
13#include <vector>
14
15namespace Belle2 {
20 namespace TrackFindingCDC {
21
28 template<typename AX, typename AY, class AItem>
30
31 public:
34
36 using XSpan = std::array<AX, 2>;
37
39 using YSpan = std::array<AY, 2>;
40
42 using XBinBounds = std::array<AX, 4>;
43
45 using YBinBounds = std::array<AY, 4>;
46
48 using Children = std::vector<This>;
49
56 QuadTreeNode(XSpan xSpan, YSpan ySpan, int level, This* parent)
57 : m_xBinBounds {
58 xSpan[0],
59 xSpan[0] + (xSpan[1] - xSpan[0]) / 2,
60 xSpan[1] - (xSpan[1] - xSpan[0]) / 2,
61 xSpan[1]
62 }
63 , m_yBinBounds({
64 ySpan[0],
65 ySpan[0] + (ySpan[1] - ySpan[0]) / 2,
66 ySpan[1] - (ySpan[1] - ySpan[0]) / 2,
67 ySpan[1]
68 })
69 , m_parent(level > 0 ? parent : nullptr)
70 , m_level(level)
71 , m_filled(false)
72 {
73 B2ASSERT("QuadTree datastructure only supports levels < 255", level < 255);
74 }
75
77 void insertItem(AItem* item)
78 {
79 m_items.push_back(item);
80 }
81
83 void reserveItems(int nItems)
84 {
85 m_items.reserve(nItems);
86 }
87
89 std::vector<AItem*>& getItems()
90 {
91 return m_items;
92 }
93
95 int getNItems() const
96 {
97 return m_items.size();
98 }
99
102 {
103 m_items.clear();
104 }
105
108 {
109 return m_children;
110 }
111
117 {
118 // automatically removes all lower level objects
119 m_children.clear();
120 m_filled = false;
121 }
122
124 int getLevel() const
125 {
126 return m_level;
127 }
128
130 bool checkFilled() const
131 {
132 return m_filled;
133 }
134
137 {
138 m_filled = true;
139 }
140
143 {
144 return m_parent;
145 }
146
148 constexpr int getXNbins() const
149 {
150 return m_xBinBounds.size() / 2;
151 }
152
154 AX getXMin() const
155 {
156 return m_xBinBounds.front();
157 }
158
160 AX getXMax() const
161 {
162 return m_xBinBounds.back();
163 }
164
166 AX getXBinWidth(int iBin)
167 {
168 return std::abs(getXUpperBound(iBin) - getXLowerBound(iBin));
169 }
170
172 AX getXLowerBound(int iBin) const
173 {
174 return m_xBinBounds[2 * iBin];
175 }
176
178 AX getXUpperBound(int iBin) const
179 {
180 return m_xBinBounds[2 * iBin + 1];
181 }
182
184 constexpr int getYNbins() const
185 {
186 return m_yBinBounds.size() / 2;
187 }
188
190 AY getYMin() const
191 {
192 return m_yBinBounds.front();
193 }
194
196 AY getYMax() const
197 {
198 return m_yBinBounds.back();
199 }
200
202 AY getYBinWidth(int iBin)
203 {
204 return std::abs(getYUpperBound(iBin) - getYLowerBound(iBin));
205 }
206
207 AY getYLowerBound(int iBin) const
208 {
209 return m_yBinBounds[2 * iBin];
210 }
211
213 AY getYUpperBound(int iBin) const
214 {
215 return m_yBinBounds[2 * iBin + 1];
216 }
217
218 private:
221
223 std::vector<AItem*> m_items;
224
226 std::vector<This> m_children;
227
230
233
236
239 };
240 }
242}
void clearChildren()
Clear items which the node holds and destroy all children below this node.
Children & getChildren()
Returns the children structure of this node.
std::vector< AItem * > & getItems()
Get items from node.
AY getYBinWidth(int iBin)
Getter for the width of the iBin bin in "r" direction.
AX getXMax() const
Get maximal "Theta" value of the node.
bool m_filled
Is the node has been filled with items.
void insertItem(AItem *item)
Insert item into node.
std::vector< This > Children
Type of the child node structure for this node.
This * getParent() const
Return pointer to the parent of the node.
AY getYMax() const
Get maximal "r" value of the node.
std::array< AY, 4 > YBinBounds
Type to store the minimum and maximum of the two bins in Y direction.
std::array< AX, 4 > XBinBounds
Type to store the minimum and maximum of the two bins in X direction.
void reserveItems(int nItems)
Reserve memory for holding items.
int m_level
Level of node in the tree.
std::array< AY, 2 > YSpan
Type for a span in the Y direction that is covered by the tree.
void setFilled()
Set status of node to "filled" (children nodes has been filled)
AY getYMin() const
Get minimal "r" value of the node.
int getLevel() const
Returns level of the node in tree (i.e., how much ancestors the node has)
AX getXLowerBound(int iBin) const
Get lower "Theta" value of given bin.
void clearItems()
Clear items which the node holds.
QuadTreeNode(XSpan xSpan, YSpan ySpan, int level, This *parent)
Constructor setting up the potential division points.
AY getYUpperBound(int iBin) const
Get upper "r" value of given bin.
std::array< AX, 2 > XSpan
Type for a span in the X direction that is covered by the tree.
This * m_parent
Pointer to the parent node.
AY getYLowerBound(int iBin) const
Get lower "r" value of given bin.
bool checkFilled() const
Check whether node has been processed, i.e.
int getNItems() const
Check if the node passes threshold on number of hits.
QuadTreeNode< AX, AY, AItem > This
Type of this class.
AX getXBinWidth(int iBin)
Getter for the width of the iBin bin in "Theta" direction.
constexpr int getXNbins() const
Get number of bins in "Theta" direction.
constexpr int getYNbins() const
Get number of bins in "r" direction.
AX getXMin() const
Get minimal "Theta" value of the node.
AX getXUpperBound(int iBin) const
Get upper "Theta" value of given bin.
Abstract base class for different kinds of events.