CBAlgoOutOfConeSeparate.cxx
Go to the documentation of this file.
2 
3 #include <math.h>
4 
5 namespace cmtool {
6 
7  //----------------------------------------
9  //----------------------------------------
10  {
11 
12  SetDebug(false);
13  SetMaxAngleSep(20.);
14  SetMinLength(15.);
15  SetMinHits(20);
16  SetStartAngleFalloff(2800); // in cm^2
17 
18  }
19 
20  //--------------------------------------------------------
21  bool CBAlgoOutOfConeSeparate::Bool(const ::cluster::ClusterParamsAlg &cluster1,
22  const ::cluster::ClusterParamsAlg &cluster2)
23  //--------------------------------------------------------
24  {
25 
26  double angle1 = cluster1.GetParams().angle_2d;
27  double angle2 = cluster2.GetParams().angle_2d;
28 
29  double w_start1 = cluster1.GetParams().start_point.w;
30  double t_start1 = cluster1.GetParams().start_point.t;
31  double w_start2 = cluster2.GetParams().start_point.w;
32  double t_start2 = cluster2.GetParams().start_point.t;
33 
34  double len1 = cluster1.GetParams().length;
35  double len2 = cluster2.GetParams().length;
36 
37  size_t hits1 = cluster1.GetHitVector().size();
38  size_t hits2 = cluster2.GetHitVector().size();
39 
40  double startseparation = (w_start2-w_start1)*(w_start2-w_start1) + (t_start2-t_start1)*(t_start2-t_start1);
41  //convert sepration to be instead of just angle -> angle/distance^n (n=1 for now)
42  SetMaxAngleFar(_MaxAngle*(_FallOff/startseparation)); //distance^2 of 400 cm^2 taken as "standard"
43  if ( _MaxAngleFar > 90. )
44  _MaxAngleFar = 90.;
45 
46  //if either cluster has less than _minHits don't even try...
47  if ( (hits1 < _minHits) or (hits2 < _minHits)
48  or (angle1 < -360) or (angle2 < -360) )
49  return false;
50 
51  if (_debug){
52  std::cout << "Cluster 1:" << std::endl;
53  std::cout << "\tStart: ( " << w_start1 << ", " << t_start1 << " )" << std::endl;
54  std::cout << "\tAngle: " << angle1 << std::endl;
55  std::cout << "\tLength: " << len1 << std::endl;
56  std::cout << "\tN Hits: " << hits1 << std::endl;
57 
58  std::cout << "Cluster 2:" << std::endl;
59  std::cout << "\tStart: ( " << w_start2 << ", " << t_start2 << " )" << std::endl;
60  std::cout << "\tAngle: " << angle2 << std::endl;
61  std::cout << "\tLength: " << len2 << std::endl;
62  std::cout << "\tN Hits: " << hits2 << std::endl;
63 
64  std::cout << "Start Point Separation: " << startseparation << std::endl;
65  }
66 
67  //cluster 1 needs to be long enough (i.e. good) and cluster 2 must have minimum number of hits
68  double angle;
69  double separation;
70 
71  if ( startseparation == 0 ) //do not prohibit merging if start point identical
72  return false;
73 
74  //first calculate angle of line in 2D plane connectng the two start points
75  if ( (t_start2-t_start1) == 0 )
76  angle = 0.;
77  else {
78  double slope = (t_start2-t_start1)/(w_start2-w_start1);
79  angle = atan(slope)*180./3.14;
80  }
81 
82  separation = abs(angle-angle1);
83 
84  if (_debug){
85  std::cout << "Angle S1--S2: " << angle << std::endl;
86  std::cout << "Angle1--S2: " << separation << std::endl;
87  }
88  if ( ( ( ( (separation > _MaxAngle) and (separation < 180-_MaxAngle) ) or
89  ( (separation > 180+_MaxAngle) and (separation< 360-_MaxAngle) ) )
90  or ( ( (separation > _MaxAngleFar) and (separation < 180-_MaxAngleFar) ) or
91  ( (separation > 180+_MaxAngleFar) and (separation< 360-_MaxAngleFar) ) ) )
92  and (hits2 > _minHits)
93  and (len1 > _MinLen) ){
94  if (_verbose) { std::cout << "Separate! cluster 1 BIG" << std::endl << std::endl; }
95  return true;
96  }
97 
98  //now change direction of angle so that it points from cluster 2 (big) to cluster 1 (small)
99  angle += 180.;
100  angle = (int)(angle) % 360;
101 
102  separation = abs(angle-angle2);
103  //separation *= (400./startseparation); //distance^2 of 400 cm^2 taken as "standard"
104  if (_debug){
105  std::cout << "Angle S2--S1: " << angle << std::endl;
106  std::cout << "Angle2--S1: " << separation << std::endl;
107  }
108  if ( ( ( ( (separation > _MaxAngle) and (separation < 180-_MaxAngle) ) or
109  ( (separation > 180+_MaxAngle) and (separation< 360-_MaxAngle) ) )
110  or ( ( (separation > _MaxAngleFar) and (separation < 180-_MaxAngleFar) ) or
111  ( (separation > 180+_MaxAngleFar) and (separation< 360-_MaxAngleFar) ) ) )
112  and (hits1 > _minHits)
113  and (len2 > _MinLen) ){
114  if (_verbose) { std::cout << "Separate! cluster 2 BIG" << std::endl << std::endl; }
115  return true;
116  }
117 
118  return false;
119  }
120 
121 }
void SetMinLength(float len)
Set Minimum length for "big" cluster.
void SetStartAngleFalloff(float d)
Set Distance at which cone-acceptance angle starts falling off as 1/distance. Value should be distanc...
void SetDebug(bool on)
Set Debug Mode on or off.
void SetMaxAngleSep(float angle)
Set Max Angle Separation for separation.
T abs(T value)
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
void SetMinHits(size_t n)
SetMinimum number of hits for small cluster.
void SetMaxAngleFar(float angle)
Set Max Angle Separation for separation for far away clusters.
bool _verbose
Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager&#39;s verbosity level is >= kPer...
Definition: CMAlgoBase.h:102
QTextStream & endl(QTextStream &s)
CBAlgoOutOfConeSeparate()
Default constructor.