Skip to content

Commit 313562b

Browse files
committed
GPU: Move some functionality to CAMath
1 parent 861c560 commit 313562b

8 files changed

Lines changed: 18 additions & 20 deletions

File tree

‎GPU/Common/GPUCommonMath.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class GPUCommonMath
106106
GPUd() constexpr static double Copysignd(double x, double y);
107107
GPUd() constexpr static float TwoPi() { return 6.2831853f; }
108108
GPUd() constexpr static float Pi() { return 3.1415927f; }
109+
GPUd() constexpr static float Deg2Rad() { return Pi() / 180.f; }
109110
GPUd() constexpr static float Round(float x);
110111
GPUd() constexpr static float Floor(float x) { return GPUCA_CHOICE(floorf(x), floorf(x), floor(x)); }
111112
GPUd() static uint32_t Float2UIntReint(const float& x);

‎GPU/GPUTracking/DataTypes/GPUTPCGeometry.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define GPUTPCGEOMETRY_H
1717

1818
#include "GPUCommonDef.h"
19+
#include "GPUCommonMath.h"
1920
#include "DataFormatsTPC/Constants.h"
2021
#ifndef GPUCA_GPUCODE_DEVICE
2122
#include <cmath>
@@ -179,7 +180,7 @@ class GPUTPCGeometry
179180
return (250.f - v) * FACTOR_Z2T; // Used in compression, must remain constant at 250cm
180181
}
181182

182-
GPUd() static constexpr float kSectAngle() { return 2 * M_PI / 18.f; }
183+
GPUd() static constexpr float kSectAngle() { return 2 * CAMath::Pi() / 18.f; }
183184
};
184185

185186
} // namespace o2::gpu

‎GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ GPUdii() int32_t GPUTPCGMTrackParam::FitHit(GPUTPCGMMerger& GPUrestrict() merger
278278
uncorrectedY = AttachClusters(merger, cluster.sector, cluster.row, iTrk, track.Leg() == 0, prop);
279279
}
280280

