CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

Definition at line 27 of file HelixBarrelCylinderCrossing.h.

Definition at line 22 of file HelixBarrelCylinderCrossing.h.

Definition at line 26 of file HelixBarrelCylinderCrossing.h.

Definition at line 21 of file HelixBarrelCylinderCrossing.h.

Definition at line 23 of file HelixBarrelCylinderCrossing.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Definition at line 16 of file HelixBarrelCylinderCrossing.cc.

References funct::abs(), alongMomentum, bothSol, funct::C, chooseSolution(), Vispa.Plugins.EdmBrowser.EdmDataAccessor::eq(), F(), f, RealQuadEquation::first, RealQuadEquation::hasSolution, PV3DBase< T, PVType, FrameType >::mag(), Basic2DVector< T >::mag(), onlyPos, p2, StraightLineCylinderCrossing::pathLength(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::perp2(), EnergyCorrector::pt, dttmaxenums::R, Cylinder::radius(), rho, RealQuadEquation::second, mathSSE::sqrt(), theDir, thePos, thePos1, thePos2, theS, theSolExists, 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().

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

Member Function Documentation

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 143 of file HelixBarrelCylinderCrossing.cc.

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

Referenced by HelixBarrelCylinderCrossing().

147 {
148 
149  Vector theD;
150  int theActualDir;
151 
152  auto momProj1 = startingDir.x()*d1.x() + startingDir.y()*d1.y();
153  auto momProj2 = startingDir.x()*d2.x() + startingDir.y()*d2.y();
154 
155  if ( propDir == anyDirection ) {
156  theSolExists = true;
157  if (d1.mag2()<d2.mag2()) {
158  theD = d1;
159  theActualDir = (momProj1 > 0) ? 1 : -1;
160  }
161  else {
162  theD = d2;
163  theActualDir = (momProj2 > 0) ? 1 : -1;
164  }
165  }
166  else {
167  int propSign = propDir==alongMomentum ? 1 : -1;
168  if (momProj1*momProj2 < 0) {
169  // if different signs return the positive one
170  theSolExists = true;
171  theD = (momProj1*propSign > 0) ? d1 : d2;
172  theActualDir = propSign;
173  }
174  else if (momProj1*propSign > 0) {
175  // if both positive, return the shortest
176  theSolExists = true;
177  theD = (d1.mag2()<d2.mag2()) ? d1 : d2;
178  theActualDir = propSign;
179  }
180  else theSolExists = false;
181  }
182 
183  return std::pair<Vector,int>(theD,theActualDir);
184 }
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
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 62 of file HelixBarrelCylinderCrossing.h.

References theDir.

Referenced by TIBRing::computeCrossings().

62 { return theDir;}
bool HelixBarrelCylinderCrossing::hasSolution ( ) const
inline
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.

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;}
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;}
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

DirectionType HelixBarrelCylinderCrossing::theDir
private

Definition at line 67 of file HelixBarrelCylinderCrossing.h.

Referenced by direction(), and HelixBarrelCylinderCrossing().

PositionType HelixBarrelCylinderCrossing::thePos
private

Definition at line 66 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and position().

PositionType HelixBarrelCylinderCrossing::thePos1
private

Definition at line 72 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and position1().

PositionType HelixBarrelCylinderCrossing::thePos2
private

Definition at line 73 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and position2().

double HelixBarrelCylinderCrossing::theS
private

Definition at line 68 of file HelixBarrelCylinderCrossing.h.

Referenced by HelixBarrelCylinderCrossing(), and pathLength().

bool HelixBarrelCylinderCrossing::theSolExists
private