CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
TangentCircle Class Reference

#include <TangentCircle.h>

Public Member Functions

int charge (float magz)
 
double curvatureError ()
 
GlobalVector directionAtVertex ()
 Return the direction at the vertex. More...
 
GlobalPoint innerPoint () const
 
bool isValid () const
 
GlobalPoint outerPoint () const
 
double rho () const
 
 TangentCircle ()
 
 TangentCircle (const GlobalVector &direction, const GlobalPoint &innerPoint, const GlobalPoint &outerPoint)
 
 TangentCircle (const GlobalPoint &outerPoint, const GlobalPoint &innerPoint, const GlobalPoint &vertexPoint)
 Copy of FastCircle. More...
 
 TangentCircle (const TangentCircle &primCircle, const GlobalPoint &outerPoint, const GlobalPoint &innerPoint)
 Calculate the parameters of a circle which pass by 2 points (innerPoint and outerPoint) and which is tangent to primCircle. More...
 
double vertexError () const
 
GlobalPoint vertexPoint () const
 
double x0 () const
 
double y0 () const
 

Private Member Functions

int chargeLocally (float magz, GlobalVector v) const
 
GlobalVector direction (const GlobalPoint &point) const
 
GlobalPoint getPosition (const TangentCircle &circle, const GlobalPoint &initalPosition, double theta, int direction) const
 
double isTangent (const TangentCircle &primCircle, const TangentCircle &secCircle) const
 

Private Attributes

int theCharge
 
GlobalVector theDirectionAtVertex
 
GlobalPoint theInnerPoint
 
GlobalPoint theOuterPoint
 
double theRho
 
double theVertexError
 
GlobalPoint theVertexPoint
 
double theX0
 
double theY0
 
bool valid
 

Detailed Description

Definition at line 7 of file TangentCircle.h.

Constructor & Destructor Documentation

TangentCircle::TangentCircle ( )
inline

Definition at line 14 of file TangentCircle.h.

14  :
16  theX0(0), theY0(0), theRho(0), theVertexError(0),
17  valid(false), theCharge(0) {}
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
GlobalPoint theInnerPoint
Definition: TangentCircle.h:53
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:57
double theVertexError
Definition: TangentCircle.h:63
TangentCircle::TangentCircle ( const GlobalVector direction,
const GlobalPoint innerPoint,
const GlobalPoint outerPoint 
)

Calculate the circle from 2 points on the circle (the vertex=innerPoint and the outerPoint) and the tangent direction at the inner point

Definition at line 7 of file TangentCircle.cc.

References funct::cos(), cuy::denominator, direction(), PV3DBase< T, PVType, FrameType >::mag(), mag(), PV3DBase< T, PVType, FrameType >::perp2(), PI, funct::sin(), theCharge, theDirectionAtVertex, theInnerPoint, theOuterPoint, theRho, theVertexError, theX0, theY0, valid, PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

7  :
9 
10  if(theInnerPoint.perp2() > theOuterPoint.perp2()) { valid = false; }
11  else valid=true;
12 
13  double x1 = inner.x();
14  double y1 = inner.y();
15  double x2 = outer.x();
16  double y2 = outer.y();
17  double alpha1 = (direction.y() != 0) ? atan(-direction.x()/direction.y()) : PI/2 ;
18  double denominator = 2*((x1-x2)*cos(alpha1)+(y1-y2)*sin(alpha1));
19  theRho = (denominator != 0) ? ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))/denominator : 1E12;
20 
21  // TODO : variable not yet calculated look in nucl.C
22  theX0 = 1E10;
23  theY0 = 1E10;
24 
27 
28  //theCharge = (theRho>0) ? -1 : 1;
29 
30  theCharge = 0;
31  theRho = fabs(theRho);
32 
34 }
#define PI
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T y() const
Definition: PV3DBase.h:63
T perp2() const
Definition: PV3DBase.h:71
T mag() const
Definition: PV3DBase.h:67
list denominator
Definition: cuy.py:484
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
GlobalVector direction(const GlobalPoint &point) const
GlobalPoint theInnerPoint
Definition: TangentCircle.h:53
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:57
double theVertexError
Definition: TangentCircle.h:63
T x() const
Definition: PV3DBase.h:62
TangentCircle::TangentCircle ( const GlobalPoint outerPoint,
const GlobalPoint innerPoint,
const GlobalPoint vertexPoint 
)

