LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CBAlgoAngleSeparate.cxx
Go to the documentation of this file.
2 
3 #include <cmath>
4 
5 namespace cmtool {
6 
7  //----------------------------------------
9  //----------------------------------------
10  {
11 
12  SetDebug(false);
13  SetMaxAngleSep(20.);
14  SetMinLength(15.);
15  SetMinHits(20);
16  }
17 
18  //--------------------------------------------------------
19  bool CBAlgoAngleSeparate::Bool(const ::cluster::ClusterParamsAlg& cluster1,
20  const ::cluster::ClusterParamsAlg& cluster2)
21  //--------------------------------------------------------
22  {
23 
24  double angle1 = cluster1.GetParams().angle_2d;
25  double angle2 = cluster2.GetParams().angle_2d;
26 
27  double w_start1 = cluster1.GetParams().start_point.w;
28  double t_start1 = cluster1.GetParams().start_point.t;
29  double w_start2 = cluster2.GetParams().start_point.w;
30  double t_start2 = cluster2.GetParams().start_point.t;
31 
32  double len1 = cluster1.GetParams().length;
33  double len2 = cluster2.GetParams().length;
34 
35  size_t hits1 = cluster1.GetHitVector().size();
36  size_t hits2 = cluster1.GetHitVector().size();
37 
38  //if either cluster has less than _minHits don't even try...
39  if ((hits1 < _minHits) or (hits2 < _minHits) or (angle1 < -360) or (angle2 < -360))
40  return false;
41 
42  if (_debug) {
43  std::cout << "Cluster 1:" << std::endl;
44  std::cout << "\tStart: ( " << w_start1 << ", " << t_start1 << " )" << std::endl;
45  std::cout << "\tAngle: " << angle1 << std::endl;
46  std::cout << "\tLength: " << len1 << std::endl;
47  std::cout << "\tN Hits: " << hits1 << std::endl;
48 
49  std::cout << "Cluster 2:" << std::endl;
50  std::cout << "\tStart: ( " << w_start2 << ", " << t_start2 << " )" << std::endl;
51  std::cout << "\tAngle: " << angle2 << std::endl;
52  std::cout << "\tLength: " << len2 << std::endl;
53  std::cout << "\tN Hits: " << hits2 << std::endl;
54  }
55 
56  //cluster 1 needs to be long enough (i.e. good) and cluster 2 must have minimum number of hits
57  double angle;
58  double separation;
59 
60  //first calculate angle of line in 2D plane connectng the two start points
61  if ((t_start2 - t_start1) == 0)
62  angle = 0.;
63  else {
64  double slope = (t_start2 - t_start1) / (w_start2 - w_start1);
65  angle = atan(slope) * 180. / 3.14;
66  }
67 
68  separation = abs(angle - angle1);
69  if (_debug) {
70  std::cout << "Angle S1--S2: " << angle << std::endl;
71  std::cout << "Angle1--S2: " << separation << std::endl;
72  }
73  if ((((separation > _MaxAngle) and (separation < 180 - _MaxAngle)) or
74  ((separation > 180 + _MaxAngle) and (separation < 360 - _MaxAngle))) and
75  (hits2 > _minHits) and (len1 > _MinLen)) {
76  if (_verbose) { std::cout << "Separate! cluster 1 BIG" << std::endl << std::endl; }
77  return true;
78  }
79 
80  //now change direction of angle so that it points from cluster 2 (big) to cluster 1 (small)
81  angle += 180.;
82  angle = (int)(angle) % 360;
83  separation = abs(angle - angle2);
84  if (_debug) {
85  std::cout << "Angle S2--S1: " << angle << std::endl;
86  std::cout << "Angle2--S1: " << separation << std::endl;
87  }
88  if ((((separation > _MaxAngle) and (separation < 180 - _MaxAngle)) or
89  ((separation > 180 + _MaxAngle) and (separation < 360 - _MaxAngle))) and
90  (hits1 > _minHits) and (len2 > _MinLen)) {
91  if (_verbose) { std::cout << "Separate! cluster 2 BIG" << std::endl << std::endl; }
92  return true;
93  }
94 
95  if (_debug) { std::cout << std::endl; }
96  return false;
97  }
98 
99  //-----------------------
101  //-----------------------
102  {}
103 
104 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
virtual void Report()
Function to report what&#39;s going on per merging.
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
CBAlgoAngleSeparate()
Default constructor.
void SetMaxAngleSep(float angle)
Set Max Angle Separation for separation.
void SetMinLength(float len)
Set Minimum length for "big" cluster.
void SetDebug(bool on)
Set Debug Mode on or off.
void SetMinHits(size_t n)
SetMinimum number of hits for small cluster.
bool _verbose
Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager&#39;s verbosity level is >= kPer...
Definition: CMAlgoBase.h:82