CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoVertex/GaussianSumVertexFit/src/VertexGaussianStateConversions.cc

Go to the documentation of this file.
00001 #include "RecoVertex/GaussianSumVertexFit/interface/VertexGaussianStateConversions.h"
00002 
00003 #include "RecoVertex/GaussianSumVertexFit/interface/BasicMultiVertexState.h"
00004 #include "TrackingTools/GsfTools/interface/SingleGaussianState.h"
00005 #include "boost/shared_ptr.hpp"
00006 
00007 namespace GaussianStateConversions {
00008 
00009   MultiGaussianState<3> multiGaussianStateFromVertex (const VertexState aState)
00010   {
00011     typedef boost::shared_ptr< SingleGaussianState<3> > SingleStatePtr;
00012     const std::vector<VertexState> components = aState.components();
00013     MultiGaussianState<3>::SingleStateContainer singleStates;
00014     singleStates.reserve(components.size());
00015     for ( std::vector<VertexState>::const_iterator ic=components.begin();
00016           ic!=components.end(); ic ++ ) {
00017       if ( ic->isValid() ) {
00018         GlobalPoint pos(ic->position());
00019         AlgebraicVector3 parameters;
00020         parameters(0) = pos.x(); parameters(1) = pos.y(); parameters(2) = pos.z();
00021         SingleStatePtr sgs(new SingleGaussianState<3>(parameters,
00022                                                          ic->error().matrix_new(),
00023                                                          ic->weightInMixture()));
00024         singleStates.push_back(sgs);
00025       }
00026     }
00027     return MultiGaussianState<3>(singleStates);
00028   }
00029 
00030   VertexState vertexFromMultiGaussianState (const MultiGaussianState<3>& multiState)
00031   {
00032     if ( multiState.components().empty() )  return VertexState();
00033 
00034     const MultiGaussianState<3>::SingleStateContainer& singleStates = 
00035       multiState.components();
00036     std::vector<VertexState> components;
00037     components.reserve(singleStates.size());
00038     for ( MultiGaussianState<3>::SingleStateContainer::const_iterator ic=singleStates.begin();
00039           ic!=singleStates.end(); ic++ ) {
00040       const AlgebraicVector3& par = (**ic).mean();
00041       GlobalPoint position(par(0),par(1),par(2));
00042       const AlgebraicSymMatrix33& cov = (**ic).covariance();
00043       GlobalError error(cov(0,0),cov(1,0),cov(2,0),cov(1,1),cov(2,1),cov(2,2));
00044       components.push_back(VertexState(position,error,(**ic).weight()));
00045     }
00046     return VertexState(new BasicMultiVertexState(components));
00047   }
00048 }
00049