CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
CircleFromThreePoints Class Reference

#include <CircleFromThreePoints.h>

Public Types

typedef Basic2DVector< float > Vector2D
 

Public Member Functions

Vector2D center () const
 
 CircleFromThreePoints ()
 dummy More...
 
 CircleFromThreePoints (const GlobalPoint &inner, const GlobalPoint &mid, const GlobalPoint &outer, double precision=1.e-7)
 
float curvature () const
 

Private Member Functions

void init (const Vector2D &b, const Vector2D &c, const Vector2D &offset, double precision)
 

Private Attributes

Vector2D theCenter
 
float theCurvature
 

Detailed Description

Computes the curvature (1/radius) and, if possible, the center of the circle passing through three points. The input points are three dimensional for convenience, but the calculation is done in the transverse (x,y) plane. No verification of the reasonableness of the z coordinate is done. If the three points lie on a line the curvature is zero and the center position is undefined. The 3 points are assumed to make sense: if the distance between two of them is very small compared to the ditance to the third the result will be numerically unstable.

Definition at line 18 of file CircleFromThreePoints.h.

Member Typedef Documentation

◆ Vector2D

Definition at line 23 of file CircleFromThreePoints.h.

Constructor & Destructor Documentation

◆ CircleFromThreePoints() [1/2]

CircleFromThreePoints::CircleFromThreePoints ( )
inline

dummy

Definition at line 21 of file CircleFromThreePoints.h.

21 {}

◆ CircleFromThreePoints() [2/2]

CircleFromThreePoints::CircleFromThreePoints ( const GlobalPoint inner,
const GlobalPoint mid,
const GlobalPoint outer,
double  precision = 1.e-7 
)

Construct from three points (see class description). The order of points is not essential, but accuracy should be better if the second point lies between the other two on the circle. The optional argument "precision" specifies how accurately the straight line check has to be satisfied for setting the curvature to zero and the center position to "undefined".

Definition at line 3 of file CircleFromThreePoints.cc.

6  {
7  // move to frame where inner.x() == inner.y() == 0;
8  Vector2D b(mid.x() - inner.x(), mid.y() - inner.y());
9  Vector2D c(outer.x() - inner.x(), outer.y() - inner.y());
10  init(b, c, Vector2D(inner.x(), inner.y()), precision);
11 }

References b, HltBtagPostValidation_cff::c, init(), SurfaceOrientation::inner, SurfaceOrientation::outer, common_cff::precision, PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

Member Function Documentation

◆ center()

Vector2D CircleFromThreePoints::center ( ) const
inline

returns the position of the center of the circle. If curvature is zero, center() throws an exception to avoid use of undefined position. If the curvature is very small the position of the center will be very inaccurate.

Definition at line 50 of file CircleFromThreePoints.h.

50 { return theCenter; }

References theCenter.

Referenced by ClusterShapeTrackFilter::getGlobalDirs(), PixelFitterByHelixProjections::run(), TrackFitter::run(), and KFBasedPixelFitter::run().

◆ curvature()

float CircleFromThreePoints::curvature ( ) const
inline

Returns the curvature (1/radius), in cm^(-1). The curvature is precomputed, this is just access method (takes no time). If curvature is zero the center is undefined (see description of presicion above).

Definition at line 42 of file CircleFromThreePoints.h.

42 { return theCurvature; }

References theCurvature.

Referenced by ClusterShapeTrackFilter::getGlobalDirs(), PixelFitterByHelixProjections::run(), TrackFitter::run(), and KFBasedPixelFitter::run().

◆ init()

void CircleFromThreePoints::init ( const Vector2D b,
const Vector2D c,
const Vector2D offset,
double  precision 
)
private

Definition at line 13 of file CircleFromThreePoints.cc.

13  {
14  double b2 = b.mag2();
15  double c2 = c.mag2();
16 
17  double oX(0), oY(0);
18  bool solved = false;
19  if (fabs(b.x()) > fabs(b.y())) { // solve for y first
20  double k = c.x() / b.x();
21  double div = 2 * (k * b.y() - c.y());
22  if (fabs(div) < precision)
23  theCurvature = 0; // if the 3 points lie on a line
24  else {
25  oY = (k * b2 - c2) / div;
26  oX = b2 / (2 * b.x()) - b.y() / b.x() * oY;
27  solved = true;
28  }
29  } else { // solve for x first
30  double k = c.y() / b.y();
31  double div = 2 * (k * b.x() - c.x());
32  if (fabs(div) < precision)
33  theCurvature = 0; // if the 3 points lie on a line
34  else {
35  oX = (k * b2 - c2) / div;
36  oY = b2 / (2 * b.y()) - b.x() / b.y() * oX;
37  solved = true;
38  }
39  }
40  if (solved) {
41  theCurvature = 1. / sqrt(oX * oX + oY * oY);
42  double xC = oX + offset.x();
43  double yC = oY + offset.y();
44  theCenter = Vector2D(xC, yC);
45  // thePhi = acos(xC/sqrt(xC*xC + yC*yC));
46 
47  // if (xC<0.) thePhi = thePhi - PI;
48  // cout << setiosflags(ios::showpoint | ios::fixed);
49  //
50  // cout << "CircleFromThreePoints::init curv = " << theCurvature << endl;
51  // cout << "CircleFromThreePoints::init center prime = " << oX << " " << oY << endl;
52  // cout << "CircleFromThreePoints::init offset = " << offset.x() << " " << offset.y() << endl;
53  // cout << "CircleFromThreePoints::init center = " << theCenter.x()<< " " << theCenter.y() << endl;
54  //
55  // float d = sqrt(theCenter.x()*theCenter.x()+theCenter.y()*theCenter.y());
56  // cout << "CircleFromThreePoints::init dfloat = " << setw(10) << setprecision(5) << d << endl;
57  // cout << "CircleFromThreePoints::init radius = " << 1/theCurvature << endl;
58  }
59 }

References b, b2, HltBtagPostValidation_cff::c, dqmdumpme::k, hltrates_dqm_sourceclient-live_cfg::offset, common_cff::precision, mathSSE::sqrt(), theCenter, and theCurvature.

Referenced by CircleFromThreePoints().

Member Data Documentation

◆ theCenter

Vector2D CircleFromThreePoints::theCenter
private

Definition at line 54 of file CircleFromThreePoints.h.

Referenced by center(), and init().

◆ theCurvature

float CircleFromThreePoints::theCurvature
private

Definition at line 53 of file CircleFromThreePoints.h.

Referenced by curvature(), and init().

CircleFromThreePoints::theCurvature
float theCurvature
Definition: CircleFromThreePoints.h:53
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
b2
static constexpr float b2
Definition: L1EGammaCrystalsEmulatorProducer.cc:83
SurfaceOrientation::inner
Definition: Surface.h:19
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
dqmdumpme.k
k
Definition: dqmdumpme.py:60
b
double b
Definition: hdecay.h:118
CircleFromThreePoints::init
void init(const Vector2D &b, const Vector2D &c, const Vector2D &offset, double precision)
Definition: CircleFromThreePoints.cc:13
common_cff.precision
precision
Definition: common_cff.py:44
Vector2D
Basic2DVector< double >::MathVector Vector2D
Definition: LinkByRecHit.cc:7
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
CircleFromThreePoints::theCenter
Vector2D theCenter
Definition: CircleFromThreePoints.h:54
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
CircleFromThreePoints::Vector2D
Basic2DVector< float > Vector2D
Definition: CircleFromThreePoints.h:23
SurfaceOrientation::outer
Definition: Surface.h:19
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82