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

#include <CBAlgoCenterOfMass.h>

Inheritance diagram for cmtool::CBAlgoCenterOfMass:
cmtool::CBoolAlgoBase cmtool::CMAlgoBase

Public Member Functions

 CBAlgoCenterOfMass ()
 Default constructor. More...
 
virtual ~CBAlgoCenterOfMass ()
 Default destructor. More...
 
virtual bool Bool (const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
 
virtual void Reset ()
 Function to reset the algorithm instance ... maybe implemented via child class. More...
 
virtual void Report ()
 Function to report what's going on per merging iteration. More...
 
void SetDebug (bool on)
 Function to set Debug mode of output. More...
 
void SetMaxHitsSmallClus (size_t n)
 Function to set Max hits for small clsuters. More...
 
void SetMinHitsBigClus (size_t n)
 Function to se Min hits for big clusters. More...
 
void SetMaxDistance (double d)
 Function to set Max Distance for COM to be from start-end. More...
 
void UseCOMInPoly (bool on)
 Use COM in Poly algo to decide merging. More...
 
void UseCOMInCone (bool on)
 Use COM in Poly algo to decide merging. More...
 
void UseCOMNearClus (bool on)
 Use COM in Poly algo to decide merging. More...
 
void SetLengthReach (double frac)
 Set Length Reach: How for out the cone extends as percent of cluster length. 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 ()
 
virtual ~CMAlgoBase ()=default
 
virtual void EventBegin (const std::vector< cluster::ClusterParamsAlg > &)
 
virtual void EventEnd ()
 
virtual void IterationBegin (const std::vector< cluster::ClusterParamsAlg > &)
 
virtual void IterationEnd ()
 
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
 
size_t _maxHits
 
double _MaxDist
 
double _lengthReach
 
bool _COMinPolyAlg
 How four out - as percent of cluster length - cone will extend from start point. More...
 
bool _COMinConeAlg
 
bool _COMNearClus
 
- 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

Designed mainly for small clusters (< 10 hits): Find Cluster's center of mass weighing by Q Then see if COM is in polygon/cone of a big cluster If so -> merge

Definition at line 28 of file CBAlgoCenterOfMass.h.

Constructor & Destructor Documentation

cmtool::CBAlgoCenterOfMass::CBAlgoCenterOfMass ( )

Default constructor.

Definition at line 8 of file CBAlgoCenterOfMass.cxx.

8  : CBoolAlgoBase()
9  //----------------------------------------
10  {
11 
12  SetDebug(false);
15  SetMaxDistance(20.);
16  SetLengthReach(3.0);
17  UseCOMInPoly(true);
18  UseCOMInCone(true);
19  UseCOMNearClus(true);
20 
21  }
void SetLengthReach(double frac)
Set Length Reach: How for out the cone extends as percent of cluster length.
CBoolAlgoBase()
Default constructor.
Definition: CBoolAlgoBase.h:32
void SetMaxDistance(double d)
Function to set Max Distance for COM to be from start-end.
void UseCOMInCone(bool on)
Use COM in Poly algo to decide merging.
void UseCOMNearClus(bool on)
Use COM in Poly algo to decide merging.
void UseCOMInPoly(bool on)
Use COM in Poly algo to decide merging.
void SetDebug(bool on)
Function to set Debug mode of output.
void SetMaxHitsSmallClus(size_t n)
Function to set Max hits for small clsuters.
void SetMinHitsBigClus(size_t n)
Function to se Min hits for big clusters.
virtual cmtool::CBAlgoCenterOfMass::~CBAlgoCenterOfMass ( )
inlinevirtual

Default destructor.

Definition at line 36 of file CBAlgoCenterOfMass.h.

36 {};

Member Function Documentation

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

Core function: given the ClusterParamsAlg input, return whether a cluster should be merged or not.

Reimplemented from cmtool::CBoolAlgoBase.

Definition at line 24 of file CBAlgoCenterOfMass.cxx.

27  {
28 
29  int small = 0;
30  int hitssmall = 0;
31 
32  //determine if clusters ok and if so which is big and which is small
33  if ( (cluster1.GetHitVector().size() > _minHits) and (cluster2.GetHitVector().size() < _maxHits) )
34  small = 2;
35  else if ( (cluster2.GetHitVector().size() > _minHits) and (cluster1.GetHitVector().size() < _maxHits) )
36  small = 1;
37  else
38  return false;
39 
40  //Define COM values on w & t
41  double COM_t_s = 0;
42  double COM_w_s = 0;
43  double Q_s = 0;
44  //Define cone parameters
45  double opening_angle;
46  double direc_angle;
47  double length;
48  double start_w;
49  double start_t;
50  double end_w;
51  double end_t;
52  Polygon2D poly;
53 
54  //Get Hit vector for small cluster
55  //std::vector<util::PxHit> hitss;
56  std::vector<util::PxHit> hitss;
57  if ( small == 1 ){
58  hitss = cluster1.GetHitVector();
59  hitssmall = hitss.size();
60  direc_angle = cluster2.GetParams().angle_2d;
61  opening_angle = cluster2.GetParams().opening_angle * (180./3.14);
62  length = cluster2.GetParams().length;
63  start_w = cluster2.GetParams().start_point.w;
64  start_t = cluster2.GetParams().start_point.t;
65  end_w = cluster2.GetParams().end_point.w;
66  end_t = cluster2.GetParams().end_point.t;
67  poly = cluster2.GetParams().PolyObject;
68  }
69  if ( small == 2 ){
70  hitss = cluster2.GetHitVector();
71  hitssmall = hitss.size();
72  direc_angle = cluster1.GetParams().angle_2d;
73  opening_angle = cluster1.GetParams().opening_angle * (180./3.14);
74  length = cluster1.GetParams().length;
75  start_w = cluster1.GetParams().start_point.w;
76  start_t = cluster1.GetParams().start_point.t;
77  end_w = cluster1.GetParams().end_point.w;
78  end_t = cluster1.GetParams().end_point.t;
79  poly = cluster1.GetParams().PolyObject;
80  }
81 
82  if (_debug){
83  std::cout << "Big Cluster:" << std::endl;
84  std::cout << "\tOpening Angle: " << opening_angle << std::endl;
85  std::cout << "\tLength: " << length << std::endl;
86  std::cout << "\tStart Point: (" << start_w << ", " << end_w << ")" << std::endl;
87  std::cout << "\tDirection Angle: " << direc_angle << std::endl;
88  std::cout << std::endl;
89  }
90 
91  for (auto& hit: hitss){
92  COM_t_s += hit.t * hit.charge;
93  COM_w_s += hit.w * hit.charge;
94  Q_s += hit.charge;
95  }
96  COM_t_s /= Q_s;
97  COM_w_s /= Q_s;
98 
99  if (_debug) {
100  std::cout << "Small Cluster: " << std::endl;
101  std::cout << "N Hits: " << hitssmall << std::endl;
102  std::cout << "COM: (w,t) -> (" << COM_w_s << ", " << COM_t_s << ")" << std::endl;
103  std::cout << std::endl;
104  }
105 
106  //Get COM
107  std::pair<float,float> COM_s;
108  COM_s = std::make_pair( COM_w_s, COM_t_s );
109 
110  //Get rotate COM to see if in cone
111  double COM_w_rot = (COM_w_s - start_w)*cos(direc_angle*3.14/180.) + (COM_t_s - start_t)*sin(direc_angle*3.14/180.);
112  double COM_t_rot = - (COM_w_s - start_w)*sin(direc_angle*3.14/180.) + (COM_t_s - start_t)*cos(direc_angle*3.14/180.);
113 
114  //look for polygon overlap
115  if ( ( poly.PointInside(COM_s) ) and _COMinPolyAlg ){
116  if (_verbose) { std::cout << "Polygon Overlap -> Merge!" << std::endl << std::endl;}
117  return true;
118  }
119  //look for COM in cone
120  if ( _COMinConeAlg and
121  (COM_w_rot < length*_lengthReach ) and ( COM_w_rot > 0 ) and
122  ( abs(COM_t_rot) < abs(COM_w_rot*sin(opening_angle*3.14/180.)) ) ){
123  if (_verbose) { std::cout << "COM in Cone -> Merge! " << std::endl; }
124  return true;
125  }
126  //look for COM close to start-end of other cluster
127  if ( _COMNearClus and
128  ShortestDistanceSquared( COM_w_s, COM_t_s, start_w, start_t, end_w, end_t ) < _MaxDist ) {
129  if (_verbose) { std::cout << "COM close to start-end -> Merge!" << std::endl; }
130  return true;
131  }
132 
133  return false;
134  }
T abs(T value)
Detector simulation of raw signals on wires.
bool PointInside(const std::pair< float, float > &point) const
Definition: Polygon2D.cxx:252
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:102
bool _COMinPolyAlg
How four out - as percent of cluster length - cone will extend from start point.
QTextStream & endl(QTextStream &s)
void cmtool::CBAlgoCenterOfMass::Report ( )
virtual

Function to report what's going on per merging iteration.

Reimplemented from cmtool::CMAlgoBase.

Definition at line 137 of file CBAlgoCenterOfMass.cxx.

139  {
140 
141  }
virtual void cmtool::CBAlgoCenterOfMass::Reset ( void  )
inlinevirtual

Function to reset the algorithm instance ... maybe implemented via child class.

Reimplemented from cmtool::CMAlgoBase.

Definition at line 46 of file CBAlgoCenterOfMass.h.

46 {}
void cmtool::CBAlgoCenterOfMass::SetDebug ( bool  on)
inline

Function to set Debug mode of output.

Definition at line 52 of file CBAlgoCenterOfMass.h.

void cmtool::CBAlgoCenterOfMass::SetLengthReach ( double  frac)
inline

Set Length Reach: How for out the cone extends as percent of cluster length.

Definition at line 73 of file CBAlgoCenterOfMass.h.

void cmtool::CBAlgoCenterOfMass::SetMaxDistance ( double  d)
inline

Function to set Max Distance for COM to be from start-end.

Definition at line 61 of file CBAlgoCenterOfMass.h.

void cmtool::CBAlgoCenterOfMass::SetMaxHitsSmallClus ( size_t  n)
inline

Function to set Max hits for small clsuters.

Definition at line 55 of file CBAlgoCenterOfMass.h.

55 { _maxHits = n; }
std::void_t< T > n
void cmtool::CBAlgoCenterOfMass::SetMinHitsBigClus ( size_t  n)
inline

Function to se Min hits for big clusters.

Definition at line 58 of file CBAlgoCenterOfMass.h.

58 { _minHits = n; }
std::void_t< T > n
double cmtool::CBAlgoCenterOfMass::ShortestDistanceSquared ( double  point_x,
double  point_y,
double  start_x,
double  start_y,
double  end_x,
double  end_y 
) const

Definition at line 143 of file CBAlgoCenterOfMass.cxx.

145  {
146 
147  //This code finds the shortest distance between a point and a line segment.
148  //code based off sample from
149  //http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
150  //note to self: rewrite this with TVector2 and compare time differences...
151  //TVector2 code might be more understandable
152 
153  double distance_squared = -1;
154 
155  // Line segment: from ("V") = (start_x, start_y) to ("W")=(end_x, end_y)
156  double length_squared = pow((end_x - start_x), 2) + pow((end_y - start_y), 2);
157 
158  // Treat the case start & end point overlaps
159  if(length_squared < 0.1) {
160  if(_verbose){
161  std::cout << std::endl;
162  std::cout << Form(" Provided very short line segment: (%g,%g) => (%g,%g)",
163  start_x,start_y,end_x,end_y) << std::endl;
164  std::cout << " Likely this means one of two clusters have start & end point identical." << std::endl;
165  std::cout << " Check the cluster output!" << std::endl;
166  std::cout << std::endl;
167  std::cout << Form(" At this time, the algorithm uses a point (%g,%g)",start_x,start_y) << std::endl;
168  std::cout << " to represent this cluster's location." << std::endl;
169  std::cout << std::endl;
170  }
171 
172  return (pow((point_x - start_x),2) + pow((point_y - start_y),2));
173  }
174 
175  //Find shortest distance between point ("P")=(point_x,point_y) to this line segment
176  double t = ( (point_x - start_x)*(end_x - start_x) + (point_y - start_y)*(end_y - start_y) ) / length_squared;
177 
178  if(t<0.0) distance_squared = pow((point_x - start_x), 2) + pow((point_y - start_y), 2);
179 
180  else if (t>1.0) distance_squared = pow((point_x - end_x), 2) + pow(point_y - end_y, 2);
181 
182  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);
183 
184  return distance_squared;
185 
186  }//end ShortestDistanceSquared function
constexpr T pow(T x)
Definition: pow.h:72
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)
void cmtool::CBAlgoCenterOfMass::UseCOMInCone ( bool  on)
inline

