forked from sPHENIX-Collaboration/coresoftware
/
SvtxTrackState_v1.cc
82 lines (67 loc) · 1.93 KB
/
SvtxTrackState_v1.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "SvtxTrackState_v1.h"
#include <iostream>
#include <utility> // for swap
using namespace std;
namespace
{
// square convenience function
template<class T> inline constexpr T square( const T& x ) { return x*x; }
// get unique index in cov. matrix array from i and j
inline unsigned int covar_index(unsigned int i, unsigned int j)
{
if (i > j) std::swap(i, j);
return i + 1 + (j + 1) * (j) / 2 - 1;
}
}
SvtxTrackState_v1::SvtxTrackState_v1(float pathlength)
: _pathlength(pathlength)
{
for (int i = 0; i < 3; ++i) _pos[i] = 0.0;
for (int i = 0; i < 3; ++i) _mom[i] = NAN;
for (int i = 0; i < 6; ++i)
{
for (int j = i; j < 6; ++j)
{
set_error(i, j, 0.0);
}
}
state_name = "UNKNOWN";
}
void SvtxTrackState_v1::identify(std::ostream &os) const
{
os << "---SvtxTrackState_v1-------------" << endl;
os << "pathlength: " << get_pathlength() << endl;
os << "(px,py,pz) = ("
<< get_px() << ","
<< get_py() << ","
<< get_pz() << ")" << endl;
os << "(x,y,z) = (" << get_x() << "," << get_y() << "," << get_z() << ")" << endl;
os << "---------------------------------" << endl;
}
float SvtxTrackState_v1::get_error(unsigned int i, unsigned int j) const
{
return _covar[covar_index(i, j)];
}
void SvtxTrackState_v1::set_error(unsigned int i, unsigned int j, float value)
{
_covar[covar_index(i, j)] = value;
return;
}
float SvtxTrackState_v1::get_phi_error() const
{
const float r = std::sqrt( square(_pos[0]) + square(_pos[1]));
if (r > 0) return get_rphi_error() / r;
return 0;
}
float SvtxTrackState_v1::get_rphi_error() const
{
const auto phi = -std::atan2(_pos[1], _pos[0] );
const auto cosphi = std::cos(phi);
const auto sinphi = std::sin(phi);
return std::sqrt(
square(sinphi)*get_error(0,0) +
square(cosphi)*get_error(1,1) +
2.*cosphi*sinphi*get_error(0,1));
}
float SvtxTrackState_v1::get_z_error() const
{ return std::sqrt(get_error(2, 2)); }