|
| 1 | +// Mantid Repository : https://github.com/mantidproject/mantid |
| 2 | +// |
| 3 | +// Copyright © 2025 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 + |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include <cxxtest/TestSuite.h> |
| 10 | + |
| 11 | +#include "MantidAPI/AnalysisDataService.h" |
| 12 | +#include "MantidAPI/NexusFileLoader.h" |
| 13 | +#include "MantidAPI/WorkspaceGroup.h" |
| 14 | +#include "MantidDataObjects/Workspace2D.h" |
| 15 | +#include "MantidMuon/LoadMuonNexus1.h" |
| 16 | +#include "MantidMuon/LoadMuonNexus2.h" |
| 17 | +#include "MantidMuon/LoadMuonNexus3.h" |
| 18 | + |
| 19 | +using namespace Mantid::API; |
| 20 | +using namespace Mantid::Kernel; |
| 21 | +using namespace Mantid::Algorithms; |
| 22 | +using namespace Mantid::DataObjects; |
| 23 | + |
| 24 | +namespace { |
| 25 | +// Mock class for LoadMuonNexusV2 which is in the DataHandling Library |
| 26 | +class LoadMuonNexusV2 : public NexusFileLoader { |
| 27 | + const std::string name() const override { return "LoadMuonNexusV2"; } |
| 28 | + int version() const override { return 1; } |
| 29 | + int confidence(NexusHDF5Descriptor &) const override { return 100; } |
| 30 | + void execLoader() override {} |
| 31 | + const std::string summary() const override { return "mock class"; } |
| 32 | + void init() override {} |
| 33 | +}; |
| 34 | +} // namespace |
| 35 | + |
| 36 | +class LoadMuonNexus3Test : public CxxTest::TestSuite { |
| 37 | +public: |
| 38 | + void check_spectra_and_detectors(const MatrixWorkspace_sptr &output) { |
| 39 | + |
| 40 | + //---------------------------------------------------------------------- |
| 41 | + // Tests to check that spectra-detector mapping is done correctly |
| 42 | + //---------------------------------------------------------------------- |
| 43 | + // Check the total number of elements in the map for HET |
| 44 | + TS_ASSERT_EQUALS(output->getNumberHistograms(), 192); |
| 45 | + |
| 46 | + // Test one to one mapping, for example spectra 6 has only 1 pixel |
| 47 | + TS_ASSERT_EQUALS(output->getSpectrum(6).getDetectorIDs().size(), 1); |
| 48 | + |
| 49 | + auto detectorgroup = output->getSpectrum(99).getDetectorIDs(); |
| 50 | + TS_ASSERT_EQUALS(detectorgroup.size(), 1); |
| 51 | + TS_ASSERT_EQUALS(*detectorgroup.begin(), 100); |
| 52 | + } |
| 53 | + |
| 54 | + void testExecLoadMuonNexus2() { |
| 55 | + LoadMuonNexus3 nxLoad; |
| 56 | + nxLoad.initialize(); |
| 57 | + |
| 58 | + // Now set required filename and output workspace name |
| 59 | + std::string inputFile = "argus0026287.nxs"; |
| 60 | + nxLoad.setPropertyValue("FileName", inputFile); |
| 61 | + |
| 62 | + std::string outputSpace = "outer"; |
| 63 | + nxLoad.setPropertyValue("OutputWorkspace", outputSpace); |
| 64 | + |
| 65 | + // Test execute to read file and populate workspace |
| 66 | + TS_ASSERT_THROWS_NOTHING(nxLoad.execute()); |
| 67 | + TS_ASSERT(nxLoad.isExecuted()); |
| 68 | + |
| 69 | + // Check output workspace |
| 70 | + MatrixWorkspace_sptr output; |
| 71 | + output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace); |
| 72 | + Workspace2D_sptr output2D = std::dynamic_pointer_cast<Workspace2D>(output); |
| 73 | + |
| 74 | + // Perform limited tests on the outwork workspace as this is essentially just a wrapper algorithm. |
| 75 | + // subset of tests performed in LoadMuonNexus2Test |
| 76 | + check_spectra_and_detectors(output); |
| 77 | + |
| 78 | + TS_ASSERT(nxLoad.getSelectedAlg() == "LoadMuonNexus"); |
| 79 | + TS_ASSERT(nxLoad.getSelectedVersion() == 2); |
| 80 | + } |
| 81 | + |
| 82 | + void testExecLoadMuonNexus1() { |
| 83 | + LoadMuonNexus3 nxLoad; |
| 84 | + nxLoad.initialize(); |
| 85 | + |
| 86 | + // Now set required filename and output workspace name |
| 87 | + std::string inputFile = "emu00006475.nxs"; |
| 88 | + nxLoad.setPropertyValue("FileName", inputFile); |
| 89 | + |
| 90 | + std::string outputSpace = "outer"; |
| 91 | + nxLoad.setPropertyValue("OutputWorkspace", outputSpace); |
| 92 | + |
| 93 | + // Test execute to read file and populate workspace |
| 94 | + TS_ASSERT_THROWS_NOTHING(nxLoad.execute()); |
| 95 | + TS_ASSERT(nxLoad.isExecuted()); |
| 96 | + |
| 97 | + // Check output workspace group |
| 98 | + Mantid::API::WorkspaceGroup_sptr output = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(outputSpace); |
| 99 | + TS_ASSERT(output->size() == 4); |
| 100 | + |
| 101 | + TS_ASSERT(nxLoad.getSelectedAlg() == "LoadMuonNexus"); |
| 102 | + TS_ASSERT(nxLoad.getSelectedVersion() == 1); |
| 103 | + } |
| 104 | + |
| 105 | + void testExecLoadMuonNexusV2() { |
| 106 | + LoadMuonNexus3 nxLoad; |
| 107 | + nxLoad.initialize(); |
| 108 | + |
| 109 | + // Now set required filename and output workspace name |
| 110 | + std::string inputFile = "ARGUS00073601.nxs"; |
| 111 | + nxLoad.setPropertyValue("FileName", inputFile); |
| 112 | + |
| 113 | + std::string outputSpace = "outer"; |
| 114 | + nxLoad.setPropertyValue("OutputWorkspace", outputSpace); |
| 115 | + |
| 116 | + // Test execute to read file and populate workspace |
| 117 | + TS_ASSERT_THROWS_NOTHING(nxLoad.execute()); |
| 118 | + TS_ASSERT(nxLoad.isExecuted()); |
| 119 | + |
| 120 | + TS_ASSERT(nxLoad.getSelectedAlg() == "LoadMuonNexusV2"); |
| 121 | + TS_ASSERT(nxLoad.getSelectedVersion() == 1); |
| 122 | + } |
| 123 | +}; |
0 commit comments