00001 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexTrackCompatibilityEstimator.h"
00002 #include "RecoVertex/VertexPrimitives/interface/ConvertError.h"
00003 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
00004 #include "RecoVertex/VertexTools/interface/LinearizedTrackStateFactory.h"
00005 #include <algorithm>
00006 using namespace reco;
00007
00008
00009 template <unsigned int N>
00010 float KalmanVertexTrackCompatibilityEstimator<N>::estimate(const CachingVertex<N> & vertex,
00011 const RefCountedVertexTrack tr) const
00012 {
00013
00014 vector<RefCountedVertexTrack> tracks = vertex.tracks();
00015 typename 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 float KalmanVertexTrackCompatibilityEstimator<N>::estimate(const CachingVertex<N> & vertex,
00027 const RefCountedLinearizedTrackState track) const
00028 {
00029 RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(track,
00030 vertex.vertexState());
00031 return estimate(vertex, vertexTrack);
00032 }
00033
00034
00035 template <unsigned int N>
00036 float KalmanVertexTrackCompatibilityEstimator<N>::estimate(const reco::Vertex & vertex,
00037 const reco::TransientTrack & track) const
00038 {
00039
00040 GlobalPoint linP(Basic3DVector<float> (vertex.position()));
00041
00042 LinearizedTrackStateFactory lTrackFactory;
00043 RefCountedLinearizedTrackState linTrack =
00044 lTrackFactory.linearizedTrackState(linP, track);
00045 GlobalError err(RecoVertex::convertError(vertex.covariance()));
00046 VertexState vState(linP, err);
00047 RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(linTrack, vState);
00048
00049 vector<RefCountedVertexTrack> initialTracks(1, vertexTrack);
00050 CachingVertex<N> cachingVertex(linP, err, initialTracks,
00051 vertex.chi2());
00052
00053
00054 if (find(vertex.tracks_begin(), vertex.tracks_end(), track.trackBaseRef()) != vertex.tracks_end())
00055 {
00056 return estimateFittedTrack(cachingVertex, vertexTrack);
00057 } else {
00058 return estimateNFittedTrack(cachingVertex, vertexTrack);
00059 }
00060 }
00061
00062
00063
00064
00065
00066
00067 template <unsigned int N>
00068 float KalmanVertexTrackCompatibilityEstimator<N>::estimateFittedTrack
00069 (const CachingVertex<N> & v, const RefCountedVertexTrack track) const
00070 {
00071
00072
00073
00074
00075 RefCountedVertexTrack newSmoothedTrack = trackUpdator.update(v, track);
00076
00077
00078 return newSmoothedTrack->smoothedChi2();
00079 }
00080
00081
00082
00083 template <unsigned int N>
00084 float KalmanVertexTrackCompatibilityEstimator<N>::estimateNFittedTrack
00085 (const CachingVertex<N> & v, const RefCountedVertexTrack track) const
00086 {
00087
00088
00089 CachingVertex<N> rVert = updator.add(v, track);
00090 return (rVert.totalChiSquared()-v.totalChiSquared());
00091 }
00092
00093
00094
00095 template <unsigned int N>
00096 float KalmanVertexTrackCompatibilityEstimator<N>::estimateDifference
00097 (const CachingVertex<N> & more, const CachingVertex<N> & less,
00098 const RefCountedVertexTrack track) const
00099 {
00100 return helper.vertexChi2(less, more) + helper.trackParameterChi2(track);
00101 }
00102
00103 template class KalmanVertexTrackCompatibilityEstimator<5>;