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