22using namespace Kernel;
23using namespace DataObjects;
25using namespace Kernel::VectorHelper;
31 "Name of the input workspace. If you use the default vanadium peak "
32 "positions are used, the workspace must be in units of d-spacing.");
34 "The name of the workspace to be created as the output of the "
36 "If the input workspace is an EventWorkspace, then the output must be "
37 "different (and will be made into a Workspace2D).");
39 auto min = std::make_shared<BoundedValidator<double>>();
43 "The estimated peak width as a "
44 "percentage of the d-spacing "
45 "of the center of the peak.");
48 "Optional: enter a comma-separated list of the expected X-position of "
49 "the centre of the peaks. \n"
50 "Only peaks near these positions will be fitted.\n"
51 "If not entered, the default vanadium peak positions will be used.");
53 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
54 mustBePositive->setLower(0);
56 "If set, peaks will only be removed from this spectrum "
57 "(otherwise from all)");
67 if (inputEvent && (inputWS == outputWS)) {
68 throw std::invalid_argument(
"Cannot strip vanadium peaks in-place for an EventWorkspace. Please "
69 "specify a different output workspace name, which will be a "
70 "Workspace2D copy of the input EventWorkspace.");
75 bool singleSpectrum = !
isEmpty(singleIndex);
76 if (singleSpectrum && singleIndex >=
static_cast<int>(inputWS->getNumberHistograms())) {
77 g_log.
error() <<
"The value of WorkspaceIndex provided (" << singleIndex
78 <<
") is larger than the size of this workspace (" << inputWS->getNumberHistograms() <<
")\n";
80 "StripVanadiumPeaks WorkspaceIndex property");
86 const auto nhists =
static_cast<int>(inputWS->getNumberHistograms());
89 for (
int k = 0; k < nhists; ++k) {
90 outputWS->setHistogram(k, inputWS->histogram(k));
96 if (peakPositions.length() == 0) {
98 peakPositions =
"0.5044,0.5191,0.5350,0.5526,0.5936,0.6178,0.6453,0.6768,0."
99 "7134,0.7566,0.8089,0.8737,0.9571,1.0701,1.2356,1.5133,2."
102 if (inputWS->getAxis(0)->unit()->unitID() !=
"dSpacing")
103 throw std::invalid_argument(
"Cannot strip using default Vanadium peak positions for an input "
104 "workspace whose units are not d-spacing. Convert to d-spacing or "
105 "specify your own alternative peak positions.");
110 double widthPercent =
getProperty(
"PeakWidthPercent");
112 for (
int k = 0; k < nhists; ++k) {
113 if ((!singleSpectrum) || (singleIndex == k)) {
115 const auto &
X = outputWS->x(k);
118 auto midX = outputWS->points(k);
121 auto &outY = outputWS->mutableY(k);
124 std::vector<double>::iterator it;
125 for (it = centers.begin(); it != centers.end(); ++it) {
128 double width = center * widthPercent / 100.0;
133 int L1 =
getBinIndex(
X.rawData(), center - width * 0.75);
134 int L2 =
getBinIndex(
X.rawData(), center - width * 0.25);
135 double leftX = (midX[L1] + midX[L2]) / 2;
138 for (
int i = L1; i <= L2; i++) {
142 double leftY = totY / (L2 - L1 + 1);
144 int R1 =
getBinIndex(
X.rawData(), center + width * 0.25);
145 int R2 =
getBinIndex(
X.rawData(), center + width * 0.75);
146 double rightX = (midX[R1] + midX[R2]) / 2;
149 for (
int i = R1; i <= R2; i++) {
153 double rightY = totY / (R2 - R1 + 1);
157 if (
fabs(rightX - leftX) > 0.0)
158 slope = (rightY - leftY) / (rightX - leftX);
159 double abscissa = leftY - slope * leftX;
162 for (
int i = L2; i <= R1; i++) {
163 outY[i] = midX[i] * slope + abscissa;
#define DECLARE_ALGORITHM(classname)
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Execution code.
void init() override
Initialisation code.
StripVanadiumPeaks()
(Empty) Constructor
Exception for index errors.
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.
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
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
template DLLExport std::vector< double > splitStringIntoVector< double >(std::string listString)
MANTID_KERNEL_DLL int getBinIndex(const std::vector< double > &bins, const double value)
Return the index into a vector of bin boundaries for a particular X value.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
@ Input
An input workspace.
@ Output
An output workspace.