Mantid
Loading...
Searching...
No Matches
ShowPeakHKLOffsets.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 "MantidAPI/Sample.h"
13
15
25/*
26 * ShowPeakHKLOffsets.cpp *
27 * Created on: May 13, 2013
28 * Author: ruth
29 */
30namespace Mantid::Crystal {
31
32DECLARE_ALGORITHM(ShowPeakHKLOffsets)
33
34void ShowPeakHKLOffsets::init() {
35 declareProperty(std::make_unique<WorkspaceProperty<PeaksWorkspace>>("PeaksWorkspace", "", Direction::Input),
36 "Workspace of Peaks with UB loaded");
37
38 declareProperty(
39 std::make_unique<WorkspaceProperty<ITableWorkspace>>("HKLIntegerOffsets", "HKLIntegerOffsets", Direction::Output),
40 "Workspace with the Results");
41}
42
44 PeaksWorkspace_sptr Peaks = getProperty(std::string("PeaksWorkspace"));
45
46 if (!Peaks) {
47 g_log.error(" Invalid peaks workspace ");
48 throw std::invalid_argument(" Invalid peaks workspace ");
49 }
50
51 if (Peaks->getNumberPeaks() < 1) {
52 g_log.error("The peaks workspace has NO peaks");
53 throw std::invalid_argument("The peaks workspace has NO peaks");
54 }
55
56 if (!Peaks->sample().hasOrientedLattice()) {
57 g_log.error("The peaks workspace does not have an oriented lattice");
58 throw std::invalid_argument("The peaks workspace does not have an oriented lattice");
59 }
60
61 Kernel::Matrix<double> UBinv = Peaks->mutableSample().getOrientedLattice().getUB();
62 UBinv.Invert();
63 UBinv /= 2 * M_PI;
64
65 std::shared_ptr<ITableWorkspace> Res = WorkspaceFactory::Instance().createTable("TableWorkspace");
66 Res->setTitle("HKL int offsets for " + Peaks->getName());
67
68 Res->addColumn("double", "H offset from int");
69 Res->addColumn("double", "K offset from int");
70 Res->addColumn("double", "L offset from int");
71 Res->addColumn("double", "Max offset from int");
72
73 Res->addColumn("int", "bank");
74 Res->addColumn("int", "RunNumber");
75
76 for (int i = 0; i < Peaks->getNumberPeaks(); i++) {
77 Res->appendRow();
78 Peak peak = Peaks->getPeak(i);
79 V3D hkl = UBinv * peak.getQSampleFrame();
80 double maxOffset = 0;
81 for (int j = 0; j < 3; j++) {
82 double offset = hkl[j] - floor(hkl[j]);
83 if (offset > .5)
84 offset -= 1;
85 Res->Double(i, j) = offset;
86 if (fabs(offset) > fabs(maxOffset))
87 maxOffset = offset;
88 }
89 Res->Double(i, 3) = maxOffset;
90 Res->Int(i, 5) = peak.getRunNumber();
91 std::string bankName = peak.getBankName();
92 size_t k = bankName.find_last_not_of("0123456789");
93 int bank = 0;
94 if (k < bankName.length())
95 bank = boost::lexical_cast<int>(bankName.substr(k + 1));
96 Res->Int(i, 4) = bank;
97 }
98
99 setProperty("HKLIntegerOffsets", Res);
100}
101
102} // namespace Mantid::Crystal
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
#define fabs(x)
Definition: Matrix.cpp:22
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Kernel::Logger & g_log
Definition: Algorithm.h:451
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
A property class for workspaces.
void exec() override
Virtual method - must be overridden by concrete algorithm.
int getRunNumber() const override
Return the run number this peak was measured at.
Definition: BasePeak.cpp:78
Structure describing a single-crystal peak.
Definition: Peak.h:34
std::string getBankName() const
Find the name of the bank that is the parent of the detector.
Definition: Peak.cpp:353
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition: Peak.cpp:472
The class PeaksWorkspace stores information about a set of SCD peaks.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
Numerical Matrix class.
Definition: Matrix.h:42
T Invert()
LU inversion routine.
Definition: Matrix.cpp:924
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Class for 3D vectors.
Definition: V3D.h:34
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54