Public Member Functions | Protected Attributes | List of all members
cmtool::CBAlgoShortestDistNonEndpoint Class Reference

#include <CBAlgoShortestDistNonEndPoint.h>

Inheritance diagram for cmtool::CBAlgoShortestDistNonEndpoint:
cmtool::CBoolAlgoBase cmtool::CMAlgoBase

Public Member Functions

 CBAlgoShortestDistNonEndpoint ()
 Default constructor. More...
 
virtual ~CBAlgoShortestDistNonEndpoint ()
 Default destructor. More...
 
virtual bool Bool (const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
 Overloaded (from CBoolAlgoBase) Bool function. More...
 
void SetSquaredDistanceCut (double d)
 Method to set cut value in cm^2 for distance compatibility test. More...
 
void SetVerbose (bool on)
 Method to set verbose mode. More...
 
void SetDebug (bool on)
 Method to set debug mode. More...
 
void SetMinHits (int n)
 Set Minimum Number of Hits to consider Cluster. More...
 
double ShortestDistanceSquared (double point_x, double point_y, double start_x, double start_y, double end_x, double end_y) const
 
- Public Member Functions inherited from cmtool::CBoolAlgoBase
 CBoolAlgoBase ()
 Default constructor. More...
 
virtual ~CBoolAlgoBase ()
 Default destructor. More...
 
- Public Member Functions inherited from cmtool::CMAlgoBase
 CMAlgoBase ()
 Default constructor. More...
 
virtual ~CMAlgoBase ()
 Default destructor. More...
 
virtual void Reset ()
 Function to reset the algorithm instance called within CMergeManager/CMatchManager's Reset() ... maybe implemented via child class. More...
 
virtual void EventBegin (const std::vector< cluster::ClusterParamsAlg > &clusters)
 
virtual void EventEnd ()
 
virtual void IterationBegin (const std::vector< cluster::ClusterParamsAlg > &clusters)
 
virtual void IterationEnd ()
 
virtual void Report ()
 
void SetAnaFile (TFile *fout)
 Setter function for an output plot TFile pointer. More...
 

Protected Attributes

bool _verbose
 
bool _debug
 bool to suppress lots of output if you want More...
 
size_t _minHits
 bool to suppress lots of output if you want More...
 
double _min_distance_unit
 Min Number of hits for cluster to be considered. More...
 
double _max_2D_dist2
 minimum distance b/t start and end point of cluster to use it More...
 
- Protected Attributes inherited from cmtool::CMAlgoBase
TFile * _fout
 TFile pointer to an output file. More...
 
bool _verbose
 Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager's verbosity level is >= kPerMerging. More...
 

Detailed Description

User defined class CBAlgoShortestDistNonEndpoint ... these comments are used to generate doxygen documentation!

Definition at line 26 of file CBAlgoShortestDistNonEndPoint.h.

Constructor & Destructor Documentation

cmtool::CBAlgoShortestDistNonEndpoint::CBAlgoShortestDistNonEndpoint ( )

Default constructor.

Definition at line 8 of file CBAlgoShortestDistNonEndPoint.cxx.

8  {
9 
10  //this just sets default values
11  SetVerbose(true);
12  SetDebug(false);
13  SetMinHits(0);
14 
15  //1e9 is huge; everything will be merged
17 
18  _min_distance_unit = 1.e-3;
19  } //end constructor
void SetMinHits(int n)
Set Minimum Number of Hits to consider Cluster.
void SetVerbose(bool on)
Method to set verbose mode.
double _min_distance_unit
Min Number of hits for cluster to be considered.
void SetSquaredDistanceCut(double d)
Method to set cut value in cm^2 for distance compatibility test.
void SetDebug(bool on)
Method to set debug mode.
virtual cmtool::CBAlgoShortestDistNonEndpoint::~CBAlgoShortestDistNonEndpoint ( )
inlinevirtual

Default destructor.

Definition at line 34 of file CBAlgoShortestDistNonEndPoint.h.

34 {};

Member Function Documentation

bool cmtool::CBAlgoShortestDistNonEndpoint::Bool ( const ::cluster::ClusterParamsAlg cluster1,
const ::cluster::ClusterParamsAlg cluster2 
)
virtual

Overloaded (from CBoolAlgoBase) Bool function.

Reimplemented from cmtool::CBoolAlgoBase.

Definition at line 21 of file CBAlgoShortestDistNonEndPoint.cxx.

23  {
24 
25  //if number of hits not large enough skip
26  if ( (_minHits > 0) and ((cluster1.GetParams().N_Hits < _minHits) or (cluster2.GetParams().N_Hits < _minHits)) ) {
27  if (_debug) { std::cout << "Num of Hits below threshold..." << std::endl; }
28  return false;
29  }
30 
31  double w_start1 = cluster1.GetParams().start_point.w;
32  double t_start1 = cluster1.GetParams().start_point.t;
33  double w_end1 = cluster1.GetParams().end_point.w;
34  double t_end1 = cluster1.GetParams().end_point.t;
35 
36  double w_start2 = cluster2.GetParams().start_point.w;
37  double t_start2 = cluster2.GetParams().start_point.t;
38  double w_end2 = cluster2.GetParams().end_point.w;
39  double t_end2 = cluster2.GetParams().end_point.t;
40 
41  if (_debug){
42  std::cout << "Start point Cluster 1: (" << w_start1 << ", " << t_start1 << ")" << std::endl;
43  std::cout << "End point Cluster 2: (" << w_end1 << ", " << t_end1 << ")" << std::endl;
44  std::cout << "Start point Cluster 1: (" << w_start2 << ", " << t_start2 << ")" << std::endl;
45  std::cout << "End point Cluster 2: (" << w_end2 << ", " << t_end2 << ")" << std::endl;
46  }
47 
48  //First, pretend the first cluster is a 2D line segment, from its start point to end point
49  //Find the shortest distance between start point of the second cluster to this line segment.
50  //Repeat for end point of second cluster to this line segment.
51  //Then, pretend second cluster is a 2D line segment, from its start point to end point.
52  //Find the shortest distance between start point of the first cluster to this line segment.
53  //Repeat for end point of first cluster to this line segment.
54  //If the shortest of these four distances is less than the cutoff,
55  //return true (the clusters are merge-compatible). else, return false.
56 
57  // Step 1: inspect (w_start1, t_start1) vs. line (w_start2, t_start2) => (w_end2, t_end2)
58  double shortest_distance2 = ShortestDistanceSquared(w_start1, t_start1,
59  w_start2, t_start2,
60  w_end2, t_end2);
61 
62  // Step 2: inspect (w_end1, t_end1) vs. line (w_start2, t_start2) => (w_end2, t_end2)
63  double shortest_distance2_tmp = ShortestDistanceSquared(w_end1, t_end1,
64  w_start2, t_start2,
65  w_end2, t_end2);
66 
67  shortest_distance2 = (shortest_distance2_tmp < shortest_distance2) ?
68  shortest_distance2_tmp : shortest_distance2;
69 
70  // Step 3: inspect (w_start2, t_start2) vs. line (w_start1, t_start1) => (w_end1, t_end1)
71  shortest_distance2_tmp = ShortestDistanceSquared(w_start2, t_start2,
72  w_start1, t_start1,
73  w_end1, t_end1);
74 
75  shortest_distance2 = (shortest_distance2_tmp < shortest_distance2) ?
76  shortest_distance2_tmp : shortest_distance2;
77 
78  // Step 4: inspect (w_end2, t_end2) vs. line (w_start1, t_start1) => (w_end1, t_end1)
79  shortest_distance2_tmp = ShortestDistanceSquared(w_end2, t_end2,
80  w_start1, t_start1,
81  w_end1, t_end1);
82 
83  shortest_distance2 = (shortest_distance2_tmp < shortest_distance2) ?
84  shortest_distance2_tmp : shortest_distance2;
85 
86  bool compatible = shortest_distance2 < _max_2D_dist2;
87 
88  if(_verbose) {
89 
90  if(compatible) std::cout<<Form(" Compatible in distance (%g).\n",shortest_distance2);
91  else std::cout<<Form(" NOT compatible in distance (%g).\n",shortest_distance2);
92 
93  }
94 
95  return compatible;
96 
97 
98  }//end Bool function
double ShortestDistanceSquared(double point_x, double point_y, double start_x, double start_y, double end_x, double end_y) const
size_t _minHits
bool to suppress lots of output if you want
double _max_2D_dist2
minimum distance b/t start and end point of cluster to use it
bool _debug
bool to suppress lots of output if you want
QTextStream & endl(QTextStream &s)
void cmtool::CBAlgoShortestDistNonEndpoint::SetDebug ( bool  on)
inline

Method to set debug mode.

Definition at line 48 of file CBAlgoShortestDistNonEndPoint.h.

48 { _debug = on; }
bool _debug
bool to suppress lots of output if you want
void cmtool::CBAlgoShortestDistNonEndpoint::SetMinHits ( int  n)
inline

Set Minimum Number of Hits to consider Cluster.

Definition at line 51 of file CBAlgoShortestDistNonEndPoint.h.

51 { _minHits = n; }
size_t _minHits
bool to suppress lots of output if you want
std::void_t< T > n
void cmtool::CBAlgoShortestDistNonEndpoint::SetSquaredDistanceCut ( double  d)
inline

Method to set cut value in cm^2 for distance compatibility test.

Definition at line 42 of file CBAlgoShortestDistNonEndPoint.h.

42 { _max_2D_dist2 = d; }
double _max_2D_dist2
minimum distance b/t start and end point of cluster to use it
void cmtool::CBAlgoShortestDistNonEndpoint::SetVerbose ( bool  on)
inlinevirtual

Method to set verbose mode.

Reimplemented from cmtool::CMAlgoBase.

Definition at line 45 of file CBAlgoShortestDistNonEndPoint.h.

double cmtool::CBAlgoShortestDistNonEndpoint::ShortestDistanceSquared ( double  point_x,
double  point_y,
double  start_x,
double  start_y,
double  end_x,
double  end_y 
) const

Function to compute a distance between a 2D point (point_x, point_y) to a 2D finite line segment (start_x, start_y) => (end_x, end_y).

Definition at line 100 of file CBAlgoShortestDistNonEndPoint.cxx.

102  {
103 
104  //This code finds the shortest distance between a point and a line segment.
105  //code based off sample from
106  //http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
107  //note to self: rewrite this with TVector2 and compare time differences...
108  //TVector2 code might be more understandable
109 
110  double distance_squared = 999999;
111 
112  // Line segment: from ("V") = (start_x, start_y) to ("W")=(end_x, end_y)
113  double length_squared = pow((end_x - start_x), 2) + pow((end_y - start_y), 2);
114 
115  // Treat the case start & end point overlaps
116  if(length_squared < _min_distance_unit) {
117  if(_verbose){
118  std::cout << std::endl;
119  std::cout << Form(" Provided very short line segment: (%g,%g) => (%g,%g)",
120  start_x,start_y,end_x,end_y) << std::endl;
121  std::cout << " Likely this means one of two clusters have start & end point identical." << std::endl;
122  std::cout << " Check the cluster output!" << std::endl;
123  std::cout << std::endl;
124  std::cout << Form(" At this time, the algorithm uses a point (%g,%g)",start_x,start_y) << std::endl;
125  std::cout << " to represent this cluster's location." << std::endl;
126  std::cout << std::endl;
127  }
128 
129  return (pow((point_x - start_x),2) + pow((point_y - start_y),2));
130  }
131 
132  //Find shortest distance between point ("P")=(point_x,point_y) to this line segment
133  double t = ( (point_x - start_x)*(end_x - start_x) + (point_y - start_y)*(end_y - start_y) ) / length_squared;
134 
135  //if(t<0.0) distance_squared = pow((point_x - start_x), 2) + pow((point_y - start_y), 2);
136 
137  //else if (t>1.0) distance_squared = pow((point_x - end_x), 2) + pow(point_y - end_y, 2);
138 
139  //else distance_squared = pow((point_x - (start_x + t*(end_x - start_x))), 2) + pow((point_y - (start_y + t*(end_y - start_y))),2);
140 
141 
142  if(t>0.1 && t < 0.9) distance_squared = pow((point_x - (start_x + t*(end_x - start_x))), 2) + pow((point_y - (start_y + t*(end_y - start_y))),2);
143 
144 
145  return distance_squared;
146 
147  }//end ShortestDistanceSquared function
constexpr T pow(T x)
Definition: pow.h:72
double _min_distance_unit
Min Number of hits for cluster to be considered.
QTextStream & endl(QTextStream &s)

Member Data Documentation

bool cmtool::CBAlgoShortestDistNonEndpoint::_debug
protected

bool to suppress lots of output if you want

Definition at line 67 of file CBAlgoShortestDistNonEndPoint.h.

double cmtool::CBAlgoShortestDistNonEndpoint::_max_2D_dist2
protected

minimum distance b/t start and end point of cluster to use it

Definition at line 73 of file CBAlgoShortestDistNonEndPoint.h.

double cmtool::CBAlgoShortestDistNonEndpoint::_min_distance_unit
protected

Min Number of hits for cluster to be considered.

Definition at line 71 of file CBAlgoShortestDistNonEndPoint.h.

size_t cmtool::CBAlgoShortestDistNonEndpoint::_minHits
protected

bool to suppress lots of output if you want

Definition at line 69 of file CBAlgoShortestDistNonEndPoint.h.

bool cmtool::CBAlgoShortestDistNonEndpoint::_verbose
protected

Definition at line 65 of file CBAlgoShortestDistNonEndPoint.h.


The documentation for this class was generated from the following files: