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

Re #29025 Changes requested

parent 2a0eea94
......@@ -14,6 +14,11 @@
namespace Mantid {
namespace DataHandling {
class LoadMuonNexusV2NexusHelper;
// Create time zero table
DataObjects::TableWorkspace_sptr
createTimeZeroTable(const size_t numSpec, const std::vector<double> &timeZeros);
class DLLExport LoadMuonStrategy {
public:
// Constructor
......@@ -44,11 +49,6 @@ protected:
createDeadTimeTable(const std::vector<detid_t> &detectorsLoaded,
const std::vector<double> &deadTimes) const;
// Create time zero table
DataObjects::TableWorkspace_sptr
createTimeZeroTable(const size_t numSpec,
const std::vector<double> &timeZeros) const;
API::Workspace_sptr loadDefaultDetectorGrouping(
const DataObjects::Workspace2D &localWorkspace) const;
......
......@@ -88,7 +88,6 @@ private:
void readInHistograms(Mantid::Kernel::BinaryStreamReader &streamReader);
void generateUnknownAxis();
void makeDeadTimeTable(const size_t &numSpec);
void makeTimeZeroTable(const std::vector<double> &timeZeroList);
// Temperature file processing
void readInTemperatureFile(DataObjects::Workspace2D_sptr &ws);
......
......@@ -18,6 +18,29 @@
namespace Mantid {
namespace DataHandling {
/**
* Creates a timezero table for the loaded detectors
* @param numSpec :: Numer of spectra (number of rows in table)
* @param timeZeros :: Vector containing time zero values for each spectra
* @return TableWorkspace of time zeros
*/
DataObjects::TableWorkspace_sptr
createTimeZeroTable(const size_t numSpec,
const std::vector<double> &timeZeros) {
Mantid::DataObjects::TableWorkspace_sptr timeZeroTable =
std::dynamic_pointer_cast<Mantid::DataObjects::TableWorkspace>(
Mantid::API::WorkspaceFactory::Instance().createTable(
"TableWorkspace"));
timeZeroTable->addColumn("double", "time zero");
for (size_t specNum = 0; specNum < numSpec; ++specNum) {
Mantid::API::TableRow row = timeZeroTable->appendRow();
row << timeZeros[specNum];
}
return timeZeroTable;
}
// Constructor
LoadMuonStrategy::LoadMuonStrategy(Kernel::Logger &g_log, std::string filename,
LoadMuonNexusV2NexusHelper &nexusLoader)
......@@ -124,28 +147,5 @@ DataObjects::TableWorkspace_sptr LoadMuonStrategy::createDeadTimeTable(
return deadTimesTable;
}
/**
* Creates a timezero table for the loaded detectors
* @param numSpec :: Numer of spectra (number of rows in table)
* @param timeZeros :: Vector containing time zero values for each spectra
* @return TableWorkspace of time zeros
*/
DataObjects::TableWorkspace_sptr LoadMuonStrategy::createTimeZeroTable(
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 specNum = 0; specNum < numSpec; ++specNum) {
Mantid::API::TableRow row = timeZeroTable->appendRow();
row << timeZeros[specNum];
}
return timeZeroTable;
}
} // namespace DataHandling
} // namespace Mantid
......@@ -13,6 +13,7 @@
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataHandling/LoadMuonStrategy.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/WorkspaceCreation.h"
......@@ -234,7 +235,11 @@ void LoadPSIMuonBin::exec() {
setProperty("TimeZeroList", correctedTimeZeroList);
// create time zero table
makeTimeZeroTable(correctedTimeZeroList);
if (!getPropertyValue("TimeZeroTable").empty()) {
auto table =
createTimeZeroTable(m_histograms.size(), correctedTimeZeroList);
setProperty("TimeZeroTable", table);
}
auto firstGoodDataSpecIndex = static_cast<int>(
*std::max_element(m_header.firstGood, m_header.firstGood + 16));
......@@ -273,25 +278,6 @@ void LoadPSIMuonBin::makeDeadTimeTable(const size_t &numSpec) {
setProperty("DeadTimeTable", deadTimeTable);
}
void LoadPSIMuonBin::makeTimeZeroTable(
const std::vector<double> &timeZeroList) {
if (getPropertyValue("TimeZeroTable").empty())
return;
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 < timeZeroList.size(); ++i) {
Mantid::API::TableRow row = timeZeroTable->appendRow();
row << timeZeroList[i];
}
setProperty("TimeZeroTable", timeZeroTable);
}
std::string LoadPSIMuonBin::getFormattedDateTime(const std::string &date,
const std::string &time) {
std::string year;
......
......@@ -237,27 +237,25 @@ MatrixWorkspace_sptr MuonPreProcess::applyTimeOffset(MatrixWorkspace_sptr ws,
MatrixWorkspace_sptr
MuonPreProcess::applyTimeZeroTable(MatrixWorkspace_sptr ws,
const TableWorkspace_sptr &tz) {
if (tz != nullptr) {
const auto numSpec = ws->getNumberHistograms();
const TableWorkspace_sptr &timeZeroTable) {
auto cloneWs = cloneWorkspace(ws);
if (timeZeroTable != nullptr) {
const auto numSpec = cloneWs->getNumberHistograms();
for (auto specNum = 0u; specNum < numSpec; ++specNum) {
auto &xData = ws->mutableX(specNum);
auto &xData = cloneWs->mutableX(specNum);
for (auto &xValue : xData) {
API::TableRow row = tz->getRow(specNum);
API::TableRow row = timeZeroTable->getRow(specNum);
xValue -= row.Double(0);
}
}
return ws;
} else {
return ws;
}
return cloneWs;
}
MatrixWorkspace_sptr MuonPreProcess::applyCropping(MatrixWorkspace_sptr ws,
const double &xMin,
const double &xMax) {
if (xMin != EMPTY_DBL() || xMax != EMPTY_DBL()) {
std::cout << "xMin : " << xMin << " , xMax : " << xMax << std::endl;
IAlgorithm_sptr crop = createChildAlgorithm("CropWorkspace");
crop->setProperty("InputWorkspace", ws);
if (xMin != EMPTY_DBL())
......
......@@ -9,7 +9,7 @@
Description
-----------
When interacting with the :ref:`Muon_Analysis-ref` interface, operations such as detector grouping, group and pair asymmetry are performed on data. As part of the workflow, several "pre-processing" steps are also necessary; such as rebinning and cropping the data, applying dead time corrections, applying time zero corrections, and shifting the time axis by a fixed amount (sometimes referred to as "first good data").
When interacting with the :ref:`Muon_Analysis-ref` interface, operations such as detector grouping, group and pair asymmetry are performed on data. As part of the workflow, several "pre-processing" steps are also necessary; such as rebinning and cropping the data, applying dead time corrections and applying time zero corrections/shifting the time axis by a fixed amount (sometimes referred to as "first good data").
This algorithm intends to capture the common pre-processing steps, which are not muon physics specific concepts, and apply them all at once to produce data which is ready for the muon-specific operations. This way, scripting the workflows of the :ref:`Muon_Analysis-ref` interface is much more intuitive and simple.
......
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