Skip to content

Commit

Permalink
Refactor and simplify pol index correction
Browse files Browse the repository at this point in the history
RE #35067

Co-authored-by: Yusuf Jimoh  <[email protected]>
  • Loading branch information
cailafinn and yusufjimoh committed Aug 16, 2024
1 parent a2a8e31 commit 8ce6029
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions Framework/Algorithms/test/PolarizationCorrectionWildesTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,28 +597,8 @@ class PolarizationCorrectionWildesTest : public CxxTest::TestSuite {
if (!spinStates.empty()) {
compareCorrectionResults(
outputWS, pols, nHist, nBins, edges, counts,
[&](size_t wsIndex, double c) {
if (pols[wsIndex] == "_++")
wsIndex = 0;
else if (pols[wsIndex] == "_+-")
wsIndex = 1;
else if (pols[wsIndex] == "_-+")
wsIndex = 2;
else if (pols[wsIndex] == "_--")
wsIndex = 3;
return c * static_cast<double>(wsIndex + 1);
},
[&](size_t wsIndex, double c) {
if (pols[wsIndex] == "_++")
wsIndex = 0;
else if (pols[wsIndex] == "_+-")
wsIndex = 1;
else if (pols[wsIndex] == "_-+")
wsIndex = 2;
else if (pols[wsIndex] == "_--")
wsIndex = 3;
return std::sqrt(c) * static_cast<double>(wsIndex + 1);
});
[&](size_t wsIndex, double c) { return c * static_cast<double>(getPolIndex(pols[wsIndex]) + 1); },
[&](size_t wsIndex, double c) { return std::sqrt(c) * static_cast<double>(getPolIndex(pols[wsIndex]) + 1); });
} else {
compareCorrectionResults(
outputWS, pols, nHist, nBins, edges, counts,
Expand Down Expand Up @@ -1374,6 +1354,15 @@ class PolarizationCorrectionWildesTest : public CxxTest::TestSuite {
}
idealCaseFullCorrectionsTest(edges, effWS, outputOrder, flipperConfig, spinStates);
}

size_t getPolIndex(const std::string &pol) {
static const std::unordered_map<std::string, size_t> polMap = {{"_++", 0}, {"_+-", 1}, {"_-+", 2}, {"_--", 3}};
const auto it = polMap.find(pol);
if (it != polMap.end()) {
return it->second;
}
throw std::invalid_argument("Unknown polarization string: " + pol);
}
};

class PolarizationCorrectionWildesTestPerformance : public CxxTest::TestSuite {
Expand Down

0 comments on commit 8ce6029

Please sign in to comment.