forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackExtrap.cxx
More file actions
1286 lines (1111 loc) · 50.9 KB
/
TrackExtrap.cxx
File metadata and controls
1286 lines (1111 loc) · 50.9 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.
/// \file TrackExtrap.cxx
/// \brief Implementation of tools for track extrapolation
///
/// \author Philippe Pillot, Subatech
#include "MCHTracking/TrackExtrap.h"
#include <TGeoGlobalMagField.h>
#include <TGeoManager.h>
#include <TGeoMaterial.h>
#include <TGeoNode.h>
#include <TGeoShape.h>
#include <TMath.h>
#include "Framework/Logger.h"
#include "MCHTracking/TrackParam.h"
namespace o2
{
namespace mch
{
bool TrackExtrap::sExtrapV2 = false;
double TrackExtrap::sSimpleBValue = 0.;
bool TrackExtrap::sFieldON = false;
std::size_t TrackExtrap::sNCallExtrapToZCov = 0;
std::size_t TrackExtrap::sNCallField = 0;
//__________________________________________________________________________
void TrackExtrap::setField()
{
/// Set field on/off flag.
/// Set field at the centre of the dipole
const double x[3] = {50., 50., SSimpleBPosition};
double b[3] = {0., 0., 0.};
TGeoGlobalMagField::Instance()->Field(x, b);
sSimpleBValue = b[0];
sFieldON = (TMath::Abs(sSimpleBValue) > 1.e-10) ? true : false;
LOG(info) << "Track extrapolation with magnetic field " << (sFieldON ? "ON" : "OFF");
}
//__________________________________________________________________________
double TrackExtrap::getImpactParamFromBendingMomentum(double bendingMomentum)
{
/// Returns impact parameter at vertex in bending plane (cm),
/// from the signed bending momentum "BendingMomentum" in bending plane (GeV/c),
/// using simple values for dipole magnetic field.
/// The sign of "BendingMomentum" is the sign of the charge.
const double correctionFactor = 1.1; // impact parameter is 10% underestimated
if (bendingMomentum == 0.) {
return 1.e10;
}
return correctionFactor * (-0.0003 * sSimpleBValue * SSimpleBLength * SSimpleBPosition / bendingMomentum);
}
//__________________________________________________________________________
double TrackExtrap::getBendingMomentumFromImpactParam(double impactParam)
{
/// Returns signed bending momentum in bending plane (GeV/c),
/// the sign being the sign of the charge for particles moving forward in Z,
/// from the impact parameter "ImpactParam" at vertex in bending plane (cm),
/// using simple values for dipole magnetic field.
const double correctionFactor = 1.1; // bending momentum is 10% underestimated
if (impactParam == 0.) {
return 1.e10;
}
if (sFieldON) {
return correctionFactor * (-0.0003 * sSimpleBValue * SSimpleBLength * SSimpleBPosition / impactParam);
} else {
return SMostProbBendingMomentum;
}
}
//__________________________________________________________________________
void TrackExtrap::linearExtrapToZ(TrackParam& trackParam, double zEnd)
{
/// Track parameters linearly extrapolated to the plane at "zEnd".
/// On return, results from the extrapolation are updated in trackParam.
if (trackParam.getZ() == zEnd) {
return; // nothing to be done if same z
}
// Compute track parameters
double dZ = zEnd - trackParam.getZ();
trackParam.setNonBendingCoor(trackParam.getNonBendingCoor() + trackParam.getNonBendingSlope() * dZ);
trackParam.setBendingCoor(trackParam.getBendingCoor() + trackParam.getBendingSlope() * dZ);
trackParam.setZ(zEnd);
}
//__________________________________________________________________________
void TrackExtrap::linearExtrapToZCov(TrackParam& trackParam, double zEnd, bool updatePropagator)
{
/// Track parameters and their covariances linearly extrapolated to the plane at "zEnd".
/// On return, results from the extrapolation are updated in trackParam.
if (trackParam.getZ() == zEnd) {
return; // nothing to be done if same z
}
// No need to propagate the covariance matrix if it does not exist
if (!trackParam.hasCovariances()) {
LOG(warning) << "Covariance matrix does not exist";
// Extrapolate linearly track parameters to "zEnd"
linearExtrapToZ(trackParam, zEnd);
return;
}
// Compute track parameters
double dZ = zEnd - trackParam.getZ();
trackParam.setNonBendingCoor(trackParam.getNonBendingCoor() + trackParam.getNonBendingSlope() * dZ);
trackParam.setBendingCoor(trackParam.getBendingCoor() + trackParam.getBendingSlope() * dZ);
trackParam.setZ(zEnd);
// Calculate the jacobian related to the track parameters linear extrapolation to "zEnd"
TMatrixD jacob(5, 5);
jacob.UnitMatrix();
jacob(0, 1) = dZ;
jacob(2, 3) = dZ;
// Extrapolate track parameter covariances to "zEnd"
TMatrixD tmp(trackParam.getCovariances(), TMatrixD::kMultTranspose, jacob);
TMatrixD tmp2(jacob, TMatrixD::kMult, tmp);
trackParam.setCovariances(tmp2);
// Update the propagator if required
if (updatePropagator) {
trackParam.updatePropagator(jacob);
}
}
//__________________________________________________________________________
bool TrackExtrap::extrapToZ(TrackParam& trackParam, double zEnd)
{
/// Interface to track parameter extrapolation to the plane at "Z" using Helix or Rungekutta algorithm.
/// On return, the track parameters resulting from the extrapolation are updated in trackParam.
if (!sFieldON) {
linearExtrapToZ(trackParam, zEnd);
return true;
} else if (sExtrapV2) {
return extrapToZRungekuttaV2(trackParam, zEnd);
} else {
return extrapToZRungekutta(trackParam, zEnd);
}
}
//__________________________________________________________________________
bool TrackExtrap::extrapToZCov(TrackParam& trackParam, double zEnd, bool updatePropagator)
{
/// Track parameters and their covariances extrapolated to the plane at "zEnd".
/// On return, results from the extrapolation are updated in trackParam.
++sNCallExtrapToZCov;
if (trackParam.getZ() == zEnd) {
return true; // nothing to be done if same z
}
if (!sFieldON) { // linear extrapolation if no magnetic field
linearExtrapToZCov(trackParam, zEnd, updatePropagator);
return true;
}
// No need to propagate the covariance matrix if it does not exist
if (!trackParam.hasCovariances()) {
LOG(warning) << "Covariance matrix does not exist";
// Extrapolate track parameters to "zEnd"
return extrapToZ(trackParam, zEnd);
}
// Save the actual track parameters
TrackParam trackParamSave(trackParam);
TMatrixD paramSave(trackParamSave.getParameters());
double zBegin = trackParamSave.getZ();
// Get reference to the parameter covariance matrix
const TMatrixD& kParamCov = trackParam.getCovariances();
// Extrapolate track parameters to "zEnd"
// Do not update the covariance matrix if the extrapolation failed
if (!extrapToZ(trackParam, zEnd)) {
return false;
}
// Get reference to the extrapolated parameters
const TMatrixD& extrapParam = trackParam.getParameters();
// Calculate the jacobian related to the track parameters extrapolation to "zEnd"
TMatrixD jacob(5, 5);
jacob.Zero();
TMatrixD dParam(5, 1);
double direction[5] = {-1., -1., 1., 1., -1.};
for (int i = 0; i < 5; i++) {
// Skip jacobian calculation for parameters with no associated error
if (kParamCov(i, i) <= 0.) {
continue;
}
// Small variation of parameter i only
for (int j = 0; j < 5; j++) {
if (j == i) {
dParam(j, 0) = TMath::Sqrt(kParamCov(i, i));
dParam(j, 0) *= TMath::Sign(1., direction[j] * paramSave(j, 0)); // variation always in the same direction
} else {
dParam(j, 0) = 0.;
}
}
// Set new parameters
trackParamSave.setParameters(paramSave);
trackParamSave.addParameters(dParam);
trackParamSave.setZ(zBegin);
// Extrapolate new track parameters to "zEnd"
if (!extrapToZ(trackParamSave, zEnd)) {
LOG(warning) << "Bad covariance matrix";
return false;
}
// Calculate the jacobian
TMatrixD jacobji(trackParamSave.getParameters(), TMatrixD::kMinus, extrapParam);
jacobji *= 1. / dParam(i, 0);
jacob.SetSub(0, i, jacobji);
}
// Extrapolate track parameter covariances to "zEnd"
TMatrixD tmp(kParamCov, TMatrixD::kMultTranspose, jacob);
TMatrixD tmp2(jacob, TMatrixD::kMult, tmp);
trackParam.setCovariances(tmp2);
// Update the propagator if required
if (updatePropagator) {
trackParam.updatePropagator(jacob);
}
return true;
}
//__________________________________________________________________________
bool TrackExtrap::extrapToMID(TrackParam& trackParam)
{
/// Extrapolate the track parameters and their covariances to the z position of the first MID chamber
/// Add to the track parameter covariances the effects of multiple Coulomb scattering in the muon filter
if (trackParam.getZ() == SMIDZ) {
return true; // nothing to be done
}
// check the track position with respect to the muon filter (spectro z<0)
if (trackParam.getZ() < SMuonFilterZBeg) {
LOG(warning) << "The track already passed the beginning of the muon filter";
return false;
}
// propagate through the muon filter and add MCS effets
if (!extrapToZCov(trackParam, SMuonFilterZEnd)) {
return false;
}
addMCSEffect(trackParam, -SMuonFilterThickness, SMuonFilterX0);
// propagate to the first MID chamber
return extrapToZCov(trackParam, SMIDZ);
}
//__________________________________________________________________________
bool TrackExtrap::extrapToVertex(TrackParam& trackParam, double xVtx, double yVtx, double zVtx,
double errXVtx, double errYVtx, bool correctForMCS, bool correctForEnergyLoss,
double xUpstream, double yUpstream, std::optional<double> zUpstream)
{
/// Main method for extrapolation to the vertex:
/// Returns the track parameters and covariances resulting from the extrapolation of the current trackParam
/// Changes parameters and covariances according to multiple scattering and energy loss corrections:
/// if correctForMCS=true: compute parameters using Branson correction and add correction resolution to covariances
/// if correctForMCS=false: add parameter dispersion due to MCS in parameter covariances
/// if correctForEnergyLoss=true: correct parameters for energy loss and add energy loss fluctuation to covariances
/// if correctForEnergyLoss=false: do nothing about energy loss
/// In case correctForMCS=false and the position of the track upstream the absorber is provided, it is used
/// to compute the absorber correction parameters, instead of the extrapolated track position from downstream
if (trackParam.getZ() == zVtx) {
return true; // nothing to be done if already at vertex
}
// Check the vertex position with respect to the absorber (spectro z<0)
if (zVtx < SAbsZBeg) {
if (zVtx < SAbsZEnd) {
LOG(warning) << "Ending Z (" << zVtx << ") downstream the front absorber (zAbsorberEnd = " << SAbsZEnd << ")";
return false;
} else {
LOG(warning) << "Ending Z (" << zVtx << ") inside the front absorber (" << SAbsZBeg << ", " << SAbsZEnd << ")";
return false;
}
}
// check the upstream track position with respect to the absorber if provided and used (spectro z<0)
// zUpstream must be >= SAbsZBeg with 100 µm tolerance to account for numerical precision
if (!correctForMCS && zUpstream && *zUpstream < SAbsZBeg - 0.01) {
if (*zUpstream < SAbsZEnd) {
LOG(warning) << "Upstream Z (" << *zUpstream << ") downstream the front absorber (zAbsorberEnd = " << SAbsZEnd << ")";
return false;
} else {
LOG(warning) << "Upstream Z (" << *zUpstream << ") inside the front absorber (" << SAbsZBeg << ", " << SAbsZEnd << ")";
return false;
}
}
// Check the track position with respect to the vertex and the absorber (spectro z<0)
if (trackParam.getZ() > SAbsZEnd) {
if (trackParam.getZ() > zVtx) {
LOG(warning) << "Starting Z (" << trackParam.getZ() << ") upstream the vertex (zVtx = " << zVtx << ")";
return false;
} else if (trackParam.getZ() > SAbsZBeg) {
LOG(warning) << "Starting Z (" << trackParam.getZ() << ") upstream the front absorber (zAbsorberBegin = " << SAbsZBeg << ")";
return false;
} else {
LOG(warning) << "Starting Z (" << trackParam.getZ() << ") inside the front absorber (" << SAbsZBeg << ", " << SAbsZEnd << ")";
return false;
}
}
// Extrapolate track parameters (and covariances if any) to the end of the absorber
if ((trackParam.hasCovariances() && !extrapToZCov(trackParam, SAbsZEnd)) ||
(!trackParam.hasCovariances() && !extrapToZ(trackParam, SAbsZEnd))) {
return false;
}
// Get absorber correction parameters assuming linear propagation in absorber
double trackXYZOut[3] = {trackParam.getNonBendingCoor(), trackParam.getBendingCoor(), trackParam.getZ()};
double trackXYZIn[3] = {0., 0., 0.};
if (correctForMCS) { // assume linear propagation to the vertex
trackXYZIn[2] = SAbsZBeg;
trackXYZIn[0] = trackXYZOut[0] + (xVtx - trackXYZOut[0]) / (zVtx - trackXYZOut[2]) * (trackXYZIn[2] - trackXYZOut[2]);
trackXYZIn[1] = trackXYZOut[1] + (yVtx - trackXYZOut[1]) / (zVtx - trackXYZOut[2]) * (trackXYZIn[2] - trackXYZOut[2]);
} else if (zUpstream) { // or linear propagation to the upstream track position
trackXYZIn[2] = SAbsZBeg;
trackXYZIn[0] = trackXYZOut[0] + (xUpstream - trackXYZOut[0]) / (*zUpstream - trackXYZOut[2]) * (trackXYZIn[2] - trackXYZOut[2]);
trackXYZIn[1] = trackXYZOut[1] + (yUpstream - trackXYZOut[1]) / (*zUpstream - trackXYZOut[2]) * (trackXYZIn[2] - trackXYZOut[2]);
} else { // or standard propagation without vertex constraint
TrackParam trackParamIn(trackParam);
if (!extrapToZ(trackParamIn, SAbsZBeg)) {
return false;
}
trackXYZIn[0] = trackParamIn.getNonBendingCoor();
trackXYZIn[1] = trackParamIn.getBendingCoor();
trackXYZIn[2] = trackParamIn.getZ();
}
double pTot = trackParam.p();
double pathLength(0.), f0(0.), f1(0.), f2(0.), meanRho(0.), totalELoss(0.), sigmaELoss2(0.);
if (!getAbsorberCorrectionParam(trackXYZIn, trackXYZOut, pTot, pathLength, f0, f1, f2, meanRho, totalELoss, sigmaELoss2)) {
return false;
}
// Compute track parameters and covariances at vertex according to correctForMCS and correctForEnergyLoss flags
if (correctForMCS) {
if (correctForEnergyLoss) {
// Correct for multiple scattering and energy loss
correctELossEffectInAbsorber(trackParam, 0.5 * totalELoss, 0.5 * sigmaELoss2);
if (!correctMCSEffectInAbsorber(trackParam, xVtx, yVtx, zVtx, errXVtx, errYVtx, trackXYZIn[2], pathLength, f0, f1, f2)) {
return false;
}
correctELossEffectInAbsorber(trackParam, 0.5 * totalELoss, 0.5 * sigmaELoss2);
} else {
// Correct for multiple scattering
if (!correctMCSEffectInAbsorber(trackParam, xVtx, yVtx, zVtx, errXVtx, errYVtx, trackXYZIn[2], pathLength, f0, f1, f2)) {
return false;
}
}
} else {
if (correctForEnergyLoss) {
// Correct for energy loss add multiple scattering dispersion in covariance matrix
correctELossEffectInAbsorber(trackParam, 0.5 * totalELoss, 0.5 * sigmaELoss2);
addMCSEffectInAbsorber(trackParam, -pathLength, f0, f1, f2); // (spectro. (z<0))
if (!extrapToZCov(trackParam, trackXYZIn[2])) {
return false;
}
correctELossEffectInAbsorber(trackParam, 0.5 * totalELoss, 0.5 * sigmaELoss2);
if (!extrapToZCov(trackParam, zVtx)) {
return false;
}
} else {
// add multiple scattering dispersion in covariance matrix
addMCSEffectInAbsorber(trackParam, -pathLength, f0, f1, f2); // (spectro. (z<0))
if (!extrapToZCov(trackParam, zVtx)) {
return false;
}
}
}
return true;
}
//__________________________________________________________________________
bool TrackExtrap::getAbsorberCorrectionParam(double trackXYZIn[3], double trackXYZOut[3], double pTotal,
double& pathLength, double& f0, double& f1, double& f2,
double& meanRho, double& totalELoss, double& sigmaELoss2)
{
/// Parameters used to correct for Multiple Coulomb Scattering and energy loss in absorber
/// Calculated assuming a linear propagation from trackXYZIn to trackXYZOut (order is important)
/// pathLength: path length between trackXYZIn and trackXYZOut (cm)
/// f0: 0th moment of z calculated with the inverse radiation-length distribution
/// f1: 1st moment of z calculated with the inverse radiation-length distribution
/// f2: 2nd moment of z calculated with the inverse radiation-length distribution
/// meanRho: average density of crossed material (g/cm3)
/// totalELoss: total energy loss in absorber
/// sigmaELoss2: square of energy loss fluctuation in absorber
// Check whether the geometry is available
if (!gGeoManager) {
LOG(warning) << "geometry is missing";
return false;
}
// Initialize starting point and direction
pathLength = TMath::Sqrt((trackXYZOut[0] - trackXYZIn[0]) * (trackXYZOut[0] - trackXYZIn[0]) +
(trackXYZOut[1] - trackXYZIn[1]) * (trackXYZOut[1] - trackXYZIn[1]) +
(trackXYZOut[2] - trackXYZIn[2]) * (trackXYZOut[2] - trackXYZIn[2]));
if (pathLength < TGeoShape::Tolerance()) {
LOG(warning) << "path length is too small";
return false;
}
double b[3] = {(trackXYZOut[0] - trackXYZIn[0]) / pathLength, (trackXYZOut[1] - trackXYZIn[1]) / pathLength, (trackXYZOut[2] - trackXYZIn[2]) / pathLength};
TGeoNode* currentnode = gGeoManager->InitTrack(trackXYZIn, b);
if (!currentnode) {
LOG(warning) << "starting point out of geometry";
return false;
}
// loop over absorber slices and calculate absorber's parameters
f0 = f1 = f2 = meanRho = totalELoss = 0.;
double sigmaELoss(0.);
double zB = trackXYZIn[2];
double remainingPathLength = pathLength;
do {
// Get material properties
TGeoMaterial* material = currentnode->GetVolume()->GetMedium()->GetMaterial();
double rho = material->GetDensity(); // material density (g/cm3)
double x0 = material->GetRadLen(); // radiation-length (cm-1)
double atomicZ = material->GetZ(); // Z of material
double atomicZoverA(0.); // Z/A of material
if (material->IsMixture()) {
TGeoMixture* mixture = static_cast<TGeoMixture*>(material);
double sum(0.);
for (int iel = 0; iel < mixture->GetNelements(); ++iel) {
sum += mixture->GetWmixt()[iel];
atomicZoverA += mixture->GetWmixt()[iel] * mixture->GetZmixt()[iel] / mixture->GetAmixt()[iel];
}
atomicZoverA /= sum;
} else {
atomicZoverA = atomicZ / material->GetA();
}
// Get path length within this material
gGeoManager->FindNextBoundary(remainingPathLength);
double localPathLength = gGeoManager->GetStep() + 1.e-6;
// Check if boundary within remaining path length. If so, make sure to cross the boundary to prepare the next step
if (localPathLength >= remainingPathLength) {
localPathLength = remainingPathLength;
} else {
currentnode = gGeoManager->Step();
if (!currentnode) {
LOG(warning) << "navigation failed";
return false;
}
if (!gGeoManager->IsEntering()) {
// make another small step to try to enter in new absorber slice
gGeoManager->SetStep(0.001);
currentnode = gGeoManager->Step();
if (!gGeoManager->IsEntering() || !currentnode) {
LOG(warning) << "navigation failed";
return false;
}
localPathLength += 0.001;
}
}
// calculate absorber's parameters
double zE = b[2] * localPathLength + zB;
double dzB = zB - trackXYZIn[2];
double dzE = zE - trackXYZIn[2];
f0 += localPathLength / x0;
f1 += (dzE * dzE - dzB * dzB) / b[2] / b[2] / x0 / 2.;
f2 += (dzE * dzE * dzE - dzB * dzB * dzB) / b[2] / b[2] / b[2] / x0 / 3.;
meanRho += localPathLength * rho;
totalELoss += betheBloch(pTotal, localPathLength, rho, atomicZ, atomicZoverA);
sigmaELoss += energyLossFluctuation(pTotal, localPathLength, rho, atomicZoverA);
// prepare next step
zB = zE;
remainingPathLength -= localPathLength;
} while (remainingPathLength > TGeoShape::Tolerance());
meanRho /= pathLength;
sigmaELoss2 = sigmaELoss * sigmaELoss;
return true;
}
//__________________________________________________________________________
double TrackExtrap::getMCSAngle2(const TrackParam& param, double dZ, double x0)
{
/// Return the angular dispersion square due to multiple Coulomb scattering
/// through a material of thickness "abs(dZ)" and of radiation length "x0"
/// assuming linear propagation and using the small angle approximation.
double bendingSlope = param.getBendingSlope();
double nonBendingSlope = param.getNonBendingSlope();
double inverseTotalMomentum2 = param.getInverseBendingMomentum() * param.getInverseBendingMomentum() *
(1.0 + bendingSlope * bendingSlope) /
(1.0 + bendingSlope * bendingSlope + nonBendingSlope * nonBendingSlope);
// Path length in the material
double pathLength = TMath::Abs(dZ) * TMath::Sqrt(1.0 + bendingSlope * bendingSlope + nonBendingSlope * nonBendingSlope);
// relativistic velocity
double velo = 1.;
// Angular dispersion square of the track (variance) in a plane perpendicular to the trajectory
double theta02 = 0.0136 / velo * (1 + 0.038 * TMath::Log(pathLength / x0));
return theta02 * theta02 * inverseTotalMomentum2 * pathLength / x0;
}
//__________________________________________________________________________
void TrackExtrap::addMCSEffect(TrackParam& trackParam, double dZ, double x0)
{
/// Add to the track parameter covariances the effects of multiple Coulomb scattering
/// through a material of thickness "abs(dZ)" and of radiation length "x0"
/// assuming linear propagation and using the small angle approximation.
/// dZ = zOut - zIn (sign is important) and "param" is assumed to be given zOut.
/// If x0 <= 0., assume dZ = pathLength/x0 and consider the material thickness as negligible.
double bendingSlope = trackParam.getBendingSlope();
double nonBendingSlope = trackParam.getNonBendingSlope();
double inverseBendingMomentum = trackParam.getInverseBendingMomentum();
double inverseTotalMomentum2 = inverseBendingMomentum * inverseBendingMomentum * (1.0 + bendingSlope * bendingSlope) /
(1.0 + bendingSlope * bendingSlope + nonBendingSlope * nonBendingSlope);
// Path length in the material
double signedPathLength = dZ * TMath::Sqrt(1.0 + bendingSlope * bendingSlope + nonBendingSlope * nonBendingSlope);
double pathLengthOverX0 = (x0 > 0.) ? TMath::Abs(signedPathLength) / x0 : TMath::Abs(signedPathLength);
// relativistic velocity
double velo = 1.;
// Angular dispersion square of the track (variance) in a plane perpendicular to the trajectory
double theta02 = 0.0136 / velo * (1 + 0.038 * TMath::Log(pathLengthOverX0));
theta02 *= theta02 * inverseTotalMomentum2 * pathLengthOverX0;
double varCoor = (x0 > 0.) ? signedPathLength * signedPathLength * theta02 / 3. : 0.;
double varSlop = theta02;
double covCorrSlope = (x0 > 0.) ? signedPathLength * theta02 / 2. : 0.;
// Set MCS covariance matrix
TMatrixD newParamCov(trackParam.getCovariances());
// Non bending plane
newParamCov(0, 0) += varCoor;
newParamCov(0, 1) += covCorrSlope;
newParamCov(1, 0) += covCorrSlope;
newParamCov(1, 1) += varSlop;
// Bending plane
newParamCov(2, 2) += varCoor;
newParamCov(2, 3) += covCorrSlope;
newParamCov(3, 2) += covCorrSlope;
newParamCov(3, 3) += varSlop;
// Set momentum related covariances if B!=0
if (sFieldON) {
// compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeY
double dqPxydSlopeX =
inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope * nonBendingSlope + bendingSlope * bendingSlope);
double dqPxydSlopeY = -inverseBendingMomentum * nonBendingSlope * nonBendingSlope * bendingSlope /
(1. + bendingSlope * bendingSlope) /
(1. + nonBendingSlope * nonBendingSlope + bendingSlope * bendingSlope);
// Inverse bending momentum (due to dependences with bending and non bending slopes)
newParamCov(4, 0) += dqPxydSlopeX * covCorrSlope;
newParamCov(0, 4) += dqPxydSlopeX * covCorrSlope;
newParamCov(4, 1) += dqPxydSlopeX * varSlop;
newParamCov(1, 4) += dqPxydSlopeX * varSlop;
newParamCov(4, 2) += dqPxydSlopeY * covCorrSlope;
newParamCov(2, 4) += dqPxydSlopeY * covCorrSlope;
newParamCov(4, 3) += dqPxydSlopeY * varSlop;
newParamCov(3, 4) += dqPxydSlopeY * varSlop;
newParamCov(4, 4) += (dqPxydSlopeX * dqPxydSlopeX + dqPxydSlopeY * dqPxydSlopeY) * varSlop;
}
// Set new covariances
trackParam.setCovariances(newParamCov);
}
//__________________________________________________________________________
void TrackExtrap::addMCSEffectInAbsorber(TrackParam& param, double signedPathLength, double f0, double f1, double f2)
{
/// Add to the track parameter covariances the effects of multiple Coulomb scattering
/// signedPathLength must have the sign of (zOut - zIn) where all other parameters are assumed to be given at zOut.
// absorber related covariance parameters
double bendingSlope = param.getBendingSlope();
double nonBendingSlope = param.getNonBendingSlope();
double inverseBendingMomentum = param.getInverseBendingMomentum();
double alpha2 = 0.0136 * 0.0136 * inverseBendingMomentum * inverseBendingMomentum * (1.0 + bendingSlope * bendingSlope) /
(1.0 + bendingSlope * bendingSlope + nonBendingSlope * nonBendingSlope); // velocity = 1
double pathLength = TMath::Abs(signedPathLength);
double varCoor = alpha2 * (pathLength * pathLength * f0 - 2. * pathLength * f1 + f2);
double covCorrSlope = TMath::Sign(1., signedPathLength) * alpha2 * (pathLength * f0 - f1);
double varSlop = alpha2 * f0;
// Set MCS covariance matrix
TMatrixD newParamCov(param.getCovariances());
// Non bending plane
newParamCov(0, 0) += varCoor;
newParamCov(0, 1) += covCorrSlope;
newParamCov(1, 0) += covCorrSlope;
newParamCov(1, 1) += varSlop;
// Bending plane
newParamCov(2, 2) += varCoor;
newParamCov(2, 3) += covCorrSlope;
newParamCov(3, 2) += covCorrSlope;
newParamCov(3, 3) += varSlop;
// Set momentum related covariances if B!=0
if (sFieldON) {
// compute derivative d(q/Pxy) / dSlopeX and d(q/Pxy) / dSlopeY
double dqPxydSlopeX = inverseBendingMomentum * nonBendingSlope / (1. + nonBendingSlope * nonBendingSlope + bendingSlope * bendingSlope);
double dqPxydSlopeY = -inverseBendingMomentum * nonBendingSlope * nonBendingSlope * bendingSlope /
(1. + bendingSlope * bendingSlope) / (1. + nonBendingSlope * nonBendingSlope + bendingSlope * bendingSlope);
// Inverse bending momentum (due to dependences with bending and non bending slopes)
newParamCov(4, 0) += dqPxydSlopeX * covCorrSlope;
newParamCov(0, 4) += dqPxydSlopeX * covCorrSlope;
newParamCov(4, 1) += dqPxydSlopeX * varSlop;
newParamCov(1, 4) += dqPxydSlopeX * varSlop;
newParamCov(4, 2) += dqPxydSlopeY * covCorrSlope;
newParamCov(2, 4) += dqPxydSlopeY * covCorrSlope;
newParamCov(4, 3) += dqPxydSlopeY * varSlop;
newParamCov(3, 4) += dqPxydSlopeY * varSlop;
newParamCov(4, 4) += (dqPxydSlopeX * dqPxydSlopeX + dqPxydSlopeY * dqPxydSlopeY) * varSlop;
}
// Set new covariances
param.setCovariances(newParamCov);
}
//__________________________________________________________________________
double TrackExtrap::betheBloch(double pTotal, double pathLength, double rho, double atomicZ, double atomicZoverA)
{
/// Returns the mean total momentum energy loss of muon with total momentum='pTotal'
/// in the absorber layer of lenght='pathLength', density='rho', Z='atomicZ' and mean Z/A='atomicZoverA'
/// This is the parameterization of the Bethe-Bloch formula inspired by Geant.
static constexpr double mK = 0.307075e-3; // [GeV*cm^2/g]
static constexpr double me = 0.511e-3; // [GeV/c^2]
static constexpr double x0 = 0.2 * 2.303; // density effect first junction point * 2.303
static constexpr double x1 = 3. * 2.303; // density effect second junction point * 2.303
double bg = pTotal / SMuMass; // beta*gamma
double bg2 = bg * bg;
double maxT = 2 * me * bg2; // neglecting the electron mass
// mean exitation energy (GeV)
double mI = (atomicZ < 13) ? (12. * atomicZ + 7.) * 1.e-9 : (9.76 * atomicZ + 58.8 * TMath::Power(atomicZ, -0.19)) * 1.e-9;
// density effect
double x = TMath::Log(bg);
double lhwI = TMath::Log(28.816 * 1e-9 * TMath::Sqrt(rho * atomicZoverA) / mI);
double d2(0.);
if (x > x1) {
d2 = lhwI + x - 0.5;
} else if (x > x0) {
double r = (x1 - x) / (x1 - x0);
d2 = lhwI + x - 0.5 + (0.5 - lhwI - x0) * r * r * r;
}
return pathLength * rho * (mK * atomicZoverA * (1 + bg2) / bg2 * (0.5 * TMath::Log(2 * me * bg2 * maxT / (mI * mI)) - bg2 / (1 + bg2) - d2));
}
//__________________________________________________________________________
double TrackExtrap::energyLossFluctuation(double pTotal, double pathLength, double rho, double atomicZoverA)
{
/// Returns the total momentum energy loss fluctuation of muon with total momentum='pTotal'
/// in the absorber layer of lenght='pathLength', density='rho', A='atomicA' and Z='atomicZ'
static constexpr double mK = 0.307075e-3; // GeV.g^-1.cm^2
double p2 = pTotal * pTotal;
double beta2 = p2 / (p2 + SMuMass * SMuMass);
double fwhm = 2. * mK * rho * pathLength * atomicZoverA / beta2; // FWHM of the energy loss Landau distribution
return fwhm / TMath::Sqrt(8. * log(2.)); // gaussian: fwmh = 2 * srqt(2*ln(2)) * sigma (i.e. fwmh = 2.35 * sigma)
}
//__________________________________________________________________________
bool TrackExtrap::correctMCSEffectInAbsorber(TrackParam& param, double xVtx, double yVtx, double zVtx, double errXVtx, double errYVtx,
double absZBeg, double pathLength, double f0, double f1, double f2)
{
/// Correct parameters and corresponding covariances using Branson correction
/// - input param are parameters and covariances at the end of absorber
/// - output param are parameters and covariances at vertex
/// Absorber correction parameters are supposed to be calculated at the current track z-position
// Position of the Branson plane (spectro. (z<0))
double zB = (f1 > 0.) ? absZBeg - f2 / f1 : 0.;
// Add MCS effects to current parameter covariances (spectro. (z<0))
addMCSEffectInAbsorber(param, -pathLength, f0, f1, f2);
// Get track parameters and covariances in the Branson plane corrected for magnetic field effect
if (!extrapToZCov(param, zVtx)) {
return false;
}
linearExtrapToZCov(param, zB);
// compute track parameters at vertex
TMatrixD newParam(5, 1);
newParam(0, 0) = xVtx;
newParam(1, 0) = (param.getNonBendingCoor() - xVtx) / (zB - zVtx);
newParam(2, 0) = yVtx;
newParam(3, 0) = (param.getBendingCoor() - yVtx) / (zB - zVtx);
newParam(4, 0) = param.getCharge() / param.p() *
TMath::Sqrt(1.0 + newParam(1, 0) * newParam(1, 0) + newParam(3, 0) * newParam(3, 0)) /
TMath::Sqrt(1.0 + newParam(3, 0) * newParam(3, 0));
// Get covariances in (X, SlopeX, Y, SlopeY, q*PTot) coordinate system
TMatrixD paramCovP(param.getCovariances());
cov2CovP(param.getParameters(), paramCovP);
// Get the covariance matrix in the (XVtx, X, YVtx, Y, q*PTot) coordinate system
TMatrixD paramCovVtx(5, 5);
paramCovVtx.Zero();
paramCovVtx(0, 0) = errXVtx * errXVtx;
paramCovVtx(1, 1) = paramCovP(0, 0);
paramCovVtx(2, 2) = errYVtx * errYVtx;
paramCovVtx(3, 3) = paramCovP(2, 2);
paramCovVtx(4, 4) = paramCovP(4, 4);
paramCovVtx(1, 3) = paramCovP(0, 2);
paramCovVtx(3, 1) = paramCovP(2, 0);
paramCovVtx(1, 4) = paramCovP(0, 4);
paramCovVtx(4, 1) = paramCovP(4, 0);
paramCovVtx(3, 4) = paramCovP(2, 4);
paramCovVtx(4, 3) = paramCovP(4, 2);
// Jacobian of the transformation (XVtx, X, YVtx, Y, q*PTot) -> (XVtx, SlopeXVtx, YVtx, SlopeYVtx, q*PTotVtx)
TMatrixD jacob(5, 5);
jacob.UnitMatrix();
jacob(1, 0) = -1. / (zB - zVtx);
jacob(1, 1) = 1. / (zB - zVtx);
jacob(3, 2) = -1. / (zB - zVtx);
jacob(3, 3) = 1. / (zB - zVtx);
// Compute covariances at vertex in the (XVtx, SlopeXVtx, YVtx, SlopeYVtx, q*PTotVtx) coordinate system
TMatrixD tmp(paramCovVtx, TMatrixD::kMultTranspose, jacob);
TMatrixD newParamCov(jacob, TMatrixD::kMult, tmp);
// Compute covariances at vertex in the (XVtx, SlopeXVtx, YVtx, SlopeYVtx, q/PyzVtx) coordinate system
covP2Cov(newParam, newParamCov);
// Set parameters and covariances at vertex
param.setParameters(newParam);
param.setZ(zVtx);
param.setCovariances(newParamCov);
return true;
}
//__________________________________________________________________________
void TrackExtrap::correctELossEffectInAbsorber(TrackParam& param, double eLoss, double sigmaELoss2)
{
/// Correct parameters for energy loss and add energy loss fluctuation effect to covariances
// Get parameter covariances in (X, SlopeX, Y, SlopeY, q*PTot) coordinate system
TMatrixD newParamCov(param.getCovariances());
cov2CovP(param.getParameters(), newParamCov);
// Compute new parameters corrected for energy loss
double p = param.p();
double e = TMath::Sqrt(p * p + SMuMass * SMuMass);
double eCorr = e + eLoss;
double pCorr = TMath::Sqrt(eCorr * eCorr - SMuMass * SMuMass);
double nonBendingSlope = param.getNonBendingSlope();
double bendingSlope = param.getBendingSlope();
param.setInverseBendingMomentum(param.getCharge() / pCorr *
TMath::Sqrt(1.0 + nonBendingSlope * nonBendingSlope + bendingSlope * bendingSlope) /
TMath::Sqrt(1.0 + bendingSlope * bendingSlope));
// Add effects of energy loss fluctuation to covariances
newParamCov(4, 4) += eCorr * eCorr / pCorr / pCorr * sigmaELoss2;
// Get new parameter covariances in (X, SlopeX, Y, SlopeY, q/Pyz) coordinate system
covP2Cov(param.getParameters(), newParamCov);
// Set new parameter covariances
param.setCovariances(newParamCov);
}
//__________________________________________________________________________
void TrackExtrap::cov2CovP(const TMatrixD& param, TMatrixD& cov)
{
/// change coordinate system: (X, SlopeX, Y, SlopeY, q/Pyz) -> (X, SlopeX, Y, SlopeY, q*PTot)
/// parameters (param) are given in the (X, SlopeX, Y, SlopeY, q/Pyz) coordinate system
// charge * total momentum
double qPTot = TMath::Sqrt(1. + param(1, 0) * param(1, 0) + param(3, 0) * param(3, 0)) /
TMath::Sqrt(1. + param(3, 0) * param(3, 0)) / param(4, 0);
// Jacobian of the opposite transformation
TMatrixD jacob(5, 5);
jacob.UnitMatrix();
jacob(4, 1) = qPTot * param(1, 0) / (1. + param(1, 0) * param(1, 0) + param(3, 0) * param(3, 0));
jacob(4, 3) = -qPTot * param(1, 0) * param(1, 0) * param(3, 0) /
(1. + param(3, 0) * param(3, 0)) / (1. + param(1, 0) * param(1, 0) + param(3, 0) * param(3, 0));
jacob(4, 4) = -qPTot / param(4, 0);
// compute covariances in new coordinate system
TMatrixD tmp(cov, TMatrixD::kMultTranspose, jacob);
cov.Mult(jacob, tmp);
}
//__________________________________________________________________________
void TrackExtrap::covP2Cov(const TMatrixD& param, TMatrixD& covP)
{
/// change coordinate system: (X, SlopeX, Y, SlopeY, q*PTot) -> (X, SlopeX, Y, SlopeY, q/Pyz)
/// parameters (param) are given in the (X, SlopeX, Y, SlopeY, q/Pyz) coordinate system
// charge * total momentum
double qPTot = TMath::Sqrt(1. + param(1, 0) * param(1, 0) + param(3, 0) * param(3, 0)) /
TMath::Sqrt(1. + param(3, 0) * param(3, 0)) / param(4, 0);
// Jacobian of the transformation
TMatrixD jacob(5, 5);
jacob.UnitMatrix();
jacob(4, 1) = param(4, 0) * param(1, 0) / (1. + param(1, 0) * param(1, 0) + param(3, 0) * param(3, 0));
jacob(4, 3) = -param(4, 0) * param(1, 0) * param(1, 0) * param(3, 0) /
(1. + param(3, 0) * param(3, 0)) / (1. + param(1, 0) * param(1, 0) + param(3, 0) * param(3, 0));
jacob(4, 4) = -param(4, 0) / qPTot;
// compute covariances in new coordinate system
TMatrixD tmp(covP, TMatrixD::kMultTranspose, jacob);
covP.Mult(jacob, tmp);
}
//__________________________________________________________________________
void TrackExtrap::convertTrackParamForExtrap(TrackParam& trackParam, double forwardBackward, double* v3)
{
/// Set vector of Geant3 parameters pointed to by "v3" from track parameters in trackParam.
/// Since TrackParam is only geometry, one uses "forwardBackward"
/// to know whether the particle is going forward (+1) or backward (-1).
v3[0] = trackParam.getNonBendingCoor(); // X
v3[1] = trackParam.getBendingCoor(); // Y
v3[2] = trackParam.getZ(); // Z
double pYZ = TMath::Abs(1.0 / trackParam.getInverseBendingMomentum());
double pZ = pYZ / TMath::Sqrt(1.0 + trackParam.getBendingSlope() * trackParam.getBendingSlope());
v3[6] = TMath::Sqrt(pYZ * pYZ + pZ * pZ * trackParam.getNonBendingSlope() * trackParam.getNonBendingSlope()); // P
v3[5] = -forwardBackward * pZ / v3[6]; // PZ/P spectro. z<0
v3[3] = trackParam.getNonBendingSlope() * v3[5]; // PX/P
v3[4] = trackParam.getBendingSlope() * v3[5]; // PY/P
}
//__________________________________________________________________________
void TrackExtrap::recoverTrackParam(double* v3, double charge, TrackParam& trackParam)
{
/// Set track parameters in trackParam from Geant3 parameters pointed to by "v3",
/// assumed to be calculated for forward motion in Z.
/// "InverseBendingMomentum" is signed with "charge".
trackParam.setNonBendingCoor(v3[0]); // X
trackParam.setBendingCoor(v3[1]); // Y
trackParam.setZ(v3[2]); // Z
double pYZ = v3[6] * TMath::Sqrt((1. - v3[3]) * (1. + v3[3]));
trackParam.setInverseBendingMomentum(charge / pYZ);
trackParam.setBendingSlope(v3[4] / v3[5]);
trackParam.setNonBendingSlope(v3[3] / v3[5]);
}
//__________________________________________________________________________
bool TrackExtrap::extrapToZRungekutta(TrackParam& trackParam, double zEnd)
{
/// Track parameter extrapolation to the plane at "Z" using Rungekutta algorithm.
/// On return, the track parameters resulting from the extrapolation are updated in trackParam.
/// Return false in case of failure and let the trackParam as they were when that happened
if (trackParam.getZ() == zEnd) {
return true; // nothing to be done if same Z
}
double forwardBackward; // +1 if forward, -1 if backward
if (zEnd < trackParam.getZ()) {
forwardBackward = 1.0; // spectro. z<0
} else {
forwardBackward = -1.0;
}
// sign of charge (sign of fInverseBendingMomentum if forward motion)
// must be changed if backward extrapolation
double chargeExtrap = forwardBackward * TMath::Sign(double(1.0), trackParam.getInverseBendingMomentum());
double v3[7] = {0.}, v3New[7] = {0.};
double dZ(0.), step(0.);
int stepNumber = 0;
// Extrapolation loop (until within tolerance or the track turn around)
double residue = zEnd - trackParam.getZ();
while (TMath::Abs(residue) > SRungeKuttaMaxResidue) {
dZ = zEnd - trackParam.getZ();
// step length assuming linear trajectory
step = dZ * TMath::Sqrt(1.0 + trackParam.getBendingSlope() * trackParam.getBendingSlope() +
trackParam.getNonBendingSlope() * trackParam.getNonBendingSlope());
convertTrackParamForExtrap(trackParam, forwardBackward, v3);
do { // reduce step length while zEnd overstepped
if (++stepNumber > SMaxStepNumber) {
LOG(warning) << "Too many trials";
return false;
}
step = TMath::Abs(step);
if (!extrapOneStepRungekutta(chargeExtrap, step, v3, v3New)) {
return false;
}
residue = zEnd - v3New[2];
step *= dZ / (v3New[2] - trackParam.getZ());
} while (residue * dZ < 0 && TMath::Abs(residue) > SRungeKuttaMaxResidue);
if (v3New[5] * v3[5] < 0) { // the track turned around
LOG(warning) << "The track turned around";
return false;
}
recoverTrackParam(v3New, chargeExtrap * forwardBackward, trackParam);
}
// terminate the extropolation with a straight line up to the exact "zEnd" value
trackParam.setNonBendingCoor(trackParam.getNonBendingCoor() + residue * trackParam.getNonBendingSlope());
trackParam.setBendingCoor(trackParam.getBendingCoor() + residue * trackParam.getBendingSlope());
trackParam.setZ(zEnd);
return true;
}
//__________________________________________________________________________
bool TrackExtrap::extrapToZRungekuttaV2(TrackParam& trackParam, double zEnd)
{
/// Track parameter extrapolation to the plane at "Z" using Rungekutta algorithm.
/// On return, the track parameters resulting from the extrapolation are updated in trackParam.
/// Return false in case of failure and let the trackParam as they were when that happened
if (trackParam.getZ() == zEnd) {
return true; // nothing to be done if same Z
}
double residue = zEnd - trackParam.getZ();
double forwardBackward = (residue < 0) ? 1. : -1.; // +1 if forward, -1 if backward
double v3[7] = {0.};
convertTrackParamForExtrap(trackParam, forwardBackward, v3);
double charge = TMath::Sign(double(1.), trackParam.getInverseBendingMomentum());
// Extrapolation loop (until within tolerance or the track turn around)
double v3New[7] = {0.};
int stepNumber = 0;
while (true) {
if (++stepNumber > SMaxStepNumber) {
LOG(warning) << "Too many trials";
return false;
}
// step length assuming linear trajectory
double slopeX = v3[3] / v3[5];
double slopeY = v3[4] / v3[5];
double step = TMath::Abs(residue) * TMath::Sqrt(1.0 + slopeX * slopeX + slopeY * slopeY);
if (!extrapOneStepRungekutta(forwardBackward * charge, step, v3, v3New)) {
return false;
}
if (v3New[5] * v3[5] < 0) {
LOG(warning) << "The track turned around";
return false;
}
residue = zEnd - v3New[2];
if (TMath::Abs(residue) < SRungeKuttaMaxResidueV2) {
break;
}
for (int i = 0; i < 7; ++i) {
v3[i] = v3New[i];
}
// invert the sens of propagation if the track went too far
if (forwardBackward * residue > 0) {
forwardBackward = -forwardBackward;
v3[3] = -v3[3];
v3[4] = -v3[4];
v3[5] = -v3[5];
}
}
recoverTrackParam(v3New, charge, trackParam);
// terminate the extrapolation with a straight line up to the exact "zEnd" value
trackParam.setNonBendingCoor(trackParam.getNonBendingCoor() + residue * trackParam.getNonBendingSlope());