Copy of FastCircle.

Definition at line 36 of file TangentCircle.cc.

References FastCircle::isValid(), PV3DBase< T, PVType, FrameType >::perp2(), FastCircle::rho(), theCharge, theDirectionAtVertex, theInnerPoint, theOuterPoint, theRho, theVertexError, theX0, theY0, valid, FastCircle::x0(), and FastCircle::y0().

36  :
37  theInnerPoint(innerPoint), theOuterPoint(outerPoint), theVertexPoint(vertexPoint) {
38  FastCircle circle(outerPoint, innerPoint, vertexPoint);
39  theX0 = circle.x0();
40  theY0 = circle.y0();
41  theRho = circle.rho();
42  theVertexError = 0;
43  theCharge = 0;
44  theDirectionAtVertex = GlobalVector(1000, 1000, 1000);
45  if(theInnerPoint.perp2() > theOuterPoint.perp2() || !circle.isValid()) { valid = false; }
46  else valid=true;
47 }
T perp2() const
Definition: PV3DBase.h:71
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
GlobalPoint theInnerPoint
Definition: TangentCircle.h:53
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:57
double theVertexError
Definition: TangentCircle.h:63
Global3DVector GlobalVector
Definition: GlobalVector.h:10
TangentCircle::TangentCircle ( const TangentCircle primCircle,
const GlobalPoint outerPoint,
const GlobalPoint innerPoint 
)

Calculate the parameters of a circle which pass by 2 points (innerPoint and outerPoint) and which is tangent to primCircle.

Definition at line 49 of file TangentCircle.cc.

References dir, getPosition(), i, innerPoint(), isTangent(), LogDebug, mag(), outerPoint(), PV3DBase< T, PVType, FrameType >::perp2(), rho(), alignCSCRings::s, theCharge, theDirectionAtVertex, theInnerPoint, theOuterPoint, theRho, theta(), theVertexError, theVertexPoint, theX0, theY0, valid, vertexPoint(), PV3DBase< T, PVType, FrameType >::x(), x0(), PV3DBase< T, PVType, FrameType >::y(), and y0().

49  {
50 
51  if(theInnerPoint.perp2() > theOuterPoint.perp2()) { valid = false; }
52  else valid = true;
53 
54  int NITER = 10;
55 
56  // Initial vertex used = outerPoint of the primary circle (should be the first estimation of the nuclear interaction position)
57  GlobalPoint InitialVertex( primCircle.outerPoint().x() , primCircle.outerPoint().y(), 0);
58  GlobalPoint SecInnerPoint( innerPoint.x(), innerPoint.y(), 0);
59  GlobalPoint SecOuterPoint( outerPoint.x(), outerPoint.y(), 0);
60 
61  // distance between the initial vertex and the inner point of the secondary circle
62  double s = (SecInnerPoint - InitialVertex).mag();
63  double deltaTheta = s/primCircle.rho();
64 
65  double minTangentCondition = 1E12;
66  TangentCircle theCorrectSecCircle;
67  GlobalPoint vertex = InitialVertex;
68  int dir = 1;
69  double theta = deltaTheta/(NITER-1);
70 
71  for(int i=0; i<NITER; i++) {
72 
73  // get the circle which pass through outerPoint, innerPoint and the vertex
74  TangentCircle secCircle( SecOuterPoint, SecInnerPoint, vertex );
75 
76  // get a value relative to the tangentness of the 2 circles
77  double minCond = isTangent(primCircle, secCircle);
78 
79  // double dirDiff = (primCircle.direction(vertex) - secCircle.direction(vertex)).mag();
80  // if( dirDiff > 1) dirDiff = 2-dirDiff;
81 
82  if(minCond < minTangentCondition) {
83  minTangentCondition = minCond;
84  theCorrectSecCircle = secCircle;
85  vertex = getPosition( primCircle, secCircle.vertexPoint(), theta, dir );
86  if( i==0 && ((vertex-SecInnerPoint).mag() > (InitialVertex-SecInnerPoint).mag()) ) {
87  dir=-1;
88  vertex = getPosition( primCircle, InitialVertex, theta, dir );
89  LogDebug("NuclearSeedGenerator") << "Change direction to look for vertex" << "\n";
90  }
91  }
92  else break;
93 
94  }
95  theInnerPoint = theCorrectSecCircle.innerPoint();
96  theOuterPoint = theCorrectSecCircle.outerPoint();
97  theVertexPoint = theCorrectSecCircle.vertexPoint();
98  theX0 = theCorrectSecCircle.x0();
99  theY0 = theCorrectSecCircle.y0();
100  theRho = theCorrectSecCircle.rho();
101  theCharge = 0;
102  theDirectionAtVertex = GlobalVector(1000, 1000, 1000);
103 
104  theVertexError = s/NITER;
105 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
double y0() const
Definition: TangentCircle.h:34
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
double x0() const
Definition: TangentCircle.h:32
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
GlobalPoint innerPoint() const
Definition: TangentCircle.h:40
T perp2() const
Definition: PV3DBase.h:71
GlobalPoint getPosition(const TangentCircle &circle, const GlobalPoint &initalPosition, double theta, int direction) const
double rho() const
Definition: TangentCircle.h:36
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalPoint outerPoint() const
Definition: TangentCircle.h:38
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
GlobalPoint theInnerPoint
Definition: TangentCircle.h:53
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:57
dbl *** dir
Definition: mlp_gen.cc:35
double theVertexError
Definition: TangentCircle.h:63
double isTangent(const TangentCircle &primCircle, const TangentCircle &secCircle) const
T x() const
Definition: PV3DBase.h:62
GlobalPoint vertexPoint() const
Definition: TangentCircle.h:42
Global3DVector GlobalVector
Definition: GlobalVector.h:10

Member Function Documentation

int TangentCircle::charge ( float  magz)

Definition at line 180 of file TangentCircle.cc.

References chargeLocally(), directionAtVertex(), F(), LogDebug, theCharge, theVertexPoint, theX0, theY0, findQualityFiles::v, PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

Referenced by TangentHelix::charge().

180  {
181 
182  if(theCharge != 0) return theCharge;
183 
184  if(theX0 > 1E9 || theY0 > 1E9) theCharge = chargeLocally(magz, directionAtVertex());
185  else {
186  GlobalPoint center(theX0, theY0, 0);
187  GlobalVector u = center - theVertexPoint;
189 
190  // F = force vector
191  GlobalVector F( v.y() * magz, -v.x() * magz, 0);
192  if( u.x() * F.x() + u.y() * F.y() > 0) theCharge=-1;
193  else theCharge=1;
194 
195  if(theCharge != chargeLocally(magz, v)) {
196  LogDebug("NuclearSeedGenerator") << "Inconsistency in calculation of the charge" << "\n";
197  }
198 
199  }
200  return theCharge;
201 }
#define LogDebug(id)
T y() const
Definition: PV3DBase.h:63
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalVector directionAtVertex()
Return the direction at the vertex.
int chargeLocally(float magz, GlobalVector v) const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
T x() const
Definition: PV3DBase.h:62
int TangentCircle::chargeLocally ( float  magz,
GlobalVector  v 
) const
private

Definition at line 203 of file TangentCircle.cc.

References theOuterPoint, theVertexPoint, PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

Referenced by charge().

203  {
205  double tz = v.x() * u.y() - v.y() * u.x() ;
206 
207  if(tz * magz > 0) return 1; else return -1;
208 }
T y() const
Definition: PV3DBase.h:63
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
T x() const
Definition: PV3DBase.h:62
double TangentCircle::curvatureError ( )

Definition at line 167 of file TangentCircle.cc.

References directionAtVertex(), mag(), rho(), theInnerPoint, theOuterPoint, theVertexError, and theVertexPoint.

Referenced by TangentHelix::curvatureError().

167  {
171  return fabs(1/circle1.rho() - 1/circle2.rho());
172  }
173  else {
176  return fabs(1/circle1.rho() - 1/circle2.rho());
177  }
178 }
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
GlobalVector directionAtVertex()
Return the direction at the vertex.
GlobalPoint theInnerPoint
Definition: TangentCircle.h:53
double theVertexError
Definition: TangentCircle.h:63
GlobalVector TangentCircle::direction ( const GlobalPoint point) const
private

Definition at line 118 of file TangentCircle.cc.

References mps_update::diff, dir, LogDebug, mag(), theInnerPoint, theOuterPoint, theX0, theY0, PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

Referenced by directionAtVertex(), and TangentCircle().

118  {
119 
120  if(theY0 > 1E9 || theX0 > 1E9) {
121  LogDebug("NuclearSeedGenerator") << "Center of TangentCircle not calculated but used !!!" << "\n";
122  }
123 
124  // calculate the direction perpendicular to the vector v = point - center_of_circle
125  GlobalVector dir(point.y() - theY0, theX0 - point.x(), 0);
126 
127  dir/=dir.mag();
128 
129  // Check the sign :
131  double diff = (dir - fastDir).mag();
132  double sum = (dir + fastDir).mag();
133 
134  if( sum < diff ) dir = (-1)*dir;
135 
136  return dir;
137 }
#define LogDebug(id)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
T y() const
Definition: PV3DBase.h:63
list diff
Definition: mps_update.py:85
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
GlobalPoint theInnerPoint
Definition: TangentCircle.h:53
dbl *** dir
Definition: mlp_gen.cc:35
T x() const
Definition: PV3DBase.h:62
GlobalVector TangentCircle::directionAtVertex ( )

Return the direction at the vertex.

Definition at line 139 of file TangentCircle.cc.

References direction(), theDirectionAtVertex, theVertexPoint, and PV3DBase< T, PVType, FrameType >::x().

Referenced by charge(), curvatureError(), and TangentHelix::directionAtVertex().

139  {
140  if(theDirectionAtVertex.x() > 999)
142  return theDirectionAtVertex;
143 }
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
GlobalVector direction(const GlobalPoint &point) const
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:57
T x() const
Definition: PV3DBase.h:62
GlobalPoint TangentCircle::getPosition ( const TangentCircle circle,
const GlobalPoint initalPosition,
double  theta,
int  direction 
) const
private

Definition at line 145 of file TangentCircle.cc.

References alpha, beta, funct::cos(), cmsLHEtoEOSManager::l, PI, rho(), jetcorrextractor::sign(), funct::sin(), PV3DBase< T, PVType, FrameType >::x(), x0(), PV3DBase< T, PVType, FrameType >::y(), and y0().

Referenced by TangentCircle().

145  {
146 
147  int sign[3];
148  double x2 = initalPosition.x();
149  double y2 = initalPosition.y();
150 
151  if( (x2>circle.x0()) && dir >0) { sign[0] = 1; sign[1] = -1; sign[2] = -1; }
152  if( (x2>circle.x0()) && dir <0) { sign[0] = 1; sign[1] = 1; sign[2] = 1; }
153  if( (x2<circle.x0()) && dir >0) { sign[0] = -1; sign[1] = 1; sign[2] = -1; }
154  if( (x2<circle.x0()) && dir <0) { sign[0] = -1; sign[1] = -1; sign[2] = 1; }
155 
156  double l = 2*circle.rho()*sin(theta/2);
157  double alpha = atan((y2-circle.y0())/(x2-circle.x0()));
158  double beta = PI/2-theta/2;
159  double gamma = PI + sign[2]* alpha - beta;
160 
161  double xnew = x2 + sign[0]*l*cos(gamma);
162  double ynew = y2 + sign[1]*l*sin(gamma);
163 
164  return GlobalPoint( xnew, ynew, 0 );
165 }
const double beta
float alpha
Definition: AMPTWrapper.h:95
double y0() const
Definition: TangentCircle.h:34
#define PI
double sign(double x)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double x0() const
Definition: TangentCircle.h:32
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
double rho() const
Definition: TangentCircle.h:36
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
dbl *** dir
Definition: mlp_gen.cc:35
T x() const
Definition: PV3DBase.h:62
GlobalPoint TangentCircle::innerPoint ( ) const
inline

Definition at line 40 of file TangentCircle.h.

References theInnerPoint.

Referenced by TangentCircle().

40 { return theInnerPoint; }
GlobalPoint theInnerPoint
Definition: TangentCircle.h:53
double TangentCircle::isTangent ( const TangentCircle primCircle,
const TangentCircle secCircle 
) const
private

Definition at line 107 of file TangentCircle.cc.

References min(), rho(), x0(), and y0().

