Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <cmath>
0002 
0003 #include <Math/SMatrix.h>
0004 #include <Math/MatrixFunctions.h>
0005 
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 
0008 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0009 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0010 
0011 #include "RecoVertex/VertexPrimitives/interface/VertexState.h"
0012 #include "RecoVertex/GhostTrackFitter/interface/GhostTrackPrediction.h"
0013 
0014 #include "RecoVertex/GhostTrackFitter/interface/GhostTrackState.h"
0015 #include "RecoVertex/GhostTrackFitter/interface/TrackGhostTrackState.h"
0016 #include "RecoVertex/GhostTrackFitter/interface/VertexGhostTrackState.h"
0017 
0018 using namespace reco;
0019 
0020 namespace {
0021   using namespace ROOT::Math;
0022 
0023   typedef SVector<double, 3> Vector3;
0024 
0025   inline Vector3 conv(const GlobalVector &vec) {
0026     Vector3 result;
0027     result[0] = vec.x();
0028     result[1] = vec.y();
0029     result[2] = vec.z();
0030     return result;
0031   }
0032 }  // namespace
0033 
0034 GhostTrackState::GhostTrackState(const TransientTrack &track) : Base(new TrackGhostTrackState(track)) {}
0035 
0036 GhostTrackState::GhostTrackState(const GlobalPoint &pos, const CovarianceMatrix &cov)
0037     : Base(new VertexGhostTrackState(pos, cov)) {}
0038 
0039 GhostTrackState::GhostTrackState(const GlobalPoint &pos, const GlobalError &error)
0040     : Base(new VertexGhostTrackState(pos, error.matrix())) {}
0041 
0042 GhostTrackState::GhostTrackState(const VertexState &state)
0043     : Base(new VertexGhostTrackState(state.position(), state.error().matrix())) {}
0044 
0045 bool GhostTrackState::isTrack() const { return dynamic_cast<const TrackGhostTrackState *>(&data()) != nullptr; }
0046 
0047 bool GhostTrackState::isVertex() const { return dynamic_cast<const VertexGhostTrackState *>(&data()) != nullptr; }
0048 
0049 static const TrackGhostTrackState *getTrack(const BasicGhostTrackState *basic) {
0050   const TrackGhostTrackState *track = dynamic_cast<const TrackGhostTrackState *>(basic);
0051   if (!track)
0052     throw cms::Exception("InvalidOperation") << "track requested on non non-track GhostTrackState";
0053   return track;
0054 }
0055 
0056 const TransientTrack &GhostTrackState::track() const { return getTrack(&data())->track(); }
0057 
0058 const TrajectoryStateOnSurface &GhostTrackState::tsos() const { return getTrack(&data())->tsos(); }
0059 
0060 double GhostTrackState::flightDistance(const GlobalPoint &point, const GlobalVector &dir) const {
0061   return (globalPosition() - point).dot(dir.unit());
0062 }
0063 
0064 double GhostTrackState::axisDistance(const GlobalPoint &point, const GlobalVector &dir) const {
0065   return (globalPosition() - point).cross(dir.unit()).mag();
0066 }
0067 
0068 double GhostTrackState::axisDistance(const GhostTrackPrediction &pred) const {
0069   return axisDistance(pred.origin(), pred.direction());
0070 }
0071 
0072 double GhostTrackState::lambdaError(const GhostTrackPrediction &pred, const GlobalError &pvError) const {
0073   if (!isValid())
0074     return -1.;
0075 
0076   return std::sqrt(ROOT::Math::Similarity(conv(pred.direction()),
0077                                           (vertexStateOnGhostTrack(pred).second.matrix() + pvError.matrix())) /
0078                    pred.rho2());
0079 }