Skip to content

Commit b899de3

Browse files
MichaelLettrichshahor02
authored andcommitted
[Align] Remove implicit conversions in TrackParam
Removes undesired implicite conversions from float->double->float and calling of more costly double versions of functions.
1 parent 3826aac commit b899de3

5 files changed

Lines changed: 251 additions & 250 deletions

File tree

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrization.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ constexpr float kCY2max = 100 * 100, // SigmaY<=100cm
117117
kCSnp2max = 1 * 1, // SigmaSin<=1
118118
kCTgl2max = 1 * 1, // SigmaTan<=1
119119
kC1Pt2max = 100 * 100, // Sigma1/Pt<=100 1/GeV
120-
kMostProbablePt = 0.6, // Most Probable Pt (GeV), for running with Bz=0
120+
kMostProbablePt = 0.6f, // Most Probable Pt (GeV), for running with Bz=0
121121
kCalcdEdxAuto = -999.f; // value indicating request for dedx calculation
122122

123123
// access to covariance matrix by row and column
@@ -138,13 +138,15 @@ class TrackParametrization
138138

139139
public:
140140
using value_t = value_T;
141-
using dim3v_t = std::array<value_t, 3>;
141+
using dim2_t = std::array<value_t, 2>;
142+
using dim3_t = std::array<value_t, 3>;
143+
using params_t = std::array<value_t, kNParams>;
142144

143145
static_assert(std::is_floating_point_v<value_t>);
144146

145147
TrackParametrization() = default;
146-
TrackParametrization(value_t x, value_t alpha, const std::array<value_t, kNParams>& par, int charge = 1);
147-
TrackParametrization(const std::array<value_t, 3>& xyz, const std::array<value_t, 3>& pxpypz, int charge, bool sectorAlpha = true);
148+
TrackParametrization(value_t x, value_t alpha, const params_t& par, int charge = 1);
149+
TrackParametrization(const dim3_t& xyz, const dim3_t& pxpypz, int charge, bool sectorAlpha = true);
148150
TrackParametrization(const TrackParametrization&) = default;
149151
TrackParametrization(TrackParametrization&&) = default;
150152
TrackParametrization& operator=(const TrackParametrization& src) = default;
@@ -200,8 +202,8 @@ class TrackParametrization
200202
value_t getTheta() const;
201203
value_t getEta() const;
202204
Point3D<value_t> getXYZGlo() const;
203-
void getXYZGlo(std::array<value_t, 3>& xyz) const;
204-
bool getPxPyPzGlo(std::array<value_t, 3>& pxyz) const;
205+
void getXYZGlo(dim3_t& xyz) const;
206+
bool getPxPyPzGlo(dim3_t& pxyz) const;
205207
bool getPosDirGlo(std::array<value_t, 9>& posdirp) const;
206208

207209
// methods for track params estimate at other point
@@ -214,9 +216,9 @@ class TrackParametrization
214216
bool correctForELoss(value_t xrho, value_t mass, bool anglecorr = false, value_t dedx = kCalcdEdxAuto);
215217
bool rotateParam(value_t alpha);
216218
bool propagateParamTo(value_t xk, value_t b);
217-
bool propagateParamTo(value_t xk, const std::array<value_t, 3>& b);
219+
bool propagateParamTo(value_t xk, const dim3_t& b);
218220

219-
bool propagateParamToDCA(const Point3D<value_t>& vtx, value_t b, std::array<value_t, 2>* dca = nullptr, value_t maxD = 999.f);
221+
bool propagateParamToDCA(const Point3D<value_t>& vtx, value_t b, dim2_t* dca = nullptr, value_t maxD = 999.f);
220222

221223
void invertParam();
222224

@@ -237,7 +239,7 @@ class TrackParametrization
237239

238240
private:
239241
//
240-
static constexpr value_t InvalidX = -99999.;
242+
static constexpr value_t InvalidX = -99999.f;
241243
value_t mX = 0.f; /// X of track evaluation
242244
value_t mAlpha = 0.f; /// track frame angle
243245
value_t mP[kNParams] = {0.f}; /// 5 parameters: Y,Z,sin(phi),tg(lambda),q/pT
@@ -250,7 +252,7 @@ class TrackParametrization
250252

