CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/RecoVertex/VertexPrimitives/src/TransientVertex.cc

Go to the documentation of this file.
00001 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
00002 #include "RecoVertex/VertexPrimitives/interface/VertexException.h"
00003 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
00004 #include <algorithm>
00005 
00006 using namespace std;
00007 using namespace reco;
00008 
00009 TransientVertex::TransientVertex() : theVertexState(), theOriginalTracks(),
00010   theChi2(0), theNDF(0), vertexValid(false), withPrior(false),
00011   theWeightMapIsAvailable(false), theCovMapAvailable(false), 
00012   withRefittedTracks(false)
00013 {}
00014 
00015 
00016 TransientVertex::TransientVertex(const GlobalPoint & pos, const GlobalError & posError,
00017                      const std::vector<TransientTrack> & tracks, float chi2) :
00018     theVertexState(pos, posError), theOriginalTracks(tracks),
00019     theChi2(chi2), theNDF(0), vertexValid(true), withPrior(false),
00020   theWeightMapIsAvailable(false), theCovMapAvailable(false), 
00021   withRefittedTracks(false)
00022 {
00023   theNDF = 2.*theOriginalTracks.size() - 3.;
00024   //  addTracks(tracks);
00025 }
00026 
00027 
00028 TransientVertex::TransientVertex(const GlobalPoint & pos, const GlobalError & posError,
00029                      const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
00030     theVertexState(pos, posError), theOriginalTracks(tracks),
00031     theChi2(chi2), theNDF(ndf), vertexValid(true), withPrior(false),
00032     theWeightMapIsAvailable(false), theCovMapAvailable(false), 
00033     withRefittedTracks(false)
00034 {
00035   //  addTracks(tracks);
00036 }
00037 
00038 
00039 TransientVertex::TransientVertex(const GlobalPoint & priorPos, const GlobalError & priorErr,
00040                      const GlobalPoint & pos, const GlobalError & posError,
00041                      const std::vector<TransientTrack> & tracks, float chi2) :
00042     thePriorVertexState(priorPos, priorErr), theVertexState(pos, posError),
00043     theOriginalTracks(tracks), theChi2(chi2), theNDF(0), vertexValid(true),
00044     withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
00045     withRefittedTracks(false)
00046 {
00047   theNDF = 2.*theOriginalTracks.size();
00048   //  addTracks(tracks);
00049 }
00050 
00051 
00052 TransientVertex::TransientVertex(const GlobalPoint & priorPos, const GlobalError & priorErr,
00053                      const GlobalPoint & pos, const GlobalError & posError,
00054                      const std::vector<TransientTrack> & tracks, float chi2, float ndf) :
00055     thePriorVertexState(priorPos, priorErr), theVertexState(pos, posError),
00056     theOriginalTracks(tracks), theChi2(chi2), theNDF(ndf), vertexValid(true),
00057     withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
00058     withRefittedTracks(false)
00059 {
00060   //  addTracks(tracks);
00061 }
00062 
00063 
00064 TransientVertex::TransientVertex(const VertexState & state, 
00065                      const std::vector<TransientTrack> & tracks, float chi2) : 
00066   theVertexState(state), theOriginalTracks(tracks),
00067   theChi2(chi2), theNDF(0), vertexValid(true), withPrior(false),
00068   theWeightMapIsAvailable(false), theCovMapAvailable(false), 
00069   withRefittedTracks(false)
00070 {
00071   theNDF = 2.*theOriginalTracks.size() - 3.;
00072 }
00073 
00074 
00075 TransientVertex::TransientVertex(const VertexState & state, 
00076                      const std::vector<TransientTrack> & tracks, float chi2, float ndf) : 
00077     theVertexState(state), theOriginalTracks(tracks),
00078     theChi2(chi2), theNDF(ndf), vertexValid(true), withPrior(false),
00079     theWeightMapIsAvailable(false), theCovMapAvailable(false), 
00080     withRefittedTracks(false) 
00081 {
00082   //  addTracks(tracks);
00083 }
00084 
00085 
00086 TransientVertex::TransientVertex(const VertexState & prior, 
00087                                      const VertexState & state, 
00088                                      const std::vector<TransientTrack> & tracks, 
00089                                      float chi2) :
00090     thePriorVertexState(prior), theVertexState(state),
00091     theOriginalTracks(tracks), theChi2(chi2), theNDF(0), vertexValid(true),
00092     withPrior(true), theWeightMapIsAvailable(false), theCovMapAvailable(false),
00093     withRefittedTracks(false)
00094 {
00095   theNDF = 2.*theOriginalTracks.size();
00096   //  addTracks(tracks);
00097 }
00098 
00099 
00100 TransientVertex::TransientVertex(const VertexState & prior, 
00101                      const VertexState & state, 
00102                      const std::vector<TransientTrack> & tracks, 
00103                      float chi2, float ndf) :
00104     thePriorVertexState(prior), theVertexState(state),
00105     theOriginalTracks(tracks), theChi2(chi2), theNDF(ndf), vertexValid(true),
00106     withPrior(true), theWeightMapIsAvailable(false),
00107     theCovMapAvailable(false), withRefittedTracks(false)
00108 {
00109   //  addTracks(tracks);
00110 }
00111 
00112 void TransientVertex::weightMap(const TransientTrackToFloatMap & theMap)
00113 {
00114   theWeightMap = theMap;
00115   theWeightMapIsAvailable = true;
00116 //   removeTracks(); // remove trackrefs from reco::Vertex
00117 //   addTracks( theOriginalTracks );
00118 }
00119 
00120 void TransientVertex::refittedTracks(
00121         const std::vector<reco::TransientTrack> & refittedTracks)
00122 {
00123   if (refittedTracks.empty())
00124     throw VertexException("TransientVertex::refittedTracks: No refitted tracks stored in input container");
00125   theRefittedTracks = refittedTracks;
00126   withRefittedTracks = true;
00127 }
00128 
00129 
00130 void TransientVertex::tkToTkCovariance(const TTtoTTmap covMap)
00131 {
00132   theCovMap = covMap;
00133   theCovMapAvailable = true;
00134 }
00135 
00136 float TransientVertex::trackWeight(const TransientTrack & track) const {
00137   if (!theWeightMapIsAvailable) {
00138     std::vector<TransientTrack>::const_iterator foundTrack = find(theOriginalTracks.begin(), 
00139                 theOriginalTracks.end(), track);
00140     return ((foundTrack != theOriginalTracks.end()) ? 1. : 0.);
00141   }
00142   TransientTrackToFloatMap::const_iterator it = theWeightMap.find(track);
00143   if (it !=  theWeightMap.end()) {
00144     return(it->second);
00145   }
00146   return 0.;
00147 
00148 }
00149 
00150 AlgebraicMatrix33
00151 TransientVertex::tkToTkCovariance(const TransientTrack& t1, const TransientTrack& t2) const
00152 {
00153   if (!theCovMapAvailable) {
00154    throw VertexException("TransientVertex::Track-to-track covariance matrices not available");
00155   }
00156   const TransientTrack* tr1;
00157   const TransientTrack* tr2;
00158   if (t1<t2) {
00159     tr1 = &t1;
00160     tr2 = &t2;
00161   } else {
00162     tr1 = &t2;
00163     tr2 = &t1;
00164   }
00165   TTtoTTmap::const_iterator it = theCovMap.find(*tr1);
00166   if (it !=  theCovMap.end()) {
00167     const TTmap & tm = it->second;
00168     TTmap::const_iterator nit = tm.find(*tr2);
00169     if (nit != tm.end()) {
00170       return( nit->second);
00171     }
00172     else {
00173       throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
00174     }
00175   }
00176   else {
00177     throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
00178   }
00179 }
00180 
00181 
00182 TransientTrack TransientVertex::originalTrack(const TransientTrack & refTrack) const
00183 {
00184   if (theRefittedTracks.empty())
00185         throw VertexException("No refitted tracks stored in vertex");
00186   std::vector<TransientTrack>::const_iterator it =
00187         find(theRefittedTracks.begin(), theRefittedTracks.end(), refTrack);
00188   if (it==theRefittedTracks.end())
00189         throw VertexException("Refitted track not found in list");
00190   size_t pos = it - theRefittedTracks.begin();
00191   return theOriginalTracks[pos];
00192 }
00193 
00194 TransientTrack TransientVertex::refittedTrack(const TransientTrack & track) const
00195 {
00196   if (theRefittedTracks.empty())
00197         throw VertexException("No refitted tracks stored in vertex");
00198   std::vector<TransientTrack>::const_iterator it =
00199         find(theOriginalTracks.begin(), theOriginalTracks.end(), track);
00200   if (it==theOriginalTracks.end())
00201         throw VertexException("Track not found in list");
00202   size_t pos = it - theOriginalTracks.begin();
00203   return theRefittedTracks[pos];
00204 }
00205 
00206 TransientVertex::operator reco::Vertex() const
00207 {
00208    //If the vertex is invalid, return an invalid TV !
00209   if (!isValid()) return Vertex();
00210 
00211   Vertex vertex(Vertex::Point(theVertexState.position()),
00212 //      RecoVertex::convertError(theVertexState.error()), 
00213         theVertexState.error().matrix_new(), 
00214         totalChiSquared(), degreesOfFreedom(), theOriginalTracks.size() );
00215   for (std::vector<TransientTrack>::const_iterator i = theOriginalTracks.begin();
00216        i != theOriginalTracks.end(); ++i) {
00217 //     const TrackTransientTrack* ttt = dynamic_cast<const TrackTransientTrack*>((*i).basicTransientTrack());
00218 //     if ((ttt!=0) && (ttt->persistentTrackRef().isNonnull()))
00219 //     {
00220 //       TrackRef tr = ttt->persistentTrackRef();
00221 //       TrackBaseRef tbr(tr);
00222       if (withRefittedTracks) {
00223         
00224         vertex.add((*i).trackBaseRef(), refittedTrack(*i).track(), trackWeight ( *i ) );
00225       } else { 
00226         vertex.add((*i).trackBaseRef(), trackWeight ( *i ) );
00227       }
00228     //}
00229   }
00230   return vertex;
00231 }