Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrkrClusterv2.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrkrClusterv2.cc
1 
7 #include "TrkrClusterv2.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 (TrkrClusterv2::*accessor)(unsigned int, unsigned int) const>
27  float rotate( const TrkrClusterv2* 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_subsurfkey(TrkrDefs::SUBSURFKEYMAX)
44  , m_isGlobal(true)
45  , m_adc(0xFFFFFFFF)
46 {
47  for (int i = 0; i < 3; ++i) m_pos[i] = NAN;
48 
49  for (int j = 0; j < 6; ++j)
50  {
51  m_err[j] = NAN;
52  m_size[j] = NAN;
53  }
54  for (int i = 0; i < 2; i++)
55  {
56  m_local[i] = NAN;
57  for(int j = 0; j < 2; j ++)
58  {
59  m_actsLocalErr[i][j] = NAN;
60  }
61  }
62 }
63 
64 void TrkrClusterv2::identify(std::ostream& os) const
65 {
66  os << "---TrkrClusterv2--------------------" << std::endl;
67 
68  os << " (x,y,z) = (" << getPosition(0);
69  os << ", " << getPosition(1) << ", ";
70  os << getPosition(2) << ") cm";
71  if (m_isGlobal)
72  os << " - global coordinates" << std::endl;
73  else
74  os << " - local coordinates" << std::endl;
75 
76  os << " adc = " << getAdc() << std::endl;
77 
78  os << " size phi = " << getPhiSize();
79  os << " cm, size z = " << getZSize() << " cm" << std::endl;
80 
81  os << " ( ";
82  os << getSize(0, 0) << " , ";
83  os << getSize(0, 1) << " , ";
84  os << getSize(0, 2) << " )" << std::endl;
85  os << " size = ( ";
86  os << getSize(1, 0) << " , ";
87  os << getSize(1, 1) << " , ";
88  os << getSize(1, 2) << " )" << std::endl;
89  os << " ( ";
90  os << getSize(2, 0) << " , ";
91  os << getSize(2, 1) << " , ";
92  os << getSize(2, 2) << " )" << std::endl;
93 
94  os << " ( ";
95  os << getError(0, 0) << " , ";
96  os << getError(0, 1) << " , ";
97  os << getError(0, 2) << " )" << std::endl;
98  os << " err = ( ";
99  os << getError(1, 0) << " , ";
100  os << getError(1, 1) << " , ";
101  os << getError(1, 2) << " )" << std::endl;
102  os << " ( ";
103  os << getError(2, 0) << " , ";
104  os << getError(2, 1) << " , ";
105  os << getError(2, 2) << " )" << std::endl;
106 
107  os << std::endl;
108  os << "-----------------------------------------------" << std::endl;
109 
110  return;
111 }
112 
114 {
115  if (m_cluskey == TrkrDefs::CLUSKEYMAX) return 0;
116  for (int i = 0; i < 3; ++i)
117  {
118  if (std::isnan(getPosition(i))) return 0;
119  }
120  if (m_adc == 0xFFFFFFFF) return 0;
121  for (int j = 0; j < 3; ++j)
122  {
123  for (int i = j; i < 3; ++i)
124  {
125  if (std::isnan(getSize(i, j))) return 0;
126  if (std::isnan(getError(i, j))) return 0;
127  }
128  }
129 
130  return 1;
131 }
132 
134 {
135  // do nothing if copying onto oneself
136  if( this == &source ) return;
137 
138  // parent class method
139  TrkrCluster::CopyFrom( source );
140 
141  setX( source.getX() );
142  setY( source.getY() );
143  setZ( source.getZ() );
144  m_isGlobal = source.isGlobal();
145  setAdc( source.getAdc() );
146 
147  for (int j = 0; j < 3; ++j)
148  for (int i = 0; i < 3; ++i)
149  {
150  setSize(i, j, source.getSize(i, j));
151  setError(i, j, source.getError(i, j));
152  }
153 
154  setSubSurfKey( source.getSubSurfKey() );
155  setLocalX( source.getLocalX() );
156  setLocalY( source.getLocalY() );
157 
158  for (int j = 0; j < 2; ++j)
159  for (int i = 0; i < 2; ++i)
160  { setActsLocalError(i, j, source.getActsLocalError(i, j)); }
161 }
162 
163 void TrkrClusterv2::setSize(unsigned int i, unsigned int j, float value)
164 {
165  m_size[covarIndex(i, j)] = value;
166  return;
167 }
168 
169 float TrkrClusterv2::getSize(unsigned int i, unsigned int j) const
170 { return m_size[covarIndex(i, j)]; }
171 
172 void TrkrClusterv2::setError(unsigned int i, unsigned int j, float value)
173 {
174  m_err[covarIndex(i, j)] = value;
175  return;
176 }
177 
178 float TrkrClusterv2::getError(unsigned int i, unsigned int j) const
179 { return m_err[covarIndex(i, j)]; }
180 
182 { return 2*std::sqrt(rotate<&TrkrClusterv2::getSize>(this)); }
183 
185 { return 2.*sqrt(getSize(2, 2)); }
186 
188 {
189  const float rad = std::sqrt(square(m_pos[0])+square(m_pos[1]));
190  if (rad > 0) return getRPhiError() / rad;
191  return 0;
192 }
193 
195 { return std::sqrt(rotate<&TrkrClusterv2::getError>( this )); }
196 
198 { return std::sqrt(getError(2, 2)); }
199 
200 void TrkrClusterv2::setActsLocalError(unsigned int i, unsigned int j,
201  float value)
202 {
203  m_actsLocalErr[i][j] = value;
204 }