JHUGen MELA  JHUGen v7.5.6, MELA v2.4.2
Matrix element calculations as used in JHUGen.
TNumericUtil.cc
Go to the documentation of this file.
1 #include "TNumericUtil.hh"
2 #include <numeric>
3 #include <algorithm>
4 
5 using namespace std;
6 
7 void TNumericUtil::PermutationGenerator(int n, int k, std::vector<std::vector<int>>& perms, int valbegin, int increment){
8  if (n<=0 || k<=0 || k>n) return;
9  vector<int> d(n);
10  iota(d.begin(), d.end(), 1);
11  do{
12  vector<int> aperm;
13  for (int i=0; i<k; i++) aperm.push_back(d[i]);
14  perms.push_back(aperm);
15  reverse(d.begin()+k, d.end());
16  } while (next_permutation(d.begin(), d.end()));
17  if (valbegin!=1 || increment!=1){ for (auto& p:perms){ for (auto& pp:p) pp = increment*(pp-1)+valbegin; } }
18 }
19 void TNumericUtil::CombinationGenerator(int n, int k, std::vector<std::vector<int>>& perms, int valbegin, int increment){
20  if (n==k && k>0){
21  vector<int> d(n);
22  iota(d.begin(), d.end(), 1);
23  perms.push_back(d);
24  }
25  else{
26  PermutationGenerator(n, k, perms);
27  for (auto& perm:perms) sort(perm.begin(), perm.end());
28  for (auto ip=perms.begin(); ip!=perms.end(); ip++){
29  for (auto jp=perms.rbegin(); (jp.base()-1)!=ip; jp++){
30  if (*(ip)==*(jp)) perms.erase(jp.base()-1);
31  }
32  }
33  }
34  if (valbegin!=1 || increment!=1){ for (auto& p:perms){ for (auto& pp:p) pp = increment*(pp-1)+valbegin; } }
35 }
TNumericUtil.hh
TNumericUtil::PermutationGenerator
void PermutationGenerator(int n, int k, std::vector< std::vector< int >> &perms, int valbegin=1, int increment=1)
Definition: TNumericUtil.cc:7
TNumericUtil::CombinationGenerator
void CombinationGenerator(int n, int k, std::vector< std::vector< int >> &perms, int valbegin=1, int increment=1)
Definition: TNumericUtil.cc:19