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