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 120 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().

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

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

Definition at line 24 of file HelixBarrelPlaneCrossingByCircle.cc.

References Basic3DVector< T >::mag(), python.connectstrParser::o, Basic3DVector< T >::perp(), EnergyCorrector::pt, 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 HLT_25ns14e33_v1_cff::A, funct::abs(), funct::C, chooseSolution(), RealQuadEquation::first, RealQuadEquation::hasSolution, Plane::localZ(), Basic2DVector< T >::mag(), gen::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(), TrackKinematicStatePropagator::propagateToTheTransversePCACharged(), and TrackKinematicStatePropagator::willPropagateToTheTransversePCA().

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
111  double sinAlpha = 0.5*theDmag*theRho;
112  if ( std::abs(sinAlpha)>1.) sinAlpha = std::copysign(1.,sinAlpha);
113  theS = theActualDir*2./(theRho*theSinTheta) * asin( sinAlpha);
114  return ResultType( true, theS);
115  }
116  else return ResultType( false, 0.);
117 }
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:63
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
bool chooseSolution(const Vector2D &d1, const Vector2D &d2)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T x() const
Definition: PV3DBase.h:62
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 159 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().

160 {
161  if(useStraightLine){
163  }else{
164  if ( s==theS) {
165  return PositionType( theStartingPos.x() + theD.x(),
166  theStartingPos.y() + theD.y(),
168  }
169  else {
170  double phi = s*theSinTheta*theRho;
171  double x1Shift = theStartingPos.x() - theXCenter;
172  double y1Shift = theStartingPos.y() - theYCenter;
173 
174  return PositionType(x1Shift*cos(phi)-y1Shift*sin(phi) + theXCenter,
175  x1Shift*sin(phi)+y1Shift*cos(phi) + theYCenter,
177  }
178  }
179 }
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.

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().