LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CBAlgoPolyShortestDist.cxx
Go to the documentation of this file.
2 
3 #include <cmath>
4 
5 namespace cmtool {
6 
7  //-------------------------------------------------------
9  //-------------------------------------------------------
10  {
12  SetMinNumHits(0);
13  SetMaxNumHits(99999);
14  SetDebug(false);
15  }
16 
17  //-----------------------------
19  //-----------------------------
20  {}
21 
22  //------------------------------------------------------------------------------------------
23  void CBAlgoPolyShortestDist::EventBegin(const std::vector<cluster::ClusterParamsAlg>& clusters)
24  //------------------------------------------------------------------------------------------
25  {
26  if (clusters.size()) tmp_min_dist = 99999;
27  }
28 
29  //-------------------------------
30  //void CBAlgoPolyShortestDist::EventEnd()
31  //-------------------------------
32  //{
33  //
34  //}
35 
36  //-----------------------------------------------------------------------------------------------
37  //void CBAlgoPolyShortestDist::IterationBegin(const std::vector<cluster::ClusterParamsAlg> &clusters)
38  //-----------------------------------------------------------------------------------------------
39  //{
40  //
41  //}
42 
43  //------------------------------------
44  //void CBAlgoPolyShortestDist::IterationEnd()
45  //------------------------------------
46  //{
47  //
48  //}
49 
50  //----------------------------------------------------------------
51  bool CBAlgoPolyShortestDist::Bool(const ::cluster::ClusterParamsAlg& cluster1,
52  const ::cluster::ClusterParamsAlg& cluster2)
53  //----------------------------------------------------------------
54  {
55  if ((cluster1.GetHitVector().size() < _min_hits) ||
56  (cluster2.GetHitVector().size() < _min_hits))
57  return false;
58 
59  if ((cluster1.GetHitVector().size() > _max_hits) ||
60  (cluster2.GetHitVector().size() > _max_hits))
61  return false;
62 
63  //if either has < 3 sides do not merge!
64  if ((cluster1.GetParams().PolyObject.Size() < 2) or
65  (cluster2.GetParams().PolyObject.Size() < 2)) {
66  return false;
67  }
68 
69  //loop over the points on the first polygon and calculate
70  //distance to each point on the second polygon
71  //if any two points are close enough to each other,
72  //merge the two clusters
73 
74  unsigned int npoints1 = cluster1.GetParams().PolyObject.Size();
75  unsigned int npoints2 = cluster2.GetParams().PolyObject.Size();
76  //loop over points on first polygon
77  for (unsigned int i = 0; i < npoints1; ++i) {
78  float pt1w = cluster1.GetParams().PolyObject.Point(i).first;
79  float pt1t = cluster1.GetParams().PolyObject.Point(i).second;
80  //loop over points on second polygon
81  for (unsigned int j = 0; j < npoints2; ++j) {
82  float pt2w = cluster2.GetParams().PolyObject.Point(j).first;
83  float pt2t = cluster2.GetParams().PolyObject.Point(j).second;
84  double distsqrd = pow(pt2w - pt1w, 2) + pow(pt2t - pt1t, 2);
85 
86  if (distsqrd < tmp_min_dist) tmp_min_dist = distsqrd;
87 
88  if (_debug) {
89  std::cout << "two polygon points dist2 is " << distsqrd << std::endl;
90  std::cout << "minimum dist was " << tmp_min_dist << std::endl;
91  }
92  if (distsqrd < _dist_sqrd_cut) return true;
93  }
94  }
95 
96  return false;
97  }
98 
99  //------------------------------
101  //------------------------------
102  {}
103 
104 }
virtual void Reset()
Function to reset the algorithm instance ... maybe implemented via child class.
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
Class def header for a class CBAlgoPolyShortestDist.
virtual void EventBegin(const std::vector< cluster::ClusterParamsAlg > &clusters)
CBAlgoPolyShortestDist()
Default constructor.