Skip to content

Commit 6346222

Browse files
committed
GPU: Move some functionality to CAMath
1 parent fb0384b commit 6346222

File tree

8 files changed

+18
-20
lines changed

8 files changed

+18
-20
lines changed

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

2021
#if !defined(GPUCA_NSECTORS) && !defined(GPUCA_ROW_COUNT)
2122
#include "DataFormatsTPC/Constants.h"
@@ -145,7 +146,7 @@ class GPUTPCGeometry // TODO: Make values constexpr
145146
return (250.f - v) * FACTOR_Z2T; // Used in compression, must remain constant at 250cm
146147
}
147148

148-
GPUd() static constexpr float kSectAngle() { return 2 * M_PI / 18.f; }
149+
GPUd() static constexpr float kSectAngle() { return 2 * CAMath::Pi() / 18.f; }
149150
};
150151

151152
} // namespace o2::gpu

GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx

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

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

527526
GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& GPUrestrict() prop, const GPUParam& GPUrestrict() param, float& GPUrestrict() Alpha)
528527
{
529-
static constexpr float kDeg2Rad = M_PI / 180.f;
530-
531528
if (param.rec.tpc.trackReferenceX <= 500) {
532529
GPUTPCGMTrackParam save = *this;
533530
float saveAlpha = Alpha;
534531
for (int32_t attempt = 0; attempt < 3; attempt++) {
535-
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
532+
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
536533
Alpha += dAngle;
537534
if (prop.PropagateToXAlpha(param.rec.tpc.trackReferenceX, Alpha, 0)) {
538535
break;
@@ -546,7 +543,7 @@ GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& GPUrestric
546543
Alpha = saveAlpha;
547544
}
548545
if (CAMath::Abs(mP[0]) > mX * CAMath::Tan(GPUTPCGeometry::kSectAngle() / 2.f)) {
549-
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
546+
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
550547
Rotate(dAngle);
551548
ConstrainSinPhi();
552549
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
@@ -188,7 +188,7 @@ static const constexpr int32_t COLORS_HEX[COLORCOUNT] = {0xB03030, 0x00A000, 0x0
188188
static const constexpr int32_t CONFIG_DASHED_MARKERS = 0;
189189

190190
static const constexpr float AXES_MIN[5] = {-Y_MAX, -Z_MAX, 0.f, -ETA_MAX, PT_MIN};
191-
static const constexpr float AXES_MAX[5] = {Y_MAX, Z_MAX, 2.f * M_PI, ETA_MAX, PT_MAX};
191+
static const constexpr float AXES_MAX[5] = {Y_MAX, Z_MAX, 2.f * CAMath::Pi(), ETA_MAX, PT_MAX};
192192
static const constexpr int32_t AXIS_BINS[5] = {51, 51, 144, 31, 50};
193193
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.
194194
static const constexpr float RES_AXES[5] = {1., 1., 0.03, 0.03, 1.0};
@@ -1162,12 +1162,12 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
11621162
const mcInfo_t& info = GetMCTrack(i, iCol);
11631163
additionalMCParameters& mc2 = mMCParam[iCol][i];
11641164
mc2.pt = std::sqrt(info.pX * info.pX + info.pY * info.pY);
1165-
mc2.phi = M_PI + std::atan2(-info.pY, -info.pX);
1165+
mc2.phi = CAMath::Pi() + std::atan2(-info.pY, -info.pX);
11661166
float p = info.pX * info.pX + info.pY * info.pY + info.pZ * info.pZ;
11671167
if (p < 1e-18) {
11681168
mc2.theta = mc2.eta = 0.f;
11691169
} else {
1170-
mc2.theta = info.pZ == 0 ? (M_PI / 2) : (std::acos(info.pZ / std::sqrt(p)));
1170+
mc2.theta = info.pZ == 0 ? (CAMath::Pi() / 2) : (std::acos(info.pZ / std::sqrt(p)));
11711171
mc2.eta = -std::log(std::tan(0.5 * mc2.theta));
11721172
}
11731173
if (mConfig.writeMCLabels) {
@@ -1221,10 +1221,10 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
12211221
}
12221222

12231223
float alpha = std::atan2(info.y, info.x);
1224-
alpha /= M_PI / 9.f;
1224+
alpha /= CAMath::Pi() / 9.f;
12251225
alpha = std::floor(alpha);
1226-
alpha *= M_PI / 9.f;
1227-
alpha += M_PI / 18.f;
1226+
alpha *= CAMath::Pi() / 9.f;
1227+
alpha += CAMath::Pi() / 18.f;
12281228

12291229
float c = std::cos(alpha);
12301230
float s = std::sin(alpha);

GPU/GPUTracking/qa/genEvents.cxx

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

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

207207
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)