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 <>
30  const Vertex &pv, const VertexCompositePtrCandidate &sv, const GlobalVector &direction, bool withPVError) {
31  typedef ROOT::Math::SVector<double, 3> SVector1;
32  typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym1;
33  CovarianceMatrix covariance;
34  sv.fillVertexCovariance(covariance);
35  SMatrixSym1 cov = covariance;
36  if (withPVError)
37  cov += pv.covariance();
38  SVector1 vector(0, 0, sv.vertex().Z() - pv.position().Z());
39 
40  double dist = ROOT::Math::Mag(vector);
41  double error = ROOT::Math::Similarity(cov, vector);
42  if (error > 0.0 && dist > 1.0e-9)
43  error = std::sqrt(error) / dist;
44  else
45  error = -1.0;
46  if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
47  dist = -dist;
48  return Measurement1D(dist, error);
49  }
50 
51  template <>
53  const Vertex &pv, const VertexCompositePtrCandidate &sv, const GlobalVector &direction, bool withPVError) {
54  typedef ROOT::Math::SVector<double, 2> SVector2;
55  typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
56  CovarianceMatrix covariance;
57  sv.fillVertexCovariance(covariance);
58 
59  SMatrixSym2 cov = covariance.Sub<SMatrixSym2>(0, 0);
60  if (withPVError)
61  cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
62 
63  SVector2 vector(sv.vertex().X() - pv.position().X(), sv.vertex().Y() - pv.position().Y());
64  double dist = ROOT::Math::Mag(vector);
65  double error = ROOT::Math::Similarity(cov, vector);
66  if (error > 0.0 && dist > 1.0e-9)
67  error = std::sqrt(error) / dist;
68  else
69  error = -1.0;
70 
71  if ((vector[0] * direction.x() + vector[1] * direction.y()) < 0.0)
72  dist = -dist;
73 
74  return Measurement1D(dist, error);
75  }
76  template <>
78  const Vertex &pv, const VertexCompositePtrCandidate &sv, const GlobalVector &direction, bool withPVError) {
79  typedef ROOT::Math::SVector<double, 3> SVector3;
80  typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
81  CovarianceMatrix covariance;
82  sv.fillVertexCovariance(covariance);
83 
84  SMatrixSym3 cov = covariance;
85  if (withPVError)
86  cov += pv.covariance();
87 
89  sv.vertex().X() - pv.position().X(), sv.vertex().Y() - pv.position().Y(), sv.vertex().Z() - pv.position().Z());
90 
91  double dist = ROOT::Math::Mag(vector);
92  double error = ROOT::Math::Similarity(cov, vector);
93  if (error > 0.0 && dist > 1.0e-9)
94  error = std::sqrt(error) / dist;
95  else
96  error = -1.0;
97 
98  if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
99  dist = -dist;
100 
101  return Measurement1D(dist, error);
102  }
103 
104  template <>
106  const Vertex &sv,
107  const GlobalVector &direction,
108  bool withPVError) {
109  typedef ROOT::Math::SVector<double, 3> SVector1;
110  typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym1;
111 
112  SMatrixSym1 cov = sv.covariance();
113  if (withPVError)
114  cov += pv.covariance();
115 
116  SVector1 vector(0.0, 0.0, sv.position().Z() - pv.position().Z());
117 
118  double dist = ROOT::Math::Mag(vector);
119  double error = ROOT::Math::Similarity(cov, vector);
120  if (error > 0.0 && dist > 1.0e-9)
121  error = std::sqrt(error) / dist;
122  else
123  error = -1.0;
124 
125  if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
126  dist = -dist;
127 
128  return Measurement1D(dist, error);
129  }
130 
131  template <>
133  const Vertex &sv,
134  const GlobalVector &direction,
135  bool withPVError) {
136  typedef ROOT::Math::SVector<double, 2> SVector2;
137  typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > SMatrixSym2;
138 
139  SMatrixSym2 cov = sv.covariance().Sub<SMatrixSym2>(0, 0);
140  if (withPVError)
141  cov += pv.covariance().Sub<SMatrixSym2>(0, 0);
142 
143  SVector2 vector(sv.position().X() - pv.position().X(), sv.position().Y() - pv.position().Y());
144 
145  double dist = ROOT::Math::Mag(vector);
146  double error = ROOT::Math::Similarity(cov, vector);
147  if (error > 0.0 && dist > 1.0e-9)
148  error = std::sqrt(error) / dist;
149  else
150  error = -1.0;
151 
152  if ((vector[0] * direction.x() + vector[1] * direction.y()) < 0.0)
153  dist = -dist;
154 
155  return Measurement1D(dist, error);
156  }
157  template <>
159  const Vertex &sv,
160  const GlobalVector &direction,
161  bool withPVError) {
162  typedef ROOT::Math::SVector<double, 3> SVector3;
163  typedef ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > SMatrixSym3;
164 
165  SMatrixSym3 cov = sv.covariance();
166  if (withPVError)
167  cov += pv.covariance();
168 
169  SVector3 vector(sv.position().X() - pv.position().X(),
170  sv.position().Y() - pv.position().Y(),
171  sv.position().Z() - pv.position().Z());
172 
173  double dist = ROOT::Math::Mag(vector);
174  double error = ROOT::Math::Similarity(cov, vector);
175  if (error > 0.0 && dist > 1.0e-9)
176  error = std::sqrt(error) / dist;
177  else
178  error = -1.0;
179 
180  if ((vector[0] * direction.x() + vector[1] * direction.y() + vector[2] * direction.z()) < 0.0)
181  dist = -dist;
182 
183  return Measurement1D(dist, error);
184  }
185 
186 } // namespace reco
static Measurement1D computeDist3d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
ROOT::Math::SVector< float, 2 > SVector2
Definition: MatrixSTypes.h:18
static Measurement1D computeDist2d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
T sqrt(T t)
Definition: SSEVec.h:19
static Measurement1D computeDist1d(const reco::Vertex &pv, const SV &sv, const GlobalVector &direction, bool withPVError)
def pv(vc)
Definition: MetAnalyzer.py:7
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
Definition: Vector3D.h:28
fixed size matrix
ROOT::Math::SVector< double, 3 > SVector3
Definition: V0Fitter.cc:47