Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:12

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   //checking if the track passed really belongs to the vertex
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   //   GlobalPoint linP(vertex.position().x(), vertex.position().z(),vertex.position().z());
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   // FIXME: this should work also for tracks without a persistent ref.
0054   //   return estimateNFittedTrack(cachingVertex, vertexTrack);
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 // methods to calculate track<-->vertex compatibility
0063 // with the track belonging to the vertex
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   //remove track from the vertex using the vertex updator
0070   // Using the update instead of the remove methode, we can specify a weight which
0071   // is different than then one which the vertex track has been defined with.
0072   //CachingVertex rVert = updator.remove(v, track);
0073   RefCountedVertexTrack newSmoothedTrack = trackUpdator.update(v, track);
0074   //   std::cout << newSmoothedTrack->smoothedChi2()<<" "<<estimateDifference(v,rVert,newSmoothedTrack)<<std::endl;
0075   //   return estimateDifference(v,rVert,newSmoothedTrack);
0076   return BDpair(true, newSmoothedTrack->smoothedChi2());
0077 }
0078 
0079 // method calculating track<-->vertex compatibility
0080 //with the track not belonging to vertex
0081 template <unsigned int N>
0082 typename KalmanVertexTrackCompatibilityEstimator<N>::BDpair
0083 KalmanVertexTrackCompatibilityEstimator<N>::estimateNFittedTrack(const CachingVertex<N> &v,
0084                                                                  const RefCountedVertexTrack track) const {
0085   // Using the update instead of the add methode, we can specify a weight which
0086   // is different than then one which the vertex track has been defined with.
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>;