LoadMuonNexusV2Test.h 2.96 KB
Newer Older
1
2
3
4
5
6
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
Stephen's avatar
Stephen committed
7
#pragma once
8
9

#include "MantidAPI/AnalysisDataService.h"
Stephen's avatar
Stephen committed
10
#include "MantidAPI/Axis.h"
11
12
13
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/WorkspaceGroup.h"
Stephen's avatar
Stephen committed
14
#include "MantidDataHandling/LoadMuonNexusV2.h"
15
#include "MantidDataObjects/Workspace2D.h"
Stephen's avatar
Stephen committed
16
17
18
19
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/UnitLabelTypes.h"

#include <cxxtest/TestSuite.h>
20
21
22
23
24
25
26
27

#include <cmath>

using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataHandling;
using namespace Mantid::DataObjects;

Stephen's avatar
Stephen committed
28
class LoadMuonNexusV2Test : public CxxTest::TestSuite {
29
30
31
32
private:
  // helper methods
public:
  void testExec() {
Stephen's avatar
Stephen committed
33
    LoadMuonNexusV2 ld;
34
    ld.initialize();
Stephen's avatar
Stephen committed
35
    ld.setPropertyValue("Filename", "EMU00103638.nxs_v2");
36
    ld.setPropertyValue("OutputWorkspace", "outWS");
Stephen's avatar
Stephen committed
37
38
    ld.setPropertyValue("DeadTimeTable", "DeadTimeTable");
    ld.setPropertyValue("DetectorGroupingTable", "DetectorGroupingTable");
39
40
41
42
43
44
45
46
47

    TS_ASSERT_THROWS_NOTHING(ld.execute());
    TS_ASSERT(ld.isExecuted());
    // Verify that the output workspace exists
    MatrixWorkspace_sptr output_ws;
    TS_ASSERT_THROWS_NOTHING(
        output_ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
            "outWS"));

Stephen's avatar
Stephen committed
48
49

    Workspace2D_sptr output2D =
Stephen's avatar
Stephen committed
50
        std::dynamic_pointer_cast<Workspace2D>(output_ws);
51

Stephen's avatar
Stephen committed
52
53
    const Mantid::API::Run &run = output2D->run();
    int goodfrm = run.getPropertyAsIntegerValue("goodfrm");
Stephen's avatar
Stephen committed
54
55
56
57
58
    TS_ASSERT_EQUALS(goodfrm, 36197);
    double firstGoodData = ld.getProperty("FirstGoodData");
    TS_ASSERT_EQUALS(firstGoodData, 0.384);
    double timeZero = ld.getProperty("TimeZero");
    TS_ASSERT_DELTA(timeZero, 0.1599999, 1e-5);
Stephen's avatar
Stephen committed
59
60
61
62
63
64
65
66
67
68

    // Check the unit has been set correctly
    TS_ASSERT_EQUALS(output2D->getAxis(0)->unit()->unitID(), "Label");
    TS_ASSERT(!output2D->isDistribution());

    // Check that sample temp and field set
    double temperature = run.getPropertyAsSingleValue("sample_temp");
    TS_ASSERT_EQUALS(100.0, temperature);
    double field = run.getPropertyAsSingleValue("sample_magn_field");
    TS_ASSERT_EQUALS(0.0, field);
69
  }
Stephen's avatar
Stephen committed
70
71

  void testExecWithGroupingTable() {}
72
73
74
75
76
77
};

//------------------------------------------------------------------------------
// Performance test
//------------------------------------------------------------------------------

Stephen's avatar
Stephen committed
78
class LoadMuonNexusV2TestPerformance : public CxxTest::TestSuite {
79
80
81
public:
  void setUp() override {
    loader.initialize();
Stephen's avatar
Stephen committed
82
    loader.setPropertyValue("Filename", "EMU00103638.nxs_v2");
83
84
85
86
87
88
89
90
    loader.setPropertyValue("OutputWorkspace", "ws");
  }

  void tearDown() override { AnalysisDataService::Instance().remove("ws"); }

  void testDefaultLoad() { loader.execute(); }

private:
Stephen's avatar
Stephen committed
91
  LoadMuonNexusV2 loader;
92
};