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

#include <CBAlgoShortestDistSmallCluster.h>

Inheritance diagram for cmtool::CBAlgoShortestDistSmallCluster:
cmtool::CBoolAlgoBase cmtool::CMAlgoBase

Public Member Functions

 CBAlgoShortestDistSmallCluster ()
 Default constructor. More...
 
virtual ~CBAlgoShortestDistSmallCluster ()
 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 SetDebug (bool on)
 Method to set debug mode. More...
 
void SetMinHits (size_t n)
 Set Minimum Number of Hits to consider Cluster. More...
 
void SetMaxHits (size_t n)
 Set Maximum 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...
 
virtual void SetVerbose (bool doit=true)
 Setter function for verbosity. More...
 

Protected Attributes

bool _debug
 
size_t _minHits
 bool to suppress lots of output if you want More...
 
size_t _maxHits
 Min Number of hits for cluster to be considered. More...
 
double _wire_2_cm
 Max Number of hits for cluster to be considered. More...
 
double _time_2_cm
 
double _min_distance_unit
 Conversion factors ogtten from GeometryUtilities. 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 CBAlgoShortestDistSmallCluster ... these comments are used to generate doxygen documentation!

Definition at line 26 of file CBAlgoShortestDistSmallCluster.h.

Constructor & Destructor Documentation

cmtool::CBAlgoShortestDistSmallCluster::CBAlgoShortestDistSmallCluster ( )

Default constructor.

Definition at line 9 of file CBAlgoShortestDistSmallCluster.cxx.

9  {
10 
11  //this just sets default values
12  SetDebug(false);
13  SetMinHits(0);
14 
15  //1e9 is huge; everything will be merged
17 
18  if(_verbose or _debug)
19  std::cout << "wire2cm: " << _wire_2_cm << " time2cm: " << _time_2_cm << std::endl;
20 
22  _wire_2_cm = geou.WireToCm();
23  _time_2_cm = geou.TimeToCm();
24 
25  //shortest allowable length of a cluster (distance start->end point)
26  //this is used in cases where the start/end points basically overlap
28 
29  } //end constructor
Double_t TimeToCm() const
Double_t WireToCm() const
double _wire_2_cm
Max Number of hits for cluster to be considered.
void SetSquaredDistanceCut(double d)
Method to set cut value in cm^2 for distance compatibility test.
double _min_distance_unit
Conversion factors ogtten from GeometryUtilities.
void SetMinHits(size_t n)
Set Minimum Number of Hits to consider Cluster.
void SetDebug(bool on)
Method to set debug mode.
bool _verbose
Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager&#39;s verbosity level is >= kPer...
Definition: CMAlgoBase.h:89
QTextStream & endl(QTextStream &s)
virtual cmtool::CBAlgoShortestDistSmallCluster::~CBAlgoShortestDistSmallCluster ( )
inlinevirtual

Default destructor.

Definition at line 34 of file CBAlgoShortestDistSmallCluster.h.

34 {};

Member Function Documentation

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

Overloaded (from CBoolAlgoBase) Bool function.

Reimplemented from cmtool::CBoolAlgoBase.

Definition at line 31 of file CBAlgoShortestDistSmallCluster.cxx.

