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