From c72b4a3af275ddd0c911ce9db6a50f553dcb9ed3 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Tue, 13 Aug 2024 14:57:38 -0400 Subject: [PATCH 01/21] inital commit add codes that filters by time --- Framework/DataHandling/src/BankPulseTimes.cpp | 9 +- .../src/LoadEventAsWorkspace2D.cpp | 102 ++++++++++++++---- .../test/LoadEventAsWorkspace2DTest.h | 16 ++- 3 files changed, 105 insertions(+), 22 deletions(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index 588bd13a2115..c810d00f2ba6 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -5,7 +5,6 @@ // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + #include "MantidDataHandling/BankPulseTimes.h" - #include #include @@ -54,7 +53,12 @@ BankPulseTimes::BankPulseTimes(const std::vector &periodNumbers) : startTime(DEFAULT_START_TIME), periodNumbers(periodNumbers), have_period_info(true), m_sorting_info(PulseSorting::UNKNOWN) { - file.openData("event_time_zero"); + + try { + file.openData("event_time_zero"); + } catch (std::exception &e) { + file.openData("pulse_time"); + } // Read the offset (time zero) // Use the offset if it is present @@ -191,6 +195,7 @@ std::size_t getFirstExcludedIndex(const std::vector BankPulseTimes::getPulseIndices(const Mantid::Types::Core::DateAndTime &start, const Mantid::Types::Core::DateAndTime &stop) const { std::vector roi; diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 7e2d5a1d391e..8852b2ea78be 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -14,12 +14,13 @@ #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataHandling/LoadEventNexus.h" #include "MantidDataHandling/LoadEventNexusIndexSetup.h" +#include "MantidDataHandling/PulseIndexer.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidKernel/ListValidator.h" +#include "MantidKernel/TimeROI.h" #include "MantidKernel/TimeSeriesProperty.h" #include "MantidKernel/UnitFactory.h" #include "MantidNexus/NexusIOHelper.h" - #include namespace Mantid { @@ -32,6 +33,7 @@ using Mantid::Kernel::PropertyWithValue; using Mantid::Kernel::StringListValidator; using Mantid::Kernel::TimeSeriesProperty; using Mantid::Kernel::UnitFactory; +// using Mantid::Kernel::TimeROI; // Register the algorithm into the AlgorithmFactory DECLARE_ALGORITHM(LoadEventAsWorkspace2D) @@ -69,6 +71,15 @@ void LoadEventAsWorkspace2D::init() { "of times-of-flight. " "This is the maximum accepted value in microseconds. Keep " "blank to load all events."); + + declareProperty(std::make_unique>("FilterByTimeStart", EMPTY_DBL(), Direction::Input), + "Optional: To only include events after the provided start " + "time, in seconds (relative to the start of the run)."); + + declareProperty(std::make_unique>("FilterByTimeStop", EMPTY_DBL(), Direction::Input), + "Optional: To only include events before the provided stop " + "time, in seconds (relative to the start of the run)."); + declareProperty(std::make_unique>>( "LogAllowList", std::vector(), Direction::Input), "If specified, only these logs will be loaded from the file (each " @@ -123,6 +134,7 @@ std::map LoadEventAsWorkspace2D::validateInputs() { return results; } + //---------------------------------------------------------------------------------------------- /** Execute the algorithm. */ @@ -200,6 +212,26 @@ void LoadEventAsWorkspace2D::exec() { const double tof_max = getProperty("FilterByTofMax"); const bool tof_filtering = (tof_min != EMPTY_DBL() && tof_max != EMPTY_DBL()); + double filter_time_start_sec, filter_time_stop_sec; + filter_time_start_sec = getProperty("FilterByTimeStart"); + filter_time_stop_sec = getProperty("FilterByTimeStop"); + + // if (!WS->run().hasProperty("start_time")) { + // g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); + // } + Types::Core::DateAndTime runstart(WS->run().hasProperty("start_time") ? WS->run().getProperty("start_time")->value() + : WS->run().getFirstPulseTime()); + + // if (!WS->run().hasProperty("end_time")) { + // g_log.warning("This NXS file does not have an end time, last pulse time is used instead."); + // } + + Types::Core::DateAndTime endtime(WS->run().hasProperty("end_time") ? WS->run().getProperty("end_time")->value() + : WS->run().getLastPulseTime()); + Types::Core::DateAndTime filter_time_start; + Types::Core::DateAndTime filter_time_stop; + // const bool time_filtering = (filter_time_start_sec != EMPTY_DBL() && filter_time_stop_sec != EMPTY_DBL()); + // vector to stored to integrated counts by detector ID std::vector Y(max_detid - min_detid + 1, 0); @@ -212,24 +244,20 @@ void LoadEventAsWorkspace2D::exec() { const std::map> &allEntries = descriptor.getAllEntries(); prog->doReport("Reading and integrating data"); - + // int ct = 0; auto itClassEntries = allEntries.find("NXevent_data"); - if (itClassEntries != allEntries.end()) { const std::set &classEntries = itClassEntries->second; const std::regex classRegex("(/entry/)([^/]*)"); std::smatch groups; - for (const std::string &classEntry : classEntries) { if (std::regex_match(classEntry, groups, classRegex)) { const std::string entry_name(groups[2].str()); - // skip entries with junk data if (entry_name == "bank_error_events" || entry_name == "bank_unmapped_events") continue; - g_log.debug() << "Loading bank " << entry_name << '\n'; h5file.openGroup(entry_name, "NXevent_data"); @@ -239,6 +267,42 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_id"); else event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); + // closeGroup and skip this bank if there is no event + if (event_ids.size() == 1) { + h5file.closeGroup(); + continue; + } + // Load "h5file" into BankPulseTimes using a shared ptr + const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); + + // Get event_index from the "h5file" + const auto event_index = std::make_shared>( + Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); + + // if (runstart == Types::Core::DateAndTime::minimum()) { + // runstart = run().getFirstPulseTime() + // } + + if (filter_time_start_sec != EMPTY_DBL()) { + filter_time_start = runstart + filter_time_start_sec; + } else { + filter_time_start = runstart; + } + + if (filter_time_stop_sec != EMPTY_DBL()) { + filter_time_stop = runstart + filter_time_stop_sec; + // std::cout<<"end time is not empty"<getPulseIndices(filter_time_start, filter_time_stop); + std::cout << filter_time_stop << std::endl; + // Give pulseIndexer a TimeROI + const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); + // const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, std::vector event_times; if (tof_filtering) { @@ -247,21 +311,23 @@ void LoadEventAsWorkspace2D::exec() { else event_times = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_time_of_flight"); } - - for (size_t i = 0; i < event_ids.size(); i++) { - if (tof_filtering) { - const auto tof = event_times[i]; - if (tof < tof_min || tof > tof_max) + // Nested loop to loop through all the relavent pulses and relavent event_ids + for (const auto &pulse : pulseIndexer_time) { + // const auto &pulsetime = bankPulseTimes->pulseTime(pulse.pulseIndex); + // std::cout << pulsetime < tof_max) + continue; + } + const detid_t det_id = event_ids[i]; + if (det_id < min_detid || det_id > max_detid) continue; + Y[det_id - min_detid]++; } - - const detid_t det_id = event_ids[i]; - if (det_id < min_detid || det_id > max_detid) - continue; - - Y[det_id - min_detid]++; } - h5file.closeGroup(); } } diff --git a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h index 594800037d86..d012fbd92e63 100644 --- a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h +++ b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h @@ -24,6 +24,14 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { static LoadEventAsWorkspace2DTest *createSuite() { return new LoadEventAsWorkspace2DTest(); } static void destroySuite(LoadEventAsWorkspace2DTest *suite) { delete suite; } + void xtest_filterbytime() { + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "CNCS_7860_event.nxs")) + } + void test_EQSANS() { LoadEventAsWorkspace2D alg; alg.setChild(true); @@ -62,8 +70,12 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(outputWS->blocksize(), 1) TS_ASSERT_EQUALS(outputWS->getAxis(0)->unit()->unitID(), "Energy") - TS_ASSERT_EQUALS(outputWS->readY(0)[0], 1) - TS_ASSERT_EQUALS(outputWS->readE(0)[0], 1) + // TS_ASSERT_EQUALS(outputWS->readY(0)[0], 1) + // TS_ASSERT_EQUALS(outputWS->readE(0)[0], 1) + // I don't agree with original test to have values of 1 in Y(0)[0] and E(0)[0]. CNCS_7860_event.nxs bank5 + // has 0 total counts this should count as faulty detector and the feature is spurious and should be excluded. + TS_ASSERT_EQUALS(outputWS->readY(0)[0], 0) + TS_ASSERT_EQUALS(outputWS->readE(0)[0], 0) TS_ASSERT_EQUALS(outputWS->readX(0)[0], 2.85) TS_ASSERT_EQUALS(outputWS->readX(0)[1], 3.15) } From 15b5743dad4cd5694772670afd6b0438b1899f14 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:00:00 -0400 Subject: [PATCH 02/21] implemented additional unit tests to test filter by time functionality --- .../src/LoadEventAsWorkspace2D.cpp | 37 ++-- .../test/LoadEventAsWorkspace2DTest.h | 179 +++++++++++++++++- 2 files changed, 192 insertions(+), 24 deletions(-) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 8852b2ea78be..7d86667be580 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -216,18 +216,22 @@ void LoadEventAsWorkspace2D::exec() { filter_time_start_sec = getProperty("FilterByTimeStart"); filter_time_stop_sec = getProperty("FilterByTimeStop"); - // if (!WS->run().hasProperty("start_time")) { - // g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); - // } + if (!WS->run().hasProperty("start_time")) { + g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); + } + Types::Core::DateAndTime runstart(WS->run().hasProperty("start_time") ? WS->run().getProperty("start_time")->value() : WS->run().getFirstPulseTime()); - // if (!WS->run().hasProperty("end_time")) { - // g_log.warning("This NXS file does not have an end time, last pulse time is used instead."); - // } + Types::Core::DateAndTime endtime; + if (WS->run().hasProperty("proton_charge") && + WS->run().getLastPulseTime() > WS->run().getProperty("end_time")->value()) { + endtime = WS->run().getLastPulseTime(); + g_log.warning("Last pulse time is used because the last pulse time is greater than the end time!"); + } else { + endtime = WS->run().getProperty("end_time")->value(); + } - Types::Core::DateAndTime endtime(WS->run().hasProperty("end_time") ? WS->run().getProperty("end_time")->value() - : WS->run().getLastPulseTime()); Types::Core::DateAndTime filter_time_start; Types::Core::DateAndTime filter_time_stop; // const bool time_filtering = (filter_time_start_sec != EMPTY_DBL() && filter_time_stop_sec != EMPTY_DBL()); @@ -267,8 +271,14 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_id"); else event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); + // closeGroup and skip this bank if there is no event + // std::vector total_counts; + // if (descriptor.isEntry("/entry/" + entry_name + "/total_counts", "SDS")) + // total_counts = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "total_counts"); if (event_ids.size() == 1) { + // std::cout <<"total_counts[0]"<getPulseIndices(filter_time_start, filter_time_stop); - std::cout << filter_time_stop << std::endl; + // Give pulseIndexer a TimeROI - const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); - // const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, + const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); std::vector event_times; if (tof_filtering) { @@ -312,9 +319,7 @@ void LoadEventAsWorkspace2D::exec() { event_times = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_time_of_flight"); } // Nested loop to loop through all the relavent pulses and relavent event_ids - for (const auto &pulse : pulseIndexer_time) { - // const auto &pulsetime = bankPulseTimes->pulseTime(pulse.pulseIndex); - // std::cout << pulsetime <execute(); TS_ASSERT(compare->getProperty("Result")); } + + void test_BSS_filterbytimeROI() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + + // load with LoadEventAsWorkspace2D + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "0.0")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "5.0")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + // load with LoadEventNexus then do Integration + auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); + load->initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + load->setProperty("FilterByTimeStart", "0.0"); + load->setProperty("FilterByTimeStop", "5.0"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } + + void test_BSS_filterbytimeStart() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + + // load with LoadEventAsWorkspace2D + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "5.0")) + // TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "5.0")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + // load with LoadEventNexus then do Integration + auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); + load->initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + load->setProperty("FilterByTimeStart", "5.0"); + // load->setProperty("FilterByTimeStop", "5.0"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } + + void test_BSS_filterbytimeStop() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + + // load with LoadEventAsWorkspace2D + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) + // TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "0.0")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "7.1")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + // load with LoadEventNexus then do Integration + auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); + load->initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + // load->setProperty("FilterByTimeStart", "0.0"); + load->setProperty("FilterByTimeStop", "7.1"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } }; From 6515446ca8c29e414f8de38c0d68a9c10450bfef Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:51:07 -0400 Subject: [PATCH 03/21] fixed format and added comments --- Framework/DataHandling/src/BankPulseTimes.cpp | 1 + .../src/LoadEventAsWorkspace2D.cpp | 41 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index c810d00f2ba6..5e747048fd27 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -54,6 +54,7 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector &peri : startTime(DEFAULT_START_TIME), periodNumbers(periodNumbers), have_period_info(true), m_sorting_info(PulseSorting::UNKNOWN) { + // Some old data use "pulse_time" instead of "event_time_zero" as entry try { file.openData("event_time_zero"); } catch (std::exception &e) { diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 7d86667be580..8a5939db9ce0 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -71,15 +71,14 @@ void LoadEventAsWorkspace2D::init() { "of times-of-flight. " "This is the maximum accepted value in microseconds. Keep " "blank to load all events."); - - declareProperty(std::make_unique>("FilterByTimeStart", EMPTY_DBL(), Direction::Input), - "Optional: To only include events after the provided start " - "time, in seconds (relative to the start of the run)."); - + declareProperty( + std::make_unique>("FilterByTimeStart", EMPTY_DBL(), Direction::Input), + "Optional: To only include events after the provided start " + "time, in seconds (relative to the start of the run). If left empty, it will take start time as default."); declareProperty(std::make_unique>("FilterByTimeStop", EMPTY_DBL(), Direction::Input), "Optional: To only include events before the provided stop " - "time, in seconds (relative to the start of the run)."); - + "time, in seconds (relative to the start of the run). if left empty, it will take run end time or " + "last pulse time as default."); declareProperty(std::make_unique>>( "LogAllowList", std::vector(), Direction::Input), "If specified, only these logs will be loaded from the file (each " @@ -216,6 +215,7 @@ void LoadEventAsWorkspace2D::exec() { filter_time_start_sec = getProperty("FilterByTimeStart"); filter_time_stop_sec = getProperty("FilterByTimeStop"); + // get the start time if (!WS->run().hasProperty("start_time")) { g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); } @@ -223,6 +223,8 @@ void LoadEventAsWorkspace2D::exec() { Types::Core::DateAndTime runstart(WS->run().hasProperty("start_time") ? WS->run().getProperty("start_time")->value() : WS->run().getFirstPulseTime()); + // get end time, to account for some older DAS issue where last pulse time can be slightly greater than end time, use + // last pulse time in this case and check if WS has "proton_charge" property otherwise last pulse time doesn't exist. Types::Core::DateAndTime endtime; if (WS->run().hasProperty("proton_charge") && WS->run().getLastPulseTime() > WS->run().getProperty("end_time")->value()) { @@ -234,7 +236,6 @@ void LoadEventAsWorkspace2D::exec() { Types::Core::DateAndTime filter_time_start; Types::Core::DateAndTime filter_time_stop; - // const bool time_filtering = (filter_time_start_sec != EMPTY_DBL() && filter_time_stop_sec != EMPTY_DBL()); // vector to stored to integrated counts by detector ID std::vector Y(max_detid - min_detid + 1, 0); @@ -273,15 +274,11 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); // closeGroup and skip this bank if there is no event - // std::vector total_counts; - // if (descriptor.isEntry("/entry/" + entry_name + "/total_counts", "SDS")) - // total_counts = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "total_counts"); - if (event_ids.size() == 1) { - // std::cout <<"total_counts[0]"<(boost::ref(h5file), std::vector()); @@ -289,26 +286,24 @@ void LoadEventAsWorkspace2D::exec() { const auto event_index = std::make_shared>( Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); - // if (runstart == Types::Core::DateAndTime::minimum()) { - // runstart = run().getFirstPulseTime() - // } - + // if "filterTimeStart" is empty, use run start time as default if (filter_time_start_sec != EMPTY_DBL()) { filter_time_start = runstart + filter_time_start_sec; } else { filter_time_start = runstart; } + // if "filterTimeStop" is empty, use end time as default if (filter_time_stop_sec != EMPTY_DBL()) { filter_time_stop = runstart + filter_time_stop_sec; } else { filter_time_stop = endtime; } - // Use run_start time as starting reference in time and create a TimeROI using bankPulseTimes + // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); - // Give pulseIndexer a TimeROI + // set up PulseIndexer and give previous TimeROI to pulseIndexer const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); std::vector event_times; @@ -318,7 +313,11 @@ void LoadEventAsWorkspace2D::exec() { else event_times = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_time_of_flight"); } - // Nested loop to loop through all the relavent pulses and relavent event_ids + + // Nested loop to loop through all the relavent pulses and relavent event_ids. + // For someone new to this, every pulse creates an entry in event_index, event_index.size() = # of pulses, + // the value of event_index[i] points to the index of event_ids. In short, event_ids[event_index[i]] is the + // detector id from the i-th pulse. See NXevent_data description for more details. for (const auto &pulse : pulseIndexer) { for (size_t i = pulse.eventIndexStart; i < pulse.eventIndexStop; i++) { // for (size_t i = 0; i < event_ids.size(); i++) { From fb811e21fdc397b7fe556b3c33cc29923c9ef7a7 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:53:37 -0400 Subject: [PATCH 04/21] minor fixes --- Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 8a5939db9ce0..9f94d09f0bb9 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -249,7 +249,6 @@ void LoadEventAsWorkspace2D::exec() { const std::map> &allEntries = descriptor.getAllEntries(); prog->doReport("Reading and integrating data"); - // int ct = 0; auto itClassEntries = allEntries.find("NXevent_data"); if (itClassEntries != allEntries.end()) { From acb0fcd62446950587b6793a277839d1560a55d0 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Tue, 13 Aug 2024 14:57:38 -0400 Subject: [PATCH 05/21] inital commit add codes that filters by time --- Framework/DataHandling/src/BankPulseTimes.cpp | 9 +- .../src/LoadEventAsWorkspace2D.cpp | 102 ++++++++++++++---- .../test/LoadEventAsWorkspace2DTest.h | 16 ++- 3 files changed, 105 insertions(+), 22 deletions(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index 588bd13a2115..c810d00f2ba6 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -5,7 +5,6 @@ // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + #include "MantidDataHandling/BankPulseTimes.h" - #include #include @@ -54,7 +53,12 @@ BankPulseTimes::BankPulseTimes(const std::vector &periodNumbers) : startTime(DEFAULT_START_TIME), periodNumbers(periodNumbers), have_period_info(true), m_sorting_info(PulseSorting::UNKNOWN) { - file.openData("event_time_zero"); + + try { + file.openData("event_time_zero"); + } catch (std::exception &e) { + file.openData("pulse_time"); + } // Read the offset (time zero) // Use the offset if it is present @@ -191,6 +195,7 @@ std::size_t getFirstExcludedIndex(const std::vector BankPulseTimes::getPulseIndices(const Mantid::Types::Core::DateAndTime &start, const Mantid::Types::Core::DateAndTime &stop) const { std::vector roi; diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 7e2d5a1d391e..8852b2ea78be 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -14,12 +14,13 @@ #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataHandling/LoadEventNexus.h" #include "MantidDataHandling/LoadEventNexusIndexSetup.h" +#include "MantidDataHandling/PulseIndexer.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidKernel/ListValidator.h" +#include "MantidKernel/TimeROI.h" #include "MantidKernel/TimeSeriesProperty.h" #include "MantidKernel/UnitFactory.h" #include "MantidNexus/NexusIOHelper.h" - #include namespace Mantid { @@ -32,6 +33,7 @@ using Mantid::Kernel::PropertyWithValue; using Mantid::Kernel::StringListValidator; using Mantid::Kernel::TimeSeriesProperty; using Mantid::Kernel::UnitFactory; +// using Mantid::Kernel::TimeROI; // Register the algorithm into the AlgorithmFactory DECLARE_ALGORITHM(LoadEventAsWorkspace2D) @@ -69,6 +71,15 @@ void LoadEventAsWorkspace2D::init() { "of times-of-flight. " "This is the maximum accepted value in microseconds. Keep " "blank to load all events."); + + declareProperty(std::make_unique>("FilterByTimeStart", EMPTY_DBL(), Direction::Input), + "Optional: To only include events after the provided start " + "time, in seconds (relative to the start of the run)."); + + declareProperty(std::make_unique>("FilterByTimeStop", EMPTY_DBL(), Direction::Input), + "Optional: To only include events before the provided stop " + "time, in seconds (relative to the start of the run)."); + declareProperty(std::make_unique>>( "LogAllowList", std::vector(), Direction::Input), "If specified, only these logs will be loaded from the file (each " @@ -123,6 +134,7 @@ std::map LoadEventAsWorkspace2D::validateInputs() { return results; } + //---------------------------------------------------------------------------------------------- /** Execute the algorithm. */ @@ -200,6 +212,26 @@ void LoadEventAsWorkspace2D::exec() { const double tof_max = getProperty("FilterByTofMax"); const bool tof_filtering = (tof_min != EMPTY_DBL() && tof_max != EMPTY_DBL()); + double filter_time_start_sec, filter_time_stop_sec; + filter_time_start_sec = getProperty("FilterByTimeStart"); + filter_time_stop_sec = getProperty("FilterByTimeStop"); + + // if (!WS->run().hasProperty("start_time")) { + // g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); + // } + Types::Core::DateAndTime runstart(WS->run().hasProperty("start_time") ? WS->run().getProperty("start_time")->value() + : WS->run().getFirstPulseTime()); + + // if (!WS->run().hasProperty("end_time")) { + // g_log.warning("This NXS file does not have an end time, last pulse time is used instead."); + // } + + Types::Core::DateAndTime endtime(WS->run().hasProperty("end_time") ? WS->run().getProperty("end_time")->value() + : WS->run().getLastPulseTime()); + Types::Core::DateAndTime filter_time_start; + Types::Core::DateAndTime filter_time_stop; + // const bool time_filtering = (filter_time_start_sec != EMPTY_DBL() && filter_time_stop_sec != EMPTY_DBL()); + // vector to stored to integrated counts by detector ID std::vector Y(max_detid - min_detid + 1, 0); @@ -212,24 +244,20 @@ void LoadEventAsWorkspace2D::exec() { const std::map> &allEntries = descriptor.getAllEntries(); prog->doReport("Reading and integrating data"); - + // int ct = 0; auto itClassEntries = allEntries.find("NXevent_data"); - if (itClassEntries != allEntries.end()) { const std::set &classEntries = itClassEntries->second; const std::regex classRegex("(/entry/)([^/]*)"); std::smatch groups; - for (const std::string &classEntry : classEntries) { if (std::regex_match(classEntry, groups, classRegex)) { const std::string entry_name(groups[2].str()); - // skip entries with junk data if (entry_name == "bank_error_events" || entry_name == "bank_unmapped_events") continue; - g_log.debug() << "Loading bank " << entry_name << '\n'; h5file.openGroup(entry_name, "NXevent_data"); @@ -239,6 +267,42 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_id"); else event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); + // closeGroup and skip this bank if there is no event + if (event_ids.size() == 1) { + h5file.closeGroup(); + continue; + } + // Load "h5file" into BankPulseTimes using a shared ptr + const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); + + // Get event_index from the "h5file" + const auto event_index = std::make_shared>( + Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); + + // if (runstart == Types::Core::DateAndTime::minimum()) { + // runstart = run().getFirstPulseTime() + // } + + if (filter_time_start_sec != EMPTY_DBL()) { + filter_time_start = runstart + filter_time_start_sec; + } else { + filter_time_start = runstart; + } + + if (filter_time_stop_sec != EMPTY_DBL()) { + filter_time_stop = runstart + filter_time_stop_sec; + // std::cout<<"end time is not empty"<getPulseIndices(filter_time_start, filter_time_stop); + std::cout << filter_time_stop << std::endl; + // Give pulseIndexer a TimeROI + const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); + // const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, std::vector event_times; if (tof_filtering) { @@ -247,21 +311,23 @@ void LoadEventAsWorkspace2D::exec() { else event_times = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_time_of_flight"); } - - for (size_t i = 0; i < event_ids.size(); i++) { - if (tof_filtering) { - const auto tof = event_times[i]; - if (tof < tof_min || tof > tof_max) + // Nested loop to loop through all the relavent pulses and relavent event_ids + for (const auto &pulse : pulseIndexer_time) { + // const auto &pulsetime = bankPulseTimes->pulseTime(pulse.pulseIndex); + // std::cout << pulsetime < tof_max) + continue; + } + const detid_t det_id = event_ids[i]; + if (det_id < min_detid || det_id > max_detid) continue; + Y[det_id - min_detid]++; } - - const detid_t det_id = event_ids[i]; - if (det_id < min_detid || det_id > max_detid) - continue; - - Y[det_id - min_detid]++; } - h5file.closeGroup(); } } diff --git a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h index 431cb6f64702..75afaa533147 100644 --- a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h +++ b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h @@ -25,6 +25,14 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { static LoadEventAsWorkspace2DTest *createSuite() { return new LoadEventAsWorkspace2DTest(); } static void destroySuite(LoadEventAsWorkspace2DTest *suite) { delete suite; } + void xtest_filterbytime() { + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "CNCS_7860_event.nxs")) + } + void test_EQSANS() { LoadEventAsWorkspace2D alg; alg.setChild(true); @@ -63,8 +71,12 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(outputWS->blocksize(), 1) TS_ASSERT_EQUALS(outputWS->getAxis(0)->unit()->unitID(), "Energy") - TS_ASSERT_EQUALS(outputWS->readY(0)[0], 1) - TS_ASSERT_EQUALS(outputWS->readE(0)[0], 1) + // TS_ASSERT_EQUALS(outputWS->readY(0)[0], 1) + // TS_ASSERT_EQUALS(outputWS->readE(0)[0], 1) + // I don't agree with original test to have values of 1 in Y(0)[0] and E(0)[0]. CNCS_7860_event.nxs bank5 + // has 0 total counts this should count as faulty detector and the feature is spurious and should be excluded. + TS_ASSERT_EQUALS(outputWS->readY(0)[0], 0) + TS_ASSERT_EQUALS(outputWS->readE(0)[0], 0) TS_ASSERT_EQUALS(outputWS->readX(0)[0], 2.85) TS_ASSERT_EQUALS(outputWS->readX(0)[1], 3.15) } From 1fa195a35d6d4a8dd42941f82bf1fbb1462dc184 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:00:00 -0400 Subject: [PATCH 06/21] implemented additional unit tests to test filter by time functionality --- .../src/LoadEventAsWorkspace2D.cpp | 37 ++-- .../test/LoadEventAsWorkspace2DTest.h | 181 +++++++++++++++++- 2 files changed, 193 insertions(+), 25 deletions(-) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 8852b2ea78be..7d86667be580 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -216,18 +216,22 @@ void LoadEventAsWorkspace2D::exec() { filter_time_start_sec = getProperty("FilterByTimeStart"); filter_time_stop_sec = getProperty("FilterByTimeStop"); - // if (!WS->run().hasProperty("start_time")) { - // g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); - // } + if (!WS->run().hasProperty("start_time")) { + g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); + } + Types::Core::DateAndTime runstart(WS->run().hasProperty("start_time") ? WS->run().getProperty("start_time")->value() : WS->run().getFirstPulseTime()); - // if (!WS->run().hasProperty("end_time")) { - // g_log.warning("This NXS file does not have an end time, last pulse time is used instead."); - // } + Types::Core::DateAndTime endtime; + if (WS->run().hasProperty("proton_charge") && + WS->run().getLastPulseTime() > WS->run().getProperty("end_time")->value()) { + endtime = WS->run().getLastPulseTime(); + g_log.warning("Last pulse time is used because the last pulse time is greater than the end time!"); + } else { + endtime = WS->run().getProperty("end_time")->value(); + } - Types::Core::DateAndTime endtime(WS->run().hasProperty("end_time") ? WS->run().getProperty("end_time")->value() - : WS->run().getLastPulseTime()); Types::Core::DateAndTime filter_time_start; Types::Core::DateAndTime filter_time_stop; // const bool time_filtering = (filter_time_start_sec != EMPTY_DBL() && filter_time_stop_sec != EMPTY_DBL()); @@ -267,8 +271,14 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_id"); else event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); + // closeGroup and skip this bank if there is no event + // std::vector total_counts; + // if (descriptor.isEntry("/entry/" + entry_name + "/total_counts", "SDS")) + // total_counts = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "total_counts"); if (event_ids.size() == 1) { + // std::cout <<"total_counts[0]"<getPulseIndices(filter_time_start, filter_time_stop); - std::cout << filter_time_stop << std::endl; + // Give pulseIndexer a TimeROI - const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); - // const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, + const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); std::vector event_times; if (tof_filtering) { @@ -312,9 +319,7 @@ void LoadEventAsWorkspace2D::exec() { event_times = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_time_of_flight"); } // Nested loop to loop through all the relavent pulses and relavent event_ids - for (const auto &pulse : pulseIndexer_time) { - // const auto &pulsetime = bankPulseTimes->pulseTime(pulse.pulseIndex); - // std::cout << pulsetime <initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + load->setProperty("FilterByTimeStart", "0.0"); + load->setProperty("FilterByTimeStop", "5.0"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } + + void test_BSS_filterbytimeStart() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + + // load with LoadEventAsWorkspace2D + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "5.0")) + // TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "5.0")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + // load with LoadEventNexus then do Integration + auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); + load->initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + load->setProperty("FilterByTimeStart", "5.0"); + // load->setProperty("FilterByTimeStop", "5.0"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } + + void test_BSS_filterbytimeStop() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + + // load with LoadEventAsWorkspace2D + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) + // TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "0.0")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "7.1")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + // load with LoadEventNexus then do Integration + auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); + load->initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + // load->setProperty("FilterByTimeStart", "0.0"); + load->setProperty("FilterByTimeStop", "7.1"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } +}; From 6c34de2551a41d83978f860184caba46eac69ac3 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:51:07 -0400 Subject: [PATCH 07/21] fixed format and added comments --- Framework/DataHandling/src/BankPulseTimes.cpp | 1 + .../src/LoadEventAsWorkspace2D.cpp | 41 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index c810d00f2ba6..5e747048fd27 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -54,6 +54,7 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector &peri : startTime(DEFAULT_START_TIME), periodNumbers(periodNumbers), have_period_info(true), m_sorting_info(PulseSorting::UNKNOWN) { + // Some old data use "pulse_time" instead of "event_time_zero" as entry try { file.openData("event_time_zero"); } catch (std::exception &e) { diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 7d86667be580..8a5939db9ce0 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -71,15 +71,14 @@ void LoadEventAsWorkspace2D::init() { "of times-of-flight. " "This is the maximum accepted value in microseconds. Keep " "blank to load all events."); - - declareProperty(std::make_unique>("FilterByTimeStart", EMPTY_DBL(), Direction::Input), - "Optional: To only include events after the provided start " - "time, in seconds (relative to the start of the run)."); - + declareProperty( + std::make_unique>("FilterByTimeStart", EMPTY_DBL(), Direction::Input), + "Optional: To only include events after the provided start " + "time, in seconds (relative to the start of the run). If left empty, it will take start time as default."); declareProperty(std::make_unique>("FilterByTimeStop", EMPTY_DBL(), Direction::Input), "Optional: To only include events before the provided stop " - "time, in seconds (relative to the start of the run)."); - + "time, in seconds (relative to the start of the run). if left empty, it will take run end time or " + "last pulse time as default."); declareProperty(std::make_unique>>( "LogAllowList", std::vector(), Direction::Input), "If specified, only these logs will be loaded from the file (each " @@ -216,6 +215,7 @@ void LoadEventAsWorkspace2D::exec() { filter_time_start_sec = getProperty("FilterByTimeStart"); filter_time_stop_sec = getProperty("FilterByTimeStop"); + // get the start time if (!WS->run().hasProperty("start_time")) { g_log.warning("This NXS file does not have a start time, first pulse time is used instead."); } @@ -223,6 +223,8 @@ void LoadEventAsWorkspace2D::exec() { Types::Core::DateAndTime runstart(WS->run().hasProperty("start_time") ? WS->run().getProperty("start_time")->value() : WS->run().getFirstPulseTime()); + // get end time, to account for some older DAS issue where last pulse time can be slightly greater than end time, use + // last pulse time in this case and check if WS has "proton_charge" property otherwise last pulse time doesn't exist. Types::Core::DateAndTime endtime; if (WS->run().hasProperty("proton_charge") && WS->run().getLastPulseTime() > WS->run().getProperty("end_time")->value()) { @@ -234,7 +236,6 @@ void LoadEventAsWorkspace2D::exec() { Types::Core::DateAndTime filter_time_start; Types::Core::DateAndTime filter_time_stop; - // const bool time_filtering = (filter_time_start_sec != EMPTY_DBL() && filter_time_stop_sec != EMPTY_DBL()); // vector to stored to integrated counts by detector ID std::vector Y(max_detid - min_detid + 1, 0); @@ -273,15 +274,11 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); // closeGroup and skip this bank if there is no event - // std::vector total_counts; - // if (descriptor.isEntry("/entry/" + entry_name + "/total_counts", "SDS")) - // total_counts = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "total_counts"); - if (event_ids.size() == 1) { - // std::cout <<"total_counts[0]"<(boost::ref(h5file), std::vector()); @@ -289,26 +286,24 @@ void LoadEventAsWorkspace2D::exec() { const auto event_index = std::make_shared>( Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); - // if (runstart == Types::Core::DateAndTime::minimum()) { - // runstart = run().getFirstPulseTime() - // } - + // if "filterTimeStart" is empty, use run start time as default if (filter_time_start_sec != EMPTY_DBL()) { filter_time_start = runstart + filter_time_start_sec; } else { filter_time_start = runstart; } + // if "filterTimeStop" is empty, use end time as default if (filter_time_stop_sec != EMPTY_DBL()) { filter_time_stop = runstart + filter_time_stop_sec; } else { filter_time_stop = endtime; } - // Use run_start time as starting reference in time and create a TimeROI using bankPulseTimes + // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); - // Give pulseIndexer a TimeROI + // set up PulseIndexer and give previous TimeROI to pulseIndexer const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); std::vector event_times; @@ -318,7 +313,11 @@ void LoadEventAsWorkspace2D::exec() { else event_times = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_time_of_flight"); } - // Nested loop to loop through all the relavent pulses and relavent event_ids + + // Nested loop to loop through all the relavent pulses and relavent event_ids. + // For someone new to this, every pulse creates an entry in event_index, event_index.size() = # of pulses, + // the value of event_index[i] points to the index of event_ids. In short, event_ids[event_index[i]] is the + // detector id from the i-th pulse. See NXevent_data description for more details. for (const auto &pulse : pulseIndexer) { for (size_t i = pulse.eventIndexStart; i < pulse.eventIndexStop; i++) { // for (size_t i = 0; i < event_ids.size(); i++) { From 54d5c9257ebf6f15be19abfbf46cffd92ce8fa79 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:53:37 -0400 Subject: [PATCH 08/21] minor fixes --- Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 8a5939db9ce0..9f94d09f0bb9 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -249,7 +249,6 @@ void LoadEventAsWorkspace2D::exec() { const std::map> &allEntries = descriptor.getAllEntries(); prog->doReport("Reading and integrating data"); - // int ct = 0; auto itClassEntries = allEntries.find("NXevent_data"); if (itClassEntries != allEntries.end()) { From 415259484fdbf65bdc136132b563deb4117d2937 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Fri, 16 Aug 2024 12:08:43 -0400 Subject: [PATCH 09/21] fixed small merge issue in test --- Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h index 11001e8acd92..ef8358fd28da 100644 --- a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h +++ b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h @@ -69,10 +69,6 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { // has 0 total counts this should count as faulty detector and the feature is spurious and should be excluded. TS_ASSERT_EQUALS(outputWS->readY(0)[0], 0) TS_ASSERT_EQUALS(outputWS->readE(0)[0], 0) - // I don't agree with original test to have values of 1 in Y(0)[0] and E(0)[0]. CNCS_7860_event.nxs bank5 - // has 0 total counts this should count as faulty detector and the feature is spurious and should be excluded. - TS_ASSERT_EQUALS(outputWS->readY(0)[0], 0) - TS_ASSERT_EQUALS(outputWS->readE(0)[0], 0) TS_ASSERT_EQUALS(outputWS->readX(0)[0], 2.85) TS_ASSERT_EQUALS(outputWS->readX(0)[1], 3.15) } From a7c15a9bb24de5c3999a33058b2eb110fd6a2164 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Fri, 16 Aug 2024 12:13:00 -0400 Subject: [PATCH 10/21] fix more duplicated code from merge conflicts --- .../test/LoadEventAsWorkspace2DTest.h | 178 +----------------- 1 file changed, 4 insertions(+), 174 deletions(-) diff --git a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h index ef8358fd28da..1a60ed528aa0 100644 --- a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h +++ b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h @@ -272,178 +272,8 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { } void test_BSS_filterbytimeStart() { - // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data - - // load with LoadEventAsWorkspace2D - LoadEventAsWorkspace2D alg; - alg.setChild(true); - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "5.0")) - // TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "5.0")) - TS_ASSERT(alg.execute()); - - Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); - TS_ASSERT(outputWS); - - // load with LoadEventNexus then do Integration - auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); - load->initialize(); - load->setChild(true); - load->setProperty("Filename", "BSS_11841_event.nxs"); - load->setProperty("FilterByTimeStart", "5.0"); - // load->setProperty("FilterByTimeStop", "5.0"); - load->execute(); - Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); - TS_ASSERT(outputWS2); - - auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); - integrate->initialize(); - integrate->setChild(true); - integrate->setProperty("InputWorkspace", outputWS2); - integrate->setProperty("RangeLower", 0.0); - integrate->execute(); - - Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); - TS_ASSERT(outputWS3); - - // set the expected X-axis - outputWS3->getAxis(0)->setUnit("Wavelength"); - const auto xBins = {1.463, 1.617}; - const auto histX = Mantid::Kernel::make_cow(xBins); - for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) - outputWS3->setSharedX(i, histX); - - // compare workspaces - auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); - compare->initialize(); - compare->setChild(true); - compare->setProperty("Workspace1", outputWS); - compare->setProperty("Workspace2", outputWS3); - compare->execute(); - TS_ASSERT(compare->getProperty("Result")); - } - - void test_BSS_filterbytimeStop() { - // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data - - // load with LoadEventAsWorkspace2D - LoadEventAsWorkspace2D alg; - alg.setChild(true); - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) - // TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "0.0")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "7.1")) - TS_ASSERT(alg.execute()); - - Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); - TS_ASSERT(outputWS); - - // load with LoadEventNexus then do Integration - auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); - load->initialize(); - load->setChild(true); - load->setProperty("Filename", "BSS_11841_event.nxs"); - // load->setProperty("FilterByTimeStart", "0.0"); - load->setProperty("FilterByTimeStop", "7.1"); - load->execute(); - Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); - TS_ASSERT(outputWS2); - - auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); - integrate->initialize(); - integrate->setChild(true); - integrate->setProperty("InputWorkspace", outputWS2); - integrate->setProperty("RangeLower", 0.0); - integrate->execute(); - - Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); - TS_ASSERT(outputWS3); - - // set the expected X-axis - outputWS3->getAxis(0)->setUnit("Wavelength"); - const auto xBins = {1.463, 1.617}; - const auto histX = Mantid::Kernel::make_cow(xBins); - for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) - outputWS3->setSharedX(i, histX); - - // compare workspaces - auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); - compare->initialize(); - compare->setChild(true); - compare->setProperty("Workspace1", outputWS); - compare->setProperty("Workspace2", outputWS3); - compare->execute(); - TS_ASSERT(compare->getProperty("Result")); - } - - void test_BSS_filterbytimeROI() { - // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data - - // load with LoadEventAsWorkspace2D - LoadEventAsWorkspace2D alg; - alg.setChild(true); - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "0.0")) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "5.0")) - TS_ASSERT(alg.execute()); - - Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); - TS_ASSERT(outputWS); - - // load with LoadEventNexus then do Integration - auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); - load->initialize(); - load->setChild(true); - load->setProperty("Filename", "BSS_11841_event.nxs"); - load->setProperty("FilterByTimeStart", "0.0"); - load->setProperty("FilterByTimeStop", "5.0"); - load->execute(); - Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); - TS_ASSERT(outputWS2); - - auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); - integrate->initialize(); - integrate->setChild(true); - integrate->setProperty("InputWorkspace", outputWS2); - integrate->setProperty("RangeLower", 0.0); - integrate->execute(); - - Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); - TS_ASSERT(outputWS3); - - // set the expected X-axis - outputWS3->getAxis(0)->setUnit("Wavelength"); - const auto xBins = {1.463, 1.617}; - const auto histX = Mantid::Kernel::make_cow(xBins); - for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) - outputWS3->setSharedX(i, histX); - - // compare workspaces - auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); - compare->initialize(); - compare->setChild(true); - compare->setProperty("Workspace1", outputWS); - compare->setProperty("Workspace2", outputWS3); - compare->execute(); - TS_ASSERT(compare->getProperty("Result")); - } - - void test_BSS_filterbytimeStart() { - // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering from 5.0s of data + // till the end of run when FiltertByTimeStop is not given. // load with LoadEventAsWorkspace2D LoadEventAsWorkspace2D alg; @@ -500,8 +330,8 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { } void test_BSS_filterbytimeStop() { - // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data - + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering from start + // till 7.1s of run when FiltertByTimeStart is not given. // load with LoadEventAsWorkspace2D LoadEventAsWorkspace2D alg; alg.setChild(true); From e73f15f19f0cb14bef720e1cc3d73f79c9077d4c Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Fri, 16 Aug 2024 13:34:49 -0400 Subject: [PATCH 11/21] added release note --- .../release/v6.11.0/Framework/Algorithms/New_features/37816.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst diff --git a/docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst b/docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst new file mode 100644 index 000000000000..7e195e91a58e --- /dev/null +++ b/docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst @@ -0,0 +1 @@ +- New version 2 of :ref:`LoadEventAsWorkspace2D ` that adds FilterByTime functionality. \ No newline at end of file From be1149fc2544f8c77be8f8ac3267103973dce631 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Mon, 19 Aug 2024 15:58:36 -0400 Subject: [PATCH 12/21] deleted e in line 60 of BankPulseTimes.cpp that failed conda:windows test --- Framework/DataHandling/src/BankPulseTimes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index 5e747048fd27..34b158ea201d 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -57,7 +57,7 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector &peri // Some old data use "pulse_time" instead of "event_time_zero" as entry try { file.openData("event_time_zero"); - } catch (std::exception &e) { + } catch (std::exception &) { file.openData("pulse_time"); } // Read the offset (time zero) From 055aa611f01b0f7edd297e4cb2a81f065ec15ede Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Tue, 20 Aug 2024 09:43:43 -0400 Subject: [PATCH 13/21] made the exception const --- Framework/DataHandling/src/BankPulseTimes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index 34b158ea201d..f0dbc6ed0d70 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -57,7 +57,7 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector &peri // Some old data use "pulse_time" instead of "event_time_zero" as entry try { file.openData("event_time_zero"); - } catch (std::exception &) { + } catch (const std::exception &) { file.openData("pulse_time"); } // Read the offset (time zero) From f635c21389dbeb40e574871d63602fdff8b8063f Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Tue, 13 Aug 2024 14:57:38 -0400 Subject: [PATCH 14/21] inital commit add codes that filters by time --- .../src/LoadEventAsWorkspace2D.cpp | 102 ++++++++++++++++++ .../test/LoadEventAsWorkspace2DTest.h | 8 ++ 2 files changed, 110 insertions(+) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 9f94d09f0bb9..30749415f683 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -271,6 +271,108 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_id"); else event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); + // closeGroup and skip this bank if there is no event + if (event_ids.size() == 1) { + h5file.closeGroup(); + continue; + } + // Load "h5file" into BankPulseTimes using a shared ptr + const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); + + // Get event_index from the "h5file" + const auto event_index = std::make_shared>( + Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); + + // if (runstart == Types::Core::DateAndTime::minimum()) { + // runstart = run().getFirstPulseTime() + // } + + if (filter_time_start_sec != EMPTY_DBL()) { + filter_time_start = runstart + filter_time_start_sec; + } else { + filter_time_start = runstart; + } + + if (filter_time_stop_sec != EMPTY_DBL()) { + filter_time_stop = runstart + filter_time_stop_sec; + // std::cout<<"end time is not empty"<getPulseIndices(filter_time_start, filter_time_stop); + std::cout << filter_time_stop << std::endl; + // Give pulseIndexer a TimeROI + const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); + // const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, + + // closeGroup and skip this bank if there is no event + if (event_ids.size() <= 1) { + h5file.closeGroup(); + continue; + } + + // Load "h5file" into BankPulseTimes using a shared ptr + const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); + + // Get event_index from the "h5file" + const auto event_index = std::make_shared>( + Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); + + // if "filterTimeStart" is empty, use run start time as default + if (filter_time_start_sec != EMPTY_DBL()) { + filter_time_start = runstart + filter_time_start_sec; + } else { + filter_time_start = runstart; + } + + // if "filterTimeStop" is empty, use end time as default + if (filter_time_stop_sec != EMPTY_DBL()) { + filter_time_stop = runstart + filter_time_stop_sec; + } else { + filter_time_stop = endtime; + } + + // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes + const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); + + // set up PulseIndexer and give previous TimeROI to pulseIndexer + const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); + + // closeGroup and skip this bank if there is no event + if (event_ids.size() <= 1) { + h5file.closeGroup(); + continue; + } + + // Load "h5file" into BankPulseTimes using a shared ptr + const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); + + // Get event_index from the "h5file" + const auto event_index = std::make_shared>( + Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); + + // if "filterTimeStart" is empty, use run start time as default + if (filter_time_start_sec != EMPTY_DBL()) { + filter_time_start = runstart + filter_time_start_sec; + } else { + filter_time_start = runstart; + } + + // if "filterTimeStop" is empty, use end time as default + if (filter_time_stop_sec != EMPTY_DBL()) { + filter_time_stop = runstart + filter_time_stop_sec; + } else { + filter_time_stop = endtime; + } + + // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes + const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); + + // set up PulseIndexer and give previous TimeROI to pulseIndexer + const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); // closeGroup and skip this bank if there is no event if (event_ids.size() <= 1) { diff --git a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h index 1df13f104529..a5de1579b828 100644 --- a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h +++ b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h @@ -25,6 +25,14 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { static LoadEventAsWorkspace2DTest *createSuite() { return new LoadEventAsWorkspace2DTest(); } static void destroySuite(LoadEventAsWorkspace2DTest *suite) { delete suite; } + void xtest_filterbytime() { + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "CNCS_7860_event.nxs")) + } + void test_EQSANS() { LoadEventAsWorkspace2D alg; alg.setChild(true); From 33a9fd86114e824c567b83c4bde08aa1cb3171d2 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:00:00 -0400 Subject: [PATCH 15/21] implemented additional unit tests to test filter by time functionality --- Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp | 10 +++++++--- .../DataHandling/test/LoadEventAsWorkspace2DTest.h | 8 -------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 30749415f683..7c1d27b200ea 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -271,8 +271,14 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_id"); else event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); + // closeGroup and skip this bank if there is no event + // std::vector total_counts; + // if (descriptor.isEntry("/entry/" + entry_name + "/total_counts", "SDS")) + // total_counts = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "total_counts"); if (event_ids.size() == 1) { + // std::cout <<"total_counts[0]"<getPulseIndices(filter_time_start, filter_time_stop); - std::cout << filter_time_stop << std::endl; + // Give pulseIndexer a TimeROI const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); // const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, diff --git a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h index a5de1579b828..1df13f104529 100644 --- a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h +++ b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h @@ -25,14 +25,6 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { static LoadEventAsWorkspace2DTest *createSuite() { return new LoadEventAsWorkspace2DTest(); } static void destroySuite(LoadEventAsWorkspace2DTest *suite) { delete suite; } - void xtest_filterbytime() { - LoadEventAsWorkspace2D alg; - alg.setChild(true); - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "CNCS_7860_event.nxs")) - } - void test_EQSANS() { LoadEventAsWorkspace2D alg; alg.setChild(true); From 09237cb56814b59d0f50177a18318afa54216146 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Thu, 15 Aug 2024 10:51:07 -0400 Subject: [PATCH 16/21] fixed format and added comments --- .../DataHandling/src/LoadEventAsWorkspace2D.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index 7c1d27b200ea..d69a0d163756 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -273,15 +273,11 @@ void LoadEventAsWorkspace2D::exec() { event_ids = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_pixel_id"); // closeGroup and skip this bank if there is no event - // std::vector total_counts; - // if (descriptor.isEntry("/entry/" + entry_name + "/total_counts", "SDS")) - // total_counts = Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "total_counts"); - if (event_ids.size() == 1) { - // std::cout <<"total_counts[0]"<(boost::ref(h5file), std::vector()); @@ -289,23 +285,21 @@ void LoadEventAsWorkspace2D::exec() { const auto event_index = std::make_shared>( Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); - // if (runstart == Types::Core::DateAndTime::minimum()) { - // runstart = run().getFirstPulseTime() - // } - + // if "filterTimeStart" is empty, use run start time as default if (filter_time_start_sec != EMPTY_DBL()) { filter_time_start = runstart + filter_time_start_sec; } else { filter_time_start = runstart; } + // if "filterTimeStop" is empty, use end time as default if (filter_time_stop_sec != EMPTY_DBL()) { filter_time_stop = runstart + filter_time_stop_sec; } else { filter_time_stop = endtime; } - // Use run_start time as starting reference in time and create a TimeROI using bankPulseTimes + // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); // Give pulseIndexer a TimeROI From a157def3d550eec2e7c488e3184968dcddfd26e9 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Fri, 16 Aug 2024 12:13:00 -0400 Subject: [PATCH 17/21] fix more duplicated code from merge conflicts --- .../test/LoadEventAsWorkspace2DTest.h | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h index 1df13f104529..8204eb652330 100644 --- a/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h +++ b/Framework/DataHandling/test/LoadEventAsWorkspace2DTest.h @@ -331,6 +331,125 @@ class LoadEventAsWorkspace2DTest : public CxxTest::TestSuite { void test_BSS_filterbytimeStop() { // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + + void test_BSS_filterbytimeROI() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering 0.0 to 5.0s of data + + // load with LoadEventAsWorkspace2D + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "0.0")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "5.0")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + // load with LoadEventNexus then do Integration + auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); + load->initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + load->setProperty("FilterByTimeStart", "0.0"); + load->setProperty("FilterByTimeStop", "5.0"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } + + void test_BSS_filterbytimeStart() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering from 5.0s of data + // till the end of run when FiltertByTimeStop is not given. + + // load with LoadEventAsWorkspace2D + LoadEventAsWorkspace2D alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "BSS_11841_event.nxs")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XCenter", "1.54")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("XWidth", "0.1")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStart", "5.0")) + // TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("FilterByTimeStop", "5.0")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::Workspace2D_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + // load with LoadEventNexus then do Integration + auto load = AlgorithmManager::Instance().createUnmanaged("LoadEventNexus"); + load->initialize(); + load->setChild(true); + load->setProperty("Filename", "BSS_11841_event.nxs"); + load->setProperty("FilterByTimeStart", "5.0"); + // load->setProperty("FilterByTimeStop", "5.0"); + load->execute(); + Mantid::API::Workspace_sptr outputWS2 = load->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS2); + + auto integrate = AlgorithmManager::Instance().createUnmanaged("Integration"); + integrate->initialize(); + integrate->setChild(true); + integrate->setProperty("InputWorkspace", outputWS2); + integrate->setProperty("RangeLower", 0.0); + integrate->execute(); + + Mantid::API::MatrixWorkspace_sptr outputWS3 = integrate->getProperty("OutputWorkspace"); + TS_ASSERT(outputWS3); + + // set the expected X-axis + outputWS3->getAxis(0)->setUnit("Wavelength"); + const auto xBins = {1.463, 1.617}; + const auto histX = Mantid::Kernel::make_cow(xBins); + for (size_t i = 0; i < outputWS3->getNumberHistograms(); i++) + outputWS3->setSharedX(i, histX); + + // compare workspaces + auto compare = AlgorithmManager::Instance().createUnmanaged("CompareWorkspaces"); + compare->initialize(); + compare->setChild(true); + compare->setProperty("Workspace1", outputWS); + compare->setProperty("Workspace2", outputWS3); + compare->execute(); + TS_ASSERT(compare->getProperty("Result")); + } + + void test_BSS_filterbytimeStop() { + // compare loading with LoadEventAsWorkspace2D to LoadEventNexus+Integration by filtering from start + // till 7.1s of run when FiltertByTimeStart is not given. // load with LoadEventAsWorkspace2D LoadEventAsWorkspace2D alg; alg.setChild(true); From c0e24c591776f3c921d1baef0a186d6293bfb919 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Fri, 16 Aug 2024 13:34:49 -0400 Subject: [PATCH 18/21] added release note --- .../release/v6.11.0/Framework/Algorithms/New_features/37816.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst diff --git a/docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst b/docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst new file mode 100644 index 000000000000..7e195e91a58e --- /dev/null +++ b/docs/source/release/v6.11.0/Framework/Algorithms/New_features/37816.rst @@ -0,0 +1 @@ +- New version 2 of :ref:`LoadEventAsWorkspace2D ` that adds FilterByTime functionality. \ No newline at end of file From 62ebc945d270e6afb70973ab92a2dacbf16c8863 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Mon, 19 Aug 2024 15:58:36 -0400 Subject: [PATCH 19/21] deleted e in line 60 of BankPulseTimes.cpp that failed conda:windows test --- Framework/DataHandling/src/BankPulseTimes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index 5e747048fd27..34b158ea201d 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -57,7 +57,7 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector &peri // Some old data use "pulse_time" instead of "event_time_zero" as entry try { file.openData("event_time_zero"); - } catch (std::exception &e) { + } catch (std::exception &) { file.openData("pulse_time"); } // Read the offset (time zero) From 78eb9b2d6779566db496f1d13798088d9d87ee99 Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Tue, 20 Aug 2024 09:43:43 -0400 Subject: [PATCH 20/21] made the exception const --- Framework/DataHandling/src/BankPulseTimes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/DataHandling/src/BankPulseTimes.cpp b/Framework/DataHandling/src/BankPulseTimes.cpp index 34b158ea201d..f0dbc6ed0d70 100644 --- a/Framework/DataHandling/src/BankPulseTimes.cpp +++ b/Framework/DataHandling/src/BankPulseTimes.cpp @@ -57,7 +57,7 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector &peri // Some old data use "pulse_time" instead of "event_time_zero" as entry try { file.openData("event_time_zero"); - } catch (std::exception &) { + } catch (const std::exception &) { file.openData("pulse_time"); } // Read the offset (time zero) From e393fadf419a898b5e6c301b002045efa6b6154c Mon Sep 17 00:00:00 2001 From: Kyle Ma Date: Wed, 21 Aug 2024 14:46:25 -0400 Subject: [PATCH 21/21] fixing rebasing issues --- .../src/LoadEventAsWorkspace2D.cpp | 100 ------------------ 1 file changed, 100 deletions(-) diff --git a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp index d69a0d163756..9f94d09f0bb9 100644 --- a/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp +++ b/Framework/DataHandling/src/LoadEventAsWorkspace2D.cpp @@ -302,106 +302,6 @@ void LoadEventAsWorkspace2D::exec() { // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); - // Give pulseIndexer a TimeROI - const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); - // const PulseIndexer pulseIndexer_time(event_index, event_index->at(0), event_ids.size(), entry_name, - - // closeGroup and skip this bank if there is no event - if (event_ids.size() <= 1) { - h5file.closeGroup(); - continue; - } - - // Load "h5file" into BankPulseTimes using a shared ptr - const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); - - // Get event_index from the "h5file" - const auto event_index = std::make_shared>( - Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); - - // if "filterTimeStart" is empty, use run start time as default - if (filter_time_start_sec != EMPTY_DBL()) { - filter_time_start = runstart + filter_time_start_sec; - } else { - filter_time_start = runstart; - } - - // if "filterTimeStop" is empty, use end time as default - if (filter_time_stop_sec != EMPTY_DBL()) { - filter_time_stop = runstart + filter_time_stop_sec; - } else { - filter_time_stop = endtime; - } - - // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes - const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); - - // set up PulseIndexer and give previous TimeROI to pulseIndexer - const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); - - // closeGroup and skip this bank if there is no event - if (event_ids.size() <= 1) { - h5file.closeGroup(); - continue; - } - - // Load "h5file" into BankPulseTimes using a shared ptr - const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); - - // Get event_index from the "h5file" - const auto event_index = std::make_shared>( - Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); - - // if "filterTimeStart" is empty, use run start time as default - if (filter_time_start_sec != EMPTY_DBL()) { - filter_time_start = runstart + filter_time_start_sec; - } else { - filter_time_start = runstart; - } - - // if "filterTimeStop" is empty, use end time as default - if (filter_time_stop_sec != EMPTY_DBL()) { - filter_time_stop = runstart + filter_time_stop_sec; - } else { - filter_time_stop = endtime; - } - - // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes - const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); - - // set up PulseIndexer and give previous TimeROI to pulseIndexer - const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI); - - // closeGroup and skip this bank if there is no event - if (event_ids.size() <= 1) { - h5file.closeGroup(); - continue; - } - - // Load "h5file" into BankPulseTimes using a shared ptr - const auto bankPulseTimes = std::make_shared(boost::ref(h5file), std::vector()); - - // Get event_index from the "h5file" - const auto event_index = std::make_shared>( - Mantid::NeXus::NeXusIOHelper::readNexusVector(h5file, "event_index")); - - // if "filterTimeStart" is empty, use run start time as default - if (filter_time_start_sec != EMPTY_DBL()) { - filter_time_start = runstart + filter_time_start_sec; - } else { - filter_time_start = runstart; - } - - // if "filterTimeStop" is empty, use end time as default - if (filter_time_stop_sec != EMPTY_DBL()) { - filter_time_stop = runstart + filter_time_stop_sec; - } else { - filter_time_stop = endtime; - } - - // Use filter_time_start time as starting reference in time and create a TimeROI using bankPulseTimes - const auto TimeROI = bankPulseTimes->getPulseIndices(filter_time_start, filter_time_stop); - // set up PulseIndexer and give previous TimeROI to pulseIndexer const PulseIndexer pulseIndexer(event_index, event_index->at(0), event_ids.size(), entry_name, TimeROI);