LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
CFAlgoStartPointMatch.cxx
Go to the documentation of this file.
1 #ifndef RECOTOOL_CFALGOSTARTPOINTMATCH_CXX
2 #define RECOTOOL_CFALGOSTARTPOINTMATCH_CXX
3 
5 
6 namespace cmtool {
7 
8  //-------------------------------------------------------
10  //-------------------------------------------------------
11  {
13  _w2cm = geou.WireToCm();
14  _t2cm = geou.TimeToCm();
15  UseTime(true);
16  SetMaxArea(100.);
17 
18  }
19 
20  //-----------------------------
22  //-----------------------------
23  {
24 
25  }
26 
27  //----------------------------------------------------------------------------------------------
28  float CFAlgoStartPointMatch::Float(const std::vector<const cluster::ClusterParamsAlg*> &clusters)
29  //----------------------------------------------------------------------------------------------
30  {
31 
32  // Code-block by Kazu starts
33  // This ensures the algorithm works only if # clusters is > 2 (and not =2)
34  // You may take out this block if you want to allow matching using clusters from only 2 planes.
35  if(clusters.size()==2) return -1;
36  // Code-block by Kazu ends
37 
38  //This algorithm now works for 3 planes: find 3Dstart point from first 2 planes and find
39  //How well that agrees with 3rd plane's start point location.
40 
41  //So first, make sure clusters vector has only 3 elements. If not return -1
42  if ( clusters.size() != 3 )
43  return -1;
44 
45  //Find 3D start point from start point on first 2 planes:
46  //For now convert start point wire in cm back to wire number
47  //Round to integer (sometimes output is double...why???)
48  int startWire1 = int( clusters.at(0)->GetParams().start_point.w / _w2cm );
49  double startTime1 = clusters.at(0)->GetParams().start_point.t;
50  unsigned int Pl1 = clusters.at(0)->GetParams().start_point.plane;
51  int startWire2 = int( clusters.at(1)->GetParams().start_point.w / _w2cm );
52  double startTime2 = clusters.at(1)->GetParams().start_point.t;
53  unsigned int Pl2 = clusters.at(1)->GetParams().start_point.plane;
54  int startWire3 = int( clusters.at(2)->GetParams().start_point.w / _w2cm );
55  double startTime3 = clusters.at(2)->GetParams().start_point.t;
56  unsigned int Pl3 = clusters.at(2)->GetParams().start_point.plane;
57 
58  unsigned int cryo=0;
59  unsigned int tpc =0;
60 
61  //Get Intersections in pairs:
62  //y and z indicate detector coordinate and numbers indicate planes
63  //used to generate that intersection point
64  double yS12, zS12, yS13, zS13, yS23, zS23;
65 
67  geo->IntersectionPoint( startWire1, startWire2,
68  Pl1, Pl2,
69  cryo, tpc,
70  yS12, zS12);
71 
72  geo->IntersectionPoint( startWire1, startWire3,
73  Pl1, Pl3,
74  cryo, tpc,
75  yS13, zS13);
76 
77  geo->IntersectionPoint( startWire2, startWire3,
78  Pl2, Pl3,
79  cryo, tpc,
80  yS23, zS23);
81 
82  if ( _verbose ){
83  std::cout << "Wire Start Numbers: " << std::endl;
84  std::cout << "\t" << startWire1 << std::endl;
85  std::cout << "\t" << startWire2 << std::endl;
86  std::cout << "\t" << startWire3 << std::endl;
87  std::cout << std::endl;
88  }
89 
90  if ( _verbose ){
91  std::cout << "Intersection Pl1-Pl3: ( " << yS13 << ", " << zS13 << " )" << std::endl;
92  std::cout << "Intersection Pl1-Pl2: ( " << yS12 << ", " << zS12 << " )" << std::endl;
93  std::cout << "Intersection Pl2-Pl3: ( " << yS23 << ", " << zS23 << " )" << std::endl;
94  }
95 
96  //Parameter used for evaluation is area of triangle formed by the three intersection points
97  double area = -1;
98  if ( !_time ){
99  area = Area2D( yS12, zS12, yS23, zS23, yS13, zS13 );
100  }
101  if ( _time ){
102  area = Area3D( (yS12+yS13)/2. , (zS12+zS13)/2. , startTime1,
103  (yS13+yS23)/2. , (zS13+zS23)/2. , startTime3,
104  (yS12+yS23)/2. , (zS13+zS23)/2. , startTime2 );
105  }
106 
107  if ( _verbose ) { std::cout << "Area of intersections triangle is: " << area << std::endl; }
108 
109  if ( area > _MaxArea )
110  return -1;
111  else
112  return 1./area;
113 
114  }
115 
116  //------------------------------
118  //------------------------------
119  {
120 
121  }
122 
123  //---------------------------------------------------------------------------------------------------
124  double CFAlgoStartPointMatch::Area2D( double Ax, double Ay, double Bx, double By, double Cx, double Cy ) {
125  //---------------------------------------------------------------------------------------------------
126 
127  double a = (Ax*(By-Cy)+Bx*(Cy-Ay)+Cx*(Ay-By))*0.5;
128 
129  if ( a < 0 ) { a *= -1; }
130 
131  return a;
132 
133  }
134 
135  //---------------------------------------------------------------------------------------------------
136  double CFAlgoStartPointMatch::Area3D( double Ax, double Ay, double Az,
137  double Bx, double By, double Bz,
138  double Cx, double Cy, double Cz ) {
139  //---------------------------------------------------------------------------------------------------
140 
141  //Create vectors AB and AC
142  Bx = Bx-Ax;
143  By = By-Ay;
144  Bz = Bz-Az;
145  Cx = Cx-Ax;
146  Cy = Cy-Ay;
147  Cz = Cz-Az;
148 
149  return 0.5*sqrt( (By*Cz-Cz*By)*(By*Cz-Cz*By) + (Bz*Cx-Bx*Cz)*(Bz*Cx-Bx*Cz) + (Bx*Cy-By*Cx)*(Bx*Cy-By*Cx) );
150  }
151 
152 
153 }
154 #endif
Double_t TimeToCm() const
CFAlgoStartPointMatch()
Default constructor.
Double_t WireToCm() const
double Area2D(double Ax, double Ay, double Bx, double By, double Cx, double Cy)
double Area3D(double Ax, double Ay, double Az, double Bx, double By, double Bz, double Cx, double Cy, double Cz)
bool IntersectionPoint(geo::WireID const &wid1, geo::WireID const &wid2, double &y, double &z) const
Returns the intersection point of two wires.
Class def header for a class CFAlgoStartPointMatch.
virtual float Float(const std::vector< const cluster::ClusterParamsAlg * > &clusters)
virtual void Reset()
Function to reset the algorithm instance, called together with manager&#39;s Reset()
Namespace collecting geometry-related classes utilities.
bool _verbose
Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager&#39;s verbosity level is >= kPer...
Definition: CMAlgoBase.h:88