forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackParametrizationWithError.cxx
More file actions
1779 lines (1634 loc) · 70.2 KB
/
TrackParametrizationWithError.cxx
File metadata and controls
1779 lines (1634 loc) · 70.2 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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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.
#include "ReconstructionDataFormats/TrackParametrizationWithError.h"
#include "ReconstructionDataFormats/Vertex.h"
#include "ReconstructionDataFormats/DCA.h"
#include "CommonConstants/MathConstants.h"
#include <GPUCommonLogger.h>
#ifndef GPUCA_GPUCODE_DEVICE
#include <iostream>
#endif
#ifndef GPUCA_ALIGPUCODE
#include <fmt/printf.h>
#endif
using namespace o2::track;
using namespace o2::gpu;
//______________________________________________________________
template <typename value_T>
GPUd() void TrackParametrizationWithError<value_T>::invert()
{
// Transform this track to the local coord. system rotated by 180 deg.
this->invertParam();
// since the fP1 and fP2 are not inverted, their covariances with others change sign
mC[kSigZY] = -mC[kSigZY];
mC[kSigSnpY] = -mC[kSigSnpY];
mC[kSigTglZ] = -mC[kSigTglZ];
mC[kSigTglSnp] = -mC[kSigTglSnp];
mC[kSigQ2PtZ] = -mC[kSigQ2PtZ];
mC[kSigQ2PtSnp] = -mC[kSigQ2PtSnp];
}
//______________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::propagateTo(value_t xk, value_t bz)
{
//----------------------------------------------------------------
// propagate this track to the plane X=xk (cm) in the field "b" (kG)
//----------------------------------------------------------------
value_t dx = xk - this->getX();
if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
return true;
}
value_t crv = this->getCurvature(bz);
value_t x2r = crv * dx;
value_t f1 = this->getSnp(), f2 = f1 + x2r;
if ((gpu::CAMath::Abs(f1) > constants::math::Almost1) || (gpu::CAMath::Abs(f2) > constants::math::Almost1)) {
return false;
}
value_t r1 = gpu::CAMath::Sqrt((1.f - f1) * (1.f + f1));
if (gpu::CAMath::Abs(r1) < constants::math::Almost0) {
return false;
}
value_t r2 = gpu::CAMath::Sqrt((1.f - f2) * (1.f + f2));
if (gpu::CAMath::Abs(r2) < constants::math::Almost0) {
return false;
}
double r1pr2Inv = 1. / (r1 + r2);
double dy2dx = (f1 + f2) * r1pr2Inv;
bool arcz = gpu::CAMath::Abs(x2r) > 0.05f;
params_t dP{0.f};
if (arcz) {
// for small dx/R the linear apporximation of the arc by the segment is OK,
// but at large dx/R the error is very large and leads to incorrect Z propagation
// angle traversed delta = 2*asin(dist_start_end / R / 2), hence the arc is: R*deltaPhi
// The dist_start_end is obtained from sqrt(dx^2+dy^2) = x/(r1+r2)*sqrt(2+f1*f2+r1*r2)
// double chord = dx*TMath::Sqrt(1+dy2dx*dy2dx); // distance from old position to new one
// double rot = 2*TMath::ASin(0.5*chord*crv); // angular difference seen from the circle center
// track1 += rot/crv*track3;
//
auto arg = r1 * f2 - r2 * f1;
if (gpu::CAMath::Abs(arg) > constants::math::Almost1) {
return false;
}
value_t rot = gpu::CAMath::ASin(arg); // more economic version from Yura.
if (f1 * f1 + f2 * f2 > 1.f && f1 * f2 < 0.f) { // special cases of large rotations or large abs angles
if (f2 > 0.f) {
rot = constants::math::PI - rot; //
} else {
rot = -constants::math::PI - rot;
}
}
dP[kZ] = this->getTgl() / crv * rot;
} else {
dP[kZ] = dx * (r2 + f2 * dy2dx) * this->getTgl();
}
this->setX(xk);
dP[kY] = dx * dy2dx;
dP[kSnp] = x2r;
this->updateParams(dP); // apply corrections
value_t &c00 = mC[kSigY2], &c10 = mC[kSigZY], &c11 = mC[kSigZ2], &c20 = mC[kSigSnpY], &c21 = mC[kSigSnpZ],
&c22 = mC[kSigSnp2], &c30 = mC[kSigTglY], &c31 = mC[kSigTglZ], &c32 = mC[kSigTglSnp], &c33 = mC[kSigTgl2],
&c40 = mC[kSigQ2PtY], &c41 = mC[kSigQ2PtZ], &c42 = mC[kSigQ2PtSnp], &c43 = mC[kSigQ2PtTgl],
&c44 = mC[kSigQ2Pt2];
// evaluate matrix in double prec.
value_t kb = bz * constants::math::B2C;
double r2inv = 1. / r2, r1inv = 1. / r1;
double dx2r1pr2 = dx * r1pr2Inv;
double hh = dx2r1pr2 * r2inv * (1. + r1 * r2 + f1 * f2), jj = dx * (dy2dx - f2 * r2inv);
double f02 = hh * r1inv;
double f04 = hh * dx2r1pr2 * kb;
double f24 = dx * kb; // x2r/mP[kQ2Pt];
double f12 = this->getTgl() * (f02 * f2 + jj);
double f13 = dx * (r2 + f2 * dy2dx);
double f14 = this->getTgl() * (f04 * f2 + jj * f24);
// b = C*ft
double b00 = f02 * c20 + f04 * c40, b01 = f12 * c20 + f14 * c40 + f13 * c30;
double b02 = f24 * c40;
double b10 = f02 * c21 + f04 * c41, b11 = f12 * c21 + f14 * c41 + f13 * c31;
double b12 = f24 * c41;
double b20 = f02 * c22 + f04 * c42, b21 = f12 * c22 + f14 * c42 + f13 * c32;
double b22 = f24 * c42;
double b40 = f02 * c42 + f04 * c44, b41 = f12 * c42 + f14 * c44 + f13 * c43;
double b42 = f24 * c44;
double b30 = f02 * c32 + f04 * c43, b31 = f12 * c32 + f14 * c43 + f13 * c33;
double b32 = f24 * c43;
// a = f*b = f*C*ft
double a00 = f02 * b20 + f04 * b40, a01 = f02 * b21 + f04 * b41, a02 = f02 * b22 + f04 * b42;
double a11 = f12 * b21 + f14 * b41 + f13 * b31, a12 = f12 * b22 + f14 * b42 + f13 * b32;
double a22 = f24 * b42;
// F*C*Ft = C + (b + bt + a)
c00 += b00 + b00 + a00;
c10 += b10 + b01 + a01;
c20 += b20 + b02 + a02;
c30 += b30;
c40 += b40;
c11 += b11 + b11 + a11;
c21 += b21 + b12 + a12;
c31 += b31;
c41 += b41;
c22 += b22 + b22 + a22;
c32 += b32;
c42 += b42;
checkCovariance();
return true;
}
//______________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::propagateTo(value_t xk, TrackParametrization<value_T>& linRef0, value_t bz)
{
//----------------------------------------------------------------
// propagate this track to the plane X=xk (cm) in the field "b" (kG), using linRef as linearization point
//----------------------------------------------------------------
if (this->getAbsCharge() == 0) {
bz = 0;
}
value_t dx = xk - this->getX();
if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
this->setX(xk);
linRef0.setX(xk);
return true;
}
// propagate reference track
TrackParametrization<value_T> linRef1 = linRef0;
if (!linRef1.propagateTo(xk, bz)) {
return false;
}
value_t kb = bz * constants::math::B2C;
// evaluate in double prec.
double snpRef0 = linRef0.getSnp(), cspRef0 = gpu::CAMath::Sqrt((1 - snpRef0) * (1 + snpRef0));
double snpRef1 = linRef1.getSnp(), cspRef1 = gpu::CAMath::Sqrt((1 - snpRef1) * (1 + snpRef1));
double cspRef0Inv = 1 / cspRef0, cspRef1Inv = 1 / cspRef1, cc = cspRef0 + cspRef1, ccInv = 1 / cc, dy2dx = (snpRef0 + snpRef1) * ccInv;
double dxccInv = dx * ccInv, hh = dxccInv * cspRef1Inv * (1 + cspRef0 * cspRef1 + snpRef0 * snpRef1), jj = dx * (dy2dx - snpRef1 * cspRef1Inv);
double f02 = hh * cspRef0Inv;
double f04 = hh * dxccInv * kb;
double f24 = dx * kb;
double f12 = linRef0.getTgl() * (f02 * snpRef1 + jj);
double f13 = dx * (cspRef1 + snpRef1 * dy2dx); // dS
double f14 = linRef0.getTgl() * (f04 * snpRef1 + jj * f24);
// difference between the current and reference state
value_t diff[5];
for (int i = 0; i < 5; i++) {
diff[i] = this->getParam(i) - linRef0.getParam(i);
}
value_t snpUpd = snpRef1 + diff[kSnp] + f24 * diff[kQ2Pt];
if (gpu::CAMath::Abs(snpUpd) > constants::math::Almost1) {
return false;
}
linRef0 = linRef1; // update reference track
this->setX(xk);
this->setY(linRef1.getY() + diff[kY] + f02 * diff[kSnp] + f04 * diff[kQ2Pt]);
this->setZ(linRef1.getZ() + diff[kZ] + f13 * diff[kTgl] + f14 * diff[kQ2Pt]);
this->setSnp(snpUpd);
this->setTgl(linRef1.getTgl() + diff[kTgl]);
this->setQ2Pt(linRef1.getQ2Pt() + diff[kQ2Pt]);
value_t &c00 = mC[kSigY2], &c10 = mC[kSigZY], &c11 = mC[kSigZ2], &c20 = mC[kSigSnpY], &c21 = mC[kSigSnpZ],
&c22 = mC[kSigSnp2], &c30 = mC[kSigTglY], &c31 = mC[kSigTglZ], &c32 = mC[kSigTglSnp], &c33 = mC[kSigTgl2],
&c40 = mC[kSigQ2PtY], &c41 = mC[kSigQ2PtZ], &c42 = mC[kSigQ2PtSnp], &c43 = mC[kSigQ2PtTgl],
&c44 = mC[kSigQ2Pt2];
// b = C*ft
double b00 = f02 * c20 + f04 * c40, b01 = f12 * c20 + f14 * c40 + f13 * c30;
double b02 = f24 * c40;
double b10 = f02 * c21 + f04 * c41, b11 = f12 * c21 + f14 * c41 + f13 * c31;
double b12 = f24 * c41;
double b20 = f02 * c22 + f04 * c42, b21 = f12 * c22 + f14 * c42 + f13 * c32;
double b22 = f24 * c42;
double b40 = f02 * c42 + f04 * c44, b41 = f12 * c42 + f14 * c44 + f13 * c43;
double b42 = f24 * c44;
double b30 = f02 * c32 + f04 * c43, b31 = f12 * c32 + f14 * c43 + f13 * c33;
double b32 = f24 * c43;
// a = f*b = f*C*ft
double a00 = f02 * b20 + f04 * b40, a01 = f02 * b21 + f04 * b41, a02 = f02 * b22 + f04 * b42;
double a11 = f12 * b21 + f14 * b41 + f13 * b31, a12 = f12 * b22 + f14 * b42 + f13 * b32;
double a22 = f24 * b42;
// F*C*Ft = C + (b + bt + a)
c00 += b00 + b00 + a00;
c10 += b10 + b01 + a01;
c20 += b20 + b02 + a02;
c30 += b30;
c40 += b40;
c11 += b11 + b11 + a11;
c21 += b21 + b12 + a12;
c31 += b31;
c41 += b41;
c22 += b22 + b22 + a22;
c32 += b32;
c42 += b42;
checkCovariance();
return true;
}
//______________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::testRotate(value_t) const
{
// no ops
return true;
}
//______________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::rotate(value_t alpha)
{
// rotate to alpha frame
if (gpu::CAMath::Abs(this->getSnp()) > constants::math::Almost1) {
LOGP(debug, "Precondition is not satisfied: |sin(phi)|>1 ! {:f}", this->getSnp());
return false;
}
//
math_utils::detail::bringToPMPi<value_t>(alpha);
//
value_t ca = 0, sa = 0;
math_utils::detail::sincos(alpha - this->getAlpha(), sa, ca);
value_t snp = this->getSnp(), csp = gpu::CAMath::Sqrt((1.f - snp) * (1.f + snp)); // Improve precision
// RS: check if rotation does no invalidate track model (cos(local_phi)>=0, i.e. particle
// direction in local frame is along the X axis
if ((csp * ca + snp * sa) < 0) {
// LOGP(warning,"Rotation failed: local cos(phi) would become {:.2f}", csp * ca + snp * sa);
return false;
}
//
value_t updSnp = snp * ca - csp * sa;
if (gpu::CAMath::Abs(updSnp) > constants::math::Almost1) {
LOGP(debug, "Rotation failed: new snp {:.2f}", updSnp);
return false;
}
value_t xold = this->getX(), yold = this->getY();
this->setAlpha(alpha);
this->setX(xold * ca + yold * sa);
this->setY(-xold * sa + yold * ca);
this->setSnp(updSnp);
if (gpu::CAMath::Abs(csp) < constants::math::Almost0) {
LOGP(debug, "Too small cosine value {:f}", csp);
csp = constants::math::Almost0;
}
value_t rr = (ca + snp / csp * sa);
mC[kSigY2] *= (ca * ca);
mC[kSigZY] *= ca;
mC[kSigSnpY] *= ca * rr;
mC[kSigSnpZ] *= rr;
mC[kSigSnp2] *= rr * rr;
mC[kSigTglY] *= ca;
mC[kSigTglSnp] *= rr;
mC[kSigQ2PtY] *= ca;
mC[kSigQ2PtSnp] *= rr;
checkCovariance();
return true;
}
//______________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::rotate(value_t alpha, TrackParametrization<value_T>& linRef0, value_t bz)
{
// RS: similar to int32_t GPUTPCGMPropagator::RotateToAlpha(float newAlpha), i.e. rotate the track to new frame alpha, using linRef as linearization point
// rotate to alpha frame the reference (linearization point) trackParam, then align the current track to it
if (gpu::CAMath::Abs(this->getSnp()) > constants::math::Almost1) {
LOGP(debug, "Precondition is not satisfied: |sin(phi)|>1 ! {:f}", this->getSnp());
return false;
}
//
math_utils::detail::bringToPMPi<value_t>(alpha);
//
value_t ca = 0, sa = 0;
TrackParametrization<value_T> linRef1 = linRef0;
// rotate the reference, adjusting alpha to +-pi, return precalculated cos and sin of alpha - alphaOld
if (!linRef1.rotateParam(alpha, ca, sa)) {
return false;
}
value_t trackX = this->getX() * ca + this->getY() * sa; // X of the rotated current track
if (!linRef1.propagateParamTo(trackX, bz)) {
return false;
}
// now rotate the current track
value_t snp = this->getSnp(), csp = gpu::CAMath::Sqrt((1.f - snp) * (1.f + snp)), updSnp = snp * ca - csp * sa;
if ((csp * ca + snp * sa) < 0 || gpu::CAMath::Abs(updSnp) > constants::math::Almost1) {
// LOGP(warning,"Rotation failed: local cos(phi) would become {:.2f}", csp * ca + snp * sa);
return false;
}
this->setY(-sa * this->getX() + ca * this->getY());
this->setX(trackX);
this->setSnp(updSnp);
this->setAlpha(alpha);
// rotate covariance, accounting for the extra error from the rotated X
value_t snpRef0 = linRef0.getSnp(), cspRef0 = gpu::CAMath::Sqrt((value_t(1) - snpRef0) * (value_t(1) + snpRef0)); // original reference
value_t snpRef1 = linRef1.getSnp(), cspRef1 = ca * cspRef0 + sa * snpRef0; // rotated reference
value_t rr = cspRef1 / cspRef0; // cos1_ref / cos0_ref
// "extra row" of the lower triangle of cov. matrix
value_t cXSigY = mC[kSigY2] * ca * sa;
value_t cXSigZ = mC[kSigZY] * sa;
value_t cXSigSnp = mC[kSigSnpY] * rr * sa;
value_t cXSigTgl = mC[kSigTglY] * sa;
value_t cXSigQ2Pt = mC[kSigQ2PtY] * sa;
value_t cSigX2 = mC[kSigY2] * sa * sa;
// plane rotation of existing cov matrix
mC[kSigY2] *= ca * ca;
mC[kSigZY] *= ca;
mC[kSigSnpY] *= ca * rr;
mC[kSigSnpZ] *= rr;
mC[kSigSnp2] *= rr * rr;
mC[kSigTglY] *= ca;
mC[kSigTglSnp] *= rr;
mC[kSigQ2PtY] *= ca;
mC[kSigQ2PtSnp] *= rr;
// transport covariance from pseudo 6x6 matrix to usual 5x5, Jacobian (trust to Sergey):
auto cspRef1Inv = value_t(1) / cspRef1;
auto j3 = -snpRef1 * cspRef1Inv; // -pYmod/pXmod = -tg_pho = -sin_phi_mod / cos_phi_mod
auto j4 = -linRef1.getTgl() * cspRef1Inv; // -pZmod/pXmod = -tgl_mod / cos_phi_mod
auto j5 = linRef1.getCurvature(bz);
// Y Z Sin DzDs q/p X
// { { 1, 0, 0, 0, 0, j3 }, // Y
// { 0, 1, 0, 0, 0, j4 }, // Z
// { 0, 0, 1, 0, 0, j5 }, // snp
// { 0, 0, 0, 1, 0, 0 }, // tgl
// { 0, 0, 0, 0, 1, 0 } }; // q/pt
auto hXSigY = cXSigY + cSigX2 * j3;
auto hXSigZ = cXSigZ + cSigX2 * j4;
auto hXSigSnp = cXSigSnp + cSigX2 * j5;
mC[kSigY2] += j3 * (cXSigY + hXSigY);
mC[kSigZ2] += j4 * (cXSigZ + hXSigZ);
mC[kSigSnpY] += cXSigSnp * j3 + hXSigY * j5;
mC[kSigSnp2] += j5 * (cXSigSnp + hXSigSnp);
mC[kSigTglZ] += cXSigTgl * j4;
mC[kSigQ2PtY] += cXSigQ2Pt * j3;
mC[kSigQ2PtSnp] += cXSigQ2Pt * j5;
mC[kSigZY] += cXSigZ * j3 + hXSigY * j4;
mC[kSigSnpZ] += cXSigSnp * j4 + hXSigZ * j5;
mC[kSigTglY] += cXSigTgl * j3;
mC[kSigTglSnp] += cXSigTgl * j5;
mC[kSigQ2PtZ] += cXSigQ2Pt * j4;
checkCovariance();
linRef0 = linRef1;
return true;
}
//_______________________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::propagateToDCA(const o2::dataformats::VertexBase& vtx, value_t b, o2::dataformats::DCA* dca, value_t maxD)
{
// propagate track to DCA to the vertex
value_t sn, cs, alp = this->getAlpha();
o2::math_utils::detail::sincos(alp, sn, cs);
value_t x = this->getX(), y = this->getY(), snp = this->getSnp(), csp = gpu::CAMath::Sqrt((1.f - snp) * (1.f + snp));
value_t xv = vtx.getX() * cs + vtx.getY() * sn, yv = -vtx.getX() * sn + vtx.getY() * cs, zv = vtx.getZ();
x -= xv;
y -= yv;
// Estimate the impact parameter neglecting the track curvature
value_t d = gpu::CAMath::Abs(x * snp - y * csp);
if (d > maxD) {
if (dca) { // provide default DCA for failed propag
dca->set(o2::track::DefaultDCA, o2::track::DefaultDCA,
o2::track::DefaultDCACov, o2::track::DefaultDCACov, o2::track::DefaultDCACov);
}
return false;
}
value_t crv = this->getCurvature(b);
value_t tgfv = -(crv * x - snp) / (crv * y + csp);
sn = tgfv / gpu::CAMath::Sqrt(1.f + tgfv * tgfv);
cs = gpu::CAMath::Sqrt((1.f - sn) * (1.f + sn));
cs = (gpu::CAMath::Abs(tgfv) > constants::math::Almost0) ? sn / tgfv : constants::math::Almost1;
x = xv * cs + yv * sn;
yv = -xv * sn + yv * cs;
xv = x;
auto tmpT(*this); // operate on the copy to recover after the failure
alp += gpu::CAMath::ASin(sn);
if (!tmpT.rotate(alp) || !tmpT.propagateTo(xv, b)) {
#if !defined(GPUCA_ALIGPUCODE)
LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << vtx << " | Track is: " << tmpT.asString();
#endif
if (dca) { // provide default DCA for failed propag
dca->set(o2::track::DefaultDCA, o2::track::DefaultDCA,
o2::track::DefaultDCACov, o2::track::DefaultDCACov, o2::track::DefaultDCACov);
}
return false;
}
*this = tmpT;
if (dca) {
o2::math_utils::detail::sincos(alp, sn, cs);
auto s2ylocvtx = vtx.getSigmaX2() * sn * sn + vtx.getSigmaY2() * cs * cs - 2. * vtx.getSigmaXY() * cs * sn;
dca->set(this->getY() - yv, this->getZ() - zv, getSigmaY2() + s2ylocvtx, getSigmaZY(), getSigmaZ2() + vtx.getSigmaZ2());
}
return true;
}
//______________________________________________________________
template <typename value_T>
GPUd() TrackParametrizationWithError<value_T>::TrackParametrizationWithError(const dim3_t& xyz, const dim3_t& pxpypz,
const std::array<value_t, kLabCovMatSize>& cv, int charge, bool sectorAlpha, const PID pid)
{
// construct track param and covariance from kinematics and lab errors
set(xyz, pxpypz, cv, charge, sectorAlpha, pid);
}
//______________________________________________________________
template <typename value_T>
GPUd() void TrackParametrizationWithError<value_T>::set(const dim3_t& xyz, const dim3_t& pxpypz,
const std::array<value_t, kLabCovMatSize>& cv, int charge, bool sectorAlpha, const PID pid)
{
// set track param and covariance from kinematics and lab errors
// Alpha of the frame is defined as:
// sectorAlpha == false : -> angle of pt direction
// sectorAlpha == true : -> angle of the sector from X,Y coordinate for r>1
// angle of pt direction for r==0
//
//
constexpr value_t kSafe = 1e-5f;
value_t radPos2 = xyz[0] * xyz[0] + xyz[1] * xyz[1];
value_t alp = 0;
if (sectorAlpha || radPos2 < 1) {
alp = gpu::CAMath::ATan2(pxpypz[1], pxpypz[0]);
} else {
alp = gpu::CAMath::ATan2(xyz[1], xyz[0]);
}
if (sectorAlpha) {
alp = math_utils::detail::angle2Alpha<value_t>(alp);
}
//
value_t sn, cs;
math_utils::detail::sincos(alp, sn, cs);
// protection against cosp<0
if (cs * pxpypz[0] + sn * pxpypz[1] < 0) {
LOG(debug) << "alpha from phiPos() will invalidate this track parameters, overriding to alpha from phi()";
alp = gpu::CAMath::ATan2(pxpypz[1], pxpypz[0]);
if (sectorAlpha) {
alp = math_utils::detail::angle2Alpha<value_t>(alp);
}
math_utils::detail::sincos(alp, sn, cs);
}
// protection: avoid alpha being too close to 0 or +-pi/2
if (gpu::CAMath::Abs(sn) < 2.f * kSafe) {
if (alp > 0) {
alp += alp < constants::math::PIHalf ? 2.f * kSafe : -2.f * kSafe;
} else {
alp += alp > -constants::math::PIHalf ? -2.f * kSafe : 2.f * kSafe;
}
math_utils::detail::sincos(alp, sn, cs);
} else if (gpu::CAMath::Abs(cs) < 2.f * kSafe) {
if (alp > 0) {
alp += alp > constants::math::PIHalf ? 2.f * kSafe : -2.f * kSafe;
} else {
alp += alp > -constants::math::PIHalf ? 2.f * kSafe : -2.f * kSafe;
}
math_utils::detail::sincos(alp, sn, cs);
}
// get the vertex of origin and the momentum
dim3_t ver{xyz[0], xyz[1], xyz[2]};
dim3_t mom{pxpypz[0], pxpypz[1], pxpypz[2]};
//
// Rotate to the local coordinate system
math_utils::detail::rotateZ<value_t>(ver, -alp);
math_utils::detail::rotateZ<value_t>(mom, -alp);
//
value_t pt = gpu::CAMath::Sqrt(mom[0] * mom[0] + mom[1] * mom[1]);
value_t ptI = 1.f / pt;
this->setX(ver[0]);
this->setAlpha(alp);
this->setY(ver[1]);
this->setZ(ver[2]);
this->setSnp(mom[1] * ptI); // cos(phi)
this->setTgl(mom[2] * ptI); // tg(lambda)
this->setAbsCharge(gpu::CAMath::Abs(charge));
this->setQ2Pt(charge ? ptI * charge : ptI);
this->setPID(pid);
//
if (gpu::CAMath::Abs(1.f - this->getSnp()) < kSafe) {
this->setSnp(1.f - kSafe); // Protection
} else if (gpu::CAMath::Abs(-1.f - this->getSnp()) < kSafe) {
this->setSnp(-1.f + kSafe); // Protection
}
//
// Covariance matrix (formulas to be simplified)
value_t r = mom[0] * ptI; // cos(phi)
value_t cv34 = gpu::CAMath::Sqrt(cv[3] * cv[3] + cv[4] * cv[4]);
//
int special = 0;
value_t sgcheck = r * sn + this->getSnp() * cs;
if (gpu::CAMath::Abs(sgcheck) > 1 - kSafe) { // special case: lab phi is +-pi/2
special = 1;
sgcheck = sgcheck < 0 ? -1.f : 1.f;
} else if (gpu::CAMath::Abs(sgcheck) < kSafe) {
sgcheck = cs < 0 ? -1.0f : 1.0f;
special = 2; // special case: lab phi is 0
}
//
mC[kSigY2] = cv[0] + cv[2];
mC[kSigZY] = (-cv[3] * sn) < 0 ? -cv34 : cv34;
mC[kSigZ2] = cv[5];
//
value_t ptI2 = ptI * ptI;
value_t tgl2 = this->getTgl() * this->getTgl();
if (special == 1) {
mC[kSigSnpY] = cv[6] * ptI;
mC[kSigSnpZ] = -sgcheck * cv[8] * r * ptI;
mC[kSigSnp2] = gpu::CAMath::Abs(cv[9] * r * r * ptI2);
mC[kSigTglY] = (cv[10] * this->getTgl() - sgcheck * cv[15]) * ptI / r;
mC[kSigTglZ] = (cv[17] - sgcheck * cv[12] * this->getTgl()) * ptI;
mC[kSigTglSnp] = (-sgcheck * cv[18] + cv[13] * this->getTgl()) * r * ptI2;
mC[kSigTgl2] = gpu::CAMath::Abs(cv[20] - 2 * sgcheck * cv[19] * mC[4] + cv[14] * tgl2) * ptI2;
mC[kSigQ2PtY] = cv[10] * ptI2 / r * charge;
mC[kSigQ2PtZ] = -sgcheck * cv[12] * ptI2 * charge;
mC[kSigQ2PtSnp] = cv[13] * r * ptI * ptI2 * charge;
mC[kSigQ2PtTgl] = (-sgcheck * cv[19] + cv[14] * this->getTgl()) * r * ptI2 * ptI;
mC[kSigQ2Pt2] = gpu::CAMath::Abs(cv[14] * ptI2 * ptI2);
} else if (special == 2) {
mC[kSigSnpY] = -cv[10] * ptI * cs / sn;
mC[kSigSnpZ] = cv[12] * cs * ptI;
mC[kSigSnp2] = gpu::CAMath::Abs(cv[14] * cs * cs * ptI2);
mC[kSigTglY] = (sgcheck * cv[6] * this->getTgl() - cv[15]) * ptI / sn;
mC[kSigTglZ] = (cv[17] - sgcheck * cv[8] * this->getTgl()) * ptI;
mC[kSigTglSnp] = (cv[19] - sgcheck * cv[13] * this->getTgl()) * cs * ptI2;
mC[kSigTgl2] = gpu::CAMath::Abs(cv[20] - 2 * sgcheck * cv[18] * this->getTgl() + cv[9] * tgl2) * ptI2;
mC[kSigQ2PtY] = sgcheck * cv[6] * ptI2 / sn * charge;
mC[kSigQ2PtZ] = -sgcheck * cv[8] * ptI2 * charge;
mC[kSigQ2PtSnp] = -sgcheck * cv[13] * cs * ptI * ptI2 * charge;
mC[kSigQ2PtTgl] = (-sgcheck * cv[18] + cv[9] * this->getTgl()) * ptI2 * ptI * charge;
mC[kSigQ2Pt2] = gpu::CAMath::Abs(cv[9] * ptI2 * ptI2);
} else {
double m00 = -sn; // m10=cs;
double m23 = -pt * (sn + this->getSnp() * cs / r), m43 = -pt * pt * (r * cs - this->getSnp() * sn);
double m24 = pt * (cs - this->getSnp() * sn / r), m44 = -pt * pt * (r * sn + this->getSnp() * cs);
double m35 = pt, m45 = -pt * pt * this->getTgl();
//
if (charge) { // RS: this is a hack, proper treatment to be implemented
m43 *= charge;
m44 *= charge;
m45 *= charge;
}
//
double a1 = cv[13] - cv[9] * (m23 * m44 + m43 * m24) / m23 / m43;
double a2 = m23 * m24 - m23 * (m23 * m44 + m43 * m24) / m43;
double a3 = m43 * m44 - m43 * (m23 * m44 + m43 * m24) / m23;
double a4 = cv[14] + 2. * cv[9];
double a5 = m24 * m24 - 2. * m24 * m44 * m23 / m43;
double a6 = m44 * m44 - 2. * m24 * m44 * m43 / m23;
//
mC[kSigSnpY] = (cv[10] * m43 - cv[6] * m44) / (m24 * m43 - m23 * m44) / m00;
mC[kSigQ2PtY] = (cv[6] / m00 - mC[kSigSnpY] * m23) / m43;
mC[kSigTglY] = (cv[15] / m00 - mC[kSigQ2PtY] * m45) / m35;
mC[kSigSnpZ] = (cv[12] * m43 - cv[8] * m44) / (m24 * m43 - m23 * m44);
mC[kSigQ2PtZ] = (cv[8] - mC[kSigSnpZ] * m23) / m43;
mC[kSigTglZ] = cv[17] / m35 - mC[kSigQ2PtZ] * m45 / m35;
mC[kSigSnp2] = gpu::CAMath::Abs((a4 * a3 - a6 * a1) / (a5 * a3 - a6 * a2));
mC[kSigQ2Pt2] = gpu::CAMath::Abs((a1 - a2 * mC[kSigSnp2]) / a3);
mC[kSigQ2PtSnp] = (cv[9] - mC[kSigSnp2] * m23 * m23 - mC[kSigQ2Pt2] * m43 * m43) / m23 / m43;
double b1 = cv[18] - mC[kSigQ2PtSnp] * m23 * m45 - mC[kSigQ2Pt2] * m43 * m45;
double b2 = m23 * m35;
double b3 = m43 * m35;
double b4 = cv[19] - mC[kSigQ2PtSnp] * m24 * m45 - mC[kSigQ2Pt2] * m44 * m45;
double b5 = m24 * m35;
double b6 = m44 * m35;
mC[kSigTglSnp] = (b4 - b6 * b1 / b3) / (b5 - b6 * b2 / b3);
mC[kSigQ2PtTgl] = b1 / b3 - b2 * mC[kSigTglSnp] / b3;
mC[kSigTgl2] = gpu::CAMath::Abs((cv[20] - mC[kSigQ2Pt2] * (m45 * m45) - mC[kSigQ2PtTgl] * 2.f * m35 * m45) / (m35 * m35));
}
checkCovariance();
}
//____________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::propagateTo(value_t xk, const dim3_t& b)
{
//----------------------------------------------------------------
// Extrapolate this track to the plane X=xk in the field b[].
//
// X [cm] is in the "tracking coordinate system" of this track.
// b[]={Bx,By,Bz} [kG] is in the Global coordidate system.
//----------------------------------------------------------------
value_t dx = xk - this->getX();
if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
return true;
}
// Do not propagate tracks outside the ALICE detector
if (gpu::CAMath::Abs(dx) > 1e5 || gpu::CAMath::Abs(this->getY()) > 1e5 || gpu::CAMath::Abs(this->getZ()) > 1e5) {
LOG(warning) << "Anomalous track, target X:" << xk;
// print();
return false;
}
value_t crv = (gpu::CAMath::Abs(b[2]) < constants::math::Almost0) ? 0.f : this->getCurvature(b[2]);
if (gpu::CAMath::Abs(crv) < constants::math::Almost0) {
return propagateTo(xk, 0.);
}
value_t x2r = crv * dx;
value_t f1 = this->getSnp(), f2 = f1 + x2r;
if ((gpu::CAMath::Abs(f1) > constants::math::Almost1) || (gpu::CAMath::Abs(f2) > constants::math::Almost1)) {
return false;
}
value_t r1 = gpu::CAMath::Sqrt((1.f - f1) * (1.f + f1));
if (gpu::CAMath::Abs(r1) < constants::math::Almost0) {
return false;
}
value_t r2 = gpu::CAMath::Sqrt((1.f - f2) * (1.f + f2));
if (gpu::CAMath::Abs(r2) < constants::math::Almost0) {
return false;
}
double r1pr2Inv = 1. / (r1 + r2), r2inv = 1. / r2, r1inv = 1. / r1;
double dy2dx = (f1 + f2) * r1pr2Inv, dx2r1pr2 = dx * r1pr2Inv;
value_t step = (gpu::CAMath::Abs(x2r) < 0.05f) ? dx * gpu::CAMath::Abs(r2 + f2 * dy2dx) // chord
: 2.f * gpu::CAMath::ASin(0.5f * dx * gpu::CAMath::Sqrt(1.f + dy2dx * dy2dx) * crv) / crv; // arc
step *= gpu::CAMath::Sqrt(1.f + this->getTgl() * this->getTgl());
//
// get the track x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha in the Global System
std::array<value_t, 9> vecLab{0.f};
if (!this->getPosDirGlo(vecLab)) {
return false;
}
//
// matrix transformed with Bz component only
value_t &c00 = mC[kSigY2], &c10 = mC[kSigZY], &c11 = mC[kSigZ2], &c20 = mC[kSigSnpY], &c21 = mC[kSigSnpZ],
&c22 = mC[kSigSnp2], &c30 = mC[kSigTglY], &c31 = mC[kSigTglZ], &c32 = mC[kSigTglSnp], &c33 = mC[kSigTgl2],
&c40 = mC[kSigQ2PtY], &c41 = mC[kSigQ2PtZ], &c42 = mC[kSigQ2PtSnp], &c43 = mC[kSigQ2PtTgl],
&c44 = mC[kSigQ2Pt2];
// evaluate matrix in double prec.
value_t kb = b[2] * constants::math::B2C;
double hh = dx2r1pr2 * r2inv * (1. + r1 * r2 + f1 * f2), jj = dx * (dy2dx - f2 * r2inv);
double f02 = hh * r1inv;
double f04 = hh * dx2r1pr2 * kb;
double f24 = dx * kb; // x2r/mP[kQ2Pt];
double f12 = this->getTgl() * (f02 * f2 + jj);
double f13 = dx * (r2 + f2 * dy2dx);
double f14 = this->getTgl() * (f04 * f2 + jj * f24);
// b = C*ft
double b00 = f02 * c20 + f04 * c40, b01 = f12 * c20 + f14 * c40 + f13 * c30;
double b02 = f24 * c40;
double b10 = f02 * c21 + f04 * c41, b11 = f12 * c21 + f14 * c41 + f13 * c31;
double b12 = f24 * c41;
double b20 = f02 * c22 + f04 * c42, b21 = f12 * c22 + f14 * c42 + f13 * c32;
double b22 = f24 * c42;
double b40 = f02 * c42 + f04 * c44, b41 = f12 * c42 + f14 * c44 + f13 * c43;
double b42 = f24 * c44;
double b30 = f02 * c32 + f04 * c43, b31 = f12 * c32 + f14 * c43 + f13 * c33;
double b32 = f24 * c43;
// a = f*b = f*C*ft
double a00 = f02 * b20 + f04 * b40, a01 = f02 * b21 + f04 * b41, a02 = f02 * b22 + f04 * b42;
double a11 = f12 * b21 + f14 * b41 + f13 * b31, a12 = f12 * b22 + f14 * b42 + f13 * b32;
double a22 = f24 * b42;
// F*C*Ft = C + (b + bt + a)
c00 += b00 + b00 + a00;
c10 += b10 + b01 + a01;
c20 += b20 + b02 + a02;
c30 += b30;
c40 += b40;
c11 += b11 + b11 + a11;
c21 += b21 + b12 + a12;
c31 += b31;
c41 += b41;
c22 += b22 + b22 + a22;
c32 += b32;
c42 += b42;
checkCovariance();
// Rotate to the system where Bx=By=0.
value_t bxy2 = b[0] * b[0] + b[1] * b[1];
value_t bt = gpu::CAMath::Sqrt(bxy2);
value_t cosphi = 1.f, sinphi = 0.f;
if (bt > constants::math::Almost0) {
cosphi = b[0] / bt;
sinphi = b[1] / bt;
}
value_t bb = gpu::CAMath::Sqrt(bxy2 + b[2] * b[2]);
value_t costet = 1., sintet = 0.;
if (bb > constants::math::Almost0) {
costet = b[2] / bb;
sintet = bt / bb;
}
std::array<value_t, 7> vect{costet * cosphi * vecLab[0] + costet * sinphi * vecLab[1] - sintet * vecLab[2],
-sinphi * vecLab[0] + cosphi * vecLab[1],
sintet * cosphi * vecLab[0] + sintet * sinphi * vecLab[1] + costet * vecLab[2],
costet * cosphi * vecLab[3] + costet * sinphi * vecLab[4] - sintet * vecLab[5],
-sinphi * vecLab[3] + cosphi * vecLab[4],
sintet * cosphi * vecLab[3] + sintet * sinphi * vecLab[4] + costet * vecLab[5],
vecLab[6]};
// Do the helix step
value_t q = this->getCharge();
g3helx3(q * bb, step, vect);
// Rotate back to the Global System
vecLab[0] = cosphi * costet * vect[0] - sinphi * vect[1] + cosphi * sintet * vect[2];
vecLab[1] = sinphi * costet * vect[0] + cosphi * vect[1] + sinphi * sintet * vect[2];
vecLab[2] = -sintet * vect[0] + costet * vect[2];
vecLab[3] = cosphi * costet * vect[3] - sinphi * vect[4] + cosphi * sintet * vect[5];
vecLab[4] = sinphi * costet * vect[3] + cosphi * vect[4] + sinphi * sintet * vect[5];
vecLab[5] = -sintet * vect[3] + costet * vect[5];
// Rotate back to the Tracking System
value_t sinalp = -vecLab[7], cosalp = vecLab[8];
value_t t = cosalp * vecLab[0] - sinalp * vecLab[1];
vecLab[1] = sinalp * vecLab[0] + cosalp * vecLab[1];
vecLab[0] = t;
t = cosalp * vecLab[3] - sinalp * vecLab[4];
vecLab[4] = sinalp * vecLab[3] + cosalp * vecLab[4];
vecLab[3] = t;
// Do the final correcting step to the target plane (linear approximation)
value_t x = vecLab[0], y = vecLab[1], z = vecLab[2];
if (gpu::CAMath::Abs(x - xk) > constants::math::Almost0) {
if (gpu::CAMath::Abs(vecLab[3]) < constants::math::Almost0) {
return false;
}
auto dxFin = xk - vecLab[0];
x += dxFin;
y += vecLab[4] / vecLab[3] * dxFin;
z += vecLab[5] / vecLab[3] * dxFin;
}
// Calculate the track parameters
t = 1.f / gpu::CAMath::Sqrt(vecLab[3] * vecLab[3] + vecLab[4] * vecLab[4]);
this->setX(xk);
this->setY(y);
this->setZ(z);
this->setSnp(vecLab[4] * t);
this->setTgl(vecLab[5] * t);
this->setQ2Pt(q * t / vecLab[6]);
return true;
}
//____________________________________________________________
template <typename value_T>
GPUd() bool TrackParametrizationWithError<value_T>::propagateTo(value_t xk, TrackParametrization<value_T>& linRef0, const dim3_t& b)
{
//----------------------------------------------------------------
// Extrapolate this track to the plane X=xk in the field b[].
//
// X [cm] is in the "tracking coordinate system" of this track.
// b[]={Bx,By,Bz} [kG] is in the Global coordidate system.
//----------------------------------------------------------------
value_t dx = xk - this->getX();
if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
return true;
}
// Do not propagate tracks outside the ALICE detector
if (gpu::CAMath::Abs(dx) > 1e5 || gpu::CAMath::Abs(this->getY()) > 1e5 || gpu::CAMath::Abs(this->getZ()) > 1e5) {
LOG(warning) << "Anomalous track, target X:" << xk;
// print();
return false;
}
if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
this->setX(xk);
linRef0.setX(xk);
return true;
}
// preliminary calculations to find the step size
value_t crv = (gpu::CAMath::Abs(b[2]) < constants::math::Almost0) ? 0.f : linRef0.getCurvature(b[2]);
if (gpu::CAMath::Abs(crv) < constants::math::Almost0) {
return propagateTo(xk, linRef0, 0.);
}
value_t kb = b[2] * constants::math::B2C, x2r = crv * dx;
// evaluate in double prec.
value_t snpRef0 = linRef0.getSnp(), snpRef1 = snpRef0 + x2r;
if ((gpu::CAMath::Abs(snpRef0) > constants::math::Almost1) || (gpu::CAMath::Abs(snpRef1) > constants::math::Almost1)) {
return false;
}
value_t cspRef0 = gpu::CAMath::Sqrt((1 - snpRef0) * (1 + snpRef0)), cspRef1 = gpu::CAMath::Sqrt((1 - snpRef1) * (1 + snpRef1));
if (gpu::CAMath::Abs(cspRef0) < constants::math::Almost0 || gpu::CAMath::Abs(cspRef1) < constants::math::Almost0) {
return false;
}
value_t cspRef0Inv = value_t(1) / cspRef0, cspRef1Inv = value_t(1) / cspRef1, cc = cspRef0 + cspRef1, ccInv = value_t(1) / cc, dy2dx = (snpRef0 + snpRef1) * ccInv;
value_t step = (gpu::CAMath::Abs(crv * dx) < 0.05f) ? dx * (cspRef1 + snpRef1 * dy2dx) : 2. * gpu::CAMath::ASin(0.5 * dx * gpu::CAMath::Sqrt(1.f + dy2dx * dy2dx) * crv) / crv; // arc
step *= gpu::CAMath::Sqrt(1.f + linRef0.getTgl() * linRef0.getTgl());
//
// get the track x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha in the Global System
std::array<value_t, 9> vecLab{0.f};
if (!linRef0.getPosDirGlo(vecLab)) {
return false;
}
//
// Rotate to the system where Bx=By=0.
value_t bxy2 = b[0] * b[0] + b[1] * b[1];
value_t bt = gpu::CAMath::Sqrt(bxy2);
value_t cosphi = 1.f, sinphi = 0.f;
if (bt > constants::math::Almost0) {
cosphi = b[0] / bt;
sinphi = b[1] / bt;
}
value_t bb = gpu::CAMath::Sqrt(bxy2 + b[2] * b[2]);
value_t costet = 1., sintet = 0.;
if (bb > constants::math::Almost0) {
costet = b[2] / bb;
sintet = bt / bb;
}
std::array<value_t, 7> vect{costet * cosphi * vecLab[0] + costet * sinphi * vecLab[1] - sintet * vecLab[2],
-sinphi * vecLab[0] + cosphi * vecLab[1],
sintet * cosphi * vecLab[0] + sintet * sinphi * vecLab[1] + costet * vecLab[2],
costet * cosphi * vecLab[3] + costet * sinphi * vecLab[4] - sintet * vecLab[5],
-sinphi * vecLab[3] + cosphi * vecLab[4],
sintet * cosphi * vecLab[3] + sintet * sinphi * vecLab[4] + costet * vecLab[5],
vecLab[6]};
// Do the helix step
value_t q = this->getCharge();
g3helx3(q * bb, step, vect);
// Rotate back to the Global System
vecLab[0] = cosphi * costet * vect[0] - sinphi * vect[1] + cosphi * sintet * vect[2];
vecLab[1] = sinphi * costet * vect[0] + cosphi * vect[1] + sinphi * sintet * vect[2];
vecLab[2] = -sintet * vect[0] + costet * vect[2];
vecLab[3] = cosphi * costet * vect[3] - sinphi * vect[4] + cosphi * sintet * vect[5];
vecLab[4] = sinphi * costet * vect[3] + cosphi * vect[4] + sinphi * sintet * vect[5];
vecLab[5] = -sintet * vect[3] + costet * vect[5];
// Rotate back to the Tracking System
value_t sinalp = -vecLab[7], cosalp = vecLab[8];
value_t t = cosalp * vecLab[0] - sinalp * vecLab[1];
vecLab[1] = sinalp * vecLab[0] + cosalp * vecLab[1];
vecLab[0] = t;
t = cosalp * vecLab[3] - sinalp * vecLab[4];
vecLab[4] = sinalp * vecLab[3] + cosalp * vecLab[4];
vecLab[3] = t;
// Do the final correcting step to the target plane (linear approximation)
value_t x = vecLab[0], y = vecLab[1], z = vecLab[2];
if (gpu::CAMath::Abs(x - xk) > constants::math::Almost0) {
if (gpu::CAMath::Abs(vecLab[3]) < constants::math::Almost0) {
return false;
}
auto dxFin = xk - vecLab[0];
x += dxFin;
y += vecLab[4] / vecLab[3] * dxFin;
z += vecLab[5] / vecLab[3] * dxFin;
}
// Calculate the track parameters
auto linRef1 = linRef0;
t = 1.f / gpu::CAMath::Sqrt(vecLab[3] * vecLab[3] + vecLab[4] * vecLab[4]);
linRef1.setX(xk);
linRef1.setY(y);
linRef1.setZ(z);
linRef1.setSnp(snpRef1 = vecLab[4] * t); // reassign snpRef1
linRef1.setTgl(vecLab[5] * t);
linRef1.setQ2Pt(q * t / vecLab[6]);
// recalculate parameters of the transported ref track needed for transport of this:
cspRef1 = gpu::CAMath::Sqrt((1 - snpRef1) * (1 + snpRef1));
cspRef1Inv = value_t(1) / cspRef1;
cc = cspRef0 + cspRef1;
ccInv = value_t(1) / cc;
dy2dx = (snpRef0 + snpRef1) * ccInv;
double dxccInv = dx * ccInv, hh = dxccInv * cspRef1Inv * (1 + cspRef0 * cspRef1 + snpRef0 * snpRef1), jj = dx * (dy2dx - snpRef1 * cspRef1Inv);
double f02 = hh * cspRef0Inv;
double f04 = hh * dxccInv * kb;
double f24 = dx * kb;
double f12 = linRef0.getTgl() * (f02 * snpRef1 + jj);
double f13 = dx * (cspRef1 + snpRef1 * dy2dx); // dS
double f14 = linRef0.getTgl() * (f04 * snpRef1 + jj * f24);
// difference between the current and reference state
value_t diff[5];
for (int i = 0; i < 5; i++) {
diff[i] = this->getParam(i) - linRef0.getParam(i);
}
value_t snpUpd = snpRef1 + diff[kSnp] + f24 * diff[kQ2Pt];
if (gpu::CAMath::Abs(snpUpd) > constants::math::Almost1) {
return false;
}
this->setX(xk);
this->setY(linRef1.getY() + diff[kY] + f02 * diff[kSnp] + f04 * diff[kQ2Pt]);
this->setZ(linRef1.getZ() + diff[kZ] + f13 * diff[kTgl] + f14 * diff[kQ2Pt]);
this->setSnp(snpUpd);
this->setTgl(linRef1.getTgl() + diff[kTgl]);
this->setQ2Pt(linRef1.getQ2Pt() + diff[kQ2Pt]);
linRef0 = linRef1; // update reference track
// matrix transformed with Bz component only
value_t &c00 = mC[kSigY2], &c10 = mC[kSigZY], &c11 = mC[kSigZ2], &c20 = mC[kSigSnpY], &c21 = mC[kSigSnpZ],
&c22 = mC[kSigSnp2], &c30 = mC[kSigTglY], &c31 = mC[kSigTglZ], &c32 = mC[kSigTglSnp], &c33 = mC[kSigTgl2],
&c40 = mC[kSigQ2PtY], &c41 = mC[kSigQ2PtZ], &c42 = mC[kSigQ2PtSnp], &c43 = mC[kSigQ2PtTgl],
&c44 = mC[kSigQ2Pt2];
// b = C*ft
double b00 = f02 * c20 + f04 * c40, b01 = f12 * c20 + f14 * c40 + f13 * c30;
double b02 = f24 * c40;
double b10 = f02 * c21 + f04 * c41, b11 = f12 * c21 + f14 * c41 + f13 * c31;
double b12 = f24 * c41;
double b20 = f02 * c22 + f04 * c42, b21 = f12 * c22 + f14 * c42 + f13 * c32;
double b22 = f24 * c42;
double b40 = f02 * c42 + f04 * c44, b41 = f12 * c42 + f14 * c44 + f13 * c43;
double b42 = f24 * c44;
double b30 = f02 * c32 + f04 * c43, b31 = f12 * c32 + f14 * c43 + f13 * c33;
double b32 = f24 * c43;
// a = f*b = f*C*ft
double a00 = f02 * b20 + f04 * b40, a01 = f02 * b21 + f04 * b41, a02 = f02 * b22 + f04 * b42;
double a11 = f12 * b21 + f14 * b41 + f13 * b31, a12 = f12 * b22 + f14 * b42 + f13 * b32;
double a22 = f24 * b42;
// F*C*Ft = C + (b + bt + a)
c00 += b00 + b00 + a00;
c10 += b10 + b01 + a01;
c20 += b20 + b02 + a02;
c30 += b30;
c40 += b40;
c11 += b11 + b11 + a11;
c21 += b21 + b12 + a12;
c31 += b31;
c41 += b41;
c22 += b22 + b22 + a22;
c32 += b32;
c42 += b42;
checkCovariance();
return true;
}
//______________________________________________
template <typename value_T>
GPUd() void TrackParametrizationWithError<value_T>::checkCorrelations()
{
// This function forces the abs of correlation coefficients to be <1.
constexpr float MaxCorr = 0.99;
for (int i = kNParams; i--;) {
for (int j = i; j--;) {