ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MuonCalib::Combination Class Reference

#include <Combination.h>

Collaboration diagram for MuonCalib::Combination:

Public Member Functions

 Combination ()
 Default construcor. A combination of 1 out of 1 is created. More...
 
 Combination (const unsigned int &n, const unsigned int &k)
 Constructor. More...
 
unsigned int numberOfElements () const
 get the number of elements More...
 
unsigned int whichClass () const
 get the class of which the combination is More...
 
unsigned int numberOfCombinations () const
 get the number of combinations More...
 
void currentCombination (std::vector< unsigned int > &index_array) const
 get the current combination; the result is stored in the vector index_array More...
 
void nextCombination (std::vector< unsigned int > &index_array)
 get the next combination; the results is stored in the array index_array More...
 
void reset ()
 go back to the first combination More...
 
void setNewParameters (const unsigned int &nb_elements, const unsigned int &wh_class)
 set the number of elements = nb_elements; set the class of which the combination is = wh_class More...
 

Private Member Functions

void init (const unsigned int &n, const unsigned int &k)
 

Private Attributes

unsigned int m_n = 0U
 
unsigned int m_k = 0U
 
std::vector< unsigned int > m_index
 
std::vector< unsigned int > m_flag
 

Detailed Description

Definition at line 33 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/MuonCalibMath/Combination.h.

Constructor & Destructor Documentation

◆ Combination() [1/2]

Combination::Combination ( )

Default construcor. A combination of 1 out of 1 is created.

Definition at line 20 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

20  {
21 
22  init(1,1);
23 
24 }

◆ Combination() [2/2]

Combination::Combination ( const unsigned int &  n,
const unsigned int &  k 
)

Constructor.

Parameters
nNumber of elements.
kClass of the combination.

Definition at line 32 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

32  {
33 
34  init(n, k);
35 
36 }

Member Function Documentation

◆ currentCombination()

void Combination::currentCombination ( std::vector< unsigned int > &  index_array) const

get the current combination; the result is stored in the vector index_array

Definition at line 125 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

126  {
127 
128  if (index_array.size()<m_k) {
129  index_array = std::vector<unsigned int>(m_k);
130  }
131  for (unsigned int j=0; j<m_k; j++) {
132  index_array[j] = m_index[j];
133  }
134 
135  return;
136 
137 }

◆ init()

void Combination::init ( const unsigned int &  n,
const unsigned int &  k 
)
private

Definition at line 44 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

44  {
45 
47 // CHECK IF k<=n //
49 
50  if (k>n) {
51  throw std::runtime_error(Form("File: %s, Line: %d\nCombination::init() - error, class number greater than number of elements!", __FILE__, __LINE__));
52  }
53 
55 // ALLOCATE MEMORY //
57 
58  m_k = k;
59  m_n = n;
60  m_index = std::vector<unsigned int>(m_k);
61  m_flag = std::vector<unsigned int>(m_k);
62 
64 // SETUP START CONFIGURATION //
66 
67  reset();
68 
69  return;
70 
71 }

◆ nextCombination()

void Combination::nextCombination ( std::vector< unsigned int > &  index_array)

get the next combination; the results is stored in the array index_array

Definition at line 145 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

145  {
146 
148 // VARIABLES //
150 
151  int loc_flag; // local flag
152 
154 // CHECK SIZE OF index_array//
156 
157  if (index_array.size()<m_k) {
158  index_array = std::vector<unsigned int>(m_k);
159  }
160 
162 // CHECK FLAGS //
164 
165  for (unsigned int j=0; j<m_k; j++) {
166  if (m_index[j] == (m_n-(m_k-j-1))) {
167  m_flag[j] = 1;
168  }
169  }
170  if (m_flag[0] == 1) {
171  reset();
172  currentCombination(index_array);
173  return;
174  }
175  loc_flag = 0;
176  for (unsigned int j=1; j<m_k; j++) {
177  if (m_flag[j] == 1) {
178  m_index[j-1] = m_index[j-1]+1;
179  for (unsigned int l=j; l<m_k; l++) {
180  m_index[l] = m_index[l-1]+1;
181  }
182  loc_flag = 1;
183  break;
184  }
185  }
186  if (loc_flag == 0) {
187  m_index[m_k-1] = m_index[m_k-1]+1;
188  }
189  for (unsigned int j=0; j<m_k; j++) {
190  if (m_index[j] == (m_n-(m_k-j-1))) {
191  m_flag[j] = 1;
192  }
193  else {
194  m_flag[j] = 0;
195  }
196  index_array[j] = m_index[j];
197  }
198 
200 // RETURN THE DESIRED COMBINATION //
202 
203  return;
204 
205 }

◆ numberOfCombinations()

unsigned int Combination::numberOfCombinations ( ) const

get the number of combinations

Definition at line 103 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

103  {
104 
106 // VARIABLES //
108 
109  int ncomb = TMath::Binomial(m_n, m_k);
110 
112 // RETURN THE NUMBER OF COMBINATIONS //
114 
115  return ncomb;
116 
117 }

◆ numberOfElements()

unsigned int Combination::numberOfElements ( ) const

get the number of elements

Definition at line 79 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

79  {
80 
81  return m_n;
82 
83 }

◆ reset()

void Combination::reset ( )

go back to the first combination

Definition at line 213 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

213  {
214 
215  for (unsigned int j=0; j<m_k; j++) {
216  m_index[j] = j+1;
217  m_flag[j] = 0;
218  }
219 
220  return;
221 
222 }

◆ setNewParameters()

void Combination::setNewParameters ( const unsigned int &  nb_elements,
const unsigned int &  wh_class 
)

set the number of elements = nb_elements; set the class of which the combination is = wh_class

Definition at line 230 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

231  {
232 
233  init(nb_elements, wh_class);
234 
235  return;
236 
237 }

◆ whichClass()

unsigned int Combination::whichClass ( ) const

get the class of which the combination is

Definition at line 91 of file MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx.

91  {
92 
93  return m_k;
94 
95 }

Member Data Documentation

◆ m_flag

std::vector<unsigned int> MuonCalib::Combination::m_flag
private

◆ m_index

std::vector<unsigned int> MuonCalib::Combination::m_index
private

◆ m_k

unsigned int MuonCalib::Combination::m_k = 0U
private

◆ m_n

unsigned int MuonCalib::Combination::m_n = 0U
private

The documentation for this class was generated from the following files:
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
MuonCalib::Combination::currentCombination
void currentCombination(std::vector< unsigned int > &index_array) const
get the current combination; the result is stored in the vector index_array
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx:125
MuonCalib::Combination::m_k
unsigned int m_k
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/MuonCalibMath/Combination.h:71
beamspotman.n
n
Definition: beamspotman.py:731
MuonCalib::Combination::reset
void reset()
go back to the first combination
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx:213
MuonCalib::Combination::m_index
std::vector< unsigned int > m_index
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/MuonCalibMath/Combination.h:72
MuonCalib::Combination::m_flag
std::vector< unsigned int > m_flag
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/MuonCalibMath/Combination.h:74
MuonCalib::Combination::init
void init(const unsigned int &n, const unsigned int &k)
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/Combination.cxx:44
fitman.k
k
Definition: fitman.py:528
MuonCalib::Combination::m_n
unsigned int m_n
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/MuonCalibMath/Combination.h:70