Skip to content

Commit

Permalink
use bit-logic with uint8_t, provide function documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Lubynets committed Dec 18, 2024
1 parent eff34e6 commit 47dcfe1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 4 additions & 4 deletions PWGHF/TableProducer/candidateCreator2Prong.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ struct HfCandidateCreator2Prong {
auto indexCollision = collision.globalIndex();
uint8_t indicesProngsContributorsPV = 0;
if (indexCollision == track0.collisionId() && track0.isPVContributor()) {
indicesProngsContributorsPV += 1;
SETBIT(indicesProngsContributorsPV, 0);
}
if (indexCollision == track1.collisionId() && track1.isPVContributor()) {
indicesProngsContributorsPV += 2;
SETBIT(indicesProngsContributorsPV, 1);
}

// fill candidate table rows
Expand Down Expand Up @@ -434,10 +434,10 @@ struct HfCandidateCreator2Prong {
auto indexCollision = collision.globalIndex();
uint8_t indicesProngsContributorsPV = 0;
if (indexCollision == track0.collisionId() && track0.isPVContributor()) {
indicesProngsContributorsPV += 1;
SETBIT(indicesProngsContributorsPV, 0);
}
if (indexCollision == track1.collisionId() && track1.isPVContributor()) {
indicesProngsContributorsPV += 2;
SETBIT(indicesProngsContributorsPV, 1);
}

// fill candidate table rows
Expand Down
6 changes: 3 additions & 3 deletions PWGHF/TableProducer/candidateCreator3Prong.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ struct HfCandidateCreator3Prong {
auto indexCollision = collision.globalIndex();
uint8_t indicesProngsContributorsPV = 0;
if (indexCollision == track0.collisionId() && track0.isPVContributor()) {
indicesProngsContributorsPV += 1;
SETBIT(indicesProngsContributorsPV, 0);
}
if (indexCollision == track1.collisionId() && track1.isPVContributor()) {
indicesProngsContributorsPV += 2;
SETBIT(indicesProngsContributorsPV, 1);
}
if (indexCollision == track2.collisionId() && track2.isPVContributor()) {
indicesProngsContributorsPV += 4;
SETBIT(indicesProngsContributorsPV, 2);
}

// fill candidate table rows
Expand Down
11 changes: 4 additions & 7 deletions PWGHF/Utils/utilsTrkCandHf.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ void setLabelHistoCands(Histo& hCandidates)
hCandidates->GetXaxis()->SetBinLabel(SVFitting::Fail + 1, "Run-time error in secondary vertexing");
}

/// @brief Function to evaluate number of ones in a binary representation of the argument
/// \param num is the input argument
int countOnesInBinary(uint8_t num)
{
int count = 0;

// Loop through all bits of the number (8 bits for uint8_t)
while (num > 0) {
// Increment count if the last bit is 1
count += num & 1;

// Right shift the number by 1 to check the next bit
num >>= 1;
for (int iBit = 0; iBit < 8; iBit++) {
count += TESTBIT(num, iBit);
}

return count;
Expand Down

0 comments on commit 47dcfe1

Please sign in to comment.