Logo ROOT   6.16/01
Reference Guide
Classes | Functions
ROOT::VecOps Namespace Reference

Classes

class  RVec
 A "std::vector"-like collection of values implementing handy operation to analyse them. More...
 

Functions

template<typename T >
auto All (const RVec< T > &v) -> decltype(v[0]==false)
 Return true if all of the elements equate to true, return false otherwise. More...
 
template<typename T >
auto Any (const RVec< T > &v) -> decltype(v[0]==true)
 Return true if any of the elements equates to true, return false otherwise. More...
 
template<typename T >
RVec< typename RVec< T >::size_type > Argsort (const RVec< T > &v)
 Return an RVec of indices that sort the input RVec. More...
 
template<typename T >
RVec< RVec< typename RVec< T >::size_type > > Combinations (const RVec< T > &v, const typename RVec< T >::size_type n)
 Return the indices that represent all unique combinations of the elements of a given RVec. More...
 
template<typename T1 , typename T2 >
RVec< RVec< typename RVec< T1 >::size_type > > Combinations (const RVec< T1 > &v1, const RVec< T2 > &v2)
 Return the indices that represent all combinations of the elements of two RVecs. More...
 
template<typename T , typename V >
auto Dot (const RVec< T > &v0, const RVec< V > &v1) -> decltype(v0[0] *v1[0])
 Inner product. More...
 
template<typename T , typename F >
RVec< T > Filter (const RVec< T > &v, F &&f)
 Create a new collection with the elements passing the filter expressed by the predicate. More...
 
template<typename T >
RVec< T > Intersect (const RVec< T > &v1, const RVec< T > &v2, bool v2_is_sorted=false)
 Return the intersection of elements of two RVecs. More...
 
template<typename T , typename F >
auto Map (const RVec< T > &v, F &&f) -> RVec< decltype(f(v[0]))>
 Create new collection applying a callable to the elements of the input collection. More...
 
template<typename T >
double Mean (const RVec< T > &v)
 Get the mean of the elements of an RVec. More...
 
template<typename T >
RVec< typename RVec< T >::size_type > Nonzero (const RVec< T > &v)
 Return the indices of the elements which are not zero. More...
 
template<class T >
std::ostream & operator<< (std::ostream &os, const RVec< T > &v)
 Print a RVec at the prompt: More...
 
template<typename T >
RVec< T > Reverse (const RVec< T > &v)
 Return copy of reversed vector. More...
 
template<typename T >
RVec< T > Sort (const RVec< T > &v)
 Return copy of RVec with elements sorted in ascending order. More...
 
template<typename T , typename Compare >
RVec< T > Sort (const RVec< T > &v, Compare &&c)
 Return copy of RVec with elements sorted based on a comparison operator. More...
 
template<typename T >
double StdDev (const RVec< T > &v)
 Get the standard deviation of the elements of an RVec. More...
 
template<typename T >
Sum (const RVec< T > &v)
 Sum elements of an RVec. More...
 
template<typename T >
void swap (RVec< T > &lhs, RVec< T > &rhs)
 
template<typename T >
RVec< T > Take (const RVec< T > &v, const int n)
 Return first or last n elements of an RVec. More...
 
template<typename T >
RVec< T > Take (const RVec< T > &v, const RVec< typename RVec< T >::size_type > &i)
 Return elements of a vector at given indices. More...
 
template<typename T >
double Var (const RVec< T > &v)
 Get the variance of the elements of an RVec. More...
 
template<typename T >
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. More...
 
template<typename T >
RVec< T > Where (const RVec< int > &c, const RVec< T > &v1, T v2)
 Return the elements of v1 if the condition c is true and sets the value v2 if the condition c is false. More...
 
template<typename T >
RVec< T > Where (const RVec< int > &c, T v1, const RVec< T > &v2)
 Return the elements of v2 if the condition c is false and sets the value v1 if the condition c is true. More...
 
