CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/TkSeedGenerator/src/FastHelix.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkSeedGenerator/interface/FastHelix.h"
00002 #include "RecoTracker/TkSeedGenerator/interface/FastLine.h"
00003 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
00004 #include "TrackingTools/TrajectoryParametrization/interface/CurvilinearTrajectoryError.h"
00005 #include "TrackingTools/TrajectoryParametrization/interface/CartesianTrajectoryError.h"
00006 
00007 FreeTrajectoryState FastHelix::stateAtVertex() const {
00008   
00009   if(isValid() && (fabs(tesla0.z()) > 1e-3))
00010     return helixStateAtVertex();
00011   else 
00012     return straightLineStateAtVertex();
00013     
00014 }
00015 
00016 FreeTrajectoryState FastHelix::helixStateAtVertex() const {
00017   
00018   GlobalPoint pMid(theMiddleHit);
00019   GlobalPoint v(theVertex);
00020   
00021   double dydx = 0., dxdy = 0.;
00022   double pt = 0., px = 0., py = 0.;
00023   
00024   //remember (radius rho in cm):
00025   //rho = 
00026   //100. * pt * 
00027   //(10./(3.*MagneticField::inTesla(GlobalPoint(0., 0., 0.)).z()));
00028   
00029   double rho = theCircle.rho();
00030   // pt = 0.01 * rho * (0.3*MagneticField::inTesla(GlobalPoint(0.,0.,0.)).z());
00031   pt = 0.01 * rho * (0.3*tesla0.z());
00032   //  pt = 0.01 * rho * (0.3*GlobalPoint(0.,0.,0.).MagneticField().z());
00033 
00034   // (py/px)|x=v.x() = (dy/dx)|x=v.x()
00035   //remember:
00036   //y(x) = +-sqrt(rho^2 - (x-x0)^2) + y0 
00037   //y(x) =  sqrt(rho^2 - (x-x0)^2) + y0  if y(x) >= y0 
00038   //y(x) = -sqrt(rho^2 - (x-x0)^2) + y0  if y(x) < y0
00039   //=> (dy/dx) = -(x-x0)/sqrt(Q)  if y(x) >= y0
00040   //   (dy/dx) =  (x-x0)/sqrt(Q)  if y(x) < y0
00041   //with Q = rho^2 - (x-x0)^2
00042   // Check approximate slope to determine whether to use dydx or dxdy
00043   // Choose the one that goes to 0 rather than infinity.
00044   double arg1 = rho*rho - (v.x()-theCircle.x0())*(v.x()-theCircle.x0());
00045   double arg2 = rho*rho - (v.y()-theCircle.y0())*(v.y()-theCircle.y0());
00046   if (arg1<0.0 && arg2<0.0) {
00047     if(fabs(theCircle.n2()) > 0.) {
00048       dydx = -theCircle.n1()/theCircle.n2(); //else px = 0
00049       px = pt/sqrt(1. + dydx*dydx);
00050       py = px*dydx;
00051     } else {
00052       px = 0.;
00053       py = pt;
00054     }
00055   } else if ( arg1>arg2 ) {
00056     if( v.y() > theCircle.y0() )
00057       dydx = -(v.x() - theCircle.x0()) / sqrt(arg1);
00058     else
00059       dydx = (v.x() - theCircle.x0()) / sqrt(arg1);
00060     px = pt/sqrt(1. + dydx*dydx);
00061     py = px*dydx;
00062   } else {
00063     if( v.x() > theCircle.x0() )
00064       dxdy = -(v.y() - theCircle.y0()) / sqrt(arg2);
00065     else
00066       dxdy = (v.y() - theCircle.y0()) / sqrt(arg2);
00067     py = pt/sqrt(1. + dxdy*dxdy);
00068     px = py*dxdy;
00069   }
00070   // check sign with scalar product
00071   if(px*(pMid.x() - v.x()) + py*(pMid.y() - v.y()) < 0.) {
00072     px *= -1.;
00073     py *= -1.;
00074   } 
00075 
00076   //calculate z0, pz
00077   //(z, R*phi) linear relation in a helix
00078   //with R, phi defined as radius and angle w.r.t. centre of circle
00079   //in transverse plane
00080   //pz = pT*(dz/d(R*phi)))
00081   
00082   FastLine flfit(theOuterHit, theMiddleHit, theCircle.rho());
00083   double dzdrphi = -flfit.n1()/flfit.n2();
00084   double pz = pt*dzdrphi;
00085   //get sign of particle
00086 
00087   GlobalVector magvtx=pSetup->inTesla(v);
00088   TrackCharge q = 
00089     ((theCircle.x0()*py - theCircle.y0()*px) / 
00090      (magvtx.z()) < 0.) ? 
00091     -1 : 1;
00092   ROOT::Math::SMatrixIdentity id;
00093   AlgebraicSymMatrix55 C(id);
00094   //MP
00095 
00096   if ( useBasisVertex ) {
00097     return FTS(GlobalTrajectoryParameters(basisVertex, 
00098                                                   GlobalVector(px, py, pz),
00099                                                   q, 
00100                                                   &(*pSetup)), 
00101                        CurvilinearTrajectoryError(C));
00102   } else {
00103     double z_0 = -flfit.c()/flfit.n2();
00104     return FTS(GlobalTrajectoryParameters(GlobalPoint(v.x(),v.y(),z_0), 
00105                                                   GlobalVector(px, py, pz),
00106                                                   q, 
00107                                                   &(*pSetup)), 
00108                        CurvilinearTrajectoryError(C));
00109   }
00110   
00111 }
00112 
00113 FreeTrajectoryState FastHelix::straightLineStateAtVertex() const {
00114 
00115   //calculate FTS assuming straight line...
00116 
00117   GlobalPoint pMid(theMiddleHit);
00118   GlobalPoint v(theVertex);
00119 
00120   double dydx = 0.;
00121   double pt = 0., px = 0., py = 0.;
00122   
00123   if(fabs(theCircle.n1()) > 0. || fabs(theCircle.n2()) > 0.)
00124     pt = 1.e+4;// 10 TeV //else no pt
00125   if(fabs(theCircle.n2()) > 0.) {
00126     dydx = -theCircle.n1()/theCircle.n2(); //else px = 0 
00127   }
00128   px = pt/sqrt(1. + dydx*dydx);
00129   py = px*dydx;
00130   // check sign with scalar product
00131   if (px*(pMid.x() - v.x()) + py*(pMid.y() - v.y()) < 0.) {
00132     px *= -1.;
00133     py *= -1.;
00134   } 
00135 
00136   //calculate z_0 and pz at vertex using weighted mean
00137   //z = z(r) = z0 + (dz/dr)*r
00138   //tan(theta) = dr/dz = (dz/dr)^-1
00139   //theta = atan(1./dzdr)
00140   //p = pt/sin(theta)
00141   //pz = p*cos(theta) = pt/tan(theta) 
00142 
00143   FastLine flfit(theOuterHit, theMiddleHit);
00144   double dzdr = -flfit.n1()/flfit.n2();
00145   double pz = pt*dzdr; 
00146   
00147   TrackCharge q = 1;
00148   AlgebraicSymMatrix66 C = AlgebraicMatrixID();
00149   //MP
00150 
00151   if ( useBasisVertex ) {
00152     return FTS(GlobalTrajectoryParameters(basisVertex, 
00153                                                   GlobalVector(px, py, pz),
00154                                                   q, 
00155                                                   &(*pSetup)), 
00156                        CartesianTrajectoryError(C));
00157   } else {
00158   double z_0 = -flfit.c()/flfit.n2();
00159   return FTS(GlobalTrajectoryParameters(GlobalPoint(v.x(), v.y(), z_0),
00160                                                 GlobalVector(px, py, pz),
00161                                                 q,
00162                                                 &(*pSetup)),
00163                      CartesianTrajectoryError());
00164   }
00165 }