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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class DLLExport AlignAndFocusPowder : public API::DataProcessorAlgorithm {
/// Call diffraction focus to a matrix workspace.
API::MatrixWorkspace_sptr diffractionFocus(API::MatrixWorkspace_sptr ws);

/// Call diffraction focus to a matrix workspace with ragged rebin parameters
API::MatrixWorkspace_sptr diffractionFocusRaggedRebinInDspace(API::MatrixWorkspace_sptr ws);

/// Convert units
API::MatrixWorkspace_sptr convertUnits(API::MatrixWorkspace_sptr matrixws, const std::string &target);

Expand Down
71 changes: 54 additions & 17 deletions Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,23 +757,31 @@ void AlignAndFocusPowder::exec() {
setProperty("UnfocussedWorkspace", std::move(wkspCopy));
}

// Diffraction focus
m_outputW = diffractionFocus(m_outputW);
if (m_processLowResTOF)
m_lowResW = diffractionFocus(m_lowResW);
m_progress->report();

// this next call should probably be in for rebin as well
// but it changes the system tests
if (binInDspace) {
if (m_resampleX != 0.) {
m_outputW = rebin(m_outputW);
if (m_processLowResTOF)
m_lowResW = rebin(m_lowResW);
} else if (!m_delta_ragged.empty()) {
m_outputW = rebinRagged(m_outputW, true);
if (m_processLowResTOF)
m_lowResW = rebinRagged(m_lowResW, true);
if (binInDspace && m_resampleX == 0 && !m_delta_ragged.empty() && !m_dmins.empty() && !m_dmaxs.empty()) {
// Special case where we can do ragged rebin within diffraction focus
m_outputW = diffractionFocusRaggedRebinInDspace(m_outputW);
if (m_processLowResTOF)
m_lowResW = diffractionFocusRaggedRebinInDspace(m_lowResW);
m_progress->report();
} else {
// Diffraction focus
m_outputW = diffractionFocus(m_outputW);
if (m_processLowResTOF)
m_lowResW = diffractionFocus(m_lowResW);
m_progress->report();

// this next call should probably be in for rebin as well
// but it changes the system tests
if (binInDspace) {
if (m_resampleX != 0.) {
m_outputW = rebin(m_outputW);
if (m_processLowResTOF)
m_lowResW = rebin(m_lowResW);
} else if (!m_delta_ragged.empty()) {
m_outputW = rebinRagged(m_outputW, true);
if (m_processLowResTOF)
m_lowResW = rebinRagged(m_lowResW, true);
}
}
}
m_progress->report();
Expand Down Expand Up @@ -881,6 +889,35 @@ API::MatrixWorkspace_sptr AlignAndFocusPowder::diffractionFocus(API::MatrixWorks
return ws;
}

//----------------------------------------------------------------------------------------------
/** Call diffraction focus to a matrix workspace with ragged rebin parameters
*/
API::MatrixWorkspace_sptr AlignAndFocusPowder::diffractionFocusRaggedRebinInDspace(API::MatrixWorkspace_sptr ws) {
if (!m_groupWS) {
g_log.information() << "not focussing data\n";
return ws;
}

API::IAlgorithm_sptr focusAlg = createChildAlgorithm("DiffractionFocussing");
focusAlg->setProperty("InputWorkspace", ws);
focusAlg->setProperty("OutputWorkspace", ws);
focusAlg->setProperty("GroupingWorkspace", m_groupWS);
focusAlg->setProperty("PreserveEvents", m_preserveEvents);
focusAlg->setProperty("DMin", m_dmins);
focusAlg->setProperty("DMax", m_dmaxs);
focusAlg->setProperty("Delta", m_delta_ragged);

g_log.information() << "running DiffractionFocussing(PreserveEvents=" << m_preserveEvents;
g_log.information() << " XMin=" << focusAlg->getPropertyValue("DMin");
g_log.information() << " XMax=" << focusAlg->getPropertyValue("DMax");
g_log.information() << " Delta=" << focusAlg->getPropertyValue("Delta");
g_log.information() << ") started at " << Types::Core::DateAndTime::getCurrentTime() << "\n";

focusAlg->executeAsChildAlg();
ws = focusAlg->getProperty("OutputWorkspace");

return ws;
}
//----------------------------------------------------------------------------------------------
/** Convert units
*/
Expand Down
57 changes: 55 additions & 2 deletions Framework/WorkflowAlgorithms/test/AlignAndFocusPowderTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,59 @@ class AlignAndFocusPowderTest : public CxxTest::TestSuite {
AnalysisDataService::Instance().remove(m_outputWS);
}

void testEventWksp_preserveEvents_ragged() {
// Setup the event workspace
m_numBanks = 2;
setUp_EventWorkspace("EventWksp_preserveEvents_ragged");
m_numBanks = 1;

groupAllBanks(m_inputWS, "bank"); // should result in 2 output histograms

for (bool preserveEvents : {true, false}) {

AlignAndFocusPowder align_and_focus;
align_and_focus.initialize();
align_and_focus.setPropertyValue("InputWorkspace", m_inputWS);
align_and_focus.setPropertyValue("OutputWorkspace", m_outputWS);
align_and_focus.setProperty("GroupingWorkspace", m_groupWS);
align_and_focus.setProperty("DMin", std::vector<double>{0.2, 0.3});
align_and_focus.setProperty("DMax", std::vector<double>{1.5, 2.0});
align_and_focus.setProperty("DeltaRagged", std::vector<double>{-2., -1.});
align_and_focus.setProperty("Dspacing", true);
align_and_focus.setProperty("PreserveEvents", preserveEvents);
TS_ASSERT_THROWS_NOTHING(align_and_focus.execute());
TS_ASSERT(align_and_focus.isExecuted());

m_outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(m_outputWS);

// test the output
if (preserveEvents)
TS_ASSERT_EQUALS(m_outWS->id(), "EventWorkspace")
else
TS_ASSERT_EQUALS(m_outWS->id(), "Workspace2D")

TS_ASSERT_EQUALS(m_outWS->getAxis(0)->unit()->unitID(), "TOF");
TS_ASSERT_EQUALS(m_outWS->getNumberHistograms(), 2);

TS_ASSERT_EQUALS(m_outWS->x(0).size(), 3);
TS_ASSERT_EQUALS(m_outWS->x(1).size(), 4);
TS_ASSERT_EQUALS(m_outWS->y(0).size(), 2);
TS_ASSERT_EQUALS(m_outWS->y(1).size(), 3);
TS_ASSERT_DELTA(m_outWS->x(0)[0], 1066.4818329, 0.0001);
TS_ASSERT_DELTA(m_outWS->x(0)[1], 3199.4454987, 0.0001);
TS_ASSERT_DELTA(m_outWS->x(1)[0], 1599.7227493, 0.0001);
TS_ASSERT_DELTA(m_outWS->x(1)[1], 3199.4454987, 0.0001);
TS_ASSERT_DELTA(m_outWS->y(0)[0], 13968, 0.0001);
TS_ASSERT_DELTA(m_outWS->y(0)[1], 113472, 0.0001);
TS_ASSERT_DELTA(m_outWS->y(1)[0], 13968, 0.0001);
TS_ASSERT_DELTA(m_outWS->y(1)[1], 82512, 0.0001);

AnalysisDataService::Instance().remove(m_outputWS);
}
AnalysisDataService::Instance().remove(m_inputWS);
AnalysisDataService::Instance().remove(m_groupWS);
}

void testEventWksp_preserveEvents_tmin_tmax() {
// Setup the event workspace
setUp_EventWorkspace("EventWksp_preserveEvents_tmin_tmax");
Expand Down Expand Up @@ -859,11 +912,11 @@ class AlignAndFocusPowderTest : public CxxTest::TestSuite {
loadDiffAlg.execute();
}

void groupAllBanks(const std::string &m_inputWS) {
void groupAllBanks(const std::string &m_inputWS, std::string group_by = "All") {
CreateGroupingWorkspace groupAlg;
groupAlg.initialize();
groupAlg.setPropertyValue("InputWorkspace", m_inputWS);
groupAlg.setPropertyValue("GroupDetectorsBy", "All");
groupAlg.setPropertyValue("GroupDetectorsBy", group_by);
groupAlg.setPropertyValue("OutputWorkspace", m_groupWS);
groupAlg.execute();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- :ref:`AlignAndFocusPowder <algm-AlignAndFocusPowder-v1>` has been modified to utilize the new binning parameters added to :ref:`DiffractionFocussing <algm-DiffractionFocussing-v2>`.
Loading