CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KDTreeLinkerTools.h
Go to the documentation of this file.
1 #ifndef KDTreeLinkerToolsTemplated_h
2 #define KDTreeLinkerToolsTemplated_h
3 
4 #include <algorithm>
5 
6 // Box structure used to define 2D field.
7 // It's used in KDTree building step to divide the detector
8 // space (ECAL, HCAL...) and in searching step to create a bounding
9 // box around the demanded point (Track collision point, PS projection...).
10 struct KDTreeBox
11 {
12  float dim1min, dim1max;
13  float dim2min, dim2max;
14 
15  public:
16 
17  KDTreeBox(float d1min, float d1max,
18  float d2min, float d2max)
19  : dim1min (d1min), dim1max(d1max)
20  , dim2min (d2min), dim2max(d2max)
21  {}
22 
24  : dim1min (0), dim1max(0)
25  , dim2min (0), dim2max(0)
26  {}
27 };
28 
29 
30 // Data stored in each KDTree node.
31 // The dim1/dim2 fields are usually the duplication of some PFRecHit values
32 // (eta/phi or x/y). But in some situations, phi field is shifted by +-2.Pi
33 template <typename DATA>
34 struct KDTreeNodeInfo
35 {
37  float dim[2];
38  enum {kDim1=0, kDim2=1};
39 
40  public:
42  {}
43 
45  float dim_1,
46  float dim_2)
47  : data(d), dim{dim_1, dim_2}
48  {}
49 };
50 
51 template <typename DATA>
52 struct KDTreeNodes {
53  std::vector<float> median; // or dimCurrent;
54  std::vector<int> right;
55  std::vector<float> dimOther;
56  std::vector<DATA> data;
57 
58  int poolSize;
59  int poolPos;
60 
62 
63  bool empty() const { return poolPos == -1; }
64  int size() const { return poolPos + 1; }
65 
66  void clear() {
67  median.clear();
68  right.clear();
69  dimOther.clear();
70  data.clear();
71  poolSize = -1;
72  poolPos = -1;
73  }
74 
75  int getNextNode() {
76  ++poolPos;
77  return poolPos;
78  }
79 
80  void build(int sizeData) {
81  poolSize = sizeData*2-1;
82  median.resize(poolSize);
83  right.resize(poolSize);
84  dimOther.resize(poolSize);
85  data.resize(poolSize);
86  };
87 
88  constexpr bool isLeaf(int right) const {
89  // Valid values of right are always >= 2
90  // index 0 is the root, and 1 is the first left node
91  // Exploit index values 0 and 1 to mark which of dim1/dim2 is the
92  // current one in recSearch() at the depth of the leaf.
93  return right < 2;
94  }
95 
96  bool isLeafIndex(int index) const {
97  return isLeaf(right[index]);
98  }
99 };
100 
101 #endif
constexpr KDTreeNodes()
constexpr bool isLeaf(int right) const
std::vector< int > right
std::vector< float > dimOther
std::vector< float > median
KDTreeBox(float d1min, float d1max, float d2min, float d2max)
#define constexpr
bool empty() const
tuple d
Definition: ztail.py:151
bool isLeafIndex(int index) const
int size() const
void build(int sizeData)
std::vector< DATA > data
KDTreeNodeInfo(const DATA &d, float dim_1, float dim_2)