CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoVertex/GaussianSumVertexFit/src/GsfVertexWeightCalculator.cc

Go to the documentation of this file.
00001 #include "RecoVertex/GaussianSumVertexFit/interface/GsfVertexWeightCalculator.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 #include <cfloat>
00005 
00006 double GsfVertexWeightCalculator::calculate(const  VertexState & oldVertex,
00007          const RefCountedLinearizedTrackState track, double cov) const
00008 {
00009   double previousWeight = oldVertex.weightInMixture() * track->weightInMixture();
00010   // Jacobians
00011   const AlgebraicMatrixN3 & a = track->positionJacobian();
00012   const AlgebraicMatrixNM & b = track->momentumJacobian();
00013 
00014   //track information
00015   AlgebraicVectorN trackParameters = track->predictedStateParameters();
00016   AlgebraicSymMatrixNN trackParametersError = track->predictedStateError();
00017   //vertex information
00018   AlgebraicSymMatrix33 oldVertexError  = oldVertex.error().matrix_new();
00019   //Vertex position
00020   GlobalPoint oldVertexPosition = oldVertex.position();
00021   AlgebraicVector3 oldVertexCoord;
00022   oldVertexCoord[0] = oldVertexPosition.x();
00023   oldVertexCoord[1] = oldVertexPosition.y();
00024   oldVertexCoord[2] = oldVertexPosition.z();
00025 
00026   // prior momentum information
00027   AlgebraicVector3 priorMomentum = track->predictedStateMomentumParameters();
00028 
00029   AlgebraicSymMatrix33 priorMomentumCov;
00030   priorMomentumCov(0,0) = 1.0E-9;
00031   priorMomentumCov(1,1) = 1.0E-6;
00032   priorMomentumCov(2,2) = 1.0E-6;
00033   priorMomentumCov *= cov;
00034 
00035   AlgebraicVectorN diff = trackParameters - track->constantTerm() -
00036     a*oldVertexCoord -b*priorMomentum;
00037   track->checkParameters(diff);
00038   AlgebraicSymMatrixNN sigmaM = trackParametersError +
00039         ROOT::Math::Similarity(a,oldVertexError) +
00040         ROOT::Math::Similarity(b,priorMomentumCov);
00041 
00042   double sigmaDet;
00043   sigmaM.Det(sigmaDet);
00044   int  ifail = ! sigmaM.Invert(); 
00045   if(ifail != 0) {
00046     edm::LogWarning("GsfVertexWeightCalculator") << "S matrix inversion failed";
00047     return -1.;
00048   }
00049   
00050         
00051   double chi = ROOT::Math::Similarity(diff,sigmaM);;  //SigmaM is now inverted !!!
00052   double weight = pow(2. * M_PI, -0.5 * 5) * sqrt(1./sigmaDet) * exp(-0.5 * chi);
00053 
00054   if (std::isnan(weight) || sigmaDet<=0.) {
00055     edm::LogWarning("GsfVertexWeightCalculator") << "Weight is NaN";
00056     return -1.;
00057   }
00058 
00059   return weight*previousWeight;
00060 
00061 }