CMS 3D CMS Logo

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