template<typename T >
RVec< T > Where (const RVec< int > &c, T v1, T v2)
 Return a vector with the value v2 if the condition c is false and sets the value v1 if the condition c is true. More...
 

Function Documentation

◆ All()

template<typename T >
auto ROOT::VecOps::All ( const RVec< T > &  v) -> decltype(v[0] == false)

Return true if all of the elements equate to true, return false otherwise.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<int> v {0, 1, 0};
auto allTrue = All(v);
allTrue
// (bool) false
SVector< double, 2 > v
Definition: Dict.h:5
A "std::vector"-like collection of values implementing handy operation to analyse them.
Definition: RVec.hxx:221
auto All(const RVec< T > &v) -> decltype(v[0]==false)
Return true if all of the elements equate to true, return false otherwise.
Definition: RVec.hxx:837

Definition at line 837 of file RVec.hxx.

◆ Any()

template<typename T >
auto ROOT::VecOps::Any ( const RVec< T > &  v) -> decltype(v[0] == true)

Return true if any of the elements equates to true, return false otherwise.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<int> v {0, 1, 0};
auto anyTrue = Any(v);
anyTrue
// (bool) true
auto Any(const RVec< T > &v) -> decltype(v[0]==true)
Return true if any of the elements equates to true, return false otherwise.
Definition: RVec.hxx:818

Definition at line 818 of file RVec.hxx.

◆ Argsort()

template<typename T >
RVec< typename RVec< T >::size_type > ROOT::VecOps::Argsort ( const RVec< T > &  v)

Return an RVec of indices that sort the input RVec.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v {2., 3., 1.};
auto sortIndices = Argsort(v);
sortIndices
// (ROOT::VecOps::RVec<unsigned long> &) { 2, 0, 1 }
RVec< typename RVec< T >::size_type > Argsort(const RVec< T > &v)
Return an RVec of indices that sort the input RVec.
Definition: RVec.hxx:862

Definition at line 862 of file RVec.hxx.

◆ Combinations() [1/2]

template<typename T >
RVec< RVec< typename RVec< T >::size_type > > ROOT::VecOps::Combinations ( const RVec< T > &  v,
const typename RVec< T >::size_type  n 
)

Return the indices that represent all unique combinations of the elements of a given RVec.

using namespace ROOT::VecOps;
RVec<double> v {1., 2., 3., 4.};
auto v_1 = Combinations(v, 1);
v_1
auto v_2 = Combinations(v, 2);
auto v_2
(ROOT::VecOps::RVec<ROOT::VecOps::RVec<ROOT::VecOps::RVec<double>::size_type> >) { { 0, 0, 0, 1, 1, 2 }, { 1, 2, 3, 2, 3, 3 } }
auto v_3 = Combinations(v, 3);
v_3
(ROOT::VecOps::RVec<ROOT::VecOps::RVec<ROOT::VecOps::RVec<double>::size_type> >) { { 0, 0, 0, 1 }, { 1, 1, 2, 2 }, { 2, 3, 3, 3 } }
auto v_4 = Combinations(v, 4);
v_4
typename Impl_t::size_type size_type
Definition: RVec.hxx:230
RVec< RVec< typename RVec< T1 >::size_type > > Combinations(const RVec< T1 > &v1, const RVec< T2 > &v2)
Return the indices that represent all combinations of the elements of two RVecs.
Definition: RVec.hxx:1008

Definition at line 1047 of file RVec.hxx.

◆ Combinations() [2/2]

template<typename T1 , typename T2 >
RVec< RVec< typename RVec< T1 >::size_type > > ROOT::VecOps::Combinations ( const RVec< T1 > &  v1,
const RVec< T2 > &  v2 
)

Return the indices that represent all combinations of the elements of two RVecs.

The type of the return value is an RVec of two RVecs containing indices.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v1 {1., 2., 3.};
RVec<double> v2 {-4., -5.};
auto comb_idx = Combinations(v1, v2);
comb_idx
// (ROOT::VecOps::RVec<ROOT::VecOps::RVec<ROOT::VecOps::RVec<double>::size_type> >) { { 0, 0, 1, 1, 2, 2 }, { 0, 1, 0, 1, 0, 1 } }

