Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions PWGUD/Core/DGPIDSelector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,29 @@ DGAnaparHolder::~DGAnaparHolder()
void DGAnaparHolder::Print()
{
LOGF(info, " DGAnaparHolder");
LOGF(info, " nCombine: %i", mNCombine);
LOGF(info, " max dcaxy: %f", mMaxDCAxy);
LOGF(info, " max dcaz: %f", mMaxDCAz);
LOGF(info, " min number tracks: %d", mMinNTracks);
LOGF(info, " max number tracks: %d", mMaxNTracks);
LOGF(info, " min fraction of PV contr. with TOF: %f", mMinRgtrwTOF);
LOGF(info, " max dcaxy: %f", mMaxDCAxy);
LOGF(info, " max dcaz: %f", mMaxDCAz);
LOGF(info, " min dBC: %d", mdBCMin);
LOGF(info, " max dBC: %d", mdBCMax);
LOGF(info, " min track pT: %f", mMinpt);
LOGF(info, " max track pT: %f", mMaxpt);
LOGF(info, " min eta: %f", mMineta);
LOGF(info, " max eta: %f", mMaxeta);
LOGF(info, " min alpha: %f", mMinAlpha);
LOGF(info, " max alpha: %f", mMaxAlpha);
LOGF(info, " min system pT: %f", mMinptsys);
LOGF(info, " max system pT: %f", mMaxptsys);
LOGF(info, " nCombine: %d", mNCombine);
LOGF(info, " net charges");
for (auto ch : mNetCharges) {
LOGF(info, " %i", ch);
}
LOGF(info, " PIDs");
for (auto pid : mDGPIDs) {
LOGF(info, " %f", pid);
LOGF(info, " %d", pid);
}
PIDCuts().Print();
}
Expand All @@ -145,8 +158,11 @@ DGPIDCuts DGAnaparHolder::PIDCuts()
// -----------------------------------------------------------------------------
void DGAnaparHolder::makeUniquePermutations()
{
// reset
muniquePerms.clear();

// all permutations of mNCombine elements
std::vector<std::vector<uint>> perms;
std::vector<std::vector<int>> perms;
permutations(mNCombine, perms);

// compute unique permutations
Expand All @@ -160,7 +176,7 @@ void DGAnaparHolder::makeUniquePermutations()
cnt = -1;
for (auto ind : perm) {
cnt++;
perminfo[cnt] = static_cast<int>(mDGPIDs[ind]);
perminfo[cnt] = mDGPIDs[ind];
}
hashstr = "";
for (auto tok : perminfo) {
Expand All @@ -183,19 +199,17 @@ void DGAnaparHolder::makeUniquePermutations()
std::vector<int> DGAnaparHolder::uniquePermutations()
{
// create unique permutations if not done already
if (muniquePerms.size() == 0) {
if (muniquePerms.size() < mNCombine) {
makeUniquePermutations();
LOGF(info, "Number of unique permutations: %i", muniquePerms.size() / mNCombine);
}

return muniquePerms;
}

// -----------------------------------------------------------------------------
// find all permutations of n0 elements
void DGAnaparHolder::permutations(std::vector<uint>& ref, int n0, int np, std::vector<std::vector<uint>>& perms)
void DGAnaparHolder::permutations(std::vector<int>& ref, int n0, int np, std::vector<std::vector<int>>& perms)
{

// create local reference
auto ref2u = ref;

Expand All @@ -205,7 +219,7 @@ void DGAnaparHolder::permutations(std::vector<uint>& ref, int n0, int np, std::v
// create a new permutation
// copy first n0-np elements from ref
// then rotate last np elements of ref
std::vector<uint> perm(n0, 0);
std::vector<int> perm(n0, 0);
for (auto ii = 0; ii < n0 - np; ii++) {
perm[ii] = ref2u[ii];
}
Expand Down Expand Up @@ -233,15 +247,15 @@ void DGAnaparHolder::permutations(std::vector<uint>& ref, int n0, int np, std::v

//-----------------------------------------------------------------------------
// find all permutations of n0 elements
int DGAnaparHolder::permutations(int n0, std::vector<std::vector<uint>>& perms)
int DGAnaparHolder::permutations(int n0, std::vector<std::vector<int>>& perms)
{
// initialize with first trivial combination
perms.clear();
if (n0 == 0) {
return 0;
}

std::vector<uint> ref(n0, 0);
std::vector<int> ref(n0, 0);
for (auto ii = 0; ii < n0; ii++) {
ref[ii] = ii;
}
Expand Down Expand Up @@ -323,8 +337,8 @@ int DGPIDSelector::pid2ind(int pid)

// -----------------------------------------------------------------------------
// find selections of np out of n0
void DGPIDSelector::combinations(int n0, std::vector<uint>& pool, int np, std::vector<uint>& inds, int n,
std::vector<std::vector<uint>>& combs)
void DGPIDSelector::combinations(int n0, std::vector<int>& pool, int np, std::vector<int>& inds, int n,
std::vector<std::vector<int>>& combs)
{
// loop over pool
for (auto ii = 0; ii < n0 - n; ii++) {
Expand All @@ -335,7 +349,7 @@ void DGPIDSelector::combinations(int n0, std::vector<uint>& pool, int np, std::v
// else get next inds
if (np == 1) {

std::vector<uint> comb(n + 1, 0);
std::vector<int> comb(n + 1, 0);
for (uint ii = 0; ii < inds.size(); ii++) {
comb[ii] = inds[ii];
}
Expand All @@ -344,7 +358,7 @@ void DGPIDSelector::combinations(int n0, std::vector<uint>& pool, int np, std::v
} else {

auto n0new = n0 - ii;
std::vector<uint> newpool(n0new, 0);
std::vector<int> newpool(n0new, 0);
for (auto kk = 0; kk < n0new; kk++) {
newpool[kk] = pool[kk + ii + 1];
}
Expand All @@ -358,19 +372,19 @@ void DGPIDSelector::combinations(int n0, std::vector<uint>& pool, int np, std::v

// -----------------------------------------------------------------------------
// find all possible selections of np out of n0
int DGPIDSelector::combinations(int n0, int np, std::vector<std::vector<uint>>& combs)
int DGPIDSelector::combinations(int n0, int np, std::vector<std::vector<int>>& combs)
{
// initialisations
combs.clear();
if (n0 < np) {
return 0;
}

std::vector<uint> pool(n0, 0);
std::vector<int> pool(n0, 0);
for (auto ii = 0; ii < n0; ii++) {
pool[ii] = ii;
}
std::vector<uint> inds(np, 0);
std::vector<int> inds(np, 0);

// iterate recursively
combinations(n0, pool, np, inds, 0, combs);
Expand All @@ -379,21 +393,21 @@ int DGPIDSelector::combinations(int n0, int np, std::vector<std::vector<uint>>&
}

// -----------------------------------------------------------------------------
std::vector<std::vector<uint>> DGPIDSelector::combinations(int nPool)
std::vector<std::vector<int>> DGPIDSelector::combinations(int nPool)
{
// get the unique permutations
auto uniquePerms = mAnaPars.uniquePermutations();
auto numUniquePerms = uniquePerms.size() / mAnaPars.nCombine();

// all selections of nCombine elements from nPool elements
std::vector<std::vector<uint>> combs;
std::vector<std::vector<int>> combs;
combinations(nPool, mAnaPars.nCombine(), combs);

// permute the combinations
std::vector<std::vector<uint>> copes;
std::vector<std::vector<int>> copes;
for (auto comb : combs) {
for (auto ii = 0u; ii < numUniquePerms; ii++) {
std::vector<uint> cope(mAnaPars.nCombine(), 0);
std::vector<int> cope(mAnaPars.nCombine(), 0);
for (auto jj = 0; jj < mAnaPars.nCombine(); jj++) {
auto ind = ii * mAnaPars.nCombine() + jj;
cope[uniquePerms[ind]] = comb[jj];
Expand All @@ -402,15 +416,6 @@ std::vector<std::vector<uint>> DGPIDSelector::combinations(int nPool)
}
}

// print copes
LOGF(debug, "copes");
for (auto cope : copes) {
LOGF(debug, " cope");
for (auto ind : cope) {
LOGF(debug, " %i", ind);
}
}

return copes;
}

Expand Down
Loading