Mantid
Loading...
Searching...
No Matches
PeakClusterProjection.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
15
16using namespace Mantid::Kernel;
17using namespace Mantid::API;
18using namespace Mantid::Geometry;
19
20namespace {
27PeakTransform_sptr makePeakTransform(IMDWorkspace const *const mdWS) {
28 const SpecialCoordinateSystem mdCoordinates = mdWS->getSpecialCoordinateSystem();
29 PeakTransformFactory_sptr peakTransformFactory;
30 if (mdCoordinates == QLab) {
31 peakTransformFactory = std::make_shared<PeakTransformQLabFactory>();
32 } else if (mdCoordinates == QSample) {
33 peakTransformFactory = std::make_shared<PeakTransformQSampleFactory>();
34 } else if (mdCoordinates == Mantid::Kernel::HKL) {
35 peakTransformFactory = std::make_shared<PeakTransformHKLFactory>();
36 }
37 if (!peakTransformFactory) {
38 throw std::runtime_error("Failed to get a valid PeakTransformFactory");
39 }
40 const std::string xDim = mdWS->getDimension(0)->getName();
41 const std::string yDim = mdWS->getDimension(1)->getName();
42 PeakTransform_sptr peakTransform = peakTransformFactory->createTransform(xDim, yDim);
43 return peakTransform;
44}
45
50void validate(IMDWorkspace const *const mdWS) {
51 auto coordinateSystem = mdWS->getSpecialCoordinateSystem();
52 if (coordinateSystem == None) {
53 throw std::invalid_argument("Input image IMDHistoWorkspace must have a "
54 "known special coordinate system.");
55 }
56
57 if (mdWS->getNumDims() < 3) {
58 throw std::invalid_argument("Need to have 3 or more dimension in the workspace.");
59 }
60}
61} // namespace
62
63namespace Mantid::Crystal {
64
70PeakClusterProjection::PeakClusterProjection(std::shared_ptr<Mantid::API::IMDWorkspace> &mdWS) : m_mdWS(mdWS) {
71 validate(mdWS.get());
72
73 // Make a peak transform so that we can understand a peak in the context of
74 // the mdworkspace coordinate setup.
75 m_peakTransform = makePeakTransform(mdWS.get());
76}
77
83PeakClusterProjection::PeakClusterProjection(std::shared_ptr<Mantid::API::IMDHistoWorkspace> &mdWS)
84 : m_mdWS(std::static_pointer_cast<IMDWorkspace>(mdWS)) {
85 validate(mdWS.get());
86
87 // Make a peak transform so that we can understand a peak in the context of
88 // the mdworkspace coordinate setup.
89 m_peakTransform = makePeakTransform(mdWS.get());
90}
91
97PeakClusterProjection::PeakClusterProjection(std::shared_ptr<Mantid::API::IMDEventWorkspace> &mdWS)
98 : m_mdWS(std::static_pointer_cast<IMDWorkspace>(mdWS)) {
99 validate(mdWS.get());
100
101 // Make a peak transform so that we can understand a peak in the context of
102 // the mdworkspace coordinate setup.
103 m_peakTransform = makePeakTransform(mdWS.get());
104}
105
110 return m_peakTransform->transformPeak(peak);
111}
112
121 const Mantid::Kernel::V3D &center = m_peakTransform->transformPeak(peak);
122 return m_mdWS->getSignalAtVMD(center, normalization);
123}
124
125} // namespace Mantid::Crystal
Basic MD Workspace Abstract Class.
Definition: IMDWorkspace.h:40
virtual Kernel::SpecialCoordinateSystem getSpecialCoordinateSystem() const =0
virtual std::shared_ptr< const Mantid::Geometry::IMDDimension > getDimension(size_t index) const
Get a dimension.
Definition: MDGeometry.cpp:161
virtual size_t getNumDims() const
Definition: MDGeometry.cpp:148
Mantid::signal_t signalAtPeakCenter(const Mantid::Geometry::IPeak &peak, Mantid::API::MDNormalization normalization=Mantid::API::NoNormalization) const
Get the signal value at the peak center.
PeakClusterProjection(std::shared_ptr< Mantid::API::IMDWorkspace > &mdWS)
Constructor.
std::shared_ptr< Mantid::API::IMDWorkspace > m_mdWS
Image.
std::shared_ptr< Mantid::Geometry::PeakTransform > m_peakTransform
Peak Transform.
Mantid::Kernel::V3D peakCenter(const Mantid::Geometry::IPeak &peak) const
Get the peak center.
Structure describing a single-crystal peak.
Definition: IPeak.h:26
QLab : Q in the lab frame MDFrame.
Definition: QLab.h:21
QSample : Q in the sample frame.
Definition: QSample.h:21
Class for 3D vectors.
Definition: V3D.h:34
MDNormalization
Enum describing different ways to normalize the signal in a MDWorkspace.
Definition: IMDIterator.h:25
std::shared_ptr< PeakTransformFactory > PeakTransformFactory_sptr
Factory Shared Pointer typedef.
std::shared_ptr< PeakTransform > PeakTransform_sptr
Typedef for a PeakTransform wrapped in a shared_pointer.
Definition: PeakTransform.h:59
SpecialCoordinateSystem
Special coordinate systems for Q3D.
double signal_t
Typedef for the signal recorded in a MDBox, etc.
Definition: MDTypes.h:36
STL namespace.