CMS 3D CMS Logo

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 template <>
31  const GlobalVector &direction, bool withPVError)
32 {
33  typedef ROOT::Math::SVector<double, 3> SVector1;
34  typedef ROOT::Math::SMatrix<double, 3, 3,
35  ROOT::Math::MatRepSym<double, 3> > SMatrixSym1;
36  CovarianceMatrix covariance;
37  sv.fillVertexCovariance(covariance);
38  SMatrixSym1 cov = covariance;
39  if (withPVError)
40  cov += pv.covariance();
41  SVector1 vector(0,0,sv.vertex().Z() - pv.position().Z());
42 
43  double dist = ROOT::Math::Mag(vector);
44  double error = ROOT::Math::Similarity(cov, vector);
45  if (error > 0.0 && dist > 1.0e-9)
46  error = std::sqrt(error) / dist;
47  else
48  error = -1.0;
49  if ((vector[0] * direction.x() +
50  vector[1] * direction.y() +
51  vector[2] * direction.z()) < 0.0)
52  dist = -dist;
53  return Measurement1D(dist, error);
54 }
55 
56 template <>
59  const GlobalVector &direction, bool withPVError)
60 {
61  typedef ROOT::Math::SVector<double, 2> SVector2;
62  typedef ROOT::Math::SMatrix<double, 2, 2,
63  ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
64  CovarianceMatrix covariance;
65  sv.fillVertexCovariance(covariance);
66 
67  SMatrixSym2 cov = covariance.Sub<SMatrixSym2>(0, 0);
68  if (withPVError)
69  cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
70 
71  SVector2 vector(sv.vertex().X() - pv.position().X(),
72  sv.vertex().Y() - pv.position().Y());
73  double dist = ROOT::Math::Mag(vector);
74  double error = ROOT::Math::Similarity(cov, vector);
75  if (error > 0.0 && dist > 1.0e-9)
76  error = std::sqrt(error) / dist;
77  else
78  error = -1.0;
79 
80  if ((vector[0] * direction.x() +
81  vector[1] * direction.y()) < 0.0)
82  dist = -dist;
83 
84  return Measurement1D(dist, error);
85 }
86 template <>
89  const GlobalVector &direction, bool withPVError)
90 {
91  typedef ROOT::Math::SVector<double, 3> SVector3;
92  typedef ROOT::Math::SMatrix<double, 3, 3,
93  ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
94  CovarianceMatrix covariance;
95  sv.fillVertexCovariance(covariance);
96 
97  SMatrixSym3 cov = covariance;
98  if (withPVError)
99  cov += pv.covariance();
100 
101  SVector3 vector(sv.vertex().X() - pv.position().X(),
102  sv.vertex().Y() - pv.position().Y(),
103  sv.vertex().Z() - pv.position().Z());
104 
105  double dist = ROOT::Math::Mag(vector);
106  double error = ROOT::Math::Similarity(cov, vector);
107  if (error > 0.0 && dist > 1.0e-9)
108  error = std::sqrt(error) / dist;
109  else
110  error = -1.0;
111 
112  if ((vector[0] * direction.x() +
113  vector[1] * direction.y() +
114  vector[2] * direction.z()) < 0.0)
115  dist = -dist;
116 
117  return Measurement1D(dist, error);
118 }
119 
120 template <>
123  const GlobalVector &direction, bool withPVError)
124 {
125  typedef ROOT::Math::SVector<double, 3> SVector1;
126  typedef ROOT::Math::SMatrix<double, 3, 3,
127  ROOT::Math::MatRepSym<double, 3> > SMatrixSym1;
128 
129  SMatrixSym1 cov = sv.covariance();
130  if (withPVError)
131  cov += pv.covariance();
132 
133  SVector1 vector(0.0,0.0,sv.position().Z() - pv.position().Z());
134 
135  double dist = ROOT::Math::Mag(vector);
136  double error = ROOT::Math::Similarity(cov, vector);
137  if (error > 0.0 && dist > 1.0e-9)
138  error = std::sqrt(error) / dist;
139  else
140  error = -1.0;
141 
142  if ((vector[0] * direction.x() +
143  vector[1] * direction.y() +
144  vector[2] * direction.z()) < 0.0)
145  dist = -dist;
146 
147  return Measurement1D(dist, error);
148 }
149 
150 
151 template <>
154  const GlobalVector &direction, bool withPVError)
155 {
156  typedef ROOT::Math::SVector<double, 2> SVector2;
157  typedef ROOT::Math::SMatrix<double, 2, 2,
158  ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
159 
160  SMatrixSym2 cov = sv.covariance().Sub<SMatrixSym2>(0, 0);
161  if (withPVError)
162  cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
163 
164  SVector2 vector(sv.position().X() - pv.position().X(),
165  sv.position().Y() - pv.position().Y());
166 
167  double dist = ROOT::Math::Mag(vector);
168  double error = ROOT::Math::Similarity(cov, vector);
169  if (error > 0.0 && dist > 1.0e-9)
170  error = std::sqrt(error) / dist;
171  else
172  error = -1.0;
173 
174  if ((vector[0] * direction.x() +
175  vector[1] * direction.y()) < 0.0)
176  dist = -dist;
177 
178  return Measurement1D(dist, error);
179 }
180 template <>
183  const GlobalVector &direction, bool withPVError)
184 {
185  typedef ROOT::Math::SVector<double, 3> SVector3;
186  typedef ROOT::Math::SMatrix<double, 3, 3,
187  ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
188 
189  SMatrixSym3 cov = sv.covariance();
190  if (withPVError)
191  cov += pv.covariance();
192 
193  SVector3 vector(sv.position().X() - pv.position().X(),
194  sv.position().Y() - pv.position().Y(),
195  sv.position().Z() - pv.position().Z());
196 
197  double dist = ROOT::Math::Mag(vector);
198  double error = ROOT::Math::Similarity(cov, vector);
199  if (error > 0.0 && dist > 1.0e-9)
200  error = std::sqrt(error) / dist;
201  else
202  error = -1.0;
203 
204  if ((vector[0] * direction.x() +
205  vector[1] * direction.y() +
206  vector[2] * direction.z()) < 0.0)
207  dist = -dist;
208 
209  return Measurement1D(dist, error);
210 }
211 
212 }
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
static Measurement1D computeDist3d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:130
static Measurement1D computeDist2d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
const Point & position() const
position
Definition: Vertex.h:109
T sqrt(T t)
Definition: SSEVec.h:18
static Measurement1D computeDist1d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
const Point & vertex() const override
vertex position (overwritten by PF...)
def pv(vc)
Definition: MetAnalyzer.py:6
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
fixed size matrix
ROOT::Math::SVector< double, 3 > SVector3
Definition: V0Fitter.cc:47