Mantid
Loading...
Searching...
No Matches
MDTransfNoQ.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 "MantidKernel/Unit.h"
10
11namespace Mantid::MDAlgorithms {
12
13// register the class, whith conversion factory under NoQ name
14DECLARE_MD_TRANSFID(MDTransfNoQ, CopyToMD)
15
16
27bool MDTransfNoQ::calcGenericVariables(std::vector<coord_t> &Coord, size_t nd) {
28 // sanity check. If fails, something went fundamentally wrong
29 if (m_NMatrixDim + m_AddDimCoordinates.size() != nd) {
30 std::string ERR = "Number of matrix dimensions: " + std::to_string(m_NMatrixDim) +
31 " plus number of additional dimensions: " + std::to_string(m_AddDimCoordinates.size()) +
32 " not equal to number of workspace dimensions: " + std::to_string(nd);
33 throw(std::invalid_argument(ERR));
34 }
35 // if one axis is numeric, 1 coordinate came from workspace
36 // if two axis are numeric, two values come from the ws. All other are defined
37 // by properties.
38 unsigned int ic(0);
39 for (unsigned int i = m_NMatrixDim; i < nd; i++) {
40 if (m_AddDimCoordinates[ic] < m_DimMin[i] || m_AddDimCoordinates[ic] >= m_DimMax[i])
41 return false;
42 Coord[i] = m_AddDimCoordinates[ic];
43 ic++;
44 }
45 return true;
46}
48
49 // get pointer to the positions of the detectors
50 std::vector<Kernel::V3D> const &DetDir = ConvParams.m_PreprDetTable->getColVector<Kernel::V3D>("DetDirections");
51 m_Det = &DetDir[0]; //
52
53 // get min and max values defined by the algorithm.
54 ConvParams.getMinMax(m_DimMin, m_DimMax);
55
57 m_AddDimCoordinates = ConvParams.getAddCoord();
58
59 API::NumericAxis *pXAx;
60 this->getAxes(ConvParams.getInWS(), pXAx, m_YAxis);
61}
69bool MDTransfNoQ::calcYDepCoordinates(std::vector<coord_t> &Coord, size_t i) {
70 if (m_YAxis) {
71 Coord[1] = static_cast<coord_t>(m_YAxis->operator()(i));
72 return !(Coord[1] < m_DimMin[1] || Coord[1] >= m_DimMax[1]);
73 }
74 return true;
75}
76bool MDTransfNoQ::calcMatrixCoord(const double &X, std::vector<coord_t> &Coord, double & /*s*/,
77 double & /*errSq*/) const {
78 if (X < m_DimMin[0] || X >= m_DimMax[0])
79 return false;
80
81 Coord[0] = static_cast<coord_t>(X);
82 return true;
83}
84
85std::vector<double> MDTransfNoQ::getExtremumPoints(const double xMin, const double xMax, size_t det_num) const {
86 UNUSED_ARG(det_num);
87
88 std::vector<double> rez(2);
89 rez[0] = xMin;
90 rez[1] = xMax;
91
92 return rez;
93}
94
101 UNUSED_ARG(mode);
102
103 API::NumericAxis *pXAx, *pYAx;
104 this->getAxes(inWS, pXAx, pYAx);
105
106 unsigned int nMatrDim = 1;
107 if (pYAx)
108 nMatrDim = 2;
109 return nMatrDim;
110}
111// internal helper function which extract one or two axis from input matrix
112// workspace;
114 API::NumericAxis *&pYAxis) {
115 // get the X axis of input workspace, it has to be there; if not axis throws
116 // invalid index
117 pXAxis = dynamic_cast<API::NumericAxis *>(inWS->getAxis(0));
118 if (!pXAxis) {
119 std::string ERR = "Can not retrieve X axis from the source workspace: " + inWS->getName();
120 throw(std::invalid_argument(ERR));
121 }
122 // get optional Y axis which can be used in NoQ-kind of algorithms
123 pYAxis = dynamic_cast<API::NumericAxis *>(inWS->getAxis(1));
124}
125
134 UNUSED_ARG(mode);
135
136 std::vector<std::string> rez;
137 API::NumericAxis *pXAxis, *pYAx;
138 this->getAxes(inWS, pXAxis, pYAx);
139
140 if (pYAx) {
141 rez.resize(2);
142 rez[1] = pYAx->unit()->unitID();
143 } else {
144 rez.resize(1);
145 }
146 rez[0] = pXAxis->unit()->unitID();
147
148 return rez;
149}
153 return this->outputUnitID(mode, inWS);
154}
158 UNUSED_ARG(mode);
159 API::NumericAxis *pXAxis;
160 // get the X axis of input workspace, it has to be there; if not axis throws
161 // invalid index
162 pXAxis = dynamic_cast<API::NumericAxis *>(inWS->getAxis(0));
163 if (!pXAxis) {
164 std::string ERR = "Can not retrieve X axis from the source workspace: " + inWS->getName();
165 throw(std::invalid_argument(ERR));
166 }
167 return pXAxis->unit()->unitID();
168}
169
170MDTransfNoQ::MDTransfNoQ() : m_NMatrixDim(0), m_YAxis(nullptr), m_Det(nullptr) {}
171
178 Mantid::API::MatrixWorkspace_sptr underlyingWorkspace) const {
180 auto isQ = false;
181 setter(mdWorkspace, underlyingWorkspace, isQ);
182}
183
184} // namespace Mantid::MDAlgorithms
#define DECLARE_MD_TRANSFID(classname, regID)
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
const std::shared_ptr< Kernel::Unit > & unit() const
The unit for this axis.
Definition: Axis.cpp:28
Class to represent a numeric axis of a workspace.
Definition: NumericAxis.h:29
Class for 3D vectors.
Definition: V3D.h:34
DisplayNormalizationSetter: Sets the displaynormalization on a workspace based on several parameters ...
Class responsible for conversion of input workspace data into proper number of output dimensions in N...
Definition: MDTransfNoQ.h:28
std::vector< double > m_DimMin
Definition: MDTransfNoQ.h:80
std::vector< std::string > outputUnitID(Kernel::DeltaEMode::Type mode, API::MatrixWorkspace_const_sptr inWS) const override
function returns units ID-s which this transformation prodiuces its ouptut.
void initialize(const MDWSDescription &ConvParams) override
set up transformation from the class, which can provide all variables necessary for the conversion
Definition: MDTransfNoQ.cpp:47
static void getAxes(const API::MatrixWorkspace_const_sptr &inWS, API::NumericAxis *&pXAxis, API::NumericAxis *&pYAxis)
bool calcYDepCoordinates(std::vector< coord_t > &Coord, size_t i) override
Method updates the value of preprocessed detector coordinates in Q-space, used by other functions.
Definition: MDTransfNoQ.cpp:69
void setDisplayNormalization(Mantid::API::IMDWorkspace_sptr mdWorkspace, Mantid::API::MatrixWorkspace_sptr underlyingWorkspace) const override
Set the display normalization for no Q.
unsigned int getNMatrixDimensions(Kernel::DeltaEMode::Type mode, API::MatrixWorkspace_const_sptr inWS) const override
return the number of dimensions, calculated by the transformation from the workspace.
Definition: MDTransfNoQ.cpp:99
std::vector< double > m_DimMax
Definition: MDTransfNoQ.h:80
const std::string inputUnitID(Kernel::DeltaEMode::Type mode, API::MatrixWorkspace_const_sptr inWS) const override
returns the units, the input ws is actually in as they coinside with input units for this class
std::vector< std::string > getDefaultDimID(Kernel::DeltaEMode::Type mode, API::MatrixWorkspace_const_sptr inWS) const override
the default dimID-s in noQ mode equal to input WS dim-id-s
std::vector< double > getExtremumPoints(const double xMin, const double xMax, size_t det_num) const override
This transformation dos nothing with the workspace ranges, so extremum points for this transformation...
Definition: MDTransfNoQ.cpp:85
std::vector< coord_t > m_AddDimCoordinates
the vector of the additional coordinates which define additional MD dimensions.
Definition: MDTransfNoQ.h:85
bool calcMatrixCoord(const double &X, std::vector< coord_t > &Coord, double &s, double &err) const override
The method to calculate all remaining coordinates, defined within the inner loop given that the input...
Definition: MDTransfNoQ.cpp:76
helper class describes the properties of target MD workspace, which should be obtained as the result ...
API::MatrixWorkspace_const_sptr getInWS() const
std::vector< coord_t > getAddCoord() const
void getMinMax(std::vector< double > &min, std::vector< double > &max) const
get vector of minimal and maximal values from the class
DataObjects::TableWorkspace_const_sptr m_PreprDetTable
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
Definition: IMDWorkspace.h:146
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition: MDTypes.h:27
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)
Type
Define the available energy transfer modes It is important to assign enums proper numbers,...
Definition: DeltaEMode.h:29
@ Undefined
this mode should not be displayed among modes availible to select but may have string representation
Definition: DeltaEMode.h:33