LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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
 
virtual void EventBegin (const std::vector< cluster::ClusterParamsAlg > &clusters)
 
virtual void EventEnd ()
 
virtual void IterationBegin (const std::vector< cluster::ClusterParamsAlg > &clusters)
 
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
 
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 29 of file CBAlgoCenterOfMass.h.

Constructor & Destructor Documentation

cmtool::CBAlgoCenterOfMass::CBAlgoCenterOfMass ( )

Default constructor.

Definition at line 9 of file CBAlgoCenterOfMass.cxx.

References SetDebug(), SetLengthReach(), SetMaxDistance(), SetMaxHitsSmallClus(), SetMinHitsBigClus(), UseCOMInCone(), UseCOMInPoly(), and UseCOMNearClus().

9  : CBoolAlgoBase()
10  //----------------------------------------
11  {
12 
13  SetDebug(false);
16  SetMaxDistance(20.);
17  SetLengthReach(3.0);
18  UseCOMInPoly(true);
19  UseCOMInCone(true);
20  UseCOMNearClus(true);
21 
22  }
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 37 of file CBAlgoCenterOfMass.h.

References Bool().

37 {};

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 25 of file CBAlgoCenterOfMass.cxx.

References _COMinConeAlg, _COMinPolyAlg, _COMNearClus, _debug, _lengthReach, _MaxDist, _maxHits, _minHits, cmtool::CMAlgoBase::_verbose, Polygon2D::PointInside(), and ShortestDistanceSquared().

Referenced by ~CBAlgoCenterOfMass().

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

Optional function: called at the beginning of 1st iteration. This is called per event.

Reimplemented in cmtool::CFAlgoArray, cmtool::CPAlgoArray, cmtool::CBAlgoArray, and cmtool::CBAlgoPolyShortestDist.

Definition at line 45 of file CMAlgoBase.h.

Referenced by cmtool::CMergeManager::EventBegin().

46  { if(clusters.size()) return; }
virtual void cmtool::CMAlgoBase::EventEnd ( )
inlinevirtualinherited

Optional function: called at the end of event ... after the last merging iteration is over.

Reimplemented in cmtool::CFAlgoArray, cmtool::CPAlgoArray, and cmtool::CBAlgoArray.

Definition at line 51 of file CMAlgoBase.h.

Referenced by cmtool::CMatchManager::EventEnd(), and cmtool::CMergeManager::EventEnd().

52  {return;}
virtual void cmtool::CMAlgoBase::IterationBegin ( const std::vector< cluster::ClusterParamsAlg > &  clusters)
inlinevirtualinherited

Optional function: called at the beggining of each iteration over all pairs of clusters. This provides all clusters' information in case the algorithm need them. Note this is called per iteration which may be more than once per event.

Reimplemented in cmtool::CFAlgoArray, cmtool::CPAlgoArray, and cmtool::CBAlgoArray.

Definition at line 59 of file CMAlgoBase.h.

Referenced by cmtool::CMatchManager::EventBegin(), cmtool::CMatchManager::IterationBegin(), and cmtool::CMergeManager::IterationBegin().

60  { if(clusters.size()) return;}
virtual void cmtool::CMAlgoBase::IterationEnd ( )
inlinevirtualinherited

Optional function: called at the end of each iteration over all pairs of clusters.

Reimplemented in cmtool::CFAlgoArray, cmtool::CPAlgoArray, and cmtool::CBAlgoArray.

Definition at line 65 of file CMAlgoBase.h.

Referenced by cmtool::CMatchManager::IterationEnd(), and cmtool::CMergeManager::IterationEnd().

66  {return; }
void cmtool::CBAlgoCenterOfMass::Report ( )
virtual

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

Reimplemented from cmtool::CMAlgoBase.

Definition at line 138 of file CBAlgoCenterOfMass.cxx.

Referenced by Reset().

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

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

Reimplemented from cmtool::CMAlgoBase.

Definition at line 47 of file CBAlgoCenterOfMass.h.

References Report().

