Commit b6974ffa authored by Matt Cumber's avatar Matt Cumber
Browse files

Re #29025 allow multiple time zeros

Added tests to LoadPSIMuonBin, started updating loadMuonNexusV2 but need clarification on time zero for multi-period data
parent c01803d4
......@@ -263,8 +263,6 @@ public:
std::vector<double> timeZeros = {0.5, 1.0, 1.5};
ITableWorkspace_sptr timeZeroTable = createTimeZeroTable(3, timeZeros);
const auto test = timeZeroTable->getRow(0);
TS_ASSERT_EQUALS(timeZeroTable->columnCount(), 1);
TS_ASSERT_EQUALS(timeZeroTable->rowCount(), 3);
TS_ASSERT_DELTA(timeZeroTable->getColumn(0)->toDouble(0), 0.5, 0.01);
......
......@@ -42,6 +42,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;
API::Workspace_sptr loadDefaultDetectorGrouping(
const DataObjects::Workspace2D &localWorkspace) const;
......
......@@ -125,6 +125,11 @@ void LoadMuonNexusV2::init() {
Direction::Output),
"A vector of time zero values");
declareProperty(
std::make_unique<WorkspaceProperty<Workspace>>(
"TimeZeroTable", "", Direction::Output, PropertyMode::Optional),
"TableWorkspace containing time zero values per spectra.");
declareProperty(
"CorrectTime", true,
"Boolean flag controlling whether time should be corrected by timezero.",
......@@ -171,6 +176,14 @@ void LoadMuonNexusV2::execLoader() {
if (!getPropertyValue("DeadTimeTable").empty()) {
setProperty("DeadTimeTable", deadtimeTable);
}
// 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));
}
}
/**
......
......@@ -124,5 +124,25 @@ DataObjects::TableWorkspace_sptr LoadMuonStrategy::createDeadTimeTable(
return deadTimesTable;
}
/**
* Creates a timezero table for the loaded detectors
* @param timeZeros :: Vector containing time zero values for each spectra
* @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"));
timeZeroTable->addColumn("double", "time zero");
for (size_t i = 0; i < timeZeros.size(); ++i) {
API::TableRow row = timeZeroTable->appendRow();
row << timeZeros[i];
}
return timeZeroTable;
}
} // namespace DataHandling
} // namespace Mantid
......@@ -126,11 +126,13 @@ void LoadPSIMuonBin::init() {
declareProperty(std::make_unique<Kernel::ArrayProperty<double>>(
"TimeZeroList", Kernel::Direction::Output),
"A vector of time zero values");
declareProperty(
std::make_unique<Mantid::API::WorkspaceProperty<Mantid::API::Workspace>>(
std::make_unique<Mantid::API::WorkspaceProperty<Mantid::API::ITableWorkspace>>(
"TimeZeroTable", "", Mantid::Kernel::Direction::Output,
Mantid::API::PropertyMode::Optional),
"A table containing the time zero values");
"TableWorkspace of time zeros for each spectra");
declareProperty(
"CorrectTime", true,
"Boolean flag controlling whether time should be corrected by timezero.",
......
......@@ -13,11 +13,13 @@
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Sample.h"
#include "MantidDataHandling/LoadPSIMuonBin.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/FileDescriptor.h"
using namespace Mantid;
using namespace Mantid::DataHandling;
using namespace Mantid::DataObjects;
using namespace Mantid::API;
using namespace Mantid::Kernel;
......@@ -209,6 +211,60 @@ public:
AnalysisDataService::Instance().remove("ws");
}
void test_time_zero_table_loaded_correctly() {
LoadPSIMuonBin alg;
alg.initialize();
alg.isInitialized();
alg.setProperty("SearchForTempFile", false);
alg.setProperty("Filename", getTestFilePath("deltat_tdc_dolly_1529.bin"));
alg.setProperty("OutputWorkspace", "ws");
alg.setProperty("TimeZeroTable", "tzt");
alg.execute();
ITableWorkspace_sptr tbl;
TS_ASSERT_THROWS_NOTHING(
tbl = AnalysisDataService::Instance().retrieveWS<TableWorkspace>("tzt"));
TS_ASSERT_EQUALS(tbl->columnCount(), 1);
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();
alg.isInitialized();
alg.setProperty("SearchForTempFile", false);
alg.setProperty("Filename", getTestFilePath("deltat_tdc_dolly_1529.bin"));
alg.setProperty("OutputWorkspace", "ws");
alg.setProperty("DeadTimeTable", "dtt");
alg.execute();
ITableWorkspace_sptr tbl;
TS_ASSERT_THROWS_NOTHING(
tbl =
AnalysisDataService::Instance().retrieveWS<TableWorkspace>("dtt"));
TS_ASSERT_EQUALS(tbl->columnCount(), 2);
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);
TS_ASSERT_EQUALS(tbl->getColumn(1)->toDouble(0), 0.0);
TS_ASSERT_EQUALS(tbl->getColumn(0)->toDouble(1), 2.0);
TS_ASSERT_EQUALS(tbl->getColumn(1)->toDouble(1), 0.0);
TS_ASSERT_EQUALS(tbl->getColumn(0)->toDouble(2), 3.0);
TS_ASSERT_EQUALS(tbl->getColumn(1)->toDouble(2), 0.0);
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();
......
......@@ -67,17 +67,6 @@ void MuonPreProcess::init() {
"become 0.0 seconds.",
Direction::Input);
declareProperty(
std::make_unique<ArrayProperty<double>>("TimeOffsetVector",
Direction::Input),
"An array of time offsets which correspond to each spectra, if "
"length one the same offset is assumed for all spectra");
declareProperty(std::make_unique<ArrayProperty<double>>("TimeZeroVector",
Direction::Input),
"An array of time zeros which correspond to each spectra, if "
"length one the same time zero is assumed for all spectra");
declareProperty(
std::make_unique<WorkspaceProperty<TableWorkspace>>(
"TimeZeroTable", "", Direction::Input, PropertyMode::Optional),
......@@ -203,8 +192,6 @@ MatrixWorkspace_sptr MuonPreProcess::correctWorkspace(MatrixWorkspace_sptr ws) {
double xMin = getProperty("TimeMin");
double xMax = getProperty("TimeMax");
std::vector<double> rebinParams = getProperty("RebinArgs");
std::vector<double> offsets = getProperty("TimeOffsetVector");
std::vector<double> timeZeros = getProperty("TimeZeroVector");
TableWorkspace_sptr deadTimes = getProperty("DeadTimeTable");
TableWorkspace_sptr timeZeroTable = getProperty("TimeZeroTable");
......
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