Project
Loading...
Searching...
No Matches
Propagator.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
13#include "GPUCommonLogger.h"
14#include "GPUCommonConstants.h"
15#include "GPUCommonMath.h"
17#include "MathUtils/Utils.h"
20
21using namespace o2::base;
22using namespace o2::gpu;
23
24#if !defined(GPUCA_GPUCODE)
25#include "Field/MagFieldFast.h" // Don't use this on the GPU
26#endif
27
28#if !defined(GPUCA_STANDALONE) && !defined(GPUCA_GPUCODE)
29#include "Field/MagneticField.h"
33#include <TGeoGlobalMagField.h>
34
35template <typename value_T>
37{
38 if (uninitialized) {
39 return;
40 }
42 updateField();
43}
44
45//____________________________________________________________
46template <typename value_T>
48{
49 if (!mField) {
50 mField = static_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField());
51 // The legacy FairRunAna fallback was removed with the FairRoot analysis-run
52 // class: O2 never instantiates one, so FairRunAna::Instance() was null here
53 // and the call was undefined behaviour; the fatal below is the real outcome.
54 if (!mField) {
55 LOG(fatal) << "Magnetic field is not initialized!";
56 }
57 if (!mField->getFastField() && mField->fastFieldExists()) {
58 mField->AllowFastField(true);
59 mFieldFast = mField->getFastField();
60 }
61 }
62 const value_type xyz[3] = {0.};
63 if (mFieldFast) {
64 mFieldFast->GetBz(xyz, mNominalBz);
65 } else {
66 mNominalBz = mField->GetBz(xyz[0], xyz[1], xyz[2]);
67 }
68}
69
70//____________________________________________________________
71template <typename value_T>
72int PropagatorImpl<value_T>::initFieldFromGRP(const std::string grpFileName, bool verbose)
73{
75 if (verbose) {
76 LOG(info) << "Loading field from GRP of " << grpFileName;
77 }
78 const auto grp = o2::parameters::GRPObject::loadFrom(grpFileName);
79 if (!grp) {
80 return -1;
81 }
82 if (verbose) {
83 grp->print();
84 }
85 return initFieldFromGRP(grp);
86}
87
88//____________________________________________________________
89template <typename value_T>
91{
92 return initFieldFromGRP(grp->getL3Current(), grp->getDipoleCurrent(), grp->getFieldUniformity(), verbose);
93}
94
95//____________________________________________________________
96template <typename value_T>
98{
100 return initFieldFromGRP(grp->getL3Current(), grp->getDipoleCurrent(), grp->getFieldUniformity(), verbose);
101}
102
103//____________________________________________________________
104template <typename value_T>
105int PropagatorImpl<value_T>::initFieldFromGRP(float currL3, float currDip, bool uniform, bool verbose)
106{
108 auto fldGlo = static_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField());
109 if (fldGlo) { // global field object was already initialized, reuse it if it is locked (as it normally should be)
110 float _currL3(currL3), _currDip(currDip);
111 auto newFieldType = fldGlo->getFieldMapScale(_currL3, _currDip, uniform);
112 bool sameFieldType = newFieldType == fldGlo->getMapType();
113 if (!sameFieldType) {
114 LOGP(warn, "Existing B-field type {} cannot be rescaled to type {} requested by the GRP", int(fldGlo->getMapType()), int(newFieldType));
115 }
116 if (TGeoGlobalMagField::Instance()->IsLocked() && sameFieldType) {
117 if (Instance()->mField && Instance()->mField != fldGlo) { // just make sure that cached field is the same as the global one
118 std::string name{"PropagatorF"};
119 if constexpr (std::is_same_v<value_T, double>) {
120 std::string name{"PropagatorD"};
121 }
122 LOGP(fatal, "Magnetic field pointer cached in the {} instance differs from the gloabal field pointer", name);
123 }
124 if (verbose) {
125 LOGP(info, "Rescaling magnetic field to currents L3: {}, Dipole: {}, UniformityFlag: {}", currL3, currDip, uniform);
126 }
127 fldGlo->rescaleField(currL3, currDip, uniform);
128 } else {
129 LOGP(warn, "Destroying existing B field instance. This may invalidate field pointer cached in other objects");
130 delete TGeoGlobalMagField::Instance();
131 Instance()->mField = nullptr;
132 Instance()->mFieldFast = nullptr;
133 fldGlo = nullptr;
134 }
135 }
136 if (!fldGlo) {
138 TGeoGlobalMagField::Instance()->SetField(fldGlo);
139 TGeoGlobalMagField::Instance()->Lock();
140 if (verbose) {
141 LOG(info) << "Running with the B field constructed out of GRP";
142 LOG(info) << "Access field via TGeoGlobalMagField::Instance()->Field(xyz,bxyz) or via";
143 LOG(info) << "auto o2field = static_cast<o2::field::MagneticField*>( TGeoGlobalMagField::Instance()->GetField() )";
144 }
145 }
146 Instance()->updateField();
147 return 0;
148}
149
150#elif !defined(GPUCA_GPUCODE)
151template <typename value_T>
153{
154} // empty dummy constructor for standalone benchmark
155#endif
156
157//_______________________________________________________________________
158template <typename value_T>
159GPUd() bool PropagatorImpl<value_T>::PropagateToXBxByBz(TrackParCov_t& track, value_type xToGo, value_type maxSnp, value_type maxStep,
160 PropagatorImpl<value_T>::MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
161{
162 //----------------------------------------------------------------
163 //
164 // Propagates the track to the plane X=xk (cm)
165 // taking into account all the three components of the magnetic field
166 // and correcting for the crossed material.
167 //
168 // maxStep - maximal step for propagation
169 // tofInfo - optional container for track length and PID-dependent TOF integration
170 //
171 // matCorr - material correction type, it is up to the user to make sure the pointer is attached (if LUT is requested)
172 //----------------------------------------------------------------
173 auto dx = xToGo - track.getX();
174 int dir = dx > 0.f ? 1 : -1;
175 if (!signCorr) {
176 signCorr = -dir; // sign of eloss correction is not imposed
177 }
178
179 std::array<value_type, 3> b{};
180 while (math_utils::detail::abs<value_type>(dx) > Epsilon) {
181 auto step = math_utils::detail::min<value_type>(math_utils::detail::abs<value_type>(dx), maxStep);
182 if (dir < 0) {
183 step = -step;
184 }
185 auto x = track.getX() + step;
186 auto xyz0 = track.getXYZGlo();
187 getFieldXYZ(xyz0, &b[0]);
189 auto correct = [&track, &xyz0, tofInfo, matCorr, signCorr, this]() {
190 bool res = true;
191 if (matCorr != MatCorrType::USEMatCorrNONE) {
192 auto xyz1 = track.getXYZGlo();
193 auto mb = this->getMatBudget(matCorr, xyz0, xyz1);
194 if (!track.correctForMaterial(mb.meanX2X0, mb.getXRho(signCorr))) {
195 res = false;
196 }
197 if (tofInfo) {
198 tofInfo->addStep(mb.length, track.getQ2P2()); // fill L,ToF info using already calculated step length
199 tofInfo->addX2X0(mb.meanX2X0);
200 tofInfo->addXRho(mb.getXRho(signCorr));
201 }
202 } else if (tofInfo) { // if tofInfo filling was requested w/o material correction, we need to calculate the step lenght
203 auto xyz1 = track.getXYZGlo();
204 math_utils::Vector3D<value_type> stepV(xyz1.X() - xyz0.X(), xyz1.Y() - xyz0.Y(), xyz1.Z() - xyz0.Z());
205 tofInfo->addStep(stepV.R(), track.getQ2P2());
206 }
207 return res;
208 };
209
210 if (!track.propagateTo(x, b)) {
211 return false;
212 }
213 if (maxSnp > 0 && math_utils::detail::abs<value_type>(track.getSnp()) >= maxSnp) {
214 correct();
215 return false;
216 }
217 if (!correct()) {
218 return false;
219 }
220 dx = xToGo - track.getX();
221 }
222 track.setX(xToGo);
223 return true;
224}
225
226//_______________________________________________________________________
227template <typename value_T>
228GPUd() bool PropagatorImpl<value_T>::PropagateToXBxByBz(TrackParCov_t& track, TrackPar_t& linRef, value_type xToGo, value_type maxSnp, value_type maxStep,
229 PropagatorImpl<value_T>::MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
230{
231 //----------------------------------------------------------------
232 //
233 // Propagates the track to the plane X=xk (cm), using linRef as a Kalman linearisation point.
234 // taking into account all the three components of the magnetic field
235 // and correcting for the crossed material.
236 //
237 // maxStep - maximal step for propagation
238 // tofInfo - optional container for track length and PID-dependent TOF integration
239 //
240 // matCorr - material correction type, it is up to the user to make sure the pointer is attached (if LUT is requested)
241 //----------------------------------------------------------------
242 auto dx = xToGo - track.getX();
243 int dir = dx > 0.f ? 1 : -1;
244 if (!signCorr) {
245 signCorr = -dir; // sign of eloss correction is not imposed
246 }
247
248 std::array<value_type, 3> b{};
249 while (math_utils::detail::abs<value_type>(dx) > Epsilon) {
250 auto step = math_utils::detail::min<value_type>(math_utils::detail::abs<value_type>(dx), maxStep);
251 if (dir < 0) {
252 step = -step;
253 }
254 auto x = track.getX() + step;
255 auto xyz0 = linRef.getXYZGlo();
256 getFieldXYZ(xyz0, &b[0]);
257
258 auto correct = [&track, &linRef, &xyz0, tofInfo, matCorr, signCorr, this]() {
259 bool res = true;
260 if (matCorr != MatCorrType::USEMatCorrNONE) {
261 auto xyz1 = linRef.getXYZGlo();
262 auto mb = this->getMatBudget(matCorr, xyz0, xyz1);
263 if (!track.correctForMaterial(linRef, mb.meanX2X0, mb.getXRho(signCorr))) {
264 res = false;
265 }
266 if (tofInfo) {
267 tofInfo->addStep(mb.length, linRef.getQ2P2()); // fill L,ToF info using already calculated step length
268 tofInfo->addX2X0(mb.meanX2X0);
269 tofInfo->addXRho(mb.getXRho(signCorr));
270 }
271 } else if (tofInfo) { // if tofInfo filling was requested w/o material correction, we need to calculate the step lenght
272 auto xyz1 = linRef.getXYZGlo();
273 math_utils::Vector3D<value_type> stepV(xyz1.X() - xyz0.X(), xyz1.Y() - xyz0.Y(), xyz1.Z() - xyz0.Z());
274 tofInfo->addStep(stepV.R(), linRef.getQ2P2());
275 }
276 return res;
277 };
278
279 if (!track.propagateTo(x, linRef, b)) {
280 return false;
281 }
282 if (maxSnp > 0 && math_utils::detail::abs<value_type>(track.getSnp()) >= maxSnp) {
283 correct();
284 return false;
285 }
286 if (!correct()) {
287 return false;
288 }
289 dx = xToGo - track.getX();
290 }
291 track.setX(xToGo);
292 return true;
293}
294
295//_______________________________________________________________________
296template <typename value_T>
297GPUd() bool PropagatorImpl<value_T>::PropagateToXBxByBz(TrackPar_t& track, value_type xToGo, value_type maxSnp, value_type maxStep,
298 PropagatorImpl<value_T>::MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
299{
300 //----------------------------------------------------------------
301 //
302 // Propagates the track params to the plane X=xk (cm), NO error evaluation
303 // taking into account all the three components of the magnetic field
304 // and optionally correcting for the e.loss crossed material.
305 //
306 // maxStep - maximal step for propagation
307 // tofInfo - optional container for track length and PID-dependent TOF integration
308 //
309 // matCorr - material correction type, it is up to the user to make sure the pointer is attached (if LUT is requested)
310 //----------------------------------------------------------------
311 auto dx = xToGo - track.getX();
312 int dir = dx > 0.f ? 1 : -1;
313 if (!signCorr) {
314 signCorr = -dir; // sign of eloss correction is not imposed
315 }
316
317 std::array<value_type, 3> b{};
318 while (math_utils::detail::abs<value_type>(dx) > Epsilon) {
319 auto step = math_utils::detail::min<value_type>(math_utils::detail::abs<value_type>(dx), maxStep);
320 if (dir < 0) {
321 step = -step;
322 }
323 auto x = track.getX() + step;
324 auto xyz0 = track.getXYZGlo();
325 getFieldXYZ(xyz0, &b[0]);
326
327 auto correct = [&track, &xyz0, tofInfo, matCorr, signCorr, this]() {
328 bool res = true;
329 if (matCorr != MatCorrType::USEMatCorrNONE) {
330 auto xyz1 = track.getXYZGlo();
331 auto mb = this->getMatBudget(matCorr, xyz0, xyz1);
332 if (!track.correctForELoss(((signCorr < 0) ? -mb.length : mb.length) * mb.meanRho)) {
333 res = false;
334 }
335 if (tofInfo) {
336 tofInfo->addStep(mb.length, track.getQ2P2()); // fill L,ToF info using already calculated step length
337 tofInfo->addX2X0(mb.meanX2X0);
338 tofInfo->addXRho(mb.getXRho(signCorr));
339 }
340 } else if (tofInfo) { // if tofInfo filling was requested w/o material correction, we need to calculate the step lenght
341 auto xyz1 = track.getXYZGlo();
342 math_utils::Vector3D<value_type> stepV(xyz1.X() - xyz0.X(), xyz1.Y() - xyz0.Y(), xyz1.Z() - xyz0.Z());
343 tofInfo->addStep(stepV.R(), track.getQ2P2());
344 }
345 return res;
346 };
347
348 if (!track.propagateParamTo(x, b)) {
349 return false;
350 }
351 if (maxSnp > 0 && math_utils::detail::abs<value_type>(track.getSnp()) >= maxSnp) {
352 correct();
353 return false;
354 }
355 if (!correct()) {
356 return false;
357 }
358 dx = xToGo - track.getX();
359 }
360 track.setX(xToGo);
361 return true;
362}
363
364//_______________________________________________________________________
365template <typename value_T>
366GPUd() bool PropagatorImpl<value_T>::propagateToX(TrackParCov_t& track, value_type xToGo, value_type bZ, value_type maxSnp, value_type maxStep,
367 PropagatorImpl<value_T>::MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
368{
369 //----------------------------------------------------------------
370 //
371 // Propagates the track to the plane X=xk (cm)
372 // Use bz only and correct for the crossed material.
373 //
374 // maxStep - maximal step for propagation
375 // tofInfo - optional container for track length and PID-dependent TOF integration
376 //
377 // matCorr - material correction type, it is up to the user to make sure the pointer is attached (if LUT is requested)
378 //----------------------------------------------------------------
379 auto dx = xToGo - track.getX();
380 int dir = dx > 0.f ? 1 : -1;
381 if (!signCorr) {
382 signCorr = -dir; // sign of eloss correction is not imposed
383 }
384
385 while (math_utils::detail::abs<value_type>(dx) > Epsilon) {
386 auto step = math_utils::detail::min<value_type>(math_utils::detail::abs<value_type>(dx), maxStep);
387 if (dir < 0) {
388 step = -step;
389 }
390 auto x = track.getX() + step;
391 auto xyz0 = track.getXYZGlo();
392 auto correct = [&track, &xyz0, tofInfo, matCorr, signCorr, this]() {
393 bool res = true;
394 if (matCorr != MatCorrType::USEMatCorrNONE) {
395 auto xyz1 = track.getXYZGlo();
396 auto mb = this->getMatBudget(matCorr, xyz0, xyz1);
397 if (!track.correctForMaterial(mb.meanX2X0, mb.getXRho(signCorr))) {
398 res = false;
399 }
400 if (tofInfo) {
401 tofInfo->addStep(mb.length, track.getQ2P2()); // fill L,ToF info using already calculated step length
402 tofInfo->addX2X0(mb.meanX2X0);
403 tofInfo->addXRho(mb.getXRho(signCorr));
404 }
405 } else if (tofInfo) { // if tofInfo filling was requested w/o material correction, we need to calculate the step lenght
406 auto xyz1 = track.getXYZGlo();
407 math_utils::Vector3D<value_type> stepV(xyz1.X() - xyz0.X(), xyz1.Y() - xyz0.Y(), xyz1.Z() - xyz0.Z());
408 tofInfo->addStep(stepV.R(), track.getQ2P2());
409 }
410 return res;
411 };
412 if (!track.propagateTo(x, bZ)) {
413 return false;
414 }
415 if (maxSnp > 0 && math_utils::detail::abs<value_type>(track.getSnp()) >= maxSnp) {
416 correct();
417 return false;
418 }
419 if (!correct()) {
420 return false;
421 }
422 dx = xToGo - track.getX();
423 }
424 track.setX(xToGo);
425 return true;
426}
427
428//_______________________________________________________________________
429template <typename value_T>
430GPUd() bool PropagatorImpl<value_T>::propagateToX(TrackParCov_t& track, TrackPar_t& linRef, value_type xToGo, value_type bZ, value_type maxSnp, value_type maxStep,
431 PropagatorImpl<value_T>::MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
432{
433 //----------------------------------------------------------------
434 //
435 // Propagates the track to the plane X=xk (cm), using linRef as a Kalman linearisation point.
436 // Use bz only and correct for the crossed material if requested.
437 //
438 // maxStep - maximal step for propagation
439 // tofInfo - optional container for track length and PID-dependent TOF integration
440 //
441 // matCorr - material correction type, it is up to the user to make sure the pointer is attached (if LUT is requested)
442 //----------------------------------------------------------------
443 auto dx = xToGo - track.getX();
444 int dir = dx > 0.f ? 1 : -1;
445 if (!signCorr) {
446 signCorr = -dir; // sign of eloss correction is not imposed
447 }
448
449 while (math_utils::detail::abs<value_type>(dx) > Epsilon) {
450 auto step = math_utils::detail::min<value_type>(math_utils::detail::abs<value_type>(dx), maxStep);
451 if (dir < 0) {
452 step = -step;
453 }
454 auto x = track.getX() + step;
455 auto xyz0 = linRef.getXYZGlo();
456
457 auto correct = [&track, &linRef, &xyz0, tofInfo, matCorr, signCorr, this]() {
458 bool res = true;
459 if (matCorr != MatCorrType::USEMatCorrNONE) {
460 auto xyz1 = linRef.getXYZGlo();
461 auto mb = this->getMatBudget(matCorr, xyz0, xyz1);
462 if (!track.correctForMaterial(linRef, mb.meanX2X0, mb.getXRho(signCorr))) {
463 res = false;
464 }
465 if (tofInfo) {
466 tofInfo->addStep(mb.length, linRef.getQ2P2()); // fill L,ToF info using already calculated step length
467 tofInfo->addX2X0(mb.meanX2X0);
468 tofInfo->addXRho(mb.getXRho(signCorr));
469 }
470 } else if (tofInfo) { // if tofInfo filling was requested w/o material correction, we need to calculate the step lenght
471 auto xyz1 = linRef.getXYZGlo();
472 math_utils::Vector3D<value_type> stepV(xyz1.X() - xyz0.X(), xyz1.Y() - xyz0.Y(), xyz1.Z() - xyz0.Z());
473 tofInfo->addStep(stepV.R(), linRef.getQ2P2());
474 }
475 return res;
476 };
477
478 if (!track.propagateTo(x, linRef, bZ)) { // linRef also updated
479 return false;
480 }
481 if (maxSnp > 0 && math_utils::detail::abs<value_type>(track.getSnp()) >= maxSnp) {
482 correct();
483 return false;
484 }
485 if (!correct()) {
486 return false;
487 }
488 dx = xToGo - track.getX();
489 }
490 track.setX(xToGo);
491 return true;
492}
493
494//_______________________________________________________________________
495template <typename value_T>
496GPUd() bool PropagatorImpl<value_T>::propagateToX(TrackPar_t& track, value_type xToGo, value_type bZ, value_type maxSnp, value_type maxStep,
497 PropagatorImpl<value_T>::MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
498{
499 //----------------------------------------------------------------
500 //
501 // Propagates the track parameters only to the plane X=xk (cm)
502 // taking into account all the three components of the magnetic field
503 // and correcting for the crossed material.
504 //
505 // maxStep - maximal step for propagation
506 // tofInfo - optional container for track length and PID-dependent TOF integration
507 //
508 // matCorr - material correction type, it is up to the user to make sure the pointer is attached (if LUT is requested)
509 //----------------------------------------------------------------
510 auto dx = xToGo - track.getX();
511 int dir = dx > 0.f ? 1 : -1;
512 if (!signCorr) {
513 signCorr = -dir; // sign of eloss correction is not imposed
514 }
515
516 while (math_utils::detail::abs<value_type>(dx) > Epsilon) {
517 auto step = math_utils::detail::min<value_type>(math_utils::detail::abs<value_type>(dx), maxStep);
518 if (dir < 0) {
519 step = -step;
520 }
521 auto x = track.getX() + step;
522 auto xyz0 = track.getXYZGlo();
523
524 auto correct = [&track, &xyz0, tofInfo, matCorr, signCorr, this]() {
525 bool res = true;
526 if (matCorr != MatCorrType::USEMatCorrNONE) {
527 auto xyz1 = track.getXYZGlo();
528 auto mb = this->getMatBudget(matCorr, xyz0, xyz1);
529 if (!track.correctForELoss(mb.getXRho(signCorr))) {
530 res = false;
531 }
532 if (tofInfo) {
533 tofInfo->addStep(mb.length, track.getQ2P2()); // fill L,ToF info using already calculated step length
534 tofInfo->addX2X0(mb.meanX2X0);
535 tofInfo->addXRho(mb.getXRho(signCorr));
536 }
537 } else if (tofInfo) { // if tofInfo filling was requested w/o material correction, we need to calculate the step lenght
538 auto xyz1 = track.getXYZGlo();
539 math_utils::Vector3D<value_type> stepV(xyz1.X() - xyz0.X(), xyz1.Y() - xyz0.Y(), xyz1.Z() - xyz0.Z());
540 tofInfo->addStep(stepV.R(), track.getQ2P2());
541 }
542 return res;
543 };
544
545 if (!track.propagateParamTo(x, bZ)) {
546 return false;
547 }
548 if (maxSnp > 0 && math_utils::detail::abs<value_type>(track.getSnp()) >= maxSnp) {
549 correct();
550 return false;
551 }
552 if (!correct()) {
553 return false;
554 }
555 dx = xToGo - track.getX();
556 }
557 track.setX(xToGo);
558 return true;
559}
560
561//_______________________________________________________________________
562template <typename value_T>
563template <typename track_T>
564GPUd() bool PropagatorImpl<value_T>::propagateToR(track_T& track, value_type r, bool bzOnly, value_type maxSnp, value_type maxStep,
565 MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
566{
567 const value_T MaxPhiLoc = math_utils::detail::asin<value_T>(maxSnp), MaxPhiLocSafe = 0.95 * MaxPhiLoc;
568 auto bz = getNominalBz();
569 if (math_utils::detail::abs(bz) > constants::math::Almost0) {
570 o2::track::TrackAuxPar traux(track, bz);
572 value_type r0 = math_utils::detail::sqrt<value_T>(track.getX() * track.getX() + track.getY() * track.getY());
573 value_type dr = (r - r0);
574 value_type rTmp = r - (math_utils::detail::abs<value_T>(dr) > 1. ? (dr > 0 ? 0.5 : -0.5) : 0.5 * dr); // 1st propagate a few mm short of the targer R
575 crad.rC = rTmp;
576 crad.c = crad.cc = 1.f;
577 crad.s = crad.ss = crad.cs = 0.f;
579 cross.circlesCrossInfo(crad, traux, 0.);
580 if (cross.nDCA < 1) {
581 return false;
582 }
583 double phiCross[2] = {}, dphi[2] = {};
584 auto curv = track.getCurvature(bz);
585 bool clockwise = curv < 0; // q+ in B+ or q- in B- goes clockwise
586 auto phiLoc = math_utils::detail::asin<double>(track.getSnp());
587 auto phi0 = phiLoc + track.getAlpha();
589 for (int i = 0; i < cross.nDCA; i++) {
590 // track pT direction angle at crossing points:
591 // == angle of the tangential to track circle at the crossing point X,Y
592 // == normal to the radial vector from the track circle center {X-cX, Y-cY}
593 // i.e. the angle of the vector {Y-cY, -(X-cx)}
594 auto normX = double(cross.yDCA[i]) - double(traux.yC), normY = -(double(cross.xDCA[i]) - double(traux.xC));
595 if (!clockwise) {
596 normX = -normX;
597 normY = -normY;
598 }
599 phiCross[i] = math_utils::detail::atan2<double>(normY, normX);
601 dphi[i] = phiCross[i] - phi0;
602 if (dphi[i] > o2::constants::math::PI) {
603 dphi[i] -= o2::constants::math::TwoPI;
604 } else if (dphi[i] < -o2::constants::math::PI) {
605 dphi[i] += o2::constants::math::TwoPI;
606 }
607 }
608 int sel = cross.nDCA == 1 ? 0 : (clockwise ? (dphi[0] < dphi[1] ? 0 : 1) : (dphi[1] < dphi[0] ? 0 : 1));
609 auto deltaPhi = dphi[sel];
610
611 while (1) {
612 auto phiLocFin = phiLoc + deltaPhi;
613 // case1
614 if (math_utils::detail::abs<value_type>(phiLocFin) < MaxPhiLocSafe) { // just 1 step propagation
615 auto deltaX = (math_utils::detail::sin<double>(phiLocFin) - track.getSnp()) / track.getCurvature(bz);
616 if (!propagateTo(track, track.getX() + deltaX, bzOnly, maxSnp, maxStep, matCorr, tofInfo, signCorr)) {
617 return false;
618 }
619 break;
620 }
621 if (math_utils::detail::abs<value_type>(deltaPhi) < (2 * MaxPhiLocSafe)) { // still can go in 1 step with one extra rotation
622 auto rot = phiLoc + 0.5 * deltaPhi;
623 if (!track.rotate(track.getAlpha() + rot)) {
624 return false;
625 }
626 phiLoc -= rot;
627 continue; // should be ok for the case 1 now.
628 }
629
630 auto rot = phiLoc + (deltaPhi > 0 ? MaxPhiLocSafe : -MaxPhiLocSafe);
631 if (!track.rotate(track.getAlpha() + rot)) {
632 return false;
633 }
634 phiLoc -= rot; // = +- MaxPhiLocSafe
635
636 // propagate to phiLoc = +-MaxPhiLocSafe
637 auto tgtPhiLoc = deltaPhi > 0 ? MaxPhiLocSafe : -MaxPhiLocSafe;
638 auto deltaX = (math_utils::detail::sin<double>(tgtPhiLoc) - track.getSnp()) / track.getCurvature(bz);
639 if (!propagateTo(track, track.getX() + deltaX, bzOnly, maxSnp, maxStep, matCorr, tofInfo, signCorr)) {
640 return false;
641 }
642 deltaPhi -= tgtPhiLoc - phiLoc;
643 phiLoc = deltaPhi > 0 ? MaxPhiLocSafe : -MaxPhiLocSafe;
644 continue; // should be of for the case 1 now.
645 }
646 bz = getBz(math_utils::Point3D<value_type>{value_type(cross.xDCA[sel]), value_type(cross.yDCA[sel]), value_type(track.getZ())});
647 }
648 // do final step till target R, also covers Bz = 0;
649 value_type xfin;
650 if (!track.getXatLabR(r, xfin, bz)) {
651 return false;
652 }
653 return propagateToX(track, xfin, bzOnly, maxSnp, maxStep, matCorr, tofInfo, signCorr);
654}
655
656template <typename value_T>
657GPUd() bool PropagatorImpl<value_T>::propagateToAlphaX(TrackParCov_t& track, TrackPar_t* linRef, value_type alpha, value_type x, bool bzOnly, value_type maxSnp, value_type maxStep, int minSteps,
658 MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
659{
660 // propagate to alpha,X, if needed in a few steps
661 auto snp = track.getSnpAt(alpha, x, getNominalBz());
662 // apply safety factor 0.9 for crude rotation estimate
663 if (math_utils::detail::abs<value_type>(snp) < maxSnp * 0.9 && (linRef ? track.rotate(alpha, *linRef, getNominalBz()) : track.rotate(alpha))) {
664 auto dx = math_utils::detail::abs<value_type>(x - track.getX());
665 if (dx < Epsilon) {
666 return true;
667 }
668 return propagateTo(track, linRef, x, bzOnly, maxSnp, math_utils::detail::min<value_type>(dx / minSteps, maxStep), matCorr, tofInfo, signCorr);
669 }
670 return false;
671}
672
673//_______________________________________________________________________
674template <typename value_T>
675template <typename track_T>
676GPUd() bool PropagatorImpl<value_T>::propagateToAlphaX(track_T& track, value_type alpha, value_type x, bool bzOnly, value_type maxSnp, value_type maxStep, int minSteps,
677 MatCorrType matCorr, track::TrackLTIntegral* tofInfo, int signCorr) const
678{
679 // propagate to alpha,X, if needed in a few steps
680 auto snp = track.getSnpAt(alpha, x, getNominalBz());
681 // apply safety factor 0.9 for crude rotation estimate
682 if (math_utils::detail::abs<value_type>(snp) < maxSnp * 0.9 && track.rotate(alpha)) {
683 auto dx = math_utils::detail::abs<value_type>(x - track.getX());
684 if (dx < Epsilon) {
685 return true;
686 }
687 return propagateTo(track, x, bzOnly, maxSnp, math_utils::detail::min<value_type>(dx / minSteps, maxStep), matCorr, tofInfo, signCorr);
688 }
689 return false;
690 /*
691 // try to go in a few steps with intermediate rotations
692
693
694 auto alphaTrg = alpha;
695 math_utils::detail::bringToPMPi<value_type>(alphaTrg);
696 auto alpCurr = track.getAlpha();
697 math_utils::detail::bringToPMPi<value_type>(alpCurr);
698 int nsteps = minSteps > 2 ? minSteps : 2;
699 auto dalp = math_utils::detail::deltaPhiSmall<value_type>(alpCurr, alphaTrg) / nsteps; // effective (alpha - alphaCurr)/nsteps
700 auto xtmp = (track.getX() + x) / nsteps;
701 return track.rotate(alpCurr + dalp) && propagateTo(track, xtmp, bzOnly, maxSnp, maxStep, matCorr, tofInfo, signCorr) &&
702 track.rotate(alpha) && propagateTo(track, x, bzOnly, maxSnp, maxStep, matCorr, tofInfo, signCorr);
703 */
704}
705
706//_______________________________________________________________________
707template <typename value_T>
708GPUd() bool PropagatorImpl<value_T>::propagateToDCA(const o2::dataformats::VertexBase& vtx, TrackParCov_t& track, value_type bZ,
709 value_type maxStep, PropagatorImpl<value_type>::MatCorrType matCorr,
710 o2::dataformats::DCA* dca, track::TrackLTIntegral* tofInfo,
711 int signCorr, value_type maxD) const
712{
713 // propagate track to DCA to the vertex
714 value_type sn, cs, alp = track.getAlpha();
715 math_utils::detail::sincos<value_type>(alp, sn, cs);
716 value_type x = track.getX(), y = track.getY(), snp = track.getSnp(), csp = math_utils::detail::sqrt<value_type>((1.f - snp) * (1.f + snp));
717 value_type xv = vtx.getX() * cs + vtx.getY() * sn, yv = -vtx.getX() * sn + vtx.getY() * cs, zv = vtx.getZ();
718 x -= xv;
719 y -= yv;
720 // Estimate the impact parameter neglecting the track curvature
721 value_type d = math_utils::detail::abs<value_type>(x * snp - y * csp);
722 if (d > maxD) {
723 if (dca) { // provide default DCA for failed propag
724 dca->set(o2::track::DefaultDCA, o2::track::DefaultDCA,
725 o2::track::DefaultDCACov, o2::track::DefaultDCACov, o2::track::DefaultDCACov);
726 }
727 return false;
728 }
729 value_type crv = track.getCurvature(bZ);
730 value_type tgfv = -(crv * x - snp) / (crv * y + csp);
731 sn = tgfv / math_utils::detail::sqrt<value_type>(1.f + tgfv * tgfv);
732 cs = math_utils::detail::sqrt<value_type>((1. - sn) * (1. + sn));
733 cs = (math_utils::detail::abs<value_type>(tgfv) > o2::constants::math::Almost0) ? sn / tgfv : o2::constants::math::Almost1;
734
735 x = xv * cs + yv * sn;
736 yv = -xv * sn + yv * cs;
737 xv = x;
738
739 auto tmpT(track); // operate on the copy to recover after the failure
740 alp += math_utils::detail::asin<value_type>(sn);
741 if (!tmpT.rotate(alp) || !propagateToX(tmpT, xv, bZ, 0.85, maxStep, matCorr, tofInfo, signCorr)) {
742#ifndef GPUCA_ALIGPUCODE
743 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << vtx << " | Track is: " << tmpT.asString();
744#elif !defined(GPUCA_NO_FMT)
745 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << vtx;
746#endif
747 if (dca) { // provide default DCA for failed propag
748 dca->set(o2::track::DefaultDCA, o2::track::DefaultDCA,
749 o2::track::DefaultDCACov, o2::track::DefaultDCACov, o2::track::DefaultDCACov);
750 }
751 return false;
752 }
753 track = tmpT;
754 if (dca) {
755 math_utils::detail::sincos<value_type>(alp, sn, cs);
756 auto s2ylocvtx = vtx.getSigmaX2() * sn * sn + vtx.getSigmaY2() * cs * cs - 2. * vtx.getSigmaXY() * cs * sn;
757 dca->set(track.getY() - yv, track.getZ() - zv,
758 track.getSigmaY2() + s2ylocvtx, track.getSigmaZY(), track.getSigmaZ2() + vtx.getSigmaZ2());
759 }
760 return true;
761}
762
763//_______________________________________________________________________
764template <typename value_T>
765GPUd() bool PropagatorImpl<value_T>::propagateToDCABxByBz(const o2::dataformats::VertexBase& vtx, TrackParCov_t& track,
766 value_type maxStep, PropagatorImpl<value_type>::MatCorrType matCorr,
767 o2::dataformats::DCA* dca, track::TrackLTIntegral* tofInfo,
768 int signCorr, value_type maxD) const
769{
770 // propagate track to DCA to the vertex
771 value_type sn, cs, alp = track.getAlpha();
772 math_utils::detail::sincos<value_type>(alp, sn, cs);
773 value_type x = track.getX(), y = track.getY(), snp = track.getSnp(), csp = math_utils::detail::sqrt<value_type>((1.f - snp) * (1.f + snp));
774 value_type xv = vtx.getX() * cs + vtx.getY() * sn, yv = -vtx.getX() * sn + vtx.getY() * cs, zv = vtx.getZ();
775 x -= xv;
776 y -= yv;
777 // Estimate the impact parameter neglecting the track curvature
778 value_type d = math_utils::detail::abs<value_type>(x * snp - y * csp);
779 if (d > maxD) {
780 if (dca) { // provide default DCA for failed propag
781 dca->set(o2::track::DefaultDCA, o2::track::DefaultDCA,
782 o2::track::DefaultDCACov, o2::track::DefaultDCACov, o2::track::DefaultDCACov);
783 }
784 return false;
785 }
786 value_type crv = track.getCurvature(mNominalBz);
787 value_type tgfv = -(crv * x - snp) / (crv * y + csp);
788 sn = tgfv / math_utils::detail::sqrt<value_type>(1.f + tgfv * tgfv);
789 cs = math_utils::detail::sqrt<value_type>((1. - sn) * (1. + sn));
790 cs = (math_utils::detail::abs<value_type>(tgfv) > o2::constants::math::Almost0) ? sn / tgfv : o2::constants::math::Almost1;
791
792 x = xv * cs + yv * sn;
793 yv = -xv * sn + yv * cs;
794 xv = x;
795
796 auto tmpT(track); // operate on the copy to recover after the failure
797 alp += math_utils::detail::asin<value_type>(sn);
798 if (!tmpT.rotate(alp) || !PropagateToXBxByBz(tmpT, xv, 0.85, maxStep, matCorr, tofInfo, signCorr)) {
799#ifndef GPUCA_ALIGPUCODE
800 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << vtx << " | Track is: " << tmpT.asString();
801#elif !defined(GPUCA_NO_FMT)
802 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << vtx;
803#endif
804 if (dca) { // provide default DCA for failed propag
805 dca->set(o2::track::DefaultDCA, o2::track::DefaultDCA,
806 o2::track::DefaultDCACov, o2::track::DefaultDCACov, o2::track::DefaultDCACov);
807 }
808 return false;
809 }
810 track = tmpT;
811 if (dca) {
812 math_utils::detail::sincos<value_type>(alp, sn, cs);
813 auto s2ylocvtx = vtx.getSigmaX2() * sn * sn + vtx.getSigmaY2() * cs * cs - 2. * vtx.getSigmaXY() * cs * sn;
814 dca->set(track.getY() - yv, track.getZ() - zv,
815 track.getSigmaY2() + s2ylocvtx, track.getSigmaZY(), track.getSigmaZ2() + vtx.getSigmaZ2());
816 }
817 return true;
818}
819
820//_______________________________________________________________________
821template <typename value_T>
822GPUd() bool PropagatorImpl<value_T>::propagateToDCA(const math_utils::Point3D<value_type>& vtx, TrackPar_t& track, value_type bZ,
823 value_type maxStep, PropagatorImpl<value_T>::MatCorrType matCorr,
824 std::array<value_type, 2>* dca, track::TrackLTIntegral* tofInfo,
825 int signCorr, value_type maxD) const
826{
827 // propagate track to DCA to the vertex
828 value_type sn, cs, alp = track.getAlpha();
829 math_utils::detail::sincos<value_type>(alp, sn, cs);
830 value_type x = track.getX(), y = track.getY(), snp = track.getSnp(), csp = math_utils::detail::sqrt<value_type>((1.f - snp) * (1.f + snp));
831 value_type xv = vtx.X() * cs + vtx.Y() * sn, yv = -vtx.X() * sn + vtx.Y() * cs, zv = vtx.Z();
832 x -= xv;
833 y -= yv;
834 // Estimate the impact parameter neglecting the track curvature
835 value_type d = math_utils::detail::abs<value_type>(x * snp - y * csp);
836 if (d > maxD) {
837 if (dca) { // provide default DCA for failed propag
838 (*dca)[0] = o2::track::DefaultDCA;
839 (*dca)[1] = o2::track::DefaultDCA;
840 }
841 return false;
842 }
843 value_type crv = track.getCurvature(bZ);
844 value_type tgfv = -(crv * x - snp) / (crv * y + csp);
845 sn = tgfv / math_utils::detail::sqrt<value_type>(1.f + tgfv * tgfv);
846 cs = math_utils::detail::sqrt<value_type>((1. - sn) * (1. + sn));
847 cs = (math_utils::detail::abs<value_type>(tgfv) > o2::constants::math::Almost0) ? sn / tgfv : o2::constants::math::Almost1;
848
849 x = xv * cs + yv * sn;
850 yv = -xv * sn + yv * cs;
851 xv = x;
852
853 auto tmpT(track); // operate on the copy to recover after the failure
854 alp += math_utils::detail::asin<value_type>(sn);
855 if (!tmpT.rotateParam(alp) || !propagateToX(tmpT, xv, bZ, 0.85, maxStep, matCorr, tofInfo, signCorr)) {
856#ifndef GPUCA_ALIGPUCODE
857 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << " for vertex "
858 << vtx.X() << ' ' << vtx.Y() << ' ' << vtx.Z() << " | Track is: " << tmpT.asString();
859#else
860 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << " for vertex " << vtx.X() << ' ' << vtx.Y() << ' ' << vtx.Z();
861#endif
862 if (dca) { // provide default DCA for failed propag
863 (*dca)[0] = o2::track::DefaultDCA;
864 (*dca)[1] = o2::track::DefaultDCA;
865 }
866 return false;
867 }
868 track = tmpT;
869 if (dca) {
870 (*dca)[0] = track.getY() - yv;
871 (*dca)[1] = track.getZ() - zv;
872 }
873 return true;
874}
875
876//_______________________________________________________________________
877template <typename value_T>
878GPUd() bool PropagatorImpl<value_T>::propagateToDCABxByBz(const math_utils::Point3D<value_type>& vtx, TrackPar_t& track,
879 value_type maxStep, PropagatorImpl<value_T>::MatCorrType matCorr,
880 std::array<value_type, 2>* dca, track::TrackLTIntegral* tofInfo,
881 int signCorr, value_type maxD) const
882{
883 // propagate track to DCA to the vertex
884 value_type sn, cs, alp = track.getAlpha();
885 math_utils::detail::sincos<value_type>(alp, sn, cs);
886 value_type x = track.getX(), y = track.getY(), snp = track.getSnp(), csp = math_utils::detail::sqrt<value_type>((1.f - snp) * (1.f + snp));
887 value_type xv = vtx.X() * cs + vtx.Y() * sn, yv = -vtx.X() * sn + vtx.Y() * cs, zv = vtx.Z();
888 x -= xv;
889 y -= yv;
890 // Estimate the impact parameter neglecting the track curvature
891 value_type d = math_utils::detail::abs<value_type>(x * snp - y * csp);
892 if (d > maxD) {
893 if (dca) { // provide default DCA for failed propag
894 (*dca)[0] = o2::track::DefaultDCA;
895 (*dca)[1] = o2::track::DefaultDCA;
896 }
897 return false;
898 }
899 value_type crv = track.getCurvature(mNominalBz);
900 value_type tgfv = -(crv * x - snp) / (crv * y + csp);
901 sn = tgfv / math_utils::detail::sqrt<value_type>(1.f + tgfv * tgfv);
902 cs = math_utils::detail::sqrt<value_type>((1. - sn) * (1. + sn));
903 cs = (math_utils::detail::abs<value_type>(tgfv) > o2::constants::math::Almost0) ? sn / tgfv : o2::constants::math::Almost1;
904
905 x = xv * cs + yv * sn;
906 yv = -xv * sn + yv * cs;
907 xv = x;
908
909 auto tmpT(track); // operate on the copy to recover after the failure
910 alp += math_utils::detail::asin<value_type>(sn);
911 if (!tmpT.rotateParam(alp) || !PropagateToXBxByBz(tmpT, xv, 0.85, maxStep, matCorr, tofInfo, signCorr)) {
912#ifndef GPUCA_ALIGPUCODE
913 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << " for vertex "
914 << vtx.X() << ' ' << vtx.Y() << ' ' << vtx.Z() << " | Track is: " << tmpT.asString();
915#else
916 LOG(debug) << "failed to propagate to alpha=" << alp << " X=" << xv << " for vertex " << vtx.X() << ' ' << vtx.Y() << ' ' << vtx.Z();
917#endif
918 if (dca) { // provide default DCA for failed propag
919 (*dca)[0] = o2::track::DefaultDCA;
920 (*dca)[1] = o2::track::DefaultDCA;
921 }
922 return false;
923 }
924 track = tmpT;
925 if (dca) {
926 (*dca)[0] = track.getY() - yv;
927 (*dca)[1] = track.getZ() - zv;
928 }
929 return true;
930}
931
932//____________________________________________________________
933template <typename value_T>
934GPUd() float PropagatorImpl<value_T>::estimateLTIncrement(const o2::track::TrackParametrization<value_type>& trc,
935 const o2::math_utils::Point3D<value_type>& posStart,
936 const o2::math_utils::Point3D<value_type>& posEnd) const
937{
938 // estimate helical step increment between 2 point
939 float dX = posEnd.X() - posStart.X(), dY = posEnd.Y() - posStart.Y(), dZ = posEnd.Z() - posStart.Z(), d2XY = dX * dX + dY * dY;
940 if (getNominalBz() != 0) { // circular arc = 2*R*asin(dXY/2R)
941 float b[3];
942 o2::math_utils::Point3D<float> posAv(0.5 * (posEnd.X() + posStart.X()), 0.5 * (posEnd.Y() + posStart.Y()), 0.5 * (posEnd.Z() + posStart.Z()));
943 getFieldXYZ(posAv, b);
944 float curvH = math_utils::detail::abs<value_type>(0.5f * trc.getCurvature(b[2])), asArg = curvH * math_utils::detail::sqrt<value_type>(d2XY);
945 if (curvH > 0.f) {
946 d2XY = asArg < 1.f ? math_utils::detail::asin<value_type>(asArg) / curvH : o2::constants::math::PIHalf / curvH;
947 d2XY *= d2XY;
948 }
949 }
950 return math_utils::detail::sqrt<value_type>(d2XY + dZ * dZ);
951}
952
953//____________________________________________________________
954template <typename value_T>
955GPUd() value_T PropagatorImpl<value_T>::estimateLTFast(o2::track::TrackLTIntegral& lt, const o2::track::TrackParametrization<value_type>& trc) const
956{
957 value_T xdca = 0., ydca = 0., length = 0.; // , zdca = 0. // zdca might be used in future
959 constexpr float TinyF = 1e-9;
960 auto straigh_line_approx = [&]() {
961 auto csp2 = (1.f - trc.getSnp()) * (1.f + trc.getSnp());
962 if (csp2 > TinyF) {
963 auto csp = math_utils::detail::sqrt<value_type>(csp2);
964 auto tgp = trc.getSnp() / csp, f = trc.getX() * tgp - trc.getY();
965 xdca = tgp * f * csp2;
966 ydca = -f * csp2;
967 auto dx = xdca - trc.getX(), dy = ydca - trc.getY(), dz = dx * trc.getTgl() / csp;
968 return math_utils::detail::sqrt<value_type>(dx * dx + dy * dy + dz * dz);
969 } else { // track is parallel to Y axis
970 xdca = trc.getX(); // ydca = 0
971 return math_utils::detail::abs<value_type>(trc.getY() * math_utils::detail::sqrt<value_type>(1. + trc.getTgl() * trc.getTgl())); // distance from the current point to DCA
972 }
973 };
974 trc.getCircleParamsLoc(mNominalBz, c);
975 if (c.rC != 0.) { // helix
976 auto distC = math_utils::detail::sqrt<value_type>(c.getCenterD2()); // distance from the circle center to origin
977 if (distC > 1.e-3) {
978 auto nrm = (distC - c.rC) / distC;
979 xdca = nrm * c.xC; // coordinates of the DCA to 0,0 in the local frame
980 ydca = nrm * c.yC;
981 auto v0x = trc.getX() - c.xC, v0y = trc.getY() - c.yC, v1x = xdca - c.xC, v1y = ydca - c.yC;
982 auto angcos = (v0x * v1x + v0y * v1y) / (c.rC * c.rC);
983 if (math_utils::detail::abs<value_type>(angcos) < 1.f) {
984 auto ang = math_utils::detail::acos<value_type>(angcos);
985 if ((trc.getSign() > 0.f) == (mNominalBz > 0.f)) {
986 ang = -ang; // we need signeg angle
987 c.rC = -c.rC; // we need signed curvature for zdca
988 }
989 // zdca = trc.getZ() + (trc.getSign() > 0. ? c.rC : -c.rC) * trc.getTgl() * ang;
990 length = math_utils::detail::abs<value_type>(c.rC * ang * math_utils::detail::sqrt<value_type>(1. + trc.getTgl() * trc.getTgl()));
991 } else { // calculation of the arc length between the position and DCA makes no sense
992 length = straigh_line_approx();
993 }
994 } else { // track with circle center at the origin, and LT makes no sense, take direct distance
995 xdca = trc.getX();
996 ydca = trc.getY();
997 }
998 } else { // straight line
999 length = straigh_line_approx();
1000 }
1001 // since we assume the track or its parent comes from the beam-line or decay, add XY(?) distance to it
1002 value_T dcaT = math_utils::detail::sqrt<value_type>(xdca * xdca + ydca * ydca);
1003 length += dcaT;
1004 lt.addStep(length, trc.getQ2P2());
1005 return dcaT;
1006}
1007
1008//____________________________________________________________
1009template <typename value_T>
1010GPUd() MatBudget PropagatorImpl<value_T>::getMatBudget(PropagatorImpl<value_type>::MatCorrType corrType, const math_utils::Point3D<value_type>& p0, const math_utils::Point3D<value_type>& p1) const
1011{
1012#if !defined(GPUCA_STANDALONE) && !defined(GPUCA_GPUCODE)
1013 if (corrType == MatCorrType::USEMatCorrTGeo) {
1015 }
1016 if (!mMatLUT) {
1017 if (mTGeoFallBackAllowed) {
1019 } else {
1020 throw std::runtime_error("requested MatLUT is absent and fall-back to TGeo is disabled");
1021 }
1022 }
1023#endif
1024 return mMatLUT->getMatBudget(p0.X(), p0.Y(), p0.Z(), p1.X(), p1.Y(), p1.Z());
1025}
1026
1027template <typename value_T>
1028template <typename T>
1029GPUd() void PropagatorImpl<value_T>::getFieldXYZImpl(const math_utils::Point3D<T> xyz, T* bxyz) const
1030{
1031 if (mGPUField) {
1032#if defined(GPUCA_GPUCODE_DEVICE) && defined(GPUCA_HAS_GLOBAL_SYMBOL_CONSTANT_MEM)
1033 const auto* f = &GPUCA_CONSMEM.param.polynomialField; // Access directly from constant memory on GPU (copied here to avoid complicated header dependencies)
1034#else
1035 const auto* f = mGPUField;
1036#endif
1037 float bxyzF[3] = {};
1038 f->GetField(xyz.X(), xyz.Y(), xyz.Z(), bxyzF);
1039 // copy and convert
1040 constexpr value_type kCLight1 = 1. / o2::gpu::gpu_common_constants::kCLight;
1041 for (uint i = 0; i < 3; ++i) {
1042 bxyz[i] = static_cast<value_type>(bxyzF[i]) * kCLight1;
1043 }
1044 } else {
1045#ifndef GPUCA_GPUCODE
1046 if (mFieldFast) {
1047 mFieldFast->Field(xyz, bxyz); // Must not call the host-only function in GPU compilation
1048 } else {
1049#ifdef GPUCA_STANDALONE
1050 LOG(fatal) << "Normal field cannot be used in standalone benchmark";
1051#else
1052 mField->field(xyz, bxyz);
1053#endif
1054 }
1055#endif
1056 }
1057}
1058
1059template <typename value_T>
1060template <typename T>
1061GPUd() T PropagatorImpl<value_T>::getBzImpl(const math_utils::Point3D<T> xyz) const
1062{
1063 T bz = 0;
1064 if (mGPUField) {
1065#if defined(GPUCA_GPUCODE_DEVICE) && defined(GPUCA_HAS_GLOBAL_SYMBOL_CONSTANT_MEM)
1066 const auto* f = &GPUCA_CONSMEM.param.polynomialField; // Access directly from constant memory on GPU (copied here to avoid complicated header dependencies)
1067#else
1068 const auto* f = mGPUField;
1069#endif
1070 constexpr value_type kCLight1 = 1. / o2::gpu::gpu_common_constants::kCLight;
1071 bz = f->GetFieldBz(xyz.X(), xyz.Y(), xyz.Z()) * kCLight1;
1072 } else {
1073#ifndef GPUCA_GPUCODE
1074 if (mFieldFast) {
1075 mFieldFast->GetBz(xyz, bz); // Must not call the host-only function in GPU compilation
1076 } else {
1077#ifdef GPUCA_STANDALONE
1078 LOG(fatal) << "Normal field cannot be used in standalone benchmark";
1079#else
1080 bz = mField->GetBz(xyz.X(), xyz.Y(), xyz.Z());
1081#endif
1082 }
1083#endif
1084 }
1085 return bz;
1086}
1087
1088template <typename value_T>
1089GPUd() void PropagatorImpl<value_T>::getFieldXYZ(const math_utils::Point3D<float> xyz, float* bxyz) const
1090{
1091 getFieldXYZImpl<float>(xyz, bxyz);
1092}
1093
1094template <typename value_T>
1095GPUd() void PropagatorImpl<value_T>::getFieldXYZ(const math_utils::Point3D<double> xyz, double* bxyz) const
1096{
1097 getFieldXYZImpl<double>(xyz, bxyz);
1098}
1099
1100template <typename value_T>
1101GPUd() float PropagatorImpl<value_T>::getBz(const math_utils::Point3D<float> xyz) const
1102{
1103 return getBzImpl<float>(xyz);
1104}
1105
1106template <typename value_T>
1107GPUd() double PropagatorImpl<value_T>::getBz(const math_utils::Point3D<double> xyz) const
1108{
1109 return getBzImpl<double>(xyz);
1110}
1111
1112namespace o2::base
1113{
1114#if !defined(GPUCA_GPUCODE) || defined(GPUCA_GPUCODE_DEVICE) // FIXME: DR: WORKAROUND to avoid CUDA bug creating host symbols for device code.
1115template class PropagatorImpl<float>;
1116template bool GPUdni() PropagatorImpl<float>::propagateToAlphaX<PropagatorImpl<float>::TrackPar_t>(PropagatorImpl<float>::TrackPar_t&, float, float, bool, float, float, int, PropagatorImpl<float>::MatCorrType matCorr, track::TrackLTIntegral*, int) const;
1117template bool GPUdni() PropagatorImpl<float>::propagateToAlphaX<PropagatorImpl<float>::TrackParCov_t>(PropagatorImpl<float>::TrackParCov_t&, float, float, bool, float, float, int, PropagatorImpl<float>::MatCorrType matCorr, track::TrackLTIntegral*, int) const;
1118template bool GPUdni() PropagatorImpl<float>::propagateToR<PropagatorImpl<float>::TrackPar_t>(PropagatorImpl<float>::TrackPar_t&, float, bool, float, float, PropagatorImpl<float>::MatCorrType matCorr, track::TrackLTIntegral*, int) const;
1119template bool GPUdni() PropagatorImpl<float>::propagateToR<PropagatorImpl<float>::TrackParCov_t>(PropagatorImpl<float>::TrackParCov_t&, float, bool, float, float, PropagatorImpl<float>::MatCorrType matCorr, track::TrackLTIntegral*, int) const;
1120#endif
1121#ifndef GPUCA_GPUCODE
1122template class PropagatorImpl<double>;
1125#endif
1126} // namespace o2::base
General auxilliary methods.
Definition of the GeometryManager class.
std::ostringstream debug
int32_t i
#define GPUdni()
#define GPUCA_CONSMEM
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
Header of the General Run Parameters object for B field values.
Header of the General Run Parameters object.
Helper classes for helical tracks manipulations.
constexpr int p1()
constexpr to accelerate the coordinates changing
Definition of the fast magnetic field parametrization MagFieldFast.
Definition of the MagF class.
uint32_t res
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
static o2::base::MatBudget meanMaterialBudget(float x0, float y0, float z0, float x1, float y1, float z1, TGeoNavigator *nav=nullptr)
GPUd() bool propagateToDCA(const o2 GPUd() bool propagateToDCABxByBz(const o2 GPUd() bool propagateToDCA(const o2 GPUd() bool propagateToDCABxByBz(const o2 PropagatorImpl(PropagatorImpl const &)=delete
static int initFieldFromGRP(const o2::parameters::GRPMagField *grp, bool verbose=false)
static MagneticField * createFieldMap(float l3Current=-30000., float diCurrent=-6000., Int_t convention=0, Bool_t uniform=kFALSE, float beamenergy=7000, const Char_t *btype="pp", const std::string path=std::string(gSystem->Getenv("VMCWORKDIR"))+std::string("/Common/maps/mfchebKGI_sym.root"))
void AllowFastField(bool v=true)
allow fast field param
o2::units::Current_t getDipoleCurrent() const
Definition GRPMagField.h:43
bool getFieldUniformity() const
Definition GRPMagField.h:49
o2::units::Current_t getL3Current() const
getters/setters for magnets currents
Definition GRPMagField.h:37
o2::units::Current_t getDipoleCurrent() const
Definition GRPObject.h:81
bool getFieldUniformity() const
Definition GRPObject.h:82
static GRPObject * loadFrom(const std::string &grpFileName="")
o2::units::Current_t getL3Current() const
getters/setters for magnets currents
Definition GRPObject.h:80
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
uint8_t int statusCode int
Vec3 cross(const Vec3 &firstVector, const Vec3 &secondVector)
GPUd() const expr uint32_t MultivariatePolynomialHelper< Dim
const bool const int TrackITSInternal< NLayers > & track
const float const float const float bz
std::array< int, 24 > p0
value_T step
Definition TrackUtils.h:42
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"