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 Types | Private Member Functions | Private Attributes
HelixBarrelPlaneCrossingByCircle Class Reference

#include <HelixBarrelPlaneCrossingByCircle.h>

Inheritance diagram for HelixBarrelPlaneCrossingByCircle:
HelixPlaneCrossing

Public Member Functions

virtual DirectionType direction (double s) const
 
 HelixBarrelPlaneCrossingByCircle (const PositionType &pos, const DirectionType &dir, double rho, PropagationDirection propDir=alongMomentum)
 
 HelixBarrelPlaneCrossingByCircle (const GlobalPoint &pos, const GlobalVector &dir, double rho, PropagationDirection propDir=alongMomentum)
 
virtual std::pair< bool, double > pathLength (const Plane &)
 
virtual PositionType position (double s) const
 

Private Types

typedef Basic2DVector< double > Vector2D
 

Private Member Functions

bool chooseSolution (const Vector2D &d1, const Vector2D &d2)
 
void init ()
 

Private Attributes

double theActualDir
 
double theCosTheta
 
Vector2D theD
 
double theDmag
 
PropagationDirection thePropDir
 
double theRho
 
double theS
 
double theSinTheta
 
DirectionType theStartingDir
 
PositionType theStartingPos
 
double theXCenter
 
double theYCenter
 
bool useStraightLine
 

Additional Inherited Members

- Public Types inherited from HelixPlaneCrossing
typedef Basic3DVector< float > DirectionType
 
typedef Basic3DVector< float > PositionType
 the helix is passed to the constructor and does not appear in the interface More...
 

Detailed Description

Computes the crossing of a helix with a barrel plane. Exact if the magnetic field is parallel to the plane.

Definition at line 13 of file HelixBarrelPlaneCrossingByCircle.h.

Member Typedef Documentation

Definition at line 34 of file HelixBarrelPlaneCrossingByCircle.h.

Constructor & Destructor Documentation

HelixBarrelPlaneCrossingByCircle::HelixBarrelPlaneCrossingByCircle ( const PositionType pos,
const DirectionType dir,
double  rho,
PropagationDirection  propDir = alongMomentum 
)
HelixBarrelPlaneCrossingByCircle::HelixBarrelPlaneCrossingByCircle ( const GlobalPoint pos,
const GlobalVector dir,
double  rho,
PropagationDirection  propDir = alongMomentum 
)

Member Function Documentation

bool HelixBarrelPlaneCrossingByCircle::chooseSolution ( const Vector2D d1,
const Vector2D d2 
)
private

Definition at line 121 of file HelixBarrelPlaneCrossingByCircle.cc.

References alongMomentum, anyDirection, Basic2DVector< T >::mag2(), mathSSE::samesign(), theActualDir, theD, thePropDir, theStartingDir, Basic2DVector< T >::x(), Basic3DVector< T >::x(), Basic2DVector< T >::y(), and Basic3DVector< T >::y().

Referenced by pathLength().

123 {
124  bool solved;
125  double momProj1 = theStartingDir.x()*d1.x() + theStartingDir.y()*d1.y();
126  double momProj2 = theStartingDir.x()*d2.x() + theStartingDir.y()*d2.y();
127 
128  if ( thePropDir == anyDirection ) {
129  solved = true;
130  if (d1.mag2()<d2.mag2()) {
131  theD = d1;
132  theActualDir = (momProj1 > 0) ? 1. : -1.;
133  }
134  else {
135  theD = d2;
136  theActualDir = (momProj2 > 0) ? 1. : -1.;
137  }
138 
139  }
140  else {
141  double propSign = thePropDir==alongMomentum ? 1 : -1;
142  if (!mathSSE::samesign(momProj1,momProj2)) {
143  // if different signs return the positive one
144  solved = true;
145  theD = mathSSE::samesign(momProj1,propSign) ? d1 : d2;
146  theActualDir = propSign;
147  }
148  else if (mathSSE::samesign(momProj1,propSign)) {
149  // if both positive, return the shortest
150  solved = true;
151  theD = (d1.mag2()<d2.mag2()) ? d1 : d2;
152  theActualDir = propSign;
153  }
154  else solved = false;
155  }
156  return solved;
157 }
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
bool samesign(T rh, T lh)
HelixPlaneCrossing::DirectionType HelixBarrelPlaneCrossingByCircle::direction ( double  s) const
virtual

