CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TemplatedSecondaryVertex.cc
Go to the documentation of this file.
1 #include <cmath>
2 
3 #include <Math/Functions.h>
4 #include <Math/SVector.h>
5 #include <Math/SMatrix.h>
6 
11 
13 
14 namespace reco {
15 
16 template <>
19 fillVertexCovariance(err);
20 return reco::Vertex(Vertex::Point(vertex()), err, vertexChi2(), vertexNdof(),numberOfSourceCandidatePtrs());
21 }
22 
23 //it should be better without if it compiles
24 /*template <>
25 TemplatedSecondaryVertex<reco::Vertex>::operator reco::Vertex() {
26 return reco::Vertex(this);
27 }*/
28 
29 template <>
32  const GlobalVector &direction, bool withPVError)
33 {
34  typedef ROOT::Math::SVector<double, 2> SVector2;
35  typedef ROOT::Math::SMatrix<double, 2, 2,
36  ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
37  CovarianceMatrix covariance;
38  sv.fillVertexCovariance(covariance);
39 
40  SMatrixSym2 cov = covariance.Sub<SMatrixSym2>(0, 0);
41  if (withPVError)
42  cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
43 
44  SVector2 vector(sv.vertex().X() - pv.position().X(),
45  sv.vertex().Y() - pv.position().Y());
46 
47  double dist = ROOT::Math::Mag(vector);
48  double error = ROOT::Math::Similarity(cov, vector);
49  if (error > 0.0 && dist > 1.0e-9)
50  error = std::sqrt(error) / dist;
51  else
52  error = -1.0;
53 
54  if ((vector[0] * direction.x() +
55  vector[1] * direction.y()) < 0.0)
56  dist = -dist;
57 
58  return Measurement1D(dist, error);
59 }
60 template <>
63  const GlobalVector &direction, bool withPVError)
64 {
65  typedef ROOT::Math::SVector<double, 3> SVector3;
66  typedef ROOT::Math::SMatrix<double, 3, 3,
67  ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
68  CovarianceMatrix covariance;
69  sv.fillVertexCovariance(covariance);
70 
71  SMatrixSym3 cov = covariance;
72  if (withPVError)
73  cov += pv.covariance();
74 
75  SVector3 vector(sv.vertex().X() - pv.position().X(),
76  sv.vertex().Y() - pv.position().Y(),
77  sv.vertex().Z() - pv.position().Z());
78 
79  double dist = ROOT::Math::Mag(vector);
80  double error = ROOT::Math::Similarity(cov, vector);
81  if (error > 0.0 && dist > 1.0e-9)
82  error = std::sqrt(error) / dist;
83  else
84  error = -1.0;
85 
86  if ((vector[0] * direction.x() +
87  vector[1] * direction.y() +
88  vector[2] * direction.z()) < 0.0)
89  dist = -dist;
90 
91  return Measurement1D(dist, error);
92 }
93 
94 
95 template <>
98  const GlobalVector &direction, bool withPVError)
99 {
100  typedef ROOT::Math::SVector<double, 2> SVector2;
101  typedef ROOT::Math::SMatrix<double, 2, 2,
102  ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
103 
104  SMatrixSym2 cov = sv.covariance().Sub<SMatrixSym2>(0, 0);
105  if (withPVError)
106  cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
107 
108  SVector2 vector(sv.position().X() - pv.position().X(),
109  sv.position().Y() - pv.position().Y());
110 
111  double dist = ROOT::Math::Mag(vector);
112  double error = ROOT::Math::Similarity(cov, vector);
113  if (error > 0.0 && dist > 1.0e-9)
114  error = std::sqrt(error) / dist;
115  else
116  error = -1.0;
117 
118  if ((vector[0] * direction.x() +
119  vector[1] * direction.y()) < 0.0)
120  dist = -dist;
121 
122  return Measurement1D(dist, error);
123 }
124 template <>
127  const GlobalVector &direction, bool withPVError)
128 {
129  typedef ROOT::Math::SVector<double, 3> SVector3;
130  typedef ROOT::Math::SMatrix<double, 3, 3,
131  ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
132 
133  SMatrixSym3 cov = sv.covariance();
134  if (withPVError)
135  cov += pv.covariance();
136 
137  SVector3 vector(sv.position().X() - pv.position().X(),
138  sv.position().Y() - pv.position().Y(),
139  sv.position().Z() - pv.position().Z());
140 
141  double dist = ROOT::Math::Mag(vector);
142  double error = ROOT::Math::Similarity(cov, vector);
143  if (error > 0.0 && dist > 1.0e-9)
144  error = std::sqrt(error) / dist;
145  else
146  error = -1.0;
147 
148  if ((vector[0] * direction.x() +
149  vector[1] * direction.y() +
150  vector[2] * direction.z()) < 0.0)
151  dist = -dist;
152 
153  return Measurement1D(dist, error);
154 }
155 
156 }
virtual void fillVertexCovariance(CovarianceMatrix &v) const
fill SMatrix
virtual const Point & vertex() const
vertex position (overwritten by PF...)
static Measurement1D computeDist3d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
ROOT::Math::SVector< double, 2 > SVector2
Definition: GblPoint.h:29
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:116
static Measurement1D computeDist2d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
const Point & position() const
position
Definition: Vertex.h:99
T sqrt(T t)
Definition: SSEVec.h:18
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
Definition: Vector3D.h:27
ROOT::Math::SVector< double, 3 > SVector3
Definition: V0Fitter.cc:47