CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RoadSearchCircleSeed.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/RoadSearchSeedFinder
3 // Class: RoadSearchCircleSeed
4 //
5 // Description: circle from three global points in 2D
6 // all data members restricted to 2 dimensions
7 //
8 // Original Author: Oliver Gutsche, gutsche@fnal.gov
9 // Created: Mon Jan 22 21:42:35 UTC 2007
10 //
11 // $Author: mkirn $
12 // $Date: 2007/09/07 16:28:52 $
13 // $Revision: 1.6 $
14 //
15 
16 #include <cmath>
17 
20 
22 
24 
26  const TrackingRecHit *hit2,
27  const TrackingRecHit *hit3,
28  GlobalPoint &point1,
29  GlobalPoint &point2,
30  GlobalPoint &point3) {
31 
32  hits_.reserve(3);
33  hits_.push_back(hit1);
34  hits_.push_back(hit2);
35  hits_.push_back(hit3);
36 
37  points_.reserve(3);
38  points_.push_back(point1);
39  points_.push_back(point2);
40  points_.push_back(point3);
41 
42  FastCircle kreis(point1,
43  point2,
44  point3);
45 
46  if ( !kreis.isValid() ) {
47  // line
49  inBarrel_ = true; // Not used for lines
50  center_ = GlobalPoint(0,0,0);
51  radius_ = 0;
52  impactParameter_ = 0;
53  } else {
54  type_ = circle;
56  radius_ = kreis.rho();
57  center_ = GlobalPoint(kreis.x0(),kreis.y0(),0);
59  }
60 
61 }
62 
64  const TrackingRecHit *hit2,
65  GlobalPoint &point1,
66  GlobalPoint &point2) {
67  //
68  // straight line constructor
69  //
70 
71  hits_.reserve(2);
72  hits_.push_back(hit1);
73  hits_.push_back(hit2);
74 
75  points_.reserve(2);
76  points_.push_back(point1);
77  points_.push_back(point2);
78 
80  inBarrel_ = true; // Not used for lines
81  center_ = GlobalPoint(0,0,0);
82  radius_ = 0;
83  impactParameter_ = 0;
84 
85 }
86 
88 }
89 
91  //
92  // returns true if all hits are in the barrel,
93  // otherwise returns false
94  //
95 
96  for (std::vector<const TrackingRecHit*>::const_iterator hit = hits_.begin();
97  hit != hits_.end(); ++hit) {
98  if ((*hit)->geographicalId().subdetId() == StripSubdetector::TEC) {
99  return false;
100  }
101  }
102 
103  return true;
104 }
105 
107  double radius) {
108  //
109  // calculate impact parameter to (0,0,0) from center and radius of circle
110  //
111 
112  double d = std::sqrt( center.x() * center.x() +
113  center.y() * center.y() );
114 
115  return std::abs(d-radius);
116 }
117 
119  //
120  // calculate eta from theta
121  //
122 
123  return -1.*std::log(std::tan(theta/2.));
124 }
125 
127  //
128  // calculate the theta of the seed
129  // by taking the average theta of all
130  // the lines formed by combinations of
131  // hits in the seed
132  //
133  // Note: A faster implementation would
134  // calculate in the constructor, save, and
135  // return the member here. This implementation
136  // minimizes the memory footprint.
137  //
138 
139  // Form all the possible lines
140  std::vector<LineRZ> lines;
141  for (std::vector<GlobalPoint>::const_iterator point1 = points_.begin();
142  point1 != points_.end(); ++point1) {
143  for (std::vector<GlobalPoint>::const_iterator point2 = point1+1;
144  point2 != points_.end(); ++point2) {
145  lines.push_back(LineRZ(*point1, *point2));
146  }
147  }
148 
149  double netTheta = 0.;
150  for (std::vector<LineRZ>::const_iterator line = lines.begin();
151  line != lines.end(); ++line){
152  netTheta += line->Theta();
153  }
154  return netTheta/(double)lines.size();
155 }
156 
158  //
159  // calculate the angle in the x-y plane
160  // of the momentum vector at the point of
161  // closest approach to (0,0,0)
162  //
163  // Note: A faster implementation would
164  // calculate in the constructor, save, and
165  // return the member here. This implementation
166  // minimizes the memory footprint.
167  //
168 
169  // Calculate phi as the average phi of all
170  // lines formed by combinations of hits if
171  // this is a straight line
172  if (type_ == straightLine) {
173  std::vector<LineXY> lines;
174  for (std::vector<GlobalPoint>::const_iterator point1 = points_.begin();
175  point1 != points_.end(); ++point1) {
176  for (std::vector<GlobalPoint>::const_iterator point2 = point1+1;
177  point2 != points_.end(); ++point2) {
178  lines.push_back(LineXY(*point1,*point2));
179  }
180  }
181  double netPhi = 0.;
182  for (std::vector<LineXY>::const_iterator line = lines.begin();
183  line != lines.end(); ++line) {
184  netPhi += line->Phi();
185  }
186  return netPhi/(double)lines.size();
187  } // END calculation for linear seeds
188 
189  // This calculation is not valid for seeds which do not exit
190  // the tracking detector (lines always exit)
191  else if (2.*Radius()+ImpactParameter()<110) {
192  return 100000.;
193  }
194 
195  // circular seeds
196  else {
197  double phi = 100000.;
198  double centerPhi = center_.barePhi();
199 
200  // Find the first hit in time, which determines the direction of
201  // the momentum vector (tangent to the circle at the point of
202  // closest approach, clockwise or counter-clockwise).
203  // The first hit in time is always the hit with the smallest
204  // value r as long as the track exits the tracking detector.
205  GlobalPoint firstPoint = points_[0];
206  for (unsigned int i=1; i<points_.size(); ++i) {
207  if (firstPoint.perp() > points_[i].perp()) {
208  firstPoint = points_[i];
209  }
210  }
211 
212  // Get the next hit, firstPoint is at the point of
213  // closest approach and cannot be used to
214  // determine the direction of the initial
215  // momentum vector
216  if (firstPoint.barePhi() == centerPhi) {
217  GlobalPoint nextHit = points_[0];
218  for (unsigned int i=1; i<points_.size(); ++i) {
219  if (nextHit.perp() == firstPoint.perp() ||
220  (firstPoint.perp()!= points_[i].perp() &&
221  nextHit.perp() > points_[i].perp())) {
222  nextHit = points_[i];
223  }
224  }
225  firstPoint = nextHit;
226  }
227 
228  // Find the direction of the momentum vector
229  if (firstPoint.barePhi() > centerPhi) {
230  // The momentum vector is tangent to
231  // the track
232  phi = centerPhi + Geom::pi()/2.;
233  if (phi>Geom::pi()) {
234  phi -= 2.*Geom::pi();
235  }
236  }
237  // Other direction!
238  else if (firstPoint.barePhi() < centerPhi) {
239  // The momentum vector is tangent to
240  // the track
241  phi = centerPhi - Geom::pi()/2.;
242  if (phi<-1.*Geom::pi()) {
243  phi += 2.*Geom::pi();
244  }
245  }
246  return phi;
247  } // END calculation for circular seeds
248 }
249 
250 std::string RoadSearchCircleSeed::print() const {
251  //
252  // print function
253  //
254 
255  std::ostringstream ost;
256 
258  ost << "Straight Line: number of points: " << points_.size() << "\n";
259  unsigned int counter = 0;
260  for ( std::vector<GlobalPoint>::const_iterator point = points_.begin();
261  point != points_.end();
262  ++point ) {
263  ++counter;
264  ost << " Point " << counter << ": " << point->x() << "," << point->y() << "\n";
265  }
266  } else {
267  ost << "Circle: number of points: " << points_.size() << "\n";
268  ost << " Radius : " << radius_ << "\n";
269  ost << " In the barrel : " << inBarrel_ << "\n";
270  ost << " ImpactParameter: " << impactParameter_ << "\n";
271  ost << " Center : " << center_.x() << "," << center_.y() << "\n";
272  unsigned int counter = 0;
273  for ( std::vector<GlobalPoint>::const_iterator point = points_.begin();
274  point != points_.end();
275  ++point ) {
276  ++counter;
277  ost << " Point " << counter << " : " << point->x() << "," << point->y() << "\n";
278  }
279  }
280 
281  return ost.str();
282 }
283 
284 std::ostream& operator<<(std::ostream& ost, const RoadSearchCircleSeed & seed) {
285  //
286  // print operator
287  //
288 
289  if ( seed.Type() == RoadSearchCircleSeed::straightLine ) {
290  ost << "Straight Line: number of points: " << seed.Points().size() << "\n";
291  unsigned int counter = 0;
292  for ( std::vector<GlobalPoint>::const_iterator point = seed.Points().begin();
293  point != seed.Points().end();
294  ++point ) {
295  ++counter;
296  ost << " Point " << counter << ": " << point->x() << "," << point->y() << "\n";
297  }
298  } else {
299  ost << "Circle: number of points: " << seed.Points().size() << "\n";
300  ost << " Radius : " << seed.Radius() << "\n";
301  ost << " In the barrel : " << seed.InBarrel() << "\n";
302  ost << " ImpactParameter: " << seed.ImpactParameter() << "\n";
303  ost << " Center : " << seed.Center().x() << "," << seed.Center().y() << "\n";
304  unsigned int counter = 0;
305  for ( std::vector<GlobalPoint>::const_iterator point = seed.Points().begin();
306  point != seed.Points().end();
307  ++point ) {
308  ++counter;
309  ost << " Point " << counter << " : " << point->x() << "," << point->y() << "\n";
310  }
311  }
312 
313  return ost;
314 }
315 
317  double centerCut,
318  double radiusCut,
319  unsigned int differentHitsCut) const {
320  //
321  // compare this circle with the input circle
322  // compare: percentage of center difference of center average
323  // compare: percentage of radius difference of radius average
324  // compare: number of hits which don't overlap between the two circles
325  //
326 
327  // return value
328  bool result = false;
329 
330  result = CompareRadius(circle,radiusCut);
331  if ( result ) {
332  result = CompareCenter(circle,centerCut);
333  if ( result ) {
334  result = CompareDifferentHits(circle,differentHitsCut);
335  }
336  }
337 
338  return result;
339 
340 }
341 
343  double centerCut) const {
344  //
345  // compare this circle with the input circle
346  // compare: percentage of center difference of center average
347  //
348 
349  // return value
350  bool result = false;
351 
352  double averageCenter = std::sqrt(((center_.x()+circle->Center().x())/2) *
353  ((center_.x()+circle->Center().x())/2) +
354  ((center_.y()+circle->Center().y())/2) *
355  ((center_.y()+circle->Center().y())/2));
356  double differenceCenter = std::sqrt((center_.x()-circle->Center().x()) *
357  (center_.x()-circle->Center().x()) +
358  (center_.y()-circle->Center().y()) *
359  (center_.y()-circle->Center().y()));
360 
361  if ( differenceCenter/averageCenter <= centerCut ) {
362  result = true;
363  }
364 
365 // edm::LogVerbatim("OLI") << "center difference: " << differenceCenter
366 // << "center average: " << averageCenter
367 // << "center percentage: " << differenceCenter/averageCenter
368 // << " cut: " << centerCut
369 // << " result: " << result;
370 
371  return result;
372 
373 }
374 
376  double radiusCut) const {
377  //
378  // compare: percentage of center difference of center average
379  // compare: percentage of radius difference of radius average
380  //
381 
382  // return value
383  bool result = false;
384 
385  double averageRadius = (radius_ + circle->Radius() ) /2;
386  double differenceRadius = std::abs(radius_ - circle->Radius());
387 
388  if ( differenceRadius/averageRadius <= radiusCut ) {
389  result = true;
390  }
391 
392 // edm::LogVerbatim("OLI") << "radius difference: " << differenceRadius
393 // << " radius average: " << averageRadius
394 // << " radius percentage: " << differenceRadius/averageRadius
395 // << " cut: " << radiusCut
396 // << " result: " << result;
397 
398  return result;
399 
400 }
401 
403  unsigned int differentHitsCut) const {
404  //
405  // compare this circle with the input circle
406  // compare: number of hits which don't overlap between the two circles
407  //
408 
409  // return value
410  bool result = false;
411 
412  // assume circles always have 3 hits
413  unsigned int counter = 0;
414  for ( std::vector<const TrackingRecHit*>::const_iterator hit1 = hits_.begin(),
415  hit1End = hits_.end();
416  hit1 != hit1End;
417  ++hit1 ) {
418  bool included = false;
419  for ( std::vector<const TrackingRecHit*>::const_iterator hit2 = circle->begin_hits(),
420  hit2End = circle->end_hits();
421  hit2 != hit2End;
422  ++hit2 ) {
423  if ( *hit1 == *hit2 ) {
424  included = true;
425  }
426  }
427  if ( !included ) {
428  ++counter;
429  }
430  }
431 
432  if ( counter <= differentHitsCut ) {
433  result = true;
434  }
435 
436 // edm::LogVerbatim("OLI") << "hits: " << counter
437 // << " cut: " << differentHitsCut
438 // << " result: " << result;
439 
440  return result;
441 
442 }
443 
444 //
445 // constructor
446 //
448 {
449  theR_ = std::fabs(point1.perp()-point2.perp());
450  theZ_ = std::fabs(point1.z()-point2.z());
451  //If the line is pointing backwards in z
452  if ((point1.perp() >= point2.perp() &&
453  point1.z() < point2.z()) ||
454  (point2.perp() >= point1.perp() &&
455  point2.z() < point1.z()))
456  {
457  theZ_ = -1.*theZ_;
458  }
459 }
460 
461 //
462 // destructor
463 //
465 { }
466 
467 //
468 // constructor
469 //
471 {
472  theX_ = std::fabs(point1.x()-point2.x());
473  theY_ = std::fabs(point1.y()-point2.y());
474  //If the line is pointing backwards in x
475  if ((point1.perp() >= point2.perp() &&
476  point1.x() < point2.x()) ||
477  (point2.perp() >= point1.perp() &&
478  point2.x() < point1.x()))
479  {
480  theX_ = -1.*theX_;
481  }
482  //If the line is pointing backwards in y
483  if ((point1.perp() >= point2.perp() &&
484  point1.y() < point2.y()) ||
485  (point2.perp() >= point1.perp() &&
486  point2.y() < point1.y()))
487  {
488  theY_ = -1.*theY_;
489  }
490 }
491 
492 //
493 // destructor
494 //
496 { }
bool Compare(const RoadSearchCircleSeed *circle, double centerCut, double radiusCut, unsigned int differentHitsCut) const
int i
Definition: DBlmapReader.cc:9
double calculateEta(double theta) const
T perp() const
Definition: PV3DBase.h:71
double x0() const
Definition: FastCircle.h:50
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:62
#define abs(x)
Definition: mlp_lapack.h:159
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
std::pair< double, double > line
double rho() const
Definition: FastCircle.h:54
std::vector< const TrackingRecHit * >::const_iterator begin_hits() const
T barePhi() const
Definition: PV3DBase.h:67
bool isValid() const
Definition: FastCircle.h:56
GlobalPoint Center() const
T sqrt(T t)
Definition: SSEVec.h:46
double calculateImpactParameter(GlobalPoint &center, double radius)
T z() const
Definition: PV3DBase.h:63
tuple result
Definition: query.py:137
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double ImpactParameter() const
bool CompareDifferentHits(const RoadSearchCircleSeed *circle, unsigned int differentHitsCut) const
std::vector< const TrackingRecHit * >::const_iterator end_hits() const
std::vector< GlobalPoint > points_
double y0() const
Definition: FastCircle.h:52
bool CompareRadius(const RoadSearchCircleSeed *circle, double radiusCut) const
bool CompareCenter(const RoadSearchCircleSeed *circle, double centerCut) const
double pi()
Definition: Pi.h:31
RoadSearchCircleSeed(const TrackingRecHit *hit1, const TrackingRecHit *hit2, const TrackingRecHit *hit3, GlobalPoint &point1, GlobalPoint &point2, GlobalPoint &point3)
std::vector< const TrackingRecHit * > hits_
LineRZ(GlobalPoint point1, GlobalPoint point2)
std::vector< GlobalPoint > Points() const
std::string print() const
T x() const
Definition: PV3DBase.h:61
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
LineXY(GlobalPoint point1, GlobalPoint point2)
Definition: DDAxes.h:10