251253
//____________________________________________________________
252254
template <typename value_T>
253-
inline TrackParametrization<value_T>::TrackParametrization(value_t x, value_t alpha, const std::array<value_t, kNParams>& par, int charge)
255+
inline TrackParametrization<value_T>::TrackParametrization(value_t x, value_t alpha, const params_t& par, int charge)
254256
: mX{x}, mAlpha{alpha}, mAbsCharge{char(std::abs(charge))}
255257
{
256258
// explicit constructor
@@ -324,7 +326,7 @@ inline typename TrackParametrization<value_T>::value_t TrackParametrization<valu
324326
template <typename value_T>
325327
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getCharge2Pt() const
326328
{
327-
return mAbsCharge ? mP[kQ2Pt] : 0.;
329+
return mAbsCharge ? mP[kQ2Pt] : 0.f;
328330
}
329331

330332
//____________________________________________________________
@@ -353,7 +355,7 @@ inline void TrackParametrization<value_T>::setPID(const PID pid)
353355
template <typename value_T>
354356
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getCsp2() const
355357
{
356-
value_t csp2 = (1. - mP[kSnp]) * (1. + mP[kSnp]);
358+
value_t csp2 = (1.f - mP[kSnp]) * (1.f + mP[kSnp]);
357359
return csp2 > o2::constants::math::Almost0 ? csp2 : o2::constants::math::Almost0;
358360
}
359361

@@ -434,10 +436,10 @@ inline void TrackParametrization<value_T>::getCircleParamsLoc(value_t bz, o2::ut
434436
// get circle params in track local frame, for straight line just set to local coordinates
435437
c.rC = getCurvature(bz);
436438
// treat as straight track if sagitta between the vertex and middle of TPC is below 0.01 cm
437-
constexpr value_t MinSagitta = 0.01, TPCMidR = 160., MinCurv = 8 * MinSagitta / (TPCMidR * TPCMidR);
439+
constexpr value_t MinSagitta = 0.01f, TPCMidR = 160.f, MinCurv = 8 * MinSagitta / (TPCMidR * TPCMidR);
438440
if (std::abs(c.rC) > MinCurv) {
439441
c.rC = 1.f / getCurvature(bz);
440-
value_t sn = getSnp(), cs = sqrtf((1. - sn) * (1. + sn));
442+
value_t sn = getSnp(), cs = sqrtf((1.f - sn) * (1.f + sn));
441443
c.xC = getX() - sn * c.rC; // center in tracking
442444
c.yC = getY() + cs * c.rC; // frame. Note: r is signed!!!
443445
c.rC = fabs(c.rC);
@@ -516,7 +518,7 @@ template <typename value_T>
516518
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getPtInv() const
517519
{
518520
// return the inverted track pT
519-
auto ptInv = fabs(mP[kQ2Pt]);
521+
const value_t ptInv = fabs(mP[kQ2Pt]);
520522
return (mAbsCharge > 1) ? ptInv / mAbsCharge : ptInv;
521523
}
522524

@@ -525,7 +527,7 @@ template <typename value_T>
525527
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getP2Inv() const
526528
{
527529
// return the inverted track momentum^2
528-
auto p2 = mP[kQ2Pt] * mP[kQ2Pt] / (1.f + getTgl() * getTgl());
530+
const value_t p2 = mP[kQ2Pt] * mP[kQ2Pt] / (1.f + getTgl() * getTgl());
529531
return (mAbsCharge > 1) ? p2 * mAbsCharge * mAbsCharge : p2;
530532
}
531533

@@ -534,16 +536,16 @@ template <typename value_T>
534536
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getP2() const
535537
{
536538
// return the track momentum^2
537-
auto p2inv = getP2Inv();
538-
return (p2inv > o2::constants::math::Almost0) ? 1. / p2inv : o2::constants::math::VeryBig;
539+
const value_t p2inv = getP2Inv();
540+
return (p2inv > o2::constants::math::Almost0) ? 1.f / p2inv : o2::constants::math::VeryBig;
539541
}
540542

541543
//____________________________________________________________
542544
template <typename value_T>
543545
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getPInv() const
544546
{
545547
// return the inverted track momentum^2
546-
auto pInv = fabs(mP[kQ2Pt]) / sqrtf(1.f + getTgl() * getTgl());
548+
const value_t pInv = fabs(mP[kQ2Pt]) / sqrtf(1.f + getTgl() * getTgl());
547549
return (mAbsCharge > 1) ? pInv / mAbsCharge : pInv;
548550
}
549551

@@ -552,8 +554,8 @@ template <typename value_T>
552554
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getP() const
553555
{
554556
// return the track momentum
555-
value_t pInv = getPInv();
556-
return (pInv > o2::constants::math::Almost0) ? 1. / pInv : o2::constants::math::VeryBig;
557+
const value_t pInv = getPInv();
558+
return (pInv > o2::constants::math::Almost0) ? 1.f / pInv : o2::constants::math::VeryBig;
557559
}
558560

559561
//____________________________________________________________
@@ -579,7 +581,7 @@ inline typename TrackParametrization<value_T>::value_t TrackParametrization<valu
579581
template <typename value_T>
580582
inline typename TrackParametrization<value_T>::value_t TrackParametrization<value_T>::getEta() const
581583
{
582-
return -std::log(std::tan(0.5 * getTheta()));
584+
return -std::log(std::tan(0.5f * getTheta()));
583585
}
584586

585587
#ifndef GPUCA_ALIGPUCODE //These functions clash with GPU code and are thus hidden
@@ -593,7 +595,7 @@ inline Point3D<typename TrackParametrization<value_T>::value_t> TrackParametriza
593595

594596
//_______________________________________________________
595597
template <typename value_T>
596-
inline void TrackParametrization<value_T>::getXYZGlo(std::array<value_t, 3>& xyz) const
598+
inline void TrackParametrization<value_T>::getXYZGlo(dim3_t& xyz) const
597599
{
598600
// track coordinates in lab frame
599601
xyz[0] = getX();

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
3030
using MatrixD5 = ROOT::Math::SMatrix<double, kNParams, kNParams, ROOT::Math::MatRepStd<double, kNParams, kNParams>>;
3131

3232
using typename TrackParametrization<value_T>::value_t;
33+
using typename TrackParametrization<value_T>::dim3_t;
34+
using typename TrackParametrization<value_T>::dim2_t;
35+
using typename TrackParametrization<value_T>::params_t;
3336

3437
static_assert(std::is_floating_point_v<value_t>);
3538

3639
public:
40+
using covMat_t = std::array<value_t, kCovMatSize>;
41+
3742
TrackParametrizationWithError();
38-
TrackParametrizationWithError(value_t x, value_t alpha, const std::array<value_t, kNParams>& par, const std::array<value_t, kCovMatSize>& cov, int charge = 1);
39-
TrackParametrizationWithError(const std::array<value_t, 3>& xyz, const std::array<value_t, 3>& pxpypz,
43+
TrackParametrizationWithError(value_t x, value_t alpha, const params_t& par, const std::array<value_t, kCovMatSize>& cov, int charge = 1);
44+
TrackParametrizationWithError(const dim3_t& xyz, const dim3_t& pxpypz,
4045
const std::array<value_t, kLabCovMatSize>& cv, int sign, bool sectorAlpha = true);
4146

4247
TrackParametrizationWithError(const TrackParametrizationWithError& src) = default;
@@ -64,7 +69,7 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
6469
value_t getCovarElem(int i, int j) const;
6570
value_t getDiagError2(int i) const;
6671

67-
bool getCovXYZPxPyPzGlo(std::array<value_t, 21>& c) const;
72+
bool getCovXYZPxPyPzGlo(std::array<value_t, kLabCovMatSize>& c) const;
6873

6974
#ifndef GPUCA_ALIGPUCODE
7075
void print() const;
@@ -74,11 +79,11 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
7479
// parameters + covmat manipulation
7580
bool rotate(value_t alpha);
7681
bool propagateTo(value_t xk, value_t b);
77-
bool propagateTo(value_t xk, const std::array<value_t, 3>& b);
82+
bool propagateTo(value_t xk, const dim3_t& b);
7883
bool propagateToDCA(const o2::dataformats::VertexBase& vtx, value_t b, o2::dataformats::DCA* dca = nullptr, value_t maxD = 999.f);
7984
void invert();
8085

81-
value_t getPredictedChi2(const std::array<value_t, 2>& p, const std::array<value_t, 3>& cov) const;
86+
value_t getPredictedChi2(const dim2_t& p, const dim3_t& cov) const;
8287

8388
template <typename T>
8489
value_t getPredictedChi2(const BaseCluster<T>& p) const;
@@ -89,7 +94,7 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
8994
value_t getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const;
9095
bool update(const TrackParametrizationWithError& rhs, const MatrixDSym5& covInv);
9196

92-
bool update(const std::array<value_t, 2>& p, const std::array<value_t, 3>& cov);
97+
bool update(const dim2_t& p, const dim3_t& cov);
9398

9499
template <typename T>
95100
bool update(const BaseCluster<T>& p);
@@ -119,7 +124,7 @@ inline TrackParametrizationWithError<value_T>::TrackParametrizationWithError() :
119124

120125
//__________________________________________________________________________
121126
template <typename value_T>
122-
inline TrackParametrizationWithError<value_T>::TrackParametrizationWithError(value_t x, value_t alpha, const std::array<value_t, kNParams>& par,
127+
inline TrackParametrizationWithError<value_T>::TrackParametrizationWithError(value_t x, value_t alpha, const params_t& par,
123128
const std::array<value_t, kCovMatSize>& cov, int charge)
124129
: TrackParametrization<value_T>{x, alpha, par, charge}
125130
{
@@ -258,8 +263,8 @@ template <typename value_T>
258263
template <typename T>
259264
typename TrackParametrizationWithError<value_T>::value_t TrackParametrizationWithError<value_T>::getPredictedChi2(const BaseCluster<T>& p) const
260265
{
261-
const std::array<value_t, 2> pyz = {p.getY(), p.getZ()};
262-
const std::array<value_t, 3> cov = {p.getSigmaY2(), p.getSigmaYZ(), p.getSigmaZ2()};
266+
const dim2_t pyz = {p.getY(), p.getZ()};
267+
const dim3_t cov = {p.getSigmaY2(), p.getSigmaYZ(), p.getSigmaZ2()};
263268
return getPredictedChi2(pyz, cov);
264269
}
265270

@@ -268,8 +273,8 @@ template <typename value_T>
268273
template <typename T>
269274
bool TrackParametrizationWithError<value_T>::update(const BaseCluster<T>& p)
270275
{
271-
const std::array<value_t, 2> pyz = {p.getY(), p.getZ()};
272-
const std::array<value_t, 3> cov = {p.getSigmaY2(), p.getSigmaYZ(), p.getSigmaZ2()};
276+
const dim2_t pyz = {p.getY(), p.getZ()};
277+
const dim3_t cov = {p.getSigmaY2(), p.getSigmaYZ(), p.getSigmaZ2()};
273278
return update(pyz, cov);
274279
}
275280

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackUtils.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ void g3helx3(value_T qfield, value_T step, std::array<value_T, 7>& vect)
7070
value_T tet = rho * step;
7171

7272
value_T tsint, sintt, sint, cos1t;
73-
if (fabs(tet) > 0.03f) {
74-
sint = sinf(tet);
73+
if (std::fabs(tet) > 0.03f) {
74+
sint = std::sin(tet);
7575
sintt = sint / tet;
7676
tsint = (tet - sint) / tet;
77-
value_T t = sinf(0.5f * tet);
77+
value_T t = std::sin(0.5f * tet);
7878
cos1t = 2 * t * t / tet;
7979
} else {
8080
tsint = tet * tet / 6.f;
@@ -126,15 +126,15 @@ value_T BetheBlochSolid(value_T bg, value_T rho, value_T kp1, value_T kp2, value
126126

127127
//*** Density effect
128128
value_T d2 = 0.;
129-
const value_T x = log(bg);
130-
const value_T lhwI = log(28.816 * 1e-9 * std::sqrt(rho * meanZA) / meanI);
129+
const value_T x = std::log(bg);
130+
const value_T lhwI = std::log(28.816f * 1e-9f * std::sqrt(rho * meanZA) / meanI);
131131
if (x > kp2) {
132-
d2 = lhwI + x - 0.5;
132+
d2 = lhwI + x - 0.5f;
133133
} else if (x > kp1) {
134134
double r = (kp2 - x) / (kp2 - kp1);
135-
d2 = lhwI + x - 0.5 + (0.5 - lhwI - kp1) * r * r * r;
135+
d2 = lhwI + x - 0.5f + (0.5f - lhwI - kp1) * r * r * r;
136136
}
137-
return mK * meanZA * (1 + bg2) / bg2 * (0.5 * log(2 * me * bg2 * maxT / (meanI * meanI)) - bg2 / (1 + bg2) - d2);
137+
return mK * meanZA * (1 + bg2) / bg2 * (0.5f * std::log(2 * me * bg2 * maxT / (meanI * meanI)) - bg2 / (1 + bg2) - d2);
138138
}
139139

140140
} // namespace track

0 commit comments

Comments
 (0)