Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
8 #include "JTools/JConstants.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JFIT {}
16 namespace JPP { using namespace JFIT; }
17 
18 namespace 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  /**
33  * Default contructor.
34  */
36  JMatrixNS()
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * The template argument <tt>T</tt> refers to an iterator of a data structure which should have the following member methods:
44  * - double %getX(); // [m]
45  * - double %getY(); // [m]
46  * - double %getZ(); // [m]
47  *
48  * \param pos reference position [m]
49  * \param __begin begin of data
50  * \param __end end of data
51  * \param alpha angular resolution [deg]
52  * \param sigma time resolution [ns]
53  */
54  template<class T>
55  JMatrixNZ(const JVector3D& pos,
56  T __begin,
57  T __end,
58  const double alpha,
59  const double sigma) :
60  JMatrixNS()
61  {
62  set(pos, __begin, __end, alpha, sigma);
63  }
64 
65 
66  /**
67  * Set co-variance matrix.
68  *
69  * The template argument <tt>T</tt> refers to an iterator of a data structure which should have the following member methods:
70  * - double %getX(); // [m]
71  * - double %getY(); // [m]
72  * - double %getZ(); // [m]
73  *
74  * \param pos reference position [m]
75  * \param __begin begin of data
76  * \param __end end of data
77  * \param alpha angular resolution [deg]
78  * \param sigma time resolution [ns]
79  */
80  template<class T>
81  void set(const JVector3D& pos,
82  T __begin,
83  T __end,
84  const double alpha,
85  const double sigma)
86  {
87  using namespace std;
88  using namespace JTOOLS;
89 
90 
91  const int N = distance(__begin, __end);
92 
93  this ->resize(N);
94  buffer.resize(N);
95 
96 
97  const double ta = alpha * PI / 180.0;
98  const double ct = cos(ta);
99  const double st = sin(ta);
100 
101 
102  // angular resolution
103 
104  for (T i = __begin; i != __end; ++i) {
105 
106  const double dx = i->getX() - pos.getX();
107  const double dy = i->getY() - pos.getY();
108  const double dz = i->getZ() - pos.getZ();
109 
110  const double R = sqrt(dx*dx + dy*dy);
111 
112  double x = ta * getKappaC() * getInverseSpeedOfLight();
113  double y = ta * getKappaC() * getInverseSpeedOfLight();
114  double v = ta * getInverseSpeedOfLight();
115  double w = ta * getInverseSpeedOfLight();
116 
117  if (R != 0.0) {
118  x *= dx / R;
119  y *= dy / R;
120  }
121 
122  x *= (dz*ct - dx*st);
123  y *= (dz*ct - dy*st);
124  v *= -(dx*ct + dz*st);
125  w *= -(dy*ct + dz*st);
126 
127  buffer[distance(__begin,i)] = variance(x, y, v, w);
128  }
129 
130  for (int i = 0; i != N; ++i) {
131 
132  for (int j = 0; j != i; ++j) {
133  (*this)(i, j) = getDot(buffer[i], buffer[j]);
134  (*this)(j, i) = (*this)(i, j);
135  }
136 
137  (*this)(i, i) = getDot(buffer[i], buffer[i]) + sigma * sigma;
138  }
139  }
140 
141  private:
142  /**
143  * Auxiliary data structure for co-variance calculation.
144  */
145  struct variance {
146  /**
147  * Default constructor.
148  */
150  x(0.0),
151  y(0.0),
152  v(0.0),
153  w(0.0)
154  {}
155 
156 
157  /**
158  * Constructor.
159  *
160  * \param __x x
161  * \param __y y
162  * \param __v v
163  * \param __w w
164  */
165  variance(const double __x,
166  const double __y,
167  const double __v,
168  const double __w) :
169  x(__x),
170  y(__y),
171  v(__v),
172  w(__w)
173  {}
174 
175 
176  double x;
177  double y;
178  double v;
179  double w;
180  };
181 
182 
184 
185 
186  /**
187  * Get dot product.
188  *
189  * \param first first variance
190  * \param second second variance
191  * \return dot product
192  */
193  static inline double getDot(const variance& first, const variance& second)
194  {
195  return (first.x * second.x +
196  first.y * second.y +
197  first.v * second.v +
198  first.w * second.w);
199 
200  }
201  };
202 }
203 
204 #endif
205 
void set(const JVector3D &pos, T __begin, T __end, const double alpha, const double sigma)
Set co-variance matrix.
Definition: JMatrixNZ.hh:81
JMatrixNZ()
Default contructor.
Definition: JMatrixNZ.hh:35
static double getDot(const variance &first, const variance &second)
Get dot product.
Definition: JMatrixNZ.hh:193
N x N symmetric matrix.
Definition: JMatrixNS.hh:26
static const double PI
Constants.
Definition: JConstants.hh:20
JMatrixNZ(const JVector3D &pos, T __begin, T __end, const double alpha, const double sigma)
Constructor.
Definition: JMatrixNZ.hh:55
const double getInverseSpeedOfLight()
Get inverse speed of light.
Definition: JConstants.hh:100
variance(const double __x, const double __y, const double __v, const double __w)
Constructor.
Definition: JMatrixNZ.hh:165
Constants.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:32
Determination of the co-variance matrix of hits for a track along z-axis (JFIT::JLine1Z).
Definition: JMatrixNZ.hh:28
std::vector< variance > buffer
Definition: JMatrixNZ.hh:183
double getY() const
Get y position.
Definition: JVector3D.hh:102
double getX() const
Get x position.
Definition: JVector3D.hh:92
variance()
Default constructor.
Definition: JMatrixNZ.hh:149
double getKappaC()
Get average kappa of Cherenkov light in water.
Definition: JConstants.hh:155
Auxiliary data structure for co-variance calculation.
Definition: JMatrixNZ.hh:145
double getZ() const
Get z position.
Definition: JVector3D.hh:113