Referenced by TangentCircle().

107  {
108  // return a value that should be equal to 0 if primCircle and secCircle are tangent
109 
110  double distanceBetweenCircle = (primCircle.x0() - secCircle.x0())*(primCircle.x0() - secCircle.x0())
111  + (primCircle.y0() - secCircle.y0())*(primCircle.y0() - secCircle.y0());
112  double RadiusSum = (primCircle.rho() + secCircle.rho())*(primCircle.rho() + secCircle.rho());
113  double RadiusDifference = (primCircle.rho() - secCircle.rho())*(primCircle.rho() - secCircle.rho());
114 
115  return std::min( fabs(RadiusSum-distanceBetweenCircle), fabs(RadiusDifference-distanceBetweenCircle) );
116 }
double y0() const
Definition: TangentCircle.h:34
double x0() const
Definition: TangentCircle.h:32
double rho() const
Definition: TangentCircle.h:36
T min(T a, T b)
Definition: MathUtil.h:58
bool TangentCircle::isValid ( void  ) const
inline

Definition at line 50 of file TangentCircle.h.

References isValid().

Referenced by isValid(), and core.AutoHandle.AutoHandle::ReallyLoad().

50 { return isValid(); }
bool isValid() const
Definition: TangentCircle.h:50
GlobalPoint TangentCircle::outerPoint ( ) const
inline

Definition at line 38 of file TangentCircle.h.

References theOuterPoint.

Referenced by TangentCircle().

38 { return theOuterPoint; }
GlobalPoint theOuterPoint
Definition: TangentCircle.h:54
double TangentCircle::rho ( ) const
inline
double TangentCircle::vertexError ( ) const
inline

Definition at line 44 of file TangentCircle.h.

References theVertexError.

Referenced by TangentHelix::vertexError().

44 { return theVertexError; }
double theVertexError
Definition: TangentCircle.h:63
GlobalPoint TangentCircle::vertexPoint ( ) const
inline

Definition at line 42 of file TangentCircle.h.

References theVertexPoint.

Referenced by TangentCircle(), and TangentHelix::TangentHelix().

42 { return theVertexPoint; }
GlobalPoint theVertexPoint
Definition: TangentCircle.h:55
double TangentCircle::x0 ( ) const
inline

Definition at line 32 of file TangentCircle.h.

References theX0.

Referenced by getPosition(), isTangent(), and TangentCircle().

32 {return theX0;}
double TangentCircle::y0 ( ) const
inline

Definition at line 34 of file TangentCircle.h.

References theY0.

Referenced by getPosition(), isTangent(), and TangentCircle().

34 {return theY0;}

Member Data Documentation

int TangentCircle::theCharge
private

Definition at line 66 of file TangentCircle.h.

Referenced by charge(), and TangentCircle().

GlobalVector TangentCircle::theDirectionAtVertex
private

Definition at line 57 of file TangentCircle.h.

Referenced by directionAtVertex(), and TangentCircle().

GlobalPoint TangentCircle::theInnerPoint
private

Definition at line 53 of file TangentCircle.h.

Referenced by curvatureError(), direction(), innerPoint(), and TangentCircle().

GlobalPoint TangentCircle::theOuterPoint
private

Definition at line 54 of file TangentCircle.h.

Referenced by chargeLocally(), curvatureError(), direction(), outerPoint(), and TangentCircle().

double TangentCircle::theRho
private

Signed radius of the circle (=q*R)

Definition at line 61 of file TangentCircle.h.

Referenced by rho(), and TangentCircle().

double TangentCircle::theVertexError
private

the error on the vertex position along the direction of the circle at this point

Definition at line 63 of file TangentCircle.h.

Referenced by curvatureError(), TangentCircle(), and vertexError().

GlobalPoint TangentCircle::theVertexPoint
private
double TangentCircle::theX0
private

x center of the circle

Definition at line 59 of file TangentCircle.h.

Referenced by charge(), direction(), TangentCircle(), and x0().

double TangentCircle::theY0
private

y center of the circle

Definition at line 60 of file TangentCircle.h.

Referenced by charge(), direction(), TangentCircle(), and y0().

bool TangentCircle::valid
private

Definition at line 65 of file TangentCircle.h.

Referenced by TangentCircle().