CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HelixBarrelPlaneCrossing2OrderLocal.cc
Go to the documentation of this file.
2 #include <algorithm>
3 #include <cmath>
4 
7  const GlobalVector& startingDir,
8  double rho, const Plane& plane)
9 {
10  // translate problem to local frame of the plane
11  LocalPoint lPos = plane.toLocal(startingPos);
12  LocalVector lDir = plane.toLocal(startingDir);
13 
14  // check if local frame is already special (local Y axis == global Z axis)
15  LocalVector yPrime = plane.toLocal( GlobalVector(0,0,1.f));
16  LocalVector diff = yPrime - LocalVector(0,-1.f,0);
17  float sinPhi=0, cosPhi=0;
18  bool rotated;
19  Vector2D pos;
20  Vector2D dir;
21 
22  if (diff.mag2() < 1.e-10) {
23 
24  // cout << "Plane already oriented, yPrime = " << yPrime << endl;
25 
26  // we are already in the special orientation
27  pos = Vector2D( lPos.x(), lPos.y());
28  dir = Vector2D( lDir.x(), lDir.y());;
29  rotated = false;
30  }
31  else {
32 
33  // cout << "Plane needs rotation, yPrime = " << yPrime << endl;
34 
35  // we need to rotate the problem
36  sinPhi = yPrime.y();
37  cosPhi = yPrime.x();
38  pos = Vector2D( lPos.x()*cosPhi + lPos.y()*sinPhi,
39  -lPos.x()*sinPhi + lPos.y()*cosPhi);
40  dir = Vector2D( lDir.x()*cosPhi + lDir.y()*sinPhi,
41  -lDir.x()*sinPhi + lDir.y()*cosPhi);
42  rotated = true;
43  }
44 
45  double d = -lPos.z();
46  double x = pos.x() + dir.x()/lDir.z()*d - 0.5*rho*d*d;
47  double y = pos.y() + dir.y()/lDir.z()*d;
48 
49 // cout << "d= " << d << ", pos.x()= " << pos.x()
50 // << ", dir.x()/lDir.z()= " << dir.x()/lDir.z()
51 // << ", 0.5*rho*d*d= " << 0.5*rho*d*d << endl;
52 
53  if (!rotated) {
54  thePos = LocalPoint( x, y, 0);
55  theDir = LocalVector( dir.x()+rho*d, dir.y(), lDir.z());
56  }
57  else {
58  thePos = LocalPoint( x*cosPhi - y*sinPhi,
59  x*sinPhi + y*cosPhi, 0);
60  float px = dir.x()+rho*d;
61  theDir = LocalVector( px*cosPhi - dir.y()*sinPhi,
62  px*sinPhi + dir.y()*cosPhi, lDir.z());
63  }
64 }
65 
Definition: DDAxes.h:10
T y() const
Definition: PV3DBase.h:63
Definition: Plane.h:17
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:64
double f[11][100]
T y() const
Cartesian y coordinate.
dbl *** dir
Definition: mlp_gen.cc:35
Definition: DDAxes.h:10
T x() const
Definition: PV3DBase.h:62
T x() const
Cartesian x coordinate.