File indexing completed on 2024-04-06 12:24:34
0001 #include <cmath>
0002
0003 #include <Math/Functions.h>
0004 #include <Math/SVector.h>
0005 #include <Math/SMatrix.h>
0006
0007 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
0008 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0009 #include "DataFormats/VertexReco/interface/Vertex.h"
0010 #include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
0011
0012 #include "RecoBTag/SecondaryVertex/interface/TemplatedSecondaryVertex.h"
0013
0014 namespace reco {
0015
0016 template <>
0017 TemplatedSecondaryVertex<reco::VertexCompositePtrCandidate>::operator reco::Vertex() {
0018 CovarianceMatrix err;
0019 fillVertexCovariance(err);
0020 return reco::Vertex(Vertex::Point(vertex()), err, vertexChi2(), vertexNdof(), numberOfSourceCandidatePtrs());
0021 }
0022
0023
0024
0025
0026
0027
0028 template <>
0029 Measurement1D TemplatedSecondaryVertex<reco::VertexCompositePtrCandidate>::computeDist1d(
0030 const Vertex &pv, const VertexCompositePtrCandidate &sv, const GlobalVector &direction, bool withPVError) {
0031 typedef ROOT::Math::SVector<double, 3> SVector1;
0032 typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym1;
0033 CovarianceMatrix covariance;
0034 sv.fillVertexCovariance(covariance);
0035 SMatrixSym1 cov = covariance;
0036 if (withPVError)
0037 cov += pv.covariance();
0038 SVector1 vector(0, 0, sv.vertex().Z() - pv.position().Z());
0039
0040 double dist = ROOT::Math::Mag(vector);
0041 double error = ROOT::Math::Similarity(cov, vector);
0042 if (error > 0.0 && dist > 1.0e-9)
0043 error = std::sqrt(error) / dist;
0044 else
0045 error = -1.0;
0046 if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
0047 dist = -dist;
0048 return Measurement1D(dist, error);
0049 }
0050
0051 template <>
0052 Measurement1D TemplatedSecondaryVertex<reco::VertexCompositePtrCandidate>::computeDist2d(
0053 const Vertex &pv, const VertexCompositePtrCandidate &sv, const GlobalVector &direction, bool withPVError) {
0054 typedef ROOT::Math::SVector<double, 2> SVector2;
0055 typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
0056 CovarianceMatrix covariance;
0057 sv.fillVertexCovariance(covariance);
0058
0059 SMatrixSym2 cov = covariance.Sub<SMatrixSym2>(0, 0);
0060 if (withPVError)
0061 cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
0062
0063 SVector2 vector(sv.vertex().X() - pv.position().X(), sv.vertex().Y() - pv.position().Y());
0064 double dist = ROOT::Math::Mag(vector);
0065 double error = ROOT::Math::Similarity(cov, vector);
0066 if (error > 0.0 && dist > 1.0e-9)
0067 error = std::sqrt(error) / dist;
0068 else
0069 error = -1.0;
0070
0071 if ((vector[0] * direction.x() + vector[1] * direction.y()) < 0.0)
0072 dist = -dist;
0073
0074 return Measurement1D(dist, error);
0075 }
0076 template <>
0077 Measurement1D TemplatedSecondaryVertex<reco::VertexCompositePtrCandidate>::computeDist3d(
0078 const Vertex &pv, const VertexCompositePtrCandidate &sv, const GlobalVector &direction, bool withPVError) {
0079 typedef ROOT::Math::SVector<double, 3> SVector3;
0080 typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
0081 CovarianceMatrix covariance;
0082 sv.fillVertexCovariance(covariance);
0083
0084 SMatrixSym3 cov = covariance;
0085 if (withPVError)
0086 cov += pv.covariance();
0087
0088 SVector3 vector(
0089 sv.vertex().X() - pv.position().X(), sv.vertex().Y() - pv.position().Y(), sv.vertex().Z() - pv.position().Z());
0090
0091 double dist = ROOT::Math::Mag(vector);
0092 double error = ROOT::Math::Similarity(cov, vector);
0093 if (error > 0.0 && dist > 1.0e-9)
0094 error = std::sqrt(error) / dist;
0095 else
0096 error = -1.0;
0097
0098 if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
0099 dist = -dist;
0100
0101 return Measurement1D(dist, error);
0102 }
0103
0104 template <>
0105 Measurement1D TemplatedSecondaryVertex<reco::Vertex>::computeDist1d(const Vertex &pv,
0106 const Vertex &sv,
0107 const GlobalVector &direction,
0108 bool withPVError) {
0109 typedef ROOT::Math::SVector<double, 3> SVector1;
0110 typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym1;
0111
0112 SMatrixSym1 cov = sv.covariance();
0113 if (withPVError)
0114 cov += pv.covariance();
0115
0116 SVector1 vector(0.0, 0.0, sv.position().Z() - pv.position().Z());
0117
0118 double dist = ROOT::Math::Mag(vector);
0119 double error = ROOT::Math::Similarity(cov, vector);
0120 if (error > 0.0 && dist > 1.0e-9)
0121 error = std::sqrt(error) / dist;
0122 else
0123 error = -1.0;
0124
0125 if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
0126 dist = -dist;
0127
0128 return Measurement1D(dist, error);
0129 }
0130
0131 template <>
0132 Measurement1D TemplatedSecondaryVertex<reco::Vertex>::computeDist2d(const Vertex &pv,
0133 const Vertex &sv,
0134 const GlobalVector &direction,
0135 bool withPVError) {
0136 typedef ROOT::Math::SVector<double, 2> SVector2;
0137 typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
0138
0139 SMatrixSym2 cov = sv.covariance().Sub<SMatrixSym2>(0, 0);
0140 if (withPVError)
0141 cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
0142
0143 SVector2 vector(sv.position().X() - pv.position().X(), sv.position().Y() - pv.position().Y());
0144
0145 double dist = ROOT::Math::Mag(vector);
0146 double error = ROOT::Math::Similarity(cov, vector);
0147 if (error > 0.0 && dist > 1.0e-9)
0148 error = std::sqrt(error) / dist;
0149 else
0150 error = -1.0;
0151
0152 if ((vector[0] * direction.x() + vector[1] * direction.y()) < 0.0)
0153 dist = -dist;
0154
0155 return Measurement1D(dist, error);
0156 }
0157 template <>
0158 Measurement1D TemplatedSecondaryVertex<reco::Vertex>::computeDist3d(const Vertex &pv,
0159 const Vertex &sv,
0160 const GlobalVector &direction,
0161 bool withPVError) {
0162 typedef ROOT::Math::SVector<double, 3> SVector3;
0163 typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
0164
0165 SMatrixSym3 cov = sv.covariance();
0166 if (withPVError)
0167 cov += pv.covariance();
0168
0169 SVector3 vector(sv.position().X() - pv.position().X(),
0170 sv.position().Y() - pv.position().Y(),
0171 sv.position().Z() - pv.position().Z());
0172
0173 double dist = ROOT::Math::Mag(vector);
0174 double error = ROOT::Math::Similarity(cov, vector);
0175 if (error > 0.0 && dist > 1.0e-9)
0176 error = std::sqrt(error) / dist;
0177 else
0178 error = -1.0;
0179
0180 if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
0181 dist = -dist;
0182
0183 return Measurement1D(dist, error);
0184 }
0185
0186 }