CMS 3D CMS Logo

Public Types | Public Member Functions | Private Types | Private Attributes

KalmanVertexUpdator< N > Class Template Reference

#include <KalmanVertexUpdator.h>

Inheritance diagram for KalmanVertexUpdator< N >:
VertexUpdator< N >

List of all members.

Public Types

typedef VertexTrack< N >
::RefCountedLinearizedTrackState 
RefCountedLinearizedTrackState
typedef CachingVertex< N >
::RefCountedVertexTrack 
RefCountedVertexTrack

Public Member Functions

CachingVertex< N > add (const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track) const
std::pair< bool, double > chi2Increment (const VertexState &oldVertex, const VertexState &newVertexState, const RefCountedLinearizedTrackState linearizedTrack, float weight) const
VertexUpdator< N > * clone () const
VertexState positionUpdate (const VertexState &oldVertex, const RefCountedLinearizedTrackState linearizedTrack, const float weight, int sign) const
CachingVertex< N > remove (const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track) const
CachingVertex< N > update (const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track, float weight, int sign) const

Private Types

typedef ROOT::Math::SMatrix
< double, N-2,
3, ROOT::Math::MatRepStd
< double, N-2, 3 > > 
AlgebraicMatrixM3
typedef ROOT::Math::SMatrix
< double, N,
3, ROOT::Math::MatRepStd
< double, N, 3 > > 
AlgebraicMatrixN3
typedef ROOT::Math::SMatrix
< double, N, N-2,
ROOT::Math::MatRepStd< double,
N, N-2 > > 
AlgebraicMatrixNM
typedef ROOT::Math::SMatrix
< double, N+1, N+1,
ROOT::Math::MatRepStd< double,
N+1, N+1 > > 
AlgebraicMatrixOO
typedef ROOT::Math::SMatrix
< double, N-2, N-2,
ROOT::Math::MatRepSym< double,
N-2 > > 
AlgebraicSymMatrixMM
typedef ROOT::Math::SMatrix
< double, N, N,
ROOT::Math::MatRepSym< double,
N > > 
AlgebraicSymMatrixNN
typedef ROOT::Math::SMatrix
< double, N+1, N+1,
ROOT::Math::MatRepSym< double,
N+1 > > 
AlgebraicSymMatrixOO
typedef ROOT::Math::SVector
< double, N-2 > 
AlgebraicVectorM
typedef ROOT::Math::SVector
< double, N > 
AlgebraicVectorN

Private Attributes

KVFHelper< N > helper

Detailed Description

template<unsigned int N>
class KalmanVertexUpdator< N >

