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