LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
CFAlgoStartPointCompat.cxx
Go to the documentation of this file.
1 #ifndef RECOTOOL_CFALGOSTARTPOINTCOMPAT_CXX
2 #define RECOTOOL_CFALGOSTARTPOINTCOMPAT_CXX
3 
5 #include <algorithm>
6 
7 namespace cmtool {
8 
9  //-------------------------------------------------------
11  //-------------------------------------------------------
12  {
14  _w2cm = geou.WireToCm();
15  _t2cm = geou.TimeToCm();
16  SetVerbose(false);
17  }
18 
19  //-----------------------------
21  //-----------------------------
22  {
23 
24  }
25 
26  //----------------------------------------------------------------------------------------------
27  float CFAlgoStartPointCompat::Float(const std::vector<const cluster::ClusterParamsAlg*> &clusters)
28  //----------------------------------------------------------------------------------------------
29  {
30 
31  // Code-block by Kazu starts
32  // This ensures the algorithm works only if # clusters is > 2 (and not =2)
33  // You may take out this block if you want to allow matching using clusters from only 2 planes.
34  if(clusters.size()==2) return -1;
35  // Code-block by Kazu ends
36 
37  //This algorithm now works for 3 planes: find 3Dstart point from first 2 planes and find
38  //How well that agrees with 3rd plane's start point location.
39 
40  //So first, make sure clusters vector has only 3 elements. If not return -1
41  if ( clusters.size() != 3 )
42  return -1;
43 
44  //Find 3D start point from start point on first 2 planes:
45  //For now convert start point wire in cm back to wire number
46  //Round to integer (sometimes output is double...why???)
47  double startWirecm0 = clusters.at(0)->GetParams().start_point.w;
48  double startTimecm0 = clusters.at(0)->GetParams().start_point.t;
49  int startWire0 = int( startWirecm0 / _w2cm );
50  unsigned int Pl0 = clusters.at(0)->GetParams().start_point.plane;
51  //int startChan1 = larutil::Geometry::GetME()->PlaneWireToChannel(Pl0, startWire0);
52  double startWirecm1 = clusters.at(1)->GetParams().start_point.w;
53  double startTimecm1 = clusters.at(1)->GetParams().start_point.t;
54  int startWire1 = int( startWirecm1 / _w2cm );
55  unsigned int Pl1 = clusters.at(1)->GetParams().start_point.plane;
56  //int startChan2 = larutil::Geometry::GetME()->PlaneWireToChannel(Pl1, startWire1);
57  double startWirecm2 = clusters.at(2)->GetParams().start_point.w;
58  double startTimecm2 = clusters.at(2)->GetParams().start_point.t;
59  int startWire2 = int( startWirecm2 / _w2cm );
60  unsigned int Pl2 = clusters.at(2)->GetParams().start_point.plane;
61  //int startChan3 = larutil::Geometry::GetME()->PlaneWireToChannel(Pl2, startWire2);
62 
63  unsigned int cryo=0;
64  unsigned int tpc =0;
65 
66  //Get Intersections in pairs:
67  //y and z indicate detector coordinate and numbers indicate planes
68  //used to generate that intersection point
69  double yS01, zS01, yS02, zS02, yS12, zS12;
70 
72  geo->IntersectionPoint( startWire0, startWire1,
73  Pl0, Pl1,
74  cryo, tpc,
75  yS01, zS01);
76 
77  geo->IntersectionPoint( startWire0, startWire2,
78  Pl0, Pl2,
79  cryo, tpc,
80  yS02, zS02);
81 
82  geo->IntersectionPoint( startWire1, startWire2,
83  Pl1, Pl2,
84  cryo, tpc,
85  yS12, zS12);
86 
87  //assume X coordinate for these start-points is 0
88  //i.e. only focus on projection onto wire-plane
89  //then check if the start point reconstructe from
90  //planes A and B falls within the wire-range of
91  //the cluster on plane C
92  //For compatibility also, check that the start-point-time
93  //is within the time-range of the cluster on plane C
94  Double_t Start2[3] = {-100., yS01, zS01};
95  Double_t Start1[3] = {-100., yS02, zS02};
96  Double_t Start0[3] = {-100., yS12, zS12};
97  UInt_t WireStart0 = 0;
98  UInt_t WireStart1 = 0;
99  UInt_t WireStart2 = 0;
100  try { WireStart0 = geo->NearestWire( Start0, Pl0); }
101  //catch ( ::larutil::LArUtilException &e) {
102  catch ( ::cet::exception &e) {
103  std::cout << e.what() << std::endl;
104  std::cout << "Exception caught!" << std::endl;
105  WireStart0 = 9999;
106  }
107  try { WireStart1 = geo->NearestWire( Start1, Pl1); }
108  //catch ( ::larutil::LArUtilException &e ) {
109  catch( ::cet::exception &e) {
110  std::cout << e.what() << std::endl;
111  std::cout << "Exception caught!" << std::endl;
112  WireStart0 = 9999;
113  }
114  try { WireStart2 = geo->NearestWire( Start2, Pl2); }
115  //catch ( ::larutil::LArUtilException &e) {
116  catch ( ::cet::exception &e) {
117  std::cout << e.what() << std::endl;
118  std::cout << "Exception caught!" << std::endl;
119  WireStart0 = 9999;
120  }
121 
122  //Now Get Hit-Range for Clusters
123  std::vector<util::PxHit> hits0 = clusters.at(0)->GetHitVector();
124  std::vector<util::PxHit> hits1 = clusters.at(1)->GetHitVector();
125  std::vector<util::PxHit> hits2 = clusters.at(2)->GetHitVector();
126  //define variables for min/max time/wire of each cluster
127  double minWire0 = 9999;
128  double minWire1 = 9999;
129  double minWire2 = 9999;
130  double maxWire0 = 0;
131  double maxWire1 = 0;
132  double maxWire2 = 0;
133  double minTime0 = 9999;
134  double minTime1 = 9999;
135  double minTime2 = 9999;
136  double maxTime0 = 0;
137  double maxTime1 = 0;
138  double maxTime2 = 0;
139  int hitWireTMP = 0;
140  double hitTimeTMP = 0;
141 
142  for (auto& h: hits0){
143  hitWireTMP = int(h.w/_w2cm);
144  hitTimeTMP = int(h.t/_t2cm);
145  if ( hitWireTMP < minWire0 ) { minWire0 = hitWireTMP; }
146  if ( hitWireTMP > maxWire0 ) { maxWire0 = hitWireTMP; }
147  if ( hitTimeTMP < minTime0 ) { minTime0 = hitTimeTMP; }
148  if ( hitTimeTMP > maxTime0 ) { maxTime0 = hitTimeTMP; }
149  }
150  for (auto& h: hits1){
151  hitWireTMP = int(h.w/_w2cm);
152  hitTimeTMP = int(h.t/_t2cm);
153  if ( hitWireTMP < minWire1 ) { minWire1 = hitWireTMP; }
154  if ( hitWireTMP > maxWire1 ) { maxWire1 = hitWireTMP; }
155  if ( hitTimeTMP < minTime1 ) { minTime1 = hitTimeTMP; }
156  if ( hitTimeTMP > maxTime1 ) { maxTime1 = hitTimeTMP; }
157  }
158  for (auto& h: hits2){
159  hitWireTMP = int(h.w/_w2cm);
160  hitTimeTMP = int(h.t/_t2cm);
161  if ( hitWireTMP < minWire2 ) { minWire2 = hitWireTMP; }
162  if ( hitWireTMP > maxWire2 ) { maxWire2 = hitWireTMP; }
163  if ( hitTimeTMP < minTime2 ) { minTime2 = hitTimeTMP; }
164  if ( hitTimeTMP > maxTime2 ) { maxTime2 = hitTimeTMP; }
165  }
166 
167  if ( _verbose ){
168  std::cout << "Start W,T on plane 0: " << "[ " << startWirecm0 << ", " << startTimecm0 << " ]" << std::endl;
169  std::cout << "Start Wire, planne 0: " << startWire0 << std::endl;
170  std::cout << "Start W,T on plane 1: " << "[ " << startWirecm1 << ", " << startTimecm1 << " ]" << std::endl;
171  std::cout << "Start Wire, planne 1: " << startWire1 << std::endl;
172  std::cout << "Start W,T on plane 2: " << "[ " << startWirecm2 << ", " << startTimecm2 << " ]" << std::endl;
173  std::cout << "Start Wire, planne 2: " << startWire2 << std::endl;
174  std::cout << std::endl;
175  std::cout << "Start Reco Point from clusters on planes 1 and 2 (Z,Y):" << std::endl
176  << "[ " << zS12 << ", " << yS12 << " ]" << std::endl;
177  std::cout << "Nearest wire on Pl0 to reco-start point from Pl1, Pl2:" << std::endl
178  << WireStart0 << std::endl;
179  std::cout << "Min-Max Wire for Hits from Cluster on Plane 0:" << std::endl
180  << "[ " << minWire0 << ", " << maxWire0 << " ]" << std::endl;
181  std::cout << "Start Reco Point from clusters on planes 0 and 2 (Z,Y):" << std::endl
182  << "[ " << zS02 << ", " << yS02 << " ]" << std::endl;
183  std::cout << "Nearest wire on Pl1 to reco-start point from Pl0, Pl2:" << std::endl
184  << WireStart1 << std::endl;
185  std::cout << "Min-Max Wire for Hits from Cluster on Plane 1:" << std::endl
186  << "[ " << minWire1 << ", " << maxWire1 << " ]" << std::endl;
187  std::cout << "Start Reco Point from clusters on planes 0 and 1 (Z,Y):" << std::endl
188  << "[ " << zS01 << ", " << yS01 << " ]" << std::endl;
189  std::cout << "Nearest wire on Pl2 to reco-start point from Pl0, Pl1:" << std::endl
190  << WireStart2 << std::endl;
191  std::cout << "Min-Max Wire for Hits from Cluster on Plane 2:" << std::endl
192  << "[ " << minWire2 << ", " << maxWire2 << " ]" << std::endl;
193  std::cout << std::endl;
194  }
195  //Parameter used for evaluation is whether the start-point of any reconstructed start point from 2 planes
196  //is in the start-end time-wire range of the other plane's cluster
197  double compat = 9999;
198  double retVal = -1;
199 
200  if ( (WireStart0 > minWire0) and (WireStart0 < maxWire0) ){
201  if ( std::min( (WireStart0-minWire0) , (maxWire0-WireStart0) ) < compat ){
202  compat = std::min( (WireStart0-minWire0) , (maxWire0-WireStart0) );
203  }
204  }
205  if ( (WireStart1 > minWire1) and (WireStart1 < maxWire1) ){
206  if ( std::min( (WireStart0-minWire0) , (maxWire0-WireStart0) ) < compat ){
207  compat = std::min( (WireStart0-minWire0) , (maxWire0-WireStart0) );
208  }
209  }
210  if ( (WireStart2 > minWire2) and (WireStart2 < maxWire2) ){
211  if ( std::min( (WireStart0-minWire0) , (maxWire0-WireStart0) ) < compat ){
212  compat = std::min( (WireStart0-minWire0) , (maxWire0-WireStart0) );
213  }
214  }
215 
216  if ( compat != 9999 )
217  retVal = 1./compat;
218 
219  return retVal;
220 
221  }
222 
223  //------------------------------
225  //------------------------------
226  {
227 
228  }
229 
230 }
231 #endif
Double_t TimeToCm() const
Double_t WireToCm() const
void SetVerbose(bool on)
Function to set verbose output.
virtual float Float(const std::vector< const cluster::ClusterParamsAlg * > &clusters)
Class def header for a class CFAlgoStartPointCompat.
geo::WireID::WireID_t NearestWire(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the index of wire closest to position in the specified TPC.
bool IntersectionPoint(geo::WireID const &wid1, geo::WireID const &wid2, double &y, double &z) const
Returns the intersection point of two wires.
CFAlgoStartPointCompat()
Default constructor.
Int_t min
Definition: plot.C:26
virtual void Reset()
Function to reset the algorithm instance, called together with manager&#39;s Reset()
Float_t e
Definition: plot.C:34
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33