CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends

ThirdHitPredictionFromCircle Class Reference

#include <ThirdHitPredictionFromCircle.h>

List of all members.

Classes

class  HelixRZ

Public Types

typedef PixelRecoRange< float > Range
typedef Basic2DVector< Scalar > Vector2D
typedef Basic2DVector< float > VectorF2D

Public Member Functions

float angle (float curvature, float radius) const
Range curvature (double transverseIP) const
double curvature (const Vector2D &thirdPoint) const
Range operator() (Range curvature, float radius) const
float phi (float curvature, float radius) const
 ThirdHitPredictionFromCircle (const GlobalPoint &P1, const GlobalPoint &P2, float tolerance)
double transverseIP (const Vector2D &thirdPoint) const

Private Member Functions

Scalar invCenterOnAxis (const Vector2D &thirdPoint) const

Private Attributes

Vector2D axis
Vector2D center
Scalar delta
Scalar delta2
Vector2D p1
float theTolerance

Friends

class HelixRZ

Detailed Description

Definition at line 11 of file ThirdHitPredictionFromCircle.h.


Member Typedef Documentation

Definition at line 15 of file ThirdHitPredictionFromCircle.h.

Definition at line 16 of file ThirdHitPredictionFromCircle.h.

Definition at line 17 of file ThirdHitPredictionFromCircle.h.


Constructor & Destructor Documentation

ThirdHitPredictionFromCircle::ThirdHitPredictionFromCircle ( const GlobalPoint P1,
const GlobalPoint P2,
float  tolerance 
)

Definition at line 24 of file ThirdHitPredictionFromCircle.cc.

References axis, center, delta, delta2, diffTreeTool::diff, p1, p2, mathSSE::sqrt(), PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

  : p1(P1.x(), P1.y()), theTolerance(tolerance)
{
  Vector2D p2(P2.x(), P2.y());
  Vector2D diff = 0.5 * (p2 - p1);
  delta2 = diff.mag2();
  delta = std::sqrt(delta2);
  axis = Vector2D(-diff.y(), diff.x()) / delta;
  center = p1 + diff;
}

Member Function Documentation

float ThirdHitPredictionFromCircle::angle ( float  curvature,
float  radius 
) const

Definition at line 59 of file ThirdHitPredictionFromCircle.cc.

References abs, axis, center, funct::cos(), delta2, alignCSCRings::e, f, Basic2DVector< T >::mag2(), FWPFMaths::sgn(), funct::sin(), funct::sqr(), and unlikely.

Referenced by MatchedHitRZCorrectionFromBending::tibMatchedHitZFixup().

{
  if (unlikely(std::abs(curvature) < float(1.0e-5))) {
    float sin = (center * axis) / radius;
    return sin / clamped_sqrt(1 - sqr(sin));
  } else {
    float radius2 = sqr(1.0f / curvature);
    float orthog = clamped_sqrt(radius2 - delta2);
    Basic2DVector<float> lcenter = Basic2DVector<float>(center) - sgn(curvature) * orthog * Basic2DVector<float>(axis);
 
    float cos = (radius2 + sqr(radius) - lcenter.mag2()) *
                 curvature / (2 * radius);
    return - cos / clamped_sqrt(1.f - sqr(cos));
 }
}
ThirdHitPredictionFromCircle::Range ThirdHitPredictionFromCircle::curvature ( double  transverseIP) const

Definition at line 87 of file ThirdHitPredictionFromCircle.cc.

References abs, axis, center, constexpr, delta, delta2, alignCSCRings::e, FWPFMaths::sgn(), SMALL, funct::sqr(), mathSSE::sqrt(), swap(), tmp, transverseIP(), unlikely, Basic2DVector< T >::x(), and Basic2DVector< T >::y().

Referenced by ThirdHitPredictionFromCircle::HelixRZ::rAtZ(), and ThirdHitPredictionFromCircle::HelixRZ::zAtR().

{
  // this is a mess.  Use a CAS and lots of drawings to verify...

  transverseIP = std::abs(transverseIP);
  double transverseIP2 = sqr(transverseIP);
  double tip = axis * center;
  double tip2 = sqr(tip);
  double lip = axis.x() * center.y() - axis.y() * center.x();
  double lip2 = sqr(lip);

  double origin = std::sqrt(tip2 + lip2);
  double tmp1 = lip2 + tip2 - transverseIP2;
  double tmp2 = 2. * (tip - transverseIP) * (tip + transverseIP);
  double tmp3 = 2. * delta * origin;
  double tmp4 = tmp1 + delta2;
  double tmp5 = 2. * delta * lip;

  // I am probably being overly careful here with border cases
  // but you never know what crap you might get fed
  // VI fixed for finiteMath

  double u1=0, u2=0;
  constexpr double SMALL = 1.0e-23;
  constexpr double LARGE = 1.0e23;

  if (unlikely(tmp4 - tmp5 < 1.0e-15)) {
    u1 = -SMALL;
    u2 = +SMALL;
  } else {
    if (unlikely(std::abs(tmp2) < 1.0e-15)) {
      // the denominator is zero
      // this means that one of the tracks will be straight
      // and the other can be computed from the limit of the equation
      double tmp = lip2 - delta2;
      u1 = LARGE;
      u2 = (sqr(0.5 * tmp) - delta2 * tip2) / (tmp * tip);
      if (tip < 0)
        std::swap(u1, u2);
    } else {
      double tmp6 = (tmp4 - tmp5) * (tmp4 + tmp5);
      if (unlikely(tmp6 < 1.0e-15)) {
        u1 = -SMALL;
        u2 = +SMALL;
      } else {
        double tmp7 = tmp6 > 0 ? (transverseIP * std::sqrt(tmp6) / tmp2) : 0.;
        double tmp8 = tip * (tmp1 - delta2) / tmp2;
        // the two quadratic solutions
        u1 = tmp8 + tmp7;
        u2 = tmp8 - tmp7;
      }
    }

    if (tmp4 <= std::abs(tmp3)) {
      if ((tmp3 < 0) == (tip < 0))
        u2 = +SMALL;
      else
        u1 = -SMALL;
    }
  }

  return Range(sgn(u1) / std::sqrt(sqr(u1) + delta2),
               sgn(u2) / std::sqrt(sqr(u2) + delta2));
}
double ThirdHitPredictionFromCircle::curvature ( const Vector2D thirdPoint) const