281-
static constexpr float kDeg2Rad = M_PI / 180.f;
282-
const float maxSinForUpdate = CAMath::Sin(70.f * kDeg2Rad);
281+
const float maxSinForUpdate = CAMath::Sin(70.f * CAMath::Deg2Rad());
283282
const bool sinPhiErr = mNDF > 0 && CAMath::Abs(prop.GetSinPhi0()) >= maxSinForUpdate;
284283
if (mNDF >= 0 && (mC[0] > param.rec.tpc.trackFitCovLimit || mC[2] > param.rec.tpc.trackFitCovLimit)) {
285284
return 1; // bad chi2 for the whole track, stop the fit
@@ -527,13 +526,11 @@ GPUdii() void GPUTPCGMTrackParam::DodEdx(GPUdEdx& GPUrestrict() dEdx, GPUdEdx& G
527526

528527
GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& GPUrestrict() prop, const GPUParam& GPUrestrict() param, float& GPUrestrict() Alpha)
529528
{
530-
constexpr float kDeg2Rad = M_PI / 180.f;
531-
532529
if (param.rec.tpc.trackReferenceX <= 500) {
533530
GPUTPCGMTrackParam save = *this;
534531
float saveAlpha = Alpha;
535532
for (int32_t attempt = 0; attempt < 3; attempt++) {
536-
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
533+
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
537534
Alpha += dAngle;
538535
if (prop.PropagateToXAlpha(param.rec.tpc.trackReferenceX, Alpha, 0)) {
539536
break;
@@ -547,7 +544,7 @@ GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& GPUrestric
547544
Alpha = saveAlpha;
548545
}
549546
if (CAMath::Abs(mP[0]) > mX * CAMath::Tan(GPUTPCGeometry::kSectAngle() / 2.f)) {
550-
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
547+
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
551548
Rotate(dAngle);
552549
ConstrainSinPhi();
553550
Alpha += dAngle;

‎GPU/GPUTracking/Refit/GPUTrackingRefit.cxx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,11 @@ GPUd() int32_t GPUTrackingRefit::RefitTrack(T& trkX, bool outward, bool resetCov
400400
trk.NormalizeAlpha(alpha);
401401
prop.SetAlpha(alpha);
402402
} else if constexpr (std::is_same_v<S, TrackParCov>) {
403-
constexpr float kDeg2Rad = M_PI / 180.f;
404403
if (mPparam->rec.tpc.trackReferenceX <= 500) {
405404
const int32_t eLossSignRef = (mPparam->rec.tpc.trackReferenceX > trk.getX()) == outward ? eLossSign : -eLossSign; // a forced energy-loss sign holds along the refit direction: the way to the reference X can run against it
406405
if (prop->PropagateToXBxByBz(trk, mPparam->rec.tpc.trackReferenceX, Propagator::MAX_SIN_PHI, Propagator::MAX_STEP, Propagator::MatCorrType::USEMatCorrLUT, nullptr, eLossSignRef)) {
407406
if (CAMath::Abs(trk.getY()) > trk.getX() * CAMath::Tan(GPUTPCGeometry::kSectAngle() / 2.f)) {
408-
float newAlpha = trk.getAlpha() + CAMath::Round(CAMath::ATan2(trk.getY(), trk.getX()) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
407+
float newAlpha = trk.getAlpha() + CAMath::Round(CAMath::ATan2(trk.getY(), trk.getX()) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
409408
GPUTPCGMTrackParam::NormalizeAlpha(newAlpha);
410409
trk.rotate(newAlpha) && prop->PropagateToXBxByBz(trk, mPparam->rec.tpc.trackReferenceX, Propagator::MAX_SIN_PHI, Propagator::MAX_STEP, Propagator::MatCorrType::USEMatCorrLUT, nullptr, eLossSignRef);
411410
}

‎GPU/GPUTracking/TRDTracking/GPUTRDInterfaces.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class trackInterface<GPUTPCGMTrackParam> : public GPUTPCGMTrackParam
147147
GPUd() float getSnp() const { return GetSinPhi(); }
148148
GPUd() float getTgl() const { return GetDzDs(); }
149149
GPUd() float getQ2Pt() const { return GetQPt(); }
150-
GPUd() float getEta() const { return -CAMath::Log(CAMath::Tan(0.5f * (0.5f * M_PI - CAMath::ATan(getTgl())))); }
150+
GPUd() float getEta() const { return -CAMath::Log(CAMath::Tan(0.5f * (0.5f * CAMath::Pi() - CAMath::ATan(getTgl())))); }
151151
GPUd() float getPt() const { return CAMath::Abs(getQ2Pt()) > 0 ? CAMath::Abs(1.f / getQ2Pt()) : 99999.f; }
152152
GPUd() float getSigmaY2() const { return GetErr2Y(); }
153153
GPUd() float getSigmaZ2() const { return GetErr2Z(); }

‎GPU/GPUTracking/qa/GPUQA.cxx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static const constexpr int32_t COLORS_HEX[COLORCOUNT] = {0xB03030, 0x00A000, 0x0
182182
static const constexpr int32_t CONFIG_DASHED_MARKERS = 0;
183183

184184
static const constexpr float AXES_MIN[5] = {-Y_MAX, -Z_MAX, 0.f, -ETA_MAX, PT_MIN};
185-
static const constexpr float AXES_MAX[5] = {Y_MAX, Z_MAX, 2.f * M_PI, ETA_MAX, PT_MAX};
185+
static const constexpr float AXES_MAX[5] = {Y_MAX, Z_MAX, 2.f * CAMath::Pi(), ETA_MAX, PT_MAX};
186186
static const constexpr int32_t AXIS_BINS[5] = {51, 51, 144, 31, 50};
187187
static const constexpr int32_t RES_AXIS_BINS[] = {1017, 113}; // Consecutive bin sizes, histograms are binned down until the maximum entry is 50, each bin size should evenly divide its predecessor.
188188
static const constexpr float RES_AXES[5] = {1., 1., 0.03, 0.03, 1.0};
@@ -1247,12 +1247,12 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
12471247
const mcInfo_t& info = GetMCTrack(i, iCol);
12481248
additionalMCParameters& mc2 = mMCParam[iCol][i];
12491249
mc2.pt = std::sqrt(info.pX * info.pX + info.pY * info.pY);
1250-
mc2.phi = M_PI + std::atan2(-info.pY, -info.pX);
1250+
mc2.phi = CAMath::Pi() + std::atan2(-info.pY, -info.pX);
12511251
float p = info.pX * info.pX + info.pY * info.pY + info.pZ * info.pZ;
12521252
if (p < 1e-18) {
12531253
mc2.theta = mc2.eta = 0.f;
12541254
} else {
1255-
mc2.theta = info.pZ == 0 ? (M_PI / 2) : (std::acos(info.pZ / std::sqrt(p)));
1255+
mc2.theta = info.pZ == 0 ? (CAMath::Pi() / 2) : (std::acos(info.pZ / std::sqrt(p)));
12561256
mc2.eta = -std::log(std::tan(0.5 * mc2.theta));
12571257
}
12581258
if (mConfig.writeMCLabels) {
@@ -1306,10 +1306,10 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
13061306
}
13071307

13081308
float alpha = std::atan2(info.y, info.x);
1309-
alpha /= M_PI / 9.f;
1309+
alpha /= CAMath::Pi() / 9.f;
13101310
alpha = std::floor(alpha);
1311-
alpha *= M_PI / 9.f;
1312-
alpha += M_PI / 18.f;
1311+
alpha *= CAMath::Pi() / 9.f;
1312+
alpha += CAMath::Pi() / 18.f;
13131313

13141314
float c = std::cos(alpha);
13151315
float s = std::sin(alpha);

‎GPU/GPUTracking/qa/genEvents.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ int32_t genEvents::GenerateEvent(const GPUParam& param, const char* filename)
199199
double eta = gRandom->Uniform(-1.5, 1.5);
200200

201201
double theta = 2 * std::atan(1. / exp(eta));
202-
double lambda = theta - M_PI / 2;
203-
// double theta = gRandom->Uniform(-60,60)*M_PI/180.;
202+
double lambda = theta - CAMath::Pi() / 2;
203+
// double theta = gRandom->Uniform(-60,60)*CAMath::Pi()/180.;
204204
double pt = .08 * std::pow(10, gRandom->Uniform(0, 2.2));
205205

206206
double q = 1.;

‎GPU/GPUTracking/qa/genEvents.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define GENEVENTS_H
1717

1818
#include "GPUCommonDef.h"
19-
#include <cmath>
19+
#include "GPUCommonMath.h"
2020

2121
namespace o2::gpu
2222
{
@@ -66,7 +66,7 @@ class genEvents
6666
uint32_t id;
6767
};
6868

69-
const double mTwoPi = 2 * M_PI;
69+
const double mTwoPi = 2 * CAMath::Pi();
7070
const double mSectorDAngle = mTwoPi / 18.;
7171
const double mSectorAngleOffset = mSectorDAngle / 2;
7272

0 commit comments

Comments
 (0)