CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StraightLineCylinderCrossing.cc
Go to the documentation of this file.
2 
5 
6 #include <cmath>
7 #include <iostream>
8 using namespace std;
9 
11 StraightLineCylinderCrossing( const LocalPoint& startingPos, const LocalVector& startingDir,
12  const PropagationDirection propDir, double tolerance) :
13  theX0(startingPos),
14  theP0(startingDir.unit()),
15  thePropDir(propDir),
16  theTolerance(tolerance) {}
17 
18 std::pair<bool,double>
20 {
21  //
22  // radius of cylinder and transversal position relative to axis
23  //
24  double R(cylinder.radius());
25  PositionType2D xt2d(theX0.x(),theX0.y());
26  //
27  // transverse direction
28  //
29  DirectionType2D pt2d(theP0.x(),theP0.y());
30  //
31  // solution of quadratic equation for s - assume |theP0|=1
32  //
33  RealQuadEquation eq(pt2d.mag2(),2.*xt2d.dot(pt2d),xt2d.mag2()-R*R);
34  if ( !eq.hasSolution ) {
35  /*
36  double A= pt2d.mag2();
37  double B= 2.*xt2d.dot(pt2d);
38  double C= xt2d.mag2()-R*R;
39  cout << "A= " << pt2d.mag2()
40  << " B= " << 2.*xt2d.dot(pt2d)
41  << " C= " << xt2d.mag2()-R*R
42  << " D= " << B*B - 4*A*C
43  << endl;
44  */
45  return std::pair<bool,double>(false,0.);
46  }
47  //
48  // choice of solution and verification of direction
49  //
50  return chooseSolution(eq.first,eq.second);
51 }
52 
53 std::pair<bool,double>
55  const double s2) const
56 {
57  //
58  // follows the logic implemented in HelixBarrelCylinderCrossing
59  //
60  if ( thePropDir==anyDirection ) {
61  return std::pair<bool,double>(true,(fabs(s1)<fabs(s2)?s1:s2));
62  }
63  else {
64  int propSign = thePropDir==alongMomentum ? 1 : -1;
65  if ( s1*s2 < 0) {
66  // if different signs return the positive one
67  return std::pair<bool,double>(true,((s1*propSign>0)?s1:s2));
68  }
69  else if ( s1*propSign>0 ) {
70  // if both positive, return the shortest
71  return std::pair<bool,double>(true,(fabs(s1)<fabs(s2)?s1:s2));
72  }
73  else {
74  // if both negative, check if the smaller (abs value) is smaller then tolerance
75  double shorter = std::min( fabs(s1), fabs(s2));
76  if (shorter < theTolerance) return std::pair<bool,double>(true,0);
77  else return std::pair<bool,double>(false,0.);
78  }
79  }
80 }
const PropagationDirection thePropDir
std::pair< bool, double > pathLength(const Cylinder &cyl) const
T y() const
Definition: PV3DBase.h:62
#define min(a, b)
Definition: mlp_lapack.h:161
PropagationDirection
tuple s2
Definition: indexGen.py:106
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:55
string unit
Definition: csvLumiCalc.py:46
std::pair< bool, double > chooseSolution(const double s1, const double s2) const
Chooses the right solution w.r.t. the propagation direction.
StraightLineCylinderCrossing(const LocalPoint &startingPos, const LocalVector &startingDir, const PropagationDirection propDir=alongMomentum, double tolerance=0)
T x() const
Definition: PV3DBase.h:61