CMS 3D CMS Logo

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