9 #ifndef EVENTPRIMITIVES_AMGMATRIXBASEPLUGIN_H
10 #define EVENTPRIMITIVES_AMGMATRIXBASEPLUGIN_H
21 inline const PlainObject
unit()
const {
22 return (*this).normalized();
26 inline Scalar
mag()
const {
27 return (*this).norm();
31 inline Scalar
mag2()
const {
32 return (*this).squaredNorm();
37 constexpr
int size = Eigen::MatrixBase<Derived>::SizeAtCompileTime;
38 constexpr
int isVector = Eigen::MatrixBase<Derived>::IsVectorAtCompileTime;
39 static_assert(
isVector &&
size>=2,
"Method applicable for vectors of size >=2");
40 return ((*
this)[0] * (*
this)[0] + (*
this)[1] * (*
this)[1]);
44 inline Scalar
perp()
const {
45 constexpr
int size = Eigen::MatrixBase<Derived>::SizeAtCompileTime;
46 constexpr
int isVector = Eigen::MatrixBase<Derived>::IsVectorAtCompileTime;
47 static_assert(
isVector &&
size>=2,
"Method applicable for vectors of size >=2");
48 return std::sqrt(this->
perp2());
52 inline Scalar
perp2(
const MatrixBase<Derived>&
vec) {
55 Scalar
s = this->
dot(vec);
62 inline Scalar
perp(
const MatrixBase<Derived>&
vec) {
63 return std::sqrt(this->
perp2(vec));
67 inline Scalar
phi()
const {
68 constexpr
int size = Eigen::MatrixBase<Derived>::SizeAtCompileTime;
69 constexpr
int isVector = Eigen::MatrixBase<Derived>::IsVectorAtCompileTime;
70 static_assert(
isVector &&
size>=2,
"Method applicable for vectors of size >=2");
71 return std::atan2((*
this)[1], (*
this)[0]);
76 constexpr
int size = Eigen::MatrixBase<Derived>::SizeAtCompileTime;
77 constexpr
int isVector = Eigen::MatrixBase<Derived>::IsVectorAtCompileTime;
78 static_assert(
isVector &&
size>=3,
"Method applicable for vectors of size >=3");
79 return std::atan2(this->
perp(), (*
this)[2]);
83 inline Scalar
eta()
const {
84 constexpr
int size = Eigen::MatrixBase<Derived>::SizeAtCompileTime;
85 constexpr
int isVector = Eigen::MatrixBase<Derived>::IsVectorAtCompileTime;
86 static_assert(
isVector &&
size>=3,
"Method applicable for vectors of size >=3");
87 const Scalar
rho2 = (*this).x() * (*this).x() + (*this).y() * (*this).y();
88 const Scalar
z = (*this).z();
89 const Scalar z2 =
z *
z;
90 constexpr Scalar epsilon = 2. * std::numeric_limits<Scalar>::epsilon();
92 if (
rho2 > z2 * epsilon) {
93 const double m = std::sqrt(
rho2 + z2);
100 constexpr Scalar s_etaMax =
static_cast<Scalar
>(22756.0);
102 return (
z > 0) ?
z + s_etaMax :
z - s_etaMax;
105 inline Scalar
deltaR(
const MatrixBase<Derived>&
vec)
const {
107 double a = this->
eta() - vec.eta();
109 return std::sqrt(
a *
a +
b *
b);
114 double dphi =
vec.phi() - this->
phi();
117 }
else if (dphi <= -
M_PI) {
130 template <
typename OtherDerived>
131 inline Matrix<Scalar, OtherDerived::RowsAtCompileTime,
132 OtherDerived::RowsAtCompileTime>
134 return m * (this->derived() *
m.transpose());
138 template <
typename OtherDerived>
139 inline Matrix<Scalar, OtherDerived::RowsAtCompileTime,
140 OtherDerived::RowsAtCompileTime>
142 return m.transpose() * (this->derived() *
m);