ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
AnalysisUtils
AnalysisUtils
AnalysisPermutation.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef ANALYSISUTILS_ANALYSISPERMUTATION_H
6
#define ANALYSISUTILS_ANALYSISPERMUTATION_H
7
13
14
#include <algorithm>
15
#include <vector>
16
17
#include "
AnalysisUtils/AnalysisCombination.h
"
18
19
namespace
AnalysisUtils
{
20
23
template
<
class
COLL>
class
Permutation
24
{
25
public
:
26
30
Permutation
(COLL *coll,
const
unsigned
int
nElement)
31
:
m_coll
(coll),
m_first
(true)
32
{
33
// init indices
34
for
(
unsigned
int
i=0; i<coll->size(); ++i)
35
m_index_for_comb
.push_back(
new
unsigned
int
(i));
36
37
m_comb
=
new
Combination<std::vector<unsigned int *>
> (&
m_index_for_comb
, nElement);
38
}
39
42
~Permutation
()
43
{
44
delete
m_comb
;
45
46
for
(
unsigned
int
i=0; i<
m_index_for_comb
.size(); ++i)
47
delete
m_index_for_comb
[i];
48
}
49
50
Permutation
(
const
Permutation
&) =
delete
;
51
Permutation
&
operator=
(
const
Permutation
&) =
delete
;
52
58
template
<
class
OUT>
59
bool
get
(
OUT
&perm)
60
{
61
// init returned vector
62
perm.clear();
63
64
// get combination if first
65
if
(
m_first
)
66
{
67
m_first
=
false
;
68
if
(!
m_comb
->get(
m_index
))
return
false
;
69
std::sort
(
m_index
.begin(),
m_index
.end());
70
}
71
else
72
{
73
// change sequence. if this is the last permutation. get next combination
74
if
(! std::next_permutation (
m_index
.begin(),
m_index
.end()))
75
{
76
if
(!
m_comb
->get(
m_index
))
return
false
;
77
std::sort
(
m_index
.begin(),
m_index
.end());
78
}
79
}
80
81
// assign
82
std::vector<unsigned int *>::const_iterator it =
m_index
.begin();
83
std::vector<unsigned int *>::const_iterator itE =
m_index
.end();
84
for
(; it!=itE; ++it)
85
perm.push_back((*
m_coll
)[**it]);
86
87
return
true
;
88
}
89
94
template
<
class
CALLER,
class
OUT,
class
CRITERIA>
95
bool
goodOnes
(CALLER *caller,
OUT
&perm, CRITERIA criteria)
96
{
97
get
(perm);
98
99
// check if this passes the criteria
100
if
(criteria(caller,perm))
return
true
;
101
102
// if not, look for next combination
103
return
goodOnes
(caller, perm, criteria);
104
}
105
106
107
private
:
108
110
Combination<std::vector<unsigned int *>
> *
m_comb
;
111
113
COLL *
m_coll
;
114
116
std::vector<unsigned int *>
m_index_for_comb
;
117
std::vector<unsigned int *>
m_index
;
118
120
bool
m_first
;
121
122
};
123
}
// end of AnalysisUtils
124
125
#endif
AnalysisCombination.h
OUT
#define OUT(dst, src)
Definition
MD5.cxx:316
AnalysisUtils::Combination
combination
Definition
AnalysisCombination.h:20
AnalysisUtils::Permutation::m_index
std::vector< unsigned int * > m_index
Definition
AnalysisPermutation.h:117
AnalysisUtils::Permutation::goodOnes
bool goodOnes(CALLER *caller, OUT &perm, CRITERIA criteria)
get a permutation which passes a selection criteria
Definition
AnalysisPermutation.h:95
AnalysisUtils::Permutation::~Permutation
~Permutation()
destructor
Definition
AnalysisPermutation.h:42
AnalysisUtils::Permutation::m_coll
COLL * m_coll
collection
Definition
AnalysisPermutation.h:113
AnalysisUtils::Permutation::m_index_for_comb
std::vector< unsigned int * > m_index_for_comb
indices of elements
Definition
AnalysisPermutation.h:116
AnalysisUtils::Permutation::Permutation
Permutation(const Permutation &)=delete
AnalysisUtils::Permutation::m_comb
Combination< std::vector< unsigned int * > > * m_comb
combination
Definition
AnalysisPermutation.h:110
AnalysisUtils::Permutation::operator=
Permutation & operator=(const Permutation &)=delete
AnalysisUtils::Permutation::m_first
bool m_first
flag to check if first
Definition
AnalysisPermutation.h:120
AnalysisUtils::Permutation::get
bool get(OUT &perm)
get a permutation.
Definition
AnalysisPermutation.h:59
AnalysisUtils::Permutation::Permutation
Permutation(COLL *coll, const unsigned int nElement)
constructor
Definition
AnalysisPermutation.h:30
AnalysisUtils
utility class to select combination of elements in a collection
Definition
AnalysisCombination.h:16
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
Generated on
for ATLAS Offline Software by
1.17.0