Belle II Software  release-05-02-19
QuadTreeNode.h
1 /**************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2014 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Viktor Trusov, Thomas Hauth *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 #pragma once
11 
12 
13 #include <framework/logging/Logger.h>
14 
15 #include <vector>
16 
17 namespace Belle2 {
22  namespace TrackFindingCDC {
23 
30  template<typename AX, typename AY, class AItem>
31  class QuadTreeNode {
32 
33  public:
35  using This = QuadTreeNode<AX, AY, AItem>;
36 
38  using XSpan = std::array<AX, 2>;
39 
41  using YSpan = std::array<AY, 2>;
42 
44  using XBinBounds = std::array<AX, 4>;
45 
47  using YBinBounds = std::array<AY, 4>;
48 
50  using Children = std::vector<This>;
51 
59  QuadTreeNode(XSpan xSpan, YSpan ySpan, int level, This* parent)
60  : m_xBinBounds(
61  {
62  xSpan[0],
63  xSpan[0] + (xSpan[1] - xSpan[0]) / 2,
64  xSpan[1] - (xSpan[1] - xSpan[0]) / 2,
65  xSpan[1]
66  })
67  , m_yBinBounds({ySpan[0],
68  ySpan[0] + (ySpan[1] - ySpan[0]) / 2,
69  ySpan[1] - (ySpan[1] - ySpan[0]) / 2,
70  ySpan[1]
71  })
72  , m_level(level)
73  , m_parent(level > 0 ? parent : nullptr)
74  , m_filled(false)
75  {
76  B2ASSERT("QuadTree datastructure only supports levels < 255", level < 255);
77  }
78 
80  void insertItem(AItem* item)
81  {
82  m_items.push_back(item);
83  }
84 
86  void reserveItems(int nItems)
87  {
88  m_items.reserve(nItems);
89  }
90 
92  std::vector<AItem*>& getItems()
93  {
94  return m_items;
95  }
96 
98  int getNItems() const
99  {
100  return m_items.size();
101  }
102 
104  void clearItems()
105  {
106  m_items.clear();
107  }
108 
111  {
112  return m_children;
113  }
114 
119  void clearChildren()
120  {
121  // automatically removes all lower level objects
122  m_children.clear();
123  m_filled = false;
124  }
125 
127  int getLevel() const
128  {
129  return m_level;
130  }
131 
133  bool checkFilled() const
134  {
135  return m_filled;
136  }
137 
139  void setFilled()
140  {
141  m_filled = true;
142  }
143 
145  This* getParent() const
146  {
147  return m_parent;
148  }
149 
151  constexpr int getXNbins() const
152  {
153  return m_xBinBounds.size() / 2;
154  }
155 
157  AX getXMin() const
158  {
159  return m_xBinBounds.front();
160  }
161 
163  AX getXMax() const
164  {
165  return m_xBinBounds.back();
166  }
167 
169  AX getXBinWidth(int iBin)
170  {
171  return std::abs(getXUpperBound(iBin) - getXLowerBound(iBin));
172  }
173 
175  AX getXLowerBound(int iBin) const
176  {
177  return m_xBinBounds[2 * iBin];
178  }
179 
181  AX getXUpperBound(int iBin) const
182  {
183  return m_xBinBounds[2 * iBin + 1];
184  }
185 
187  constexpr int getYNbins() const
188  {
189  return m_yBinBounds.size() / 2;
190  }
191 
193  AY getYMin() const
194  {
195  return m_yBinBounds.front();
196  }
197 
199  AY getYMax() const
200  {
201  return m_yBinBounds.back();
202  }
203 
205  AY getYBinWidth(int iBin)
206  {
207  return std::abs(getYUpperBound(iBin) - getYLowerBound(iBin));
208  }
210  AY getYLowerBound(int iBin) const
211  {
212  return m_yBinBounds[2 * iBin];
213  }
214 
216  AY getYUpperBound(int iBin) const
217  {
218  return m_yBinBounds[2 * iBin + 1];
219  }
220 
221  private:
224 
227 
229  int m_level;
230 
232  This* m_parent;
233 
235  std::vector<AItem*> m_items;
236 
238  std::vector<This> m_children;
239 
241  bool m_filled;
242  };
243  }
245 }
Belle2::TrackFindingCDC::QuadTreeNode::getXNbins
constexpr int getXNbins() const
Get number of bins in "Theta" direction.
Definition: QuadTreeNode.h:159
Belle2::TrackFindingCDC::QuadTreeNode::YSpan
std::array< AY, 2 > YSpan
Type for a span in the Y direction that is covered by the tree.
Definition: QuadTreeNode.h:49
Belle2::TrackFindingCDC::QuadTreeNode::getXMax
AX getXMax() const
Get maximal "Theta" value of the node.
Definition: QuadTreeNode.h:171
Belle2::TrackFindingCDC::QuadTreeNode::m_items
std::vector< AItem * > m_items
Vector of items which belongs to the node.
Definition: QuadTreeNode.h:243
Belle2::TrackFindingCDC::QuadTreeNode::getXMin
AX getXMin() const
Get minimal "Theta" value of the node.
Definition: QuadTreeNode.h:165
Belle2::TrackFindingCDC::QuadTreeNode::getYBinWidth
AY getYBinWidth(int iBin)
Getter for the width of the iBin bin in "r" direction.
Definition: QuadTreeNode.h:213
Belle2::TrackFindingCDC::QuadTreeNode::m_xBinBounds
XBinBounds m_xBinBounds
bins range on theta
Definition: QuadTreeNode.h:231
Belle2::TrackFindingCDC::QuadTreeNode::m_parent
This * m_parent
Pointer to the parent node.
Definition: QuadTreeNode.h:240
Belle2::TrackFindingCDC::QuadTreeNode::This
QuadTreeNode< AX, AY, AItem > This
Type of this class.
Definition: QuadTreeNode.h:43
Belle2::TrackFindingCDC::QuadTreeNode::checkFilled
bool checkFilled() const
Check whether node has been processed, i.e.
Definition: QuadTreeNode.h:141
Belle2::TrackFindingCDC::QuadTreeNode::m_level
int m_level
Level of node in the tree.
Definition: QuadTreeNode.h:237
Belle2::TrackFindingCDC::QuadTreeNode::getYUpperBound
AY getYUpperBound(int iBin) const
Get upper "r" value of given bin.
Definition: QuadTreeNode.h:224
Belle2::TrackFindingCDC::QuadTreeNode::insertItem
void insertItem(AItem *item)
Insert item into node.
Definition: QuadTreeNode.h:88
Belle2::TrackFindingCDC::QuadTreeNode::m_filled
bool m_filled
Is the node has been filled with items.
Definition: QuadTreeNode.h:249
Belle2::TrackFindingCDC::QuadTreeNode::getNItems
int getNItems() const
Check if the node passes threshold on number of hits.
Definition: QuadTreeNode.h:106
Belle2::TrackFindingCDC::QuadTreeNode::YBinBounds
std::array< AY, 4 > YBinBounds
Type to store the minimum and maximum of the two bins in Y direction.
Definition: QuadTreeNode.h:55
Belle2::TrackFindingCDC::QuadTreeNode::setFilled
void setFilled()
Set status of node to "filled" (children nodes has been filled)
Definition: QuadTreeNode.h:147
Belle2::TrackFindingCDC::QuadTreeNode::Children
std::vector< This > Children
Type of the child node structure for this node.
Definition: QuadTreeNode.h:58
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::QuadTreeNode::getXLowerBound
AX getXLowerBound(int iBin) const
Get lower "Theta" value of given bin.
Definition: QuadTreeNode.h:183
Belle2::TrackFindingCDC::QuadTreeNode::getXUpperBound
AX getXUpperBound(int iBin) const
Get upper "Theta" value of given bin.
Definition: QuadTreeNode.h:189
Belle2::TrackFindingCDC::QuadTreeNode::getYMin
AY getYMin() const
Get minimal "r" value of the node.
Definition: QuadTreeNode.h:201
Belle2::TrackFindingCDC::QuadTreeNode::getChildren
Children & getChildren()
Returns the children structure of this node.
Definition: QuadTreeNode.h:118
Belle2::TrackFindingCDC::QuadTreeNode::XSpan
std::array< AX, 2 > XSpan
Type for a span in the X direction that is covered by the tree.
Definition: QuadTreeNode.h:46
Belle2::TrackFindingCDC::QuadTreeNode
Class which holds quadtree structure.
Definition: QuadTreeNode.h:39
Belle2::TrackFindingCDC::QuadTreeNode::getItems
std::vector< AItem * > & getItems()
Get items from node.
Definition: QuadTreeNode.h:100
Belle2::TrackFindingCDC::QuadTreeNode::getYNbins
constexpr int getYNbins() const
Get number of bins in "r" direction.
Definition: QuadTreeNode.h:195
Belle2::TrackFindingCDC::QuadTreeNode::reserveItems
void reserveItems(int nItems)
Reserve memory for holding items.
Definition: QuadTreeNode.h:94
Belle2::TrackFindingCDC::QuadTreeNode::m_yBinBounds
YBinBounds m_yBinBounds
bins range on r
Definition: QuadTreeNode.h:234
Belle2::TrackFindingCDC::QuadTreeNode::m_children
std::vector< This > m_children
Pointers to the children nodes.
Definition: QuadTreeNode.h:246
Belle2::TrackFindingCDC::QuadTreeNode::getLevel
int getLevel() const
Returns level of the node in tree (i.e., how much ancestors the node has)
Definition: QuadTreeNode.h:135
Belle2::TrackFindingCDC::QuadTreeNode::clearChildren
void clearChildren()
Clear items which the node holds and destroy all children below this node.
Definition: QuadTreeNode.h:127
Belle2::TrackFindingCDC::QuadTreeNode::getYLowerBound
AY getYLowerBound(int iBin) const
Get lower "r" value of given bin.
Definition: QuadTreeNode.h:218
Belle2::TrackFindingCDC::QuadTreeNode::getParent
This * getParent() const
Return pointer to the parent of the node.
Definition: QuadTreeNode.h:153
Belle2::TrackFindingCDC::QuadTreeNode::XBinBounds
std::array< AX, 4 > XBinBounds
Type to store the minimum and maximum of the two bins in X direction.
Definition: QuadTreeNode.h:52
Belle2::TrackFindingCDC::QuadTreeNode::clearItems
void clearItems()
Clear items which the node holds.
Definition: QuadTreeNode.h:112
Belle2::TrackFindingCDC::QuadTreeNode::getXBinWidth
AX getXBinWidth(int iBin)
Getter for the width of the iBin bin in "Theta" direction.
Definition: QuadTreeNode.h:177
Belle2::TrackFindingCDC::QuadTreeNode::QuadTreeNode
QuadTreeNode(XSpan xSpan, YSpan ySpan, int level, This *parent)
Constructor setting up the potential division points.
Definition: QuadTreeNode.h:67
Belle2::TrackFindingCDC::QuadTreeNode::getYMax
AY getYMax() const
Get maximal "r" value of the node.
Definition: QuadTreeNode.h:207