CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:46:13 2009 for CMSSW by  doxygen 1.5.4