Returns the direction along the helix that corresponds to path length "s" from the starting point. As for position, the direction of the crossing with a plane (if it exists!) is given by direction( pathLength( plane)).

Implements HelixPlaneCrossing.

Definition at line 183 of file HelixBarrelPlaneCrossingByCircle.cc.

References funct::cos(), phi, funct::sin(), mathSSE::sqrt(), theDmag, theRho, theS, theSinTheta, theStartingDir, tmp, useStraightLine, Basic3DVector< T >::x(), Basic3DVector< T >::y(), and Basic3DVector< T >::z().

Referenced by TSCPBuilderNoMaterial::createFTSatTransverseImpactPointCharged(), and TrackKinematicStatePropagator::propagateToTheTransversePCACharged().

184 {
185  if(useStraightLine){return theStartingDir;}
186  else{
187  double sinPhi, cosPhi;
188  if ( s==theS) {
189  double tmp = 0.5*theDmag*theRho;
190  if (s < 0) tmp = -tmp;
191  // protect sqrt
192  sinPhi = 1.-(tmp*tmp);
193  if ( sinPhi<0 ) sinPhi = 0.;
194  sinPhi = 2.*tmp*sqrt(sinPhi);
195  cosPhi = 1.-2.*(tmp*tmp);
196  }
197  else {
198  double phi = s*theSinTheta*theRho;
199  sinPhi = sin(phi);
200  cosPhi = cos(phi);
201  }
202  return DirectionType(theStartingDir.x()*cosPhi-theStartingDir.y()*sinPhi,
203  theStartingDir.x()*sinPhi+theStartingDir.y()*cosPhi,
204  theStartingDir.z());
205  }
206 }
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T z() const
Cartesian z coordinate.
T sqrt(T t)
Definition: SSEVec.h:46
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Basic3DVector< float > DirectionType
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Definition: DDAxes.h:10
void HelixBarrelPlaneCrossingByCircle::init ( void  )
private

Definition at line 24 of file HelixBarrelPlaneCrossingByCircle.cc.

References Basic3DVector< T >::mag(), python.connectstrParser::o, Basic3DVector< T >::perp(), theCosTheta, theRho, theSinTheta, theStartingDir, theStartingPos, theXCenter, theYCenter, useStraightLine, Basic3DVector< T >::x(), Basic3DVector< T >::y(), and Basic3DVector< T >::z().

Referenced by HelixBarrelPlaneCrossingByCircle().

25 {
26  double pabsI = 1./theStartingDir.mag();
27  double pt = theStartingDir.perp();
28  theCosTheta = theStartingDir.z()*pabsI;
29  theSinTheta = pt*pabsI;
30 
31  // protect for zero curvature case
32  const double sraightLineCutoff = 1.e-7;
33  if (fabs(theRho) < sraightLineCutoff &&
34  fabs(theRho)*theStartingPos.perp() < sraightLineCutoff) {
35  useStraightLine = true;
36  }else{
37  // circle parameters
38  // position of center of curvature is on a line perpendicular
39  // to startingDir and at a distance 1/curvature.
40  double o = 1./(pt*theRho);
43  useStraightLine = false;
44  }
45 }
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
T z() const
Cartesian z coordinate.
T perp() const
Magnitude of transverse component.
std::pair< bool, double > HelixBarrelPlaneCrossingByCircle::pathLength ( const Plane )
virtual

