CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoVertex/KalmanVertexFit/src/KalmanVertexTrackCompatibilityEstimator.cc

Go to the documentation of this file.
00001 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexTrackCompatibilityEstimator.h"
00002 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
00003 #include "RecoVertex/VertexTools/interface/LinearizedTrackStateFactory.h"
00004 #include <algorithm>
00005 using namespace reco;
00006 
00007 
00008 template <unsigned int N>
00009 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
00010 KalmanVertexTrackCompatibilityEstimator<N>::estimate(const CachingVertex<N> & vertex,
00011                          const RefCountedVertexTrack tr) const
00012 {
00013 //checking if the track passed really belongs to the vertex
00014   std::vector<RefCountedVertexTrack> tracks = vertex.tracks();
00015   typename std::vector<RefCountedVertexTrack>::iterator pos 
00016     = find_if(tracks.begin(), tracks.end(), VertexTrackEqual<N>(tr));
00017  if(pos != tracks.end()) {
00018    return estimateFittedTrack(vertex,*pos);
00019  } else {
00020    return estimateNFittedTrack(vertex,tr);
00021  }
00022 } 
00023 
00024 
00025 template <unsigned int N>
00026 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
00027 KalmanVertexTrackCompatibilityEstimator<N>::estimate(const CachingVertex<N> & vertex, 
00028                          const RefCountedLinearizedTrackState track) const
00029 {
00030   RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(track,
00031                                                  vertex.vertexState());
00032   return estimate(vertex, vertexTrack);
00033 }
00034 
00035 
00036 template <unsigned int N>
00037 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
00038 KalmanVertexTrackCompatibilityEstimator<N>::estimate(const reco::Vertex & vertex, 
00039                          const reco::TransientTrack & track) const
00040 {       
00041 //   GlobalPoint linP(vertex.position().x(), vertex.position().z(),vertex.position().z());
00042     GlobalPoint linP(Basic3DVector<float> (vertex.position()));
00043 
00044   LinearizedTrackStateFactory lTrackFactory;
00045   RefCountedLinearizedTrackState linTrack = 
00046                         lTrackFactory.linearizedTrackState(linP, track);
00047   GlobalError err(vertex.covariance());
00048   VertexState vState(linP, err);
00049   RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(linTrack, vState);
00050 
00051   std::vector<RefCountedVertexTrack> initialTracks(1, vertexTrack);
00052   CachingVertex<N> cachingVertex(linP, err, initialTracks,
00053                             vertex.chi2());
00054   // FIXME: this should work also for tracks without a persistent ref.
00055 //   return estimateNFittedTrack(cachingVertex, vertexTrack);
00056   if (find(vertex.tracks_begin(), vertex.tracks_end(), track.trackBaseRef()) != vertex.tracks_end())
00057   {
00058     return estimateFittedTrack(cachingVertex, vertexTrack);
00059   } else {
00060     return estimateNFittedTrack(cachingVertex, vertexTrack);
00061   }
00062 }
00063 
00064 
00065 
00066 // methods to calculate track<-->vertex compatibility
00067 // with the track belonging to the vertex
00068 
00069 template <unsigned int N>
00070 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
00071 KalmanVertexTrackCompatibilityEstimator<N>::estimateFittedTrack
00072                 (const CachingVertex<N> & v, const RefCountedVertexTrack track) const
00073 {
00074   //remove track from the vertex using the vertex updator
00075   // Using the update instead of the remove methode, we can specify a weight which
00076   // is different than then one which the vertex track has been defined with.
00077   //CachingVertex rVert = updator.remove(v, track);
00078   RefCountedVertexTrack newSmoothedTrack = trackUpdator.update(v, track);
00079 //   std::cout << newSmoothedTrack->smoothedChi2()<<" "<<estimateDifference(v,rVert,newSmoothedTrack)<<std::endl;
00080 //   return estimateDifference(v,rVert,newSmoothedTrack);
00081   return BDpair(true, newSmoothedTrack->smoothedChi2());
00082 }
00083 
00084 // method calculating track<-->vertex compatibility
00085 //with the track not belonging to vertex
00086 template <unsigned int N>
00087 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
00088 KalmanVertexTrackCompatibilityEstimator<N>::estimateNFittedTrack
00089         (const CachingVertex<N> & v, const RefCountedVertexTrack track) const
00090 {
00091   // Using the update instead of the add methode, we can specify a weight which
00092   // is different than then one which the vertex track has been defined with.
00093   CachingVertex<N> rVert = updator.add(v, track);
00094   if (!rVert.isValid()) return BDpair(false,-1.);
00095   return BDpair(true, rVert.totalChiSquared()-v.totalChiSquared());
00096 }   
00097 
00098 
00099 
00100 template <unsigned int N>
00101 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
00102 KalmanVertexTrackCompatibilityEstimator<N>::estimateDifference
00103         (const CachingVertex<N> & more, const CachingVertex<N> & less, 
00104          const RefCountedVertexTrack track) const
00105 {
00106   BDpair trackRes = helper.trackParameterChi2(track);
00107   return BDpair(trackRes.first, trackRes.second + helper.vertexChi2(less, more)) ;
00108 }
00109 
00110 template class KalmanVertexTrackCompatibilityEstimator<5>;