Skip to content

Commit b02ec73

Browse files
davidrohrshahor02
authored andcommitted
Replace std::array/std::pair crossParameters by C arrays
1 parent 3b672f5 commit b02ec73

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

Detectors/Base/include/DetectorsBase/Ray.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ class Ray
3939
{
4040

4141
public:
42-
using CrossPar = std::pair<float, float>;
4342
using vecF3 = float[3];
4443

4544
static constexpr float InvalidT = -1e9;
4645
static constexpr float Tiny = 1e-9;
4746

48-
GPUd() Ray() : mP{ 0.f }, mD{ 0.f }, mDistXY2(0.f), mDistXY2i(0.f), mDistXYZ(0.f), mXDxPlusYDy(0.f), mXDxPlusYDyRed(0.f), mXDxPlusYDy2(0.f), mR02(0.f), mR12(0.f), mCrossParams()
47+
GPUd() Ray() : mP{ 0.f }, mD{ 0.f }, mDistXY2(0.f), mDistXY2i(0.f), mDistXYZ(0.f), mXDxPlusYDy(0.f), mXDxPlusYDyRed(0.f), mXDxPlusYDy2(0.f), mR02(0.f), mR12(0.f)
4948
{
5049
}
5150
GPUd() ~Ray() CON_DEFAULT;
@@ -56,13 +55,17 @@ class Ray
5655
GPUd() Ray(float x0, float y0, float z0, float x1, float y1, float z1);
5756

5857
GPUd() int crossLayer(const MatLayerCyl& lr);
59-
GPUd() bool crossCircleR(float r2, CrossPar& cross) const;
58+
GPUd() bool crossCircleR(float r2, float& cross1, float& cross2) const;
6059

6160
GPUd() float crossRadial(const MatLayerCyl& lr, int sliceID) const;
6261
GPUd() float crossRadial(float cs, float sn) const;
6362
GPUd() float crossZ(float z) const;
6463

65-
GPUd() const CrossPar& getCrossParams(int i) const { return mCrossParams[i]; }
64+
GPUd() void getCrossParams(int i, float& par1, float& par2) const
65+
{
66+
par1 = mCrossParams1[i];
67+
par2 = mCrossParams2[i];
68+
}
6669

6770
GPUd() void getMinMaxR2(float& rmin2, float& rmax2) const;
6871

@@ -81,7 +84,7 @@ class Ray
8184

8285
GPUd() float getZ(float t) const { return mP[2] + t * mD[2]; }
8386

84-
GPUd() bool validateZRange(CrossPar& cpar, const MatLayerCyl& lr) const;
87+
GPUd() bool validateZRange(float& cpar1, float& cpar2, const MatLayerCyl& lr) const;
8588

8689
private:
8790
vecF3 mP; ///< entrance point
@@ -94,7 +97,8 @@ class Ray
9497
float mXDxPlusYDy2; ///< aux (x0*DX+y0*DY)^2
9598
float mR02; ///< radius^2 of mP
9699
float mR12; ///< radius^2 of mP1
97-
std::array<CrossPar, 2> mCrossParams; ///< parameters of crossing the layer
100+
float mCrossParams1[2]; ///< parameters of crossing the layer (first parameter)
101+
float mCrossParams2[2]; ///< parameters of crossing the layer (second parameter)
98102

99103
ClassDefNV(Ray, 1);
100104
};
@@ -142,7 +146,7 @@ GPUdi() float Ray::crossRadial(float cs, float sn) const
142146
}
143147

144148
//______________________________________________________
145-
GPUdi() bool Ray::crossCircleR(float r2, CrossPar& cross) const
149+
GPUdi() bool Ray::crossCircleR(float r2, float& cross1, float& cross2) const
146150
{
147151
// calculate parameters t of intersection with circle of radius r^2
148152
// calculated as solution of equation
@@ -152,8 +156,8 @@ GPUdi() bool Ray::crossCircleR(float r2, CrossPar& cross) const
152156
if (det < 0)
153157
return false; // no intersection
154158
float detRed = std::sqrt(det) * mDistXY2i;
155-
cross.first = mXDxPlusYDyRed + detRed; // (-mXDxPlusYDy + det)*mDistXY2i;
156-
cross.second = mXDxPlusYDyRed - detRed; // (-mXDxPlusYDy - det)*mDistXY2i;
159+
cross1 = mXDxPlusYDyRed + detRed; // (-mXDxPlusYDy + det)*mDistXY2i;
160+
cross2 = mXDxPlusYDyRed - detRed; // (-mXDxPlusYDy - det)*mDistXY2i;
157161
return true;
158162
}
159163

@@ -172,20 +176,20 @@ GPUdi() float Ray::crossZ(float z) const
172176
}
173177

