From df65e8bd8673d02099a4afc4751c55d236e8f875 Mon Sep 17 00:00:00 2001 From: T Jubb <t.w.jubb@gmail.com> Date: Thu, 31 May 2018 10:16:39 +0100 Subject: [PATCH] Refs #22373 Fix rebin bug, add unit test check for future. --- .../MantidMuon/ApplyMuonDetectorGrouping.h | 2 +- .../Muon/src/ApplyMuonDetectorGrouping.cpp | 10 +-- .../Muon/test/ApplyMuonDetectorGroupingTest.h | 63 +++++++++++++++++++ 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/Framework/Muon/inc/MantidMuon/ApplyMuonDetectorGrouping.h b/Framework/Muon/inc/MantidMuon/ApplyMuonDetectorGrouping.h index ea9ef8bf3be..0bb2d4d129d 100644 --- a/Framework/Muon/inc/MantidMuon/ApplyMuonDetectorGrouping.h +++ b/Framework/Muon/inc/MantidMuon/ApplyMuonDetectorGrouping.h @@ -79,7 +79,7 @@ private: /// Creates and analyses a workspace, if noRebin does not rebin. API::Workspace_sptr createAnalysisWorkspace(API::Workspace_sptr inputWS, bool noRebin, - Muon::AnalysisOptions &options); + Muon::AnalysisOptions options); /// Sets algorithm properties according to options. void setMuonProcessAlgorithmProperties(API::IAlgorithm &alg, const AnalysisOptions &options) const; diff --git a/Framework/Muon/src/ApplyMuonDetectorGrouping.cpp b/Framework/Muon/src/ApplyMuonDetectorGrouping.cpp index 49a17357593..f50b466452c 100644 --- a/Framework/Muon/src/ApplyMuonDetectorGrouping.cpp +++ b/Framework/Muon/src/ApplyMuonDetectorGrouping.cpp @@ -294,21 +294,21 @@ void ApplyMuonDetectorGrouping::clipXRangeToWorkspace( * Creates workspace, processing the data using the MuonProcess algorithm. */ Workspace_sptr ApplyMuonDetectorGrouping::createAnalysisWorkspace( - Workspace_sptr inputWS, bool noRebin, Muon::AnalysisOptions &options) { + Workspace_sptr inputWS, bool noRebin, Muon::AnalysisOptions options) { IAlgorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("MuonProcess"); + if (noRebin) { + options.rebinArgs = ""; + } + alg->initialize(); setMuonProcessPeriodProperties(*alg, inputWS, options); setMuonProcessAlgorithmProperties(*alg, options); alg->setChild(true); alg->setPropertyValue("OutputWorkspace", "__NotUsed__"); - if (noRebin) { - options.rebinArgs = ""; - } - alg->execute(); return alg->getProperty("OutputWorkspace"); } diff --git a/Framework/Muon/test/ApplyMuonDetectorGroupingTest.h b/Framework/Muon/test/ApplyMuonDetectorGroupingTest.h index 7fc00abc9c5..6afaaf87828 100644 --- a/Framework/Muon/test/ApplyMuonDetectorGroupingTest.h +++ b/Framework/Muon/test/ApplyMuonDetectorGroupingTest.h @@ -772,6 +772,69 @@ public: TS_ASSERT_DELTA(wsOut->readE(0)[4], 0.0050, 0.0001); TS_ASSERT_DELTA(wsOut->readE(0)[9], 0.0050, 0.0001); } + + void test_rebinning() { + std::string emptyString(""); + + auto ws = createCountsWorkspace(3, 10, 0.0); + auto wsGroup = boost::make_shared<WorkspaceGroup>(); + AnalysisDataService::Instance().addOrReplace("inputData", ws); + AnalysisDataService::Instance().addOrReplace("inputGroup", wsGroup); + + TS_ASSERT_EQUALS(wsGroup->getNumberOfEntries(), 0); + + ApplyMuonDetectorGrouping alg; + TS_ASSERT_THROWS_NOTHING(alg.initialize()); + TS_ASSERT(alg.isInitialized()); + + TS_ASSERT_THROWS_NOTHING(alg.setProperty("InputWorkspace", ws->getName())); + TS_ASSERT_THROWS_NOTHING( + alg.setProperty("InputWorkspaceGroup", wsGroup->getName())); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("groupName", "test2")); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("Grouping", "1")); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("AnalysisType", "Counts")); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("TimeMin", 0.0)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("TimeMax", 30.0)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("RebinArgs", "0.2")); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("TimeOffset", 0.0)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("SummedPeriods", "1")); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("SubtractedPeriods", emptyString)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("ApplyDeadTimeCorrection", false)); + TS_ASSERT_THROWS_NOTHING(alg.execute()); + TS_ASSERT(alg.isExecuted()); + + TS_ASSERT(wsGroup); + if (wsGroup) { + TS_ASSERT_EQUALS(wsGroup->getNumberOfEntries(), 2); + } + + TS_ASSERT(wsGroup->getItem("inputGroup; Group; test2; Counts; #1")); + TS_ASSERT(wsGroup->getItem("inputGroup; Group; test2; Counts; #1_Raw")); + + auto wsOutNoRebin = boost::dynamic_pointer_cast<MatrixWorkspace>( + wsGroup->getItem("inputGroup; Group; test2; Counts; #1_Raw")); + + // Check values against calculation by hand. + TS_ASSERT_DELTA(wsOutNoRebin->readX(0)[0], 0.000, 0.001); + TS_ASSERT_DELTA(wsOutNoRebin->readX(0)[4], 0.400, 0.001); + TS_ASSERT_DELTA(wsOutNoRebin->readX(0)[9], 0.900, 0.001); + + auto wsOut = boost::dynamic_pointer_cast<MatrixWorkspace>( + wsGroup->getItem("inputGroup; Group; test2; Counts; #1")); + + // Check values against calculation by hand. + TS_ASSERT_DELTA(wsOut->readX(0)[0], 0.000, 0.001); + TS_ASSERT_DELTA(wsOut->readX(0)[1], 0.200, 0.001); + TS_ASSERT_DELTA(wsOut->readX(0)[4], 0.800, 0.001); + + TS_ASSERT_DELTA(wsOut->readY(0)[0], 1, 0.1); + TS_ASSERT_DELTA(wsOut->readY(0)[1], 5, 0.1); + TS_ASSERT_DELTA(wsOut->readY(0)[4], 17, 0.1); + + TS_ASSERT_DELTA(wsOut->readE(0)[0], 0.00707, 0.0001); + TS_ASSERT_DELTA(wsOut->readE(0)[1], 0.00707, 0.0001); + TS_ASSERT_DELTA(wsOut->readE(0)[4], 0.00707, 0.0001); + } }; #endif /* MANTID_MUON_APPLYMUONDETECTORGROUPINGTEST_H_ */ -- GitLab