CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoTracker/TkSeedGenerator/src/FastCircle.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkSeedGenerator/interface/FastCircle.h"
00002 #include "DataFormats/Math/interface/AlgebraicROOTObjects.h"
00003 
00004 FastCircle::FastCircle(const GlobalPoint& outerHit,
00005                        const GlobalPoint& middleHit,
00006                        const GlobalPoint& aVertex) : 
00007   theOuterPoint(outerHit), 
00008   theInnerPoint(middleHit), 
00009   theVertexPoint(aVertex), 
00010   theNorm(128.), 
00011   theX0(0.), 
00012   theY0(0.), 
00013   theRho(0.),
00014   theN1(0.),
00015   theN2(0.),
00016   theC(0.),
00017   theValid(true) {
00018 
00019   createCircleParameters();
00020   
00021 }
00022 
00023 FastCircle::FastCircle(const GlobalPoint& outerHit,
00024                        const GlobalPoint& middleHit,
00025                        const GlobalPoint& aVertex,
00026                        double norm) : 
00027   theOuterPoint(outerHit), 
00028   theInnerPoint(middleHit), 
00029   theVertexPoint(aVertex), 
00030   theNorm(norm), 
00031   theX0(0.), 
00032   theY0(0.), 
00033   theRho(0.),
00034   theN1(0.),
00035   theN2(0.),
00036   theC(0.),
00037   theValid(true) {
00038 
00039   createCircleParameters();
00040   
00041 }
00042 
00043 namespace {
00044   inline
00045   AlgebraicVector3 transform(const GlobalPoint& aPoint, float norm) {
00046     
00047     AlgebraicVector3 riemannPoint;
00048     
00049     auto p = aPoint.basicVector()/norm;
00050     float R2 = p.perp2();
00051     float fact = 1.f/(1.f+R2); // let's factorize the common factor out
00052     riemannPoint[0] = fact*p.x();  
00053     riemannPoint[1] = fact*p.y();  
00054     riemannPoint[2] = fact*R2;
00055     
00056     return riemannPoint;
00057   }
00058 
00059 
00060 }
00061 
00062 void FastCircle::createCircleParameters() {
00063   
00064   AlgebraicVector3 x = transform(theOuterPoint,theNorm);
00065   AlgebraicVector3 y = transform(theInnerPoint,theNorm);
00066   AlgebraicVector3 z = transform(theVertexPoint,theNorm);
00067 
00068   AlgebraicVector3 n;
00069 
00070   n[0] =   x[1]*(y[2] - z[2]) + y[1]*(z[2] - x[2]) + z[1]*(x[2] - y[2]);
00071   n[1] = -(x[0]*(y[2] - z[2]) + y[0]*(z[2] - x[2]) + z[0]*(x[2] - y[2]));
00072   n[2] =   x[0]*(y[1] - z[1]) + y[0]*(z[1] - x[1]) + z[0]*(x[1] - y[1]);
00073 
00074   double mag2 = n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
00075   if (mag2 < 1.e-20) {
00076     theValid = false;
00077     return;
00078   }
00079   n.Unit(); // reduce n to a unit vector
00080   double  c = -(n[0]*x[0] + n[1]*x[1] + n[2]*x[2]);
00081   //  c = -(n[0]*y[0] + n[1]*y[1] + n[2]*y[2]);
00082   //  c = -(n[0]*z[0] + n[1]*z[1] + n[2]*z[2]);
00083   
00084   theN1 = n[0];
00085   theN2 = n[1];
00086   theC = c;
00087 
00088   if(fabs(c + n[2]) < 1.e-5) {
00089     // numeric limit
00090     // circle is more a straight line...
00091     theValid = false;
00092     return;
00093   }
00094 
00095   double x0 = -n[0] / (2.*(c + n[2]));
00096   double y0 = -n[1] / (2.*(c + n[2]));
00097   double rho = 
00098     sqrt((n[0]*n[0] + n[1]*n[1] - 4.*c*(c + n[2]))) / fabs(2.*(c + n[2]));
00099   
00100   theX0 = theNorm*x0;
00101   theY0 = theNorm*y0;
00102   theRho = theNorm*rho;
00103 
00104 }
00105