Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eicd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIC
eicd
Commits
f2d83250
Commit
f2d83250
authored
Feb 22, 2022
by
Sylvester Joosten
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Move closer to EDM4hep (part 2)"
parent
f184edc8
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!75
Resolve "Move closer to EDM4hep (part 2)"
Pipeline
#28234
failed
Feb 22, 2022
Stage: config
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
eic_data.yaml
+58
-138
58 additions, 138 deletions
eic_data.yaml
utils/include/eicd/vector_utils.h
+40
-18
40 additions, 18 deletions
utils/include/eicd/vector_utils.h
with
98 additions
and
156 deletions
eic_data.yaml
+
58
−
138
View file @
f2d83250
...
...
@@ -45,39 +45,6 @@ components:
explicit
operator
bool()
const
{return
valid();}
"
## simple weight that defaults to 1 if not set
eic::Weight
:
Members
:
-
float value
ExtraCode
:
declaration
:
"
Weight()
:
value{1.}
{}
\n
Weight(double
w)
:
value
{static_cast<float>(w)}
{}
\n
Weight&
operator=(double
w)
{value
=
static_cast<float>(w);
return
*this;}
\n
operator
float()
const
{return
value;}
"
eic::VectorXY
:
Members
:
-
float x // [mm] or [GeV]
-
float y //
ExtraCode
:
includes
:
"
#include
<cmath>
\n
"
declaration
:
"
VectorXY()
:
x{0},
y{0}
{}
\n
VectorXY(double
xx,
double
yy)
:
x{static_cast<float>(xx)},
y{static_cast<float>(yy)}
{}
\n
float&
operator[](unsigned
i)
{return
*(&x
+
i);}
\n
const
float&
operator[](unsigned
i)
const
{return
*(&x
+
i);}
\n
float
mag()
const
{return
std::hypot(x,
y);}
\n
float
r()
const
{return
mag();}
\n
float
phi()
const
{return
atan2(y,
x);}
\n
operator
std::pair<float,
float>()
const
{return
{x,
y};}
\n
float
dot(const
VectorXY&
rhs)
const
{return
x*rhs.x
+
y*rhs.y;}
\n
VectorXY
add(const
VectorXY&
rhs)
const
{return
{x+rhs.x,
y+rhs.y};}
\n
VectorXY
subtract(const
VectorXY&
rhs)
const
{return
{x-rhs.x,
y-rhs.y};}
\n
VectorXY
scale(double
f)
const
{return
{f*x,
f*y};}
\n
"
# Copy from EDM4hep with conversion operators added
# TODO: uncomment Vector2f conversions when we migrate to new EDM4hep version
eicd::Vector2f
:
...
...
@@ -117,94 +84,47 @@ components:
includes
:
"
#include
<edm4hep/Vector3f.h>
\n
"
eic::Vector
XYZ
:
# Copy from EDM4hep with conversion operators added
eic
d
::Vector
3d
:
Members
:
-
float x // [mm] or [GeV]
-
float y //
-
float z //
-
double x
-
double y
-
double z
ExtraCode
:
includes
:
"
#include
<cmath>
\n
#include<tuple>"
declaration
:
"
VectorXYZ()
:
x{0},
y{0},
z{0}
{}
\n
VectorXYZ(double
xx,
double
yy,
double
zz)
:
x{static_cast<float>(xx)},
y{static_cast<float>(yy)},
z{static_cast<float>(zz)}
{}
\n
template
<class
V>
VectorXYZ(const
V&
v)
:
x{v.x},
y{v.y},
z{v.z}
{}
\n
float&
operator[](unsigned
i)
{return
*(&x
+
i);}
\n
const
float&
operator[](unsigned
i)
const
{return
*(&x
+
i);}
\n
float
mag()
const
{return
std::hypot(x,
y,
z);}
\n
float
r()
const
{return
mag();}
\n
float
theta()
const
{return
acos(z/mag());}
\n
float
phi()
const
{return
atan2(y,x);}
\n
float
eta()
const
{return
-log(tan(0.5*theta()));}
\n
operator
std::tuple<float,
float,
float>()
{return
{x,
y,
z};}
\n
float
dot(const
VectorXYZ&
rhs)
const
{return
x*rhs.x
+
y*rhs.y
+
z*rhs.z;}
\n
VectorXYZ
add(const
VectorXYZ&
rhs)
const
{return
{x+rhs.x,
y+rhs.y,
z+rhs.z};}
\n
VectorXYZ
subtract(const
VectorXYZ&
rhs)
const
{return
{x-rhs.x,
y-rhs.y,
z-rhs.z};}
\n
VectorXYZ
scale(double
f)
const
{return
{f*x,
f*y,
f*z};}
\n
Vector3d()
:
x(0),y(0),z(0)
{}
\n
Vector3d(double
xx,
double
yy,
double
zz)
:
x(xx),y(yy),z(zz)
{}
\n
Vector3d(const
double*
v)
:
x(v[0]),y(v[1]),z(v[2])
{}
\n
bool
operator==(const
Vector3d&
v)
const
{
return
(x==v.x&&y==v.y&&z==v.z)
;
}
\n
double
operator[](unsigned
i)
const
{
return
*(
&x
+
i
)
;
}
\n
Vector3d(const
edm4hep::Vector3d&
v)
:
x{v.x},
y{v.y},
z{v.z}
{}
operator
edm4hep::Vector3d()
const
{return
{x,
y,
z};}
\n
"
eic::VectorXYZT
:
Members
:
-
double x // [mm] or [GeV]
-
double y //
-
double z //
-
double t // [ns] or [GeV]
ExtraCode
:
includes
:
"
#include
<cmath>
\n
#include
<tuple>"
declaration
:
"
VectorXYZT()
:
x{0},
y{0},
z{0},
t{0}
{}
\n
VectorXYZT(double
xx,
double
yy,
double
zz,
double
tt)
:
x{xx},
y{yy},
z{zz},
t{tt}
{}
\n
double&
operator[](unsigned
i)
{return
*(&x
+
i);}
\n
const
double&
operator[](unsigned
i)
const
{return
*(&x
+
i);}
\n
double
mag()
const
{return
std::hypot(x,
y,
z);}
\n
double
r()
const
{return
mag();}
\n
double
theta()
const
{return
acos(z/mag());}
\n
double
phi()
const
{return
atan2(y,x);}
\n
double
eta()
const
{return
-log(tan(0.5*theta()));}
double
energy()
const
{return
t;}
\n
double
mass()
const
{return
sqrt(t*t
-
x*x
-
y*y
-
z*z);}
\n
operator
std::tuple<double,
double,
double,
double>()
{return
{x,
y,
z,
t};}
\n
double
dot(const
VectorXYZT&
rhs)
const
{return
t*rhs.t
-
x*rhs.x
-
y*rhs.y
-
z*rhs.z;}
\n
VectorXYZT
add(const
VectorXYZT&
rhs)
const
{return
{x+rhs.x,
y+rhs.y,
z+rhs.z,
t+rhs.t};}
\n
VectorXYZT
subtract(const
VectorXYZT&
rhs)
const
{return
{x-rhs.x,
y-rhs.y,
z-rhs.z,
t-rhs.t};}
\n
VectorXYZT
scale(double
f)
const
{return
{f*x,
f*y,
f*z,
f*t};}
\n
includes
:
"
#include
<edm4hep/Vector3d.h>
\n
"
eic::CovDiag
XYZ
:
eic
d
::CovDiag
3f
:
Members
:
-
float xx
-
float yy
-
float zz
ExtraCode
:
declaration
:
"
CovDiag
XYZ
()
:
xx{0},
yy{0},
zz{0}
{}
\n
CovDiag
XYZ
(double
x,
double
y,
double
z)
:
xx{static_cast<float>(x)},
yy{static_cast<float>(y)},
zz{static_cast<float>(z)}
{}
\n
CovDiag
3f
()
:
xx{0},
yy{0},
zz{0}
{}
\n
CovDiag
3f
(double
x,
double
y,
double
z)
:
xx{static_cast<float>(x)},
yy{static_cast<float>(y)},
zz{static_cast<float>(z)}
{}
\n
float
operator()(unsigned
i,
unsigned
j)
const
{return
(i
==
j)
?
*(&xx
+
i)
:
0.;}
\n
"
eic::CovDiagXYZT
:
Members
:
-
double xx
-
double yy
-
double zz
-
double tt
ExtraCode
:
declaration
:
"
CovDiagXYZT()
:
xx{0},
yy{0},
zz{0},
tt{0}
{}
\n
CovDiagXYZT(double
x,
double
y,
double
z,
double
t)
:
xx{x},
yy{y},
zz{z},
tt{t}
{}
\n
double
operator()(unsigned
i,
unsigned
j)
const
{return
(i
==
j)
?
*(&xx
+
i)
:
0.;}
\n
"
eic::CovXY
:
eicd::Cov2f
:
Members
:
-
float xx
-
float yy
-
float xy
ExtraCode
:
declaration
:
"
Cov
XY
()
:
xx{0},
yy{0},
xy{0}
{}
\n
Cov
XY
(double
vx,
double
vy,
double
vxy
=
0)
\n
Cov
2f
()
:
xx{0},
yy{0},
xy{0}
{}
\n
Cov
2f
(double
vx,
double
vy,
double
vxy
=
0)
\n
:
xx{static_cast<float>(vx)},
yy{static_cast<float>(vy)},
xy{static_cast<float>(vxy)}
{}
\n
float
operator()(unsigned
i,
unsigned
j)
const
{
\n
//
diagonal
\n
...
...
@@ -222,9 +142,9 @@ components:
Members
:
-
eic::Index ID // ID of the hit
-
uint32_t index // Raw index of the hit in the relevant array
-
eic::Weight
weight // weight of the hit
-
float
weight // weight of the hit
eic::Cov
XYZ
:
eic
d
::Cov
3f
:
Members
:
-
float xx
-
float yy
...
...
@@ -234,12 +154,12 @@ components:
-
float yz
ExtraCode
:
declaration
:
"
Cov
XYZ
()
:
xx{0},
yy{0},
zz{0},
xy{0},
xz{0},
yz{0}
{}
\n
Cov
XYZ
(double
vx,
double
vy,
double
vz,
double
vxy,
double
vxz,
double
vyz)
\n
Cov
3f
()
:
xx{0},
yy{0},
zz{0},
xy{0},
xz{0},
yz{0}
{}
\n
Cov
3f
(double
vx,
double
vy,
double
vz,
double
vxy,
double
vxz,
double
vyz)
\n
:
xx{static_cast<float>(vx)},
yy{static_cast<float>(vy)},
zz{static_cast<float>(vz)},
\n
xy{static_cast<float>(vxy)},
xz{static_cast<float>(vxz)},
yz{static_cast<float>(vyz)}
{}
\n
Cov
XYZ
(double
vx,
double
vy,
double
vz)
\n
:
Cov
XYZ
(vx,
vy,
vz,
0,
0,
0)
{}
\n
Cov
3f
(double
vx,
double
vy,
double
vz)
\n
:
Cov
3f
(vx,
vy,
vz,
0,
0,
0)
{}
\n
float
operator()(unsigned
i,
unsigned
j)
const
{
\n
//
diagonal
\n
if
(i
==
j)
{
\n
...
...
@@ -255,15 +175,15 @@ components:
## A point along a track
eic::TrackPoint
:
Members
:
-
eic::Vector
XYZ
position // Position of the trajectory point [mm]
-
eic::Cov
XYZ
positionError // Error on the position
-
eic::Vector
XYZ
momentum // 3-momentum at the point [GeV]
-
eic::Cov
XYZ
momentumError // Error on the 3-momentum
-
eic
d
::Vector
3f
position // Position of the trajectory point [mm]
-
eic
d
::Cov
3f
positionError // Error on the position
-
eic
d
::Vector
3f
momentum // 3-momentum at the point [GeV]
-
eic
d
::Cov
3f
momentumError // Error on the 3-momentum
-
float time // Time at this point [ns]
-
float timeError // Error on the time at this point
-
float theta // polar direction of the track at the surface [rad]
-
float phi // azimuthal direction of the track at the surface [rad]
-
eic::Cov
XY
directionError // Error on the polar and azimuthal angles
-
eic
d
::Cov
2f
directionError // Error on the polar and azimuthal angles
-
float pathlength // Pathlength from the origin to this point
-
float pathlengthError // Error on the pathlenght
...
...
@@ -282,7 +202,7 @@ datatypes:
-
int32_t type // Event type identifier (TBD).
-
int32_t proc // Process identifier (TBD).
-
int32_t source // Source/identifier (TBD)
-
eic::Weight
weight // Optional event weight (useful for MC)
-
float
weight // Optional event weight (useful for MC)
## ==========================================================================
...
...
@@ -295,25 +215,25 @@ datatypes:
Members
:
-
eic::Index ID // Unique particle index
-
eicd::Vector3f p // Momentum [GeV]
-
eicd::Vector3
f
v // Vertex [mm]
-
eicd::Vector3
d
v // Vertex [mm]
-
float time // Time in [ns]
-
int32_t pid // Particle PDG code
-
int16_t status // Status code
-
int16_t charge // Particle charge (or sign)
-
eic::Weight
weight // Particle weight, e.g. from PID algorithm [0-1]
-
float
weight // Particle weight, e.g. from PID algorithm [0-1]
eic::ReconstructedParticle
:
Description
:
"
EIC
Reconstructed
Particle"
Author
:
"
W.
Armstrong,
S.
Joosten"
Members
:
-
eic::Index ID // Unique particle index
-
eic::Vector
XYZ
p // Momentum vector [GeV]
-
eic::Vector
XYZ
v // Vertex [mm]
-
eic
d
::Vector
3f
p // Momentum vector [GeV]
-
eic
d
::Vector
3d
v // Vertex [mm]
-
float time // Time in [ns]
-
int32_t pid // PID of reconstructed particle.
-
int16_t status // Status code
-
int16_t charge // Particle charge (or sign)
-
eic::Weight
weight // Particle weight, e.g. from PID algorithm [0-1]
-
float
weight // Particle weight, e.g. from PID algorithm [0-1]
-
float theta // Polar angle of this particle [rad]
-
float phi // Azimuthal angle of this particle [rad]
-
float momentum // particle 3-momentum magnitude [GeV]
...
...
@@ -347,11 +267,11 @@ datatypes:
-
float energyError // Error on energy [GeV].
-
float time // The time of the hit in [ns].
-
float timeError // Error on the time
-
eic::Vector
XYZ
position // The global position of the hit in world coordinates [mm].
-
eic::Vector
XYZ
dimension // The dimension information of the cell [mm].
-
eic
d
::Vector
3f
position // The global position of the hit in world coordinates [mm].
-
eic
d
::Vector
3f
dimension // The dimension information of the cell [mm].
-
int32_t sector // Sector that this hit occured in
-
int32_t layer // Layer that the hit occured in
-
eic::Vector
XYZ
local // The local coordinates of the hit in the detector segment [mm].
-
eic
d
::Vector
3f
local // The local coordinates of the hit in the detector segment [mm].
## ==========================================================================
## Clustering
...
...
@@ -376,11 +296,11 @@ datatypes:
-
float time // [ns]
-
float timeError // Error on the cluster time
-
uint32_t nhits // Number of hits in the cluster.
-
eic::Vector
XYZ
position // Global position of the cluster [mm].
-
eic::Cov
XYZ
positionError // Covariance matrix of the position (6 Parameters).
-
eic
d
::Vector
3f
position // Global position of the cluster [mm].
-
eic
d
::Cov
3f
positionError // Covariance matrix of the position (6 Parameters).
-
float intrinsicTheta // Intrinsic cluster propagation direction polar angle [rad]
-
float intrinsicPhi // Intrinsic cluster propagation direction azimuthal angle [rad]
-
eic::Cov
XY
intrinsicDirectionError // Error on the intrinsic cluster propagation direction
-
eic
d
::Cov
2f
intrinsicDirectionError // Error on the intrinsic cluster propagation direction
VectorMembers
:
-
float shapeParameters // Should be set in metadata, for now radius/skewness
-
float hitContributions // Energy contributions of the hits. Runs parallel to ::hits()
...
...
@@ -412,9 +332,9 @@ datatypes:
-
float npe // Estimated number of photo-electrons [#]
-
float time // Time [ns]
-
float timeError // Error on the time [ns]
-
eic::Vector
XYZ
position // PMT hit position [mm]
-
eic::Vector
XYZ
local // The local position of the hit in detector coordinates [mm]
-
eic::Vector
XYZ
dimension // The dimension information of the pixel [mm].
-
eic
d
::Vector
3f
position // PMT hit position [mm]
-
eic
d
::Vector
3f
local // The local position of the hit in detector coordinates [mm]
-
eic
d
::Vector
3f
dimension // The dimension information of the pixel [mm].
eic::RingImage
:
Description
:
"
EIC
Ring
Image
Cluster"
...
...
@@ -422,8 +342,8 @@ datatypes:
Members
:
-
eic::Index ID // Unique cluster ID
-
float npe // Number of photo-electrons [#]
-
eic::Vector
XYZ
position // Global position of the cluster [mm]
-
eic::Vector
XYZ
positionError // Error on the position
-
eic
d
::Vector
3f
position // Global position of the cluster [mm]
-
eic
d
::Vector
3f
positionError // Error on the position
-
float theta // Opening angle of the ring [rad, 0->pi]
-
float thetaError // Error on the opening angle
-
float radius // Radius of the best fit ring [mm]
...
...
@@ -448,8 +368,8 @@ datatypes:
Members
:
-
eic::Index ID // Unique hit ID, same as one of the involved raw hits.
-
uint64_t cellID // The detector specific (geometrical) cell id.
-
eic::Vector
XYZ
position // Hit (cell) position and time [mm, ns]
-
eic::CovDiag
XYZ
positionError // Covariance Matrix
-
eic
d
::Vector
3f
position // Hit (cell) position and time [mm, ns]
-
eic
d
::CovDiag
3f
positionError // Covariance Matrix
-
float time // Hit time
-
float timeError // Error on the time
-
float edep // Energy deposit in this hit [GeV]
...
...
@@ -464,7 +384,7 @@ datatypes:
## Members:
## eic::Index ID // Unique identifier
## eic::Index seedID // Index of corresponding initial track parameters
##
eic::Weight
weight // prototrack weight, in case we share pixels [0-1]
##
float
weight // prototrack weight, in case we share pixels [0-1]
## VectorMembers:
## int32_t hits // tracker hit indicies
...
...
@@ -492,12 +412,12 @@ datatypes:
Author
:
"
W.
Armstrong,
S.
Joosten"
Members
:
-
int32_t type // Type of track parameters (-1/seed, 0/head, ...)
-
eic::Vector
XY
loc // 2D location on surface
-
eic::Cov
XY
locError // Covariance on loc
-
eic
d
::Vector
2f
loc // 2D location on surface
-
eic
d
::Cov
2f
locError // Covariance on loc
-
float theta // Track polar angle [rad]
-
float phi // Track azimuthal angle [rad]
-
float qOverP // [e/GeV]
-
eic::Cov
XYZ
momentumError // Covariance on theta, phi and qOverP
-
eic
d
::Cov
3f
momentumError // Covariance on theta, phi and qOverP
-
float time // Track time [ns]
-
float timeError // Error on the time
-
float charge // Particle charge
...
...
@@ -511,8 +431,8 @@ datatypes:
-
int32_t type // Flag that defines the type of track
-
float chi2 // Total chi2 (sum) of the track fit
-
int32_t ndf // Numbers of degrees of freedom of the track fit
-
eic::Vector
XYZ
momentum // Track 3-momentum at the vertex [GeV]
-
eic::Cov
XYZ
momentumError // Covariance matrix on the momentum
-
eic
d
::Vector
3f
momentum // Track 3-momentum at the vertex [GeV]
-
eic
d
::Cov
3f
momentumError // Covariance matrix on the momentum
-
float time // Track time at the vertex [ns]
-
float timeError // Error on the track vertex time
-
float charge // Particle charge
...
...
@@ -541,7 +461,7 @@ datatypes:
Author
:
"
W.
Armstrong,
S.
Joosten"
Members
:
-
eic::Index ID // Unique vertex ID
-
eic::Vector
XYZ
position // Postion of vertex [mm]
-
eic
d
::Vector
3f
position // Postion of vertex [mm]
-
float time // Time of vertex [ns]
-
float chi2 // Chi squared of the vertex fit.
-
float probability // Probability of the vertex fit
...
...
This diff is collapsed.
Click to expand it.
utils/include/eicd/vector_utils.h
+
40
−
18
View file @
f2d83250
...
...
@@ -21,14 +21,21 @@ namespace eicd {
template
<
class
V
>
concept
VectorHasX
=
requires
(
V
v
)
{
v
.
x
;
};
template
<
class
V
>
concept
VectorHasY
=
requires
(
V
v
)
{
v
.
y
;
};
template
<
class
V
>
concept
VectorHasZ
=
requires
(
V
v
)
{
v
.
z
;
};
template
<
class
V
>
concept
VectorHasA
=
requires
(
V
v
)
{
v
.
a
;
};
template
<
class
V
>
concept
VectorHasB
=
requires
(
V
v
)
{
v
.
b
;
};
template
<
class
V
>
concept
ClassVector
=
requires
(
V
v
)
{
v
.
x
();
};
template
<
class
V
>
concept
Vector2D
=
concept
Vector2D
_XY
=
VectorHasX
<
V
>&&
VectorHasY
<
V
>
&&
!
VectorHasZ
<
V
>
&&
!
ClassVector
<
V
>
;
template
<
class
V
>
concept
Vector2D_AB
=
VectorHasA
<
V
>&&
VectorHasB
<
V
>
&&
!
VectorHasZ
<
V
>
&&
!
ClassVector
<
V
>
;
template
<
class
V
>
concept
Vector2D
=
Vector2D_XY
<
V
>
||
Vector2D_AB
<
V
>
;
template
<
class
V
>
concept
Vector3D
=
VectorHasX
<
V
>&&
VectorHasY
<
V
>&&
VectorHasZ
<
V
>
&&
!
ClassVector
<
V
>
;
template
<
class
V
>
concept
VectorND
=
Vector2D
<
V
>
||
Vector3D
<
V
>
;
template
<
class
V
>
concept
VectorND_XYZ
=
Vector2D_XY
<
V
>
||
Vector3D
<
V
>
;
inline
double
etaToAngle
(
const
double
eta
)
{
return
std
::
atan
(
std
::
exp
(
-
eta
))
*
2.
;
...
...
@@ -37,13 +44,20 @@ inline double angleToEta(const double theta) {
return
-
std
::
log
(
std
::
tan
(
0.5
*
theta
));
}
// Utility getters to accomodate different vector types
template
<
VectorND_XYZ
V
>
auto
vector_x
(
const
V
&
v
)
{
return
v
.
x
;
}
template
<
VectorND_XYZ
V
>
auto
vector_y
(
const
V
&
v
)
{
return
v
.
y
;
}
template
<
Vector3D
V
>
auto
vector_z
(
const
V
&
v
)
{
return
v
.
z
;
}
template
<
Vector2D_AB
V
>
auto
vector_x
(
const
V
&
v
)
{
return
v
.
a
;
}
template
<
Vector2D_AB
V
>
auto
vector_y
(
const
V
&
v
)
{
return
v
.
b
;
}
// inline edm4hep::Vector2f VectorFromPolar(const double r, const double theta)
// {
// return {r * sin(theta), r * cos(theta)};
//}
template
<
Vector3D
V
=
edm4hep
::
Vector3f
>
V
sphericalToVector
(
const
double
r
,
const
double
theta
,
const
double
phi
)
{
using
FloatType
=
decltype
(
V
()
.
x
);
using
FloatType
=
decltype
(
vector_x
(
V
()
)
);
const
double
sth
=
sin
(
theta
);
const
double
cth
=
cos
(
theta
);
const
double
sph
=
sin
(
phi
);
...
...
@@ -55,24 +69,26 @@ V sphericalToVector(const double r, const double theta, const double phi) {
}
template
<
Vector3D
V
>
double
anglePolar
(
const
V
&
v
)
{
return
std
::
atan2
(
std
::
hypot
(
v
.
x
,
v
.
y
),
v
.
z
);
return
std
::
atan2
(
std
::
hypot
(
v
ector_x
(
v
),
vector_y
(
v
)),
vector_z
(
v
)
);
}
template
<
VectorND
V
>
double
angleAzimuthal
(
const
V
&
v
)
{
return
std
::
atan2
(
v
.
y
,
v
.
x
);
return
std
::
atan2
(
v
ector_y
(
v
),
vector_x
(
v
)
);
}
template
<
Vector3D
V
>
double
eta
(
const
V
&
v
)
{
return
angleToEta
(
anglePolar
(
v
));
}
template
<
Vector2D
V
>
double
magnitude
(
const
V
&
v
)
{
return
std
::
hypot
(
v
.
x
,
v
.
y
);
return
std
::
hypot
(
v
ector_x
(
v
),
vector_y
(
v
)
);
}
template
<
Vector3D
V
>
double
magnitude
(
const
V
&
v
)
{
return
std
::
hypot
(
v
.
x
,
v
.
y
,
v
.
z
);
return
std
::
hypot
(
v
ector_x
(
v
),
vector_y
(
v
),
vector_z
(
v
)
);
}
template
<
Vector3D
V
>
double
magnitudeTransverse
(
const
V
&
v
)
{
return
std
::
hypot
(
v
.
x
,
v
.
y
);
return
std
::
hypot
(
vector_x
(
v
),
vector_y
(
v
));
}
template
<
Vector3D
V
>
double
magnitudeLongitudinal
(
const
V
&
v
)
{
return
vector_z
(
v
);
}
template
<
Vector3D
V
>
double
magnitudeLongitudinal
(
const
V
&
v
)
{
return
v
.
z
;
}
template
<
VectorND
V
>
V
normalizeVector
(
const
V
&
v
,
double
norm
=
1.
)
{
const
double
old
=
magnitude
(
v
);
if
(
old
==
0
)
{
...
...
@@ -80,8 +96,12 @@ template <VectorND V> V normalizeVector(const V& v, double norm = 1.) {
}
return
(
norm
>
0
)
?
v
*
norm
/
old
:
v
*
0
;
}
template
<
Vector3D
V
>
V
vectorTransverse
(
const
V
&
v
)
{
return
{
v
.
x
,
v
.
y
,
0
};
}
template
<
Vector3D
V
>
V
vectorLongitudinal
(
const
V
&
v
)
{
return
{
0
,
0
,
v
.
z
};
}
template
<
Vector3D
V
>
V
vectorTransverse
(
const
V
&
v
)
{
return
{
vector_x
(
v
),
vector_y
(
v
),
0
};
}
template
<
Vector3D
V
>
V
vectorLongitudinal
(
const
V
&
v
)
{
return
{
0
,
0
,
vector_z
(
v
)};
}
// Two vector functions
template
<
VectorND
V
>
double
angleBetween
(
const
V
&
v1
,
const
V
&
v2
)
{
const
double
dot
=
v1
*
v2
;
...
...
@@ -101,28 +121,30 @@ template <Vector3D V> double projection(const V& v, const V& v1) {
}
// namespace eicd
template
<
eicd
::
Vector2D
V
>
V
operator
+
(
const
V
&
v1
,
const
V
&
v2
)
{
return
{
v
1
.
x
+
v2
.
x
,
v1
.
y
+
v2
.
y
};
return
{
v
ector_x
(
v1
)
+
vector_x
(
v2
),
vector_y
(
v1
)
+
vector_y
(
v2
)
};
}
template
<
eicd
::
Vector3D
V
>
V
operator
+
(
const
V
&
v1
,
const
V
&
v2
)
{
return
{
v1
.
x
+
v2
.
x
,
v1
.
y
+
v2
.
y
,
v1
.
z
+
v2
.
z
};
return
{
vector_x
(
v1
)
+
vector_x
(
v2
),
vector_y
(
v1
)
+
vector_y
(
v2
),
vector_z
(
v1
)
+
vector_z
(
v2
)};
}
template
<
eicd
::
Vector2D
V
>
double
operator
*
(
const
V
&
v1
,
const
V
&
v2
)
{
return
v
1
.
x
*
v2
.
x
+
v1
.
y
*
v2
.
y
;
return
v
ector_x
(
v1
)
*
vector_x
(
v2
)
+
vector_y
(
v1
)
*
vector_y
(
v2
)
;
}
template
<
eicd
::
Vector3D
V
>
double
operator
*
(
const
V
&
v1
,
const
V
&
v2
)
{
return
v1
.
x
*
v2
.
x
+
v1
.
y
*
v2
.
y
+
v1
.
z
*
v2
.
z
;
return
vector_x
(
v1
)
*
vector_x
(
v2
)
+
vector_y
(
v1
)
*
vector_y
(
v2
)
+
vector_z
(
v1
)
*
vector_z
(
v2
);
}
template
<
eicd
::
Vector2D
V
>
V
operator
*
(
const
double
d
,
const
V
&
v
)
{
return
{
d
*
v
.
x
,
d
*
v
.
y
};
return
{
d
*
v
ector_x
(
v
),
d
*
vector_y
(
v
)
};
}
template
<
eicd
::
Vector3D
V
>
V
operator
*
(
const
double
d
,
const
V
&
v
)
{
return
{
d
*
v
.
x
,
d
*
v
.
y
,
d
*
v
.
z
};
return
{
d
*
v
ector_x
(
v
),
d
*
vector_y
(
v
),
d
*
vector_z
(
v
)
};
}
template
<
eicd
::
Vector2D
V
>
V
operator
*
(
const
V
&
v
,
const
double
d
)
{
return
{
d
*
v
.
x
,
d
*
v
.
y
};
return
{
d
*
v
ector_x
(
v
),
d
*
vector_y
(
v
)
};
}
template
<
eicd
::
Vector3D
V
>
V
operator
*
(
const
V
&
v
,
const
double
d
)
{
return
{
d
*
v
.
x
,
d
*
v
.
y
,
d
*
v
.
z
};
return
{
d
*
v
ector_x
(
v
),
d
*
vector_y
(
v
),
d
*
vector_z
(
v
)
};
}
template
<
eicd
::
VectorND
V
>
V
operator
-
(
const
V
&
v1
,
const
V
&
v2
)
{
return
v1
+
(
-
1.
*
v2
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment