CMS 3D CMS Logo

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> PathToPlane2Order::operator()(const Plane& plane,
9  const Vector3D& pos,
10  const Vector3D& momentum,
11  double charge,
12  const PropagationDirection propDir) {
13  // access to the field in field frame local coordinates
15 
16  // Frame::GlobalVector localZ = Frame::GlobalVector( B.unit()); // local Z along field
17  // transform field axis to global frame
18  Frame::GlobalVector localZ = theFieldFrame->toGlobal(Frame::LocalVector(B.unit())); // local Z along field
19 
21  if (localY.mag() < 0.1) {
22  localY = localZ.cross(Frame::GlobalVector(0, 1, 0)).unit();
23  } else {
24  localY = localY.unit();
25  }
26  Frame::GlobalVector localX = localY.cross(localZ);
27 
29  Frame::RotationType frot(localX, localY, localZ);
30  // frame in which the field is along Z
31  Frame frame(fpos, frot);
32 
33  // cout << "PathToPlane2Order frame " << frame.position() << endl << frame.rotation() << endl;
34 
35  // transform the position and direction to that frame
36  Frame::LocalPoint localPos = frame.toLocal(fpos); // same as LocalPoint(0,0,0)
37 
38  //transform momentum from field frame to new frame via global frame
40  Frame::LocalVector localMom = frame.toLocal(gmom);
41 
42  // transform the plane to the same frame
43  Plane localPlane = FrameChanger::transformPlane(plane, frame);
44  /*
45  cout << "PathToPlane2Order input plane " << plane.position() << endl
46  << plane.rotation() << endl;
47  cout << "PathToPlane2Order transformed plane " << localPlane->position() << endl
48  << localPlane->rotation() << endl;
49 */
50  double k = 2.99792458e-3;
51  double transverseMomentum = localMom.perp(); // transverse to the field
52  if (!(transverseMomentum != 0)) { // if (!(x!=0)) will trap both 0 and NaN
53  //LogDebug("PathToPlane2Order_ZeroMomentum") << "Momentum transverse to the field is zero or Nan (" << transverseMomentum << ")\n";
54  return std::pair<bool, double>(false, 0);
55  }
56  double curvature = -k * charge * B.mag() / transverseMomentum;
57  /*
58  cout << "PathToPlane2Order curvature " << curvature << endl;
59  cout << "transverseMomentum " << transverseMomentum << endl;
60  cout << "B.mag() " << B.mag() << endl;
61  cout << "localZ " << localZ << endl;
62  cout << "pos " << pos << endl;
63  cout << "momentum " << momentum << endl;
64  cout << "localPos " << localPos << endl;
65  cout << "localMom " << localMom << endl;
66 */
67  /*
68  cout << "PathToPlane2Order: local pos " << localPos << " mom " << localMom
69  << " curvature " << curvature << endl;
70  cout << "PathToPlane2Order: local plane pos " << localPlane->position()
71  << " normal " << localPlane->normalVector() << endl;
72 */
73  HelixArbitraryPlaneCrossing crossing(localPos.basicVector(), localMom.basicVector(), curvature, propDir);
74  std::pair<bool, double> res = crossing.pathLength(localPlane);
75 
76  return res;
77 }
GlobalPoint toGlobal(const LocalPoint &lp) const
T perp() const
Definition: PV3DBase.h:69
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:110
Definition: APVGainStruct.h:7
PropagationDirection
Definition: Plane.h:16
Definition: Electron.h:6
T curvature(T InversePt, const MagneticField &field)
std::pair< bool, double > operator()(const Plane &plane, const Vector3D &position, const Vector3D &momentum, double charge, const PropagationDirection propDir=alongMomentum)
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
static Plane transformPlane(const Plane &plane, const GloballyPositioned< T > &frame)
Definition: FrameChanger.h:14
constexpr uint16_t localX(uint16_t px)
constexpr uint16_t localY(uint16_t py, uint16_t n)
const RKLocalFieldProvider & theField
Vector inTesla(const LocalPoint &lp) const
the argument lp is in the local frame specified in the constructor
const Frame * theFieldFrame