File indexing completed on 2024-04-06 12:29:09
0001 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexTrackCompatibilityEstimator.h"
0002 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
0003 #include "RecoVertex/VertexTools/interface/LinearizedTrackStateFactory.h"
0004 #include <algorithm>
0005 using namespace reco;
0006
0007 template <unsigned int N>
0008 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair KalmanVertexTrackCompatibilityEstimator<N>::estimate(
0009 const CachingVertex<N> &vertex, const RefCountedVertexTrack tr, unsigned int hint) const {
0010
0011
0012 const std::vector<RefCountedVertexTrack> &tracks = vertex.tracksRef();
0013
0014 if (tracks.empty())
0015 return estimateNFittedTrack(vertex, tr);
0016
0017 if (hint < tracks.size()) {
0018 VertexTrackEqual<N> d(tr);
0019 if (d(tracks[hint]))
0020 return estimateFittedTrack(vertex, tracks[hint]);
0021 }
0022
0023 typename std::vector<RefCountedVertexTrack>::const_iterator pos =
0024 find_if(tracks.begin(), tracks.end(), VertexTrackEqual<N>(tr));
0025 if (pos != tracks.end()) {
0026 return estimateFittedTrack(vertex, *pos);
0027 } else {
0028 return estimateNFittedTrack(vertex, tr);
0029 }
0030 }
0031
0032 template <unsigned int N>
0033 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair KalmanVertexTrackCompatibilityEstimator<N>::estimate(
0034 const CachingVertex<N> &vertex, const RefCountedLinearizedTrackState track, unsigned int hint) const {
0035 RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(track, vertex.vertexState());
0036 return estimate(vertex, vertexTrack, hint);
0037 }
0038
0039 template <unsigned int N>
0040 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair KalmanVertexTrackCompatibilityEstimator<N>::estimate(
0041 const reco::Vertex &vertex, const reco::TransientTrack &track) const {
0042
0043 GlobalPoint linP(Basic3DVector<float>(vertex.position()));
0044
0045 LinearizedTrackStateFactory lTrackFactory;
0046 RefCountedLinearizedTrackState linTrack = lTrackFactory.linearizedTrackState(linP, track);
0047 GlobalError err(vertex.covariance());
0048 VertexState vState(linP, err);
0049 RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(linTrack, vState);
0050
0051 std::vector<RefCountedVertexTrack> initialTracks(1, vertexTrack);
0052 CachingVertex<N> cachingVertex(linP, err, initialTracks, vertex.chi2());
0053
0054
0055 if (find(vertex.tracks_begin(), vertex.tracks_end(), track.trackBaseRef()) != vertex.tracks_end()) {
0056 return estimateFittedTrack(cachingVertex, vertexTrack);
0057 } else {
0058 return estimateNFittedTrack(cachingVertex, vertexTrack);
0059 }
0060 }
0061
0062
0063
0064
0065 template <unsigned int N>
0066 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
0067 KalmanVertexTrackCompatibilityEstimator<N>::estimateFittedTrack(const CachingVertex<N> &v,
0068 const RefCountedVertexTrack track) const {
0069
0070
0071
0072
0073 RefCountedVertexTrack newSmoothedTrack = trackUpdator.update(v, track);
0074
0075
0076 return BDpair(true, newSmoothedTrack->smoothedChi2());
0077 }
0078
0079
0080
0081 template <unsigned int N>
0082 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
0083 KalmanVertexTrackCompatibilityEstimator<N>::estimateNFittedTrack(const CachingVertex<N> &v,
0084 const RefCountedVertexTrack track) const {
0085
0086
0087 CachingVertex<N> rVert = updator.add(v, track);
0088 if (!rVert.isValid())
0089 return BDpair(false, -1.);
0090 return BDpair(true, rVert.totalChiSquared() - v.totalChiSquared());
0091 }
0092
0093 template <unsigned int N>
0094 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
0095 KalmanVertexTrackCompatibilityEstimator<N>::estimateDifference(const CachingVertex<N> &more,
0096 const CachingVertex<N> &less,
0097 const RefCountedVertexTrack track) const {
0098 BDpair trackRes = helper.trackParameterChi2(track);
0099 return BDpair(trackRes.first, trackRes.second + helper.vertexChi2(less, more));
0100 }
0101
0102 template class KalmanVertexTrackCompatibilityEstimator<5>;