29 #define ACTS_CHECK_BIT(value, mask) ((value & mask) == mask)
50 namespace VectorHelpers {
66 template <
typename Derived>
67 double phi(
const Eigen::MatrixBase<Derived>&
v) noexcept {
68 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
69 if constexpr (rows != -1) {
71 static_assert(rows >= 2,
72 "Phi function not valid for vectors not at least 2D");
76 std::cerr <<
"Phi function not valid for vectors not at least 2D"
82 return std::atan2(
v[1],
v[0]);
92 double phi(
const T&
v) noexcept {
102 template <
typename Derived>
103 double perp(
const Eigen::MatrixBase<Derived>&
v) noexcept {
104 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
105 if constexpr (rows != -1) {
107 static_assert(rows >= 2,
108 "Perp function not valid for vectors not at least 2D");
112 std::cerr <<
"Perp function not valid for vectors not at least 2D"
117 return std::sqrt(
v[0] *
v[0] +
v[1] *
v[1]);
126 template <
typename Derived>
127 double theta(
const Eigen::MatrixBase<Derived>&
v) noexcept {
128 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
129 if constexpr (rows != -1) {
131 static_assert(rows >= 3,
"Theta function not valid for non-3D vectors.");
135 std::cerr <<
"Theta function not valid for non-3D vectors." << std::endl;
140 return std::atan2(std::sqrt(
v[0] *
v[0] +
v[1] *
v[1]), v[2]);
149 template <
typename Derived>
150 double eta(
const Eigen::MatrixBase<Derived>&
v) noexcept {
151 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
152 if constexpr (rows != -1) {
154 static_assert(rows >= 3,
"Eta function not valid for non-3D vectors.");
158 std::cerr <<
"Eta function not valid for non-3D vectors." << std::endl;
163 return std::atanh(
v[2] /
v.norm());
173 return position[bval];
176 return perp(position);
179 return phi(position);
182 return theta(position);
185 return eta(position);
188 return position.norm();
202 r.col(0) = m.col(0).cross(v);
203 r.col(1) = m.col(1).cross(v);
204 r.col(2) = m.col(2).cross(v);
214 return spacePointVec[3];
223 return spacePointVec[3];
265 return spacePointVec.head<3>();
274 return spacePointVec.head<3>();
283 return freeVec.head<3>();
292 return freeVec.head<3>();
300 if (val < 0 &&
std::abs(val) * std::pow(10, precision) < 1.) {
313 const std::string&
offset =
"") {
314 std::ostringstream sout;
316 sout << std::setiosflags(std::ios::fixed) << std::setprecision(
precision);
317 if (matrix.cols() == 1) {
319 for (
int i = 0; i < matrix.rows(); ++i) {
322 if (i != matrix.rows() - 1) {
328 for (
int i = 0; i < matrix.rows(); ++i) {
329 for (
int j = 0; j < matrix.cols(); ++j) {
335 if (j == matrix.cols() - 1) {
341 if (i != matrix.rows() -
358 trans[0] = translation.x();
359 trans[1] = translation.y();
360 trans[2] = translation.z();
371 std::ostringstream sout;
374 std::string rotationOffset =
offset +
" ";
375 sout <<
offset <<
"Rotation : "
385 template <
typename T>
387 const std::vector<std::shared_ptr<T>>& items) {
388 std::vector<T*> rawPtrs;
389 rawPtrs.reserve(items.size());
390 for (
const std::shared_ptr<T>& item : items) {
391 rawPtrs.push_back(item.get());
401 template <
typename T>
403 const std::vector<std::shared_ptr<const T>>& items) {
404 std::vector<const T*> rawPtrs;
405 rawPtrs.reserve(items.size());
406 for (
const std::shared_ptr<const T>& item : items) {
407 rawPtrs.push_back(item.get());
429 template <
template <
size_t>
class Callable,
size_t N,
size_t NMAX,
432 size_t v, Args&&... args) {
434 return Callable<N>::invoke(std::forward<Args>(args)...);
436 if constexpr (
N <
NMAX) {
437 return template_switch<Callable, N + 1, NMAX>(
v,
438 std::forward<Args>(args)...);
440 std::cerr <<
"template_switch<Fn, " <<
N <<
", " <<
NMAX <<
">(v=" << v
441 <<
") is not valid (v > NMAX)" << std::endl;
452 template <
typename MatrixType>
454 MatrixType::ColsAtCompileTime>
456 constexpr
int rows = MatrixType::RowsAtCompileTime;
457 constexpr
int cols = MatrixType::ColsAtCompileTime;
459 static_assert(rows != -1 && cols != -1,
460 "bitsetToMatrix does not support dynamic matrices");
464 for (
size_t i = 0; i < rows * cols; i++) {
465 p[i] = bs[rows * cols - 1 - i];
476 template <
typename Derived>
478 using MatrixType = Eigen::PlainObjectBase<Derived>;
479 constexpr
size_t rows = MatrixType::RowsAtCompileTime;
480 constexpr
size_t cols = MatrixType::ColsAtCompileTime;
482 std::bitset<rows * cols> res;
485 for (
size_t i = 0; i < rows * cols; i++) {
486 res[rows * cols - 1 - i] =
p[i];