Definition at line 163 of file ThirdHitPredictionFromCircle.cc.

References delta2, invCenterOnAxis(), FWPFMaths::sgn(), funct::sqr(), and mathSSE::sqrt().

{
  double invDist = invCenterOnAxis(p2);
  double invDist2 = sqr(invDist);
  double curv = std::sqrt(invDist2 / (1. + invDist2 * delta2));
  return sgn(invDist) * curv;
}
ThirdHitPredictionFromCircle::Scalar ThirdHitPredictionFromCircle::invCenterOnAxis ( const Vector2D thirdPoint) const [private]

Definition at line 153 of file ThirdHitPredictionFromCircle.cc.

References a, axis, b, center, diffTreeTool::diff, Basic2DVector< T >::mag(), p1, Basic2DVector< T >::x(), and Basic2DVector< T >::y().

Referenced by curvature(), and transverseIP().

{
  Vector2D del = p2 - p1;
  Vector2D axis2 = Vector2D(-del.y(), del.x()) / del.mag();
  Vector2D diff = p1 + 0.5f * del - center;
  Scalar a = diff.y() * axis2.x() - diff.x() * axis2.y();
  Scalar b = axis.y() * axis2.x() - axis.x() * axis2.y();
  return b / a;
}
ThirdHitPredictionFromCircle::Range ThirdHitPredictionFromCircle::operator() ( Range  curvature,
float  radius 
) const

Definition at line 76 of file ThirdHitPredictionFromCircle.cc.

References M_PI, phi(), theTolerance, and unlikely.

{
  float phi1 = phi(curvature.second, radius);
  float phi2 = phi(curvature.first, radius);

  while(unlikely(phi2 <  phi1)) phi2 += float(2. * M_PI); 

  return Range(phi1 * radius - theTolerance, phi2 * radius + theTolerance);
}
float ThirdHitPredictionFromCircle::phi ( float  curvature,
float  radius 
) const

Definition at line 36 of file ThirdHitPredictionFromCircle.cc.

References abs, axis, Basic2DVector< T >::barePhi(), center, funct::cos(), delta2, alignCSCRings::e, f, M_PI, Basic2DVector< T >::mag2(), Basic2DVector< T >::phi(), CosmicsPD_Skims::radius, FWPFMaths::sgn(), funct::sqr(), mathSSE::sqrt(), and unlikely.

Referenced by operator()(), and ThirdHitPredictionFromCircle::HelixRZ::rAtZ().

{
  float phi;
  if (unlikely(std::abs(curvature) < float(1.0e-5))) {
    float cos = (center * axis) / radius;
    phi = axis.phi() - clamped_acos(cos);
  } else {
    float sign = sgn(curvature);
    float radius2 = sqr(1.0f / curvature);
    float orthog = clamped_sqrt(radius2 - delta2);
    Basic2DVector<float> lcenter = Basic2DVector<float>(center) - sign * orthog *  Basic2DVector<float>(axis);
    float rc2 = lcenter.mag2();
    float cos = (rc2 + sqr(radius) - radius2) /
      (2.f *std:: sqrt(rc2) * radius);
    phi = lcenter.barePhi() + sign * clamped_acos(cos);
 }

  while(unlikely(phi >= float(M_PI))) phi -= float(2. * M_PI);
  while(unlikely(phi < -float(M_PI))) phi += float(2. * M_PI);

  return phi;
}
double ThirdHitPredictionFromCircle::transverseIP ( const Vector2D thirdPoint) const

Definition at line 171 of file ThirdHitPredictionFromCircle.cc.

References abs, axis, center, delta2, alignCSCRings::e, invCenterOnAxis(), mag(), CosmicsPD_Skims::radius, funct::sqr(), mathSSE::sqrt(), and unlikely.

Referenced by curvature().

{
  double invDist = invCenterOnAxis(p2);
  if (unlikely(std::abs(invDist) < 1.0e-5))
    return std::abs(p2 * axis);
  else {
    double dist = 1.0 / invDist;
    double radius = std::sqrt(sqr(dist) + delta2);
    return std::abs((center + axis * dist).mag() - radius);
  }
}

Friends And Related Function Documentation

friend class HelixRZ [friend]

Definition at line 57 of file ThirdHitPredictionFromCircle.h.


Member Data Documentation

Definition at line 61 of file ThirdHitPredictionFromCircle.h.

Referenced by invCenterOnAxis(), and ThirdHitPredictionFromCircle().

Definition at line 63 of file ThirdHitPredictionFromCircle.h.

Referenced by operator()().