47 {}
void cmtool::CMAlgoBase::SetAnaFile ( TFile *  fout)
inlineinherited

Setter function for an output plot TFile pointer.

Definition at line 77 of file CMAlgoBase.h.

References cmtool::CMAlgoBase::_fout.

Referenced by cmtool::CMergeManager::EventBegin().

77 { _fout = fout; }
TFile * _fout
TFile pointer to an output file.
Definition: CMAlgoBase.h:85
void cmtool::CBAlgoCenterOfMass::SetDebug ( bool  on)
inline

Function to set Debug mode of output.

Definition at line 53 of file CBAlgoCenterOfMass.h.

References _debug.

Referenced by CBAlgoCenterOfMass().

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

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

Definition at line 74 of file CBAlgoCenterOfMass.h.

References _lengthReach, and ShortestDistanceSquared().

Referenced by CBAlgoCenterOfMass().

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

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

Definition at line 62 of file CBAlgoCenterOfMass.h.

References _MaxDist, and d.

Referenced by CBAlgoCenterOfMass().

62 { _MaxDist = d; }
Float_t d
Definition: plot.C:237
void cmtool::CBAlgoCenterOfMass::SetMaxHitsSmallClus ( size_t  n)
inline

Function to set Max hits for small clsuters.

Definition at line 56 of file CBAlgoCenterOfMass.h.

References _maxHits, and n.

Referenced by CBAlgoCenterOfMass().

56 { _maxHits = n; }
Char_t n[5]
void cmtool::CBAlgoCenterOfMass::SetMinHitsBigClus ( size_t  n)
inline

Function to se Min hits for big clusters.

Definition at line 59 of file CBAlgoCenterOfMass.h.

References _minHits, and n.

Referenced by CBAlgoCenterOfMass().

59 { _minHits = n; }
Char_t n[5]
virtual void cmtool::CMAlgoBase::SetVerbose ( bool  doit = true)
inlinevirtualinherited
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 144 of file CBAlgoCenterOfMass.cxx.

References cmtool::CMAlgoBase::_verbose.

Referenced by Bool(), and SetLengthReach().

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

Use COM in Poly algo to decide merging.

Definition at line 68 of file CBAlgoCenterOfMass.h.

References _COMinConeAlg.

Referenced by CBAlgoCenterOfMass().

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

Use COM in Poly algo to decide merging.

Definition at line 65 of file CBAlgoCenterOfMass.h.

References _COMinPolyAlg.

Referenced by CBAlgoCenterOfMass().

65 { _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 71 of file CBAlgoCenterOfMass.h.

References _COMNearClus.

Referenced by CBAlgoCenterOfMass().

Member Data Documentation

bool cmtool::CBAlgoCenterOfMass::_COMinConeAlg
protected

Definition at line 89 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and UseCOMInCone().

bool cmtool::CBAlgoCenterOfMass::_COMinPolyAlg
protected

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

Definition at line 88 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and UseCOMInPoly().

bool cmtool::CBAlgoCenterOfMass::_COMNearClus
protected

Definition at line 90 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and UseCOMNearClus().

bool cmtool::CBAlgoCenterOfMass::_debug
protected

Definition at line 83 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and SetDebug().

TFile* cmtool::CMAlgoBase::_fout
protectedinherited

TFile pointer to an output file.

Definition at line 85 of file CMAlgoBase.h.

Referenced by cmtool::CMAlgoBase::CMAlgoBase(), and cmtool::CMAlgoBase::SetAnaFile().

double cmtool::CBAlgoCenterOfMass::_lengthReach
protected

Definition at line 87 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and SetLengthReach().

double cmtool::CBAlgoCenterOfMass::_MaxDist
protected

Definition at line 86 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and SetMaxDistance().

size_t cmtool::CBAlgoCenterOfMass::_maxHits
protected

Definition at line 85 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and SetMaxHitsSmallClus().

size_t cmtool::CBAlgoCenterOfMass::_minHits
protected

Definition at line 84 of file CBAlgoCenterOfMass.h.

Referenced by Bool(), and SetMinHitsBigClus().


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