Propagation status (true if valid) and (signed) path length along the helix from the starting point to the plane. The starting point is given in the constructor.

Implements HelixPlaneCrossing.

Definition at line 48 of file HelixBarrelPlaneCrossingByCircle.cc.

References funct::A, funct::C, chooseSolution(), RealQuadEquation::first, RealQuadEquation::hasSolution, Plane::localZ(), Basic2DVector< T >::mag(), n, Plane::normalVector(), StraightLinePlaneCrossing::pathLength(), RealQuadEquation::second, theActualDir, theD, theDmag, thePropDir, theRho, theS, theSinTheta, theStartingDir, theStartingPos, theXCenter, theYCenter, useStraightLine, PV3DBase< T, PVType, FrameType >::x(), Basic3DVector< T >::x(), PV3DBase< T, PVType, FrameType >::y(), and Basic3DVector< T >::y().

Referenced by TSCPBuilderNoMaterial::createFTSatTransverseImpactPointCharged(), and TrackKinematicStatePropagator::propagateToTheTransversePCACharged().

49 {
50  typedef std::pair<bool,double> ResultType;
51 
52  if(useStraightLine){
53  // switch to straight line case
56  return slc.pathLength( plane);
57  }
58 
59 
60  // plane parameters
61  GlobalVector n = plane.normalVector();
62  double distToPlane = -plane.localZ( GlobalPoint( theStartingPos));
63  // double distToPlane = (plane.position().x()-theStartingPos.x()) * n.x() +
64  // (plane.position().y()-theStartingPos.y()) * n.y();
65  double nx = n.x(); // convert to double
66  double ny = n.y(); // convert to double
67  double distCx = theStartingPos.x() - theXCenter;
68  double distCy = theStartingPos.y() - theYCenter;
69 
70  double nfac, dfac;
71  double A, B, C;
72  bool solveForX;
73  if (fabs(nx) > fabs(ny)) {
74  solveForX = false;
75  nfac = ny/nx;
76  dfac = distToPlane/nx;
77  B = distCy - nfac*distCx; // only part of B, may have large cancelation
78  C = (2.*distCx + dfac)*dfac;
79  }
80  else {
81  solveForX = true;
82  nfac = nx/ny;
83  dfac = distToPlane/ny;
84  B = distCx - nfac*distCy; // only part of B, may have large cancelation
85  C = (2.*distCy + dfac)*dfac;
86  }
87  B -= nfac*dfac; B *= 2; // the rest of B (normally small)
88  A = 1.+ nfac*nfac;
89 
90  double dx1, dx2, dy1, dy2;
91  RealQuadEquation equation(A,B,C);
92  if (!equation.hasSolution) return ResultType( false, 0.);
93  else {
94  if (solveForX) {
95  dx1 = equation.first;
96  dx2 = equation.second;
97  dy1 = dfac - nfac*dx1;
98  dy2 = dfac - nfac*dx2;
99  }
100  else {
101  dy1 = equation.first;
102  dy2 = equation.second;
103  dx1 = dfac - nfac*dy1;
104  dx2 = dfac - nfac*dy2;
105  }
106  }
107  bool solved = chooseSolution( Vector2D(dx1, dy1), Vector2D(dx2, dy2));
108  if (solved) {
109  theDmag = theD.mag();
110  // protect asin (taking some safety margin)
111  double sinAlpha = 0.5*theDmag*theRho;
112  if ( sinAlpha>(1.-10*DBL_EPSILON) ) sinAlpha = 1.-10*DBL_EPSILON;
113  else if ( sinAlpha<-(1.-10*DBL_EPSILON) ) sinAlpha = -(1.-10*DBL_EPSILON);
114  theS = theActualDir*2./(theRho*theSinTheta) * asin( sinAlpha);
115  return ResultType( true, theS);
116  }
117  else return ResultType( false, 0.);
118 }
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
double_binary B
Definition: DDStreamer.cc:234
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:62
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
bool chooseSolution(const Vector2D &d1, const Vector2D &d2)
T x() const
Definition: PV3DBase.h:61
HelixPlaneCrossing::PositionType HelixBarrelPlaneCrossingByCircle::position ( double  s) const
virtual

