Mantid
Loading...
Searching...
No Matches
MultiPeriodLoadMuonStrategy.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "MantidAPI/Run.h"
14
15namespace Mantid::DataHandling {
16
17using namespace API;
18using namespace Nexus;
19using namespace DataObjects;
20
21namespace {
22const std::string GOODFRAMESPROP{"goodfrm"};
23constexpr bool MULTIPERIODSLOADED = true;
24} // namespace
25
26// Constructor
28 LoadMuonNexusV2NexusHelper &nexusLoader,
30 : LoadMuonStrategy(g_log, filename, nexusLoader), m_workspaceGroup(workspace), m_detectors(getLoadedDetectors()) {}
31
37 auto sampleInformation = m_nexusLoader.loadSampleInformationFromNexus();
38 std::string mainFieldDirection = m_nexusLoader.loadMainFieldDirectionFromNexus();
39 double firstGoodData = m_nexusLoader.loadFirstGoodDataFromNexus();
40
41 for (int i = 0; i < m_workspaceGroup.getNumberOfEntries(); ++i) {
42 auto workspace = std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(i));
43 auto &run = workspace->mutableRun();
44 run.addProperty("main_field_direction", mainFieldDirection);
45 run.addProperty("FirstGoodData", firstGoodData);
46 run.addProperty("sample_temp", sampleInformation.temperature);
47 run.addProperty("sample_magn_field", sampleInformation.magneticField);
48 }
49}
54 NXInt goodframes = m_nexusLoader.loadGoodFramesDataFromNexus(MULTIPERIODSLOADED);
55 for (int i = 0; i < m_workspaceGroup.getNumberOfEntries(); ++i) {
56 auto workspace = std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(i));
57 auto &run = workspace->mutableRun();
58 run.removeProperty(GOODFRAMESPROP);
59 run.addProperty(GOODFRAMESPROP, goodframes[i]);
60 }
61}
62
70 // Each period could in theory have its own grouping, which is reflected in
71 // the nexus file which has (periods*numDetectors) entries in the Nexus
72 // grouping entry.
73 WorkspaceGroup_sptr tableGroup = std::make_shared<WorkspaceGroup>();
74 for (int i = 0; i < m_workspaceGroup.getNumberOfEntries(); ++i) {
75 int periodNumber = i + 1;
76 auto const grouping = m_nexusLoader.loadDetectorGroupingFromNexus(m_detectors, MULTIPERIODSLOADED, periodNumber);
77 auto const table = createDetectorGroupingTable(m_detectors, grouping);
78 // if any of the tables are empty we'll load grouping from the IDF
79 if (!table || (*table)->rowCount() == 0) {
80 return loadDefaultDetectorGrouping(*std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(i)));
81 }
82 tableGroup->addWorkspace(*table);
83 }
84 return tableGroup;
85}
90 double timeZero = m_nexusLoader.loadTimeZeroFromNexusFile();
91 for (int wsIndex = 0; wsIndex < m_workspaceGroup.getNumberOfEntries(); ++wsIndex) {
92 auto workspace = std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(wsIndex));
93 auto numHistograms = workspace->getNumberHistograms();
94 for (size_t i = 0; i < numHistograms; ++i) {
95 auto &timeAxis = workspace->mutableX(i);
96 timeAxis = timeAxis - timeZero;
97 }
98 }
99}
100// Load dead time table
102 WorkspaceGroup_sptr tableGroup = std::make_shared<WorkspaceGroup>();
103 for (int i = 0; i < m_workspaceGroup.getNumberOfEntries(); ++i) {
104 int periodNumber = i + 1;
105 auto deadTimes = m_nexusLoader.loadDeadTimesFromNexus(m_detectors, MULTIPERIODSLOADED, periodNumber);
106 tableGroup->addWorkspace(createDeadTimeTable(m_detectors, deadTimes));
107 }
108 return tableGroup;
109}
110
117 auto workspace = std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(0));
118 const auto numSpec = workspace->getNumberHistograms();
119 auto timeZeros = m_nexusLoader.loadTimeZeroListFromNexusFile(numSpec);
120 return createTimeZeroTable(numSpec, timeZeros);
121}
122
127 // Assume each spectrum maps to the same detector in each period.
128 auto workspace = std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(0));
130}
131
132} // namespace Mantid::DataHandling
IPeaksWorkspace_sptr workspace
Class to hold a set of workspaces.
int getNumberOfEntries() const
Return the number of entries within the group.
Workspace_sptr getItem(const size_t index) const
Return the ith workspace.
std::vector< double > loadDeadTimesFromNexus(const std::vector< detid_t > &loadedDetectors, bool isFileMultiPeriod, int periodNumber)
std::optional< std::vector< detid_t > > loadDetectorGroupingFromNexus(const std::vector< detid_t > &loadedDetectors, bool isFileMultiPeriod, int periodNumber)
std::vector< double > loadTimeZeroListFromNexusFile(size_t numSpectra)
Nexus::NXInt loadGoodFramesDataFromNexus(bool isFileMultiPeriod)
std::optional< DataObjects::TableWorkspace_sptr > createDetectorGroupingTable(const std::vector< detid_t > &specToLoad, const std::optional< std::vector< detid_t > > &grouping) const
Creates Detector Grouping Table .
DataObjects::TableWorkspace_sptr createDeadTimeTable(const std::vector< detid_t > &detectorsLoaded, const std::vector< double > &deadTimes) const
Creates the deadtime table for the loaded detectors .
std::vector< detid_t > getLoadedDetectorsFromWorkspace(const DataObjects::Workspace2D &localWorkspace) const
Determines the detectors loaded in the input workspace.
API::Workspace_sptr loadDefaultDetectorGrouping(const DataObjects::Workspace2D &localWorkspace) const
Loads default detector grouping, if this isn't present return dummy grouping.
LoadMuonNexusV2NexusHelper & m_nexusLoader
std::vector< detid_t > getLoadedDetectors()
Finds the detectors which are loaded in the stored workspace group.
API::Workspace_sptr loadDetectorGrouping() const override
Loads detector grouping.
API::Workspace_sptr getTimeZeroTable() override
Gets time zero table from loaded time zeros Assumes all periods have same time zero.
void loadGoodFrames() override
Loads the good frames data into each of the stored workspace objects.
void applyTimeZeroCorrection() override
Performs time-zero correction on the loaded workspace.
void loadMuonLogData() override
Loads Muon specific logs into each of the workspaces in the workspace group.
MultiPeriodLoadMuonStrategy(Kernel::Logger &g_log, const std::string &filename, LoadMuonNexusV2NexusHelper &nexusLoader, API::WorkspaceGroup &workspaceGroup)
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
Templated class implementation of NXDataSet.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
DataObjects::TableWorkspace_sptr createTimeZeroTable(const size_t numSpec, const std::vector< double > &timeZeros)
Creates a timezero table for the loaded detectors.