Skip to content

Commit

Permalink
Refs #8534. GroupAsymmetry option support.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Dec 2, 2013
1 parent 952d87b commit 657c61a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,38 @@ namespace WorkflowAlgorithms
{
const std::string type = getPropertyValue("OutputType");

if ( type == "GroupCounts" )
if ( type == "GroupCounts" || type == "GroupAsymmetry" )
{
// The simpliest one - just copy the counts of some group

int groupIndex = getProperty("GroupIndex");

if ( groupIndex == EMPTY_INT() )
throw std::runtime_error("GroupIndex is not specified");

// Yank out the counts of requested group
IAlgorithm_sptr alg = createChildAlgorithm("ExtractSingleSpectrum");
alg->initialize();
alg->setProperty("InputWorkspace", ws);
alg->setProperty("WorkspaceIndex", groupIndex);
alg->execute();

return alg->getProperty("OutputWorkspace");

MatrixWorkspace_sptr outWS = alg->getProperty("OutputWorkspace");

if ( type == "GroupAsymmetry" )
{
// GroupAsymmetry - counts with ExpDecay removed and normalized

IAlgorithm_sptr alg = createChildAlgorithm("RemoveExpDecay");
alg->initialize();
alg->setProperty("InputWorkspace", outWS);
alg->execute();

outWS = alg->getProperty("OutputWorkspace");
}

return outWS;
}

throw std::invalid_argument("Specified OutputType is not supported");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cxxtest/TestSuite.h>

#include "MantidAPI/FrameworkManager.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidWorkflowAlgorithms/MuonCalculateAsymmetry.h"

Expand All @@ -20,6 +21,11 @@ class MuonCalculateAsymmetryTest : public CxxTest::TestSuite
static MuonCalculateAsymmetryTest *createSuite() { return new MuonCalculateAsymmetryTest(); }
static void destroySuite( MuonCalculateAsymmetryTest *suite ) { delete suite; }

MuonCalculateAsymmetryTest()
{
// To make sure everything is loaded
FrameworkManager::Instance();
}

void test_Init()
{
Expand Down Expand Up @@ -159,6 +165,48 @@ class MuonCalculateAsymmetryTest : public CxxTest::TestSuite
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}

void test_groupAsymmetry()
{
// Name of the output workspace.
const std::string outWSName = outputWorkspaceName("GroupAsymmetry");

MatrixWorkspace_sptr inWS = createWorkspace();

MuonCalculateAsymmetry alg;
alg.initialize();
TS_ASSERT_THROWS_NOTHING( alg.setProperty("FirstPeriodWorkspace", inWS) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("OutputType", "GroupAsymmetry") );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("GroupIndex", 2) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) );
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );

// Retrieve the workspace from data service.
auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName);
TS_ASSERT(ws);

if (ws)
{
TS_ASSERT_EQUALS( ws->getNumberHistograms(), 1 );
TS_ASSERT_EQUALS( ws->blocksize(), 3 );

TS_ASSERT_DELTA( ws->readY(0)[0], -0.247, 0.001 );
TS_ASSERT_DELTA( ws->readY(0)[1], 0.356, 0.001 );
TS_ASSERT_DELTA( ws->readY(0)[2], 1.405, 0.001 );

TS_ASSERT_EQUALS( ws->readX(0)[0], 1 );
TS_ASSERT_EQUALS( ws->readX(0)[1], 2 );
TS_ASSERT_EQUALS( ws->readX(0)[2], 3 );

TS_ASSERT_DELTA( ws->readE(0)[0], 0.075, 0.01 );
TS_ASSERT_DELTA( ws->readE(0)[1], 0.136, 0.01 );
TS_ASSERT_DELTA( ws->readE(0)[2], 0.240, 0.01 );
}

// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}

private:

Expand Down

0 comments on commit 657c61a

Please sign in to comment.