CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
HelixBarrelCylinderCrossing Class Reference

#include <HelixBarrelCylinderCrossing.h>

Public Types

typedef GlobalVector DirectionType
 
typedef Basic2DVector< TmpTypePoint
 
typedef GlobalPoint PositionType
 
enum  Solution { bothSol, bestSol, onlyPos }
 
typedef double TmpType
 
typedef Basic2DVector< TmpTypeVector
 

Public Member Functions

DirectionType direction () const
 
bool hasSolution () const
 
 HelixBarrelCylinderCrossing (const GlobalPoint &startingPos, const GlobalVector &startingDir, double rho, PropagationDirection propDir, const Cylinder &cyl, Solution sol=bothSol)
 
double pathLength () const
 
PositionType position () const
 
PositionType position1 () const
 Method to access separately each solution of the helix-cylinder crossing equations. More...
 
PositionType position2 () const
 Method to access separately each solution of the helix-cylinder crossing equations. More...
 

Private Member Functions

std::pair< Vector, int > chooseSolution (const Point &p1, const Point &p2, const PositionType &startingPos, const DirectionType &startingDir, PropagationDirection propDir)
 

Private Attributes

DirectionType theDir
 
PositionType thePos
 
PositionType thePos1
 
PositionType thePos2
 
double theS
 
bool theSolExists
 

Detailed Description

Calculates the crossing of a helix with a barrel cylinder.

Definition at line 16 of file HelixBarrelCylinderCrossing.h.

Member Typedef Documentation

◆ DirectionType

Definition at line 25 of file HelixBarrelCylinderCrossing.h.

◆ Point

Definition at line 21 of file HelixBarrelCylinderCrossing.h.

◆ PositionType

Definition at line 24 of file HelixBarrelCylinderCrossing.h.

◆ TmpType

Definition at line 20 of file HelixBarrelCylinderCrossing.h.

◆ Vector

Definition at line 22 of file HelixBarrelCylinderCrossing.h.

Member Enumeration Documentation

◆ Solution

Constructor & Destructor Documentation

◆ HelixBarrelCylinderCrossing()

HelixBarrelCylinderCrossing::HelixBarrelCylinderCrossing ( const GlobalPoint startingPos,
const GlobalVector startingDir,
double  rho,
PropagationDirection  propDir,
const Cylinder cyl,
Solution  sol = bothSol 
)

Definition at line 17 of file HelixBarrelCylinderCrossing.cc.

