-
Notifications
You must be signed in to change notification settings - Fork 184
/
ActsGeometry.cc
238 lines (197 loc) · 6.71 KB
/
ActsGeometry.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "ActsGeometry.h"
#include <Acts/Definitions/Algebra.hpp>
#include "TpcDefs.h"
#include "TrkrCluster.h"
#include "alignmentTransformationContainer.h"
namespace
{
/// square
template <class T>
inline constexpr T square(const T& x)
{
return x * x;
}
/// get radius from coordinates
template <class T>
T radius(const T& x, const T& y)
{
return std::sqrt(square(x) + square(y));
}
} // namespace
Eigen::Matrix<float, 3, 1> ActsGeometry::getGlobalPositionF(
TrkrDefs::cluskey key,
TrkrCluster* cluster)
{
Acts::Vector3 doublePos = getGlobalPosition(key, cluster);
return Eigen::Matrix<float, 3, 1>(doublePos(0), doublePos(1), doublePos(2));
}
Acts::Vector3 ActsGeometry::getGlobalPosition(TrkrDefs::cluskey key, TrkrCluster* cluster)
{
Acts::Vector3 glob;
const auto trkrid = TrkrDefs::getTrkrId(key);
if (trkrid == TrkrDefs::tpcId)
{
return getGlobalPositionTpc(key, cluster);
}
/// If silicon/TPOT, the transform is one-to-one since the surface is planar
auto surface = maps().getSurface(key, cluster);
if (!surface)
{
std::cerr << "Couldn't identify cluster surface. Returning NAN"
<< std::endl;
glob(0) = NAN;
glob(1) = NAN;
glob(2) = NAN;
return glob;
}
Acts::Vector2 local(cluster->getLocalX(), cluster->getLocalY());
Acts::Vector3 global;
global = surface->localToGlobal(geometry().getGeoContext(),
local * Acts::UnitConstants::cm,
Acts::Vector3(1, 1, 1));
global /= Acts::UnitConstants::cm;
return global;
}
Acts::Vector3 ActsGeometry::getGlobalPositionTpc(TrkrDefs::cluskey key, TrkrCluster* cluster)
{
Acts::Vector3 glob;
// This method is for the TPC only
const auto trkrid = TrkrDefs::getTrkrId(key);
if (trkrid != TrkrDefs::tpcId)
{
std::cout << "ActsGeometry::getGlobalPositionTpc - this is the wrong global transform for silicon or MM's clusters! Returning zero" << std::endl;
return glob;
}
auto surface = maps().getSurface(key, cluster);
if (!surface)
{
std::cerr << "Couldn't identify cluster surface. Returning NAN"
<< std::endl;
glob(0) = NAN;
glob(1) = NAN;
glob(2) = NAN;
return glob;
}
double surfaceZCenter = 52.89; // this is where G4 thinks the surface center is in cm
double zdriftlength = cluster->getLocalY() * _drift_velocity; // cm
double zloc = surfaceZCenter - zdriftlength; // local z relative to surface center (for north side):
unsigned int side = TpcDefs::getSide(key);
if (side == 0)
{
zloc = -zloc;
}
Acts::Vector2 local(cluster->getLocalX(), zloc);
glob = surface->localToGlobal(geometry().getGeoContext(),
local * Acts::UnitConstants::cm,
Acts::Vector3(1, 1, 1));
glob /= Acts::UnitConstants::cm;
return glob;
}
Surface ActsGeometry::get_tpc_surface_from_coords(
TrkrDefs::hitsetkey hitsetkey,
Acts::Vector3 world,
TrkrDefs::subsurfkey& subsurfkey)
{
unsigned int layer = TrkrDefs::getLayer(hitsetkey);
unsigned int side = TpcDefs::getSide(hitsetkey);
auto mapIter = maps().m_tpcSurfaceMap.find(layer);
if (mapIter == maps().m_tpcSurfaceMap.end())
{
std::cout << "Error: hitsetkey not found in ActsGeometry::get_tpc_surface_from_coords, hitsetkey = "
<< hitsetkey << std::endl;
return nullptr;
}
double world_phi = atan2(world[1], world[0]);
std::vector<Surface>& surf_vec = mapIter->second;
unsigned int surf_index = 999;
// Predict which surface index this phi and side will correspond to
// assumes that the vector elements are ordered positive z, -pi to pi, then negative z, -pi to pi
// we use TPC side from the hitsetkey, since z can be either sign in northa nd south, depending on crossing
double fraction = (world_phi + M_PI) / (2.0 * M_PI);
double rounded_nsurf = round((double) (surf_vec.size() / 2) * fraction - 0.5); // NOLINT
unsigned int nsurfm = (unsigned int) rounded_nsurf;
if (side == 0)
{
nsurfm += surf_vec.size() / 2;
}
unsigned int nsurf = nsurfm % surf_vec.size();
Surface this_surf = surf_vec[nsurf];
auto vec3d = this_surf->center(geometry().getGeoContext());
std::vector<double> surf_center = {vec3d(0) / 10.0, vec3d(1) / 10.0, vec3d(2) / 10.0}; // convert from mm to cm
double surf_phi = atan2(surf_center[1], surf_center[0]);
double surfStepPhi = geometry().tpcSurfStepPhi;
if ((world_phi > surf_phi - surfStepPhi / 2.0 && world_phi < surf_phi + surfStepPhi / 2.0))
{
surf_index = nsurf;
subsurfkey = nsurf;
}
else
{
return nullptr;
}
return surf_vec[surf_index];
}
Acts::Transform3 ActsGeometry::makeAffineTransform(Acts::Vector3 rot, Acts::Vector3 trans)
{
Acts::Transform3 actsAffine;
Eigen::AngleAxisd alpha(rot(0), Eigen::Vector3d::UnitX());
Eigen::AngleAxisd beta(rot(1), Eigen::Vector3d::UnitY());
Eigen::AngleAxisd gamma(rot(2), Eigen::Vector3d::UnitZ());
Eigen::Quaternion<double> q = gamma * beta * alpha;
actsAffine.linear() = q.matrix();
Eigen::Vector3d translation(trans(0), trans(1), trans(2));
actsAffine.translation() = translation;
return actsAffine;
}
Acts::Vector2 ActsGeometry::getLocalCoords(TrkrDefs::cluskey key, TrkrCluster* cluster)
{
Acts::Vector2 local;
const auto trkrid = TrkrDefs::getTrkrId(key);
if (trkrid == TrkrDefs::tpcId)
{
double surfaceZCenter = 52.89; // this is where G4 thinks the surface center is in cm
double zdriftlength = cluster->getLocalY() * _drift_velocity; // cm
double zloc = surfaceZCenter - zdriftlength; // local z relative to surface center (for north side):
unsigned int side = TpcDefs::getSide(key);
if (side == 0)
{
zloc = -zloc;
}
local(0) = cluster->getLocalX();
local(1) = zloc;
}
else
{
local(0) = cluster->getLocalX();
local(1) = cluster->getLocalY();
}
return local;
}
Acts::Vector2 ActsGeometry::getCrossingCorrectedLocalCoords(TrkrDefs::cluskey key, TrkrCluster* cluster, int crossing)
{
Acts::Vector2 local;
const auto trkrid = TrkrDefs::getTrkrId(key);
if (trkrid == TrkrDefs::tpcId)
{
local = getLocalCoords(key, cluster);
double crossing_correction = (double) crossing * _crossing_period * _drift_velocity;
double zloc;
unsigned int side = TpcDefs::getSide(key);
if (side == 1)
{
zloc = local(1) + crossing_correction; // north correction is positive for positive crossings
}
else
{
zloc = local(1) - crossing_correction;
}
local(0) = cluster->getLocalX();
local(1) = zloc;
}
else
{
local(0) = cluster->getLocalX();
local(1) = cluster->getLocalY();
}
return local;
}