30 #define ACTS_CHECK_BIT(value, mask) ((value & mask) == mask)
34 namespace VectorHelpers {
50 template <
typename Derived>
51 double phi(
const Eigen::MatrixBase<Derived>&
v) noexcept {
52 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
53 if constexpr (rows != -1) {
55 static_assert(rows >= 2,
56 "Phi function not valid for vectors not at least 2D");
60 std::cerr <<
"Phi function not valid for vectors not at least 2D"
66 return std::atan2(
v[1],
v[0]);
76 double phi(
const T&
v) noexcept {
86 template <
typename Derived>
87 double perp(
const Eigen::MatrixBase<Derived>&
v) noexcept {
88 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
89 if constexpr (rows != -1) {
91 static_assert(rows >= 2,
92 "Perp function not valid for vectors not at least 2D");
96 std::cerr <<
"Perp function not valid for vectors not at least 2D"
101 return std::sqrt(
v[0] *
v[0] +
v[1] *
v[1]);
110 template <
typename Derived>
111 double theta(
const Eigen::MatrixBase<Derived>&
v) noexcept {
112 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
113 if constexpr (rows != -1) {
115 static_assert(rows >= 3,
"Theta function not valid for non-3D vectors.");
119 std::cerr <<
"Theta function not valid for non-3D vectors." << std::endl;
124 return std::atan2(std::sqrt(
v[0] *
v[0] +
v[1] *
v[1]), v[2]);
133 template <
typename Derived>
134 double eta(
const Eigen::MatrixBase<Derived>&
v) noexcept {
135 constexpr
int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
136 if constexpr (rows != -1) {
138 static_assert(rows >= 3,
"Eta function not valid for non-3D vectors.");
142 std::cerr <<
"Eta function not valid for non-3D vectors." << std::endl;
147 return std::atanh(
v[2] /
v.norm());
163 return perp(position);
165 return phi(position);
167 return perp(position) *
phi(position);
169 return theta(position);
171 return eta(position);
173 return position.norm();
175 assert(
false and
"Invalid BinningValue enum value");
176 return std::numeric_limits<double>::quiet_NaN();
188 r.col(0) = m.col(0).cross(v);
189 r.col(1) = m.col(1).cross(v);
190 r.col(2) = m.col(2).cross(v);
197 return pos4.segment<3>(
ePos0);
206 template <
typename vector3_t>
209 -> Eigen::Matrix<typename vector3_t::Scalar, 4, 1> {
210 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(vector3_t, 3);
212 Eigen::Matrix<typename vector3_t::Scalar, 4, 1> vec4;
225 if (val < 0 &&
std::abs(val) * std::pow(10, precision) < 1.) {
238 const std::string&
offset =
"") {
239 std::ostringstream sout;
241 sout << std::setiosflags(std::ios::fixed) << std::setprecision(
precision);
242 if (matrix.cols() == 1) {
244 for (
int i = 0; i < matrix.rows(); ++i) {
247 if (i != matrix.rows() - 1) {
253 for (
int i = 0; i < matrix.rows(); ++i) {
254 for (
int j = 0; j < matrix.cols(); ++j) {
260 if (j == matrix.cols() - 1) {
266 if (i != matrix.rows() -
283 trans[0] = translation.x();
284 trans[1] = translation.y();
285 trans[2] = translation.z();
296 std::ostringstream sout;
299 std::string rotationOffset =
offset +
" ";
300 sout <<
offset <<
"Rotation : "
310 template <
typename T>
313 std::vector<T*> rawPtrs;
314 rawPtrs.reserve(items.size());
315 for (
const std::shared_ptr<T>& item : items) {
316 rawPtrs.push_back(item.get());
326 template <
typename T>
328 const std::vector<std::shared_ptr<const T>>& items) {
329 std::vector<const T*> rawPtrs;
330 rawPtrs.reserve(items.size());
331 for (
const std::shared_ptr<const T>& item : items) {
332 rawPtrs.push_back(item.get());
354 template <
template <
size_t>
class Callable,
size_t N,
size_t NMAX,
357 size_t v, Args&&...
args) {
359 return Callable<N>::invoke(std::forward<Args>(args)...);
361 if constexpr (
N <
NMAX) {
362 return template_switch<Callable, N + 1, NMAX>(
v,
363 std::forward<Args>(
args)...);
365 std::cerr <<
"template_switch<Fn, " <<
N <<
", " <<
NMAX <<
">(v=" << v
366 <<
") is not valid (v > NMAX)" << std::endl;
377 template <
typename MatrixType>
379 MatrixType::ColsAtCompileTime>
381 constexpr
int rows = MatrixType::RowsAtCompileTime;
382 constexpr
int cols = MatrixType::ColsAtCompileTime;
384 static_assert(rows != -1 && cols != -1,
385 "bitsetToMatrix does not support dynamic matrices");
389 for (
size_t i = 0; i < rows * cols; i++) {
390 p[i] = bs[rows * cols - 1 - i];
401 template <
typename Derived>
403 using MatrixType = Eigen::PlainObjectBase<Derived>;
404 constexpr
size_t rows = MatrixType::RowsAtCompileTime;
405 constexpr
size_t cols = MatrixType::ColsAtCompileTime;
407 std::bitset<rows * cols> res;
410 for (
size_t i = 0; i < rows * cols; i++) {
411 res[rows * cols - 1 - i] =
p[i];