Definition at line 1008 of file RVec.hxx.

◆ Dot()

template<typename T , typename V >
auto ROOT::VecOps::Dot ( const RVec< T > &  v0,
const RVec< V > &  v1 
) -> decltype(v0[0] * v1[0])

Inner product.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<float> v1 {1., 2., 3.};
RVec<float> v2 {4., 5., 6.};
auto v1_dot_v2 = Dot(v1, v2);
v1_dot_v2
// (float) 32.f
auto Dot(const RVec< T > &v0, const RVec< V > &v1) -> decltype(v0[0] *v1[0])
Inner product.
Definition: RVec.hxx:684

Definition at line 684 of file RVec.hxx.

◆ Filter()

template<typename T , typename F >
RVec< T > ROOT::VecOps::Filter ( const RVec< T > &  v,
F &&  f 
)

Create a new collection with the elements passing the filter expressed by the predicate.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<int> v {1, 2, 4};
auto v_even = Filter(v, [](int i){return 0 == i%2;});
v_even
// (ROOT::VecOps::RVec<int> &) { 2, 4 }
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
Definition: RVec.hxx:795

Definition at line 795 of file RVec.hxx.

◆ Intersect()

template<typename T >
RVec< T > ROOT::VecOps::Intersect ( const RVec< T > &  v1,
const RVec< T > &  v2,
bool  v2_is_sorted = false 
)

Return the intersection of elements of two RVecs.

Each element of v1 is looked up in v2 and added to the returned vector if found. Following, the order of v1 is preserved. If v2 is already sorted, the optional argument v2_is_sorted can be used to toggle of the internal sorting step, therewith optimising runtime.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v1 {1., 2., 3.};
RVec<double> v2 {-4., -5., 2., 1.};
auto v1_intersect_v2 = Intersect(v1, v2);
v1_intersect_v2
// (ROOT::VecOps::RVec<double>) { 1.0000000, 2.0000000 }
RVec< T > Intersect(const RVec< T > &v1, const RVec< T > &v2, bool v2_is_sorted=false)
Return the intersection of elements of two RVecs.
Definition: RVec.hxx:1124

Definition at line 1124 of file RVec.hxx.

◆ Map()

template<typename T , typename F >
auto ROOT::VecOps::Map ( const RVec< T > &  v,
F &&  f 
) -> RVec<decltype(f(v[0]))>

Create new collection applying a callable to the elements of the input collection.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<float> v {1.f, 2.f, 4.f};
auto v_square = Map(v, [](float f){return f* 2.f;});
v_square
// (ROOT::VecOps::RVec<float> &) { 2.00000f, 4.00000f, 8.00000f }
#define f(i)
Definition: RSha256.hxx:104
auto Map(const RVec< T > &v, F &&f) -> RVec< decltype(f(v[0]))>
Create new collection applying a callable to the elements of the input collection.
Definition: RVec.hxx:777

Definition at line 777 of file RVec.hxx.

◆ Mean()

template<typename T >
double ROOT::VecOps::Mean ( const RVec< T > &  v)

Get the mean of the elements of an RVec.

The return type is a double precision floating point number. Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<float> v {1.f, 2.f, 4.f};
auto v_mean = Mean(v);
v_mean
// (double) 2.3333333
double Mean(const RVec< T > &v)
Get the mean of the elements of an RVec.
Definition: RVec.hxx:719

Definition at line 719 of file RVec.hxx.

◆ Nonzero()

template<typename T >
RVec< typename RVec< T >::size_type > ROOT::VecOps::Nonzero ( const RVec< T > &  v)

