Commit 51baa1ed authored by Matt Cumber's avatar Matt Cumber
Browse files

Re #29025 allow multiple time zeros

Updated LoadMuonNexusV2 and it's unit tests
parent b6974ffa
......@@ -31,6 +31,8 @@ public:
virtual API::Workspace_sptr loadDetectorGrouping() const = 0;
// Load dead time table
virtual API::Workspace_sptr loadDeadTimeTable() const = 0;
// Set time zero table
virtual API::Workspace_sptr setTimeZeroTable() const = 0;
protected:
// Create grouping table
......@@ -42,8 +44,9 @@ protected:
createDeadTimeTable(const std::vector<detid_t> &detectorsLoaded,
const std::vector<double> &deadTimes) const;
DataObjects::TableWorkspace_sptr LoadMuonStrategy::createTimeZeroTable(
const std::vector<double> &timeZeros) const;
DataObjects::TableWorkspace_sptr
createTimeZeroTable(const size_t numSpec,
const std::vector<double> &timeZeros) const;
API::Workspace_sptr loadDefaultDetectorGrouping(
const DataObjects::Workspace2D &localWorkspace) const;
......
......@@ -27,6 +27,8 @@ public:
API::Workspace_sptr loadDetectorGrouping() const override;
// Load dead time table
API::Workspace_sptr loadDeadTimeTable() const override;
// Set time zero table
API::Workspace_sptr setTimeZeroTable() const override;
private:
API::WorkspaceGroup &m_workspaceGroup;
......
......@@ -29,6 +29,8 @@ public:
API::Workspace_sptr loadDetectorGrouping() const override;
// Load dead time table
API::Workspace_sptr loadDeadTimeTable() const override;
// Set time zero table
API::Workspace_sptr setTimeZeroTable() const override;
private:
DataObjects::Workspace2D &m_workspace;
......
......@@ -8,11 +8,13 @@
#include "MantidAPI/Axis.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidDataHandling/LoadISISNexus2.h"
#include "MantidDataHandling/MultiPeriodLoadMuonStrategy.h"
#include "MantidDataHandling/SinglePeriodLoadMuonStrategy.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/BoundedValidator.h"
......@@ -178,11 +180,10 @@ void LoadMuonNexusV2::execLoader() {
}
// Time Zero table should be returned if found
const std::vector<double> timeZeros = getProperty("TimeZeroList");
if (!timeZeros.empty()) {
// Create table and set property
//setProperty("TimeZeroTable",
// m_loadMuonStrategy->createTimeZeroTable(timeZeros));
if (!getPropertyValue("TimeZerotable").empty()) {
// Create table and set property]
auto timeZeroTable = m_loadMuonStrategy->setTimeZeroTable();
setProperty("TimeZeroTable", timeZeroTable);
}
}
......
......@@ -130,15 +130,17 @@ DataObjects::TableWorkspace_sptr LoadMuonStrategy::createDeadTimeTable(
* @return TableWorkspace of time zeros
*/
DataObjects::TableWorkspace_sptr LoadMuonStrategy::createTimeZeroTable(
const std::vector<double> &timeZeros) const {
auto timeZeroTable = std::dynamic_pointer_cast<DataObjects::TableWorkspace>(
API::WorkspaceFactory::Instance().createTable("TableWorkspace"));
const size_t numSpec, const std::vector<double> &timeZeros) const {
Mantid::DataObjects::TableWorkspace_sptr timeZeroTable =
std::dynamic_pointer_cast<Mantid::DataObjects::TableWorkspace>(
Mantid::API::WorkspaceFactory::Instance().createTable(
"TableWorkspace"));
assert(timeZeroTable);
timeZeroTable->addColumn("double", "time zero");
for (size_t i = 0; i < timeZeros.size(); ++i) {
API::TableRow row = timeZeroTable->appendRow();
row << timeZeros[i];
for (size_t specNum = 0; specNum < numSpec; ++specNum) {
Mantid::API::TableRow row = timeZeroTable->appendRow();
row << timeZeros[specNum];
}
return timeZeroTable;
......
......@@ -119,6 +119,20 @@ API::Workspace_sptr MultiPeriodLoadMuonStrategy::loadDeadTimeTable() const {
return tableGroup;
}
/**
* Sets time zero table from loaded time zeros
* Assumes all peridos have same time zero
* @returns :: Time zero table
*/
Workspace_sptr MultiPeriodLoadMuonStrategy::setTimeZeroTable() const {
const double timeZero = m_nexusLoader.loadTimeZeroFromNexusFile();
auto workspace =
std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(0));
const auto numSpec = workspace->getNumberHistograms();
std::vector<double> timeZeros(numSpec, timeZero);
return createTimeZeroTable(numSpec, timeZeros);
}
/**
* Finds the detectors which are loaded in the stored workspace group
*/
......
......@@ -93,6 +93,16 @@ Workspace_sptr SinglePeriodLoadMuonStrategy::loadDeadTimeTable() const {
m_detectors, m_isFileMultiPeriod, m_entryNumber);
return createDeadTimeTable(m_detectors, deadTimes);
}
/**
* Sets time zero table from loaded time zeros
* @returns :: Time zero table
*/
Workspace_sptr SinglePeriodLoadMuonStrategy::setTimeZeroTable() const {
const double timeZero = m_nexusLoader.loadTimeZeroFromNexusFile();
const auto numSpec = m_workspace.getNumberHistograms();
std::vector<double> timeZeros(numSpec, timeZero);
return createTimeZeroTable(numSpec, timeZeros);
}
/**
* Performs time-zero correction on the loaded workspace.
*/
......
......@@ -124,6 +124,37 @@ public:
TS_ASSERT_DELTA(deadTimeTable->Double(62, 1), 0.0073113599, 1e-6);
}
void testExecWithTimeZeroTable() {
LoadMuonNexusV2 ld;
ld.initialize();
ld.setPropertyValue("Filename", "EMU00102347.nxs_v2");
ld.setPropertyValue("OutputWorkspace", "outWS");
ld.setPropertyValue("TimeZeroTable", "tzt");
TS_ASSERT_THROWS_NOTHING(ld.execute());
TS_ASSERT(ld.isExecuted());
// Verify that the output workspace exists
MatrixWorkspace_sptr output_ws;
TS_ASSERT_THROWS_NOTHING(
output_ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
"outWS"));
Workspace2D_sptr output2D =
std::dynamic_pointer_cast<Workspace2D>(output_ws);
TableWorkspace_sptr tbl;
TS_ASSERT_THROWS_NOTHING(
tbl =
AnalysisDataService::Instance().retrieveWS<TableWorkspace>("tzt"));
TS_ASSERT(tbl);
// Check number of rows and columns
TS_ASSERT_EQUALS(tbl->columnCount(), 1);
TS_ASSERT_EQUALS(tbl->rowCount(), output2D->getNumberHistograms());
TS_ASSERT_DELTA(tbl->Double(0, 0), 0.16, 0.001);
TS_ASSERT_DELTA(tbl->Double(47, 0), 0.16, 0.001);
TS_ASSERT_DELTA(tbl->Double(95, 0), 0.16, 0.001);
}
void testExecWithGroupingTable() {
LoadMuonNexusV2 ld;
......
......@@ -219,22 +219,25 @@ public:
alg.setProperty("Filename", getTestFilePath("deltat_tdc_dolly_1529.bin"));
alg.setProperty("OutputWorkspace", "ws");
alg.setProperty("TimeZeroTable", "tzt");
alg.setPropertyValue("TimeZeroTable", "tzt");
alg.execute();
ITableWorkspace_sptr tbl;
TS_ASSERT_THROWS_NOTHING(
tbl = AnalysisDataService::Instance().retrieveWS<TableWorkspace>("tzt"));
tbl =
AnalysisDataService::Instance().retrieveWS<TableWorkspace>("tzt"));
TS_ASSERT(tbl);
TS_ASSERT_EQUALS(tbl->columnCount(), 1);
TS_ASSERT_EQUALS(tbl->getColumnNames(), std::vector<std::string>{"time zero"});
TS_ASSERT_EQUALS(tbl->getColumnNames(),
std::vector<std::string>{"time zero"});
TS_ASSERT_EQUALS(tbl->rowCount(), 4);
TS_ASSERT_DELTA(tbl->getColumn(0)->toDouble(0), 0.1582, 0.0001);
TS_ASSERT_DELTA(tbl->getColumn(0)->toDouble(1), 0.1553, 0.0001);
TS_ASSERT_DELTA(tbl->getColumn(0)->toDouble(2), 0.1592, 0.0001);
TS_ASSERT_DELTA(tbl->getColumn(0)->toDouble(3), 0.1602, 0.0001);
}
void test_dead_time_table_loaded_correctly() {
LoadPSIMuonBin alg;
alg.initialize();
......@@ -243,7 +246,7 @@ public:
alg.setProperty("Filename", getTestFilePath("deltat_tdc_dolly_1529.bin"));
alg.setProperty("OutputWorkspace", "ws");
alg.setProperty("DeadTimeTable", "dtt");
alg.setPropertyValue("DeadTimeTable", "dtt");
alg.execute();
ITableWorkspace_sptr tbl;
......@@ -251,8 +254,9 @@ public:
tbl =
AnalysisDataService::Instance().retrieveWS<TableWorkspace>("dtt"));
TS_ASSERT(tbl);
TS_ASSERT_EQUALS(tbl->columnCount(), 2);
std::vector<std::string> colNames{"spectrum","dead-time"};
std::vector<std::string> colNames{"spectrum", "dead-time"};
TS_ASSERT_EQUALS(tbl->getColumnNames(), colNames);
TS_ASSERT_EQUALS(tbl->rowCount(), 4);
TS_ASSERT_EQUALS(tbl->getColumn(0)->toDouble(0), 1.0);
......@@ -264,7 +268,7 @@ public:
TS_ASSERT_EQUALS(tbl->getColumn(0)->toDouble(3), 4.0);
TS_ASSERT_EQUALS(tbl->getColumn(1)->toDouble(3), 0.0);
}
void test_uncorected_time_loaded_if_corrected_time_flag_is_false() {
LoadPSIMuonBin alg;
alg.initialize();
......
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