Vertex updator for the Kalman vertex filter. (c.f. R. Fruewirth et.al., Comp.Phys.Comm 96 (1996) 189

Definition at line 13 of file KalmanVertexUpdator.h.


Member Typedef Documentation

template<unsigned int N>
typedef ROOT::Math::SMatrix<double,N-2,3,ROOT::Math::MatRepStd<double,N-2,3> > KalmanVertexUpdator< N >::AlgebraicMatrixM3 [private]

Definition at line 68 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SMatrix<double,N,3,ROOT::Math::MatRepStd<double,N,3> > KalmanVertexUpdator< N >::AlgebraicMatrixN3 [private]

Definition at line 66 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SMatrix<double,N,N-2,ROOT::Math::MatRepStd<double,N,N-2> > KalmanVertexUpdator< N >::AlgebraicMatrixNM [private]

Definition at line 67 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SMatrix<double,N+1,N+1,ROOT::Math::MatRepStd<double,N+1,N+1> > KalmanVertexUpdator< N >::AlgebraicMatrixOO [private]

Definition at line 71 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SMatrix<double,N-2,N-2,ROOT::Math::MatRepSym<double,N-2> > KalmanVertexUpdator< N >::AlgebraicSymMatrixMM [private]

Definition at line 72 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SMatrix<double,N,N,ROOT::Math::MatRepSym<double,N> > KalmanVertexUpdator< N >::AlgebraicSymMatrixNN [private]

Definition at line 69 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SMatrix<double,N+1,N+1,ROOT::Math::MatRepSym<double,N+1> > KalmanVertexUpdator< N >::AlgebraicSymMatrixOO [private]

Definition at line 70 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SVector<double,N-2> KalmanVertexUpdator< N >::AlgebraicVectorM [private]

Definition at line 65 of file KalmanVertexUpdator.h.

template<unsigned int N>
typedef ROOT::Math::SVector<double,N> KalmanVertexUpdator< N >::AlgebraicVectorN [private]

Definition at line 64 of file KalmanVertexUpdator.h.

Definition at line 18 of file KalmanVertexUpdator.h.

Reimplemented from VertexUpdator< N >.

Definition at line 17 of file KalmanVertexUpdator.h.


Member Function Documentation

template<unsigned int N>
CachingVertex< N > KalmanVertexUpdator< N >::add ( const CachingVertex< N > &  oldVertex,
const RefCountedVertexTrack  track 
) const

Method to add a track to an existing CachingVertex An invalid vertex is returned in case of problems during the update.

Definition at line 56 of file KalmanVertexUpdator.cc.

References update, and CommonMethods::weight().

Referenced by GsfVertexUpdator::add().

{
  float weight = track->weight();
  return update(oldVertex,track,weight,+1);
}
template<unsigned int N>
std::pair< bool, double > KalmanVertexUpdator< N >::chi2Increment ( const VertexState oldVertex,
const VertexState newVertexState,
const RefCountedLinearizedTrackState  linearizedTrack,
float  weight 
) const

Definition at line 137 of file KalmanVertexUpdator.cc.

References a, b, error, VertexState::position(), asciidump::s, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by GsfVertexUpdator::createNewComponent().

{
  int error;
  GlobalPoint newVertexPosition = newVertexState.position();

  if (!linearizedTrack->isValid())
    return std::pair <bool, double> ( false, -1. );

  AlgebraicVector3 newVertexPositionV;
  newVertexPositionV(0) = newVertexPosition.x();
  newVertexPositionV(1) = newVertexPosition.y();
  newVertexPositionV(2) = newVertexPosition.z();

  const AlgebraicMatrixN3 & a = linearizedTrack->positionJacobian();
  const AlgebraicMatrixNM & b = linearizedTrack->momentumJacobian();

  AlgebraicVectorN trackParameters = 
        linearizedTrack->predictedStateParameters();

  AlgebraicSymMatrixNN trackParametersWeight = 
        linearizedTrack->predictedStateWeight(error);
  if(error!=0) {
    edm::LogWarning("KalmanVertexUpdator") << "predictedState error matrix inversion failed. An invalid vertex will be returned.";
    return std::pair <bool, double> (false, -1.);
  }

  AlgebraicSymMatrixMM s = ROOT::Math::SimilarityT(b,trackParametersWeight);
  error = ! s.Invert();
  if(error!=0) {
    edm::LogWarning("KalmanVertexUpdator") << "S matrix inversion failed. An invalid vertex will be returned.";
    return std::pair <bool, double> (false, -1.);
  }

  const AlgebraicVectorN & theResidual = linearizedTrack->constantTerm();
  AlgebraicVectorM newTrackMomentumP =  s * ROOT::Math::Transpose(b) * trackParametersWeight *
    (trackParameters - theResidual - a*newVertexPositionV);


//   AlgebraicVectorN rtp = ( theResidual +  a * newVertexPositionV + b * newTrackMomentumP);

  AlgebraicVectorN parameterResiduals = trackParameters -
        ( theResidual +  a * newVertexPositionV + b * newTrackMomentumP);
  linearizedTrack->checkParameters(parameterResiduals);

  double chi2 = weight * ROOT::Math::Similarity(parameterResiduals, trackParametersWeight);

//   chi2 += vertexPositionChi2(oldVertex, newVertexPosition);
  chi2 += helper.vertexChi2(oldVertex, newVertexState);

  return std::pair <bool, double> (true, chi2);
}
template<unsigned int N>
VertexUpdator<N>* KalmanVertexUpdator< N >::clone ( void  ) const [inline, virtual]

Clone method

Implements VertexUpdator< N >.

Definition at line 40 of file KalmanVertexUpdator.h.

   {
    return new KalmanVertexUpdator(* this);
   }
template<unsigned int N>
VertexState KalmanVertexUpdator< N >::positionUpdate ( const VertexState oldVertex,
const RefCountedLinearizedTrackState  linearizedTrack,
const float  weight,
int  sign 
) const

Definition at line 74 of file KalmanVertexUpdator.cc.

References a, b, error, GlobalErrorBase< T, ErrorWeightType >::matrix_new(), asciidump::s, VertexState::weight(), and VertexState::weightTimesPosition().

Referenced by GsfVertexUpdator::createNewComponent(), and GsfVertexSmoother::createNewComponent().

{
  int error;

  if (!linearizedTrack->isValid())
    return VertexState();

  const AlgebraicMatrixN3 & a = linearizedTrack->positionJacobian();
  const AlgebraicMatrixNM & b = linearizedTrack->momentumJacobian();

//   AlgebraicVectorN trackParameters = 
//      linearizedTrack->predictedStateParameters();

  AlgebraicSymMatrixNN trackParametersWeight = 
        linearizedTrack->predictedStateWeight(error);
  if(error != 0) {
    edm::LogWarning("KalmanVertexUpdator") << "predictedState error matrix inversion failed. An invalid vertex will be returned.";
    return VertexState();
  }


  // Jacobians
  //  edm::LogInfo("RecoVertex/KalmanVertexUpdator") 
  //    << "Now updating position" << "\n";

  //vertex information
//   AlgebraicSymMatrix33 oldVertexWeight = oldVertex.weight().matrix_new();
  AlgebraicSymMatrixMM s = ROOT::Math::SimilarityT(b,trackParametersWeight);
  error = ! s.Invert(); 
  if(error != 0) {
    edm::LogWarning("KalmanVertexUpdator") << "S matrix inversion failed. An invalid vertex will be returned.";
    return VertexState();
  }

  AlgebraicSymMatrixNN gB = trackParametersWeight -
       ROOT::Math::Similarity(trackParametersWeight, ROOT::Math::Similarity(b,s));

// Getting the new covariance matrix of the vertex.

  AlgebraicSymMatrix33 newVertexWeight =  oldVertex.weight().matrix_new()
        + weight * sign * ROOT::Math::SimilarityT(a,gB);
  //  edm::LogInfo("RecoVertex/KalmanVertexUpdator") 
  //    << "weight matrix" << newVertexWeight << "\n";


  AlgebraicVector3 newSwr =
                oldVertex.weightTimesPosition() + weight * sign * ROOT::Math::Transpose(a) * gB *
                ( linearizedTrack->predictedStateParameters() - linearizedTrack->constantTerm());
  //  edm::LogInfo("RecoVertex/KalmanVertexUpdator") 
  //    << "weighttimespos" << newSwr << "\n";

  VertexState newpos (newSwr, GlobalWeight(newVertexWeight), 1.0);

  //  edm::LogInfo("RecoVertex/KalmanVertexUpdator") 
  //    << "pos" << newpos.position() << "\n";

  return newpos;
}
template<unsigned int N>
CachingVertex< N > KalmanVertexUpdator< N >::remove ( const CachingVertex< N > &  oldVertex,
const RefCountedVertexTrack  track 
) const

Method removing already used VertexTrack from existing CachingVertex An invalid vertex is returned in case of problems during the update.

Definition at line 64 of file KalmanVertexUpdator.cc.

References update, and CommonMethods::weight().

{
  float weight = track->weight();
  return update(oldVertex,track,weight,-1);
}
template<unsigned int N>
CachingVertex< N > KalmanVertexUpdator< N >::update ( const CachingVertex< N > &  oldVertex,
const RefCountedVertexTrack  track,
float  weight,
int  sign 
) const

The methode which actually does the vertex update. An invalid vertex is returned in case of problems during the update.

Definition at line 12 of file KalmanVertexUpdator.cc.

References abs, gather_cfg::cout, spr::find(), CachingVertex< N >::hasPrior(), VertexState::isValid(), pos, CachingVertex< N >::priorVertexState(), CachingVertex< N >::totalChiSquared(), CachingVertex< N >::tracks(), CachingVertex< N >::vertexState(), and CommonMethods::weight().

{
  if(abs(sign) != 1) throw VertexException
                          ("KalmanVertexUpdator::abs(sign) not equal to 1");

  VertexState newVertexState = positionUpdate(oldVertex.vertexState(), 
                                track->linearizedTrack(), weight, sign);
  if (!newVertexState.isValid()) return CachingVertex<N>();

  float chi1 = oldVertex.totalChiSquared();
  std::pair <bool, double> chi2P = chi2Increment(oldVertex.vertexState(), newVertexState, 
                             track->linearizedTrack() , weight );
  if (!chi2P.first) return CachingVertex<N>(); // return invalid vertex

  chi1 +=sign * chi2P.second;

//adding or removing track from the CachingVertex::VertexTracks
  std::vector<RefCountedVertexTrack> newVertexTracks = oldVertex.tracks();

  if (sign > 0) {
    newVertexTracks.push_back(track);
  }else{

    typename std::vector<RefCountedVertexTrack>::iterator pos 
      = find(newVertexTracks.begin(), newVertexTracks.end(), track);
    if (pos != newVertexTracks.end()) {
      newVertexTracks.erase(pos);
    } else {
      std::cout<<"KalmanVertexUpdator::Unable to find requested track in the current vertex"<<std::endl;
      throw VertexException("KalmanVertexUpdator::Unable to find requested track in the current vertex");
    }
  }

  if  (oldVertex.hasPrior()) {
    return CachingVertex<N>( oldVertex.priorVertexState(),
                          newVertexState, newVertexTracks, chi1);
  } else {
    return CachingVertex<N>(newVertexState, newVertexTracks, chi1);
  }
}

Member Data Documentation

template<unsigned int N>
KVFHelper<N> KalmanVertexUpdator< N >::helper [private]

Definition at line 74 of file KalmanVertexUpdator.h.