Commit fe5bd167 authored by Anthony Lim's avatar Anthony Lim
Browse files

updated fitting range for PSI background subtraction

parent 9478f730
......@@ -20,17 +20,20 @@ namespace {
constexpr char *WORKSPACE_NAME = "DummyWS";
MatrixWorkspace_sptr createCountsTestWorkspace(const size_t numberOfHistograms,
const size_t numberOfBins) {
const size_t numberOfBins,bool addLogs = true) {
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::create2DWorkspace(
numberOfHistograms, numberOfBins);
ws->setYUnit("Counts");
for (int index = 0; index < numberOfHistograms; index++) {
ws->mutableRun().addProperty("First good spectra "+std::to_string(index), int(numberOfBins/2.));
ws->mutableRun().addProperty("Last good spectra " +
std::to_string(index), numberOfBins);
if (addLogs) {
for (int index = 0; index < numberOfHistograms; index++) {
ws->mutableRun().addProperty("First good spectra " +
std::to_string(index),
int(numberOfBins / 2.));
ws->mutableRun().addProperty("Last good spectra " + std::to_string(index),
numberOfBins);
}
}
AnalysisDataService::Instance().addOrReplace(WORKSPACE_NAME, ws);
......@@ -100,6 +103,78 @@ public:
clearADS();
}
void test_that_algorithm_does_not_execute_if_no_good_data() {
PSIBackgroundSubtraction alg;
auto ws = createCountsTestWorkspace(2, 100, false);
alg.initialize();
alg.setProperty("InputWorkspace", ws);
TS_ASSERT_THROWS(alg.execute(), const std::runtime_error &);
clearADS();
}
void test_that_algorithm_does_not_execute_if_bad_first_good_data() {
PSIBackgroundSubtraction alg;
int numberOfHistograms = 2;
int numberOfBins = 100;
auto ws =
createCountsTestWorkspace(numberOfHistograms, numberOfBins, false);
for (int index = 0; index < numberOfHistograms; index++) {
ws->mutableRun().addProperty("First good spectra " +
std::to_string(index),
-1);
ws->mutableRun().addProperty("Last good spectra " + std::to_string(index),
numberOfBins-10);
}
alg.initialize();
alg.setProperty("InputWorkspace", ws);
TS_ASSERT_THROWS(alg.execute(), const std::runtime_error &);
clearADS();
}
void test_that_algorithm_does_not_execute_if_bad_last_good_data() {
PSIBackgroundSubtraction alg;
int numberOfHistograms = 2;
int numberOfBins = 100;
auto ws =
createCountsTestWorkspace(numberOfHistograms, numberOfBins, false);
for (int index = 0; index < numberOfHistograms; index++) {
ws->mutableRun().addProperty(
"First good spectra " + std::to_string(index), 1);
ws->mutableRun().addProperty("Last good spectra " + std::to_string(index),
numberOfBins*2);
}
alg.initialize();
alg.setProperty("InputWorkspace", ws);
TS_ASSERT_THROWS(alg.execute(), const std::runtime_error &);
clearADS();
}
void test_that_algorithm_does_not_execute_if_last_before_first_good_data() {
PSIBackgroundSubtraction alg;
int numberOfHistograms = 2;
int numberOfBins = 100;
auto ws =
createCountsTestWorkspace(numberOfHistograms, numberOfBins, false);
for (int index = 0; index < numberOfHistograms; index++) {
ws->mutableRun().addProperty(
"First good spectra " + std::to_string(index), 50);
ws->mutableRun().addProperty("Last good spectra " + std::to_string(index),
40);
}
alg.initialize();
alg.setProperty("InputWorkspace", ws);
TS_ASSERT_THROWS(alg.execute(), const std::runtime_error &);
clearADS();
}
void test_background_correctly_removed_from_input_workspace() {
MockPSIBackgroundSubtraction alg;
double background = 20;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment