Skip to content

Commit

Permalink
Added logic to check for L1.
Browse files Browse the repository at this point in the history
Added code to see if an L1 column is there in
the detector pars workspace.
Added unit test for with/without L1
refs #9880
  • Loading branch information
stuartcampbell committed Sep 15, 2014
1 parent e174dac commit 654aa32
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 5 deletions.
49 changes: 44 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp
Expand Up @@ -357,20 +357,59 @@ void ConvertUnits::convertViaTOF(Kernel::Unit_const_sptr fromUnit, API::MatrixWo

// Let's see if we are using a TableWorkspace to override parameters
ITableWorkspace_sptr paramWS = getProperty("DetectorParameters");

// Some
bool usingDetPars = false;
bool usingDetParsL1 = false;
Column_const_sptr l1Column;
Column_const_sptr l2Column;
Column_const_sptr spectraColumn;
Column_const_sptr twoThetaColumn;
Column_const_sptr efixedColumn;
Column_const_sptr emodeColumn;

// See if we have supplied a DetectorParameters Workspace
if ( paramWS != NULL )
{
usingDetPars = true;

// First lets see if the table includes L1 ?
try {
l1Column = paramWS->getColumn("l1");
if ( l1Column != NULL )
{
usingDetParsL1 = true;
g_log.notice() << "Overriding L1 from IDF with parameter table." << std::endl;
}

} catch (...) {
// make sure we know we are using L1 from the IDF
usingDetParsL1 = false;
g_log.debug() << "Could not find L1 in parameter table supplied - using values from IDF.";
}


// Now lets read the rest of the parameters
try {
l2Column = paramWS->getColumn("l2");
spectraColumn = paramWS->getColumn("spectra");
twoThetaColumn = paramWS->getColumn("twotheta");
efixedColumn = paramWS->getColumn("efixed");
emodeColumn = paramWS->getColumn("emode");
} catch (...) {
throw Exception::NotFoundError("DetectorParameter TableWorkspace is not defined correctly.");
}

}


ColumnVector<int> detPars_spectra = paramWS->getVector("spectra");
ColumnVector<double> detPars_l2 = paramWS->getVector("l2");
ColumnVector<double> detPars_twotheta = paramWS->getVector("twotheta");
ColumnVector<double> detPars_efixed = paramWS->getVector("efixed");
ColumnVector<int> detPars_emode = paramWS->getVector("emode");

if ( paramWS != NULL )
{
usingDetPars = true;
g_log.notice() << "Size of table == " << paramWS->rowCount() << std::endl;

}

EventWorkspace_sptr eventWS = boost::dynamic_pointer_cast<EventWorkspace>(outputWS);
assert ( static_cast<bool>(eventWS) == m_inputEvents ); // Sanity check
Expand Down
45 changes: 45 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h
Expand Up @@ -233,6 +233,51 @@ class ConvertUnitsTest : public CxxTest::TestSuite
AnalysisDataService::Instance().remove(workspaceName);
}

void testConvertUsingDetectorTablewithoutL1()
{
ConvertUnits myAlg;
myAlg.initialize();
TS_ASSERT(myAlg.isInitialized());

const std::string workspaceName("_ws_testConvertUsingDetectorTable");
int nBins = 10;
MatrixWorkspace_sptr WS = WorkspaceCreationHelper::Create2DWorkspaceBinned(2, nBins, 0.0, 10.0);
WS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");

AnalysisDataService::Instance().add(workspaceName,WS);

// Create TableWorkspace with values in it

ITableWorkspace_sptr pars = WorkspaceFactory::Instance().createTable("TableWorkspace");
pars->addColumn("int", "spectra");
pars->addColumn("double", "l2");
pars->addColumn("double", "twotheta");
pars->addColumn("double", "efixed");
pars->addColumn("int", "emode");

API::TableRow row0 = pars->appendRow();
row0 << 1 << 10.0 << 90.0 << 7.0 << 1;

API::TableRow row1 = pars->appendRow();
row1 << 2 << 10.0 << 90.0 << 7.0 << 1;

// Set the properties
myAlg.setRethrows(true);
myAlg.setPropertyValue("InputWorkspace", workspaceName);
myAlg.setPropertyValue("OutputWorkspace", workspaceName);
myAlg.setPropertyValue("Target", "Wavelength");
myAlg.setProperty("DetectorParameters", pars);

myAlg.execute();

auto outWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(workspaceName);

// TODO: test that output workspace values


AnalysisDataService::Instance().remove(workspaceName);
}

void testConvertQuickly()
{
ConvertUnits quickly;
Expand Down

0 comments on commit 654aa32

Please sign in to comment.