CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoVertex/GaussianSumVertexFit/src/GsfVertexTrackCompatibilityEstimator.cc

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