FEDRA emulsion software from the OPERA Collaboration
SDistance.hh
Go to the documentation of this file.
1 #ifndef __SDISTANCE_HH
2 #define __SDISTANCE_HH
3 // *****************************************************************************
4 //
5 // source:
6 //
7 // type: source code
8 //
9 // created: 24. Apr 2001
10 //
11 // author: Thorsten Glebe
12 // HERA-B Collaboration
13 // Max-Planck-Institut fuer Kernphysik
14 // Saupfercheckweg 1
15 // 69117 Heidelberg
16 // Germany
17 // E-mail: T.Glebe@mpi-hd.mpg.de
18 //
19 // Description: an (incomplete) collection of distance functions
20 //
21 // changes:
22 // 24 Apr 2001 (TG) creation
23 // 04 Mai 2001 (TG) Tdistance() added
24 // 06 Jul 2001 (TG) corrected Tdistance()
25 // 27 Jul 2001 (TG) added Sdistance(SVector,SVector)
26 // 15 Aug 2001 (TG) added Sdistance(Vertex,Vertex)
27 // 28 Sep 2001 (TG) declared TDistance() and SGNdistance() inline, renamed all
28 // distance() functions which calculate spatial distances to Sdistance()
29 // 02 Okt 2001 (TG) added SGNVVdistance()
30 //
31 // *****************************************************************************
32 #include "smatrix/SVector.hh"
33 #include "smatrix/Functions.hh"
34 #include "smatrix/SVertex.hh"
35 #include "smatrix/BinaryOperators.hh"
36 
42 //============================================================================
43 // distance: spatial distance between SpacePoints
44 //============================================================================
45 inline double Sdistance(const SVector<double,3>& x1, const SVector<double,3>& x2) {
46  return mag(x1 - x2);
47 }
48 
54 //============================================================================
55 // distance: spatial distance between Vertex objects
56 //============================================================================
57 inline double Sdistance(const Vertex& v1, const Vertex& v2) {
58  return mag(v1.vpos() - v2.vpos());
59 }
60 
66 //============================================================================
67 // distance: spatial distance between Vertex objects
68 //============================================================================
69 inline double SGNVVdistance(const Vertex& v1, const Vertex& v2) {
70  return mag(v1.vpos() - v2.vpos()) * sign(v1.vpos()[2] - v2.vpos()[2]);
71 }
72 
78 //============================================================================
79 // distance: spatial distance between Vertex and SpacePoint
80 //============================================================================
81 inline double Sdistance(const Vertex& v, const SVector<double,3>& x) {
82  return mag(v.vpos() - x);
83 }
84 
92 //============================================================================
93 // distance: spatial distance between Track and Vertex
94 //============================================================================
95 inline double TVdistance(const Track& t, const Vertex& v) {
96  return mag(cross(t.xvec()-v.vpos(), t.evec()));
97 }
98 
112 //============================================================================
113 // distance: spatial distance between Track and Track
114 //============================================================================
115 inline double Tdistance(const Track& t1, const Track& t2) {
116  const double a = t1.tx();
117  const double b = t1.ty();
118  const double c = 1;
119  const double a1 = t2.tx();
120  const double b1 = t2.ty();
121  const double c1 = 1;
122 
123  const double det = square(a*b1 - b*a1) + square(b*c1 - c*b1) + square(c*a1 - a*c1);
124  const SVector<double,3> dx = t2.xvec() - t1.xvec();
125  // are tracks parallel?
126  if(det==0) return mag(cross(dx,t1.evec()));
127 
128  const double det2 = dx[0]*(b*c1 - c*b1) + dx[1]*(c*a1 - a*c1) + dx[2]*(a*b1 - b*a1);
129 
130  return fabs(det2/sqrt(det));
131 }
132 
141 //============================================================================
142 // distance: spatial distance between Track and Wire
143 //============================================================================
144 //inline double Sdistance(const Track& t, const Wire& w) {
145 // const SVector<double,3> cr = cross(w.dvec(),t.tvec());
146 // return dot(cr, t.xvec() - w.xvec())/mag2(cr);
147 //}
148 
149 
166 //============================================================================
167 // SGNdistance: signed spatial distance between Track and Vertex
168 //============================================================================
169 inline double SGNdistance(const Track& t, const Vertex& v) {
170  // dx = point of track closest to vertex - vertex position
171  const SVector<double,3> dx =
172  t.xvec() - t.tvec() * dot(t.evec(), t.xvec()-v.vpos()) - v.vpos();
173  return sign(dx[2]) * mag(dx);
174 }
175 
179 //============================================================================
180 // Chi2distance: chi2 distance between two tracks
181 //============================================================================
182 inline double Chi2distance(const Track& t1, const Track& t2) {
183  SVertex<2> vtx(t1,t2);
184  if(vtx.findVertexVt() == true)
185  return vtx.chi2();
186  else
187  return 1.e10;
188 }
189 
193 //============================================================================
194 // Chi2distance: chi2 distance between SVertex and Space Point
195 //============================================================================
196 template <unsigned int NTR>
197 inline double Chi2distance(const SVertex<NTR>& v, const SVector<double,3>& x) {
198  return product(v.kalman(0).KCINV(),v.vposR()-x);
199 }
200 
204 //============================================================================
205 // Chi2distance: chi2 distance between two SVertex objects
206 //============================================================================
207 template <unsigned int NTR, unsigned int NTR2>
208 inline double Chi2distance(const SVertex<NTR>& v1, const SVertex<NTR2>& v2) {
209  const SMatrix<double,3>& cinv1 = v1.kalman(0).KCINV();
210  const SMatrix<double,3>& cinv2 = v2.kalman(0).KCINV();
211  const SMatrix<double,3> Cmat = cinv1 + cinv2;
212 
213  if(Cmat.sinvert() == false) { return 1.e10; }
214 
215  const SVector<double,3> xav = Cmat * (cinv1*v1.vposR() + cinv2*v2.vposR());
216  return product(cinv1, xav - v1.vposR()) + product(cinv2, xav - v2.vposR());
217 }
218 #endif
T mag(const SVector< T, D > &rhs)
Definition: Functions.hh:216
SVector< T, 3 > cross(const SVector< T, 3 > &lhs, const SVector< T, 3 > &rhs)
Definition: Functions.hh:283
T dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
Definition: Functions.hh:132
const T square(const T &x)
Definition: Functions.hh:46
const int sign(const T &x)
Definition: Functions.hh:97
T product(const SMatrix< T, D > &lhs, const SVector< T, D > &rhs)
Definition: MatrixFunctions.hh:451
double SGNVVdistance(const Vertex &v1, const Vertex &v2)
Definition: SDistance.hh:69
double Sdistance(const SVector< double, 3 > &x1, const SVector< double, 3 > &x2)
Definition: SDistance.hh:45
double Chi2distance(const Track &t1, const Track &t2)
Definition: SDistance.hh:182
double SGNdistance(const Track &t, const Vertex &v)
Definition: SDistance.hh:169
double Tdistance(const Track &t1, const Track &t2)
Definition: SDistance.hh:115
double TVdistance(const Track &t, const Vertex &v)
Definition: SDistance.hh:95
Expr< UnaryOp< Fabs< T >, Expr< A, T, D >, T >, T, D > fabs(const Expr< A, T, D > &rhs)
Definition: UnaryOperators.hh:96
void a()
Definition: check_aligned.C:59
TTree * t
Definition: check_shower.C:4
bool sinvert()
invert symmetric, pos. def. Matrix via Dsinv
Definition: SVertex.hh:73
float chi2() const
vertex $\chi^2$
const SVector< double, 3 > & vposR() const
vertex position $\vec{v} = (v_x,v_y,v_z)$ (fast readonly access)
bool findVertexVt()
Vt based Kalman filter vertex fit.
const SKalman< NTR > & kalman(unsigned int i) const
read only access to Kalman objects
Definition: Track.h:10
TCanvas * c1
Definition: energy.C:13