Return the indices of the elements which are not zero.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v {2., 0., 3., 0., 1.};
auto nonzero_idx = Nonzero(v);
nonzero_idx
// (ROOT::VecOps::RVec<ROOT::VecOps::RVec<double>::size_type>) { 0, 2, 4 }
RVec< typename RVec< T >::size_type > Nonzero(const RVec< T > &v)
Return the indices of the elements which are not zero.
Definition: RVec.hxx:1093

Definition at line 1093 of file RVec.hxx.

◆ operator<<()

template<class T >
std::ostream & ROOT::VecOps::operator<< ( std::ostream &  os,
const RVec< T > &  v 
)

Print a RVec at the prompt:

Definition at line 1255 of file RVec.hxx.

◆ Reverse()

template<typename T >
RVec< T > ROOT::VecOps::Reverse ( const RVec< T > &  v)

Return copy of reversed vector.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v {2., 3., 1.};
auto v_reverse = Reverse(v);
v_reverse
// (ROOT::VecOps::RVec<double>) { 1.0000000, 3.0000000, 2.0000000 }
RVec< T > Reverse(const RVec< T > &v)
Return copy of reversed vector.
Definition: RVec.hxx:940

Definition at line 940 of file RVec.hxx.

◆ Sort() [1/2]

template<typename T >
RVec< T > ROOT::VecOps::Sort ( const RVec< T > &  v)

Return copy of RVec with elements sorted in ascending order.

This helper is different from ArgSort since it does not return an RVec of indices, but an RVec of values.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v {2., 3., 1.};
auto v_sorted = Sort(v);
v_sorted
// (ROOT::VecOps::RVec<double>) { 1.0000000, 2.0000000, 3.0000000 }
RVec< T > Sort(const RVec< T > &v)
Return copy of RVec with elements sorted in ascending order.
Definition: RVec.hxx:961

Definition at line 961 of file RVec.hxx.

◆ Sort() [2/2]

template<typename T , typename Compare >
RVec< T > ROOT::VecOps::Sort ( const RVec< T > &  v,
Compare &&  c 
)

Return copy of RVec with elements sorted based on a comparison operator.

The comparison operator has to fullfill the same requirements of the predicate of by std::sort.

This helper is different from ArgSort since it does not return an RVec of indices, but an RVec of values.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v {2., 3., 1.};
auto v_sorted = Sort(v, [](double x, double y) {return 1/x < 1/y;});
v_sorted
// (ROOT::VecOps::RVec<double>) { 3.0000000, 2.0000000, 1.0000000 }
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17

Definition at line 986 of file RVec.hxx.

◆ StdDev()

template<typename T >
double ROOT::VecOps::StdDev ( const RVec< T > &  v)

Get the standard deviation of the elements of an RVec.

The return type is a double precision floating point number. Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<float> v {1.f, 2.f, 4.f};
auto v_sd = StdDev(v);
v_sd
// (double) 1.5275252
double StdDev(const RVec< T > &v)
Get the standard deviation of the elements of an RVec.
Definition: RVec.hxx:761

Definition at line 761 of file RVec.hxx.

◆ Sum()

template<typename T >
T ROOT::VecOps::Sum ( const RVec< T > &  v)

Sum elements of an RVec.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<float> v {1.f, 2.f, 3.f};
auto v_sum = Sum(v);
v_sum
// (float) 6.f
T Sum(const RVec< T > &v)
Sum elements of an RVec.
Definition: RVec.hxx:702

Definition at line 702 of file RVec.hxx.

◆ swap()

template<typename T >
void ROOT::VecOps::swap ( RVec< T > &  lhs,
RVec< T > &  rhs 
)

Definition at line 846 of file RVec.hxx.

◆ Take() [1/2]

template<typename T >
RVec< T > ROOT::VecOps::Take ( const RVec< T > &  v,
const int  n 
)

Return first or last n elements of an RVec.

if n > 0 and last elements if n < 0.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v {2., 3., 1.};
auto firstTwo = Take(v, 2);
firstTwo
// (ROOT::VecOps::RVec<double>) { 2.0000000, 3.0000000 }
auto lastOne = Take(v, -1);
lastOne
// (ROOT::VecOps::RVec<double>) { 1.0000000 }
RVec< T > Take(const RVec< T > &v, const RVec< typename RVec< T >::size_type > &i)
Return elements of a vector at given indices.
Definition: RVec.hxx:882

