Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvtxTrackState_v2.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SvtxTrackState_v2.cc
1 #include "SvtxTrackState_v2.h"
2 
3 #include <iostream>
4 #include <utility> // for swap
5 
6 
7 using namespace std;
8 
9 namespace
10 {
11 
12  // square convenience function
13  template<class T> inline constexpr T square( const T& x ) { return x*x; }
14 
15  // get unique index in cov. matrix array from i and j
16  inline unsigned int covar_index(unsigned int i, unsigned int j)
17  {
18  if (i > j) std::swap(i, j);
19  return i + 1 + (j + 1) * (j) / 2 - 1;
20  }
21 
22 }
23 
25  : _pathlength(pathlength)
26 {
27  for (int i = 0; i < 3; ++i) _pos[i] = 0.0;
28  for (int i = 0; i < 3; ++i) _mom[i] = NAN;
29  for (int i = 0; i < 6; ++i)
30  {
31  for (int j = i; j < 6; ++j)
32  {
33  set_error(i, j, 0.0);
34  }
35  }
36  state_name = "UNKNOWN";
37 }
38 
39 void SvtxTrackState_v2::identify(std::ostream &os) const
40 {
41  os << "---SvtxTrackState_v2-------------" << endl;
42  os << "pathlength: " << get_pathlength() << endl;
43  os << "(px,py,pz) = ("
44  << get_px() << ","
45  << get_py() << ","
46  << get_pz() << ")" << endl;
47 
48  os << "(x,y,z) = (" << get_x() << "," << get_y() << "," << get_z() << ")" << endl;
49  os << "---------------------------------" << endl;
50 }
51 
52 float SvtxTrackState_v2::get_error(unsigned int i, unsigned int j) const
53 {
54  return _covar[covar_index(i, j)];
55 }
56 
57 void SvtxTrackState_v2::set_error(unsigned int i, unsigned int j, float value)
58 {
59  _covar[covar_index(i, j)] = value;
60  return;
61 }
62 
64 {
65  const float r = std::sqrt( square(_pos[0]) + square(_pos[1]));
66  if (r > 0) return get_rphi_error() / r;
67  return 0;
68 }
69 
71 {
72  const auto phi = -std::atan2(_pos[1], _pos[0] );
73  const auto cosphi = std::cos(phi);
74  const auto sinphi = std::sin(phi);
75  return std::sqrt(
76  square(sinphi)*get_error(0,0) +
77  square(cosphi)*get_error(1,1) +
78  2.*cosphi*sinphi*get_error(0,1));
79 }
80 
82 { return std::sqrt(get_error(2, 2)); }