CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PathToPlane2Order.cc
Go to the documentation of this file.
1 #include "PathToPlane2Order.h"
2 #include "RKLocalFieldProvider.h"
3 #include "FrameChanger.h"
5 
6 #include <iostream>
7 
8 std::pair<bool,double>
10  const Vector3D& pos,
11  const Vector3D& momentum,
12  double charge,
13  const PropagationDirection propDir)
14 {
15  // access to the field in field frame local coordinates
16  RKLocalFieldProvider::Vector B = theField.inTesla( pos.x(), pos.y(), pos.z());
17 
18  // Frame::GlobalVector localZ = Frame::GlobalVector( B.unit()); // local Z along field
19  // transform field axis to global frame
20  Frame::GlobalVector localZ = theFieldFrame->toGlobal( Frame::LocalVector( B.unit())); // local Z along field
21 
22  Frame::GlobalVector localY = localZ.cross( Frame::GlobalVector( 1,0,0));
23  if (localY.mag() < 0.1) {
24  localY = localZ.cross( Frame::GlobalVector(0,1,0)).unit();
25  }
26  else {
27  localY = localY.unit();
28  }
29  Frame::GlobalVector localX = localY.cross(localZ);
30 
31 
33  Frame::RotationType frot( localX, localY, localZ);
34  // frame in which the field is along Z
35  Frame frame( fpos, frot);
36 
37  // cout << "PathToPlane2Order frame " << frame.position() << endl << frame.rotation() << endl;
38 
39  // transform the position and direction to that frame
40  Frame::LocalPoint localPos = frame.toLocal( fpos); // same as LocalPoint(0,0,0)
41 
42  //transform momentum from field frame to new frame via global frame
44  Frame::LocalVector localMom = frame.toLocal( gmom);
45 
46  // transform the plane to the same frame
47  Plane localPlane = FrameChanger::transformPlane( plane, frame);
48 /*
49  cout << "PathToPlane2Order input plane " << plane.position() << endl
50  << plane.rotation() << endl;
51  cout << "PathToPlane2Order transformed plane " << localPlane->position() << endl
52  << localPlane->rotation() << endl;
53 */
54  double k = 2.99792458e-3;
55  double transverseMomentum = localMom.perp(); // transverse to the field
56  if (!(transverseMomentum != 0) ) { // if (!(x!=0)) will trap both 0 and NaN
57  //LogDebug("PathToPlane2Order_ZeroMomentum") << "Momentum transverse to the field is zero or Nan (" << transverseMomentum << ")\n";
58  return std::pair<bool,double>(false,0);
59  }
60  double curvature = -k * charge * B.mag() / transverseMomentum;
61 /*
62  cout << "PathToPlane2Order curvature " << curvature << endl;
63  cout << "transverseMomentum " << transverseMomentum << endl;
64  cout << "B.mag() " << B.mag() << endl;
65  cout << "localZ " << localZ << endl;
66  cout << "pos " << pos << endl;
67  cout << "momentum " << momentum << endl;
68  cout << "localPos " << localPos << endl;
69  cout << "localMom " << localMom << endl;
70 */
71 /*
72  cout << "PathToPlane2Order: local pos " << localPos << " mom " << localMom
73  << " curvature " << curvature << endl;
74  cout << "PathToPlane2Order: local plane pos " << localPlane->position()
75  << " normal " << localPlane->normalVector() << endl;
76 */
77  HelixArbitraryPlaneCrossing crossing( localPos.basicVector(), localMom.basicVector(),
78  curvature, propDir);
79  std::pair<bool,double> res = crossing.pathLength(localPlane);
80 
81  return res;
82 }
T y() const
Cartesian y coordinate.
T perp() const
Definition: PV3DBase.h:72
T x() const
Cartesian x coordinate.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Basic3DVector unit() const
PropagationDirection
Definition: Plane.h:17
T mag() const
Definition: PV3DBase.h:67
T curvature(T InversePt, const edm::EventSetup &iSetup)
T z() const
Cartesian z coordinate.
LocalPoint toLocal(const GlobalPoint &gp) const
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:119
std::pair< bool, double > operator()(const Plane &plane, const Vector3D &position, const Vector3D &momentum, double charge, const PropagationDirection propDir=alongMomentum)
int k[5][pyjets_maxn]
GlobalPoint toGlobal(const LocalPoint &lp) const
Vector3DBase unit() const
Definition: Vector3DBase.h:57
static Plane transformPlane(const Plane &plane, const GloballyPositioned< T > &frame)
Definition: FrameChanger.h:15
const RKLocalFieldProvider & theField
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
const Frame * theFieldFrame
Vector inTesla(const LocalPoint &lp) const
the argument lp is in the local frame specified in the constructor