CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoVertex/GhostTrackFitter/src/GhostTrackState.cc

Go to the documentation of this file.
00001 #include <cmath>
00002 
00003 #include <Math/SMatrix.h>
00004 #include <Math/MatrixFunctions.h>
00005 
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 
00008 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00009 #include "DataFormats/GeometryVector/interface/GlobalVector.h" 
00010 
00011 #include "RecoVertex/VertexPrimitives/interface/VertexState.h"
00012 #include "RecoVertex/GhostTrackFitter/interface/GhostTrackPrediction.h"
00013 
00014 #include "RecoVertex/GhostTrackFitter/interface/GhostTrackState.h"
00015 #include "RecoVertex/GhostTrackFitter/interface/TrackGhostTrackState.h"
00016 #include "RecoVertex/GhostTrackFitter/interface/VertexGhostTrackState.h"
00017 
00018 using namespace reco;
00019 
00020 namespace {
00021         using namespace ROOT::Math;
00022 
00023         typedef SVector<double, 3> Vector3;
00024 
00025         static inline Vector3 conv(const GlobalVector &vec)
00026         {
00027                 Vector3 result;
00028                 result[0] = vec.x();
00029                 result[1] = vec.y();
00030                 result[2] = vec.z();
00031                 return result;
00032         }
00033 }
00034 
00035 GhostTrackState::GhostTrackState(const TransientTrack &track) :
00036         Base(new TrackGhostTrackState(track))
00037 {
00038 }
00039 
00040 GhostTrackState::GhostTrackState(const GlobalPoint &pos,
00041                                  const CovarianceMatrix &cov) :
00042         Base(new VertexGhostTrackState(pos, cov))
00043 {
00044 }
00045 
00046 GhostTrackState::GhostTrackState(const GlobalPoint &pos,
00047                                  const GlobalError &error) :
00048         Base(new VertexGhostTrackState(pos, error.matrix_new()))
00049 {
00050 }
00051 
00052 GhostTrackState::GhostTrackState(const VertexState &state) :
00053         Base(new VertexGhostTrackState(state.position(),
00054                                        state.error().matrix_new()))
00055 {
00056 }
00057 
00058 bool GhostTrackState::isTrack() const
00059 {
00060         return dynamic_cast<const TrackGhostTrackState*>(&data()) != 0;
00061 }
00062 
00063 bool GhostTrackState::isVertex() const
00064 {
00065         return dynamic_cast<const VertexGhostTrackState*>(&data()) != 0;
00066 }
00067 
00068 static const TrackGhostTrackState *getTrack(const BasicGhostTrackState *basic)
00069 {
00070         const TrackGhostTrackState *track =
00071                         dynamic_cast<const TrackGhostTrackState*>(basic);
00072         if (!track)
00073                 throw cms::Exception("InvalidOperation")
00074                         << "track requested on non non-track GhostTrackState";
00075         return track;
00076 }
00077 
00078 const TransientTrack &GhostTrackState::track() const
00079 {
00080         return getTrack(&data())->track();
00081 }
00082 
00083 const TrajectoryStateOnSurface &GhostTrackState::tsos() const
00084 {
00085         return getTrack(&data())->tsos();
00086 }
00087 
00088 double GhostTrackState::flightDistance(const GlobalPoint &point,
00089                                        const GlobalVector &dir) const
00090 {
00091         return (globalPosition() - point).dot(dir.unit());
00092 }
00093 
00094 double GhostTrackState::axisDistance(const GlobalPoint &point,
00095                                      const GlobalVector &dir) const
00096 {
00097         return (globalPosition() - point).cross(dir.unit()).mag();
00098 }
00099 
00100 double GhostTrackState::axisDistance(const GhostTrackPrediction &pred) const
00101 {
00102         return axisDistance(pred.origin(), pred.direction());
00103 }
00104 
00105 double GhostTrackState::lambdaError(const GhostTrackPrediction &pred,
00106                                     const GlobalError &pvError) const
00107 {
00108         if (!isValid())
00109                 return -1.;
00110 
00111         return std::sqrt(
00112                 ROOT::Math::Similarity(
00113                         conv(pred.direction()),
00114                         (vertexStateOnGhostTrack(pred).second.matrix_new() +
00115                          pvError.matrix_new()))
00116                 / pred.rho2());
00117 }