CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoBTag/SecondaryVertex/src/SecondaryVertex.cc

Go to the documentation of this file.
00001 #include <cmath>
00002 
00003 #include <Math/Functions.h>
00004 #include <Math/SVector.h>
00005 #include <Math/SMatrix.h>
00006 
00007 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
00008 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00009 #include "DataFormats/VertexReco/interface/Vertex.h"
00010 
00011 #include "RecoBTag/SecondaryVertex/interface/SecondaryVertex.h"
00012 
00013 using namespace reco;
00014 
00015 Measurement1D
00016 SecondaryVertex::computeDist2d(const Vertex &pv, const Vertex &sv,
00017                                const GlobalVector &direction, bool withPVError)
00018 {
00019         typedef ROOT::Math::SVector<double, 2> SVector2;
00020         typedef ROOT::Math::SMatrix<double, 2, 2,
00021                         ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
00022 
00023         SMatrixSym2 cov = sv.covariance().Sub<SMatrixSym2>(0, 0);
00024         if (withPVError)
00025                 cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
00026 
00027         SVector2 vector(sv.position().X() - pv.position().X(),
00028                         sv.position().Y() - pv.position().Y());
00029 
00030         double dist = ROOT::Math::Mag(vector);
00031         double error = ROOT::Math::Similarity(cov, vector);
00032         if (error > 0.0 && dist > 1.0e-9)
00033                 error = std::sqrt(error) / dist;
00034         else
00035                 error = -1.0;
00036 
00037         if ((vector[0] * direction.x() +
00038              vector[1] * direction.y()) < 0.0)
00039                 dist = -dist;
00040 
00041         return Measurement1D(dist, error);
00042 }
00043 
00044 Measurement1D
00045 SecondaryVertex::computeDist3d(const Vertex &pv, const Vertex &sv,
00046                                const GlobalVector &direction, bool withPVError)
00047 {
00048         typedef ROOT::Math::SVector<double, 3> SVector3;
00049         typedef ROOT::Math::SMatrix<double, 3, 3,
00050                         ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
00051 
00052         SMatrixSym3 cov = sv.covariance();
00053         if (withPVError)
00054                 cov += pv.covariance();
00055 
00056         SVector3 vector(sv.position().X() - pv.position().X(),
00057                         sv.position().Y() - pv.position().Y(),
00058                         sv.position().Z() - pv.position().Z());
00059 
00060         double dist = ROOT::Math::Mag(vector);
00061         double error = ROOT::Math::Similarity(cov, vector);
00062         if (error > 0.0 && dist > 1.0e-9)
00063                 error = std::sqrt(error) / dist;
00064         else
00065                 error = -1.0;
00066 
00067         if ((vector[0] * direction.x() +
00068              vector[1] * direction.y() +
00069              vector[2] * direction.z()) < 0.0)
00070                 dist = -dist;
00071 
00072         return Measurement1D(dist, error);
00073 }