33  {
34 
35  //if number of hits not large enough skip
36  if ( (_minHits > 0) and ((cluster1.GetNHits() < _minHits) or (cluster2.GetNHits() < _minHits)) ) {
37  return false;
38  }
39 
40  //if number of hits is too large
41  if ( (_maxHits > _minHits) and ((cluster1.GetNHits() > _maxHits) or (cluster2.GetNHits() > _maxHits)) ) {
42  return false;
43  }
44 
45 
46  double w_start1 = cluster1.GetParams().start_point.w;// * _wire_2_cm;
47  double t_start1 = cluster1.GetParams().start_point.t;// * _time_2_cm;
48  double w_end1 = cluster1.GetParams().end_point.w;// * _wire_2_cm;
49  double t_end1 = cluster1.GetParams().end_point.t;// * _time_2_cm;
50 
51  double w_start2 = cluster2.GetParams().start_point.w;// * _wire_2_cm;
52  double t_start2 = cluster2.GetParams().start_point.t;// * _time_2_cm;
53  double w_end2 = cluster2.GetParams().end_point.w;// * _wire_2_cm;
54  double t_end2 = cluster2.GetParams().end_point.t;// * _time_2_cm;
55 
56  if (_debug){
57  std::cout << "Start point Cluster 1: (" << cluster1.GetParams().start_point.w << ", " << cluster1.GetParams().start_point.t << ")" << std::endl;
58  std::cout << "End point Cluster 2: (" << cluster1.GetParams().end_point.w << ", " << cluster1.GetParams().end_point.t << ")" << std::endl;
59  std::cout << "Start point Cluster 1: (" << cluster2.GetParams().start_point.w << ", " << cluster2.GetParams().start_point.t << ")" << std::endl;
60  std::cout << "End point Cluster 2: (" << cluster2.GetParams().end_point.w << ", " << cluster2.GetParams().end_point.t << ")" << std::endl;
61  }
62 
63  //First, pretend the first cluster is a 2D line segment, from its start point to end point
64  //Find the shortest distance between start point of the second cluster to this line segment.
65  //Repeat for end point of second cluster to this line segment.
66  //Then, pretend second cluster is a 2D line segment, from its start point to end point.
67  //Find the shortest distance between start point of the first cluster to this line segment.
68  //Repeat for end point of first cluster to this line segment.
69  //If the shortest of these four distances is less than the cutoff,
70  //return true (the clusters are merge-compatible). else, return false.
71 
72  // Step 1: inspect (w_start1, t_start1) vs. line (w_start2, t_start2) => (w_end2, t_end2)
73  double shortest_distance2 = ShortestDistanceSquared(w_start1, t_start1,
74  w_start2, t_start2,
75  w_end2, t_end2);
76 
77  // Step 2: inspect (w_end1, t_end1) vs. line (w_start2, t_start2) => (w_end2, t_end2)
78  double shortest_distance2_tmp = ShortestDistanceSquared(w_end1, t_end1,
79  w_start2, t_start2,
80  w_end2, t_end2);
81 
82  shortest_distance2 = (shortest_distance2_tmp < shortest_distance2) ?
83  shortest_distance2_tmp : shortest_distance2;
84 
85  // Step 3: inspect (w_start2, t_start2) vs. line (w_start1, t_start1) => (w_end1, t_end1)
86  shortest_distance2_tmp = ShortestDistanceSquared(w_start2, t_start2,
87  w_start1, t_start1,
88  w_end1, t_end1);
89 
90  shortest_distance2 = (shortest_distance2_tmp < shortest_distance2) ?
91  shortest_distance2_tmp : shortest_distance2;
92 
93  // Step 4: inspect (w_end2, t_end2) vs. line (w_start1, t_start1) => (w_end1, t_end1)
94  shortest_distance2_tmp = ShortestDistanceSquared(w_end2, t_end2,
95  w_start1, t_start1,
96  w_end1, t_end1);
97 
98  shortest_distance2 = (shortest_distance2_tmp < shortest_distance2) ?
99  shortest_distance2_tmp : shortest_distance2;
100 
101  bool compatible = shortest_distance2 < _max_2D_dist2;
102 
103  if(_verbose or _debug) {
104 
105  if(compatible) std::cout<<Form(" Compatible in distance (%g).\n",shortest_distance2);
106  else std::cout<<Form(" NOT compatible in distance (%g).\n",shortest_distance2);
107 
108  }
109 
110  return compatible;
111 
112 
113  }//end Bool function
size_t _minHits
bool to suppress lots of output if you want
size_t _maxHits
Min Number of hits for cluster to be considered.
double _max_2D_dist2
minimum distance b/t start and end point of cluster to use it
double ShortestDistanceSquared(double point_x, double point_y, double start_x, double start_y, double end_x, double end_y) const
bool _verbose
Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager&#39;s verbosity level is >= kPer...
Definition: CMAlgoBase.h:89
QTextStream & endl(QTextStream &s)
void cmtool::CBAlgoShortestDistSmallCluster::SetDebug ( bool  on)
inline

Method to set debug mode.

Definition at line 45 of file CBAlgoShortestDistSmallCluster.h.

void cmtool::CBAlgoShortestDistSmallCluster::SetMaxHits ( size_t  n)
inline

Set Maximum Number of Hits to consider Cluster.

