-
Notifications
You must be signed in to change notification settings - Fork 3
/
KDTreeLinkerToolsT.h
82 lines (66 loc) · 1.79 KB
/
KDTreeLinkerToolsT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef KDTreeLinkerToolsTemplated_h
#define KDTreeLinkerToolsTemplated_h
#include <array>
// Box structure used to define 2D field.
// It's used in KDTree building step to divide the detector
// space (ECAL, HCAL...) and in searching step to create a bounding
// box around the demanded point (Track collision point, PS projection...).
template<unsigned DIM>
struct KDTreeBoxT
{
std::array<float,DIM> dimmin, dimmax;
template<typename... Ts>
KDTreeBoxT(Ts... dimargs) {
static_assert(sizeof...(dimargs) == 2*DIM,"Constructor requires 2*DIM args");
std::vector<float> dims = {dimargs...};
for( unsigned i = 0; i < DIM; ++i ) {
dimmin[i] = dims[2*i];
dimmax[i] = dims[2*i+1];
}
}
KDTreeBoxT() {}
};
typedef KDTreeBoxT<2> KDTreeBox;
typedef KDTreeBoxT<3> KDTreeCube;
// Data stored in each KDTree node.
// The dim1/dim2 fields are usually the duplication of some PFRecHit values
// (eta/phi or x/y). But in some situations, phi field is shifted by +-2.Pi
template<typename DATA,unsigned DIM>
struct KDTreeNodeInfoT
{
DATA data;
std::array<float,DIM> dims;
public:
KDTreeNodeInfoT()
{}
template<typename... Ts>
KDTreeNodeInfoT(const DATA& d,Ts... dimargs)
: data(d), dims{ {dimargs...} }
{}
};
// KDTree node.
template <typename DATA, unsigned DIM>
struct KDTreeNodeT
{
// Data
KDTreeNodeInfoT<DATA,DIM> info;
// Right/left sons.
KDTreeNodeT<DATA,DIM> *left, *right;
// Region bounding box.
KDTreeBoxT<DIM> region;
public:
KDTreeNodeT()
: left(0), right(0)
{}
void setAttributs(const KDTreeBoxT<DIM>& regionBox,
const KDTreeNodeInfoT<DATA,DIM>& infoToStore)
{
info = infoToStore;
region = regionBox;
}
void setAttributs(const KDTreeBoxT<DIM>& regionBox)
{
region = regionBox;
}
};
#endif