Mantid
Loading...
Searching...
No Matches
StripVanadiumPeaks2.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
10#include "MantidAPI/Axis.h"
15#include "MantidKernel/Unit.h"
16
17using namespace Mantid::Kernel;
18using namespace Mantid::API;
19
20namespace Mantid::Algorithms {
21
22namespace { // anonymous namespace
23std::vector<double> POSITIONS_IN_D{0.41192, 0.4279, 0.49076, 0.5044, 0.5191, 0.5350, 0.5526, 0.5936, 0.6178, 0.6453,
24 0.6768, 0.7134, 0.7566, 0.8089, 0.8737, 0.9571, 1.0701, 1.2356, 1.5133, 2.1401};
25}
26
27DECLARE_ALGORITHM(StripVanadiumPeaks2)
28
29void StripVanadiumPeaks2::init() {
30 // Declare inputs and output. Copy most from StripPeaks
31 auto algStripPeaks = AlgorithmManager::Instance().createUnmanaged("StripPeaks");
32 algStripPeaks->initialize();
33
34 auto dSpaceValidator = std::make_shared<WorkspaceUnitValidator>("dSpacing");
35 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input, dSpaceValidator),
36 "Name of the input workspace. If you use the default vanadium peak "
37 "positions are used, the workspace must be in units of d-spacing.");
38
39 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
40 "The name of the workspace to be created as the output of the "
41 "algorithm.\n"
42 "If the input workspace is an EventWorkspace, then the output must be "
43 "different (and will be made into a Workspace2D).");
44
45 copyProperty(algStripPeaks, "FWHM");
46 copyProperty(algStripPeaks, "Tolerance");
47 // peak positions are hard-coded
48 copyProperty(algStripPeaks, "BackgroundType");
49 copyProperty(algStripPeaks, "HighBackground");
50 copyProperty(algStripPeaks, "PeakPositionTolerance");
51 copyProperty(algStripPeaks, "WorkspaceIndex");
52}
53
55 // get the input workspace
56 API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
57
58 // setup StripPeaks with hard-coded positions
59 constexpr double progressStart{0.0};
60 constexpr double progressStop{1.0};
61 const bool enableLogging{true};
62 auto stripPeaks = createChildAlgorithm("StripPeaks", progressStart, progressStop, enableLogging);
63 stripPeaks->setProperty("InputWorkspace", inputWS);
64 stripPeaks->setPropertyValue("OutputWorkspace", getProperty("OutputWorkspace")); // allows for in-place operation
65 stripPeaks->setProperty<int>("FWHM", getProperty("FWHM"));
66 stripPeaks->setProperty<int>("Tolerance", getProperty("Tolerance"));
67 stripPeaks->setProperty("PeakPositions", POSITIONS_IN_D);
68 stripPeaks->setProperty<std::string>("BackgroundType", getProperty("BackgroundType"));
69 stripPeaks->setProperty<bool>("HighBackground", getProperty("HighBackground"));
70 if (!isDefault("WorkspaceIndex")) {
71 stripPeaks->setProperty<int>("WorkspaceIndex", getProperty("WorkspaceIndex"));
72 }
73 stripPeaks->setProperty<double>("PeakPositionTolerance", getProperty("PeakPositionTolerance"));
74
75 // Call StripPeaks
76 stripPeaks->executeAsChildAlg();
77
78 // Get and set output workspace
79 API::MatrixWorkspace_sptr outputWS = stripPeaks->getProperty("OutputWorkspace");
80 this->setProperty("OutputWorkspace", outputWS);
81}
82
83} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1) override
Create a Child Algorithm.
Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override
Get the property held by this object.
A property class for workspaces.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54