19 #define _VECOPS_USE_EXTERN_TEMPLATES false
21 #define _VECOPS_USE_EXTERN_TEMPLATES true
37#define _USE_MATH_DEFINES
46#include <vdt/vdtMath.h>
62template <
typename...
T>
65 constexpr const auto nArgs =
sizeof...(T);
66 const std::size_t sizes[] = {vs.
size()...};
68 for (
auto i = 1UL; i < nArgs; i++) {
69 if (sizes[0] == sizes[i])
72 msg +=
": input RVec instances have different lengths!";
73 throw std::runtime_error(msg);
79template <
typename F,
typename...
T>
83 RVec<
decltype(
f(vs[0]...))> ret(size);
85 for (
auto i = 0UL; i < size; i++)
91template <
typename Tuple_t, std::size_t... Is>
93 ->
decltype(
MapImpl(std::get<std::tuple_size<Tuple_t>::value - 1>(t), std::get<Is>(t)...))
95 constexpr const auto tupleSizeM1 = std::tuple_size<Tuple_t>::value - 1;
96 return MapImpl(std::get<tupleSizeM1>(t), std::get<Is>(t)...);
108template <
typename T,
typename... Args>
111 v.emplace_back(std::forward<Args>(args)...);
114template <
typename... Args>
117 v.push_back(std::forward<Args>(args)...);
277 static constexpr const auto IsVecBool = std::is_same<bool, T>::value;
279 using Impl_t =
typename std::conditional<IsVecBool, std::vector<bool>, std::vector<T, ::ROOT::Detail::VecOps::RAdoptAllocator<T>>>
::type;
315 template <
class InputIt>
340 template <typename U, typename = std::enable_if<std::is_convertible<T, U>::value>>
361 template <typename V, typename = std::enable_if<std::is_convertible<V, bool>::value>>
367 throw std::runtime_error(
"Cannot index RVec with condition vector of different size");
409 template <
class... Args>
417 template<typename U = T, typename std::enable_if<std::is_arithmetic<U>::value,
int>* =
nullptr>
420 return fData.emplace(pos, value);
431#define RVEC_UNARY_OPERATOR(OP) \
432template <typename T> \
433RVec<T> operator OP(const RVec<T> &v) \
436 for (auto &x : ret) \
445#undef RVEC_UNARY_OPERATOR
451#define ERROR_MESSAGE(OP) \
452 "Cannot call operator " #OP " on vectors of different sizes."
454#define RVEC_BINARY_OPERATOR(OP) \
455template <typename T0, typename T1> \
456auto operator OP(const RVec<T0> &v, const T1 &y) \
457 -> RVec<decltype(v[0] OP y)> \
459 RVec<decltype(v[0] OP y)> ret(v.size()); \
460 auto op = [&y](const T0 &x) { return x OP y; }; \
461 std::transform(v.begin(), v.end(), ret.begin(), op); \
465template <typename T0, typename T1> \
466auto operator OP(const T0 &x, const RVec<T1> &v) \
467 -> RVec<decltype(x OP v[0])> \
469 RVec<decltype(x OP v[0])> ret(v.size()); \
470 auto op = [&x](const T1 &y) { return x OP y; }; \
471 std::transform(v.begin(), v.end(), ret.begin(), op); \
475template <typename T0, typename T1> \
476auto operator OP(const RVec<T0> &v0, const RVec<T1> &v1) \
477 -> RVec<decltype(v0[0] OP v1[0])> \
479 if (v0.size() != v1.size()) \
480 throw std::runtime_error(ERROR_MESSAGE(OP)); \
482 RVec<decltype(v0[0] OP v1[0])> ret(v0.size()); \
483 auto op = [](const T0 &x, const T1 &y) { return x OP y; }; \
484 std::transform(v0.begin(), v0.end(), v1.begin(), ret.begin(), op); \
496#undef RVEC_BINARY_OPERATOR
502#define RVEC_ASSIGNMENT_OPERATOR(OP) \
503template <typename T0, typename T1> \
504RVec<T0>& operator OP(RVec<T0> &v, const T1 &y) \
506 auto op = [&y](T0 &x) { return x OP y; }; \
507 std::transform(v.begin(), v.end(), v.begin(), op); \
511template <typename T0, typename T1> \
512RVec<T0>& operator OP(RVec<T0> &v0, const RVec<T1> &v1) \
514 if (v0.size() != v1.size()) \
515 throw std::runtime_error(ERROR_MESSAGE(OP)); \
517 auto op = [](T0 &x, const T1 &y) { return x OP y; }; \
518 std::transform(v0.begin(), v0.end(), v1.begin(), v0.begin(), op); \
532#undef RVEC_ASSIGNMENT_OPERATOR
538#define RVEC_LOGICAL_OPERATOR(OP) \
539template <typename T0, typename T1> \
540auto operator OP(const RVec<T0> &v, const T1 &y) \
543 RVec<int> ret(v.size()); \
544 auto op = [y](const T0 &x) -> int { return x OP y; }; \
545 std::transform(v.begin(), v.end(), ret.begin(), op); \
549template <typename T0, typename T1> \
550auto operator OP(const T0 &x, const RVec<T1> &v) \
553 RVec<int> ret(v.size()); \
554 auto op = [x](const T1 &y) -> int { return x OP y; }; \
555 std::transform(v.begin(), v.end(), ret.begin(), op); \
559template <typename T0, typename T1> \
560auto operator OP(const RVec<T0> &v0, const RVec<T1> &v1) \
563 if (v0.size() != v1.size()) \
564 throw std::runtime_error(ERROR_MESSAGE(OP)); \
566 RVec<int> ret(v0.size()); \
567 auto op = [](const T0 &x, const T1 &y) -> int { return x OP y; }; \
568 std::transform(v0.begin(), v0.end(), v1.begin(), ret.begin(), op); \
580#undef RVEC_LOGICAL_OPERATOR
587template <
typename T>
struct PromoteTypeImpl;
589template <>
struct PromoteTypeImpl<float> {
using Type = float; };
590template <>
struct PromoteTypeImpl<double> {
using Type = double; };
591template <>
struct PromoteTypeImpl<long double> {
using Type =
long double; };
593template <
typename T>
struct PromoteTypeImpl {
using Type = double; };
598template <
typename U,
typename V>
599using PromoteTypes =
decltype(PromoteType<U>() + PromoteType<V>());
603#define RVEC_UNARY_FUNCTION(NAME, FUNC) \
604 template <typename T> \
605 RVec<PromoteType<T>> NAME(const RVec<T> &v) \
607 RVec<PromoteType<T>> ret(v.size()); \
608 auto f = [](const T &x) { return FUNC(x); }; \
609 std::transform(v.begin(), v.end(), ret.begin(), f); \
613#define RVEC_BINARY_FUNCTION(NAME, FUNC) \
614 template <typename T0, typename T1> \
615 RVec<PromoteTypes<T0, T1>> NAME(const T0 &x, const RVec<T1> &v) \
617 RVec<PromoteTypes<T0, T1>> ret(v.size()); \
618 auto f = [&x](const T1 &y) { return FUNC(x, y); }; \
619 std::transform(v.begin(), v.end(), ret.begin(), f); \
623 template <typename T0, typename T1> \
624 RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &v, const T1 &y) \
626 RVec<PromoteTypes<T0, T1>> ret(v.size()); \
627 auto f = [&y](const T1 &x) { return FUNC(x, y); }; \
628 std::transform(v.begin(), v.end(), ret.begin(), f); \
632 template <typename T0, typename T1> \
633 RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &v0, const RVec<T1> &v1) \
635 if (v0.size() != v1.size()) \
636 throw std::runtime_error(ERROR_MESSAGE(NAME)); \
638 RVec<PromoteTypes<T0, T1>> ret(v0.size()); \
639 auto f = [](const T0 &x, const T1 &y) { return FUNC(x, y); }; \
640 std::transform(v0.begin(), v0.end(), v1.begin(), ret.begin(), f); \
644#define RVEC_STD_UNARY_FUNCTION(F) RVEC_UNARY_FUNCTION(F, std::F)
645#define RVEC_STD_BINARY_FUNCTION(F) RVEC_BINARY_FUNCTION(F, std::F)
692#undef RVEC_STD_UNARY_FUNCTION
699#define RVEC_VDT_UNARY_FUNCTION(F) RVEC_UNARY_FUNCTION(F, vdt::F)
701RVEC_VDT_UNARY_FUNCTION(fast_expf)
702RVEC_VDT_UNARY_FUNCTION(fast_logf)
703RVEC_VDT_UNARY_FUNCTION(fast_sinf)
704RVEC_VDT_UNARY_FUNCTION(fast_cosf)
705RVEC_VDT_UNARY_FUNCTION(fast_tanf)
706RVEC_VDT_UNARY_FUNCTION(fast_asinf)
707RVEC_VDT_UNARY_FUNCTION(fast_acosf)
708RVEC_VDT_UNARY_FUNCTION(fast_atanf)
710RVEC_VDT_UNARY_FUNCTION(fast_exp)
711RVEC_VDT_UNARY_FUNCTION(fast_log)
712RVEC_VDT_UNARY_FUNCTION(fast_sin)
713RVEC_VDT_UNARY_FUNCTION(fast_cos)
714RVEC_VDT_UNARY_FUNCTION(fast_tan)
715RVEC_VDT_UNARY_FUNCTION(fast_asin)
716RVEC_VDT_UNARY_FUNCTION(fast_acos)
717RVEC_VDT_UNARY_FUNCTION(fast_atan)
718#undef RVEC_VDT_UNARY_FUNCTION
722#undef RVEC_UNARY_FUNCTION
737template <
typename T,
typename V>
740 if (v0.size() != v1.size())
741 throw std::runtime_error(
"Cannot compute inner product of vectors of different sizes");
742 return std::inner_product(v0.begin(), v0.end(), v1.begin(),
decltype(v0[0] * v1[0])(0));
758 return std::accumulate(
v.begin(),
v.end(),
T(0));
775 if (
v.empty())
return 0.;
776 return double(
Sum(
v)) /
v.size();
792 return *std::max_element(
v.begin(),
v.end());
808 return *std::min_element(
v.begin(),
v.end());
826 return std::distance(
v.begin(), std::max_element(
v.begin(),
v.end()));
844 return std::distance(
v.begin(), std::min_element(
v.begin(),
v.end()));
861 const std::size_t size =
v.size();
862 if (size < std::size_t(2))
return 0.;
863 T sum_squares(0), squared_sum(0);
864 auto pred = [&sum_squares, &squared_sum](
const T&
x) {sum_squares+=
x*
x; squared_sum+=
x;};
865 std::for_each(
v.begin(),
v.end(), pred);
866 squared_sum *= squared_sum;
867 const auto dsize = (double) size;
868 return 1. / (dsize - 1.) * (sum_squares - squared_sum / dsize );
906template <
typename... Args>
909 std::make_index_sequence<
sizeof...(args) - 1>()))
922 std::make_index_sequence<
sizeof...(args) - 1>());
935template <
typename T,
typename F>
938 const auto thisSize =
v.size();
941 for (
auto &&val :
v) {
1002template <
typename T>
1008 std::sort(i.
begin(), i.
end(), [&
v](size_type i1, size_type i2) { return v[i1] < v[i2]; });
1022template <
typename T>
1026 const size_type isize = i.size();
1028 for (size_type k = 0; k < isize; k++)
1048template <
typename T>
1052 const size_type size =
v.size();
1053 const size_type absn = std::abs(
n);
1055 std::stringstream ss;
1056 ss <<
"Try to take " << absn <<
" elements but vector has only size " << size <<
".";
1057 throw std::runtime_error(ss.str());
1061 for (size_type k = 0; k < absn; k++)
1062 r[k] =
v[size - absn + k];
1064 for (size_type k = 0; k < absn; k++)
1080template <
typename T>
1084 std::reverse(
r.begin(),
r.end());
1101template <
typename T>
1105 std::sort(
r.begin(),
r.end());
1126template <
typename T,
typename Compare>
1130 std::sort(
r.begin(),
r.end(), std::forward<Compare>(
c));
1148 using size_type = std::size_t;
1150 r[0].resize(size1*size2);
1151 r[1].resize(size1*size2);
1153 for(size_type i=0; i<size1; i++) {
1154 for(size_type j=0; j<size2; j++) {
1178template <
typename T1,
typename T2>
1203template <
typename T>
1207 const size_type
s =
v.size();
1209 std::stringstream ss;
1210 ss <<
"Cannot make unique combinations of size " <<
n <<
" from vector of size " <<
s <<
".";
1211 throw std::runtime_error(ss.str());
1214 for(size_type k=0; k<
s; k++)
1217 for(size_type k=0; k<
n; k++)
1220 bool run_through =
true;
1224 run_through =
false;
1232 for (
long j=i+1; j<(long)
n; j++)
1234 for(size_type k=0; k<
n; k++)
1249template <
typename T>
1254 const auto size =
v.size();
1256 for(size_type i=0; i<size; i++) {
1280template <
typename T>
1284 if (!v2_is_sorted) v2_sorted =
Sort(v2);
1285 const auto v2_begin = v2_is_sorted ? v2.
begin() : v2_sorted.
begin();
1286 const auto v2_end = v2_is_sorted ? v2.
end() : v2_sorted.
end();
1288 const auto size = v1.
size();
1291 for(size_type i=0; i<size; i++) {
1292 if (std::binary_search(v2_begin, v2_end, v1[i])) {
1293 r.emplace_back(v1[i]);
1314template <
typename T>
1318 const size_type size =
c.size();
1321 for (size_type i=0; i<size; i++) {
1322 r.emplace_back(
c[i] != 0 ? v1[i] : v2[i]);
1342template <
typename T>
1346 const size_type size =
c.size();
1349 for (size_type i=0; i<size; i++) {
1350 r.emplace_back(
c[i] != 0 ? v1[i] : v2);
1370template <
typename T>
1374 const size_type size =
c.size();
1377 for (size_type i=0; i<size; i++) {
1378 r.emplace_back(
c[i] != 0 ? v1 : v2[i]);
1396template <
typename T>
1400 const size_type size =
c.size();
1403 for (size_type i=0; i<size; i++) {
1404 r.emplace_back(
c[i] != 0 ? v1 : v2);
1427 resAsVect.insert(resAsVect.begin(), v0AsVect.begin(), v0AsVect.end());
1428 resAsVect.insert(resAsVect.end(), v1AsVect.begin(), v1AsVect.end());
1438template <
typename T>
1441 static_assert(std::is_floating_point<T>::value,
1442 "DeltaPhi must be called with floating point values.");
1443 auto r = std::fmod(v2 - v1, 2.0 *
c);
1459template <
typename T>
1463 const size_type size = v1.
size();
1465 for (size_type i = 0; i < size; i++) {
1477template <
typename T>
1481 const size_type size = v1.
size();
1483 for (size_type i = 0; i < size; i++) {
1495template <
typename T>
1499 const size_type size = v2.
size();
1501 for (size_type i = 0; i < size; i++) {
1514template <
typename T>
1517 const auto dphi =
DeltaPhi(phi1, phi2,
c);
1518 return (eta1 - eta2) * (eta1 - eta2) + dphi * dphi;
1528template <
typename T>
1541template <
typename T>
1544 const auto dphi =
DeltaPhi(phi1, phi2,
c);
1545 return std::sqrt((eta1 - eta2) * (eta1 - eta2) + dphi * dphi);
1553template <
typename T>
1559 const auto x1 = pt1 *
cos(phi1);
1560 const auto y1 = pt1 *
sin(phi1);
1561 const auto z1 = pt1 *
sinh(eta1);
1562 const auto e1 =
sqrt(
x1 *
x1 + y1 * y1 + z1 * z1 + mass1 * mass1);
1564 const auto x2 = pt2 *
cos(phi2);
1565 const auto y2 = pt2 *
sin(phi2);
1566 const auto z2 = pt2 *
sinh(eta2);
1567 const auto e2 =
sqrt(
x2 *
x2 + y2 * y2 + z2 * z2 + mass2 * mass2);
1570 const auto e = e1 + e2;
1571 const auto x =
x1 +
x2;
1572 const auto y = y1 + y2;
1573 const auto z = z1 + z2;
1584template <
typename T>
1588 const auto x =
pt *
cos(phi);
1589 const auto y =
pt *
sin(phi);
1590 const auto z =
pt *
sinh(eta);
1591 const auto e =
sqrt(
x *
x +
y *
y + z * z + mass * mass);
1594 const auto xs =
Sum(
x);
1595 const auto ys =
Sum(
y);
1596 const auto zs =
Sum(z);
1597 const auto es =
Sum(
e);
1600 return std::sqrt(es * es - xs * xs - ys * ys - zs * zs);
1621template <
typename T,
typename... Args_t>
1627 for (
auto i = 0UL; i < size; ++i) {
1639 constexpr bool mustConvert = std::is_same<char, T>::value || std::is_same<signed char, T>::value ||
1640 std::is_same<unsigned char, T>::value || std::is_same<wchar_t, T>::value ||
1641 std::is_same<char16_t, T>::value || std::is_same<char32_t, T>::value;
1644 auto size =
v.size();
1646 for (std::size_t i = 0; i < size - 1; ++i) {
1647 os << (Print_t)
v[i] <<
", ";
1649 os << (Print_t)
v[size - 1];
1655#if (_VECOPS_USE_EXTERN_TEMPLATES)
1657#define RVEC_EXTERN_UNARY_OPERATOR(T, OP) \
1658 extern template RVec<T> operator OP<T>(const RVec<T> &);
1660#define RVEC_EXTERN_BINARY_OPERATOR(T, OP) \
1661 extern template auto operator OP<T, T>(const T &x, const RVec<T> &v) \
1662 -> RVec<decltype(x OP v[0])>; \
1663 extern template auto operator OP<T, T>(const RVec<T> &v, const T &y) \
1664 -> RVec<decltype(v[0] OP y)>; \
1665 extern template auto operator OP<T, T>(const RVec<T> &v0, const RVec<T> &v1)\
1666 -> RVec<decltype(v0[0] OP v1[0])>;
1668#define RVEC_EXTERN_ASSIGN_OPERATOR(T, OP) \
1669 extern template RVec<T> &operator OP<T, T>(RVec<T> &, const T &); \
1670 extern template RVec<T> &operator OP<T, T>(RVec<T> &, const RVec<T> &);
1672#define RVEC_EXTERN_LOGICAL_OPERATOR(T, OP) \
1673 extern template RVec<int> operator OP<T, T>(const RVec<T> &, const T &); \
1674 extern template RVec<int> operator OP<T, T>(const T &, const RVec<T> &); \
1675 extern template RVec<int> operator OP<T, T>(const RVec<T> &, const RVec<T> &);
1677#define RVEC_EXTERN_FLOAT_TEMPLATE(T) \
1678 extern template class RVec<T>; \
1679 RVEC_EXTERN_UNARY_OPERATOR(T, +) \
1680 RVEC_EXTERN_UNARY_OPERATOR(T, -) \
1681 RVEC_EXTERN_UNARY_OPERATOR(T, !) \
1682 RVEC_EXTERN_BINARY_OPERATOR(T, +) \
1683 RVEC_EXTERN_BINARY_OPERATOR(T, -) \
1684 RVEC_EXTERN_BINARY_OPERATOR(T, *) \
1685 RVEC_EXTERN_BINARY_OPERATOR(T, /) \
1686 RVEC_EXTERN_ASSIGN_OPERATOR(T, +=) \
1687 RVEC_EXTERN_ASSIGN_OPERATOR(T, -=) \
1688 RVEC_EXTERN_ASSIGN_OPERATOR(T, *=) \
1689 RVEC_EXTERN_ASSIGN_OPERATOR(T, /=) \
1690 RVEC_EXTERN_LOGICAL_OPERATOR(T, <) \
1691 RVEC_EXTERN_LOGICAL_OPERATOR(T, >) \
1692 RVEC_EXTERN_LOGICAL_OPERATOR(T, ==) \
1693 RVEC_EXTERN_LOGICAL_OPERATOR(T, !=) \
1694 RVEC_EXTERN_LOGICAL_OPERATOR(T, <=) \
1695 RVEC_EXTERN_LOGICAL_OPERATOR(T, >=) \
1696 RVEC_EXTERN_LOGICAL_OPERATOR(T, &&) \
1697 RVEC_EXTERN_LOGICAL_OPERATOR(T, ||)
1699#define RVEC_EXTERN_INTEGER_TEMPLATE(T) \
1700 extern template class RVec<T>; \
1701 RVEC_EXTERN_UNARY_OPERATOR(T, +) \
1702 RVEC_EXTERN_UNARY_OPERATOR(T, -) \
1703 RVEC_EXTERN_UNARY_OPERATOR(T, ~) \
1704 RVEC_EXTERN_UNARY_OPERATOR(T, !) \
1705 RVEC_EXTERN_BINARY_OPERATOR(T, +) \
1706 RVEC_EXTERN_BINARY_OPERATOR(T, -) \
1707 RVEC_EXTERN_BINARY_OPERATOR(T, *) \
1708 RVEC_EXTERN_BINARY_OPERATOR(T, /) \
1709 RVEC_EXTERN_BINARY_OPERATOR(T, %) \
1710 RVEC_EXTERN_BINARY_OPERATOR(T, &) \
1711 RVEC_EXTERN_BINARY_OPERATOR(T, |) \
1712 RVEC_EXTERN_BINARY_OPERATOR(T, ^) \
1713 RVEC_EXTERN_ASSIGN_OPERATOR(T, +=) \
1714 RVEC_EXTERN_ASSIGN_OPERATOR(T, -=) \
1715 RVEC_EXTERN_ASSIGN_OPERATOR(T, *=) \
1716 RVEC_EXTERN_ASSIGN_OPERATOR(T, /=) \
1717 RVEC_EXTERN_ASSIGN_OPERATOR(T, %=) \
1718 RVEC_EXTERN_ASSIGN_OPERATOR(T, &=) \
1719 RVEC_EXTERN_ASSIGN_OPERATOR(T, |=) \
1720 RVEC_EXTERN_ASSIGN_OPERATOR(T, ^=) \
1721 RVEC_EXTERN_ASSIGN_OPERATOR(T, >>=) \
1722 RVEC_EXTERN_ASSIGN_OPERATOR(T, <<=) \
1723 RVEC_EXTERN_LOGICAL_OPERATOR(T, <) \
1724 RVEC_EXTERN_LOGICAL_OPERATOR(T, >) \
1725 RVEC_EXTERN_LOGICAL_OPERATOR(T, ==) \
1726 RVEC_EXTERN_LOGICAL_OPERATOR(T, !=) \
1727 RVEC_EXTERN_LOGICAL_OPERATOR(T, <=) \
1728 RVEC_EXTERN_LOGICAL_OPERATOR(T, >=) \
1729 RVEC_EXTERN_LOGICAL_OPERATOR(T, &&) \
1730 RVEC_EXTERN_LOGICAL_OPERATOR(T, ||)
1732RVEC_EXTERN_INTEGER_TEMPLATE(
char)
1733RVEC_EXTERN_INTEGER_TEMPLATE(
short)
1734RVEC_EXTERN_INTEGER_TEMPLATE(
int)
1735RVEC_EXTERN_INTEGER_TEMPLATE(
long)
1738RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned char)
1739RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned short)
1740RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned int)
1741RVEC_EXTERN_INTEGER_TEMPLATE(
unsigned long)
1744RVEC_EXTERN_FLOAT_TEMPLATE(
float)
1745RVEC_EXTERN_FLOAT_TEMPLATE(
double)
1747#undef RVEC_EXTERN_UNARY_OPERATOR
1748#undef RVEC_EXTERN_BINARY_OPERATOR
1749#undef RVEC_EXTERN_ASSIGN_OPERATOR
1750#undef RVEC_EXTERN_LOGICAL_OPERATOR
1751#undef RVEC_EXTERN_INTEGER_TEMPLATE
1752#undef RVEC_EXTERN_FLOAT_TEMPLATE
1754#define RVEC_EXTERN_UNARY_FUNCTION(T, NAME, FUNC) \
1755 extern template RVec<PromoteType<T>> NAME(const RVec<T> &);
1757#define RVEC_EXTERN_STD_UNARY_FUNCTION(T, F) RVEC_EXTERN_UNARY_FUNCTION(T, F, std::F)
1759#define RVEC_EXTERN_BINARY_FUNCTION(T0, T1, NAME, FUNC) \
1760 extern template RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &, const T1 &); \
1761 extern template RVec<PromoteTypes<T0, T1>> NAME(const T0 &, const RVec<T1> &); \
1762 extern template RVec<PromoteTypes<T0, T1>> NAME(const RVec<T0> &, const RVec<T1> &);
1764#define RVEC_EXTERN_STD_BINARY_FUNCTION(T, F) RVEC_EXTERN_BINARY_FUNCTION(T, T, F, std::F)
1766#define RVEC_EXTERN_STD_FUNCTIONS(T) \
1767 RVEC_EXTERN_STD_UNARY_FUNCTION(T, abs) \
1768 RVEC_EXTERN_STD_BINARY_FUNCTION(T, fdim) \
1769 RVEC_EXTERN_STD_BINARY_FUNCTION(T, fmod) \
1770 RVEC_EXTERN_STD_BINARY_FUNCTION(T, remainder) \
1771 RVEC_EXTERN_STD_UNARY_FUNCTION(T, exp) \
1772 RVEC_EXTERN_STD_UNARY_FUNCTION(T, exp2) \
1773 RVEC_EXTERN_STD_UNARY_FUNCTION(T, expm1) \
1774 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log) \
1775 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log10) \
1776 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log2) \
1777 RVEC_EXTERN_STD_UNARY_FUNCTION(T, log1p) \
1778 RVEC_EXTERN_STD_BINARY_FUNCTION(T, pow) \
1779 RVEC_EXTERN_STD_UNARY_FUNCTION(T, sqrt) \
1780 RVEC_EXTERN_STD_UNARY_FUNCTION(T, cbrt) \
1781 RVEC_EXTERN_STD_BINARY_FUNCTION(T, hypot) \
1782 RVEC_EXTERN_STD_UNARY_FUNCTION(T, sin) \
1783 RVEC_EXTERN_STD_UNARY_FUNCTION(T, cos) \
1784 RVEC_EXTERN_STD_UNARY_FUNCTION(T, tan) \
1785 RVEC_EXTERN_STD_UNARY_FUNCTION(T, asin) \
1786 RVEC_EXTERN_STD_UNARY_FUNCTION(T, acos) \
1787 RVEC_EXTERN_STD_UNARY_FUNCTION(T, atan) \
1788 RVEC_EXTERN_STD_BINARY_FUNCTION(T, atan2) \
1789 RVEC_EXTERN_STD_UNARY_FUNCTION(T, sinh) \
1790 RVEC_EXTERN_STD_UNARY_FUNCTION(T, cosh) \
1791 RVEC_EXTERN_STD_UNARY_FUNCTION(T, tanh) \
1792 RVEC_EXTERN_STD_UNARY_FUNCTION(T, asinh) \
1793 RVEC_EXTERN_STD_UNARY_FUNCTION(T, acosh) \
1794 RVEC_EXTERN_STD_UNARY_FUNCTION(T, atanh) \
1795 RVEC_EXTERN_STD_UNARY_FUNCTION(T, floor) \
1796 RVEC_EXTERN_STD_UNARY_FUNCTION(T, ceil) \
1797 RVEC_EXTERN_STD_UNARY_FUNCTION(T, trunc) \
1798 RVEC_EXTERN_STD_UNARY_FUNCTION(T, round) \
1799 RVEC_EXTERN_STD_UNARY_FUNCTION(T, erf) \
1800 RVEC_EXTERN_STD_UNARY_FUNCTION(T, erfc) \
1801 RVEC_EXTERN_STD_UNARY_FUNCTION(T, lgamma) \
1802 RVEC_EXTERN_STD_UNARY_FUNCTION(T, tgamma) \
1804RVEC_EXTERN_STD_FUNCTIONS(
float)
1805RVEC_EXTERN_STD_FUNCTIONS(
double)
1806#undef RVEC_EXTERN_STD_UNARY_FUNCTION
1807#undef RVEC_EXTERN_STD_BINARY_FUNCTION
1808#undef RVEC_EXTERN_STD_UNARY_FUNCTIONS
1812#define RVEC_EXTERN_VDT_UNARY_FUNCTION(T, F) RVEC_EXTERN_UNARY_FUNCTION(T, F, vdt::F)
1814RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_expf)
1815RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_logf)
1816RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_sinf)
1817RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_cosf)
1818RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_tanf)
1819RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_asinf)
1820RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_acosf)
1821RVEC_EXTERN_VDT_UNARY_FUNCTION(
float, fast_atanf)
1823RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_exp)
1824RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_log)
1825RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_sin)
1826RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_cos)
1827RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_tan)
1828RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_asin)
1829RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_acos)
1830RVEC_EXTERN_VDT_UNARY_FUNCTION(
double, fast_atan)
#define RVEC_UNARY_OPERATOR(OP)
#define RVEC_ASSIGNMENT_OPERATOR(OP)
#define RVEC_STD_BINARY_FUNCTION(F)
#define RVEC_BINARY_OPERATOR(OP)
#define RVEC_LOGICAL_OPERATOR(OP)
#define RVEC_STD_UNARY_FUNCTION(F)
static const double x2[5]
static const double x1[5]
Int_t Compare(const void *item1, const void *item2)
double atan2(double, double)
double pow(double, double)
A "std::vector"-like collection of values implementing handy operation to analyse them.
typename std::conditional< IsVecBool, std::vector< bool >, std::vector< T, ::ROOT::Detail::VecOps::RAdoptAllocator< T > > >::type Impl_t
typename Impl_t::iterator iterator
static constexpr const auto IsVecBool
const_iterator begin() const noexcept
reverse_iterator rbegin() noexcept
const_iterator cbegin() const noexcept
typename Impl_t::value_type value_type
reference operator[](size_type pos)
iterator erase(iterator pos)
RVec< T > & operator=(std::initializer_list< T > ilist)
typename Impl_t::const_pointer const_pointer
RVec(std::initializer_list< T > init)
void resize(size_type count)
void push_back(T &&value)
const_reference back() const
typename Impl_t::difference_type difference_type
const_reverse_iterator crbegin() const noexcept
RVec operator[](const RVec< V > &conds) const
iterator erase(iterator first, iterator last)
RVec< T > & operator=(RVec< T > &&v)
const_reverse_iterator crend() const noexcept
const_reference at(size_type pos) const
typename Impl_t::const_iterator const_iterator
bool empty() const noexcept
typename Impl_t::reference reference
void push_back(const value_type &value)
size_type size() const noexcept
RVec(size_type count, const T &value)
const_iterator end() const noexcept
iterator emplace(const_iterator pos, U value)
This method is intended only for arithmetic types unlike the std::vector corresponding one which is g...
typename Impl_t::const_reference const_reference
const_iterator cend() const noexcept
typename Impl_t::const_reverse_iterator const_reverse_iterator
const_reference front() const
void reserve(size_type new_cap)
reference at(size_type pos)
const_reverse_iterator rend() const noexcept
typename std::conditional< IsVecBool, void, typename Impl_t::pointer >::type data_t
typename Impl_t::reverse_iterator reverse_iterator
const_reference operator[](size_type pos) const
typename Impl_t::pointer pointer
size_type capacity() const noexcept
reverse_iterator rend() noexcept
RVec< T > & operator=(const RVec< T > &v)
typename std::conditional< IsVecBool, void, typename Impl_t::const_pointer >::type const_data_t
const Impl_t & AsVector() const
value_type at(size_type pos, value_type fallback)
No exception thrown. The user specifies the desired value in case the RVec is shorter than pos.
iterator begin() noexcept
const_reverse_iterator rbegin() const noexcept
value_type at(size_type pos, value_type fallback) const
No exception thrown. The user specifies the desired value in case the RVec is shorter than pos.
typename Impl_t::size_type size_type
void resize(size_type count, const value_type &value)
reference emplace_back(Args &&... args)
const_data_t data() const noexcept
RVec(const std::vector< T > &v)
void swap(RVec< T > &other)
RVec(InputIt first, InputIt last)
RVec(pointer p, size_type n)
size_type max_size() const noexcept
Type
enumeration specifying the integration types.
double erfc(double x)
Complementary error function.
double tgamma(double x)
The gamma function is defined to be the extension of the factorial to real numbers.
double lgamma(double x)
Calculates the logarithm of the gamma function.
double erf(double x)
Error function encountered in integrating the normal distribution.
basic_string_view< char > string_view
std::size_t GetVectorsSize(std::string_view id, const RVec< T > &... vs)
auto MapFromTuple(Tuple_t &&t, std::index_sequence< Is... >) -> decltype(MapImpl(std::get< std::tuple_size< Tuple_t >::value - 1 >(t), std::get< Is >(t)...))
ROOT::VecOps::RVec< T > RVec
auto MapImpl(F &&f, const RVec< T > &... vs) -> RVec< decltype(f(vs[0]...))>
void EmplaceBack(T &v, Args &&... args)
double log1p(double x)
declarations for functions which are not implemented by some compilers
double expm1(double x)
exp(x) -1 with error cancellation when x is small
double inner_product(const LAVector &, const LAVector &)
T Max(const RVec< T > &v)
Get the greatest element of an RVec.
RVec< T > Reverse(const RVec< T > &v)
Return copy of reversed vector.
RVec< T > Intersect(const RVec< T > &v1, const RVec< T > &v2, bool v2_is_sorted=false)
Return the intersection of elements of two RVecs.
auto All(const RVec< T > &v) -> decltype(v[0]==false)
Return true if all of the elements equate to true, return false otherwise.
T Sum(const RVec< T > &v)
Sum elements of an RVec.
RVec< typename RVec< T >::size_type > Nonzero(const RVec< T > &v)
Return the indices of the elements which are not zero.
auto Map(Args &&... args) -> decltype(ROOT::Detail::VecOps::MapFromTuple(std::forward_as_tuple(args...), std::make_index_sequence< sizeof...(args) - 1 >()))
Create new collection applying a callable to the elements of the input collection.
RVec< T > Sort(const RVec< T > &v)
Return copy of RVec with elements sorted in ascending order.
T InvariantMass(const RVec< T > &pt, const RVec< T > &eta, const RVec< T > &phi, const RVec< T > &mass)
Return the invariant mass of multiple particles given the collections of the quantities transverse mo...
std::ostream & operator<<(std::ostream &os, const RVec< T > &v)
Print a RVec at the prompt:
RVec< Common_t > Concatenate(const RVec< T0 > &v0, const RVec< T1 > &v1)
Return the concatenation of two RVecs.
RVec< T > DeltaR(const RVec< T > &eta1, const RVec< T > &eta2, const RVec< T > &phi1, const RVec< T > &phi2, const T c=M_PI)
Return the distance on the - plane ( ) from the collections eta1, eta2, phi1 and phi2.
RVec< T > InvariantMasses(const RVec< T > &pt1, const RVec< T > &eta1, const RVec< T > &phi1, const RVec< T > &mass1, const RVec< T > &pt2, const RVec< T > &eta2, const RVec< T > &phi2, const RVec< T > &mass2)
Return the invariant mass of two particles given the collections of the quantities transverse momentu...
RVec< T > DeltaR2(const RVec< T > &eta1, const RVec< T > &eta2, const RVec< T > &phi1, const RVec< T > &phi2, const T c=M_PI)
Return the square of the distance on the - plane ( ) from the collections eta1, eta2,...
double Mean(const RVec< T > &v)
Get the mean of the elements of an RVec.
RVec< T > Take(const RVec< T > &v, const RVec< typename RVec< T >::size_type > &i)
Return elements of a vector at given indices.
void swap(RVec< T > &lhs, RVec< T > &rhs)
RVec< T > Construct(const RVec< Args_t > &... args)
Build an RVec of objects starting from RVecs of input to their constructors.
T DeltaPhi(T v1, T v2, const T c=M_PI)
Return the angle difference of two scalars.
auto Dot(const RVec< T > &v0, const RVec< V > &v1) -> decltype(v0[0] *v1[0])
Inner product.
T Min(const RVec< T > &v)
Get the smallest element of an RVec.
RVec< RVec< std::size_t > > Combinations(const std::size_t size1, const std::size_t size2)
Return the indices that represent all combinations of the elements of two RVecs.
RVec< T > Where(const RVec< int > &c, const RVec< T > &v1, const RVec< T > &v2)
Return the elements of v1 if the condition c is true and v2 if the condition c is false.
double StdDev(const RVec< T > &v)
Get the standard deviation of the elements of an RVec.
auto Any(const RVec< T > &v) -> decltype(v[0]==true)
Return true if any of the elements equates to true, return false otherwise.
RVec< typename RVec< T >::size_type > Argsort(const RVec< T > &v)
Return an RVec of indices that sort the input RVec.
std::size_t ArgMin(const RVec< T > &v)
Get the index of the smallest element of an RVec In case of multiple occurrences of the minimum value...
double Var(const RVec< T > &v)
Get the variance of the elements of an RVec.
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
std::size_t ArgMax(const RVec< T > &v)
Get the index of the greatest element of an RVec In case of multiple occurrences of the maximum value...
Namespace for new ROOT classes and functions.
static constexpr double s