Go to the documentation of this file.00001 #include "TrackingTools/GeomPropagators/interface/StraightLineCylinderCrossing.h"
00002
00003 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
00004 #include "TrackingTools/GeomPropagators/src/RealQuadEquation.h"
00005
00006 #include <cmath>
00007 #include <iostream>
00008 using namespace std;
00009
00010 StraightLineCylinderCrossing::
00011 StraightLineCylinderCrossing( const LocalPoint& startingPos, const LocalVector& startingDir,
00012 const PropagationDirection propDir, double tolerance) :
00013 theX0(startingPos),
00014 theP0(startingDir.unit()),
00015 thePropDir(propDir),
00016 theTolerance(tolerance) {}
00017
00018 std::pair<bool,double>
00019 StraightLineCylinderCrossing::pathLength (const Cylinder& cylinder) const
00020 {
00021
00022
00023
00024 double R(cylinder.radius());
00025 PositionType2D xt2d(theX0.x(),theX0.y());
00026
00027
00028
00029 DirectionType2D pt2d(theP0.x(),theP0.y());
00030
00031
00032
00033 RealQuadEquation eq(pt2d.mag2(),2.*xt2d.dot(pt2d),xt2d.mag2()-R*R);
00034 if ( !eq.hasSolution ) {
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 return std::pair<bool,double>(false,0.);
00046 }
00047
00048
00049
00050 return chooseSolution(eq.first,eq.second);
00051 }
00052
00053 std::pair<bool,double>
00054 StraightLineCylinderCrossing::chooseSolution (const double s1,
00055 const double s2) const
00056 {
00057
00058
00059
00060 if ( thePropDir==anyDirection ) {
00061 return std::pair<bool,double>(true,(fabs(s1)<fabs(s2)?s1:s2));
00062 }
00063 else {
00064 int propSign = thePropDir==alongMomentum ? 1 : -1;
00065 if ( s1*s2 < 0) {
00066
00067 return std::pair<bool,double>(true,((s1*propSign>0)?s1:s2));
00068 }
00069 else if ( s1*propSign>0 ) {
00070
00071 return std::pair<bool,double>(true,(fabs(s1)<fabs(s2)?s1:s2));
00072 }
00073 else {
00074
00075 double shorter = std::min( fabs(s1), fabs(s2));
00076 if (shorter < theTolerance) return std::pair<bool,double>(true,0);
00077 else return std::pair<bool,double>(false,0.);
00078 }
00079 }
00080 }