CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoPixelVertexing/PixelTriplets/src/ThirdHitPredictionFromInvParabola.cc

Go to the documentation of this file.
00001 
00002 #include "RecoPixelVertexing/PixelTriplets/interface/ThirdHitPredictionFromInvParabola.h"
00003 
00004 #include <cmath>
00005 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00006 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00007 
00008 #include "RecoTracker/TkHitPairs/interface/OrderedHitPair.h"
00009 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00010 #include "RecoTracker/TkMSParametrization/interface/PixelRecoUtilities.h"
00011 
00012 #include "RecoTracker/TkMSParametrization/interface/PixelRecoRange.h"
00013 
00014 namespace {
00015   template <class T> inline T sqr( T t) {return t*t;}
00016 }
00017 
00018 
00019 typedef Basic2DVector<double> Point2D;
00020 typedef PixelRecoRange<double> Ranged;
00021 
00022 using namespace std;
00023 
00024 ThirdHitPredictionFromInvParabola::ThirdHitPredictionFromInvParabola( 
00025     const GlobalPoint& P1, const GlobalPoint& P2,double ip, double curv, double torlerance)
00026   : theTolerance(torlerance)
00027 {
00028   init(P1,P2,ip,std::abs(curv));
00029 }
00030 
00031 
00032 void ThirdHitPredictionFromInvParabola::
00033     init( const GlobalPoint & P1, const GlobalPoint & P2, double ip, double curv)
00034 {
00035 //  GlobalVector aX = GlobalVector( P2.x()-P1.x(), P2.y()-P1.y(), 0.).unit();
00036  
00037   Point2D p1 = P1.basicVector().xy();
00038   Point2D p2 = P2.basicVector().xy();
00039   theRotation = Rotation(p1);
00040   p1 = transform(p1);  // (1./P1.xy().mag(),0); 
00041   p2 = transform(p2);
00042 
00043  
00044   u1u2 = p1.x()*p2.x();
00045   overDu = 1./(p2.x() - p1.x());
00046   pv = p1.y()*p2.x() - p2.y()*p1.x();
00047   dv = p2.y() - p1.y();
00048   su = p2.x() + p1.x();
00049 
00050   RangeD ipRange(-ip, ip); 
00051   ipRange.sort();
00052   
00053   double ipIntyPlus = ipFromCurvature(0.,1);
00054   double ipCurvPlus = ipFromCurvature(curv, 1);
00055   double ipCurvMinus = ipFromCurvature(curv, -1);
00056 
00057   
00058   RangeD ipRangePlus(ipIntyPlus, ipCurvPlus); ipRangePlus.sort();
00059   RangeD ipRangeMinus(-ipIntyPlus, ipCurvMinus); ipRangeMinus.sort();
00060 
00061   theIpRangePlus  = ipRangePlus.intersection(ipRange);
00062   theIpRangeMinus = ipRangeMinus.intersection(ipRange);
00063 }
00064     
00065 
00066 
00067 ThirdHitPredictionFromInvParabola::Range 
00068 ThirdHitPredictionFromInvParabola::rangeRPhi(double radius, int icharge) const
00069 {
00070   double charge = icharge; // will (icharge>0) ? 1. : -1; be faster?
00071 
00072   RangeD ip = (charge > 0) ? theIpRangePlus : theIpRangeMinus;
00073 
00074 
00075   //  it will vectorize with gcc 4.7 (with -O3 -fno-math-errno)
00076   double ipv[2]={ip.min(),ip.max()};
00077   double u[2], v[2];
00078   for (int i=0; i!=2; ++i)
00079     findPointAtCurve(radius, charge, ipv[i],u[i],v[i]);
00080 
00081  
00082   double phi1 = theRotation.rotateBack(Point2D(u[0],v[0])).barePhi();
00083   double phi2 = phi1+(v[1]-v[0]); 
00084   
00085   if (ip.empty()) {
00086     Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance); 
00087     Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance); 
00088     return r1.intersection(r2);
00089   }
00090 
00091   if (phi2<phi1) std::swap(phi1, phi2); 
00092   return Range(radius*phi1-theTolerance, radius*phi2+theTolerance);
00093   
00094 }
00095 
00096 /*
00097 ThirdHitPredictionFromInvParabola::Range ThirdHitPredictionFromInvParabola::rangeRPhiSlow(
00098     double radius, int charge, int nIter) const
00099 {
00100   Range predRPhi(1.,-1.);
00101 
00102   double invr2 = 1/(radius*radius);
00103   double u = sqrt(invr2);
00104   double v = 0.;
00105 
00106   Range ip = (charge > 0) ? theIpRangePlus : theIpRangeMinus;
00107 
00108   for (int i=0; i < nIter; ++i) {
00109     v = predV(u, ip.min(), charge); 
00110     double d2 = invr2-sqr(v);
00111     u = (d2 > 0) ? sqrt(d2) : 0.;
00112   }
00113   Point2D  pred_tmp1(u, v);
00114   double phi1 = transformBack(pred_tmp1).phi(); 
00115   while ( phi1 >= M_PI) phi1 -= 2*M_PI;
00116   while ( phi1 < -M_PI) phi1 += 2*M_PI;
00117 
00118 
00119   u = sqrt(invr2); 
00120   v=0;
00121   for (int i=0; i < nIter; ++i) {
00122     v = predV(u, ip.max(), charge); 
00123     double d2 = invr2-sqr(v);
00124     u = (d2 > 0) ? sqrt(d2) : 0.;
00125   }
00126   Point2D  pred_tmp2(u, v);
00127   double phi2 = transformBack(pred_tmp2).phi(); 
00128   while ( phi2-phi1 >= M_PI) phi2 -= 2*M_PI;
00129   while ( phi2-phi1 < -M_PI) phi2 += 2*M_PI;
00130 
00131 // check faster alternative, without while(..) it is enough to:
00132 //  phi2 = phi1+radius*(pred_tmp2.v()-pred_tmp1.v()); 
00133 
00134   if (ip.empty()) {
00135     Range r1(phi1*radius-theTolerance, phi1*radius+theTolerance); 
00136     Range r2(phi2*radius-theTolerance, phi2*radius+theTolerance); 
00137     predRPhi = r1.intersection(r2);
00138   } else {
00139     Range r(phi1, phi2); 
00140     r.sort();
00141     predRPhi= Range(radius*r.min()-theTolerance, radius*r.max()+theTolerance);
00142   }
00143   return predRPhi;
00144 
00145 }
00146 */
00147