174178
//______________________________________________________
175-
GPUdi() bool Ray::validateZRange(CrossPar& cpar, const MatLayerCyl& lr) const
179+
GPUdi() bool Ray::validateZRange(float& cpar1, float& cpar2, const MatLayerCyl& lr) const
176180
{
177181
// make sure that estimated crossing parameters are compatible
178182
// with Z coverage of the layer
179-
MatLayerCyl::RangeStatus zout0 = lr.isZOutside(getZ(cpar.first)), zout1 = lr.isZOutside(getZ(cpar.second));
183+
MatLayerCyl::RangeStatus zout0 = lr.isZOutside(getZ(cpar1)), zout1 = lr.isZOutside(getZ(cpar2));
180184
if (zout0 == zout1) { // either both points outside w/o crossing or boht inside
181185
return zout0 == MatLayerCyl::Within ? true : false;
182186
}
183187
// at least 1 point is outside, but there is a crossing
184188
if (zout0 != MatLayerCyl::Within) {
185-
cpar.first = crossZ(zout0 == MatLayerCyl::Below ? lr.getZMin() : lr.getZMax());
189+
cpar1 = crossZ(zout0 == MatLayerCyl::Below ? lr.getZMin() : lr.getZMax());
186190
}
187191
if (zout1 != MatLayerCyl::Within) {
188-
cpar.second = crossZ(zout1 == MatLayerCyl::Below ? lr.getZMin() : lr.getZMax());
192+
cpar2 = crossZ(zout1 == MatLayerCyl::Below ? lr.getZMin() : lr.getZMax());
189193
}
190194
return true;
191195
}

Detectors/Base/src/MatLayerCylSet.cxx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ GPUd() MatBudget MatLayerCylSet::getMatBudget(float x0, float y0, float z0, floa
249249
const auto& lr = getLayer(lrID);
250250
int nc = ray.crossLayer(lr);
251251
for (int ic = nc; ic--;) {
252-
auto& cross = ray.getCrossParams(ic); // tmax,tmin of crossing the layer
253-
auto phi0 = ray.getPhi(cross.first), phi1 = ray.getPhi(cross.second), dPhi = phi0 - phi1;
252+
float cross1, cross2;
253+
ray.getCrossParams(ic, cross1, cross2); // tmax,tmin of crossing the layer
254+
auto phi0 = ray.getPhi(cross1), phi1 = ray.getPhi(cross2), dPhi = phi0 - phi1;
254255
auto phiID = lr.getPhiSliceID(phi0), phiIDLast = lr.getPhiSliceID(phi1);
255256
// account for eventual wrapping around 0
256257
if (dPhi > 0.f) {
@@ -264,11 +265,11 @@ GPUd() MatBudget MatLayerCylSet::getMatBudget(float x0, float y0, float z0, floa
264265
}
265266
int stepPhiID = phiID > phiIDLast ? -1 : 1;
266267
bool checkMorePhi = true;
267-
auto tStartPhi = cross.first, tEndPhi = 0.f;
268+
auto tStartPhi = cross1, tEndPhi = 0.f;
268269
do {
269270
// get the path in the current phi slice
270271
if (phiID == phiIDLast) {
271-
tEndPhi = cross.second;
272+
tEndPhi = cross2;
272273
checkMorePhi = false;
273274
} else { // last phi slice still not reached
274275
tEndPhi = ray.crossRadial(lr, (stepPhiID > 0 ? phiID + 1 : phiID) % lr.getNPhiSlices());

Detectors/Base/src/Ray.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ GPUd() int Ray::crossLayer(const MatLayerCyl& lr)
3939
}
4040
float detMin = mXDxPlusYDy2 - mDistXY2 * (mR02 - lr.getRMin2());
4141
if (detMin < 0) { // does not reach inner R -> just 1 tangential crossing
42-
mCrossParams[0].first = tCross0Min > 0.f ? tCross0Min : 0.f;
43-
mCrossParams[0].second = tCross0Max < 1.f ? tCross0Max : 1.f;
44-
return validateZRange(mCrossParams[0], lr);
42+
mCrossParams1[0] = tCross0Min > 0.f ? tCross0Min : 0.f;
43+
mCrossParams2[0] = tCross0Max < 1.f ? tCross0Max : 1.f;
44+
return validateZRange(mCrossParams1[0], mCrossParams2[0], lr);
4545
}
4646
int nCross = 0;
4747
float detMinRed = std::sqrt(detMin) * mDistXY2i;
4848
float tCross1Max = mXDxPlusYDyRed + detMinRed;
4949
float tCross1Min = mXDxPlusYDyRed - detMinRed;
5050

5151
if (tCross1Max < 1.f) {
52-
mCrossParams[0].first = tCross0Max < 1.f ? tCross0Max : 1.f;
53-
mCrossParams[0].second = tCross1Max > 0.f ? tCross1Max : 0.f;
54-
if (validateZRange(mCrossParams[nCross], lr)) {
52+
mCrossParams1[0] = tCross0Max < 1.f ? tCross0Max : 1.f;
53+
mCrossParams2[0] = tCross1Max > 0.f ? tCross1Max : 0.f;
54+
if (validateZRange(mCrossParams1[nCross], mCrossParams2[nCross], lr)) {
5555
nCross++;
5656
}
5757
}
5858

5959
if (tCross1Min > -0.f) {
60-
mCrossParams[nCross].first = tCross1Min < 1.f ? tCross1Min : 1.f;
61-
mCrossParams[nCross].second = tCross0Min > 0.f ? tCross0Min : 0.f;
62-
if (validateZRange(mCrossParams[nCross], lr)) {
60+
mCrossParams1[nCross] = tCross1Min < 1.f ? tCross1Min : 1.f;
61+
mCrossParams1[nCross] = tCross0Min > 0.f ? tCross0Min : 0.f;
62+
if (validateZRange(mCrossParams1[nCross], mCrossParams2[nCross], lr)) {
6363
nCross++;
6464
}
6565
}

0 commit comments

Comments
 (0)