Skip to content

Commit 27fdc6d

Browse files
committed
GPU: Move some functionality to CAMath
1 parent 1c30b49 commit 27fdc6d

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
@@ -279,8 +279,7 @@ GPUdii() int32_t GPUTPCGMTrackParam::FitHit(GPUTPCGMMerger& GPUrestrict() merger
279279
uncorrectedY = AttachClusters(merger, cluster.sector, cluster.row, iTrk, track.Leg() == 0, prop);
280280
}
281281

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

529528
GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& GPUrestrict() prop, const GPUParam& GPUrestrict() param, float& GPUrestrict() Alpha)
530529
{
531-
static constexpr float kDeg2Rad = M_PI / 180.f;
532-
533530
if (param.rec.tpc.trackReferenceX <= 500) {
534531
GPUTPCGMTrackParam save = *this;
535532
float saveAlpha = Alpha;
536533
for (int32_t attempt = 0; attempt < 3; attempt++) {
537-
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
534+
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
538535
Alpha += dAngle;
539536
if (prop.PropagateToXAlpha(param.rec.tpc.trackReferenceX, Alpha, 0)) {
540537
break;
@@ -548,7 +545,7 @@ GPUdni() void GPUTPCGMTrackParam::MoveToReference(GPUTPCGMPropagator& GPUrestric
548545
Alpha = saveAlpha;
549546
}
550547
if (CAMath::Abs(mP[0]) > mX * CAMath::Tan(GPUTPCGeometry::kSectAngle() / 2.f)) {
551-
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / kDeg2Rad / 20.f) * GPUTPCGeometry::kSectAngle();
548+
float dAngle = CAMath::Round(CAMath::ATan2(mP[0], mX) / CAMath::Deg2Rad() / 20.f) * GPUTPCGeometry::kSectAngle();
552549
Rotate(dAngle);
553550
ConstrainSinPhi();
554551
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
@@ -183,7 +183,7 @@ static const constexpr int32_t COLORS_HEX[COLORCOUNT] = {0xB03030, 0x00A000, 0x0
183183
static const constexpr int32_t CONFIG_DASHED_MARKERS = 0;
184184

185185
static const constexpr float AXES_MIN[5] = {-Y_MAX, -Z_MAX, 0.f, -ETA_MAX, PT_MIN};
186-
static const constexpr float AXES_MAX[5] = {Y_MAX, Z_MAX, 2.f * M_PI, ETA_MAX, PT_MAX};
186+
static const constexpr float AXES_MAX[5] = {Y_MAX, Z_MAX, 2.f * CAMath::Pi(), ETA_MAX, PT_MAX};
187187
static const constexpr int32_t AXIS_BINS[5] = {51, 51, 144, 31, 50};
188188
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.
189189
static const constexpr float RES_AXES[5] = {1., 1., 0.03, 0.03, 1.0};
@@ -1214,12 +1214,12 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
12141214
const mcInfo_t& info = GetMCTrack(i, iCol);
12151215
additionalMCParameters& mc2 = mMCParam[iCol][i];
12161216
mc2.pt = std::sqrt(info.pX * info.pX + info.pY * info.pY);
1217-
mc2.phi = M_PI + std::atan2(-info.pY, -info.pX);
1217+
mc2.phi = CAMath::Pi() + std::atan2(-info.pY, -info.pX);
12181218
float p = info.pX * info.pX + info.pY * info.pY + info.pZ * info.pZ;
12191219
if (p < 1e-18) {
12201220
mc2.theta = mc2.eta = 0.f;
12211221
} else {
1222-
mc2.theta = info.pZ == 0 ? (M_PI / 2) : (std::acos(info.pZ / std::sqrt(p)));
1222+
mc2.theta = info.pZ == 0 ? (CAMath::Pi() / 2) : (std::acos(info.pZ / std::sqrt(p)));
12231223
mc2.eta = -std::log(std::tan(0.5 * mc2.theta));
12241224
}
12251225
if (mConfig.writeMCLabels) {
@@ -1273,10 +1273,10 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
12731273
}
12741274

12751275
float alpha = std::atan2(info.y, info.x);
1276-
alpha /= M_PI / 9.f;
1276+
alpha /= CAMath::Pi() / 9.f;
12771277
alpha = std::floor(alpha);
1278-
alpha *= M_PI / 9.f;
1279-
alpha += M_PI / 18.f;
1278+
alpha *= CAMath::Pi() / 9.f;
1279+
alpha += CAMath::Pi() / 18.f;
12801280

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