Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:29

0001 #include "TrackingTools/GeomPropagators/interface/StraightLineBarrelCylinderCrossing.h"
0002 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
0003 #include "TrackingTools/GeomPropagators/src/RealQuadEquation.h"
0004 
0005 #include <cmath>
0006 
0007 StraightLineBarrelCylinderCrossing::StraightLineBarrelCylinderCrossing(const GlobalPoint& startingPos,
0008                                                                        const GlobalVector& startingDir,
0009                                                                        const PropagationDirection propDir)
0010     : theX0(startingPos), theP0(startingDir.unit()), thePropDir(propDir) {}
0011 
0012 std::pair<bool, double> StraightLineBarrelCylinderCrossing::pathLength(const Cylinder& cylinder) const {
0013   //
0014   // radius of cylinder and transversal position relative to axis
0015   //
0016   double R(cylinder.radius());
0017   GlobalPoint axis(cylinder.toGlobal(Cylinder::LocalPoint(0., 0.)));
0018   PositionType2D xt2d(theX0.x() - axis.x(), theX0.y() - axis.y());
0019   //
0020   // transverse direction
0021   //
0022   DirectionType2D pt2d(theP0.x(), theP0.y());
0023   //
0024   // solution of quadratic equation for s - assume |theP0|=1
0025   //
0026   RealQuadEquation eq(pt2d.mag2(), 2. * xt2d.dot(pt2d), xt2d.mag2() - R * R);
0027   if (!eq.hasSolution)
0028     return std::pair<bool, double>(false, 0.);
0029   //
0030   // choice of solution and verification of direction
0031   //
0032   return chooseSolution(eq.first, eq.second);
0033 }
0034 
0035 std::pair<bool, double> StraightLineBarrelCylinderCrossing::chooseSolution(const double s1, const double s2) const {
0036   //
0037   // follows the logic implemented in HelixBarrelCylinderCrossing
0038   //
0039   if (thePropDir == anyDirection) {
0040     return std::pair<bool, double>(true, (fabs(s1) < fabs(s2) ? s1 : s2));
0041   } else {
0042     int propSign = thePropDir == alongMomentum ? 1 : -1;
0043     if (s1 * s2 < 0) {
0044       // if different signs return the positive one
0045       return std::pair<bool, double>(true, ((s1 * propSign > 0) ? s1 : s2));
0046     } else if (s1 * propSign > 0) {
0047       // if both positive, return the shortest
0048       return std::pair<bool, double>(true, (fabs(s1) < fabs(s2) ? s1 : s2));
0049     }
0050   }
0051   return std::pair<bool, double>(false, 0.);
0052 }