Definition at line 908 of file RVec.hxx.

◆ Take() [2/2]

template<typename T >
RVec< T > ROOT::VecOps::Take ( const RVec< T > &  v,
const RVec< typename RVec< T >::size_type > &  i 
)

Return elements of a vector at given indices.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v {2., 3., 1.};
auto vTaken = Take(v, {0,2});
vTaken
// (ROOT::VecOps::RVec<double>) { 2.0000000, 1.0000000 }

Definition at line 882 of file RVec.hxx.

◆ Var()

template<typename T >
double ROOT::VecOps::Var ( const RVec< T > &  v)

Get the variance of the elements of an RVec.

The return type is a double precision floating point number. Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<float> v {1.f, 2.f, 4.f};
auto v_var = Var(v);
v_var
// (double) 2.3333333
double Var(const RVec< T > &v)
Get the variance of the elements of an RVec.
Definition: RVec.hxx:737

Definition at line 737 of file RVec.hxx.

◆ Where() [1/4]

template<typename T >
RVec< T > ROOT::VecOps::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.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v1 {1., 2., 3.};
RVec<double> v2 {-1., -2., -3.};
auto c = v1 > 1;
// (ROOT::VecOps::RVec<int> &) { 0, 1, 1 }
auto if_c_v1_else_v2 = Where(c, v1, v2);
if_c_v1_else_v2
// (ROOT::VecOps::RVec<double> &) { -1.0000000, 2.0000000, 3.0000000 }
#define c(i)
Definition: RSha256.hxx:101
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.
Definition: RVec.hxx:1158

Definition at line 1158 of file RVec.hxx.

◆ Where() [2/4]

template<typename T >
RVec< T > ROOT::VecOps::Where ( const RVec< int > &  c,
const RVec< T > &  v1,
v2 
)

Return the elements of v1 if the condition c is true and sets the value v2 if the condition c is false.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
RVec<double> v1 {1., 2., 3.};
double v2 = 4.;
auto c = v1 > 1;
// (ROOT::VecOps::RVec<int> &) { 0, 1, 1 }
auto if_c_v1_else_v2 = Where(c, v1, v2);
if_c_v1_else_v2
// (ROOT::VecOps::RVec<double>) { 4.0000000, 2.0000000, 3.0000000 }

Definition at line 1186 of file RVec.hxx.

◆ Where() [3/4]

template<typename T >
RVec< T > ROOT::VecOps::Where ( const RVec< int > &  c,
v1,
const RVec< T > &  v2 
)

Return the elements of v2 if the condition c is false and sets the value v1 if the condition c is true.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
double v1 = 4.;
RVec<double> v2 {1., 2., 3.};
auto c = v2 > 1;
// (ROOT::VecOps::RVec<int> &) { 0, 1, 1 }
auto if_c_v1_else_v2 = Where(c, v1, v2);
if_c_v1_else_v2
// (ROOT::VecOps::RVec<double>) { 1.0000000, 4.0000000, 4.0000000 }

Definition at line 1214 of file RVec.hxx.

◆ Where() [4/4]

template<typename T >
RVec< T > ROOT::VecOps::Where ( const RVec< int > &  c,
v1,
v2 
)

Return a vector with the value v2 if the condition c is false and sets the value v1 if the condition c is true.

Example code, at the ROOT prompt:

using namespace ROOT::VecOps;
double v1 = 4.;
double v2 = 2.;
RVec<int> c {0, 1, 1};
auto if_c_v1_else_v2 = Where(c, v1, v2);
if_c_v1_else_v2
// (ROOT::VecOps::RVec<double>) { 2.0000000, 4.0000000, 4.0000000 }

Definition at line 1240 of file RVec.hxx.