CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/RecoVertex/VertexTools/src/VertexDistanceXY.cc

Go to the documentation of this file.
00001 #include "RecoVertex/VertexTools/interface/VertexDistanceXY.h"
00002 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00003 #include "RecoVertex/VertexPrimitives/interface/VertexState.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include <cfloat>
00006 
00007 
00008 using namespace reco;
00009 
00010 Measurement1D
00011 VertexDistanceXY::signedDistance(const Vertex& vtx1, const Vertex & vtx2,
00012                                          const GlobalVector & momentum) const
00013 {
00014   Measurement1D unsignedDistance = distance(vtx1, vtx2);
00015   Basic3DVector<float> diff = Basic3DVector<float> (vtx2.position()) - 
00016     Basic3DVector<float> (vtx1.position());
00017   if ((momentum.x()*diff.x() + momentum.y()*diff.y()) < 0 )
00018     return Measurement1D(-1.0*unsignedDistance.value(),unsignedDistance.error());
00019   return unsignedDistance;
00020 }
00021 
00022 
00023 
00024 Measurement1D 
00025 VertexDistanceXY::distance(const GlobalPoint & vtx1Position, 
00026                            const GlobalError & vtx1PositionError, 
00027                            const GlobalPoint & vtx2Position, 
00028                            const GlobalError & vtx2PositionError) const
00029 {
00030     AlgebraicSymMatrix33 error = vtx1PositionError.matrix()
00031       + vtx2PositionError.matrix();
00032     GlobalVector diff = vtx1Position - vtx2Position;
00033     AlgebraicVector3 vDiff;
00034     vDiff[0] = diff.x();
00035     vDiff[1] = diff.y();
00036     vDiff[2] = 0.;
00037     
00038     double dist=sqrt(pow(diff.x(),2)+pow(diff.y(),2));
00039     
00040     double err2 =  ROOT::Math::Similarity(error,vDiff);
00041     double err  = 0;
00042     if( dist != 0) err = sqrt(err2)/dist;
00043        
00044     return Measurement1D(dist,err);
00045 }
00046 
00047 
00048 float 
00049 VertexDistanceXY::compatibility(const GlobalPoint & vtx1Position, 
00050                                 const GlobalError & vtx1PositionError, 
00051                                 const GlobalPoint & vtx2Position, 
00052                                 const GlobalError & vtx2PositionError) const
00053 {
00054   // error matrix of residuals
00055   AlgebraicSymMatrix33 err1 = vtx1PositionError.matrix();
00056   AlgebraicSymMatrix33 err2 = vtx2PositionError.matrix();
00057   AlgebraicSymMatrix22 error; 
00058   error[0][0] = err1[0][0] + err2[0][0];
00059   error[0][1] = err1[0][1] + err2[0][1];
00060   error[1][1] = err1[1][1] + err2[1][1];
00061   if (error == theNullMatrix) return FLT_MAX;
00062 
00063   // position residuals
00064   GlobalVector diff = vtx2Position - vtx1Position;
00065   AlgebraicVector2 vDiff;
00066   vDiff[0] = diff.x();
00067   vDiff[1] = diff.y();
00068 
00069   // Invert error matrix of residuals
00070   bool ifail = !error.Invert();
00071   if (ifail) {
00072     throw cms::Exception("VertexDistanceXY::matrix inversion problem");
00073   }
00074 
00075   return ROOT::Math::Similarity(error,vDiff);
00076 }