CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StraightLineBarrelCylinderCrossing.cc
Go to the documentation of this file.
4 
5 #include <cmath>
6 
8  const GlobalVector& startingDir,
9  const PropagationDirection propDir)
10  : theX0(startingPos), theP0(startingDir.unit()), thePropDir(propDir) {}
11 
12 std::pair<bool, double> StraightLineBarrelCylinderCrossing::pathLength(const Cylinder& cylinder) const {
13  //
14  // radius of cylinder and transversal position relative to axis
15  //
16  double R(cylinder.radius());
17  GlobalPoint axis(cylinder.toGlobal(Cylinder::LocalPoint(0., 0.)));
18  PositionType2D xt2d(theX0.x() - axis.x(), theX0.y() - axis.y());
19  //
20  // transverse direction
21  //
22  DirectionType2D pt2d(theP0.x(), theP0.y());
23  //
24  // solution of quadratic equation for s - assume |theP0|=1
25  //
26  RealQuadEquation eq(pt2d.mag2(), 2. * xt2d.dot(pt2d), xt2d.mag2() - R * R);
27  if (!eq.hasSolution)
28  return std::pair<bool, double>(false, 0.);
29  //
30  // choice of solution and verification of direction
31  //
32  return chooseSolution(eq.first, eq.second);
33 }
34 
35 std::pair<bool, double> StraightLineBarrelCylinderCrossing::chooseSolution(const double s1, const double s2) const {
36  //
37  // follows the logic implemented in HelixBarrelCylinderCrossing
38  //
39  if (thePropDir == anyDirection) {
40  return std::pair<bool, double>(true, (fabs(s1) < fabs(s2) ? s1 : s2));
41  } else {
42  int propSign = thePropDir == alongMomentum ? 1 : -1;
43  if (s1 * s2 < 0) {
44  // if different signs return the positive one
45  return std::pair<bool, double>(true, ((s1 * propSign > 0) ? s1 : s2));
46  } else if (s1 * propSign > 0) {
47  // if both positive, return the shortest
48  return std::pair<bool, double>(true, (fabs(s1) < fabs(s2) ? s1 : s2));
49  }
50  }
51  return std::pair<bool, double>(false, 0.);
52 }
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
T y() const
Definition: PV3DBase.h:60
std::pair< bool, double > chooseSolution(const double s1, const double s2) const
Chooses the right solution w.r.t. the propagation direction.
PropagationDirection
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:64
StraightLineBarrelCylinderCrossing(const GlobalPoint &startingPos, const GlobalVector &startingDir, const PropagationDirection propDir)
std::pair< bool, double > pathLength(const Cylinder &cyl) const
T x() const
Definition: PV3DBase.h:59
Basic3DVector unit() const