Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JMatrixNZ.hh
Go to the documentation of this file.
1#ifndef __JFIT__JMATRIXNZ__
2#define __JFIT__JMATRIXNZ__
3
4#include <cmath>
5
6#include "JMath/JMatrixNS.hh"
9
10
11/**
12 * \author mdejong
13 */
14
15namespace JFIT {}
16namespace JPP { using namespace JFIT; }
17
18namespace JFIT {
19
20 using JMATH::JMatrixNS;
22
23
24 /**
25 * Determination of the co-variance matrix of hits for a track along z-axis (JFIT::JLine1Z).
26 * In this, the given angular and time resolution are taken into account.
27 */
28 class JMatrixNZ :
29 public JMatrixNS
30 {
31 public:
32
34
35
36 /**
37 * Default contructor.
38 */
40 JMatrixNS()
41 {}
42
43
44 /**
45 * Constructor.
46 *
47 * The template argument <tt>T</tt> refers to an iterator of a data structure which should have the following member methods:
48 * - double %getX(); // [m]
49 * - double %getY(); // [m]
50 * - double %getZ(); // [m]
51 *
52 * \param pos reference position [m]
53 * \param __begin begin of data
54 * \param __end end of data
55 * \param alpha angular resolution [deg]
56 * \param sigma time resolution [ns]
57 */
58 template<class T>
59 JMatrixNZ(const JVector3D& pos,
60 T __begin,
61 T __end,
62 const double alpha,
63 const double sigma) :
64 JMatrixNS()
65 {
66 set(pos, __begin, __end, alpha, sigma);
67 }
68
69
70 /**
71 * Set co-variance matrix.
72 *
73 * The template argument <tt>T</tt> refers to an iterator of a data structure which should have the following member methods:
74 * - double %getX(); // [m]
75 * - double %getY(); // [m]
76 * - double %getZ(); // [m]
77 *
78 * \param pos reference position [m]
79 * \param __begin begin of data
80 * \param __end end of data
81 * \param alpha angular resolution [deg]
82 * \param sigma time resolution [ns]
83 */
84 template<class T>
85 void set(const JVector3D& pos,
86 T __begin,
87 T __end,
88 const double alpha,
89 const double sigma)
90 {
91 using namespace std;
92 using namespace JPP;
93
94
95 const int N = distance(__begin, __end);
96
97 this ->resize(N);
98 buffer.resize(N);
99
100 const double ta = alpha * PI / 180.0;
101 const double ct = cos(ta);
102 const double st = sin(ta);
103
104
105 // angular resolution
106
107 for (T i = __begin; i != __end; ++i) {
108
109 const double dx = i->getX() - pos.getX();
110 const double dy = i->getY() - pos.getY();
111 const double dz = i->getZ() - pos.getZ();
112
113 const double R = sqrt(dx*dx + dy*dy);
114
115 double x = ta * getKappaC() * getInverseSpeedOfLight();
116 double y = ta * getKappaC() * getInverseSpeedOfLight();
117 double v = ta * getInverseSpeedOfLight();
118 double w = ta * getInverseSpeedOfLight();
119
120 if (R != 0.0) {
121 x *= dx / R;
122 y *= dy / R;
123 }
124
125 x *= (dz*ct - dx*st);
126 y *= (dz*ct - dy*st);
127 v *= -(dx*ct + dz*st);
128 w *= -(dy*ct + dz*st);
129
130 buffer[distance(__begin,i)] = variance(x, y, v, w);
131 }
132
133 for (int i = 0; i != N; ++i) {
134
135 for (int j = 0; j != i; ++j) {
136 (*this)(i, j) = getDot(buffer[i], buffer[j]);
137 (*this)(j, i) = (*this)(i, j);
138 }
139
140 (*this)(i, i) = getDot(buffer[i], buffer[i]) + sigma * sigma;
141 }
142 }
143
144 private:
145 /**
146 * Auxiliary data structure for co-variance calculation.
147 */
148 struct variance {
149 /**
150 * Default constructor.
151 */
153 x(0.0),
154 y(0.0),
155 v(0.0),
156 w(0.0)
157 {}
158
159
160 /**
161 * Constructor.
162 *
163 * \param __x x
164 * \param __y y
165 * \param __v v
166 * \param __w w
167 */
168 variance(const double __x,
169 const double __y,
170 const double __v,
171 const double __w) :
172 x(__x),
173 y(__y),
174 v(__v),
175 w(__w)
176 {}
177
178
179 double x;
180 double y;
181 double v;
182 double w;
183 };
184
185
187
188
189 /**
190 * Get dot product.
191 *
192 * \param first first variance
193 * \param second second variance
194 * \return dot product
195 */
196 static inline double getDot(const variance& first, const variance& second)
197 {
198 return (first.x * second.x +
199 first.y * second.y +
200 first.v * second.v +
201 first.w * second.w);
202
203 }
204 };
205}
206
207#endif
208
Physics constants.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Determination of the co-variance matrix of hits for a track along z-axis (JFIT::JLine1Z).
Definition JMatrixNZ.hh:30
std::vector< variance > buffer
Definition JMatrixNZ.hh:186
void set(const JVector3D &pos, T __begin, T __end, const double alpha, const double sigma)
Set co-variance matrix.
Definition JMatrixNZ.hh:85
static double getDot(const variance &first, const variance &second)
Get dot product.
Definition JMatrixNZ.hh:196
JMatrixNZ(const JVector3D &pos, T __begin, T __end, const double alpha, const double sigma)
Constructor.
Definition JMatrixNZ.hh:59
JMatrixNZ()
Default contructor.
Definition JMatrixNZ.hh:39
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getY() const
Get y position.
Definition JVector3D.hh:104
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for co-variance calculation.
Definition JMatrixNZ.hh:148
variance(const double __x, const double __y, const double __v, const double __w)
Constructor.
Definition JMatrixNZ.hh:168
variance()
Default constructor.
Definition JMatrixNZ.hh:152
double getDot(const JVectorND &v) const
Get dot product.
Definition JMatrixND.hh:773
N x N symmetric matrix.
Definition JMatrixNS.hh:30