Returns the position along the helix that corresponds to path length "s" from the starting point. If s is obtained from the pathLength method the position is the destination point, i.e. the position of the crossing with a plane (if it exists!) is given by position( pathLength( plane)).

Implements HelixPlaneCrossing.

Definition at line 160 of file HelixBarrelPlaneCrossingByCircle.cc.

References funct::cos(), phi, funct::sin(), theCosTheta, theD, theRho, theS, theSinTheta, theStartingDir, theStartingPos, theXCenter, theYCenter, Basic3DVector< T >::unit(), useStraightLine, Basic2DVector< T >::x(), Basic3DVector< T >::x(), Basic2DVector< T >::y(), Basic3DVector< T >::y(), and Basic3DVector< T >::z().

Referenced by TSCPBuilderNoMaterial::createFTSatTransverseImpactPointCharged(), and TrackKinematicStatePropagator::propagateToTheTransversePCACharged().

161 {
162  if(useStraightLine){
164  }else{
165  if ( s==theS) {
166  return PositionType( theStartingPos.x() + theD.x(),
167  theStartingPos.y() + theD.y(),
169  }
170  else {
171  double phi = s*theSinTheta*theRho;
172  double x1Shift = theStartingPos.x() - theXCenter;
173  double y1Shift = theStartingPos.y() - theYCenter;
174 
175  return PositionType(x1Shift*cos(phi)-y1Shift*sin(phi) + theXCenter,
176  x1Shift*sin(phi)+y1Shift*cos(phi) + theYCenter,
178  }
179  }
180 }
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Basic3DVector unit() const
T z() const
Cartesian z coordinate.
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Basic3DVector< float > PositionType
the helix is passed to the constructor and does not appear in the interface
T y() const
Cartesian y coordinate.
T x() const
Cartesian x coordinate.
Definition: DDAxes.h:10

Member Data Documentation

double HelixBarrelPlaneCrossingByCircle::theActualDir
private

Definition at line 52 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by chooseSolution(), and pathLength().

double HelixBarrelPlaneCrossingByCircle::theCosTheta
private

Definition at line 41 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by init(), and position().

Vector2D HelixBarrelPlaneCrossingByCircle::theD
private

Definition at line 48 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by chooseSolution(), pathLength(), and position().

double HelixBarrelPlaneCrossingByCircle::theDmag
private

Definition at line 49 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by direction(), and pathLength().

PropagationDirection HelixBarrelPlaneCrossingByCircle::thePropDir
private

Definition at line 39 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by chooseSolution(), and pathLength().

double HelixBarrelPlaneCrossingByCircle::theRho
private

Definition at line 38 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by direction(), init(), pathLength(), and position().

double HelixBarrelPlaneCrossingByCircle::theS
private

Definition at line 47 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by direction(), pathLength(), and position().

double HelixBarrelPlaneCrossingByCircle::theSinTheta
private

Definition at line 42 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by direction(), init(), pathLength(), and position().

DirectionType HelixBarrelPlaneCrossingByCircle::theStartingDir
private
PositionType HelixBarrelPlaneCrossingByCircle::theStartingPos
private

Definition at line 36 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by init(), pathLength(), and position().

double HelixBarrelPlaneCrossingByCircle::theXCenter
private

Definition at line 43 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by init(), pathLength(), and position().

double HelixBarrelPlaneCrossingByCircle::theYCenter
private

Definition at line 44 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by init(), pathLength(), and position().

bool HelixBarrelPlaneCrossingByCircle::useStraightLine
private

Definition at line 53 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by direction(), init(), pathLength(), and position().