Skip to content

Commit c659beb

Browse files
mpuccioMohammadAlTurany
authored andcommitted
Track interface adapted to use std::array
Track objects added to the dictionaries, CATracker adapted to the new interfaces. The GetParam() and GetCov() methods are now commented: when and if there is the necessity of them hopefully we shall see what is the best implementation. The explicit copy constructor of TrackPar has been removed: the compiler is able to implement it correctly and without that definition it is free to define also the operator= and the move constructor.
1 parent ad2746d commit c659beb

8 files changed

Lines changed: 90 additions & 88 deletions

File tree

Detectors/Base/include/DetectorsBase/Track.h

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ namespace AliceO2 {
2020
using namespace std;
2121

2222
// aliases for track elements
23-
enum {kY,kZ,kSnp,kTgl,kQ2Pt};
24-
enum {kSigY2,
23+
enum ParLabels : int {
24+
kY,kZ,kSnp,kTgl,kQ2Pt
25+
};
26+
enum CovLabels : int {
27+
kSigY2,
2528
kSigZY,kSigZ2,
2629
kSigSnpY,kSigSnpZ,kSigSnp2,
2730
kSigTglY,kSigTglZ,kSigTglSnp,kSigTgl2,
28-
kSigQ2PtY,kSigQ2PtZ,kSigQ2PtSnp,kSigQ2PtTgl,kSigQ2Pt2};
31+
kSigQ2PtY,kSigQ2PtZ,kSigQ2PtSnp,kSigQ2PtTgl,kSigQ2Pt2
32+
};
2933

3034
constexpr int
3135
kNParams=5,
@@ -43,13 +47,13 @@ namespace AliceO2 {
4347
// helper function
4448
float BetheBlochSolid(float bg, float rho=2.33f,float kp1=0.20f,float kp2=3.00f,
4549
float meanI=173e-9f,float meanZA=0.49848f);
46-
void g3helx3(float qfield, float step,float vect[7]);
50+
void g3helx3(float qfield, float step,array<float,7> &vect);
4751

4852

4953
class TrackParBase { // track parameterization, kinematics only. This base class cannot be instantiated
5054
public:
5155

52-
const float* GetParam() const { return mP; }
56+
///const float* GetParam() const { return mP; }
5357
float GetX() const { return mX; }
5458
float GetAlpha() const { return mAlpha; }
5559
float GetY() const { return mP[kY]; }
@@ -66,41 +70,41 @@ namespace AliceO2 {
6670

6771
float GetP() const;
6872
float GetPt() const;
69-
void GetXYZ(float xyz[3]) const;
70-
bool GetPxPyPz(float pxyz[3]) const;
71-
bool GetPosDir(float posdirp[9]) const;
73+
void GetXYZ(array<float,3> &xyz) const;
74+
bool GetPxPyPz(array<float,3> &pxyz) const;
75+
bool GetPosDir(array<float,9> &posdirp) const;
7276

7377
// parameters manipulation
7478
bool RotateParam(float alpha);
7579
bool PropagateParamTo(float xk, float b);
76-
bool PropagateParamTo(float xk, const float b[3]);
80+
bool PropagateParamTo(float xk, const array<float,3> &b);
7781
void InvertParam();
7882

7983
void PrintParam() const;
8084

8185
protected:
8286
// to keep this class non-virtual but derivable the c-tors and d-tor are protected
83-
TrackParBase() : mX{0.},mAlpha{0.},mP{0.f} {}
84-
TrackParBase(float x,float alpha, const float par[kNParams]);
85-
TrackParBase(const float xyz[3],const float pxpypz[3],int sign, bool sectorAlpha=true);
87+
TrackParBase() : mX{0.},mAlpha{0.} {}
88+
TrackParBase(float x,float alpha, const array<float,kNParams> &par);
89+
TrackParBase(const array<float,3> &xyz,const array<float,3> &pxpypz, int sign, bool sectorAlpha=true);
8690
TrackParBase(const TrackParBase&) = default;
8791
TrackParBase(TrackParBase&&) = default;
8892
TrackParBase& operator=(const TrackParBase& src) = default;
8993
~TrackParBase() = default;
9094
//
91-
float mX; /// X of track evaluation
92-
float mAlpha; /// track frame angle
93-
float mP[kNParams]; /// 5 parameters: Y,Z,sin(phi),tg(lambda),q/pT
95+
float mX; /// X of track evaluation
96+
float mAlpha; /// track frame angle
97+
float mP[kNParams] = {0.f}; /// 5 parameters: Y,Z,sin(phi),tg(lambda),q/pT
9498
};
9599

96100
// rootcint does not swallow final keyword here
97101
class TrackParCov final : public TrackParBase { // track+error parameterization
98102
public:
99-
TrackParCov() : TrackParBase{}, mC{0.f} { }
100-
TrackParCov(float x,float alpha, const float par[kNParams], const float cov[kCovMatSize]);
101-
TrackParCov(const float xyz[3],const float pxpypz[3],const float[kLabCovMatSize], int sign, bool sectorAlpha=true);
103+
TrackParCov() : TrackParBase{} { }
104+
TrackParCov(float x, float alpha, const array<float,kNParams> &par, const array<float,kCovMatSize> &cov);
105+
TrackParCov(const array<float,3> &xyz,const array<float,3> &pxpypz,const array<float,kLabCovMatSize> &cv, int sign, bool sectorAlpha=true);
102106

103-
const float* GetCov() const { return mC; }
107+
///const float* GetCov() const { return mC; }
104108
float GetSigmaY2() const { return mC[kSigY2]; }
105109
float GetSigmaZY() const { return mC[kSigZY]; }
106110
float GetSigmaZ2() const { return mC[kSigZ2]; }
@@ -122,40 +126,39 @@ namespace AliceO2 {
122126
// parameters + covmat manipulation
123127
bool Rotate(float alpha);
124128
bool PropagateTo(float xk, float b);
125-
bool PropagateTo(float xk, const float b[3]);
129+
bool PropagateTo(float xk, const array<float,3> &b);
126130
void Invert();
127131

128-
float GetPredictedChi2(const float p[2], const float cov[3]) const;
129-
bool Update(const float p[2], const float cov[3]);
132+
float GetPredictedChi2(const array<float,2> &p, const array<float,3> &cov) const;
133+
bool Update(const array<float,2> &p, const array<float,3> &cov);
130134

131135
bool CorrectForMaterial(float x2x0,float xrho,float mass,bool anglecorr=false,float dedx=kCalcdEdxAuto);
132136

133137
void ResetCovariance(float s2=0);
134138
void CheckCovariance();
135139

136140
protected:
137-
float mC[kCovMatSize]; // x, alpha + 5 parameters + 15 errors
141+
float mC[kCovMatSize] = {0.f}; // 15 covariance matrix elements
138142

139143
};
140144

141145
class TrackPar final : public TrackParBase { // track parameterization only
142146
public:
143147
TrackPar() {}
144-
TrackPar(float x,float alpha, const float par[kNParams]) : TrackParBase{x,alpha,par} {}
145-
TrackPar(const float xyz[3], const float pxpypz[3],int sign, bool sectorAlpha=true);
146-
TrackPar(const TrackParCov& src) : TrackParBase{static_cast<const TrackParBase&>(src)} {}
148+
TrackPar(float x,float alpha, const array<float,kNParams> &par) : TrackParBase{x,alpha,par} {}
149+
TrackPar(const array<float,3> &xyz, const array<float,3> &pxpypz,int sign, bool sectorAlpha=true);
147150
//
148151
void Print() const {PrintParam();}
149152
};
150153

151154
//____________________________________________________________
152-
inline TrackParBase::TrackParBase(float x, float alpha, const float par[kNParams]) : mX{x}, mAlpha{alpha} {
155+
inline TrackParBase::TrackParBase(float x, float alpha, const array<float, kNParams> &par) : mX{x}, mAlpha{alpha} {
153156
// explicit constructor
154-
std::copy(par, par + kNParams, mP);
157+
std::copy(par.begin(), par.end(), mP);
155158
}
156159

157160
//_______________________________________________________
158-
inline void TrackParBase::GetXYZ(float xyz[3]) const {
161+
inline void TrackParBase::GetXYZ(array<float,3> &xyz) const {
159162
// track coordinates in lab frame
160163
xyz[0] = GetX();
161164
xyz[1] = GetY();
@@ -187,16 +190,16 @@ namespace AliceO2 {
187190
//============================================================
188191

189192
//____________________________________________________________
190-
inline TrackParCov::TrackParCov(float x, float alpha, const float par[kNParams], const float cov[kCovMatSize])
193+
inline TrackParCov::TrackParCov(float x, float alpha, const array<float,kNParams> &par, const array<float,kCovMatSize> &cov)
191194
: TrackParBase{x,alpha,par} {
192195
// explicit constructor
193-
std::copy(cov, cov + kCovMatSize, mC);
196+
std::copy(cov.begin(), cov.end(), mC);
194197
}
195198

196199
//============================================================
197200

198201
//____________________________________________________________
199-
inline TrackPar::TrackPar(const float xyz[3], const float pxpypz[3],int sign, bool sectorAlpha)
202+
inline TrackPar::TrackPar(const array<float,3> &xyz, const array<float,3> &pxpypz,int sign, bool sectorAlpha)
200203
: TrackParBase{xyz,pxpypz,sign,sectorAlpha} {
201204
// explicit constructor
202205
}

Detectors/Base/include/DetectorsBase/Utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "DetectorsBase/Constants.h"
99
#include <math.h>
10+
#include <array>
11+
using std::array;
1012

1113
namespace AliceO2 {
1214
namespace Base {
@@ -42,7 +44,7 @@ namespace AliceO2 {
4244
c = cos(ang);
4345
}
4446

45-
inline void RotateZ(float *xy, float alpha) {
47+
inline void RotateZ(array<float,3> &xy, float alpha) {
4648
// transforms vector in tracking frame alpha to global frame
4749
float sn,cs, x=xy[0];
4850
sincosf(alpha,sn,cs);

Detectors/Base/src/BaseLinkDef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#pragma link off all functions;
77

88
#pragma link C++ class AliceO2::Base::Detector+;
9-
#pragma link C++ class AliceO2::Base::Track+;
9+
#pragma link C++ class AliceO2::Base::TrackPar+;
10+
#pragma link C++ class AliceO2::Base::TrackParCov+;
1011
#pragma link C++ class AliceO2::Base::TrackReference+;
1112

1213
#endif

Detectors/Base/src/Track.cxx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using namespace AliceO2::Base;
44

55
//______________________________________________________________
6-
Track::TrackParBase::TrackParBase(const float xyz[3],const float pxpypz[3], int charge, bool sectorAlpha) :
6+
Track::TrackParBase::TrackParBase(const array<float,3> &xyz,const array<float,3> &pxpypz, int charge, bool sectorAlpha) :
77
mX{0.f},mAlpha{0.f},mP{0.f}
88
{
99
// construct track param from kinematics
@@ -35,8 +35,8 @@ Track::TrackParBase::TrackParBase(const float xyz[3],const float pxpypz[3], int
3535
sincosf(alp,sn,cs);
3636
}
3737
// Get the vertex of origin and the momentum
38-
float ver[3] = {xyz[0],xyz[1],xyz[2]};
39-
float mom[3] = {pxpypz[0],pxpypz[1],pxpypz[2]};
38+
array<float,3> ver {xyz[0],xyz[1],xyz[2]};
39+
array<float,3> mom {pxpypz[0],pxpypz[1],pxpypz[2]};
4040
//
4141
// Rotate to the local coordinate system
4242
RotateZ(ver,-alp);
@@ -58,7 +58,7 @@ Track::TrackParBase::TrackParBase(const float xyz[3],const float pxpypz[3], int
5858

5959

6060
//_______________________________________________________
61-
bool Track::TrackParBase::GetPxPyPz(float pxyz[3]) const
61+
bool Track::TrackParBase::GetPxPyPz(array<float,3> &pxyz) const
6262
{
6363
// track momentum
6464
if (fabs(GetQ2Pt())<kAlmost0 || fabs(GetSnp())>kAlmost1) return false;
@@ -72,7 +72,7 @@ bool Track::TrackParBase::GetPxPyPz(float pxyz[3]) const
7272
}
7373

7474
//____________________________________________________
75-
bool Track::TrackParBase::GetPosDir(float posdirp[9]) const
75+
bool Track::TrackParBase::GetPosDir(array<float,9> &posdirp) const
7676
{
7777
// fill vector with lab x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha
7878
float ptI = fabs(GetQ2Pt());
@@ -133,7 +133,7 @@ bool Track::TrackParBase::RotateParam(float alpha)
133133

134134

135135
//____________________________________________________________
136-
bool Track::TrackParBase::PropagateParamTo(float xk, const float b[3])
136+
bool Track::TrackParBase::PropagateParamTo(float xk, const array<float,3> &b)
137137
{
138138
//----------------------------------------------------------------
139139
// Extrapolate this track params (w/o cov matrix) to the plane X=xk in the field b[].
@@ -163,7 +163,7 @@ bool Track::TrackParBase::PropagateParamTo(float xk, const float b[3])
163163
step *= sqrtf(1.f+ GetTgl()*GetTgl());
164164
//
165165
// Get the track x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha in the Global System
166-
float vecLab[9];
166+
array<float,9> vecLab {0.f};
167167
if (!GetPosDir(vecLab)) return false;
168168

169169
// Rotate to the system where Bx=By=0.
@@ -180,7 +180,7 @@ bool Track::TrackParBase::PropagateParamTo(float xk, const float b[3])
180180
costet=b[2]/bb;
181181
sintet=bt/bb;
182182
}
183-
float vect[7] = {
183+
array<float,7> vect{
184184
costet*cosphi*vecLab[0] + costet*sinphi*vecLab[1] - sintet*vecLab[2],
185185
-sinphi*vecLab[0] + cosphi*vecLab[1],
186186
sintet*cosphi*vecLab[0] + sintet*sinphi*vecLab[1] + costet*vecLab[2],
@@ -461,8 +461,8 @@ bool Track::TrackParCov::Rotate(float alpha)
461461

462462

463463
//______________________________________________________________
464-
Track::TrackParCov::TrackParCov(const float xyz[3],const float pxpypz[3],
465-
const float cv[kLabCovMatSize], int charge, bool sectorAlpha)
464+
Track::TrackParCov::TrackParCov(const array<float,3> &xyz,const array<float,3> &pxpypz,
465+
const array<float,kLabCovMatSize> &cv, int charge, bool sectorAlpha)
466466
{
467467
// construct track param and covariance from kinematics and lab errors
468468

@@ -493,8 +493,8 @@ Track::TrackParCov::TrackParCov(const float xyz[3],const float pxpypz[3],
493493
sincosf(alp,sn,cs);
494494
}
495495
// Get the vertex of origin and the momentum
496-
float ver[3] = {xyz[0],xyz[1],xyz[2]};
497-
float mom[3] = {pxpypz[0],pxpypz[1],pxpypz[2]};
496+
array<float,3> ver{xyz[0],xyz[1],xyz[2]};
497+
array<float,3> mom{pxpypz[0],pxpypz[1],pxpypz[2]};
498498
//
499499
// Rotate to the local coordinate system
500500
RotateZ(ver,-alp);
@@ -602,7 +602,7 @@ Track::TrackParCov::TrackParCov(const float xyz[3],const float pxpypz[3],
602602

603603

604604
//____________________________________________________________
605-
bool Track::TrackParCov::PropagateTo(float xk, const float b[3])
605+
bool Track::TrackParCov::PropagateTo(float xk, const array<float,3> &b)
606606
{
607607
//----------------------------------------------------------------
608608
// Extrapolate this track to the plane X=xk in the field b[].
@@ -632,7 +632,7 @@ bool Track::TrackParCov::PropagateTo(float xk, const float b[3])
632632
step *= sqrtf(1.f+ GetTgl()*GetTgl());
633633
//
634634
// Get the track x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha in the Global System
635-
float vecLab[9];
635+
array<float,9> vecLab{0.f};
636636
if (!GetPosDir(vecLab)) return false;
637637
//
638638
// matrix transformed with Bz component only
@@ -699,7 +699,7 @@ bool Track::TrackParCov::PropagateTo(float xk, const float b[3])
699699
costet=b[2]/bb;
700700
sintet=bt/bb;
701701
}
702-
float vect[7] = {
702+
array<float,7> vect{
703703
costet*cosphi*vecLab[0] + costet*sinphi*vecLab[1] - sintet*vecLab[2],
704704
-sinphi*vecLab[0] + cosphi*vecLab[1],
705705
sintet*cosphi*vecLab[0] + sintet*sinphi*vecLab[1] + costet*vecLab[2],
@@ -834,7 +834,7 @@ void Track::TrackParCov::ResetCovariance(float s2)
834834
}
835835

836836
//______________________________________________
837-
float Track::TrackParCov::GetPredictedChi2(const float p[2], const float cov[3]) const
837+
float Track::TrackParCov::GetPredictedChi2(const array<float,2> &p, const array<float,3> &cov) const
838838
{
839839
// Estimate the chi2 of the space point "p" with the cov. matrix "cov"
840840
float sdd = GetSigmaY2() + cov[0];
@@ -851,7 +851,7 @@ float Track::TrackParCov::GetPredictedChi2(const float p[2], const float cov[3])
851851

852852
}
853853

854-
bool Track::TrackParCov::Update(const float p[2], const float cov[3])
854+
bool Track::TrackParCov::Update(const array<float,2> &p, const array<float,3> &cov)
855855
{
856856
// Update the track parameters with the space point "p" having
857857
// the covariance matrix "cov"
@@ -1033,7 +1033,7 @@ void Track::TrackParCov::Print() const
10331033
//
10341034
//=================================================
10351035

1036-
void Track::g3helx3(float qfield, float step,float vect[7])
1036+
void Track::g3helx3(float qfield, float step,array<float,7> &vect)
10371037
{
10381038
/******************************************************************
10391039
* *

Detectors/ITSMFT/ITS/reconstruction/include/ITSReconstruction/CATracker.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#define ALIITSUCATRACKER_H
1111

1212
#include <vector>
13+
#include <array>
1314

1415
#include "ITSReconstruction/CAaux.h"
1516
#include "ITSReconstruction/CATrackingStation.h"
1617
#include "DetectorsBase/Track.h"
1718

1819
using std::vector;
20+
using std::array;
1921

2022
namespace AliceO2 {
2123
namespace ITS {
@@ -47,7 +49,7 @@ namespace AliceO2 {
4749
Tracker(const Tracker&);
4850
Tracker &operator=(const Tracker &tr);
4951
//
50-
bool CellParams(int l, Cluster* c1, Cluster* c2, Cluster* c3, float &curv, float np[3]);
52+
bool CellParams(int l, Cluster* c1, Cluster* c2, Cluster* c3, float &curv, array<float,3> &np);
5153
void CellsTreeTraversal(vector<Road> &roads, const int &iD, const int &doubl);
5254
void FindTracksCA(int iteration);
5355
void MakeCells(int iteration);

0 commit comments

Comments
 (0)