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;