CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
HelixBarrelPlaneCrossingByCircle Class Referencefinal

#include <HelixBarrelPlaneCrossingByCircle.h>

Inheritance diagram for HelixBarrelPlaneCrossingByCircle:
HelixPlaneCrossing

Public Member Functions

DirectionType direction (double s) const override
 
 HelixBarrelPlaneCrossingByCircle (const PositionType &pos, const DirectionType &dir, double rho, PropagationDirection propDir=alongMomentum)
 
 HelixBarrelPlaneCrossingByCircle (const GlobalPoint &pos, const GlobalVector &dir, double rho, PropagationDirection propDir=alongMomentum)
 
std::pair< bool, double > pathLength (const Plane &) override
 
PositionType position (double s) const override
 
- Public Member Functions inherited from HelixPlaneCrossing
virtual ~HelixPlaneCrossing ()=default
 

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

◆ Vector2D

Definition at line 32 of file HelixBarrelPlaneCrossingByCircle.h.

Constructor & Destructor Documentation

◆ HelixBarrelPlaneCrossingByCircle() [1/2]

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

◆ HelixBarrelPlaneCrossingByCircle() [2/2]

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

Member Function Documentation

◆ chooseSolution()

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

Definition at line 116 of file HelixBarrelPlaneCrossingByCircle.cc.

References alongMomentum, anyDirection, d1, 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().

116  {
117  bool solved;
118  double momProj1 = theStartingDir.x() * d1.x() + theStartingDir.y() * d1.y();
119  double momProj2 = theStartingDir.x() * d2.x() + theStartingDir.y() * d2.y();
120 
121  if (thePropDir == anyDirection) {
122  solved = true;
123  if (d1.mag2() < d2.mag2()) {
124  theD = d1;
125  theActualDir = (momProj1 > 0) ? 1. : -1.;
126  } else {
127  theD = d2;
128  theActualDir = (momProj2 > 0) ? 1. : -1.;
129  }
130 
131  } else {
132  double propSign = thePropDir == alongMomentum ? 1 : -1;
133  if (!mathSSE::samesign(momProj1, momProj2)) {
134  // if different signs return the positive one
135  solved = true;
136  theD = mathSSE::samesign(momProj1, propSign) ? d1 : d2;
137  theActualDir = propSign;
138  } else if (mathSSE::samesign(momProj1, propSign)) {
139  // if both positive, return the shortest
140  solved = true;
141  theD = (d1.mag2() < d2.mag2()) ? d1 : d2;
142  theActualDir = propSign;
143  } else
144  solved = false;
145  }
146  return solved;
147 }
T x() const
Cartesian x coordinate.
T y() const
Cartesian y coordinate.
bool samesign(T rh, T lh)
static constexpr float d1

◆ direction()

HelixPlaneCrossing::DirectionType HelixBarrelPlaneCrossingByCircle::direction ( double  s) const
overridevirtual

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 168 of file HelixBarrelPlaneCrossingByCircle.cc.

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

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

168  {
169  if (useStraightLine) {
170  return theStartingDir;
171  } else {
172  double sinPhi, cosPhi;
173  if (s == theS) {
174  double tmp = 0.5 * theDmag * theRho;
175  if (s < 0)
176  tmp = -tmp;
177  // protect sqrt
178  sinPhi = 1. - (tmp * tmp);
179  if (sinPhi < 0)
180  sinPhi = 0.;
181  sinPhi = 2. * tmp * sqrt(sinPhi);
182  cosPhi = 1. - 2. * (tmp * tmp);
183  } else {
184  double phi = s * theSinTheta * theRho;
185  sinPhi = sin(phi);
186  cosPhi = cos(phi);
187  }
190  theStartingDir.z());
191  }
192 }
T x() const
Cartesian x coordinate.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T y() const
Cartesian y coordinate.
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Basic3DVector< float > DirectionType
T z() const
Cartesian z coordinate.
tmp
align.sh
Definition: createJobs.py:716

◆ init()

void HelixBarrelPlaneCrossingByCircle::init ( void  )
private

Definition at line 26 of file HelixBarrelPlaneCrossingByCircle.cc.

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

Referenced by HelixBarrelPlaneCrossingByCircle().

