CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoVertex/KalmanVertexFit/src/KalmanVertexTrackUpdator.cc

Go to the documentation of this file.
00001 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexTrackUpdator.h"
00002 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00003 //#include "Utilities/GenUtil/interface/ReferenceCountingPointer.h"
00004 #include "RecoVertex/VertexPrimitives/interface/VertexTrack.h"
00005 #include "RecoVertex/VertexPrimitives/interface/CachingVertex.h"
00006 #include "RecoVertex/VertexPrimitives/interface/VertexException.h"
00007 #include "DataFormats/Math/interface/invertPosDefMatrix.h"
00008 
00009 #include<iostream>
00010 
00011 
00012 template <unsigned int N>
00013 typename CachingVertex<N>::RefCountedVertexTrack
00014 KalmanVertexTrackUpdator<N>::update
00015         (const CachingVertex<N> & vertex , RefCountedVertexTrack track) const
00016 
00017 {
00018   trackMatrixPair thePair = 
00019         trackRefit(vertex.vertexState(), track->linearizedTrack(), track->weight() );
00020 
00021   VertexState rVert = updator.positionUpdate (vertex.vertexState(), track->linearizedTrack(),
00022                         track->weight(), -1);
00023 
00024   std::pair<bool, double> result = helper.trackParameterChi2(track->linearizedTrack(), thePair.first);
00025   float smoothedChi2 = helper.vertexChi2(rVert, vertex.vertexState()) + result.second;
00026 
00027   return theVTFactory.vertexTrack(track->linearizedTrack(),
00028         vertex.vertexState(), thePair.first, smoothedChi2, thePair.second,
00029         track->weight());
00030 }
00031 
00032 template <unsigned int N>
00033 typename KalmanVertexTrackUpdator<N>::trackMatrixPair
00034 KalmanVertexTrackUpdator<N>::trackRefit(const VertexState & vertex,
00035          KalmanVertexTrackUpdator<N>::RefCountedLinearizedTrackState linTrackState,
00036          float weight) const
00037 {
00038   typedef ROOT::Math::SVector<double,N> AlgebraicVectorN;
00039   typedef ROOT::Math::SVector<double,N-2> AlgebraicVectorM;
00040   typedef ROOT::Math::SMatrix<double,N,3,ROOT::Math::MatRepStd<double,N,3> > AlgebraicMatrixN3;
00041   typedef ROOT::Math::SMatrix<double,3,N,ROOT::Math::MatRepStd<double,3,N> > AlgebraicMatrix3N;
00042   typedef ROOT::Math::SMatrix<double,3,N-2,ROOT::Math::MatRepStd<double,3,N-2> > AlgebraicMatrix3M;
00043   typedef ROOT::Math::SMatrix<double,N,N-2,ROOT::Math::MatRepStd<double,N,N-2> > AlgebraicMatrixNM;
00044   typedef ROOT::Math::SMatrix<double,N-2,3,ROOT::Math::MatRepStd<double,N-2,3> > AlgebraicMatrixM3;
00045   typedef ROOT::Math::SMatrix<double,N,N,ROOT::Math::MatRepSym<double,N> > AlgebraicSymMatrixNN;
00046 //   typedef ROOT::Math::SMatrix<double,N+1,N+1,ROOT::Math::MatRepSym<double,N+1> > AlgebraicSymMatrixOO;
00047   typedef ROOT::Math::SMatrix<double,N+1,N+1,ROOT::Math::MatRepStd<double,N+1,N+1> > AlgebraicMatrixOO;
00048   typedef ROOT::Math::SMatrix<double,N-2,N-2,ROOT::Math::MatRepSym<double,N-2> > AlgebraicSymMatrixMM;
00049 
00050   //Vertex position 
00051   GlobalPoint vertexPosition = vertex.position();
00052 
00053   AlgebraicVector3 vertexCoord;
00054   vertexCoord(0) = vertexPosition.x();
00055   vertexCoord(1) = vertexPosition.y();
00056   vertexCoord(2) = vertexPosition.z();
00057   const AlgebraicSymMatrix33 vertexErrorMatrix = vertex.error().matrix_new();
00058 
00059 //track information
00060   const AlgebraicMatrixN3 a = linTrackState->positionJacobian();
00061   const AlgebraicMatrixNM b = linTrackState->momentumJacobian();
00062 
00063 //   AlgebraicVectorN trackParameters = 
00064 //      linTrackState->predictedStateParameters();
00065 
00066   int ifail;
00067   AlgebraicSymMatrixNN trackParametersWeight = 
00068         linTrackState->predictedStateWeight(ifail);
00069 
00070   AlgebraicSymMatrixMM s = ROOT::Math::SimilarityT(b,trackParametersWeight);
00071   
00072   if (!invertPosDefMatrix(s)) 
00073       throw VertexException
00074         ("KalmanVertexTrackUpdator::S matrix inversion failed");
00075    
00076   //                                    NN           NM  MM
00077   AlgebraicMatrixNM twbs =  trackParametersWeight *  b * s;
00078 
00079 
00080   AlgebraicVectorN vv = 
00081     linTrackState->predictedStateParameters() - linTrackState->constantTerm() - a*vertexCoord;
00082   //                                   MM                MN                    NN
00083   //  AlgebraicVectorM newTrackMomentumP =  s * (ROOT::Math::Transpose(b)) * trackParametersWeight * vv;
00084   AlgebraicVectorM newTrackMomentumP = ROOT::Math::Transpose(twbs) * vv;
00085 
00086    //AlgebraicMatrix3M refittedPositionMomentumConvariance = 
00087   //        33                        3N                    NN                  NM  MM
00088   //  -vertexErrorMatrix * (ROOT::Math::Transpose(a)) * trackParametersWeight * b * s;
00089 
00090   AlgebraicMatrix3N tmpM1 = -vertexErrorMatrix * (ROOT::Math::Transpose(a));
00091   AlgebraicMatrix3M  refittedPositionMomentumConvariance  = tmpM1 * twbs;
00092 
00093   AlgebraicSymMatrixMM refittedMomentumConvariance = s/weight +  
00094      ROOT::Math::SimilarityT(refittedPositionMomentumConvariance, vertex.weight().matrix_new());
00095 
00096   
00097  // int matrixSize = 3+3; //refittedMomentumConvariance.num_col();
00098   AlgebraicMatrixOO  covMatrix; //(matrixSize, matrixSize);
00099   covMatrix.Place_at(refittedPositionMomentumConvariance, 0, 3);
00100   covMatrix.Place_at(ROOT::Math::Transpose(refittedPositionMomentumConvariance), 3, 0);
00101   covMatrix.Place_at(vertexErrorMatrix, 0, 0);
00102   covMatrix.Place_at(refittedMomentumConvariance, 3 ,3);
00103 
00104   AlgebraicSymMatrixOO covSymMatrix(covMatrix.LowerBlock());
00105 
00106   RefCountedRefittedTrackState refittedTrackState = linTrackState->
00107         createRefittedTrackState(vertexPosition, newTrackMomentumP, covSymMatrix);
00108 
00109   return trackMatrixPair(refittedTrackState, covSymMatrix);
00110 //              (refittedTrackState, refittedPositionMomentumConvariance);
00111 } 
00112 
00113 template class KalmanVertexTrackUpdator<5>;
00114 template class KalmanVertexTrackUpdator<6>;