Mantid
Loading...
Searching...
No Matches
MDTransfAxisNames.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 "MantidMDAlgorithms/DllConfig.h"
9#include <boost/format.hpp>
10
11namespace Mantid::MDAlgorithms {
12using namespace Mantid::Kernel;
13
14MDTransfAxisNames::MDTransfAxisNames() : m_DefaultDimID(CnvrtToMD::nDefaultID) {
15 // this defines default dimension ID-s which are used to indentify dimensions
16 // when using the target MD workspace later
17 // for ModQ transformation:
19 // for Q3D transformation
24}
25
26//
27std::vector<std::string> MDTransfAxisNames::getDefaultDimIDQ3D(DeltaEMode::Type dEMode) const {
28 std::vector<std::string> rez;
29 if (dEMode == DeltaEMode::Elastic) {
30 rez.resize(3);
31 } else {
32
33 if (dEMode == DeltaEMode::Direct || dEMode == DeltaEMode::Indirect) {
34 rez.resize(4);
36 } else {
37 throw(std::invalid_argument("Unknown dE mode provided"));
38 }
39 }
43 return rez;
44}
45
46std::vector<std::string> MDTransfAxisNames::getDefaultDimIDModQ(DeltaEMode::Type dEMode) const {
47 std::vector<std::string> rez;
48
49 if (dEMode == DeltaEMode::Elastic) {
50 rez.resize(1);
51 } else {
52 if (dEMode == DeltaEMode::Direct || dEMode == DeltaEMode::Indirect) {
53 rez.resize(2);
55 } else {
56 throw(std::invalid_argument("Unknown dE mode provided"));
57 }
58 }
60 return rez;
61}
62
63std::string makeAxisName(const Kernel::V3D &Dir, const std::vector<std::string> &QNames) {
64 double eps(1.e-3);
65 Kernel::V3D absDir(fabs(Dir.X()), fabs(Dir.Y()), fabs(Dir.Z()));
66 std::string mainName;
67
68 if ((absDir[0] >= absDir[1]) && (absDir[0] >= absDir[2])) {
69 mainName = QNames[0];
70 } else if (absDir[1] >= absDir[2]) {
71 mainName = QNames[1];
72 } else {
73 mainName = QNames[2];
74 }
75
76 std::string name("["), separator = ",";
77 for (size_t i = 0; i < 3; i++) {
78
79 if (i == 2)
80 separator = "]";
81 if (absDir[i] < eps) {
82 name += "0" + separator;
83 continue;
84 }
85 if (Dir[i] < 0) {
86 name += "-";
87 }
88 if (std::fabs(absDir[i] - 1) < eps) {
89 name.append(mainName).append(separator);
90 continue;
91 }
92 name.append(sprintfd(absDir[i], eps)).append(mainName).append(separator);
93 }
94
95 return name;
96}
97std::string MANTID_MDALGORITHMS_DLL sprintfd(const double data, const double eps) {
98 // truncate to eps decimal points
99 double dist = std::round(data / eps) * eps;
100 return boost::str(boost::format("%d") % dist);
101}
102
103} // namespace Mantid::MDAlgorithms
std::string name
Definition Run.cpp:60
#define fabs(x)
Definition Matrix.cpp:22
Class for 3D vectors.
Definition V3D.h:35
constexpr double X() const noexcept
Get x.
Definition V3D.h:239
constexpr double Y() const noexcept
Get y.
Definition V3D.h:240
constexpr double Z() const noexcept
Get z.
Definition V3D.h:241
std::vector< std::string > getDefaultDimIDModQ(Kernel::DeltaEMode::Type dEMode) const
std::vector< std::string > getDefaultDimIDQ3D(Kernel::DeltaEMode::Type dEMode) const
function returns default dimension id-s for different Q and dE modes, defined by this class
std::vector< std::string > m_DefaultDimID
the vector describes default dimension names, specified along the axis if no names are explicitly req...
std::string MANTID_MDALGORITHMS_DLL sprintfd(const double data, const double eps)
creates string representation of the number with accuracy, cpecified by eps
std::string MANTID_MDALGORITHMS_DLL makeAxisName(const Kernel::V3D &Dir, const std::vector< std::string > &QNames)
function to build mslice-like axis name from the vector, which describes crystallographic direction a...
Type
Define the available energy transfer modes It is important to assign enums proper numbers,...
Definition DeltaEMode.h:29