EIC 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  os << "clusid: " << getClusKey() << std::dec << std::endl;
62 
63  os << " (x,y,z) = (" << getPosition(0);
64  os << ", " << getPosition(1) << ", ";
65  os << getPosition(2) << ") cm";
66  if (m_isGlobal)
67  os << " - global coordinates" << std::endl;
68  else
69  os << " - local coordinates" << std::endl;
70 
71  os << " adc = " << getAdc() << std::endl;
72 
73  os << " size phi = " << getPhiSize();
74  os << " cm, size z = " << getZSize() << " cm" << std::endl;
75 
76  os << " ( ";
77  os << getSize(0, 0) << " , ";
78  os << getSize(0, 1) << " , ";
79  os << getSize(0, 2) << " )" << std::endl;
80  os << " size = ( ";
81  os << getSize(1, 0) << " , ";
82  os << getSize(1, 1) << " , ";
83  os << getSize(1, 2) << " )" << std::endl;
84  os << " ( ";
85  os << getSize(2, 0) << " , ";
86  os << getSize(2, 1) << " , ";
87  os << getSize(2, 2) << " )" << std::endl;
88 
89  os << " ( ";
90  os << getError(0, 0) << " , ";
91  os << getError(0, 1) << " , ";
92  os << getError(0, 2) << " )" << std::endl;
93  os << " err = ( ";
94  os << getError(1, 0) << " , ";
95  os << getError(1, 1) << " , ";
96  os << getError(1, 2) << " )" << std::endl;
97  os << " ( ";
98  os << getError(2, 0) << " , ";
99  os << getError(2, 1) << " , ";
100  os << getError(2, 2) << " )" << std::endl;
101 
102  os << std::endl;
103  os << "-----------------------------------------------" << std::endl;
104 
105  return;
106 }
107 
109 {
110  if (m_cluskey == TrkrDefs::CLUSKEYMAX) return 0;
111  for (int i = 0; i < 3; ++i)
112  {
113  if (std::isnan(getPosition(i))) return 0;
114  }
115  if (m_adc == 0xFFFFFFFF) return 0;
116  for (int j = 0; j < 3; ++j)
117  {
118  for (int i = j; i < 3; ++i)
119  {
120  if (std::isnan(getSize(i, j))) return 0;
121  if (std::isnan(getError(i, j))) return 0;
122  }
123  }
124 
125  return 1;
126 }
127 
129 {
130  // do nothing if copying onto oneself
131  if( this == &source ) return;
132 
133  // parent class method
134  TrkrCluster::CopyFrom( source );
135 
136  setClusKey( source.getClusKey() );
137  setX( source.getX() );
138  setY( source.getY() );
139  setZ( source.getZ() );
140  m_isGlobal = source.isGlobal();
141  setAdc( source.getAdc() );
142 
143  for (int j = 0; j < 3; ++j)
144  for (int i = 0; i < 3; ++i)
145  {
146  setSize(i, j, source.getSize(i, j));
147  setError(i, j, source.getError(i, j));
148  }
149 }
150 
151 void TrkrClusterv1::setSize(unsigned int i, unsigned int j, float value)
152 {
153  m_size[covarIndex(i, j)] = value;
154  return;
155 }
156 
157 float TrkrClusterv1::getSize(unsigned int i, unsigned int j) const
158 { return m_size[covarIndex(i, j)]; }
159 
160 void TrkrClusterv1::setError(unsigned int i, unsigned int j, float value)
161 {
162  m_err[covarIndex(i, j)] = value;
163  return;
164 }
165 
166 float TrkrClusterv1::getError(unsigned int i, unsigned int j) const
167 { return m_err[covarIndex(i, j)]; }
168 
170 { return 2*std::sqrt(rotate<&TrkrClusterv1::getSize>(this)); }
171 
173 { return 2.*sqrt(getSize(2, 2)); }
174 
176 {
177  const float rad = std::sqrt(square(m_pos[0])+square(m_pos[1]));
178  if (rad > 0) return getRPhiError() / rad;
179  return 0;
180 }
181 
183 { return std::sqrt(rotate<&TrkrClusterv1::getError>( this )); }
184 
186 { return std::sqrt(getError(2, 2)); }