26  {
27  double pabsI = 1. / theStartingDir.mag();
28  double pt = theStartingDir.perp();
29  theCosTheta = theStartingDir.z() * pabsI;
30  theSinTheta = pt * pabsI;
31 
32  // protect for zero curvature case
33  const double sraightLineCutoff = 1.e-7;
34  if (fabs(theRho) < sraightLineCutoff && 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 x() const
Cartesian x coordinate.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
T y() const
Cartesian y coordinate.
T perp() const
Magnitude of transverse component.
T z() const
Cartesian z coordinate.

◆ pathLength()

std::pair< bool, double > HelixBarrelPlaneCrossingByCircle::pathLength ( const Plane )
overridevirtual

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 47 of file HelixBarrelPlaneCrossingByCircle.cc.

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

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

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

◆ position()

HelixPlaneCrossing::PositionType HelixBarrelPlaneCrossingByCircle::position ( double  s) const
overridevirtual

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 149 of file HelixBarrelPlaneCrossingByCircle.cc.

References funct::cos(), phi, alignCSCRings::s, 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().

149  {
150  if (useStraightLine) {
152  } else {
153  if (s == theS) {
154  return PositionType(
156  } else {
157  double phi = s * theSinTheta * theRho;
158  double x1Shift = theStartingPos.x() - theXCenter;
159  double y1Shift = theStartingPos.y() - theYCenter;
160 
161  return PositionType(x1Shift * cos(phi) - y1Shift * sin(phi) + theXCenter,
162  x1Shift * sin(phi) + y1Shift * cos(phi) + theYCenter,
163  theStartingPos.z() + s * theCosTheta);
164  }
165  }
166 }
T x() const
Cartesian x coordinate.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T y() const
Cartesian y coordinate.
T y() const
Cartesian y 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 z() const
Cartesian z coordinate.
Basic3DVector unit() const
T x() const
Cartesian x coordinate.

Member Data Documentation

◆ theActualDir

double HelixBarrelPlaneCrossingByCircle::theActualDir
private

Definition at line 50 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by chooseSolution(), and pathLength().

◆ theCosTheta

double HelixBarrelPlaneCrossingByCircle::theCosTheta
private

Definition at line 39 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by init(), and position().

◆ theD

Vector2D HelixBarrelPlaneCrossingByCircle::theD
private

Definition at line 46 of file HelixBarrelPlaneCrossingByCircle.h.

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

◆ theDmag

double HelixBarrelPlaneCrossingByCircle::theDmag
private

Definition at line 47 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by direction(), and pathLength().

◆ thePropDir

PropagationDirection HelixBarrelPlaneCrossingByCircle::thePropDir
private

Definition at line 37 of file HelixBarrelPlaneCrossingByCircle.h.

Referenced by chooseSolution(), and pathLength().

◆ theRho

double HelixBarrelPlaneCrossingByCircle::theRho
private

Definition at line 36 of file HelixBarrelPlaneCrossingByCircle.h.

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

◆ theS

double HelixBarrelPlaneCrossingByCircle::theS
private

Definition at line 45 of file HelixBarrelPlaneCrossingByCircle.h.

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

◆ theSinTheta

double HelixBarrelPlaneCrossingByCircle::theSinTheta
private

Definition at line 40 of file HelixBarrelPlaneCrossingByCircle.h.

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

◆ theStartingDir

DirectionType HelixBarrelPlaneCrossingByCircle::theStartingDir
private

◆ theStartingPos

PositionType HelixBarrelPlaneCrossingByCircle::theStartingPos
private

Definition at line 34 of file HelixBarrelPlaneCrossingByCircle.h.

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

◆ theXCenter

double HelixBarrelPlaneCrossingByCircle::theXCenter
private

Definition at line 41 of file HelixBarrelPlaneCrossingByCircle.h.

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

◆ theYCenter

double HelixBarrelPlaneCrossingByCircle::theYCenter
private

Definition at line 42 of file HelixBarrelPlaneCrossingByCircle.h.

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

◆ useStraightLine

bool HelixBarrelPlaneCrossingByCircle::useStraightLine
private

Definition at line 51 of file HelixBarrelPlaneCrossingByCircle.h.

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