Definition at line 51 of file CBAlgoShortestDistSmallCluster.h.

51 { _maxHits = n; }
std::void_t< T > n
size_t _maxHits
Min Number of hits for cluster to be considered.
void cmtool::CBAlgoShortestDistSmallCluster::SetMinHits ( size_t  n)
inline

Set Minimum Number of Hits to consider Cluster.

Definition at line 48 of file CBAlgoShortestDistSmallCluster.h.

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

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

Definition at line 42 of file CBAlgoShortestDistSmallCluster.h.

42 { _max_2D_dist2 = d; }
double _max_2D_dist2
minimum distance b/t start and end point of cluster to use it
double cmtool::CBAlgoShortestDistSmallCluster::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 115 of file CBAlgoShortestDistSmallCluster.cxx.

117  {
118 
119  //This code finds the shortest distance between a point and a line segment.
120  //code based off sample from
121  //http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
122  //note to self: rewrite this with TVector2 and compare time differences...
123  //TVector2 code might be more understandable
124 
125  double distance_squared = -1;
126 
127  // Line segment: from ("V") = (start_x, start_y) to ("W")=(end_x, end_y)
128  double length_squared = pow((end_x - start_x), 2) + pow((end_y - start_y), 2);
129 
130  // Treat the case start & end point overlaps
131  if( (_verbose or _debug) and length_squared < _min_distance_unit) {
132 
133  std::cout << std::endl;
134  std::cout << Form(" Provided very short line segment: (%g,%g) => (%g,%g)",
135  start_x,start_y,end_x,end_y) << std::endl;
136  std::cout << " Likely this means one of two clusters have start & end point identical." << std::endl;
137  std::cout << " Check the cluster output!" << std::endl;
138  std::cout << std::endl;
139  std::cout << Form(" At this time, the algorithm uses a point (%g,%g)",start_x,start_y) << std::endl;
140  std::cout << " to represent this cluster's location." << std::endl;
141  std::cout << std::endl;
142 
143  return (pow((point_x - start_x),2) + pow((point_y - start_y),2));
144  }
145 
146  //Find shortest distance between point ("P")=(point_x,point_y) to this line segment
147  double t = ( (point_x - start_x)*(end_x - start_x) + (point_y - start_y)*(end_y - start_y) ) / length_squared;
148 
149  if(t<0.0) distance_squared = pow((point_x - start_x), 2) + pow((point_y - start_y), 2);
150 
151  else if (t>1.0) distance_squared = pow((point_x - end_x), 2) + pow(point_y - end_y, 2);
152 
153  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);
154 
155  return distance_squared;
156 
157  }//end ShortestDistanceSquared function
constexpr T pow(T x)
Definition: pow.h:72
double _min_distance_unit
Conversion factors ogtten from GeometryUtilities.
bool _verbose
Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager&#39;s verbosity level is >= kPer...
Definition: CMAlgoBase.h:89
QTextStream & endl(QTextStream &s)

Member Data Documentation

bool cmtool::CBAlgoShortestDistSmallCluster::_debug
protected

Definition at line 65 of file CBAlgoShortestDistSmallCluster.h.

double cmtool::CBAlgoShortestDistSmallCluster::_max_2D_dist2
protected

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

Definition at line 75 of file CBAlgoShortestDistSmallCluster.h.

size_t cmtool::CBAlgoShortestDistSmallCluster::_maxHits
protected

Min Number of hits for cluster to be considered.

Definition at line 69 of file CBAlgoShortestDistSmallCluster.h.

double cmtool::CBAlgoShortestDistSmallCluster::_min_distance_unit
protected

Conversion factors ogtten from GeometryUtilities.

Definition at line 73 of file CBAlgoShortestDistSmallCluster.h.

size_t cmtool::CBAlgoShortestDistSmallCluster::_minHits
protected

bool to suppress lots of output if you want

Definition at line 67 of file CBAlgoShortestDistSmallCluster.h.

double cmtool::CBAlgoShortestDistSmallCluster::_time_2_cm
protected

Definition at line 71 of file CBAlgoShortestDistSmallCluster.h.

double cmtool::CBAlgoShortestDistSmallCluster::_wire_2_cm
protected

Max Number of hits for cluster to be considered.

Definition at line 71 of file CBAlgoShortestDistSmallCluster.h.


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