LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
CBAlgoMergeTinyWithBig.cxx
Go to the documentation of this file.
1 #ifndef RECOTOOL_CBALGOMERGETINYWITHBIG_CXX
2 #define RECOTOOL_CBALGOMERGETINYWITHBIG_CXX
3 
5 
6 namespace cmtool {
7 
8  //-------------------------------------------------------
10  //-------------------------------------------------------
11  {
12  SetMinHitsBig(50);
13  SetMaxHitsBig(99999);
14  SetMinHitsSmall(0);
15  SetMaxHitsSmall(15);
17 
18  SetDebug(false);
19  }
20 
21  //-----------------------------
23  //-----------------------------
24  {
25 
26  }
27 
28  //----------------------------------------------------------------
29  bool CBAlgoMergeTinyWithBig::Bool(const ::cluster::ClusterParamsAlg &cluster1,
30  const ::cluster::ClusterParamsAlg &cluster2)
31  //----------------------------------------------------------------
32  {
33 
34  if(_debug)
35  std::cout<<"MergeTinyWithBig. One cluster has "
36  <<cluster1.GetNHits()<<" hits, the other has "
37  <<cluster2.GetNHits()<<" hits."<<std::endl;
38 
39 
40  bool is_1_small = false;
41  bool is_2_small = false;
42  bool is_1_big = false;
43  bool is_2_big = false;
44 
45  //if the first cluster counts as "small"
46  if(cluster1.GetNHits() > _min_hits_small &&
47  cluster1.GetNHits() < _max_hits_small)
48  is_1_small = true;
49  //if the second cluster counts as "small"
50  if(cluster2.GetNHits() > _min_hits_small &&
51  cluster2.GetNHits() < _max_hits_small)
52  is_2_small = true;
53  if(cluster1.GetNHits() > _min_hits_big &&
54  cluster1.GetNHits() < _max_hits_big)
55  is_1_big = true;
56  if(cluster2.GetNHits() > _min_hits_big &&
57  cluster2.GetNHits() < _max_hits_big)
58  is_2_big = true;
59 
60  if(_debug)
61  std::cout<<"is_1_small, is_1_big, is_2_small, is_2_big are: "
62  <<is_1_small<<", "<<is_1_big<<", "
63  <<is_2_small<<", "<<is_2_big<<std::endl;
64 
65  //if neither of the clusters is small don't merge
66  if(!is_1_small && !is_2_small)
67  return false;
68  //if neither of the clusters is big, don't merge
69  if(!is_1_big && !is_2_big)
70  return false;
71  //if both are small, don't merge
72  if(is_1_small && is_2_small)
73  return false;
74  //if both are big, don't merge
75  if(is_1_big && is_2_big)
76  return false;
77 
78  if(_debug)
79  std::cout<<"Looks like one of them is big, and one is small."<<std::endl;
80  //god this code is ugly
81 
82  //now we know which one of them is big & the other is small.
83 
84  //loop over the points on the first polygon and calculate
85  //distance to each point on the second polygon
86  //if any two points are close enough to each other,
87  //merge the two clusters
88 
89  unsigned int npoints1 = cluster1.GetParams().PolyObject.Size();
90  unsigned int npoints2 = cluster2.GetParams().PolyObject.Size();
91  //loop over points on first polygon
92  for(unsigned int i = 0; i < npoints1; ++i){
93  float pt1w = cluster1.GetParams().PolyObject.Point(i).first;
94  float pt1t = cluster1.GetParams().PolyObject.Point(i).second;
95  //loop over points on second polygon
96  for(unsigned int j = 0; j < npoints2; ++j){
97  float pt2w = cluster2.GetParams().PolyObject.Point(j).first;
98  float pt2t = cluster2.GetParams().PolyObject.Point(j).second;
99  double distsqrd = pow(pt2w-pt1w,2)+pow(pt2t-pt1t,2);
100 
101  if(_debug){
102  std::cout<<"two polygon points dist2 is "<<distsqrd<<std::endl;
103  }
104  if(distsqrd<_dist_sqrd_cut)
105  return true;
106  }
107 
108  }
109 
110  return false;
111 
112  }
113 
114  //------------------------------
116  //------------------------------
117  {
118 
119  }
120 
121 }
122 #endif
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)