CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/RecoPixelVertexing/PixelTrackFitting/src/RZLine.cc

Go to the documentation of this file.
00001 #include "RZLine.h"
00002 #include "CommonTools/Statistics/interface/LinearFit.h"
00003 
00004 using namespace std;
00005 template <class T> inline T sqr( T t) {return t*t;}
00006 
00007 RZLine::RZLine(const std::vector<float> & aR, 
00008                const std::vector<float> & aZ, 
00009                const std::vector<float> & aErrZ) :
00010   storage(3*aR.size()) {
00011   nPoints = aR.size();
00012   r = &storage.front();
00013   z = r+nPoints;
00014   errZ2 = z+nPoints;
00015   for (int i=0; i<nPoints; i++) {
00016     r[i] = aR[i];
00017     z[i]=aZ[i];
00018     errZ2[i] = aErrZ[i]*aErrZ[i];
00019   } 
00020 }
00021 
00022 RZLine::RZLine(const vector<GlobalPoint> & points, 
00023                const vector<GlobalError> & errors, 
00024                const vector<bool> isBarrel) : 
00025   storage(3*points.size()) {
00026   nPoints = points.size();
00027   r = &storage.front();
00028   z = r+nPoints;
00029   errZ2 = z+nPoints;
00030   for (int i=0; i!=nPoints; ++i) {
00031     const GlobalPoint & p = points[i];
00032     r[i] = p.perp();
00033     z[i] = p.z();
00034   }
00035 
00036   float simpleCot2 = ( z[nPoints-1]-z[0] )/ (r[nPoints-1] - r[0] );
00037   simpleCot2 *= simpleCot2;
00038   for (int i=0; i!=nPoints; ++i) {
00039     errZ2[i] = (isBarrel[i]) ? errors[i].czz() :  
00040       errors[i].rerr(points[i])  * simpleCot2;
00041   }
00042 }
00043 
00044 void RZLine::fit(float & cotTheta, float & intercept, 
00045     float &covss, float &covii, float &covsi) const
00046 {
00047   linearFit( r, z, nPoints, errZ2, cotTheta, intercept, covss, covii, covsi);
00048 }
00049 
00050 float RZLine::chi2(float cotTheta, float intercept) const
00051 {
00052   float chi2 = 0.f;
00053   for (int i=0; i!=nPoints; ++i) chi2 += sqr( ((z[i]-intercept) - cotTheta*r[i]) ) / errZ2[i];
00054   return chi2;
00055 }