CMS 3D CMS Logo

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