Project
Loading...
Searching...
No Matches
AlignmentPoint.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#include <cstdio>
18#include <TMath.h>
19#include <TString.h>
21
22using namespace o2::align::utils;
23using namespace TMath;
24
25namespace o2
26{
27namespace align
28{
29
30//_____________________________________
32{
33 // compute aux info
34 const double kCorrToler = 1e-6;
35 const double kDiagToler = 1e-14;
36 //
37 // compute parameters of tranformation to diagonal error matrix
39 //
40 // is there a correlation?
41 if (math_utils::detail::abs(mErrYZTracking[1] * mErrYZTracking[1] / (mErrYZTracking[0] * mErrYZTracking[2])) < kCorrToler) {
42 mCosDiagErr = 1.;
43 mSinDiagErr = 0.;
46 } else {
47 double dfd = 0.5 * (mErrYZTracking[2] - mErrYZTracking[0]);
48 double phi = 0;
49 // special treatment if errors are equal
50 if (Abs(dfd) < kDiagToler) {
51 phi = mErrYZTracking[1] > 0 ? (Pi() * 0.25) : (Pi() * 0.75);
52 } else {
53 phi = 0.5 * ATan2(mErrYZTracking[1], dfd);
54 }
55 //
56 mCosDiagErr = Cos(phi);
57 mSinDiagErr = Sin(phi);
58 //
59 // double det = dfd*dfd + mErrYZTracking[1]*mErrYZTracking[1];
60 // det = det>0 ? Sqrt(det) : 0;
61 // double smd = 0.5*(mErrYZTracking[0] + mErrYZTracking[2]);
62 // mErrDiag[0] = smd + det;
63 // mErrDiag[1] = smd - det;
64 double xterm = 2 * mCosDiagErr * mSinDiagErr * mErrYZTracking[1];
65 double cc = mCosDiagErr * mCosDiagErr;
66 double ss = mSinDiagErr * mSinDiagErr;
67 mErrDiag[0] = mErrYZTracking[0] * cc + mErrYZTracking[2] * ss - xterm;
68 mErrDiag[1] = mErrYZTracking[0] * ss + mErrYZTracking[2] * cc + xterm;
69 }
70 }
71 //
72}
73
74//_____________________________________
76{
77 // // recalculate point errors using info about the track in the sensor tracking frame
79}
80
81//_____________________________________
82void AlignmentPoint::print(uint16_t opt) const
83{
84 // print
85 printf("%cDet%d SID:%4d Alp:%+.3f X:%+9.4f Meas:%s Mat: ", isInvDir() ? '*' : ' ',
86 getDetID(), getSID(), getAlphaSens(), getXSens(), containsMeasurement() ? "ON" : "OFF");
87 if (!containsMaterial()) {
88 printf("OFF\n");
89 } else {
90 printf("x2X0: %.4f x*rho: %.4f | pars:[%3d:%3d)\n", getX2X0(), getXTimesRho(), getMinLocVarID(), getMaxLocVarID());
91 }
92 //
93 if ((opt & kMeasurementBit) && containsMeasurement()) {
94 printf(" MeasPnt: Xtr: %+9.4f Ytr: %+8.4f Ztr: %+9.4f | ErrYZ: %+e %+e %+e | %d DOFglo\n",
97 printf(" DiagErr: %+e %+e\n", mErrDiag[0], mErrDiag[1]);
98 }
99 //
100 if ((opt & kMaterialBit) && containsMaterial()) {
101 printf(" MatCorr Exp(ELOSS): %+.4e %+.4e %+.4e %+.4e %+.4e\n",
103 printf(" MatCorr Cov (diag): %+.4e %+.4e %+.4e %+.4e %+.4e\n",
105 //
106 if (opt & kOptUMAT) {
107 float covUndiag[15];
108 memset(covUndiag, 0, 15 * sizeof(float));
109 int np = getNMatPar();
110 for (int i = 0; i < np; i++) {
111 for (int j = 0; j <= i; j++) {
112 double val = 0;
113 for (int k = np; k--;) {
114 val += mMatDiag[i][k] * mMatDiag[j][k] * mMatCorrCov[k];
115 }
116 int ij = (i * (i + 1) / 2) + j;
117 covUndiag[ij] = val;
118 }
119 }
120 if (np < kNMatDOFs) {
121 covUndiag[14] = mMatCorrCov[4];
122 } // eloss was fixed
123 printf(" MatCorr Cov in normal form:\n");
124 printf(" %+e\n", covUndiag[0]);
125 printf(" %+e %+e\n", covUndiag[1], covUndiag[2]);
126 printf(" %+e %+e %+e\n", covUndiag[3], covUndiag[4], covUndiag[5]);
127 printf(" %+e %+e %+e %+e\n", covUndiag[6], covUndiag[7], covUndiag[8], covUndiag[9]);
128 printf(" %+e %+e %+e %+e +%e\n", covUndiag[10], covUndiag[11], covUndiag[12], covUndiag[13], covUndiag[14]);
129 }
130 }
131 //
132 if ((opt & kOptDiag) && containsMaterial()) {
133 printf(" Matrix for Mat.corr.errors diagonalization:\n");
134 int npar = getNMatPar();
135 for (int i = 0; i < npar; i++) {
136 for (int j = 0; j < npar; j++) {
137 printf("%+.4e ", mMatDiag[i][j]);
138 }
139 printf("\n");
140 }
141 }
142 //
143 if (opt & kOptWSA) { // printf track state at this point stored during residuals calculation
144 printf(" Local Track (A): ");
145 for (int i = 0; i < 5; i++) {
146 printf("%+.3e ", mTrParamWSA[i]);
147 }
148 printf("\n");
149 }
150 if (opt & kOptWSB) { // printf track state at this point stored during residuals calculation
151 printf(" Local Track (B): ");
152 for (int i = 0; i < 5; i++) {
153 printf("%+.3e ", mTrParamWSB[i]);
154 }
155 printf("\n");
156 }
157 //
158}
159
160//_____________________________________
162{
163 // dump various corrdinates for inspection
164 // global xyz
165 dim3_t xyz;
166 getXYZGlo(xyz.data());
167
168 auto print3d = [](dim3_t& xyz) {
169 for (auto i : xyz) {
170 printf("%+.4e ", i);
171 }
172 };
173
174 print3d(xyz);
175 trackParam_t wsb;
176 trackParam_t wsa;
177 getTrWSB(wsb);
178 getTrWSA(wsa);
179
180 wsb.getXYZGlo(xyz);
181 print3d(xyz); // track before mat corr
182
183 wsa.getXYZGlo(xyz);
184 print3d(xyz); // track after mat corr
185
186 printf("%+.4f ", mAlphaSens);
187 printf("%+.4e ", getXTracking());
188 printf("%+.4e ", getYTracking());
189 printf("%+.4e ", getZTracking());
190 //
191 printf("%+.4e %.4e ", wsb.getY(), wsb.getZ());
192 printf("%+.4e %.4e ", wsa.getY(), wsa.getZ());
193 //
194 printf("%4e %4e", Sqrt(mErrYZTracking[0]), Sqrt(mErrYZTracking[2]));
195 printf("\n");
196}
197
198//_____________________________________
200{
201 // reset the point
202 mBits = 0;
203 mMaxLocVarID = -1;
204 mDetID = -1;
205 mSID = -1;
206 mNGloDOFs = 0;
207 mDGloOffs = 0;
208 mSensor = nullptr;
209 setXYZTracking(0., 0., 0.);
210}
211
212//__________________________________________________________________
214{
215 // sort points in direction opposite to track propagation, i.e.
216 // 1) for tracks from collision: range in decreasing tracking X
217 // 2) for cosmic tracks: upper leg (pnt->isInvDir()==true) ranged in increasing X
218 // lower leg - in decreasing X
219 double x = getXTracking();
220 double xp = pnt.getXTracking();
221 if (!isInvDir()) { // track propagates from low to large X via this point
222 if (!pnt.isInvDir()) { // via this one also
223 return x > xp ? -1 : 1;
224 } else {
225 return true; // any point on the lower leg has higher priority than on the upper leg
226 } // range points of lower leg 1st
227 } else { // this point is from upper cosmic leg: track propagates from large to low X
228 if (pnt.isInvDir()) { // this one also
229 return x > xp ? 1 : -1;
230 } else {
231 return 1;
232 } // other point is from lower leg
233 }
234 //
235}
236
237//__________________________________________________________________
238void AlignmentPoint::getXYZGlo(double r[3]) const
239{
240 // position in lab frame
241 double cs = TMath::Cos(mAlphaSens);
242 double sn = TMath::Sin(mAlphaSens);
243 double x = getXTracking();
244 r[0] = x * cs - getYTracking() * sn;
245 r[1] = x * sn + getYTracking() * cs;
246 r[2] = getZTracking();
247 //
248}
249
250//__________________________________________________________________
252{
253 // phi angle (-pi:pi) in global frame
254 double xyz[3];
255 getXYZGlo(xyz);
256 return ATan2(xyz[1], xyz[0]);
257}
258
259//__________________________________________________________________
261{
262 // get global sector ID corresponding to this point phi
263 return math_utils::detail::angle2Sector(getPhiGlo());
264}
265
266//__________________________________________________________________
268{
269 // save non-sym matrix for material corrections cov.matrix diagonalization
270 // (actually, the eigenvectors are stored)
271 int sz = d.GetNrows();
272 for (int i = sz; i--;) {
273 for (int j = sz; j--;) {
274 mMatDiag[i][j] = d(i, j);
275 }
276 }
277}
278
279//__________________________________________________________________
280void AlignmentPoint::setMatCovDiag(const TVectorD& v)
281{
282 // save material correction diagonalized matrix
283 // (actually, the eigenvalues are stored w/o reordering them to correspond to the
284 // AliExternalTrackParam variables)
285 for (int i = v.GetNrows(); i--;) {
286 mMatCorrCov[i] = v(i);
287 }
288}
289
290//__________________________________________________________________
291void AlignmentPoint::unDiagMatCorr(const double* diag, double* nodiag) const
292{
293 // transform material corrections from the frame diagonalizing the errors to point frame
294 // nodiag = mMatDiag * diag
295 int np = getNMatPar();
296 for (int ip = np; ip--;) {
297 double v = 0;
298 for (int jp = np; jp--;) {
299 v += mMatDiag[ip][jp] * diag[jp];
300 }
301 nodiag[ip] = v;
302 }
303 //
304}
305
306//__________________________________________________________________
307void AlignmentPoint::unDiagMatCorr(const float* diag, float* nodiag) const
308{
309 // transform material corrections from the frame diagonalizing the errors to point frame
310 // nodiag = mMatDiag * diag
311 int np = getNMatPar();
312 for (int ip = np; ip--;) {
313 double v = 0;
314 for (int jp = np; jp--;) {
315 v += double(mMatDiag[ip][jp]) * diag[jp];
316 }
317 nodiag[ip] = v;
318 }
319 //
320}
321
322//__________________________________________________________________
323void AlignmentPoint::diagMatCorr(const double* nodiag, double* diag) const
324{
325 // transform material corrections from the AliExternalTrackParam frame to
326 // the frame diagonalizing the errors
327 // diag = mMatDiag^T * nodiag
328 int np = getNMatPar();
329 for (int ip = np; ip--;) {
330 double v = 0;
331 for (int jp = np; jp--;) {
332 v += mMatDiag[jp][ip] * nodiag[jp];
333 }
334 diag[ip] = v;
335 }
336 //
337}
338
339//__________________________________________________________________
340void AlignmentPoint::diagMatCorr(const float* nodiag, float* diag) const
341{
342 // transform material corrections from the AliExternalTrackParam frame to
343 // the frame diagonalizing the errors
344 // diag = mMatDiag^T * nodiag
345 int np = getNMatPar();
346 for (int ip = np; ip--;) {
347 double v = 0;
348 for (int jp = np; jp--;) {
349 v += double(mMatDiag[jp][ip]) * nodiag[jp];
350 }
351 diag[ip] = v;
352 }
353 //
354}
355
356//__________________________________________________________________
358{
359 // assign WSA (after material corrections) parameters to supplied track
360 const trackParam_t::covMat_t covDum{
361 1.e-4,
362 0, 1.e-4,
363 0, 0, 1.e-4,
364 0, 0, 0, 1.e-4,
365 0, 0, 0, 0, 1e-4};
366 params_t tmp;
367 std::copy(std::begin(mTrParamWSA), std::end(mTrParamWSA), std::begin(tmp));
368
369 etp.set(getXTracking(), getAlphaSens(), tmp, covDum);
370}
371
372//__________________________________________________________________
374{
375 // assign WSB parameters (before material corrections) to supplied track
376 const trackParam_t::covMat_t covDum{
377 1.e-4,
378 0, 1.e-4,
379 0, 0, 1.e-4,
380 0, 0, 0, 1.e-4,
381 0, 0, 0, 0, 1e-4};
382 params_t tmp;
383 std::copy(std::begin(mTrParamWSB), std::end(mTrParamWSB), std::begin(tmp));
384
385 etp.set(getXTracking(), getAlphaSens(), tmp, covDum);
386}
387
388} // namespace align
389} // namespace o2
Meausered point in the sensor.
int32_t i
uint32_t j
Definition RawData.h:0
virtual void updatePointByTrackInfo(AlignmentPoint *pnt, const trackParam_t *t) const
void getTrWSA(trackParam_t &etp) const
virtual void dumpCoordinates() const
void updatePointByTrackInfo(const trackParam_t *t)
double mTrParamWSB[kNMatDOFs]
void print(uint16_t opt=0) const
void setMatCovDiag(const TVectorD &v)
float mMatCorrCov[kNMatDOFs]
void diagMatCorr(const double *nodiag, double *diag) const
void getXYZGlo(double r[3]) const
void getTrWSB(trackParam_t &etp) const
AlignableSensor * mSensor
double mTrParamWSA[kNMatDOFs]
void setMatCovDiagonalizationMatrix(const TMatrixD &d)
float mMatDiag[kNMatDOFs][kNMatDOFs]
bool isAfter(const AlignmentPoint &pnt) const
float mMatCorrExp[kNMatDOFs]
void setXYZTracking(const double r[3])
void unDiagMatCorr(const double *diag, double *nodiag) const
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLuint GLfloat * val
Definition glcorearb.h:1582
GLboolean r
Definition glcorearb.h:1233
constexpr bool isZeroPos(double d) noexcept
Definition utils.h:65
typename trackParam_t::params_t params_t
Definition utils.h:33
typename trackParam_t::dim3_t dim3_t
Definition utils.h:32
typename track::TrackParametrizationWithError< double > trackParam_t
Definition utils.h:29
void align(gsl::span< ElinkEncoder< BareFormat, CHARGESUM > > elinks)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< o2::mch::ChannelCode > cc