forked from sPHENIX-Collaboration/coresoftware
/
TrkrClusterv2.cc
206 lines (171 loc) · 5.13 KB
/
TrkrClusterv2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* @file trackbase/TrkrClusterv2.cc
* @author J. Osborn
* @date March 2021
* @brief Implementation of TrkrClusterv2
*/
#include "TrkrClusterv2.h"
#include <cmath>
#include <utility> // for swap
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 covarIndex(unsigned int i, unsigned int j)
{
if (i > j) std::swap(i, j);
return i + 1 + (j + 1) * (j) / 2 - 1;
}
// rotate size or covariant matrix to polar coordinates and return the phi component
template<float (TrkrClusterv2::*accessor)(unsigned int, unsigned int) const>
float rotate( const TrkrClusterv2* cluster )
{
const auto phi = -std::atan2(cluster->getY(), cluster->getX());
const auto cosphi = std::cos(phi);
const auto sinphi = std::sin(phi);
return
square(sinphi)*(cluster->*accessor)(0,0) +
square(cosphi)*(cluster->*accessor)(1,1) +
2.*cosphi*sinphi*(cluster->*accessor)(0,1);
}
}
TrkrClusterv2::TrkrClusterv2()
: m_cluskey(TrkrDefs::CLUSKEYMAX)
, m_subsurfkey(TrkrDefs::SUBSURFKEYMAX)
, m_isGlobal(true)
, m_adc(0xFFFFFFFF)
{
for (int i = 0; i < 3; ++i) m_pos[i] = NAN;
for (int j = 0; j < 6; ++j)
{
m_err[j] = NAN;
m_size[j] = NAN;
}
for (int i = 0; i < 2; i++)
{
m_local[i] = NAN;
for(int j = 0; j < 2; j ++)
{
m_actsLocalErr[i][j] = NAN;
}
}
}
void TrkrClusterv2::identify(std::ostream& os) const
{
os << "---TrkrClusterv2--------------------" << std::endl;
os << "clusid: " << getClusKey() << std::dec << std::endl;
os << " (x,y,z) = (" << getPosition(0);
os << ", " << getPosition(1) << ", ";
os << getPosition(2) << ") cm";
if (m_isGlobal)
os << " - global coordinates" << std::endl;
else
os << " - local coordinates" << std::endl;
os << " adc = " << getAdc() << std::endl;
os << " size phi = " << getPhiSize();
os << " cm, size z = " << getZSize() << " cm" << std::endl;
os << " ( ";
os << getSize(0, 0) << " , ";
os << getSize(0, 1) << " , ";
os << getSize(0, 2) << " )" << std::endl;
os << " size = ( ";
os << getSize(1, 0) << " , ";
os << getSize(1, 1) << " , ";
os << getSize(1, 2) << " )" << std::endl;
os << " ( ";
os << getSize(2, 0) << " , ";
os << getSize(2, 1) << " , ";
os << getSize(2, 2) << " )" << std::endl;
os << " ( ";
os << getError(0, 0) << " , ";
os << getError(0, 1) << " , ";
os << getError(0, 2) << " )" << std::endl;
os << " err = ( ";
os << getError(1, 0) << " , ";
os << getError(1, 1) << " , ";
os << getError(1, 2) << " )" << std::endl;
os << " ( ";
os << getError(2, 0) << " , ";
os << getError(2, 1) << " , ";
os << getError(2, 2) << " )" << std::endl;
os << std::endl;
os << "-----------------------------------------------" << std::endl;
return;
}
int TrkrClusterv2::isValid() const
{
if (m_cluskey == TrkrDefs::CLUSKEYMAX) return 0;
for (int i = 0; i < 3; ++i)
{
if (std::isnan(getPosition(i))) return 0;
}
if (m_adc == 0xFFFFFFFF) return 0;
for (int j = 0; j < 3; ++j)
{
for (int i = j; i < 3; ++i)
{
if (std::isnan(getSize(i, j))) return 0;
if (std::isnan(getError(i, j))) return 0;
}
}
return 1;
}
void TrkrClusterv2::CopyFrom( const TrkrCluster& source )
{
// do nothing if copying onto oneself
if( this == &source ) return;
// parent class method
TrkrCluster::CopyFrom( source );
setClusKey( source.getClusKey() );
setX( source.getX() );
setY( source.getY() );
setZ( source.getZ() );
m_isGlobal = source.isGlobal();
setAdc( source.getAdc() );
for (int j = 0; j < 3; ++j)
for (int i = 0; i < 3; ++i)
{
setSize(i, j, source.getSize(i, j));
setError(i, j, source.getError(i, j));
}
setSubSurfKey( source.getSubSurfKey() );
setLocalX( source.getLocalX() );
setLocalY( source.getLocalY() );
for (int j = 0; j < 2; ++j)
for (int i = 0; i < 2; ++i)
{ setActsLocalError(i, j, source.getActsLocalError(i, j)); }
}
void TrkrClusterv2::setSize(unsigned int i, unsigned int j, float value)
{
m_size[covarIndex(i, j)] = value;
return;
}
float TrkrClusterv2::getSize(unsigned int i, unsigned int j) const
{ return m_size[covarIndex(i, j)]; }
void TrkrClusterv2::setError(unsigned int i, unsigned int j, float value)
{
m_err[covarIndex(i, j)] = value;
return;
}
float TrkrClusterv2::getError(unsigned int i, unsigned int j) const
{ return m_err[covarIndex(i, j)]; }
float TrkrClusterv2::getPhiSize() const
{ return 2*std::sqrt(rotate<&TrkrClusterv2::getSize>(this)); }
float TrkrClusterv2::getZSize() const
{ return 2.*sqrt(getSize(2, 2)); }
float TrkrClusterv2::getPhiError() const
{
const float rad = std::sqrt(square(m_pos[0])+square(m_pos[1]));
if (rad > 0) return getRPhiError() / rad;
return 0;
}
float TrkrClusterv2::getRPhiError() const
{ return std::sqrt(rotate<&TrkrClusterv2::getError>( this )); }
float TrkrClusterv2::getZError() const
{ return std::sqrt(getError(2, 2)); }
void TrkrClusterv2::setActsLocalError(unsigned int i, unsigned int j,
float value)
{
m_actsLocalErr[i][j] = value;
}