Mantid
Loading...
Searching...
No Matches
LoadMuonStrategy.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
6// SPDX - License - Identifier: GPL - 3.0 +
7
10#include "MantidAPI/Run.h"
11#include "MantidAPI/TableRow.h"
16#include <vector>
17
18namespace Mantid::DataHandling {
19
26DataObjects::TableWorkspace_sptr createTimeZeroTable(const size_t numSpec, const std::vector<double> &timeZeros) {
28 std::dynamic_pointer_cast<Mantid::DataObjects::TableWorkspace>(
29 Mantid::API::WorkspaceFactory::Instance().createTable("TableWorkspace"));
30 timeZeroTable->addColumn("double", "time zero");
31
32 for (size_t specNum = 0; specNum < numSpec; ++specNum) {
33 Mantid::API::TableRow row = timeZeroTable->appendRow();
34 row << timeZeros[specNum];
35 }
36
37 return timeZeroTable;
38}
39
40// Constructor
42 : m_logger(g_log), m_filename(std::move(filename)), m_nexusLoader(nexusLoader) {}
43
51
52 auto instrument = localWorkspace.getInstrument();
53 auto &run = localWorkspace.run();
54 std::string mainFieldDirection = run.getLogData("main_field_direction")->value();
55 API::GroupingLoader groupLoader(instrument, mainFieldDirection);
56 try {
57 const auto idfGrouping = groupLoader.getGroupingFromIDF();
58 return idfGrouping->toTable();
59 } catch (const std::runtime_error &) {
60 auto dummyGrouping = std::make_shared<API::Grouping>();
61 if (instrument->getNumberDetectors() != 0) {
62 dummyGrouping = groupLoader.getDummyGrouping();
63 } else {
64 // Make sure it uses the right number of detectors
65 std::string numDetectors = "1-" + std::to_string(localWorkspace.getNumberHistograms());
66 dummyGrouping->groups.emplace_back(std::move(numDetectors));
67 dummyGrouping->groupNames.emplace_back("all");
68 }
69 return dummyGrouping->toTable();
70 }
71}
76std::vector<detid_t>
78 size_t numberOfSpectra = localWorkspace.getNumberHistograms();
79 std::vector<detid_t> loadedDetectors;
80 loadedDetectors.reserve(numberOfSpectra);
81 for (size_t spectraIndex = 0; spectraIndex < numberOfSpectra; spectraIndex++) {
82 const auto detIdSet = localWorkspace.getSpectrum(spectraIndex).getDetectorIDs();
83 // each spectrum should only point to one detector in the Muon file
84 loadedDetectors.emplace_back(*detIdSet.begin());
85 }
86 return loadedDetectors;
87}
88
96LoadMuonStrategy::createDetectorGroupingTable(const std::vector<detid_t> &detectorsLoaded,
97 const std::vector<detid_t> &grouping) const {
98 auto detectorGroupingTable = std::dynamic_pointer_cast<DataObjects::TableWorkspace>(
99 API::WorkspaceFactory::Instance().createTable("TableWorkspace"));
100 detectorGroupingTable->addColumn("vector_int", "Detectors");
101
102 std::map<detid_t, std::vector<detid_t>> groupingMap;
103 for (size_t i = 0; i < detectorsLoaded.size(); ++i) {
104 // Add detector ID to the list of group detectors. Detector ID is always
105 groupingMap[grouping[i]].emplace_back(detectorsLoaded[i]);
106 }
107
108 for (auto &group : groupingMap) {
109 if (group.first != 0) { // Skip 0 group
110 API::TableRow newRow = detectorGroupingTable->appendRow();
111 newRow << group.second;
112 }
113 }
114 return detectorGroupingTable;
115}
123 const std::vector<double> &deadTimes) const {
124 auto deadTimesTable = std::dynamic_pointer_cast<DataObjects::TableWorkspace>(
125 API::WorkspaceFactory::Instance().createTable("TableWorkspace"));
126
127 deadTimesTable->addColumn("int", "spectrum");
128 deadTimesTable->addColumn("double", "dead-time");
129
130 for (size_t i = 0; i < detectorsLoaded.size(); i++) {
131 API::TableRow row = deadTimesTable->appendRow();
132 row << detectorsLoaded[i] << deadTimes[i];
133 }
134
135 return deadTimesTable;
136}
137
138} // namespace Mantid::DataHandling
const Run & run() const
Run details object access.
Geometry::Instrument_const_sptr getInstrument() const
Returns the parameterized instrument.
GroupingLoader : Loads instrument grouping from IDF file.
std::shared_ptr< Grouping > getDummyGrouping()
Returns a "dummy" grouping of a single group with all the detectors in it.
std::shared_ptr< Grouping > getGroupingFromIDF() const
Load the grouping from the instrument's IDF.
const std::set< detid_t > & getDetectorIDs() const
Get a const reference to the detector IDs set.
Definition: ISpectrum.cpp:113
Kernel::Property * getLogData(const std::string &name) const
Access a single log entry.
Definition: LogManager.h:129
TableRow represents a row in a TableWorkspace.
Definition: TableRow.h:39
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.
LoadMuonStrategy(Kernel::Logger &g_log, std::string filename, LoadMuonNexusV2NexusHelper &nexusLoader)
DataObjects::TableWorkspace_sptr createDetectorGroupingTable(const std::vector< detid_t > &specToLoad, const std::vector< detid_t > &grouping) const
Creates Detector Grouping Table .
Concrete workspace implementation.
Definition: Workspace2D.h:29
std::size_t getNumberHistograms() const override
Returns the histogram number.
Histogram1D & getSpectrum(const size_t index) override
Return the underlying ISpectrum ptr at the given workspace index.
Definition: Workspace2D.h:62
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
virtual std::string value() const =0
Returns the value of the property as a string.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
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
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)