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"
13
14namespace Mantid::DataHandling {
15
16using namespace API;
17using namespace NeXus;
18using namespace DataObjects;
19
20namespace {
21const std::string GOODFRAMESPROP{"goodfrm"};
22constexpr bool MULTIPERIODSLOADED = true;
23} // namespace
24
25// Constructor
27 LoadMuonNexusV2NexusHelper &nexusLoader,
29 : LoadMuonStrategy(g_log, filename, nexusLoader), m_workspaceGroup(workspace), m_detectors(getLoadedDetectors()) {}
30
36 auto sampleInformation = m_nexusLoader.loadSampleInformationFromNexus();
37 std::string mainFieldDirection = m_nexusLoader.loadMainFieldDirectionFromNexus();
38 double firstGoodData = m_nexusLoader.loadFirstGoodDataFromNexus();
39
40 for (int i = 0; i < m_workspaceGroup.getNumberOfEntries(); ++i) {
41 auto workspace = std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(i));
42 auto &run = workspace->mutableRun();
43 run.addProperty("main_field_direction", mainFieldDirection);
44 run.addProperty("FirstGoodData", firstGoodData);
45 run.addProperty("sample_temp", sampleInformation.temperature);
46 run.addProperty("sample_magn_field", sampleInformation.magneticField);
47 }
48}
53 NXInt goodframes = m_nexusLoader.loadGoodFramesDataFromNexus(MULTIPERIODSLOADED);
54 for (int i = 0; i < m_workspaceGroup.getNumberOfEntries(); ++i) {
55 auto workspace = std::dynamic_pointer_cast<Workspace2D>(m_workspaceGroup.getItem(i));
56 auto &run = workspace->mutableRun();
57 run.removeProperty(GOODFRAMESPROP);
58 run.addProperty(GOODFRAMESPROP, goodframes[i]);
59 }
60}
61
69 // Each period could in theory have its own grouping, which is reflected in
70 // the nexus file which has (periods*numDetectors) entries in the Nexus
71 // grouping entry.
72 WorkspaceGroup_sptr tableGroup = std::make_shared<WorkspaceGroup>();
73 for (int i = 0; i < m_workspaceGroup.getNumberOfEntries(); ++i) {
74 int periodNumber = i + 1;
75 auto grouping = m_nexusLoader.loadDetectorGroupingFromNexus(m_detectors, MULTIPERIODSLOADED, periodNumber);
77 // if any of the tables are empty we'll load grouping from the IDF
78 if (table->rowCount() == 0) {
79 m_logger.notice("Loading grouping information from IDF");
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
Definition: IndexPeaks.cpp:114
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::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)
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.
DataObjects::TableWorkspace_sptr createDetectorGroupingTable(const std::vector< detid_t > &specToLoad, const std::vector< detid_t > &grouping) const
Creates Detector Grouping Table .
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:52
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
Templated class implementation of NXDataSet.
Definition: NexusClasses.h:203
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
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.
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace