Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:07

0001 #include "RecoVertex/GaussianSumVertexFit/interface/GsfVertexTrackCompatibilityEstimator.h"
0002 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
0003 #include <algorithm>
0004 using namespace reco;
0005 
0006 // template <unsigned int N>
0007 // struct vT_find
0008 // {
0009 //   typedef typename CachingVertex<N>::RefCountedVertexTrack RefCountedVertexTrack;
0010 //   bool operator()(const CachingVertex<5> & v, const RefCountedVertexTrack t)
0011 //   {
0012 // //initial tracks
0013 //     vector<RefCountedVertexTrack> tracks = v.tracks();
0014 //     vector<RefCountedVertexTrack>::iterator pos
0015 //       = find_if(tracks.begin(), tracks.end(), VertexTrackEqual(t));
0016 //     return (pos != tracks.end());
0017 //   }
0018 // };
0019 
0020 std::pair<bool, double> GsfVertexTrackCompatibilityEstimator::estimate(const CachingVertex<5>& vertex,
0021                                                                        const RefCountedVertexTrack tr,
0022                                                                        unsigned int hint) const {
0023   //checking if the track passed really belongs to the vertex
0024   std::vector<RefCountedVertexTrack> tracks = vertex.tracks();
0025   std::vector<RefCountedVertexTrack>::iterator pos = find_if(tracks.begin(), tracks.end(), VertexTrackEqual<5>(tr));
0026   if (pos != tracks.end()) {
0027     return estimateFittedTrack(vertex, *pos);
0028   } else {
0029     return estimateNFittedTrack(vertex, tr);
0030   }
0031 }
0032 
0033 std::pair<bool, double> GsfVertexTrackCompatibilityEstimator::estimate(const CachingVertex<5>& vertex,
0034                                                                        const RefCountedLinearizedTrackState track,
0035                                                                        unsigned int hint) const {
0036   RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(track, vertex.vertexState());
0037   return estimate(vertex, vertexTrack);
0038 }
0039 
0040 std::pair<bool, double> GsfVertexTrackCompatibilityEstimator::estimate(const reco::Vertex& vertex,
0041                                                                        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   RefCountedLinearizedTrackState linTrack = lTrackFactory.linearizedTrackState(linP, track);
0046   GlobalError err(vertex.covariance());
0047   VertexState vState(linP, err);
0048   RefCountedVertexTrack vertexTrack = vTrackFactory.vertexTrack(linTrack, vState);
0049 
0050   std::vector<RefCountedVertexTrack> initialTracks(1, vertexTrack);
0051   CachingVertex<5> cachingVertex(linP, err, initialTracks, vertex.chi2());
0052   // FIXME: this should work also for tracks without a persistent ref.
0053   //   const TrackTransientTrack* ttt = dynamic_cast<const TrackTransientTrack*>(track.basicTransientTrack());
0054   //   if ((ttt!=0) &&
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 std::pair<bool, double> GsfVertexTrackCompatibilityEstimator::estimateFittedTrack(
0066     const CachingVertex<5>& v, const RefCountedVertexTrack track) const {
0067   //remove track from the vertex using the vertex updator
0068   // Using the update instead of the remove methode, we can specify a weight which
0069   // is different than then one which the vertex track has been defined with.
0070   if (track->refittedStateAvailable())
0071     return BDpair(true, track->smoothedChi2());
0072   throw VertexException("GsfVertexTrackCompatibilityEstimator::vertex has to be smoothed.");
0073 
0074   //   CachingVertex rVert = updator.remove(v, track);
0075   //   RefCountedVertexTrack newSmoothedTrack = trackUpdator.update(v, track);
0076   //   return estimateDifference(v,rVert,newSmoothedTrack);
0077 }
0078 
0079 // method calculating track<-->vertex compatibility
0080 //with the track not belonging to vertex
0081 std::pair<bool, double> GsfVertexTrackCompatibilityEstimator::estimateNFittedTrack(
0082     const CachingVertex<5>& v, const RefCountedVertexTrack track) const {
0083   // Using the update instead of the add methode, we can specify a weight which
0084   // is different than then one which the vertex track has been defined with.
0085   CachingVertex<5> rVert = updator.add(v, track);
0086   if (!rVert.isValid())
0087     return BDpair(false, -1.);
0088   return BDpair(true, rVert.totalChiSquared() - v.totalChiSquared());
0089 }