Loading [MathJax]/extensions/tex2jax.js
ROOT
Version v6.22
master
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
vo005_Combinations.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_vecops
3
/// \notebook -nodraw
4
/// In this tutorial we learn how combinations of RVecs can be build.
5
///
6
/// \macro_code
7
/// \macro_output
8
///
9
/// \date August 2018
10
/// \author Stefan Wunsch
11
12
using namespace
ROOT::VecOps
;
13
14
void
vo005_Combinations
()
15
{
16
// The starting point are two collections and we want to calculate the result
17
// of combinations of the elements.
18
RVec<double>
v1
{1., 2., 3.};
19
RVec<double>
v2
{-4., -5.};
20
21
// To get the indices, which result in all combinations, you can call the
22
// following helper.
23
// Note that you can also pass the size of the vectors directly.
24
auto
idx =
Combinations
(
v1
,
v2
);
25
26
// Next, the respective elements can be taken via the computed indices.
27
auto
c1
=
Take
(
v1
, idx[0]);
28
auto
c2
=
Take
(
v2
, idx[1]);
29
30
// Finally, you can perform any set of operations conveniently.
31
auto
v3
=
c1
*
c2
;
32
33
std::cout <<
"Combinations of "
<<
v1
<<
" and "
<<
v2
<<
":"
<< std::endl;
34
for
(
size_t
i=0; i<
v3
.size(); i++) {
35
std::cout <<
c1
[i] <<
" * "
<<
c2
[i] <<
" = "
<<
v3
[i] << std::endl;
36
}
37
std::cout << std::endl;
38
39
// However, if you want to compute operations on unique combinations of a
40
// single RVec, you can perform this as follows.
41
42
// Get the indices of unique triples for the given vector.
43
RVec<double>
v4
{1., 2., 3., 4.};
44
auto
idx2 =
Combinations
(
v4
, 3);
45
46
// Take the elements and compute any operation on the returned collections.
47
auto
c3
=
Take
(
v4
, idx2[0]);
48
auto
c4 =
Take
(
v4
, idx2[1]);
49
auto
c5 =
Take
(
v4
, idx2[2]);
50
51
auto
v5 =
c3
* c4 * c5;
52
53
std::cout <<
"Unique triples of "
<<
v4
<<
":"
<< std::endl;
54
for
(
size_t
i=0; i<
v4
.size(); i++) {
55
std::cout <<
c3
[i] <<
" * "
<< c4[i] <<
" * "
<< c5[i] <<
" = "
<< v5[i] << std::endl;
56
}
57
std::cout << std::endl;
58
}
ROOT::VecOps::RVec< double >
c1
return c1
Definition:
legend1.C:41
c2
return c2
Definition:
legend2.C:14
c3
return c3
Definition:
legend3.C:15
ROOT::VecOps
Definition:
RVec.hxx:54
ROOT::VecOps::Take
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:1026
ROOT::VecOps::Combinations
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.
Definition:
RVec.hxx:1149
vo005_Combinations
Definition:
vo005_Combinations.py:1
v2
@ v2
Definition:
rootcling_impl.cxx:3627
v4
@ v4
Definition:
rootcling_impl.cxx:3629
v3
@ v3
Definition:
rootcling_impl.cxx:3628
v1
@ v1
Definition:
rootcling_impl.cxx:3626
tutorials
vecops
vo005_Combinations.C
ROOT v6-22 - Reference Guide Generated on Fri Apr 1 2022 11:53:33 (GVA Time) using Doxygen 1.9.4