LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CBAlgoMergeTinyWithBig.cxx
Go to the documentation of this file.
2 
3 #include <cmath>
4 
5 namespace cmtool {
6 
7  //-------------------------------------------------------
9  //-------------------------------------------------------
10  {
11  SetMinHitsBig(50);
12  SetMaxHitsBig(99999);
13  SetMinHitsSmall(0);
14  SetMaxHitsSmall(15);
16 
17  SetDebug(false);
18  }
19 
20  //-----------------------------
22  //-----------------------------
23  {}
24 
25  //----------------------------------------------------------------
26  bool CBAlgoMergeTinyWithBig::Bool(const ::cluster::ClusterParamsAlg& cluster1,
27  const ::cluster::ClusterParamsAlg& cluster2)
28  //----------------------------------------------------------------
29  {
30 
31  if (_debug)
32  std::cout << "MergeTinyWithBig. One cluster has " << cluster1.GetNHits()
33  << " hits, the other has " << cluster2.GetNHits() << " hits." << std::endl;
34 
35  bool is_1_small = false;
36  bool is_2_small = false;
37  bool is_1_big = false;
38  bool is_2_big = false;
39 
40  //if the first cluster counts as "small"
41  if (cluster1.GetNHits() > _min_hits_small && cluster1.GetNHits() < _max_hits_small)
42  is_1_small = true;
43  //if the second cluster counts as "small"
44  if (cluster2.GetNHits() > _min_hits_small && cluster2.GetNHits() < _max_hits_small)
45  is_2_small = true;
46  if (cluster1.GetNHits() > _min_hits_big && cluster1.GetNHits() < _max_hits_big) is_1_big = true;
47  if (cluster2.GetNHits() > _min_hits_big && cluster2.GetNHits() < _max_hits_big) is_2_big = true;
48 
49  if (_debug)
50  std::cout << "is_1_small, is_1_big, is_2_small, is_2_big are: " << is_1_small << ", "
51  << is_1_big << ", " << is_2_small << ", " << is_2_big << std::endl;
52 
53  //if neither of the clusters is small don't merge
54  if (!is_1_small && !is_2_small) return false;
55  //if neither of the clusters is big, don't merge
56  if (!is_1_big && !is_2_big) return false;
57  //if both are small, don't merge
58  if (is_1_small && is_2_small) return false;
59  //if both are big, don't merge
60  if (is_1_big && is_2_big) return false;
61 
62  if (_debug) std::cout << "Looks like one of them is big, and one is small." << std::endl;
63  //god this code is ugly
64 
65  //now we know which one of them is big & the other is small.
66 
67  //loop over the points on the first polygon and calculate
68  //distance to each point on the second polygon
69  //if any two points are close enough to each other,
70  //merge the two clusters
71 
72  unsigned int npoints1 = cluster1.GetParams().PolyObject.Size();
73  unsigned int npoints2 = cluster2.GetParams().PolyObject.Size();
74  //loop over points on first polygon
75  for (unsigned int i = 0; i < npoints1; ++i) {
76  float pt1w = cluster1.GetParams().PolyObject.Point(i).first;
77  float pt1t = cluster1.GetParams().PolyObject.Point(i).second;
78  //loop over points on second polygon
79  for (unsigned int j = 0; j < npoints2; ++j) {
80  float pt2w = cluster2.GetParams().PolyObject.Point(j).first;
81  float pt2t = cluster2.GetParams().PolyObject.Point(j).second;
82  double distsqrd = pow(pt2w - pt1w, 2) + pow(pt2t - pt1t, 2);
83 
84  if (_debug) { std::cout << "two polygon points dist2 is " << distsqrd << std::endl; }
85  if (distsqrd < _dist_sqrd_cut) return true;
86  }
87  }
88 
89  return false;
90  }
91 
92  //------------------------------
94  //------------------------------
95  {}
96 
97 }
virtual void Reset()
Function to reset the algorithm instance ... maybe implemented via child class.
CBAlgoMergeTinyWithBig()
Default constructor.
Class def header for a class CBAlgoMergeTinyWithBig.
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)