Unverified Commit 08cffc36 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #28304 from mantidproject/28303_ill_tof_channel

28303 ill tof channel
parents 8f664ba4 dd751bf9
...@@ -59,7 +59,8 @@ private: ...@@ -59,7 +59,8 @@ private:
void loadTimeDetails(NeXus::NXEntry &entry); void loadTimeDetails(NeXus::NXEntry &entry);
void loadDataIntoTheWorkSpace(NeXus::NXEntry &entry, void loadDataIntoTheWorkSpace(NeXus::NXEntry &entry,
const std::vector<std::vector<int>> &); const std::vector<std::vector<int>> &,
bool convertToTOF);
void loadSpectra(size_t &spec, const size_t numberOfTubes, void loadSpectra(size_t &spec, const size_t numberOfTubes,
const std::vector<Mantid::detid_t> &detectorIDs, const std::vector<Mantid::detid_t> &detectorIDs,
const NeXus::NXInt &data, Mantid::API::Progress &progress); const NeXus::NXInt &data, Mantid::API::Progress &progress);
......
...@@ -72,6 +72,8 @@ void LoadILLTOF2::init() { ...@@ -72,6 +72,8 @@ void LoadILLTOF2::init() {
declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "",
Direction::Output), Direction::Output),
"The name to use for the output workspace"); "The name to use for the output workspace");
declareProperty("ConvertToTOF", false,
"Convert the bin edges to time-of-flight", Direction::Input);
} }
/** /**
...@@ -80,6 +82,7 @@ void LoadILLTOF2::init() { ...@@ -80,6 +82,7 @@ void LoadILLTOF2::init() {
void LoadILLTOF2::exec() { void LoadILLTOF2::exec() {
// Retrieve filename // Retrieve filename
const std::string filenameData = getPropertyValue("Filename"); const std::string filenameData = getPropertyValue("Filename");
bool convertToTOF = getProperty("convertToTOF");
// open the root node // open the root node
NeXus::NXRoot dataRoot(filenameData); NeXus::NXRoot dataRoot(filenameData);
...@@ -97,7 +100,7 @@ void LoadILLTOF2::exec() { ...@@ -97,7 +100,7 @@ void LoadILLTOF2::exec() {
runLoadInstrument(); // just to get IDF contents runLoadInstrument(); // just to get IDF contents
loadDataIntoTheWorkSpace(dataFirstEntry, monitors); loadDataIntoTheWorkSpace(dataFirstEntry, monitors, convertToTOF);
addEnergyToRun(); addEnergyToRun();
addPulseInterval(); addPulseInterval();
...@@ -353,9 +356,12 @@ void LoadILLTOF2::addPulseInterval() { ...@@ -353,9 +356,12 @@ void LoadILLTOF2::addPulseInterval() {
* *
* @param entry The Nexus entry * @param entry The Nexus entry
* @param monitors List of monitor data * @param monitors List of monitor data
* @param convertToTOF Should the bin edges be converted to time of flight or
* keep the channel indexes
*/ */
void LoadILLTOF2::loadDataIntoTheWorkSpace( void LoadILLTOF2::loadDataIntoTheWorkSpace(
NeXus::NXEntry &entry, const std::vector<std::vector<int>> &monitors) { NeXus::NXEntry &entry, const std::vector<std::vector<int>> &monitors,
bool convertToTOF) {
g_log.debug() << "Loading data into the workspace...\n"; g_log.debug() << "Loading data into the workspace...\n";
// read in the data // read in the data
...@@ -369,9 +375,15 @@ void LoadILLTOF2::loadDataIntoTheWorkSpace( ...@@ -369,9 +375,15 @@ void LoadILLTOF2::loadDataIntoTheWorkSpace(
// Put tof in an array // Put tof in an array
auto &X0 = m_localWorkspace->mutableX(0); auto &X0 = m_localWorkspace->mutableX(0);
if (monitor.containsDataSet("time_of_flight")) { if (monitor.containsDataSet("time_of_flight")) {
for (size_t i = 0; i < m_numberOfChannels + 1; ++i) { if (convertToTOF) {
X0[i] = m_timeOfFlightDelay + m_channelWidth * static_cast<double>(i) - for (size_t i = 0; i < m_numberOfChannels + 1; ++i) {
m_channelWidth / 2; // to make sure the bin centre is correct X0[i] = m_timeOfFlightDelay + m_channelWidth * static_cast<double>(i) -
m_channelWidth / 2; // to make sure the bin centre is correct
}
} else {
for (size_t i = 0; i < m_numberOfChannels + 1; ++i) {
X0[i] = static_cast<double>(i); // just take the channel index
}
} }
} else { } else {
// Diffraction PANTHER // Diffraction PANTHER
......
...@@ -48,11 +48,13 @@ public: ...@@ -48,11 +48,13 @@ public:
MatrixWorkspace_sptr MatrixWorkspace_sptr
loadDataFile(const std::string &dataFile, const size_t numberOfHistograms, loadDataFile(const std::string &dataFile, const size_t numberOfHistograms,
const size_t numberOfMonitors, const size_t numberOfChannels, const size_t numberOfMonitors, const size_t numberOfChannels,
const double tofDelay, const double tofChannelWidth) { const double tofDelay, const double tofChannelWidth,
const bool convertToTOF) {
LoadILLTOF2 loader; LoadILLTOF2 loader;
loader.setRethrows(true); loader.setRethrows(true);
TS_ASSERT_THROWS_NOTHING(loader.initialize()) TS_ASSERT_THROWS_NOTHING(loader.initialize())
TS_ASSERT_THROWS_NOTHING(loader.setPropertyValue("Filename", dataFile)) TS_ASSERT_THROWS_NOTHING(loader.setPropertyValue("Filename", dataFile))
TS_ASSERT_THROWS_NOTHING(loader.setProperty("convertToTOF", convertToTOF))
std::string outputSpace = "LoadILLTOFTest_out"; std::string outputSpace = "LoadILLTOFTest_out";
TS_ASSERT_THROWS_NOTHING( TS_ASSERT_THROWS_NOTHING(
...@@ -79,11 +81,19 @@ public: ...@@ -79,11 +81,19 @@ public:
Mantid::HistogramData::Histogram::YMode::Counts) Mantid::HistogramData::Histogram::YMode::Counts)
TS_ASSERT_EQUALS(histogram.size(), numberOfChannels) TS_ASSERT_EQUALS(histogram.size(), numberOfChannels)
const auto &xs = histogram.x(); const auto &xs = histogram.x();
for (size_t channelIndex = 0; channelIndex != xs.size(); ++channelIndex) { if (convertToTOF) {
const double binEdge = for (size_t channelIndex = 0; channelIndex != xs.size();
tofDelay + static_cast<double>(channelIndex) * tofChannelWidth - ++channelIndex) {
tofChannelWidth / 2; const double binEdge =
TS_ASSERT_DELTA(xs[channelIndex], binEdge, 1e-3) tofDelay + static_cast<double>(channelIndex) * tofChannelWidth -
tofChannelWidth / 2;
TS_ASSERT_DELTA(xs[channelIndex], binEdge, 1e-3)
}
} else {
for (size_t channelIndex = 0; channelIndex != xs.size();
++channelIndex) {
TS_ASSERT_EQUALS(xs[channelIndex], channelIndex)
}
} }
const auto &ys = histogram.y(); const auto &ys = histogram.y();
const auto &es = histogram.e(); const auto &es = histogram.e();
...@@ -114,9 +124,10 @@ public: ...@@ -114,9 +124,10 @@ public:
const size_t channelCount = 512; const size_t channelCount = 512;
const size_t histogramCount = 397; const size_t histogramCount = 397;
const size_t monitorCount = 1; const size_t monitorCount = 1;
const bool convertToTOF = true;
MatrixWorkspace_sptr ws = MatrixWorkspace_sptr ws =
loadDataFile("ILL/IN4/084446.nxs", histogramCount, monitorCount, loadDataFile("ILL/IN4/084446.nxs", histogramCount, monitorCount,
channelCount, tofDelay, tofChannelWidth); channelCount, tofDelay, tofChannelWidth, convertToTOF);
const double pulseInterval = const double pulseInterval =
ws->run().getLogAsSingleValue("pulse_interval"); ws->run().getLogAsSingleValue("pulse_interval");
...@@ -130,8 +141,9 @@ public: ...@@ -130,8 +141,9 @@ public:
const size_t channelCount = 512; const size_t channelCount = 512;
const size_t histogramCount = 98305; const size_t histogramCount = 98305;
const size_t monitorCount = 1; const size_t monitorCount = 1;
const bool convertToTOF = true;
loadDataFile("ILL/IN5/104007.nxs", histogramCount, monitorCount, loadDataFile("ILL/IN5/104007.nxs", histogramCount, monitorCount,
channelCount, tofDelay, tofChannelWidth); channelCount, tofDelay, tofChannelWidth, convertToTOF);
} }
void test_IN6_load() { void test_IN6_load() {
...@@ -141,9 +153,10 @@ public: ...@@ -141,9 +153,10 @@ public:
const size_t channelCount = 1024; const size_t channelCount = 1024;
const size_t histogramCount = 340; const size_t histogramCount = 340;
const size_t monitorCount = 3; const size_t monitorCount = 3;
const bool convertToTOF = true;
MatrixWorkspace_sptr ws = MatrixWorkspace_sptr ws =
loadDataFile("ILL/IN6/164192.nxs", histogramCount, monitorCount, loadDataFile("ILL/IN6/164192.nxs", histogramCount, monitorCount,
channelCount, tofDelay, tofChannelWidth); channelCount, tofDelay, tofChannelWidth, convertToTOF);
const double pulseInterval = const double pulseInterval =
ws->run().getLogAsSingleValue("pulse_interval"); ws->run().getLogAsSingleValue("pulse_interval");
...@@ -216,8 +229,21 @@ public: ...@@ -216,8 +229,21 @@ public:
const size_t channelCount = 512; const size_t channelCount = 512;
const size_t histogramCount = 73729; const size_t histogramCount = 73729;
const size_t monitorCount = 1; const size_t monitorCount = 1;
const bool convertToTOF = false;
loadDataFile("ILL/PANTHER/001723.nxs", histogramCount, monitorCount, loadDataFile("ILL/PANTHER/001723.nxs", histogramCount, monitorCount,
channelCount, tofDelay, tofChannelWidth); channelCount, tofDelay, tofChannelWidth, convertToTOF);
}
void test_convertToTOF() {
// From the input test file.
const double tofDelay = 0;
const double tofChannelWidth = 0; // should not be usesd
const size_t channelCount = 512;
const size_t histogramCount = 98305;
const size_t monitorCount = 1;
const bool convertToTOF = false;
loadDataFile("ILL/IN5/104007.nxs", histogramCount, monitorCount,
channelCount, tofDelay, tofChannelWidth, convertToTOF);
} }
}; };
......
...@@ -727,7 +727,7 @@ class DirectILLCollectData(DataProcessorAlgorithm): ...@@ -727,7 +727,7 @@ class DirectILLCollectData(DataProcessorAlgorithm):
if inputFiles: if inputFiles:
mergedWSName = self._names.withSuffix('merged') mergedWSName = self._names.withSuffix('merged')
mainWS = LoadAndMerge(Filename=inputFiles, OutputWorkspace=mergedWSName, mainWS = LoadAndMerge(Filename=inputFiles, OutputWorkspace=mergedWSName,
LoaderName='LoadILLTOF', EnableLogging=self._subalgLogging) LoaderName='LoadILLTOF', LoaderOptions={"ConvertToTOF": True}, EnableLogging=self._subalgLogging)
else: else:
mainWS = self.getProperty(common.PROP_INPUT_WS).value mainWS = self.getProperty(common.PROP_INPUT_WS).value
self._cleanup.protect(mainWS) self._cleanup.protect(mainWS)
......
...@@ -208,9 +208,9 @@ class IN6(systemtesting.MantidSystemTest): ...@@ -208,9 +208,9 @@ class IN6(systemtesting.MantidSystemTest):
class IN5_Tube_Background(systemtesting.MantidSystemTest): class IN5_Tube_Background(systemtesting.MantidSystemTest):
def runTest(self): def runTest(self):
Load(Filename='ILL/IN5/Epp.nxs', OutputWorkspace='Epp') Load(Filename='ILL/IN5/Epp.nxs', OutputWorkspace='Epp', ConvertToTOF=True)
Load(Filename='ILL/IN5/Sample.nxs', OutputWorkspace='Sample') Load(Filename='ILL/IN5/Sample.nxs', OutputWorkspace='Sample', ConvertToTOF=True)
Load(Filename='ILL/IN5/Vmask.nxs', OutputWorkspace='Vmask') Load(Filename='ILL/IN5/Vmask.nxs', OutputWorkspace='Vmask', ConvertToTOF=True)
args = {'InputWorkspace':'Sample', args = {'InputWorkspace':'Sample',
'DiagnosticsWorkspace':'Vmask', 'DiagnosticsWorkspace':'Vmask',
'EPPWorkspace':'Epp', 'EPPWorkspace':'Epp',
...@@ -247,7 +247,7 @@ class IN5_Mask_Non_Overlapping_Bins(systemtesting.MantidSystemTest): ...@@ -247,7 +247,7 @@ class IN5_Mask_Non_Overlapping_Bins(systemtesting.MantidSystemTest):
OutputEPPWorkspace='Epp' OutputEPPWorkspace='Epp'
) )
ws = Load(run) ws = Load(run, ConvertToTOF=True)
self.ecrase(ws) self.ecrase(ws)
DirectILLCollectData( DirectILLCollectData(
......
...@@ -140,7 +140,7 @@ For usage of this algorithm as part of the direct geometry data reduction, check ...@@ -140,7 +140,7 @@ For usage of this algorithm as part of the direct geometry data reduction, check
# It is recommended to use DirectILLCollectData over the basic Load # It is recommended to use DirectILLCollectData over the basic Load
preprocessed = DirectILLCollectData('ILL/IN4/087294+087295.nxs') preprocessed = DirectILLCollectData('ILL/IN4/087294+087295.nxs')
# Compare to simply loading the data # Compare to simply loading the data
raw = Load('ILL/IN4/087294+087295.nxs') raw = Load('ILL/IN4/087294+087295.nxs', ConvertToTOF=True)
# The workspace loaded by 'Load' includes monitor data which # The workspace loaded by 'Load' includes monitor data which
# makes 2D plotting difficult # makes 2D plotting difficult
nRaw = raw.getNumberHistograms() nRaw = raw.getNumberHistograms()
......
...@@ -14,7 +14,9 @@ the given name. ...@@ -14,7 +14,9 @@ the given name.
To date this algorithm only supports: IN4, IN5, IN6 and PANTHER. To date this algorithm only supports: IN4, IN5, IN6 and PANTHER.
This algorithm also supports diffraction mode. In this case, the unit of the output workspace will be wavelength instead of time-of-flight. By default, this algorithm loads the data indexed by channels. To convert to time-of-flight, use the ConvertToTOF option.
This algorithm also supports diffraction mode. In this case, the unit of the output workspace will be wavelength instead of time-of-flight or channel.
.. note:: .. note::
The initial time-of-flight axis is set up using the 'time_of_flight' field in the NeXus file. Therefore the conversion from 'TOF' to 'DeltaE' may not give the correct zero-energy transfer. The initial time-of-flight axis is set up using the 'time_of_flight' field in the NeXus file. Therefore the conversion from 'TOF' to 'DeltaE' may not give the correct zero-energy transfer.
......
...@@ -9,4 +9,10 @@ Direct Geometry Changes ...@@ -9,4 +9,10 @@ Direct Geometry Changes
putting new features at the top of the section, followed by putting new features at the top of the section, followed by
improvements, followed by bug fixes. improvements, followed by bug fixes.
:ref:`Release 5.1.0 <v5.1.0>` Improvements
\ No newline at end of file ############
For ILL time-of-flight instruments, :ref:`LoadILLTOF <algm-LoadILLTOF-v2>` now allows bin edges determined by channel
number by default, but you can still convert to time-of-flight using the `ConvertToTOF` property.
:ref:`Release 5.1.0 <v5.1.0>`
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