LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
kdTree.h
Go to the documentation of this file.
1 
9 #ifndef kdTree_h
10 #define kdTree_h
11 
12 // Framework Includes
13 namespace fhicl {
14  class ParameterSet;
15 }
16 
17 // Algorithm includes
19 
20 // std includes
21 #include <list>
22 #include <utility>
23 #include <vector>
24 
25 //------------------------------------------------------------------------------------------------------------------------------------------
26 
27 namespace lar_cluster3d {
31  class kdTree {
32  public:
37  : fEnableMonitoring(false)
38  , fTimeToBuild(0.)
39  , fPairSigmaPeakTime(0.)
40  , fRefLeafBestDist(0.)
41  , fMaxWireDeltas(0)
42  {}
43 
49  kdTree(fhicl::ParameterSet const& pset);
50 
54  ~kdTree();
55 
61  void configure(fhicl::ParameterSet const& pset);
62 
66  class KdTreeNode;
67 
68  using KdTreeNodeVec = std::vector<KdTreeNode>;
69  using KdTreeNodeList = std::list<KdTreeNode>;
70  using Hit3DVec = std::vector<const reco::ClusterHit3D*>;
71 
78  KdTreeNode& BuildKdTree(Hit3DVec::iterator,
81  int depth = 0) const;
82 
83  using CandPair = std::pair<double, const reco::ClusterHit3D*>;
84  using CandPairList = std::list<CandPair>;
85 
86  size_t FindNearestNeighbors(const reco::ClusterHit3D*,
87  const KdTreeNode&,
88  CandPairList&,
89  float&) const;
90  bool FindEntry(const reco::ClusterHit3D*, const KdTreeNode&, CandPairList&, float&, bool&, int)
91  const;
92  bool FindEntryBrute(const reco::ClusterHit3D*, const KdTreeNode&, int) const;
93 
97  KdTreeNode BuildKdTree(const reco::HitPairList&, KdTreeNodeList&) const;
98 
102  KdTreeNode BuildKdTree(const reco::HitPairListPtr&, KdTreeNodeList&) const;
103 
104  float getTimeToExecute() const { return fTimeToBuild; }
105 
106  private:
110  bool consistentPairs(const reco::ClusterHit3D* pair1,
111  const reco::ClusterHit3D* pair2,
112  float& hitSeparation) const;
113 
114  float DistanceBetweenNodes(const reco::ClusterHit3D*, const reco::ClusterHit3D*) const;
115  float DistanceBetweenNodesYZ(const reco::ClusterHit3D*, const reco::ClusterHit3D*) const;
116 
118  mutable float fTimeToBuild;
122  };
123 
128  public:
129  enum SplitAxis { xPlane, yPlane, zPlane, leaf, null };
130 
131  KdTreeNode(SplitAxis axis, float axisVal, const KdTreeNode& left, const KdTreeNode& right)
132  : m_splitAxis(axis)
133  , m_axisValue(axisVal)
134  , m_clusterHit3D(0)
135  , m_leftTree(left)
136  , m_rightTree(right)
137  {}
138 
140  : m_splitAxis(SplitAxis::leaf)
141  , m_axisValue(0.)
142  , m_clusterHit3D(hit)
143  , m_leftTree(*this)
144  , m_rightTree(*this)
145  {}
146 
148  : m_splitAxis(SplitAxis::null)
149  , m_axisValue(0.)
150  , m_clusterHit3D(0)
151  , m_leftTree(*this)
152  , m_rightTree(*this)
153  {}
154 
155  bool isLeafNode() const { return m_splitAxis == SplitAxis::leaf; }
156  bool isNullNode() const { return m_splitAxis == SplitAxis::null; }
157 
158  SplitAxis getSplitAxis() const { return m_splitAxis; }
159  float getAxisValue() const { return m_axisValue; }
160  const reco::ClusterHit3D* getClusterHit3D() const { return m_clusterHit3D; }
161  const KdTreeNode& leftTree() const { return m_leftTree; }
162  const KdTreeNode& rightTree() const { return m_rightTree; }
163 
164  private:
166  float m_axisValue;
170  };
171 
172 } // namespace lar_cluster3d
173 #endif
intermediate_table::iterator iterator
float fRefLeafBestDist
Set neighborhood distance to this when ref leaf found.
Definition: kdTree.h:120
std::list< reco::ClusterHit3D > HitPairList
Definition: Cluster3D.h:330
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
kdTree class definiton
Definition: kdTree.h:31
const KdTreeNode & m_leftTree
Definition: kdTree.h:168
std::list< KdTreeNode > KdTreeNodeList
Definition: kdTree.h:69
std::pair< double, const reco::ClusterHit3D * > CandPair
Definition: kdTree.h:83
std::vector< const reco::ClusterHit3D * > Hit3DVec
Definition: kdTree.h:70
kdTree()
Default Constructor.
Definition: kdTree.h:36
const KdTreeNode & m_rightTree
Definition: kdTree.h:169
define a kd tree node
Definition: kdTree.h:127
KdTreeNode(const reco::ClusterHit3D *hit)
Definition: kdTree.h:139
parameter set interface
std::list< const reco::ClusterHit3D * > HitPairListPtr
Definition: Cluster3D.h:326
Detector simulation of raw signals on wires.
std::list< CandPair > CandPairList
Definition: kdTree.h:84
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
KdTreeNode(SplitAxis axis, float axisVal, const KdTreeNode &left, const KdTreeNode &right)
Definition: kdTree.h:131
float fPairSigmaPeakTime
Consider hits consistent if "significance" less than this.
Definition: kdTree.h:119
const KdTreeNode & rightTree() const
Definition: kdTree.h:162
int fMaxWireDeltas
Maximum total number of delta wires.
Definition: kdTree.h:121
const reco::ClusterHit3D * getClusterHit3D() const
Definition: kdTree.h:160
std::vector< KdTreeNode > KdTreeNodeVec
Definition: kdTree.h:68
float getTimeToExecute() const
Definition: kdTree.h:104
const KdTreeNode & leftTree() const
Definition: kdTree.h:161
SplitAxis getSplitAxis() const
Definition: kdTree.h:158
const reco::ClusterHit3D * m_clusterHit3D
Definition: kdTree.h:167