References funct::abs(), alongMomentum, B, bothSol, correctionTermsCaloMet_cff::C, chooseSolution(), l1tSlwPFPuppiJets_cfi::cosPhi, d1, F(), f, RealQuadEquation::first, nano_mu_digi_cff::float, RealQuadEquation::hasSolution, PV3DBase< T, PVType, FrameType >::mag(), Basic2DVector< T >::mag(), onlyPos, SiStripOfflineCRack_cfg::p2, StraightLineCylinderCrossing::pathLength(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::perp2(), DiDispStaMuonMonitor_cfi::pt, dttmaxenums::R, Cylinder::radius(), rho, RealQuadEquation::second, l1tSlwPFPuppiJets_cfi::sinPhi, mkfit::Const::sol, mathSSE::sqrt(), theDir, thePos, thePos1, thePos2, theS, theSolExists, createJobs::tmp, Surface::toGlobal(), GloballyPositioned< T >::toLocal(), PV3DBase< T, PVType, FrameType >::x(), Basic2DVector< T >::x(), PV3DBase< T, PVType, FrameType >::y(), Basic2DVector< T >::y(), and PV3DBase< T, PVType, FrameType >::z().

22  {
23  // assumes the cylinder is centered at 0,0
24  double R = cyl.radius();
25 
26  // protect for zero curvature case
27  const double sraightLineCutoff = 1.e-7;
28  if (fabs(rho) * R < sraightLineCutoff && fabs(rho) * startingPos.perp() < sraightLineCutoff) {
29  // switch to straight line case
30  StraightLineCylinderCrossing slc(cyl.toLocal(startingPos), cyl.toLocal(startingDir), propDir);
31  std::pair<bool, double> pl = slc.pathLength(cyl);
32  if (pl.first) {
33  theSolExists = true;
34  theS = pl.second;
35  thePos = cyl.toGlobal(slc.position(theS));
36  theDir = startingDir;
37  } else
38  theSolExists = false;
39  return; // all needed data members have been set
40  }
41 
42  double R2cyl = R * R;
43  double pt = startingDir.perp();
44  Point center(startingPos.x() - startingDir.y() / (pt * rho), startingPos.y() + startingDir.x() / (pt * rho));
45  double p2 = startingPos.perp2();
46  bool solveForX;
47  double B, C, E, F;
48  if (fabs(center.x()) > fabs(center.y())) {
49  solveForX = false;
50  E = (R2cyl - p2) / (2. * center.x());
51  F = center.y() / center.x();
52  B = 2. * (startingPos.y() - F * startingPos.x() - E * F);
53  C = 2. * E * startingPos.x() + E * E + p2 - R2cyl;
54  } else {
55  solveForX = true;
56  E = (R2cyl - p2) / (2. * center.y());
57  F = center.x() / center.y();
58  B = 2. * (startingPos.x() - F * startingPos.y() - E * F);
59  C = 2. * E * startingPos.y() + E * E + p2 - R2cyl;
60  }
61 
62  RealQuadEquation eq(1 + F * F, B, C);
63  if (!eq.hasSolution) {
64  theSolExists = false;
65  return;
66  }
67 
68  Vector d1, d2;
69  ;
70  if (solveForX) {
71  d1 = Point(eq.first, E - F * eq.first);
72  d2 = Point(eq.second, E - F * eq.second);
73  } else {
74  d1 = Point(E - F * eq.first, eq.first);
75  d2 = Point(E - F * eq.second, eq.second);
76  }
77 
78  Vector theD;
79  int theActualDir;
80 
81  std::tie(theD, theActualDir) = chooseSolution(d1, d2, startingPos, startingDir, propDir);
82  if (!theSolExists)
83  return;
84 
85  float ipabs = 1.f / startingDir.mag();
86  float sinTheta = float(pt) * ipabs;
87  float cosTheta = startingDir.z() * ipabs;
88 
89  // -------
90 
91  auto dMag = theD.mag();
92  float tmp = 0.5f * float(dMag * rho);
93  if (std::abs(tmp) > 1.f)
94  tmp = std::copysign(1.f, tmp);
95  theS = theActualDir * 2.f * std::asin(tmp) / (float(rho) * sinTheta);
96  thePos = GlobalPoint(startingPos.x() + theD.x(), startingPos.y() + theD.y(), startingPos.z() + theS * cosTheta);
97 
98  if (sol == onlyPos)
99  return;
100 
101  if (theS < 0)
102  tmp = -tmp;
103  auto sinPhi = 2.f * tmp * sqrt(1.f - tmp * tmp);
104  auto cosPhi = 1.f - 2.f * tmp * tmp;
105  theDir = DirectionType(startingDir.x() * cosPhi - startingDir.y() * sinPhi,
106  startingDir.x() * sinPhi + startingDir.y() * cosPhi,
107  startingDir.z());
108 
109  if (sol != bothSol)
110  return;
111 
112  //----- BM
113  //double momProj1 = startingDir.x()*d1.x() + startingDir.y()*d1.y();
114  //double momProj2 = startingDir.x()*d2.x() + startingDir.y()*d2.y();
115 
116  int theActualDir1 = propDir == alongMomentum ? 1 : -1;
117  int theActualDir2 = propDir == alongMomentum ? 1 : -1;
118 
119  auto dMag1 = d1.mag();
120  auto tmp1 = 0.5f * dMag1 * float(rho);
121  if (std::abs(tmp1) > 1.f)
122  tmp1 = std::copysign(1.f, tmp1);
123  auto theS1 = theActualDir1 * 2.f * std::asin(tmp1) / (rho * sinTheta);
124  thePos1 = GlobalPoint(startingPos.x() + d1.x(), startingPos.y() + d1.y(), startingPos.z() + theS1 * cosTheta);
125 
126  auto dMag2 = d2.mag();
127  auto tmp2 = 0.5f * dMag2 * float(rho);
128  if (std::abs(tmp2) > 1.f)
129  tmp2 = std::copysign(1.f, tmp2);
130  auto theS2 = theActualDir2 * 2.f * std::asin(tmp2) / (float(rho) * sinTheta);
131  thePos2 = GlobalPoint(startingPos.x() + d2.x(), startingPos.y() + d2.y(), startingPos.z() + theS2 * cosTheta);
132 }
T perp() const
Definition: PV3DBase.h:69
Definition: APVGainStruct.h:7
T z() const
Definition: PV3DBase.h:61
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
LocalPoint toLocal(const GlobalPoint &gp) const
std::pair< Vector, int > chooseSolution(const Point &p1, const Point &p2, const PositionType &startingPos, const DirectionType &startingDir, PropagationDirection propDir)
std::pair< bool, double > pathLength(const Cylinder &cyl) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
T sqrt(T t)
Definition: SSEVec.h:19
T mag() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
constexpr float sol
Definition: Config.h:13
T perp2() const
Definition: PV3DBase.h:68
Structure Point Contains parameters of Gaussian fits to DMRs.
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:64
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
static constexpr float d1
tmp
align.sh
Definition: createJobs.py:716

Member Function Documentation

◆ chooseSolution()

std::pair< HelixBarrelCylinderCrossing::Vector, int > HelixBarrelCylinderCrossing::chooseSolution ( const Point p1,
const Point p2,
const PositionType startingPos,
const DirectionType startingDir,
PropagationDirection  propDir 
)
private

Definition at line 134 of file HelixBarrelCylinderCrossing.cc.

References alongMomentum, anyDirection, d1, Basic2DVector< T >::mag2(), theSolExists, Basic2DVector< T >::x(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and Basic2DVector< T >::y().

Referenced by HelixBarrelCylinderCrossing().

139  {
140  Vector theD;
141  int theActualDir;
142 
143  auto momProj1 = startingDir.x() * d1.x() + startingDir.y() * d1.y();
144  auto momProj2 = startingDir.x() * d2.x() + startingDir.y() * d2.y();
145 
146  if (propDir == anyDirection) {
147  theSolExists = true;
148  if (d1.mag2() < d2.mag2()) {
149  theD = d1;
150  theActualDir = (momProj1 > 0) ? 1 : -1;
151  } else {
152  theD = d2;
153  theActualDir = (momProj2 > 0) ? 1 : -1;
154  }
155  } else {
156  int propSign = propDir == alongMomentum ? 1 : -1;
157  if (momProj1 * momProj2 < 0) {
158  // if different signs return the positive one
159  theSolExists = true;
160  theD = (momProj1 * propSign > 0) ? d1 : d2;
161  theActualDir = propSign;
162  } else if (momProj1 * propSign > 0) {
163  // if both positive, return the shortest
164  theSolExists = true;
165  theD = (d1.mag2() < d2.mag2()) ? d1 : d2;
166  theActualDir = propSign;
167  } else
168  theSolExists = false;
169  }
170 
171  return std::pair<Vector, int>(theD, theActualDir);
172 }
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
static constexpr float d1

◆ direction()

DirectionType HelixBarrelCylinderCrossing::direction ( ) const
inline

Returns the direction along the helix that corresponds to path length "s" from the starting point. As for position, the direction of the crossing with a cylinder (if it exists!) is given by direction( pathLength( cylinder)).

Definition at line 61 of file HelixBarrelCylinderCrossing.h.

References theDir.

Referenced by TIBRing::computeCrossings().

61 { return theDir; }

◆ hasSolution()

bool HelixBarrelCylinderCrossing::hasSolution ( ) const
inline

◆ pathLength()

double HelixBarrelCylinderCrossing::pathLength ( ) const
inline

Propagation status (true if valid) and (signed) path length along the helix from the starting point to the cylinder. The starting point and the cylinder are given in the constructor.

Definition at line 40 of file HelixBarrelCylinderCrossing.h.

References theS.

◆ position()

PositionType HelixBarrelCylinderCrossing::position ( ) const
inline

Returns the position along the helix that corresponds to path length "s" from the starting point. If s is obtained from the pathLength method the position is the destination point, i.e. the position of the crossing with a cylinder (if it exists!) is given by position( pathLength( cylinder)).

Definition at line 48 of file HelixBarrelCylinderCrossing.h.

References thePos.

Referenced by TBLayer::computeCrossings(), and TIBRing::computeCrossings().

48 { return thePos; }

◆ position1()

PositionType HelixBarrelCylinderCrossing::position1 ( ) const
inline

Method to access separately each solution of the helix-cylinder crossing equations.

Definition at line 51 of file HelixBarrelCylinderCrossing.h.

References thePos1.

51 { return thePos1; }

◆ position2()

PositionType HelixBarrelCylinderCrossing::position2 ( ) const
inline

Method to access separately each solution of the helix-cylinder crossing equations.

Definition at line 54 of file HelixBarrelCylinderCrossing.h.

References thePos2.

54 { return thePos2; }

Member Data Documentation

◆ theDir

DirectionType HelixBarrelCylinderCrossing::theDir
private

Definition at line 65 of file HelixBarrelCylinderCrossing.h.

Referenced by direction(), and HelixBarrelCylinderCrossing().

◆ thePos

PositionType HelixBarrelCylinderCrossing::thePos
private

Definition at line 64 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and position().

◆ thePos1

PositionType HelixBarrelCylinderCrossing::thePos1
private

Definition at line 69 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and position1().

◆ thePos2

PositionType HelixBarrelCylinderCrossing::thePos2
private

Definition at line 70 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and position2().

◆ theS

double HelixBarrelCylinderCrossing::theS
private

Definition at line 66 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and pathLength().

◆ theSolExists

bool HelixBarrelCylinderCrossing::theSolExists
private