Skip to content

Commit 418a85f

Browse files
authored
ITS: simplify constants + mathutils (#14383)
1 parent 89020a5 commit 418a85f

File tree

16 files changed

+122
-265
lines changed

16 files changed

+122
-265
lines changed

Detectors/ITSMFT/ITS/tracking/GPU/ITStrackingGPU/TrackingKernels.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ class CellSeed;
2222
class ExternalAllocator;
2323
namespace gpu
2424
{
25+
2526
#ifdef GPUCA_GPUCODE // GPUg() global kernels must only when compiled by GPU compiler
27+
28+
GPUdi() int4 getEmptyBinsRect() { return int4{0, 0, 0, 0}; }
29+
2630
GPUd() bool fitTrack(TrackITSExt& track,
2731
int start,
2832
int end,

Detectors/ITSMFT/ITS/tracking/GPU/ITStrackingGPU/VertexerTraitsGPU.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define ITSTRACKINGGPU_VERTEXERTRAITSGPU_H_
1919

2020
#include <vector>
21-
#include <array>
2221

2322
#include "ITStracking/VertexerTraits.h"
2423
#include "ITStracking/Configuration.h"
@@ -29,13 +28,8 @@
2928

3029
#include "ITStrackingGPU/TimeFrameGPU.h"
3130

32-
namespace o2
31+
namespace o2::its
3332
{
34-
namespace its
35-
{
36-
class ROframe;
37-
38-
using constants::its2::InversePhiBinSize;
3933

4034
class VertexerTraitsGPU final : public VertexerTraits
4135
{
@@ -63,6 +57,6 @@ inline void VertexerTraitsGPU::adoptTimeFrame(TimeFrame<7>* tf) noexcept
6357
mTimeFrame = static_cast<TimeFrame<7>*>(tf);
6458
}
6559

66-
} // namespace its
67-
} // namespace o2
60+
} // namespace o2::its
61+
6862
#endif

Detectors/ITSMFT/ITS/tracking/GPU/cuda/TrackingKernels.cu

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,8 @@ using namespace o2::track;
5252

5353
namespace o2::its
5454
{
55-
using namespace constants::its2;
5655
using Vertex = o2::dataformats::Vertex<o2::dataformats::TimeStamp<int>>;
5756

58-
GPUdii() float Sq(float v)
59-
{
60-
return v * v;
61-
}
62-
6357
namespace gpu
6458
{
6559

@@ -99,9 +93,9 @@ GPUd() const int4 getBinsRect(const Cluster& currentCluster, const int layerInde
9993
const float z1, const float z2, float maxdeltaz, float maxdeltaphi)
10094
{
10195
const float zRangeMin = o2::gpu::CAMath::Min(z1, z2) - maxdeltaz;
102-
const float phiRangeMin = (maxdeltaphi > constants::math::Pi) ? 0.f : currentCluster.phi - maxdeltaphi;
96+
const float phiRangeMin = (maxdeltaphi > o2::constants::math::PI) ? 0.f : currentCluster.phi - maxdeltaphi;
10397
const float zRangeMax = o2::gpu::CAMath::Max(z1, z2) + maxdeltaz;
104-
const float phiRangeMax = (maxdeltaphi > constants::math::Pi) ? constants::math::TwoPi : currentCluster.phi + maxdeltaphi;
98+
const float phiRangeMax = (maxdeltaphi > o2::constants::math::PI) ? o2::constants::math::TwoPI : currentCluster.phi + maxdeltaphi;
10599

106100
if (zRangeMax < -utils.getLayerZ(layerIndex) ||
107101
zRangeMin > utils.getLayerZ(layerIndex) || zRangeMin > zRangeMax) {
@@ -129,7 +123,7 @@ GPUd() bool fitTrack(TrackITSExt& track,
129123
o2::base::PropagatorF::MatCorrType matCorrType)
130124
{
131125
for (int iLayer{start}; iLayer != end; iLayer += step) {
132-
if (track.getClusterIndex(iLayer) == constants::its::UnusedIndex) {
126+
if (track.getClusterIndex(iLayer) == constants::UnusedIndex) {
133127
continue;
134128
}
135129
const TrackingFrameInfo& trackingHit = tfInfos[iLayer][track.getClusterIndex(iLayer)];
@@ -316,7 +310,7 @@ GPUg() void fitTrackSeedsKernel(
316310
temporaryTrack.setChi2(0);
317311
int* clusters = seed.getClusters();
318312
for (int iL{0}; iL < 7; ++iL) {
319-
temporaryTrack.setExternalClusterIndex(iL, clusters[iL], clusters[iL] != constants::its::UnusedIndex);
313+
temporaryTrack.setExternalClusterIndex(iL, clusters[iL], clusters[iL] != constants::UnusedIndex);
320314
}
321315
bool fitSuccess = fitTrack(temporaryTrack, // TrackITSExt& track,
322316
0, // int lastLayer,
@@ -422,8 +416,6 @@ GPUg() void computeLayerCellsKernel(
422416
const float cellDeltaTanLambdaSigma,
423417
const float nSigmaCut)
424418
{
425-
constexpr float radl = 9.36f; // Radiation length of Si [cm].
426-
constexpr float rho = 2.33f; // Density of Si [g/cm^3].
427419
constexpr float layerxX0[7] = {5.e-3f, 5.e-3f, 5.e-3f, 1.e-2f, 1.e-2f, 1.e-2f, 1.e-2f}; // Hardcoded here for the moment.
428420
for (int iCurrentTrackletIndex = blockIdx.x * blockDim.x + threadIdx.x; iCurrentTrackletIndex < nTrackletsCurrent; iCurrentTrackletIndex += blockDim.x * gridDim.x) {
429421
const Tracklet& currentTracklet = tracklets[layer][iCurrentTrackletIndex];
@@ -462,7 +454,7 @@ GPUg() void computeLayerCellsKernel(
462454
break;
463455
}
464456

465-
if (!track.correctForMaterial(layerxX0[layer + iC], layerxX0[layer] * radl * rho, true)) {
457+
if (!track.correctForMaterial(layerxX0[layer + iC], layerxX0[layer] * constants::Radl * constants::Rho, true)) {
466458
break;
467459
}
468460

@@ -548,12 +540,12 @@ GPUg() void computeLayerTrackletsMultiROFKernel(
548540
if (primaryVertex.isFlagSet(2) && iteration != 3) {
549541
continue;
550542
}
551-
const float resolution = o2::gpu::CAMath::Sqrt(Sq(resolutionPV) / primaryVertex.getNContributors() + Sq(positionResolution));
543+
const float resolution = o2::gpu::CAMath::Sqrt(math_utils::Sq(resolutionPV) / primaryVertex.getNContributors() + math_utils::Sq(positionResolution));
552544
const float tanLambda{(currentCluster.zCoordinate - primaryVertex.getZ()) * inverseR0};
553545
const float zAtRmin{tanLambda * (minR - currentCluster.radius) + currentCluster.zCoordinate};
554546
const float zAtRmax{tanLambda * (maxR - currentCluster.radius) + currentCluster.zCoordinate};
555-
const float sqInverseDeltaZ0{1.f / (Sq(currentCluster.zCoordinate - primaryVertex.getZ()) + 2.e-8f)}; /// protecting from overflows adding the detector resolution
556-
const float sigmaZ{o2::gpu::CAMath::Sqrt(Sq(resolution) * Sq(tanLambda) * ((Sq(inverseR0) + sqInverseDeltaZ0) * Sq(meanDeltaR) + 1.f) + Sq(meanDeltaR * MSAngle))};
547+
const float sqInverseDeltaZ0{1.f / (math_utils::Sq(currentCluster.zCoordinate - primaryVertex.getZ()) + 2.e-8f)}; /// protecting from overflows adding the detector resolution
548+
const float sigmaZ{o2::gpu::CAMath::Sqrt(math_utils::Sq(resolution) * math_utils::Sq(tanLambda) * ((math_utils::Sq(inverseR0) + sqInverseDeltaZ0) * math_utils::Sq(meanDeltaR) + 1.f) + math_utils::Sq(meanDeltaR * MSAngle))};
557549
const int4 selectedBinsRect{getBinsRect(currentCluster, layerIndex + 1, *utils, zAtRmin, zAtRmax, sigmaZ * NSigmaCut, phiCut)};
558550
if (selectedBinsRect.x == 0 && selectedBinsRect.y == 0 && selectedBinsRect.z == 0 && selectedBinsRect.w == 0) {
559551
continue;
@@ -587,7 +579,7 @@ GPUg() void computeLayerTrackletsMultiROFKernel(
587579
const float deltaPhi{o2::gpu::CAMath::Abs(currentCluster.phi - nextCluster.phi)};
588580
const float deltaZ{o2::gpu::CAMath::Abs(tanLambda * (nextCluster.radius - currentCluster.radius) + currentCluster.zCoordinate - nextCluster.zCoordinate)};
589581
const int nextSortedIndex{ROFClusters[layerIndex + 1][rof1] + nextClusterIndex};
590-
if (deltaZ / sigmaZ < NSigmaCut && (deltaPhi < phiCut || o2::gpu::CAMath::Abs(deltaPhi - constants::math::TwoPi) < phiCut)) {
582+
if (deltaZ / sigmaZ < NSigmaCut && (deltaPhi < phiCut || o2::gpu::CAMath::Abs(deltaPhi - o2::constants::math::TwoPI) < phiCut)) {
591583
if constexpr (initRun) {
592584
trackletsLUT[layerIndex][currentSortedIndex]++; // we need l0 as well for usual exclusive sums.
593585
} else {
@@ -634,8 +626,6 @@ GPUg() void processNeighboursKernel(const int layer,
634626
const o2::base::Propagator* propagator,
635627
const o2::base::PropagatorF::MatCorrType matCorrType)
636628
{
637-
constexpr float radl = 9.36f; // Radiation length of Si [cm].
638-
constexpr float rho = 2.33f; // Density of Si [g/cm^3].
639629
constexpr float layerxX0[7] = {5.e-3f, 5.e-3f, 5.e-3f, 1.e-2f, 1.e-2f, 1.e-2f, 1.e-2f}; // Hardcoded here for the moment.
640630
for (unsigned int iCurrentCell = blockIdx.x * blockDim.x + threadIdx.x; iCurrentCell < nCurrentCells; iCurrentCell += blockDim.x * gridDim.x) {
641631
int foundSeeds{0};
@@ -678,7 +668,7 @@ GPUg() void processNeighboursKernel(const int layer,
678668
}
679669

680670
if (matCorrType == o2::base::PropagatorF::MatCorrType::USEMatCorrNONE) {
681-
if (!seed.correctForMaterial(layerxX0[layer - 1], layerxX0[layer - 1] * radl * rho, true)) {
671+
if (!seed.correctForMaterial(layerxX0[layer - 1], layerxX0[layer - 1] * constants::Radl * constants::Rho, true)) {
682672
continue;
683673
}
684674
}

Detectors/ITSMFT/ITS/tracking/GPU/cuda/VertexerTraitsGPU.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void VertexerTraitsGPU::updateVertexingParameters(const std::vector<VertexingPar
4040
mTfGPUParams = tfPar;
4141
mIndexTableUtils.setTrackingParameters(vrtPar[0]);
4242
for (auto& par : mVrtParams) {
43-
par.phiSpan = static_cast<int>(std::ceil(mIndexTableUtils.getNphiBins() * par.phiCut / constants::math::TwoPi));
43+
par.phiSpan = static_cast<int>(std::ceil(mIndexTableUtils.getNphiBins() * par.phiCut / o2::constants::math::TwoPI));
4444
par.zSpan = static_cast<int>(std::ceil(par.zCut * mIndexTableUtils.getInverseZCoordinate(0)));
4545
}
4646
}

Detectors/ITSMFT/ITS/tracking/GPU/cuda/VertexingKernels.cu

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ namespace o2
2020
{
2121
namespace its
2222
{
23-
using constants::its::VertexerHistogramVolume;
24-
using constants::math::TwoPi;
2523
using math_utils::getNormalizedPhi;
26-
using namespace constants::its2;
2724

2825
namespace gpu
2926
{
@@ -58,11 +55,6 @@ void trackletFinderHandler(const Cluster* clustersNextLayer, // 0 2
5855
maxTrackletsPerCluster); // const unsigned int maxTrackletsPerCluster = 1e2
5956
}
6057
/*
61-
GPUd() float smallestAngleDifference(float a, float b)
62-
{
63-
float diff = fmod(b - a + constants::math::Pi, constants::math::TwoPi) - constants::math::Pi;
64-
return (diff < -constants::math::Pi) ? diff + constants::math::TwoPi : ((diff > constants::math::Pi) ? diff - constants::math::TwoPi : diff);
65-
}
6658
6759
GPUd() const int4 getBinsRect(const Cluster& currentCluster, const int layerIndex,
6860
const float z1, float maxdeltaz, float maxdeltaphi)

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Configuration.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class Configuration : public Param
5858
};
5959

6060
struct TrackingParameters {
61-
int CellMinimumLevel() { return MinTrackLength - constants::its::ClustersPerCell + 1; }
62-
int CellsPerRoad() const { return NLayers - 2; }
63-
int TrackletsPerRoad() const { return NLayers - 1; }
61+
int CellMinimumLevel() const noexcept { return MinTrackLength - constants::ClustersPerCell + 1; }
62+
int CellsPerRoad() const noexcept { return NLayers - 2; }
63+
int TrackletsPerRoad() const noexcept { return NLayers - 1; }
6464
std::string asString() const;
6565

6666
int NLayers = 7;

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Constants.h

Lines changed: 8 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -17,112 +17,25 @@
1717
#define TRACKINGITSU_INCLUDE_CONSTANTS_H_
1818

1919
#include "ITStracking/Definitions.h"
20-
#include "CommonConstants/MathConstants.h"
2120

22-
#include "GPUCommonMath.h"
23-
#include "GPUCommonDef.h"
24-
25-
#ifndef GPUCA_GPUCODE_DEVICE
26-
#include <climits>
27-
#include <vector>
28-
#include <array>
29-
#endif
30-
31-
namespace o2
32-
{
33-
namespace its
34-
{
35-
36-
namespace constants
21+
namespace o2::its::constants
3722
{
3823
constexpr float MB = 1024.f * 1024.f;
3924
constexpr float GB = 1024.f * 1024.f * 1024.f;
4025
constexpr bool DoTimeBenchmarks = true;
4126
constexpr bool SaveTimeBenchmarks = false;
4227

43-
namespace math
44-
{
45-
constexpr float Pi{3.14159265359f};
46-
constexpr float TwoPi{2.0f * Pi};
47-
constexpr float FloatMinThreshold{1e-20f};
48-
} // namespace math
49-
50-
namespace its
51-
{
52-
constexpr int LayersNumberVertexer{3};
28+
constexpr float Tolerance{1e-12}; // numerical tolerance
5329
constexpr int ClustersPerCell{3};
5430
constexpr int UnusedIndex{-1};
5531
constexpr float Resolution{0.0005f};
56-
57-
GPUhdi() constexpr std::array<float, 3> VertexerHistogramVolume()
58-
{
59-
return std::array<float, 3>{{1.98, 1.98, 40.f}};
60-
}
61-
} // namespace its
62-
63-
namespace its2
64-
{
65-
constexpr int LayersNumber{7};
66-
constexpr int TrackletsPerRoad{LayersNumber - 1};
67-
constexpr int CellsPerRoad{LayersNumber - 2};
68-
69-
GPUhdi() constexpr std::array<float, LayersNumber> LayersZCoordinate()
70-
{
71-
constexpr double s = 1.; // safety margin
72-
return std::array<float, LayersNumber>{16.333f + s, 16.333f + s, 16.333f + s, 42.140f + s, 42.140f + s, 73.745f + s, 73.745f + s};
73-
}
74-
75-
GPUhdi() constexpr std::array<float, LayersNumber> LayersRCoordinate()
32+
constexpr float Radl = 9.36f; // Radiation length of Si [cm]
33+
constexpr float Rho = 2.33f; // Density of Si [g/cm^3]
34+
namespace its // to be removed
7635
{
77-
return std::array<float, LayersNumber>{{2.33959f, 3.14076f, 3.91924f, 19.6213f, 24.5597f, 34.388f, 39.3329f}};
78-
}
79-
80-
constexpr int ZBins{256};
81-
constexpr int PhiBins{128};
82-
constexpr float InversePhiBinSize{PhiBins / constants::math::TwoPi};
83-
GPUhdi() constexpr std::array<float, LayersNumber> InverseZBinSize()
84-
{
85-
constexpr auto zSize = LayersZCoordinate();
86-
return std::array<float, LayersNumber>{0.5f * ZBins / (zSize[0]), 0.5f * ZBins / (zSize[1]), 0.5f * ZBins / (zSize[2]),
87-
0.5f * ZBins / (zSize[3]), 0.5f * ZBins / (zSize[4]), 0.5f * ZBins / (zSize[5]),
88-
0.5f * ZBins / (zSize[6])};
89-
}
90-
91-
GPUhdi() constexpr float getInverseZCoordinate(const int layerIndex)
92-
{
93-
return 0.5f * ZBins / LayersZCoordinate()[layerIndex];
94-
}
95-
96-
GPUhdi() int getZBinIndex(const int layerIndex, const float zCoordinate)
97-
{
98-
return (zCoordinate + LayersZCoordinate()[layerIndex]) *
99-
InverseZBinSize()[layerIndex];
100-
}
101-
102-
GPUhdi() int getPhiBinIndex(const float currentPhi)
103-
{
104-
return (currentPhi * InversePhiBinSize);
105-
}
106-
107-
GPUhdi() int getBinIndex(const int zIndex, const int phiIndex)
108-
{
109-
return o2::gpu::GPUCommonMath::Min(phiIndex * ZBins + zIndex,
110-
ZBins * PhiBins - 1);
111-
}
112-
113-
GPUhdi() constexpr int4 getEmptyBinsRect() { return int4{0, 0, 0, 0}; }
114-
115-
} // namespace its2
116-
117-
namespace pdgcodes
118-
{
119-
constexpr int PionCode{211};
120-
}
121-
} // namespace constants
122-
#ifndef GPUCA_GPUCODE_DEVICE
123-
typedef std::vector<std::vector<int>> index_table_t;
124-
#endif
36+
constexpr int UnusedIndex{-1};
37+
constexpr float Resolution{0.0005f};
12538
} // namespace its
126-
} // namespace o2
39+
} // namespace o2::its::constants
12740

12841
#endif /* TRACKINGITSU_INCLUDE_CONSTANTS_H_ */

Detectors/ITSMFT/ITS/tracking/include/ITStracking/IndexTableUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#ifndef TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_
1717
#define TRACKINGITSU_INCLUDE_INDEXTABLEUTILS_H_
1818

19-
#include "ITStracking/Constants.h"
2019
#include "ITStracking/Configuration.h"
2120
#include "ITStracking/Definitions.h"
21+
#include "CommonConstants/MathConstants.h"
2222
#include "GPUCommonMath.h"
2323
#include "GPUCommonDef.h"
2424

@@ -55,7 +55,7 @@ class IndexTableUtils
5555
template <class T>
5656
inline void IndexTableUtils::setTrackingParameters(const T& params)
5757
{
58-
mInversePhiBinSize = params.PhiBins / constants::math::TwoPi;
58+
mInversePhiBinSize = params.PhiBins / o2::constants::math::TwoPI;
5959
mNzBins = params.ZBins;
6060
mNphiBins = params.PhiBins;
6161
for (int iLayer{0}; iLayer < params.LayerZ.size(); ++iLayer) {

0 commit comments

Comments
 (0)