CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/TrackPropagation/RungeKutta/src/PathToPlane2Order.cc

Go to the documentation of this file.
00001 #include "PathToPlane2Order.h"
00002 #include "RKLocalFieldProvider.h"
00003 #include "FrameChanger.h"
00004 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h"
00005 
00006 #include <iostream>
00007 
00008 std::pair<bool,double> 
00009 PathToPlane2Order::operator()( const Plane& plane, 
00010                                const Vector3D& pos,
00011                                const Vector3D& momentum,
00012                                double charge,
00013                                const PropagationDirection propDir)
00014 {
00015   // access to the field in field frame local coordinates
00016     RKLocalFieldProvider::Vector B = theField.inTesla( pos.x(), pos.y(), pos.z());
00017 
00018     // Frame::GlobalVector localZ = Frame::GlobalVector( B.unit()); // local Z along field
00019     // transform field axis to global frame
00020     Frame::GlobalVector localZ = theFieldFrame->toGlobal( Frame::LocalVector( B.unit())); // local Z along field
00021 
00022     Frame::GlobalVector localY = localZ.cross( Frame::GlobalVector( 1,0,0));
00023     if (localY.mag() < 0.1) {
00024         localY = localZ.cross( Frame::GlobalVector(0,1,0)).unit();
00025     }
00026     else {
00027         localY = localY.unit();
00028     }
00029     Frame::GlobalVector localX = localY.cross(localZ);
00030 
00031 
00032     Frame::PositionType fpos( theFieldFrame->toGlobal( Frame::LocalPoint(pos)));
00033     Frame::RotationType frot( localX, localY, localZ);
00034     // frame in which the field is along Z
00035     Frame frame( fpos, frot);
00036     
00037     //    cout << "PathToPlane2Order frame " << frame.position() << endl << frame.rotation() << endl;
00038     
00039     // transform the position and direction to that frame
00040     Frame::LocalPoint localPos = frame.toLocal( fpos); // same as LocalPoint(0,0,0)
00041 
00042     //transform momentum from field frame to new frame via global frame
00043     Frame::GlobalVector gmom( theFieldFrame->toGlobal( Frame::LocalVector(momentum)));
00044     Frame::LocalVector localMom = frame.toLocal( gmom); 
00045 
00046     // transform the plane to the same frame
00047     Plane localPlane =  FrameChanger::transformPlane( plane, frame);
00048 /*
00049      cout << "PathToPlane2Order input plane       " << plane.position() << endl 
00050          << plane.rotation() << endl;
00051      cout << "PathToPlane2Order transformed plane " << localPlane->position() << endl 
00052          << localPlane->rotation() << endl;
00053 */
00054     double k = 2.99792458e-3;
00055     double transverseMomentum = localMom.perp();   // transverse to the field
00056     if (!(transverseMomentum != 0) ) {  // if (!(x!=0)) will trap both 0 and NaN
00057       //LogDebug("PathToPlane2Order_ZeroMomentum") << "Momentum transverse to the field is zero or Nan (" << transverseMomentum << ")\n";
00058         return std::pair<bool,double>(false,0);
00059     }
00060     double curvature = -k * charge * B.mag() / transverseMomentum;
00061 /*
00062      cout << "PathToPlane2Order curvature " << curvature << endl;
00063      cout << "transverseMomentum " << transverseMomentum << endl;
00064      cout << "B.mag() " << B.mag() << endl;
00065      cout << "localZ " << localZ << endl;
00066      cout << "pos      " << pos << endl;
00067      cout << "momentum " << momentum << endl;
00068      cout << "localPos " << localPos << endl;
00069      cout << "localMom " << localMom << endl;
00070 */
00071 /*
00072     cout << "PathToPlane2Order: local pos " << localPos << " mom " << localMom 
00073          << " curvature " << curvature << endl;
00074     cout << "PathToPlane2Order: local plane pos " << localPlane->position() 
00075          << " normal " << localPlane->normalVector() << endl;
00076 */
00077     HelixArbitraryPlaneCrossing crossing( localPos.basicVector(), localMom.basicVector(), 
00078                                           curvature, propDir);
00079     std::pair<bool,double> res = crossing.pathLength(localPlane);
00080 
00081     return res;
00082 }