Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrkrClusterv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrkrClusterv1.cc
1 
7 #include "TrkrClusterv1.h"
8 
9 #include <cmath>
10 #include <utility> // for swap
11 
12 namespace
13 {
14 
15  // square convenience function
16  template<class T> inline constexpr T square( const T& x ) { return x*x; }
17 
18  // get unique index in cov. matrix array from i and j
19  inline unsigned int covarIndex(unsigned int i, unsigned int j)
20  {
21  if (i > j) std::swap(i, j);
22  return i + 1 + (j + 1) * (j) / 2 - 1;
23  }
24 
25  // rotate size or covariant matrix to polar coordinates and return the phi component
26  template<float (TrkrClusterv1::*accessor)(unsigned int, unsigned int) const>
27  float rotate( const TrkrClusterv1* cluster )
28  {
29  const auto phi = -std::atan2(cluster->getY(), cluster->getX());
30  const auto cosphi = std::cos(phi);
31  const auto sinphi = std::sin(phi);
32 
33  return
34  square(sinphi)*(cluster->*accessor)(0,0) +
35  square(cosphi)*(cluster->*accessor)(1,1) +
36  2.*cosphi*sinphi*(cluster->*accessor)(0,1);
37  }
38 
39 }
40 
42  : m_cluskey(TrkrDefs::CLUSKEYMAX)
43  , m_isGlobal(true)
44  , m_adc(0xFFFFFFFF)
45 {
46  for (int i = 0; i < 3; ++i) m_pos[i] = NAN;
47 
48  for (int j = 0; j < 3; ++j)
49  {
50  for (int i = 0; i < 3; ++i)
51  {
52  setSize(i, j, NAN);
53  setError(i, j, NAN);
54  }
55  }
56 }
57 
58 void TrkrClusterv1::identify(std::ostream& os) const
59 {
60  os << "---TrkrClusterv1--------------------" << std::endl;
61 
62  os << " (x,y,z) = (" << getPosition(0);
63  os << ", " << getPosition(1) << ", ";
64  os << getPosition(2) << ") cm";
65  if (m_isGlobal)
66  os << " - global coordinates" << std::endl;
67  else
68  os << " - local coordinates" << std::endl;
69 
70  os << " adc = " << getAdc() << std::endl;
71 
72  os << " size phi = " << getPhiSize();
73  os << " cm, size z = " << getZSize() << " cm" << std::endl;
74 
75  os << " ( ";
76  os << getSize(0, 0) << " , ";
77  os << getSize(0, 1) << " , ";
78  os << getSize(0, 2) << " )" << std::endl;
79  os << " size = ( ";
80  os << getSize(1, 0) << " , ";
81  os << getSize(1, 1) << " , ";
82  os << getSize(1, 2) << " )" << std::endl;
83  os << " ( ";
84  os << getSize(2, 0) << " , ";
85  os << getSize(2, 1) << " , ";
86  os << getSize(2, 2) << " )" << std::endl;
87 
88  os << " ( ";
89  os << getError(0, 0) << " , ";
90  os << getError(0, 1) << " , ";
91  os << getError(0, 2) << " )" << std::endl;
92  os << " err = ( ";
93  os << getError(1, 0) << " , ";
94  os << getError(1, 1) << " , ";
95  os << getError(1, 2) << " )" << std::endl;
96  os << " ( ";
97  os << getError(2, 0) << " , ";
98  os << getError(2, 1) << " , ";
99  os << getError(2, 2) << " )" << std::endl;
100 
101  os << std::endl;
102  os << "-----------------------------------------------" << std::endl;
103 
104  return;
105 }
106 
108 {
109  if (m_cluskey == TrkrDefs::CLUSKEYMAX) return 0;
110  for (int i = 0; i < 3; ++i)
111  {
112  if (std::isnan(getPosition(i))) return 0;
113  }
114  if (m_adc == 0xFFFFFFFF) return 0;
115  for (int j = 0; j < 3; ++j)
116  {
117  for (int i = j; i < 3; ++i)
118  {
119  if (std::isnan(getSize(i, j))) return 0;
120  if (std::isnan(getError(i, j))) return 0;
121  }
122  }
123 
124  return 1;
125 }
126 
128 {
129  // do nothing if copying onto oneself
130  if( this == &source ) return;
131 
132  // parent class method
133  TrkrCluster::CopyFrom( source );
134 
135  setX( source.getX() );
136  setY( source.getY() );
137  setZ( source.getZ() );
138  m_isGlobal = source.isGlobal();
139  setAdc( source.getAdc() );
140 
141  for (int j = 0; j < 3; ++j)
142  for (int i = 0; i < 3; ++i)
143  {
144  setSize(i, j, source.getSize(i, j));
145  setError(i, j, source.getError(i, j));
146  }
147 }
148 
149 void TrkrClusterv1::setSize(unsigned int i, unsigned int j, float value)
150 {
151  m_size[covarIndex(i, j)] = value;
152  return;
153 }
154 
155 float TrkrClusterv1::getSize(unsigned int i, unsigned int j) const
156 { return m_size[covarIndex(i, j)]; }
157 
158 void TrkrClusterv1::setError(unsigned int i, unsigned int j, float value)
159 {
160  m_err[covarIndex(i, j)] = value;
161  return;
162 }
163 
164 float TrkrClusterv1::getError(unsigned int i, unsigned int j) const
165 { return m_err[covarIndex(i, j)]; }
166 
168 { return 2*std::sqrt(rotate<&TrkrClusterv1::getSize>(this)); }
169 
171 { return 2.*sqrt(getSize(2, 2)); }
172 
174 {
175  const float rad = std::sqrt(square(m_pos[0])+square(m_pos[1]));
176  if (rad > 0) return getRPhiError() / rad;
177  return 0;
178 }
179 
181 { return std::sqrt(rotate<&TrkrClusterv1::getError>( this )); }
182 
184 { return std::sqrt(getError(2, 2)); }