-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathAlignmentPoint.cxx
More file actions
389 lines (360 loc) · 12 KB
/
AlignmentPoint.cxx
File metadata and controls
389 lines (360 loc) · 12 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file AlignmentPoint.h
/// @author ruben.shahoyan@cern.ch, michael.lettrich@cern.ch
/// @since 2021-02-01
/// @brief Meausered point in the sensor.
#include <cstdio>
#include <TMath.h>
#include <TString.h>
#include "Align/AlignmentPoint.h"
using namespace o2::align::utils;
using namespace TMath;
namespace o2
{
namespace align
{
//_____________________________________
void AlignmentPoint::init()
{
// compute aux info
const double kCorrToler = 1e-6;
const double kDiagToler = 1e-14;
//
// compute parameters of tranformation to diagonal error matrix
if (!isZeroPos(mErrYZTracking[0] + mErrYZTracking[2])) {
//
// is there a correlation?
if (math_utils::detail::abs(mErrYZTracking[1] * mErrYZTracking[1] / (mErrYZTracking[0] * mErrYZTracking[2])) < kCorrToler) {
mCosDiagErr = 1.;
mSinDiagErr = 0.;
mErrDiag[0] = mErrYZTracking[0];
mErrDiag[1] = mErrYZTracking[2];
} else {
double dfd = 0.5 * (mErrYZTracking[2] - mErrYZTracking[0]);
double phi = 0;
// special treatment if errors are equal
if (Abs(dfd) < kDiagToler) {
phi = mErrYZTracking[1] > 0 ? (Pi() * 0.25) : (Pi() * 0.75);
} else {
phi = 0.5 * ATan2(mErrYZTracking[1], dfd);
}
//
mCosDiagErr = Cos(phi);
mSinDiagErr = Sin(phi);
//
// double det = dfd*dfd + mErrYZTracking[1]*mErrYZTracking[1];
// det = det>0 ? Sqrt(det) : 0;
// double smd = 0.5*(mErrYZTracking[0] + mErrYZTracking[2]);
// mErrDiag[0] = smd + det;
// mErrDiag[1] = smd - det;
double xterm = 2 * mCosDiagErr * mSinDiagErr * mErrYZTracking[1];
double cc = mCosDiagErr * mCosDiagErr;
double ss = mSinDiagErr * mSinDiagErr;
mErrDiag[0] = mErrYZTracking[0] * cc + mErrYZTracking[2] * ss - xterm;
mErrDiag[1] = mErrYZTracking[0] * ss + mErrYZTracking[2] * cc + xterm;
}
}
//
}
//_____________________________________
void AlignmentPoint::updatePointByTrackInfo(const trackParam_t* t)
{
// // recalculate point errors using info about the track in the sensor tracking frame
mSensor->updatePointByTrackInfo(this, t);
}
//_____________________________________
void AlignmentPoint::print(uint16_t opt) const
{
// print
printf("%cDet%d SID:%4d Alp:%+.3f X:%+9.4f Meas:%s Mat: ", isInvDir() ? '*' : ' ',
getDetID(), getSID(), getAlphaSens(), getXSens(), containsMeasurement() ? "ON" : "OFF");
if (!containsMaterial()) {
printf("OFF\n");
} else {
printf("x2X0: %.4f x*rho: %.4f | pars:[%3d:%3d)\n", getX2X0(), getXTimesRho(), getMinLocVarID(), getMaxLocVarID());
}
//
if ((opt & kMeasurementBit) && containsMeasurement()) {
printf(" MeasPnt: Xtr: %+9.4f Ytr: %+8.4f Ztr: %+9.4f | ErrYZ: %+e %+e %+e | %d DOFglo\n",
getXTracking(), getYTracking(), getZTracking(),
mErrYZTracking[0], mErrYZTracking[1], mErrYZTracking[2], getNGloDOFs());
printf(" DiagErr: %+e %+e\n", mErrDiag[0], mErrDiag[1]);
}
//
if ((opt & kMaterialBit) && containsMaterial()) {
printf(" MatCorr Exp(ELOSS): %+.4e %+.4e %+.4e %+.4e %+.4e\n",
mMatCorrExp[0], mMatCorrExp[1], mMatCorrExp[2], mMatCorrExp[3], mMatCorrExp[4]);
printf(" MatCorr Cov (diag): %+.4e %+.4e %+.4e %+.4e %+.4e\n",
mMatCorrCov[0], mMatCorrCov[1], mMatCorrCov[2], mMatCorrCov[3], mMatCorrCov[4]);
//
if (opt & kOptUMAT) {
float covUndiag[15];
memset(covUndiag, 0, 15 * sizeof(float));
int np = getNMatPar();
for (int i = 0; i < np; i++) {
for (int j = 0; j <= i; j++) {
double val = 0;
for (int k = np; k--;) {
val += mMatDiag[i][k] * mMatDiag[j][k] * mMatCorrCov[k];
}
int ij = (i * (i + 1) / 2) + j;
covUndiag[ij] = val;
}
}
if (np < kNMatDOFs) {
covUndiag[14] = mMatCorrCov[4];
} // eloss was fixed
printf(" MatCorr Cov in normal form:\n");
printf(" %+e\n", covUndiag[0]);
printf(" %+e %+e\n", covUndiag[1], covUndiag[2]);
printf(" %+e %+e %+e\n", covUndiag[3], covUndiag[4], covUndiag[5]);
printf(" %+e %+e %+e %+e\n", covUndiag[6], covUndiag[7], covUndiag[8], covUndiag[9]);
printf(" %+e %+e %+e %+e +%e\n", covUndiag[10], covUndiag[11], covUndiag[12], covUndiag[13], covUndiag[14]);
}
}
//
if ((opt & kOptDiag) && containsMaterial()) {
printf(" Matrix for Mat.corr.errors diagonalization:\n");
int npar = getNMatPar();
for (int i = 0; i < npar; i++) {
for (int j = 0; j < npar; j++) {
printf("%+.4e ", mMatDiag[i][j]);
}
printf("\n");
}
}
//
if (opt & kOptWSA) { // printf track state at this point stored during residuals calculation
printf(" Local Track (A): ");
for (int i = 0; i < 5; i++) {
printf("%+.3e ", mTrParamWSA[i]);
}
printf("\n");
}
if (opt & kOptWSB) { // printf track state at this point stored during residuals calculation
printf(" Local Track (B): ");
for (int i = 0; i < 5; i++) {
printf("%+.3e ", mTrParamWSB[i]);
}
printf("\n");
}
//
}
//_____________________________________
void AlignmentPoint::dumpCoordinates() const
{
// dump various corrdinates for inspection
// global xyz
dim3_t xyz;
getXYZGlo(xyz.data());
auto print3d = [](dim3_t& xyz) {
for (auto i : xyz) {
printf("%+.4e ", i);
}
};
print3d(xyz);
trackParam_t wsb;
trackParam_t wsa;
getTrWSB(wsb);
getTrWSA(wsa);
wsb.getXYZGlo(xyz);
print3d(xyz); // track before mat corr
wsa.getXYZGlo(xyz);
print3d(xyz); // track after mat corr
printf("%+.4f ", mAlphaSens);
printf("%+.4e ", getXTracking());
printf("%+.4e ", getYTracking());
printf("%+.4e ", getZTracking());
//
printf("%+.4e %.4e ", wsb.getY(), wsb.getZ());
printf("%+.4e %.4e ", wsa.getY(), wsa.getZ());
//
printf("%4e %4e", Sqrt(mErrYZTracking[0]), Sqrt(mErrYZTracking[2]));
printf("\n");
}
//_____________________________________
void AlignmentPoint::clear()
{
// reset the point
mBits = 0;
mMaxLocVarID = -1;
mDetID = -1;
mSID = -1;
mNGloDOFs = 0;
mDGloOffs = 0;
mSensor = nullptr;
setXYZTracking(0., 0., 0.);
}
//__________________________________________________________________
bool AlignmentPoint::isAfter(const AlignmentPoint& pnt) const
{
// sort points in direction opposite to track propagation, i.e.
// 1) for tracks from collision: range in decreasing tracking X
// 2) for cosmic tracks: upper leg (pnt->isInvDir()==true) ranged in increasing X
// lower leg - in decreasing X
double x = getXTracking();
double xp = pnt.getXTracking();
if (!isInvDir()) { // track propagates from low to large X via this point
if (!pnt.isInvDir()) { // via this one also
return x > xp ? -1 : 1;
} else {
return true; // any point on the lower leg has higher priority than on the upper leg
} // range points of lower leg 1st
} else { // this point is from upper cosmic leg: track propagates from large to low X
if (pnt.isInvDir()) { // this one also
return x > xp ? 1 : -1;
} else {
return 1;
} // other point is from lower leg
}
//
}
//__________________________________________________________________
void AlignmentPoint::getXYZGlo(double r[3]) const
{
// position in lab frame
double cs = TMath::Cos(mAlphaSens);
double sn = TMath::Sin(mAlphaSens);
double x = getXTracking();
r[0] = x * cs - getYTracking() * sn;
r[1] = x * sn + getYTracking() * cs;
r[2] = getZTracking();
//
}
//__________________________________________________________________
double AlignmentPoint::getPhiGlo() const
{
// phi angle (-pi:pi) in global frame
double xyz[3];
getXYZGlo(xyz);
return ATan2(xyz[1], xyz[0]);
}
//__________________________________________________________________
int AlignmentPoint::getAliceSector() const
{
// get global sector ID corresponding to this point phi
return math_utils::detail::angle2Sector(getPhiGlo());
}
//__________________________________________________________________
void AlignmentPoint::setMatCovDiagonalizationMatrix(const TMatrixD& d)
{
// save non-sym matrix for material corrections cov.matrix diagonalization
// (actually, the eigenvectors are stored)
int sz = d.GetNrows();
for (int i = sz; i--;) {
for (int j = sz; j--;) {
mMatDiag[i][j] = d(i, j);
}
}
}
//__________________________________________________________________
void AlignmentPoint::setMatCovDiag(const TVectorD& v)
{
// save material correction diagonalized matrix
// (actually, the eigenvalues are stored w/o reordering them to correspond to the
// AliExternalTrackParam variables)
for (int i = v.GetNrows(); i--;) {
mMatCorrCov[i] = v(i);
}
}
//__________________________________________________________________
void AlignmentPoint::unDiagMatCorr(const double* diag, double* nodiag) const
{
// transform material corrections from the frame diagonalizing the errors to point frame
// nodiag = mMatDiag * diag
int np = getNMatPar();
for (int ip = np; ip--;) {
double v = 0;
for (int jp = np; jp--;) {
v += mMatDiag[ip][jp] * diag[jp];
}
nodiag[ip] = v;
}
//
}
//__________________________________________________________________
void AlignmentPoint::unDiagMatCorr(const float* diag, float* nodiag) const
{
// transform material corrections from the frame diagonalizing the errors to point frame
// nodiag = mMatDiag * diag
int np = getNMatPar();
for (int ip = np; ip--;) {
double v = 0;
for (int jp = np; jp--;) {
v += double(mMatDiag[ip][jp]) * diag[jp];
}
nodiag[ip] = v;
}
//
}
//__________________________________________________________________
void AlignmentPoint::diagMatCorr(const double* nodiag, double* diag) const
{
// transform material corrections from the AliExternalTrackParam frame to
// the frame diagonalizing the errors
// diag = mMatDiag^T * nodiag
int np = getNMatPar();
for (int ip = np; ip--;) {
double v = 0;
for (int jp = np; jp--;) {
v += mMatDiag[jp][ip] * nodiag[jp];
}
diag[ip] = v;
}
//
}
//__________________________________________________________________
void AlignmentPoint::diagMatCorr(const float* nodiag, float* diag) const
{
// transform material corrections from the AliExternalTrackParam frame to
// the frame diagonalizing the errors
// diag = mMatDiag^T * nodiag
int np = getNMatPar();
for (int ip = np; ip--;) {
double v = 0;
for (int jp = np; jp--;) {
v += double(mMatDiag[jp][ip]) * nodiag[jp];
}
diag[ip] = v;
}
//
}
//__________________________________________________________________
void AlignmentPoint::getTrWSA(trackParam_t& etp) const
{
// assign WSA (after material corrections) parameters to supplied track
const trackParam_t::covMat_t covDum{
1.e-4,
0, 1.e-4,
0, 0, 1.e-4,
0, 0, 0, 1.e-4,
0, 0, 0, 0, 1e-4};
params_t tmp;
std::copy(std::begin(mTrParamWSA), std::end(mTrParamWSA), std::begin(tmp));
etp.set(getXTracking(), getAlphaSens(), tmp, covDum);
}
//__________________________________________________________________
void AlignmentPoint::getTrWSB(trackParam_t& etp) const
{
// assign WSB parameters (before material corrections) to supplied track
const trackParam_t::covMat_t covDum{
1.e-4,
0, 1.e-4,
0, 0, 1.e-4,
0, 0, 0, 1.e-4,
0, 0, 0, 0, 1e-4};
params_t tmp;
std::copy(std::begin(mTrParamWSB), std::end(mTrParamWSB), std::begin(tmp));
etp.set(getXTracking(), getAlphaSens(), tmp, covDum);
}
} // namespace align
} // namespace o2