Use COM in Poly algo to decide merging.

Definition at line 67 of file CBAlgoCenterOfMass.h.

void cmtool::CBAlgoCenterOfMass::UseCOMInPoly ( bool  on)
inline

Use COM in Poly algo to decide merging.

Definition at line 64 of file CBAlgoCenterOfMass.h.

64 { _COMinPolyAlg = on; }
bool _COMinPolyAlg
How four out - as percent of cluster length - cone will extend from start point.
void cmtool::CBAlgoCenterOfMass::UseCOMNearClus ( bool  on)
inline

Use COM in Poly algo to decide merging.

Definition at line 70 of file CBAlgoCenterOfMass.h.

Member Data Documentation

bool cmtool::CBAlgoCenterOfMass::_COMinConeAlg
protected

Definition at line 88 of file CBAlgoCenterOfMass.h.

bool cmtool::CBAlgoCenterOfMass::_COMinPolyAlg
protected

How four out - as percent of cluster length - cone will extend from start point.

Definition at line 87 of file CBAlgoCenterOfMass.h.

bool cmtool::CBAlgoCenterOfMass::_COMNearClus
protected

Definition at line 89 of file CBAlgoCenterOfMass.h.

bool cmtool::CBAlgoCenterOfMass::_debug
protected

Definition at line 82 of file CBAlgoCenterOfMass.h.

double cmtool::CBAlgoCenterOfMass::_lengthReach
protected

Definition at line 86 of file CBAlgoCenterOfMass.h.

double cmtool::CBAlgoCenterOfMass::_MaxDist
protected

Definition at line 85 of file CBAlgoCenterOfMass.h.

size_t cmtool::CBAlgoCenterOfMass::_maxHits
protected

Definition at line 84 of file CBAlgoCenterOfMass.h.

size_t cmtool::CBAlgoCenterOfMass::_minHits
protected

Definition at line 83 of file CBAlgoCenterOfMass.h.


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