Skip to content

Commit 40dc223

Browse files
committed
GPU: Move some functionality to CAMath
1 parent 0797d90 commit 40dc223

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
@@ -95,6 +95,7 @@ class GPUCommonMath
9595
GPUhdni() constexpr static float Copysign(float x, float y) { return GPUCA_CHOICE(std::copysignf(x, y), copysignf(x, y), copysign(x, y)); }
9696
GPUd() constexpr static float TwoPi() { return 6.2831853f; }
9797
GPUd() constexpr static float Pi() { return 3.1415927f; }
98+
GPUd() constexpr static float Deg2Rad() { return Pi() / 180.f; }
9899
GPUd() constexpr static float Round(float x);
99100
GPUd() constexpr static float Floor(float x) { return GPUCA_CHOICE(floorf(x), floorf(x), floor(x)); }
100101
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>
@@ -178,7 +179,7 @@ class GPUTPCGeometry
178179
return (250.f - v) * FACTOR_Z2T; // Used in compression, must remain constant at 250cm
179180
}
180181

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

184185
} // 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-
static 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
@@ -398,11 +398,10 @@ GPUd() int32_t GPUTrackingRefit::RefitTrack(T& trkX, bool outward, bool resetCov
398398
trk.NormalizeAlpha(alpha);
399399
prop.SetAlpha(alpha);
400400
} else if constexpr (std::is_same_v<S, TrackParCov>) {
401-
static constexpr float kDeg2Rad = M_PI / 180.f;
402401
if (mPparam->rec.tpc.trackReferenceX <= 500) {
403402
if (prop->PropagateToXBxByBz(trk, mPparam->rec.tpc.trackReferenceX)) {
404403
if (CAMath::Abs(trk.getY()) > trk.getX() * CAMath::Tan(GPUTPCGeometry::kSectAngle() / 2.f)) {
405-
float newAlpha = trk.getAlpha() + CAMath::Round(CAMath::ATan2(trk.getY(), trk.getX()) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
404+
float newAlpha = trk.getAlpha() + CAMath::Round(CAMath::ATan2(trk.getY(), trk.getX()) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
406405
GPUTPCGMTrackParam::NormalizeAlpha(newAlpha);
407406
trk.rotate(newAlpha) && prop->PropagateToXBxByBz(trk, mPparam->rec.tpc.trackReferenceX);
408407
}

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};
@@ -1213,12 +1213,12 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
12131213
const mcInfo_t& info = GetMCTrack(i, iCol);
12141214
additionalMCParameters& mc2 = mMCParam[iCol][i];
12151215
mc2.pt = std::sqrt(info.pX * info.pX + info.pY * info.pY);
1216-
mc2.phi = M_PI + std::atan2(-info.pY, -info.pX);
1216+
mc2.phi = CAMath::Pi() + std::atan2(-info.pY, -info.pX);
12171217
float p = info.pX * info.pX + info.pY * info.pY + info.pZ * info.pZ;
12181218
if (p < 1e-18) {
12191219
mc2.theta = mc2.eta = 0.f;
12201220
} else {
1221-
mc2.theta = info.pZ == 0 ? (M_PI / 2) : (std::acos(info.pZ / std::sqrt(p)));
1221+
mc2.theta = info.pZ == 0 ? (CAMath::Pi() / 2) : (std::acos(info.pZ / std::sqrt(p)));
12221222
mc2.eta = -std::log(std::tan(0.5 * mc2.theta));
12231223
}
12241224
if (mConfig.writeMCLabels) {
@@ -1272,10 +1272,10 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
12721272
}
12731273

12741274
float alpha = std::atan2(info.y, info.x);
1275-
alpha /= M_PI / 9.f;
1275+
alpha /= CAMath::Pi() / 9.f;
12761276
alpha = std::floor(alpha);
1277-
alpha *= M_PI / 9.f;
1278-
alpha += M_PI / 18.f;
1277+
alpha *= CAMath::Pi() / 9.f;
1278+
alpha += CAMath::Pi() / 18.f;
12791279

12801280
float c = std::cos(alpha);
12811281
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)