Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
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 "JPhysics/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  using JMatrixNS::getDot;
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
const double sigma[]
Definition: JQuadrature.cc:74
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
static const double PI
Mathematical constants.
double getKappaC()
Get average R-dependence of arrival time of Cherenkov light (a.k.a.
const double getInverseSpeedOfLight()
Get inverse speed of light.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
data_type w[N+1][M+1]
Definition: JPolint.hh:867
data_type v[N+1][M+1]
Definition: JPolint.hh:866
int j
Definition: JPolint.hh:792
Definition: JSTDTypes.hh:14
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