Mantid
Loading...
Searching...
No Matches
WorkspaceCreationHelper.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 +
7/*********************************************************************************
8 * PLEASE READ THIS!!!!!!!
9 *
10 * This collection of functions MAY NOT be used in any test from a package
11 *below
12 * DataObjects (e.g. Kernel, Geometry, API).
13 * Conversely, this file MAY NOT be modified to use anything from a package
14 *higher
15 * than DataObjects (e.g. any algorithm), even if going via the factory.
16 *********************************************************************************/
20
24#include "MantidAPI/Sample.h"
42#include "MantidHistogramData/HistogramBuilder.h"
43#include "MantidHistogramData/HistogramDx.h"
44#include "MantidHistogramData/LinearGenerator.h"
45#include "MantidIndexing/IndexInfo.h"
50#include "MantidKernel/V3D.h"
53
54#include <cmath>
55#include <sstream>
56#include <utility>
57
59using namespace Mantid;
60using namespace Mantid::DataObjects;
61using namespace Mantid::Kernel;
62using namespace Mantid::API;
63using namespace Mantid::Geometry;
64using namespace Mantid::HistogramData;
67using Mantid::Types::Core::DateAndTime;
68using Mantid::Types::Event::TofEvent;
69
71 const auto &baseComponentInfo = expInfo.baseComponentInfo();
72 return baseComponentInfo.componentID(baseComponentInfo.root());
73}
74
75StubAlgorithm::StubAlgorithm(size_t nSteps) : m_Progress(std::make_unique<API::Progress>(this, 0.0, 1.0, nSteps)) {}
76
77EPPTableRow::EPPTableRow(const double peakCentre_, const double sigma_, const double height_,
78 const FitStatus fitStatus_)
79 : peakCentre(peakCentre_), sigma(sigma_), height(height_), fitStatus(fitStatus_) {}
80
81EPPTableRow::EPPTableRow(const int index, const double peakCentre_, const double sigma_, const double height_,
82 const FitStatus fitStatus_)
83 : workspaceIndex(index), peakCentre(peakCentre_), sigma(sigma_), height(height_), fitStatus(fitStatus_) {}
84
89void removeWS(const std::string &name) { Mantid::API::AnalysisDataService::Instance().remove(name); }
90
103template <typename YType, typename EType> Histogram createHisto(bool isHistogram, YType &&yAxis, EType &&eAxis) {
104 // We don't need to check if y.size() == e.size() as the histogram
105 // type does this at construction
106 const size_t yValsSize = yAxis.size();
107 if (isHistogram) {
108 BinEdges xAxis(yValsSize + 1, LinearGenerator(1, 1));
109 Histogram histo{std::move(xAxis), std::forward<YType>(yAxis), std::forward<EType>(eAxis)};
110 return histo;
111 } else {
112 Points xAxis(yValsSize, LinearGenerator(1, 1));
113 Histogram pointsHisto{std::move(xAxis), std::forward<YType>(yAxis), std::forward<EType>(eAxis)};
114 return pointsHisto;
115 }
116}
117
119
120 MersenneTwister randomGen(DateAndTime::getCurrentTime().nanoseconds(), 0, std::numeric_limits<int>::max());
121
122 auto randFunc = [&randomGen] { return randomGen.nextValue(); };
123 Counts counts(size, randFunc);
124 CountStandardDeviations errorVals(size, randFunc);
125
126 auto retVal = std::make_shared<Workspace2D>();
127 retVal->initialize(1, createHisto(isHisto, counts, errorVals));
128 return retVal;
129}
130
131Workspace2D_sptr create1DWorkspaceConstant(int size, double value, double error, bool isHisto) {
132 Counts yVals(size, value);
133 CountStandardDeviations errVals(size, error);
134
135 auto retVal = std::make_shared<Workspace2D>();
136 retVal->initialize(1, createHisto(isHisto, yVals, errVals));
137 return retVal;
138}
139
140Workspace2D_sptr create1DWorkspaceConstantWithXerror(int size, double value, double error, double xError,
141 bool isHisto) {
142 auto ws = create1DWorkspaceConstant(size, value, error, isHisto);
143 auto dx1 = Kernel::make_cow<HistogramData::HistogramDx>(size, xError);
144 ws->setSharedDx(0, dx1);
145 return ws;
146}
147
148Workspace2D_sptr create1DWorkspaceFib(int size, bool isHisto) {
149 BinEdges xVals(size + 1, LinearGenerator(1, 1));
150 Counts yVals(size, FibSeries<double>());
151 CountStandardDeviations errVals(size);
152
153 auto retVal = std::make_shared<Workspace2D>();
154 retVal->initialize(1, createHisto(isHisto, yVals, errVals));
155 return retVal;
156}
157
158Workspace2D_sptr create2DWorkspace(size_t nhist, size_t numBoundaries) {
159 return create2DWorkspaceBinned(nhist, numBoundaries);
160}
161
169 Workspace2D_sptr out = create2DWorkspaceBinned(nhist, numBoundaries);
170 for (int workspaceIndex = 0; workspaceIndex < nhist; workspaceIndex++) {
171 std::vector<double> yValues(numBoundaries, static_cast<double>(workspaceIndex));
172 out->mutableY(workspaceIndex) = yValues;
173 }
174
175 return out;
176}
177
179
180 Workspace2D_sptr outputWS = create2DWorkspaceBinned(nHist, nBins);
181 auto newAxis = std::make_unique<NumericAxis>(nHist);
182 auto newAxisRaw = newAxis.get();
183 outputWS->replaceAxis(1, std::move(newAxis));
184 newAxisRaw->unit() = std::make_shared<Units::Degrees>();
185 for (int i = 0; i < nHist; ++i) {
186 newAxisRaw->setValue(i, i + 1);
187 }
188
189 return outputWS;
190}
191
206Workspace2D_sptr create2DWorkspaceWithValues(int64_t nHist, int64_t nBins, bool isHist,
207 const std::set<int64_t> &maskedWorkspaceIndices, double xVal, double yVal,
208 double eVal, bool hasDx = false) {
209 auto x1 = Kernel::make_cow<HistogramData::HistogramX>(isHist ? nBins + 1 : nBins, LinearGenerator(xVal, 1.0));
210 Counts y1(nBins, yVal);
211 CountStandardDeviations e1(nBins, eVal);
212 auto dx = Kernel::make_cow<HistogramData::HistogramDx>(nBins, yVal);
213 auto retVal = std::make_shared<Workspace2D>();
214 retVal->initialize(nHist, createHisto(isHist, y1, e1));
215 for (int i = 0; i < nHist; i++) {
216 retVal->setSharedX(i, x1);
217 if (hasDx)
218 retVal->setSharedDx(i, dx);
219 retVal->getSpectrum(i).setDetectorID(i);
220 retVal->getSpectrum(i).setSpectrumNo(i);
221 }
222 if (maskedWorkspaceIndices.size() > 0) {
223 retVal = maskSpectra(retVal, maskedWorkspaceIndices);
224 }
225 return retVal;
226}
227
228Workspace2D_sptr create2DWorkspaceWithValuesAndXerror(int64_t nHist, int64_t nBins, bool isHist, double xVal,
229 double yVal, double eVal, double dxVal,
230 const std::set<int64_t> &maskedWorkspaceIndices) {
231 auto ws = create2DWorkspaceWithValues(nHist, nBins, isHist, maskedWorkspaceIndices, xVal, yVal, eVal);
232 PointStandardDeviations dx1(nBins, dxVal);
233 for (int i = 0; i < nHist; i++) {
234 ws->setPointStandardDeviations(i, dx1);
235 }
236 return ws;
237}
238
239Workspace2D_sptr create2DWorkspace123(int64_t nHist, int64_t nBins, bool isHist,
240 const std::set<int64_t> &maskedWorkspaceIndices, bool hasDx) {
241 return create2DWorkspaceWithValues(nHist, nBins, isHist, maskedWorkspaceIndices, 1.0, 2.0, 3.0, hasDx);
242}
243
244Workspace2D_sptr create2DWorkspace154(int64_t nHist, int64_t nBins, bool isHist,
245 const std::set<int64_t> &maskedWorkspaceIndices, bool hasDx) {
246 return create2DWorkspaceWithValues(nHist, nBins, isHist, maskedWorkspaceIndices, 1.0, 5.0, 4.0, hasDx);
247}
248
249Workspace2D_sptr maskSpectra(Workspace2D_sptr workspace, const std::set<int64_t> &maskedWorkspaceIndices) {
250 const auto nhist = static_cast<int>(workspace->getNumberHistograms());
251 if (workspace->getInstrument()->nelements() == 0) {
252 // We need detectors to be able to mask them.
253 auto instrument = std::make_shared<Instrument>();
254 workspace->setInstrument(instrument);
255
256 std::string xmlShape = "<sphere id=\"shape\"> ";
257 xmlShape += R"(<centre x="0.0" y="0.0" z="0.0" /> )";
258 xmlShape += "<radius val=\"0.05\" /> ";
259 xmlShape += "</sphere>";
260 xmlShape += "<algebra val=\"shape\" /> ";
261
262 ShapeFactory sFactory;
263 auto shape = sFactory.createShape(xmlShape);
264 for (int i = 0; i < nhist; ++i) {
265 Detector *det = new Detector("det", detid_t(i + 1), shape, nullptr);
266 det->setPos(i, i + 1, 1);
267 instrument->add(det);
268 instrument->markAsDetector(det);
269 }
270 workspace->setInstrument(instrument);
271 // Set IndexInfo without explicit spectrum definitions to trigger building
272 // default mapping of spectra to detectors in new instrument.
273 workspace->setIndexInfo(Indexing::IndexInfo(nhist));
274 }
275
276 auto &spectrumInfo = workspace->mutableSpectrumInfo();
277 for (const auto index : maskedWorkspaceIndices)
278 spectrumInfo.setMasked(index, true);
279 return workspace;
280}
281
285WorkspaceGroup_sptr createWorkspaceGroup(int nEntries, int nHist, int nBins, const std::string &stem) {
286 auto group = std::make_shared<WorkspaceGroup>();
287 AnalysisDataService::Instance().add(stem, group);
288 for (int i = 0; i < nEntries; ++i) {
289 Workspace2D_sptr ws = create2DWorkspace(nHist, nBins);
290 std::ostringstream os;
291 os << stem << "_" << i;
292 AnalysisDataService::Instance().add(os.str(), ws);
293 group->add(os.str());
294 }
295 return group;
296}
297
302 // create workspace with 2 histograms
304
305 // create and replace histograms with ragged ones
306 MantidVec x_data{100., 200., 300., 400.};
307 MantidVec y_data{1., 1., 1.};
308 MantidVec e_data{1., 1., 1.};
309
310 MantidVec x_data2{200., 400., 600.};
311 MantidVec y_data2{1., 1.};
312 MantidVec e_data2{1., 1.};
313
314 // Update values based on version specification
315 if (version == 1) {
316 // different number of bins
317 x_data2 = {200., 400.};
318 y_data2 = {1.};
319 e_data2 = {1.};
320 } else if (version == 2) {
321 // same number of bins but different y values
322 y_data2 = {1., 2.};
323 } else if (version == 3) {
324 // same number of bins but different x values
325 x_data2 = {200., 500., 600.};
326 } else if (version == 4) {
327 // sets up histograms for the Multiply/Divide tests
328 y_data = {2., 2., 2.};
329 e_data = {2., 2., 2.};
330 y_data2 = {2., 2.};
331 e_data2 = {2., 2.};
332 }
333
334 Mantid::HistogramData::HistogramBuilder builder;
335 builder.setX(x_data);
336 builder.setY(y_data);
337 builder.setE(e_data);
338 raggedWS->setHistogram(0, builder.build());
339
340 Mantid::HistogramData::HistogramBuilder builder2;
341 builder2.setX(x_data2);
342 builder2.setY(y_data2);
343 builder2.setE(e_data2);
344 raggedWS->setHistogram(1, builder2.build());
345
346 return raggedWS;
347}
348
352Workspace2D_sptr create2DWorkspaceBinned(size_t nhist, size_t numVals, double x0, double deltax) {
353 BinEdges x(numVals + 1, LinearGenerator(x0, deltax));
354 Counts y(numVals, 2);
355 CountStandardDeviations e(numVals, M_SQRT2);
356 return create<Workspace2D>(nhist, Histogram(x, y, e));
357}
358
362Workspace2D_sptr create2DWorkspacePoints(size_t nhist, size_t numVals, double x0, double deltax) {
363 Points x(numVals, LinearGenerator(x0, deltax));
364 Counts y(numVals, 2);
365 CountStandardDeviations e(numVals, M_SQRT2);
366 return create<Workspace2D>(nhist, Histogram(x, y, e));
367}
368
375Workspace2D_sptr create2DWorkspaceNonUniformlyBinned(int nhist, const int numBoundaries, const double xBoundaries[],
376 bool hasDx) {
377 BinEdges x(xBoundaries, xBoundaries + numBoundaries);
378 const int numBins = numBoundaries - 1;
379 Counts y(numBins, 2);
380 CountStandardDeviations e(numBins, M_SQRT2);
381 auto dx = Kernel::make_cow<HistogramData::HistogramDx>(numBins, LinearGenerator(0.1, .1));
382 auto retVal = std::make_shared<Workspace2D>();
383 retVal->initialize(nhist, createHisto(true, y, e));
384 for (int i = 0; i < nhist; i++) {
385 retVal->setBinEdges(i, x);
386 if (hasDx)
387 retVal->setSharedDx(i, dx);
388 }
389 return retVal;
390}
391
399void addNoise(const Mantid::API::MatrixWorkspace_sptr &ws, double noise, const double lower, const double upper) {
400 const size_t seed(12345);
401 MersenneTwister randGen(seed, lower, upper);
402 for (size_t iSpec = 0; iSpec < ws->getNumberHistograms(); iSpec++) {
403 auto &mutableY = ws->mutableY(iSpec);
404 auto &mutableE = ws->mutableE(iSpec);
405 for (size_t i = 0; i < mutableY.size(); i++) {
406 mutableY[i] += noise * randGen.nextValue();
407 mutableE[i] += noise;
408 }
409 }
410}
411
418Workspace2D_sptr create2DWorkspaceWithFullInstrument(int nhist, int nbins, bool includeMonitors, bool startYNegative,
419 bool isHistogram, const std::string &instrumentName, bool hasDx) {
420 if (includeMonitors && nhist < 2) {
421 throw std::invalid_argument("Attempting to 2 include monitors for a "
422 "workspace with fewer than 2 histograms");
423 }
424
425 Workspace2D_sptr space;
426 // A 1:1 spectra is created by default
427 if (isHistogram)
428 space = create2DWorkspaceBinned(nhist, nbins, hasDx);
429 else
430 space = create2DWorkspace123(nhist, nbins, false, std::set<int64_t>(), hasDx);
431 // actually adds a property called run_title to the logs
432 space->setTitle("Test histogram");
433 space->getAxis(0)->setUnit("TOF");
434 space->setYUnit("Counts");
435
436 InstrumentCreationHelper::addFullInstrumentToWorkspace(*space, includeMonitors, startYNegative, instrumentName);
437
438 return space;
439}
440
441//================================================================================================================
442/*
443 * startTime is in seconds
444 */
446 size_t startTime, size_t firstInterval,
447 bool includeMonitors, bool startYNegative,
448 bool isHistogram,
449 const std::string &instrumentName) {
450
451 auto baseWS =
452 create2DWorkspaceWithFullInstrument(nhist, nbins, includeMonitors, startYNegative, isHistogram, instrumentName);
453
454 auto builder = ScanningWorkspaceBuilder(baseWS->getInstrument(), nTimeIndexes, nbins);
455
456 std::vector<double> timeRanges;
457 for (size_t i = 0; i < nTimeIndexes; ++i) {
458 timeRanges.emplace_back(double(i + firstInterval));
459 }
460
461 builder.setTimeRanges(DateAndTime(int(startTime), 0), timeRanges);
462
463 return builder.buildWorkspace();
464}
465
466//================================================================================================================
472Workspace2D_sptr create2DWorkspaceWithGeographicalDetectors(const int nlat, const int nlong, const double anginc,
473 const int nbins, const double x0, const double deltax,
474 const std::string &instrumentName,
475 const std::string &xunit) {
476 auto inputWorkspace = WorkspaceCreationHelper::create2DWorkspaceBinned(nlat * nlong, nbins, x0, deltax);
477 inputWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create(xunit);
478
480 instrumentName);
481
482 return inputWorkspace;
483}
484
485//================================================================================================================
497 int numBins,
498 const std::string &instrumentName) {
499 Instrument_sptr inst =
500 ComponentCreationHelper::createTestInstrumentRectangular(numBanks, numPixels, 0.008, 5.0, false, instrumentName);
501 Workspace2D_sptr ws = create2DWorkspaceBinned(numBanks * numPixels * numPixels, numBins);
502 ws->setInstrument(inst);
503 ws->getAxis(0)->setUnit("dSpacing");
504 for (size_t wi = 0; wi < ws->getNumberHistograms(); wi++) {
505 ws->getSpectrum(wi).setDetectorID(detid_t(numPixels * numPixels + wi));
506 ws->getSpectrum(wi).setSpectrumNo(specnum_t(wi));
507 }
508
509 return ws;
510}
511
512//================================================================================================================
524 bool clearEvents) {
526 EventWorkspace_sptr ws = createEventWorkspace2(numBanks * numPixels * numPixels, 100);
527 ws->setInstrument(inst);
528
529 // Set the X axes
530 const auto &xVals = ws->x(0);
531 const size_t xSize = xVals.size();
532 auto ax0 = std::make_unique<NumericAxis>(xSize);
533 ax0->setUnit("dSpacing");
534 for (size_t i = 0; i < xSize; i++) {
535 ax0->setValue(i, xVals[i]);
536 }
537 ws->replaceAxis(0, std::move(ax0));
538
539 // re-assign detector IDs to the rectangular detector
540 const auto detIds = inst->getDetectorIDs();
541 for (int wi = 0; wi < static_cast<int>(ws->getNumberHistograms()); ++wi) {
542 ws->getSpectrum(wi).clearDetectorIDs();
543 if (clearEvents)
544 ws->getSpectrum(wi).clear(true);
545 ws->getSpectrum(wi).setDetectorID(detIds[wi]);
546 }
547 return ws;
548}
549
561 bool clearEvents) {
563 EventWorkspace_sptr ws = createEventWorkspace2(numBanks * numPixels * numPixels, 100);
564 ws->setInstrument(inst);
565
566 // Set the X axes
567 const auto &xVals = ws->x(0);
568 const size_t xSize = xVals.size();
569 auto ax0 = std::make_unique<NumericAxis>(xSize);
570 ax0->setUnit("dSpacing");
571 for (size_t i = 0; i < xSize; i++) {
572 ax0->setValue(i, xVals[i]);
573 }
574 ws->replaceAxis(0, std::move(ax0));
575
576 // re-assign detector IDs to the rectangular detector
577 const auto detIds = inst->getDetectorIDs();
578 for (int wi = 0; wi < static_cast<int>(ws->getNumberHistograms()); ++wi) {
579 ws->getSpectrum(wi).clearDetectorIDs();
580 if (clearEvents)
581 ws->getSpectrum(wi).clear(true);
582 ws->getSpectrum(wi).setDetectorID(detIds[wi]);
583 }
584 return ws;
585}
586
588 // Number of detectors in a bank as created by createTestInstrumentCylindrical
589 const int DETECTORS_PER_BANK(9);
590
591 V3D srcPos(0., 0., -10.), samplePos;
592 Instrument_sptr inst =
593 ComponentCreationHelper::createTestInstrumentCylindrical(numBanks, srcPos, samplePos, 0.0025, 0.005);
594 EventWorkspace_sptr ws = createEventWorkspace2(numBanks * DETECTORS_PER_BANK, 100);
595 ws->setInstrument(inst);
596
597 std::vector<detid_t> detectorIds = inst->getDetectorIDs();
598
599 // Should be equal if DETECTORS_PER_BANK is correct
600 assert(detectorIds.size() == ws->getNumberHistograms());
601
602 // Re-assign detector IDs
603 for (size_t wi = 0; wi < ws->getNumberHistograms(); wi++) {
604 ws->getSpectrum(wi).clearDetectorIDs();
605 if (clearEvents)
606 ws->getSpectrum(wi).clear(true);
607 ws->getSpectrum(wi).setDetectorID(detectorIds[wi]);
608 }
609
610 return ws;
611}
612
621DataObjects::Workspace2D_sptr reflectometryWorkspace(const double startX, const int nSpectra, const int nBins,
622 const double deltaX) {
623
624 auto workspace = create2DWorkspaceBinned(nSpectra, nBins, startX, deltaX);
625
626 workspace->setTitle("Test histogram"); // actually adds a property call run_title to the logs
627 workspace->getAxis(0)->setUnit("TOF");
628 workspace->setYUnit("Counts");
629 return workspace;
630}
631
648 const V3D &slit2Pos, const double vg1,
649 const double vg2, const V3D &sourcePos,
650 const V3D &monitorPos, const V3D &samplePos,
651 const V3D &detectorPos, const int nBins,
652 const double deltaX) {
653 Instrument_sptr instrument = std::make_shared<Instrument>();
654 instrument->setReferenceFrame(
655 std::make_shared<ReferenceFrame>(PointingAlong::Y, PointingAlong::X, Handedness::Left, "0,0,0"));
656
657 InstrumentCreationHelper::addSource(instrument, sourcePos, "source");
658 InstrumentCreationHelper::addMonitor(instrument, monitorPos, 1, "Monitor");
659 InstrumentCreationHelper::addSample(instrument, samplePos, "some-surface-holder");
660 InstrumentCreationHelper::addDetector(instrument, detectorPos, 2, "point-detector");
661 auto slit1 = InstrumentCreationHelper::addComponent(instrument, slit1Pos, "slit1");
662 auto slit2 = InstrumentCreationHelper::addComponent(instrument, slit2Pos, "slit2");
663
664 auto workspace = reflectometryWorkspace(startX, 2, nBins, deltaX);
665 workspace->setInstrument(instrument);
666
667 ParameterMap &pmap = workspace->instrumentParameters();
668 pmap.addDouble(slit1, "vertical gap", vg1);
669 pmap.addDouble(slit2, "vertical gap", vg2);
670
671 workspace->getSpectrum(0).setDetectorID(2);
672 workspace->getSpectrum(1).setDetectorID(1);
673
674 return workspace;
675}
676
696 const double startX, const double detSize, const V3D &slit1Pos, const V3D &slit2Pos, const double vg1,
697 const double vg2, const V3D &sourcePos, const V3D &monitorPos, const V3D &samplePos, const V3D &detectorCenterPos,
698 const int nSpectra, const int nBins, const double deltaX) {
699 Instrument_sptr instrument = std::make_shared<Instrument>();
700 instrument->setReferenceFrame(
701 std::make_shared<ReferenceFrame>(PointingAlong::Y /*up*/, PointingAlong::X /*along*/, Handedness::Left, "0,0,0"));
702
703 InstrumentCreationHelper::addSource(instrument, sourcePos, "source");
704 InstrumentCreationHelper::addSample(instrument, samplePos, "some-surface-holder");
705 InstrumentCreationHelper::addMonitor(instrument, monitorPos, 1, "Monitor");
706
707 const int nDet = nSpectra - 1;
708 const double minY = detectorCenterPos.Y() - detSize * (nDet - 1) / 2.;
709 for (int i = 0; i < nDet; ++i) {
710 const double y = minY + i * detSize;
711 const V3D pos{detectorCenterPos.X(), y, detectorCenterPos.Z()};
712 InstrumentCreationHelper::addDetector(instrument, pos, i + 2, "point-detector");
713 }
714 auto slit1 = InstrumentCreationHelper::addComponent(instrument, slit1Pos, "slit1");
715 auto slit2 = InstrumentCreationHelper::addComponent(instrument, slit2Pos, "slit2");
716
717 auto workspace = reflectometryWorkspace(startX, nSpectra, nBins, deltaX);
718 workspace->setInstrument(instrument);
719 ParameterMap &pmap = workspace->instrumentParameters();
720 pmap.addDouble(slit1, "vertical gap", vg1);
721 pmap.addDouble(slit2, "vertical gap", vg2);
722 for (int i = 0; i < nSpectra; ++i) {
723 workspace->getSpectrum(i).setDetectorID(i + 1);
724 }
725 return workspace;
726}
727
729 const V3D &sourcePosition, const std::vector<V3D> &detectorPositions) {
730 Instrument_sptr instrument = std::make_shared<Instrument>();
731 instrument->setReferenceFrame(std::make_shared<ReferenceFrame>(Y, X, Left, "0,0,0"));
732
733 InstrumentCreationHelper::addSource(instrument, sourcePosition, "source");
734 InstrumentCreationHelper::addSample(instrument, samplePosition, "sample");
735
736 for (int i = 0; i < static_cast<int>(detectorPositions.size()); ++i) {
737 std::stringstream buffer;
738 buffer << "detector_" << i;
739 InstrumentCreationHelper::addDetector(instrument, detectorPositions[i], i, buffer.str());
740
741 // Link it to the workspace
742 workspace->getSpectrum(i).addDetectorID(i);
743 }
744 workspace->setInstrument(instrument);
745}
746
747//================================================================================================================
749 return std::make_shared<WorkspaceSingleValue>(value, sqrt(value));
750}
751
753 return std::make_shared<WorkspaceSingleValue>(value, error);
754}
755
758 // get a proton charge
759 ew->mutableRun().integrateProtonCharge();
760}
761
767
774EventWorkspace_sptr createEventWorkspace2(int numPixels, int numBins) {
775 return createEventWorkspace(numPixels, numBins, 100, 0.0, 1.0, 2);
776}
777
780EventWorkspace_sptr createEventWorkspace(int numPixels, int numBins, int numEvents, double x0, double binDelta,
781 int eventPattern, int start_at_pixelID) {
782 return createEventWorkspaceWithStartTime(numPixels, numBins, numEvents, x0, binDelta, eventPattern, start_at_pixelID,
783 DateAndTime("2010-01-01T00:00:00"));
784}
785
789EventWorkspace_sptr createEventWorkspaceWithStartTime(int numPixels, int numBins, int numEvents, double x0,
790 double binDelta, int eventPattern, int start_at_pixelID,
791 DateAndTime run_start) {
792
793 // add one to the number of bins as this is histogram
794 numBins++;
795
796 auto retVal = std::make_shared<EventWorkspace>();
797 retVal->initialize(numPixels, 1, 1);
798
799 MersenneTwister randomGen(DateAndTime::getCurrentTime().nanoseconds(), 0, std::numeric_limits<int>::max());
800 // Make fake events
801 if (eventPattern) // 0 == no events
802 {
803 size_t workspaceIndex = 0;
804 for (int pix = start_at_pixelID + 0; pix < start_at_pixelID + numPixels; pix++) {
805 EventList &el = retVal->getSpectrum(workspaceIndex);
806 el.setSpectrumNo(pix);
807 el.setDetectorID(pix);
808
809 for (int i = 0; i < numEvents; i++) {
810 if (eventPattern == 1) // 0, 1 diagonal pattern
811 el += TofEvent((pix + i + 0.5) * binDelta, run_start + double(i));
812 else if (eventPattern == 2) // solid 2
813 {
814 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
815 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
816 } else if (eventPattern == 3) // solid 1
817 {
818 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
819 } else if (eventPattern == 4) // Number of events per bin = pixelId (aka
820 // workspace index in most cases)
821 {
822 for (int q = 0; q < pix; q++)
823 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
824 } else if (eventPattern == 5) // Randomized pattern
825 {
826 el += TofEvent(static_cast<double>(randomGen.nextValue()), run_start + double(i));
827 }
828 }
829 workspaceIndex++;
830 }
831 }
832
833 retVal->setAllX(BinEdges(numBins, LinearGenerator(x0, binDelta)));
834
835 return retVal;
836}
837
838// =====================================================================================
841EventWorkspace_sptr createGroupedEventWorkspace(std::vector<std::vector<int>> const &groups, int numBins,
842 double binDelta, double xOffset) {
843
844 auto retVal = std::make_shared<EventWorkspace>();
845 retVal->initialize(groups.size(), 2, 1);
846
847 for (size_t g = 0; g < groups.size(); g++) {
848 retVal->getSpectrum(g).clearDetectorIDs();
849 std::vector<int> dets = groups[g];
850 for (auto det : dets) {
851 for (int i = 0; i < numBins; i++)
852 retVal->getSpectrum(g) += TofEvent((i + 0.5) * binDelta, 1);
853 retVal->getSpectrum(g).addDetectorID(det);
854 }
855 }
856
857 if (xOffset == 0.) {
858 retVal->setAllX(BinEdges(numBins, LinearGenerator(0.0, binDelta)));
859 } else {
860 for (size_t g = 0; g < groups.size(); g++) {
861 // Create the x-axis for histogramming.
862 const double x0 = xOffset * static_cast<double>(g);
863 retVal->setSharedX(g, make_cow<HistogramX>(numBins, LinearGenerator(x0, binDelta)));
864 }
865 }
866
867 return retVal;
868}
869
870// =====================================================================================
878EventWorkspace_sptr createRandomEventWorkspace(size_t numbins, size_t numpixels, double bin_delta) {
879 auto retVal = std::make_shared<EventWorkspace>();
880 retVal->initialize(numpixels, numbins, numbins - 1);
881
882 // and X-axis for references:
883 auto pAxis0 = std::make_unique<NumericAxis>(numbins);
884 // Create the original X axis to histogram on.
885 // Create the x-axis for histogramming.
886 HistogramData::BinEdges axis(numbins, LinearGenerator(0.0, bin_delta));
887 for (int i = 0; i < static_cast<int>(numbins); ++i) {
888 pAxis0->setValue(i, axis[i]);
889 }
890 pAxis0->setUnit("TOF");
891
892 MersenneTwister randomGen(DateAndTime::getCurrentTime().nanoseconds(), 0, std::numeric_limits<int>::max());
893 // Make up some data for each pixels
894 for (size_t i = 0; i < numpixels; i++) {
895 // Create one event for each bin
896 EventList &events = retVal->getSpectrum(static_cast<detid_t>(i));
897 for (std::size_t ie = 0; ie < numbins; ie++) {
898 // Create a list of events, randomize
899 events += TofEvent(static_cast<double>(randomGen.nextValue()), static_cast<int64_t>(randomGen.nextValue()));
900 }
901 events.addDetectorID(detid_t(i));
902 }
903 retVal->setAllX(axis);
904 retVal->replaceAxis(0, std::move(pAxis0));
905
906 return retVal;
907}
908
909// =====================================================================================
913MatrixWorkspace_sptr createGroupedWorkspace2D(size_t numHist, int numBins, double binDelta) {
914 Workspace2D_sptr retVal = create2DWorkspaceBinned(static_cast<int>(numHist), numBins, 0.0, binDelta);
915 retVal->setInstrument(ComponentCreationHelper::createTestInstrumentCylindrical(static_cast<int>(numHist)));
916
917 for (int g = 0; g < static_cast<int>(numHist); g++) {
918 auto &spec = retVal->getSpectrum(g);
919 for (int i = 1; i <= 9; i++)
920 spec.addDetectorID(g * 9 + i);
921 spec.setSpectrumNo(g + 1); // Match detector ID and spec NO
922 }
923 return std::dynamic_pointer_cast<MatrixWorkspace>(retVal);
924}
925
926// =====================================================================================
927// RootOfNumHist == square root of hystohram number;
928MatrixWorkspace_sptr createGroupedWorkspace2DWithRingsAndBoxes(size_t RootOfNumHist, int numBins, double binDelta) {
929 size_t numHist = RootOfNumHist * RootOfNumHist;
930 Workspace2D_sptr retVal = create2DWorkspaceBinned(static_cast<int>(numHist), numBins, 0.0, binDelta);
931 retVal->setInstrument(ComponentCreationHelper::createTestInstrumentCylindrical(static_cast<int>(numHist)));
932 for (int g = 0; g < static_cast<int>(numHist); g++) {
933 auto &spec = retVal->getSpectrum(g);
934 spec.addDetectorID(g + 1); // Legacy comptibilty: Used to be default IDs in Workspace2D.
935 for (int i = 1; i <= 9; i++)
936 spec.addDetectorID(g * 9 + i);
937 spec.setSpectrumNo(g + 1); // Match detector ID and spec NO
938 }
939 return std::dynamic_pointer_cast<MatrixWorkspace>(retVal);
940}
941
942// not strictly creating a workspace, but really helpful to see what one
943// contains
945 const size_t numHists = ws->getNumberHistograms();
946 for (size_t i = 0; i < numHists; ++i) {
947 std::cout << "Histogram " << i << " = ";
948 const auto &y = ws->y(i);
949 for (size_t j = 0; j < y.size(); ++j) {
950 std::cout << y[j] << " ";
951 }
952 std::cout << '\n';
953 }
954}
956
957// not strictly creating a workspace, but really helpful to see what one
958// contains
960 const size_t numHists = ws->getNumberHistograms();
961 for (size_t i = 0; i < numHists; ++i) {
962 std::cout << "Histogram " << i << " = ";
963 const auto &x = ws->x(i);
964 for (size_t j = 0; j < x.size(); ++j) {
965 std::cout << x[j] << " ";
966 }
967 std::cout << '\n';
968 }
969}
970
971// not strictly creating a workspace, but really helpful to see what one
972// contains
974 const size_t numHists = ws->getNumberHistograms();
975 for (size_t i = 0; i < numHists; ++i) {
976 std::cout << "Histogram " << i << " = ";
977 const auto &e = ws->e(i);
978 for (size_t j = 0; j < e.size(); ++j) {
979 std::cout << e[j] << " ";
980 }
981 std::cout << '\n';
982 }
983}
984
985// =====================================================================================
992void addTSPEntry(Run &runInfo, const std::string &name, double val) {
995 tsp->addValue("2011-05-24T00:00:00", val);
996 runInfo.addProperty(tsp);
997}
998
999// =====================================================================================
1008void setOrientedLattice(const Mantid::API::MatrixWorkspace_sptr &ws, double a, double b, double c) {
1009 ws->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>(a, b, c, 90., 90., 90.));
1010}
1011
1012// =====================================================================================
1020void setGoniometer(const Mantid::API::MatrixWorkspace_sptr &ws, double phi, double chi, double omega) {
1021 addTSPEntry(ws->mutableRun(), "phi", phi);
1022 addTSPEntry(ws->mutableRun(), "chi", chi);
1023 addTSPEntry(ws->mutableRun(), "omega", omega);
1026 ws->mutableRun().setGoniometer(gm, true);
1027}
1028
1029//
1031 bool has_oriented_lattice) {
1032 auto rHist = static_cast<size_t>(std::sqrt(static_cast<double>(numPixels)));
1033 while (rHist * rHist < numPixels)
1034 rHist++;
1035
1037 auto pAxis0 = std::make_unique<NumericAxis>(numBins);
1038 for (size_t i = 0; i < numBins; i++) {
1039 double dE = -1.0 + static_cast<double>(i) * 0.8;
1040 pAxis0->setValue(i, dE);
1041 }
1042 pAxis0->setUnit("DeltaE");
1043 ws->replaceAxis(0, std::move(pAxis0));
1044 if (has_oriented_lattice) {
1045 ws->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.));
1046
1047 addTSPEntry(ws->mutableRun(), "phi", 0);
1048 addTSPEntry(ws->mutableRun(), "chi", 0);
1049 addTSPEntry(ws->mutableRun(), "omega", 0);
1052 ws->mutableRun().setGoniometer(gm, true);
1053 }
1054
1055 return ws;
1056}
1057
1068 const std::vector<double> &polar,
1069 const std::vector<double> &azimutal, size_t numBins,
1070 double Emin, double Emax, double Ei) {
1071 // not used but interface needs it
1072 std::set<int64_t> maskedWorkspaceIndices;
1073 size_t numPixels = L2.size();
1074
1076 create2DWorkspaceWithValues(uint64_t(numPixels), uint64_t(numBins), true, maskedWorkspaceIndices, 0, 1, 0.1);
1077
1078 // detectors at L2, sample at 0 and source at -L2_min
1079 ws->setInstrument(ComponentCreationHelper::createCylInstrumentWithDetInGivenPositions(L2, polar, azimutal));
1080
1081 for (int g = 0; g < static_cast<int>(numPixels); g++) {
1082 auto &spec = ws->getSpectrum(g);
1083 // we just made (in createCylInstrumentWithDetInGivenPosisions) det ID-s to
1084 // start from 1
1085 spec.setDetectorID(g + 1);
1086 // and this is absolutely different nummer, corresponding to det ID just by
1087 // chance ? -- some uncertainties remain
1088 spec.setSpectrumNo(g + 1);
1089 // spec->setSpectrumNo(g+1);
1090 // spec->addDetectorID(g*9);
1091 // spec->setSpectrumNo(g+1); // Match detector ID and spec NO
1092 }
1093
1094 const double dE = (Emax - Emin) / static_cast<double>(numBins);
1095 for (size_t j = 0; j < numPixels; j++) {
1096 std::vector<double> E_transfer;
1097 E_transfer.reserve(numBins);
1098 for (size_t i = 0; i <= numBins; i++) {
1099 E_transfer.emplace_back(Emin + static_cast<double>(i) * dE);
1100 }
1101 ws->mutableX(j) = E_transfer;
1102 }
1103
1104 // set axis, correspondent to the X-values
1105 auto pAxis0 = std::make_unique<NumericAxis>(numBins);
1106 const auto &E_transfer = ws->x(0);
1107 for (size_t i = 0; i < numBins; i++) {
1108 double E = 0.5 * (E_transfer[i] + E_transfer[i + 1]);
1109 pAxis0->setValue(i, E);
1110 }
1111
1112 pAxis0->setUnit("DeltaE");
1113
1114 ws->replaceAxis(0, std::move(pAxis0));
1115
1116 // define oriented lattice which requested for processed ws
1117 ws->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.));
1118
1119 ws->mutableRun().addProperty(new PropertyWithValue<std::string>("deltaE-mode", "Direct"), true);
1120 ws->mutableRun().addProperty(new PropertyWithValue<double>("Ei", Ei), true);
1121 // these properties have to be different -> specific for processed ws, as time
1122 // now should be reconciled
1123 addTSPEntry(ws->mutableRun(), "phi", 0);
1124 addTSPEntry(ws->mutableRun(), "chi", 0);
1125 addTSPEntry(ws->mutableRun(), "omega", 0);
1128 ws->mutableRun().setGoniometer(gm, true);
1129
1130 return ws;
1131}
1132
1133/*
1134 * Create an EventWorkspace from a source EventWorkspace.
1135 * The new workspace should be exactly the same as the source workspace but
1136 * without any events
1137 */
1140 API::Algorithm *alg) {
1141 UNUSED_ARG(wsname);
1142 // 1. Initialize:use dummy numbers for arguments, for event workspace it
1143 // doesn't matter
1146 outputWS->initialize(sourceWS->getInstrument()->getDetectorIDs(true).size(), 1, 1);
1147
1148 // 2. Set the units
1149 outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
1150 outputWS->setYUnit("Counts");
1151 outputWS->setTitle("Empty_Title");
1152
1153 // 3. Add the run_start property:
1154 int runnumber = sourceWS->getRunNumber();
1155 outputWS->mutableRun().addProperty("run_number", runnumber);
1156
1157 std::string runstartstr = sourceWS->run().getProperty("run_start")->value();
1158 outputWS->mutableRun().addProperty("run_start", runstartstr);
1159
1160 // 4. Instrument
1161 Mantid::API::Algorithm_sptr loadInst = alg->createChildAlgorithm("LoadInstrument");
1162 // Now execute the Child Algorithm. Catch and log any error, but don't stop.
1163 loadInst->setPropertyValue("InstrumentName", sourceWS->getInstrumentName());
1164 loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", outputWS);
1165 loadInst->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(true));
1166 loadInst->executeAsChildAlg();
1167 // Populate the instrument parameters in this workspace - this works around a
1168 // bug
1169 outputWS->populateInstrumentParameters();
1170
1171 // 6. Build spectrum and event list
1172 // a) We want to pad out empty pixels.
1173 detid2det_map detector_map;
1174 outputWS->getInstrument()->getDetectors(detector_map);
1175
1176 // b) Pad all the pixels and Set to zero
1177 size_t workspaceIndex = 0;
1178 const auto &detectorInfo = outputWS->detectorInfo();
1179 for (auto it = detector_map.begin(); it != detector_map.end(); ++it) {
1180 if (!detectorInfo.isMonitor(detectorInfo.indexOf(it->first))) {
1181 auto &spec = outputWS->getSpectrum(workspaceIndex);
1182 spec.addDetectorID(it->first);
1183 // Start the spectrum number at 1
1184 spec.setSpectrumNo(specnum_t(workspaceIndex + 1));
1185 workspaceIndex += 1;
1186 }
1187 }
1188
1189 return outputWS;
1190}
1191
1194 // outputWS->setName("rebinTest");
1195 Mantid::API::AnalysisDataService::Instance().add("rebinTest", outputWS);
1196
1197 // Set Q ('y') axis binning
1198 std::vector<double> qbins{0.0, 1.0, 4.0};
1199 std::vector<double> qaxis;
1200 const size_t numY = VectorHelper::createAxisFromRebinParams(qbins, qaxis);
1201
1202 // Initialize the workspace
1203 const size_t numHist = numY - 1;
1204 const size_t numX = 7;
1205 outputWS->initialize(numHist, numX, numX - 1);
1206
1207 // Set the normal units
1208 outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("DeltaE");
1209 outputWS->setYUnit("Counts");
1210 outputWS->setTitle("Empty_Title");
1211
1212 // Create the i-axis for histogramming.
1213 HistogramData::BinEdges x1{-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0};
1214
1215 // Create a numeric axis to replace the default vertical one
1216 auto verticalAxis = std::make_unique<NumericAxis>(numY);
1217
1218 // Now set the axis values
1219 for (size_t i = 0; i < numHist; ++i) {
1220 outputWS->setBinEdges(i, x1);
1221 verticalAxis->setValue(i, qaxis[i]);
1222 }
1223 // One more to set on the 'y' axis
1224 verticalAxis->setValue(numHist, qaxis[numHist]);
1225
1226 // Set the 'y' axis units
1227 verticalAxis->unit() = UnitFactory::Instance().create("MomentumTransfer");
1228 verticalAxis->title() = "|Q|";
1229 outputWS->replaceAxis(1, std::move(verticalAxis));
1230
1231 // Set the X axis title (for conversion to MD)
1232 outputWS->getAxis(0)->title() = "Energy transfer";
1233
1234 // Now, setup the data
1235 // Q bin #1
1236
1237 // Populates destination starting at index 1 with the following data
1238 // e.g. y(0)[1] = 2.0, y(0)[2] = 3.0 ..etc. as the starting index is 1
1239 // if you change the values in the line below please update this comment!
1240 populateWsWithInitList(outputWS->mutableY(0), 1, {2.0, 3.0, 3.0, 2.0});
1241 populateWsWithInitList(outputWS->mutableE(0), 1, {2.0, 3.0, 3.0, 2.0});
1242 populateWsWithInitList(outputWS->dataF(0), 1, {2.0, 3.0, 3.0, 1.0});
1243
1244 // Q bin #2
1245 populateWsWithInitList(outputWS->mutableY(1), 1, {1.0, 3.0, 3.0, 2.0, 2.0});
1246 populateWsWithInitList(outputWS->mutableE(1), 1, {1.0, 3.0, 3.0, 2.0, 2.0});
1247 populateWsWithInitList(outputWS->dataF(1), 1, {1.0, 3.0, 3.0, 1.0, 2.0});
1248
1249 // Q bin #3
1250 populateWsWithInitList(outputWS->mutableY(2), 1, {1.0, 2.0, 3.0, 1.0});
1251 populateWsWithInitList(outputWS->mutableE(2), 1, {1.0, 2.0, 3.0, 1.0});
1252 populateWsWithInitList(outputWS->dataF(2), 1, {1.0, 2.0, 2.0, 1.0});
1253
1254 // Q bin #4
1255 populateWsWithInitList(outputWS->mutableY(3), 0, {1.0, 2.0, 3.0, 2.0, 1.0});
1256 populateWsWithInitList(outputWS->mutableE(3), 0, {1.0, 2.0, 3.0, 2.0, 1.0});
1257 populateWsWithInitList(outputWS->dataF(3), 0, {1.0, 2.0, 3.0, 2.0, 1.0, 1.0});
1258
1259 // Set representation
1260 outputWS->finalize();
1261
1262 // Make errors squared rooted and set sqrd err flag
1263 for (size_t i = 0; i < numHist; ++i) {
1264 auto &mutableE = outputWS->mutableE(i);
1265 for (size_t j = 0; j < numX - 1; ++j) {
1266 mutableE[j] = std::sqrt(mutableE[j]);
1267 }
1268 }
1269 outputWS->setSqrdErrors(false);
1270
1271 return outputWS;
1272}
1273
1286template <typename T>
1287void populateWsWithInitList(T &destination, size_t startingIndex, const std::initializer_list<double> &values) {
1288 size_t index = 0;
1289 for (const double val : values) {
1290 destination[startingIndex + index] = val;
1291 index++;
1292 }
1293}
1294
1295Mantid::DataObjects::PeaksWorkspace_sptr createPeaksWorkspace(const int numPeaks, const bool createOrientedLattice) {
1296 auto peaksWS = std::make_shared<PeaksWorkspace>();
1298 peaksWS->setInstrument(inst);
1299
1300 for (int i = 0; i < numPeaks; ++i) {
1301 Peak peak(inst, i, i + 0.5);
1302 peaksWS->addPeak(peak);
1303 }
1304
1305 if (createOrientedLattice) {
1306 peaksWS->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>());
1307 }
1308 return peaksWS;
1309}
1310
1312 const Mantid::Kernel::DblMatrix &ubMat) {
1313 if (ubMat.numRows() != 3 || ubMat.numCols() != 3) {
1314 throw std::invalid_argument("UB matrix is not 3x3");
1315 }
1316
1317 auto peaksWS = createPeaksWorkspace(numPeaks, true);
1318 peaksWS->mutableSample().getOrientedLattice().setUB(ubMat);
1319 return peaksWS;
1320}
1321
1323 const bool createOrientedLattice) {
1324 auto peaksWS = std::make_shared<LeanElasticPeaksWorkspace>();
1326 for (int i = 0; i < numPeaks; ++i) {
1327 Peak peak(inst, i, i + 0.5);
1328 LeanElasticPeak lpeak(peak);
1329 peaksWS->addPeak(lpeak);
1330 }
1331
1332 if (createOrientedLattice) {
1333 peaksWS->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>());
1334 }
1335 return peaksWS;
1336}
1337
1339 const Mantid::Kernel::DblMatrix &ubMat) {
1340 if (ubMat.numRows() != 3 || ubMat.numCols() != 3) {
1341 throw std::invalid_argument("UB matrix is not 3x3");
1342 }
1343
1344 auto peaksWS = createLeanPeaksWorkspace(numPeaks, true);
1345 peaksWS->mutableSample().getOrientedLattice().setUB(ubMat);
1346 return peaksWS;
1347}
1348
1349void create2DAngles(std::vector<double> &L2, std::vector<double> &polar, std::vector<double> &azim, size_t nPolar,
1350 size_t nAzim, double polStart, double polEnd, double azimStart, double azimEnd) {
1351 size_t nDet = nPolar * nAzim;
1352 L2.resize(nDet, 10);
1353 polar.resize(nDet);
1354 azim.resize(nDet);
1355
1356 double dPolar = (polEnd - polStart) / static_cast<double>(nDet - 1);
1357 double dAzim = (azimEnd - azimEnd) / static_cast<double>(nDet - 1);
1358 for (size_t i = 0; i < nPolar; i++) {
1359 for (size_t j = 0; j < nAzim; j++) {
1360 polar[i * nPolar + j] = polStart + dPolar * static_cast<double>(i);
1361 azim[i * nPolar + j] = azimStart + dAzim * static_cast<double>(j);
1362 }
1363 }
1364}
1365
1366ITableWorkspace_sptr createEPPTableWorkspace(const std::vector<EPPTableRow> &rows) {
1367 ITableWorkspace_sptr ws = std::make_shared<TableWorkspace>(rows.size());
1368 auto wsIndexColumn = ws->addColumn("int", "WorkspaceIndex");
1369 auto centreColumn = ws->addColumn("double", "PeakCentre");
1370 auto centreErrorColumn = ws->addColumn("double", "PeakCentreError");
1371 auto sigmaColumn = ws->addColumn("double", "Sigma");
1372 auto sigmaErrorColumn = ws->addColumn("double", "SigmaError");
1373 auto heightColumn = ws->addColumn("double", "Height");
1374 auto heightErrorColumn = ws->addColumn("double", "HeightError");
1375 auto chiSqColumn = ws->addColumn("double", "chiSq");
1376 auto statusColumn = ws->addColumn("str", "FitStatus");
1377 for (size_t i = 0; i != rows.size(); ++i) {
1378 const auto &row = rows[i];
1379 if (row.workspaceIndex < 0) {
1380 wsIndexColumn->cell<int>(i) = static_cast<int>(i);
1381 } else {
1382 wsIndexColumn->cell<int>(i) = row.workspaceIndex;
1383 }
1384 centreColumn->cell<double>(i) = row.peakCentre;
1385 centreErrorColumn->cell<double>(i) = row.peakCentreError;
1386 sigmaColumn->cell<double>(i) = row.sigma;
1387 sigmaErrorColumn->cell<double>(i) = row.sigmaError;
1388 heightColumn->cell<double>(i) = row.height;
1389 heightErrorColumn->cell<double>(i) = row.heightError;
1390 chiSqColumn->cell<double>(i) = row.chiSq;
1391 statusColumn->cell<std::string>(i) = row.fitStatus == EPPTableRow::FitStatus::SUCCESS ? "success" : "failed";
1392 }
1393 return ws;
1394}
1396 int maskedWorkspaceIndex, int maskedBinIndex) {
1397 auto ws = create2DWorkspace123(numHist, numBins);
1398 ws->flagMasked(maskedWorkspaceIndex, maskedBinIndex);
1399 return ws;
1400}
1401
1402MatrixWorkspace_sptr createSNAPLiteInstrument(const std::string &wkspName, const double ang1, const double ang2) {
1403 // Use lite instrument based on one valid starting 2018-05-01
1404 const std::string IDF_FILE("SNAPLite_Definition.xml");
1405
1406 // Create empty instrument
1407 auto loadEmptyInstr = AlgorithmManager::Instance().createUnmanaged("LoadEmptyInstrument");
1408 loadEmptyInstr->initialize();
1409 loadEmptyInstr->setProperty("Filename", IDF_FILE);
1410 loadEmptyInstr->setProperty("OutputWorkspace", wkspName);
1411
1412 loadEmptyInstr->execute();
1413 if (!loadEmptyInstr->isExecuted())
1414 throw std::runtime_error("Failed to execute LoadEmptyInstrument");
1415
1416 // add logs
1417 // for some reason, the units aren't in the logs
1418 TimeSeriesProperty<double> *ang1Prop = new TimeSeriesProperty<double>("det_arc1");
1419 ang1Prop->addValue(DateAndTime(0), ang1);
1420 TimeSeriesProperty<double> *ang2Prop = new TimeSeriesProperty<double>("det_arc2");
1421 ang2Prop->addValue(DateAndTime(0), ang2);
1422 TimeSeriesProperty<double> *len1Prop = new TimeSeriesProperty<double>("det_lin1");
1423 len1Prop->addValue(DateAndTime(0), 0.045);
1424 TimeSeriesProperty<double> *len2Prop = new TimeSeriesProperty<double>("det_lin2");
1425 len2Prop->addValue(DateAndTime(0), 0.043);
1426
1428 std::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(wkspName));
1429 wsIn->mutableRun().addProperty(ang1Prop);
1430 wsIn->mutableRun().addProperty(ang2Prop);
1431 wsIn->mutableRun().addProperty(len1Prop);
1432 wsIn->mutableRun().addProperty(len2Prop);
1433
1434 // reload instrument so the logs are used
1435 auto loadInstr = AlgorithmManager::Instance().createUnmanaged("LoadInstrument");
1436 loadInstr->initialize();
1437 loadInstr->setProperty("Workspace", wkspName);
1438 loadInstr->setProperty("Filename", IDF_FILE);
1439 loadInstr->setProperty("RewriteSpectraMap", "False");
1440 loadInstr->execute();
1441 if (!loadInstr->isExecuted())
1442 throw std::runtime_error("Failed to execute LoadInstrument");
1443
1444 // set the units so DiffractionFocussing will do its job
1445 auto xAxis = wsIn->getAxis(0);
1446 xAxis->unit() = Mantid::Kernel::UnitFactory::Instance().create("dSpacing");
1447 return wsIn;
1448}
1449
1450MatrixWorkspace_sptr createFocusedSNAPLiteInstrument(const std::string &wkspName, const std::string &groupingAlg,
1451 const std::string &groupingDescr, const double ang1,
1452 const double ang2) {
1453 const std::string GROUP_WS_NAME = "tmpGroupingWorkspace_" + groupingAlg + "_" + groupingDescr;
1454
1455 // create the full instrument
1457
1458 // create the groupingworkspace
1459 auto createGroupingAlg = AlgorithmManager::Instance().createUnmanaged(groupingAlg);
1460 createGroupingAlg->initialize();
1461 createGroupingAlg->setProperty("OutputWorkspace", GROUP_WS_NAME);
1462 if (groupingAlg == "CreateGroupingWorkspace") {
1463 createGroupingAlg->setProperty("InputWorkspace", ws);
1464 createGroupingAlg->setProperty("GroupDetectorsBy", groupingDescr);
1465 } else if (groupingAlg == "LoadDetectorsGroupingFile") {
1466 createGroupingAlg->setProperty("InputWorkspace", ws);
1467 createGroupingAlg->setProperty("InputFile", groupingDescr);
1468 } else {
1469 throw std::runtime_error("Do not know how to create grouping using \"" + groupingAlg + "\" algorithm");
1470 }
1471 createGroupingAlg->execute();
1472 if (!createGroupingAlg->isExecuted())
1473 throw std::runtime_error("Failed to execute CreateGroupingWorkspace");
1474
1475 // focus the data
1476 auto focusAlg = AlgorithmManager::Instance().createUnmanaged("DiffractionFocussing");
1477 focusAlg->initialize();
1478 focusAlg->setProperty("InputWorkspace", wkspName);
1479 focusAlg->setProperty("OutputWorkspace", wkspName);
1480 focusAlg->setProperty("GroupingWorkspace", GROUP_WS_NAME);
1481 focusAlg->execute();
1482 AnalysisDataService::Instance().remove(GROUP_WS_NAME); // delete the grouping workspace no matter what happened
1483 if (!focusAlg->isExecuted())
1484 throw std::runtime_error("Failed to execute DiffractionFocussing");
1485
1486 return std::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(wkspName));
1487}
1488
1489} // namespace WorkspaceCreationHelper
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double height
Definition GetAllEi.cpp:155
double error
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
int64_t nSpectra
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:44
double lower
lower and upper bounds on the multiplier, if known
double upper
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
virtual 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)
Create a Child Algorithm.
This class is shared by a few Workspace types and holds information related to a particular experimen...
Geometry::ComponentInfo const & baseComponentInfo() const
Returns a ComponentInfo for the base (unparametrized) instrument, i.e.
void addDetectorID(const detid_t detID)
Add a detector ID to the set of detector IDs.
Definition ISpectrum.cpp:51
void setDetectorID(const detid_t detID)
Clear the list of detector IDs, then add one.
Definition ISpectrum.cpp:84
void setSpectrumNo(specnum_t num)
Sets the spectrum number of this spectrum.
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
Definition LogManager.h:90
Helper class for reporting progress from algorithms.
Definition Progress.h:25
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:36
A class for holding :
Definition EventList.h:57
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
Structure describing a single-crystal peak.
Structure describing a single-crystal peak.
Definition Peak.h:34
ScanningWorkspaceBuilder : This is a helper class to make it easy to build a scanning workspace (a wo...
const IComponent * componentID(const size_t componentIndex) const
void setPos(double, double, double) override
Set the IComponent position, x, y, z respective to parent (if present)
This class represents a detector - i.e.
Definition Detector.h:30
Class to represent a particular goniometer setting, which is described by the rotation matrix.
Definition Goniometer.h:55
void makeUniversalGoniometer()
Make a default universal goniometer with phi,chi,omega angles according to SNS convention.
base class for Geometric IComponent
Definition IComponent.h:53
Parameter map iterator typedef.
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
size_t numRows() const
Return the number of rows in the matrix.
Definition Matrix.h:143
size_t numCols() const
Return the number of columns in the matrix.
Definition Matrix.h:146
This implements the Mersenne Twister 19937 pseudo-random number generator algorithm as a specialzatio...
double nextValue() override
Generate the next random number in the sequence within the given range default range.
OptionalBool : Tri-state bool.
The concrete, templated class for properties.
A specialised Property class for holding a series of time-value pairs.
void addValue(const Types::Core::DateAndTime &time, const TYPE &value)
Add a value to the map using a DateAndTime object.
Class for 3D vectors.
Definition V3D.h:35
constexpr double X() const noexcept
Get x.
Definition V3D.h:239
constexpr double Y() const noexcept
Get y.
Definition V3D.h:240
constexpr double Z() const noexcept
Get z.
Definition V3D.h:241
Implements a copy on write data template.
Definition cow_ptr.h:41
Mantid::Geometry::Instrument_sptr createCylInstrumentWithDetInGivenPositions(const std::vector< double > &L2, const std::vector< double > &polar, const std::vector< double > &azim)
create instrument with cylindrical detectors located in specific angular positions
Mantid::Geometry::Instrument_sptr createTestInstrumentCylindrical(int num_banks, const Mantid::Kernel::V3D &sourcePos=Mantid::Kernel::V3D(0.0, 0.0, -10.), const Mantid::Kernel::V3D &samplePos=Mantid::Kernel::V3D(), const double cylRadius=0.004, const double cylHeight=0.0002)
Create an test instrument with n panels of 9 cylindrical detectors, a source and a sample position.
Mantid::Geometry::Instrument_sptr createTestInstrumentRectangular2(int num_banks, int pixels, double pixelSpacing=0.008)
Create an test instrument with n panels of rectangular detectors, pixels*pixels in size,...
Mantid::Geometry::Instrument_sptr createTestInstrumentRectangular(int num_banks, int pixels, double pixelSpacing=0.008, double bankDistanceFromSample=5.0, bool addMonitor=false, const std::string &instrumentName="basic_rect")
Create a test instrument with n panels of rectangular detectors, pixels*pixels in size,...
void addMonitor(Mantid::Geometry::Instrument_sptr &instrument, const Mantid::Kernel::V3D &position, const int ID, const std::string &name)
Adds a monitor to an instrument.
void addSource(Mantid::Geometry::Instrument_sptr &instrument, const Mantid::Kernel::V3D &position, const std::string &name)
Adds a source to an instrument.
void addFullInstrumentToWorkspace(Mantid::API::MatrixWorkspace &workspace, bool includeMonitors, bool startYNegative, const std::string &instrumentName)
void addInstrumentWithGeographicalDetectorsToWorkspace(Mantid::API::MatrixWorkspace &workspace, const int nlat, const int nlong, const double anginc, const std::string &instrumentName)
void addSample(Mantid::Geometry::Instrument_sptr &instrument, const Mantid::Kernel::V3D &position, const std::string &name)
Adds a sample to an instrument.
Mantid::Geometry::Component * addComponent(Mantid::Geometry::Instrument_sptr &instrument, const Mantid::Kernel::V3D &position, const std::string &name)
Adds a component to an instrument.
void addDetector(Mantid::Geometry::Instrument_sptr &instrument, const Mantid::Kernel::V3D &position, const int ID, const std::string &name, Mantid::Geometry::ObjCompAssembly *compAss=nullptr)
Adds a detector to an instrument.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Definition Algorithm.h:52
static MatrixWorkspace_sptr createWorkspaceSingleValue(const double &rhsValue)
Creates a temporary single value workspace the error is set to zero.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix)
Get the number of events in the currently opened group.
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< LeanElasticPeaksWorkspace > LeanElasticPeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< WorkspaceSingleValue > WorkspaceSingleValue_sptr
shared pointer to the WorkspaceSingleValue class
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::shared_ptr< RebinnedOutput > RebinnedOutput_sptr
shared pointer to the RebinnedOutput class
Definition SumSpectra.h:23
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
std::size_t MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > &params, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.
std::map< detid_t, Geometry::IDetector_const_sptr > detid2det_map
Typedef of a map from detector ID to detector shared pointer.
Definition Instrument.h:28
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition cow_ptr.h:172
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWhereYIsWorkspaceIndex(int nhist, int numBoundaries)
Create a Workspace2D where the Y value at each bin is == to the workspace index.
Mantid::DataObjects::Workspace2D_sptr create1DWorkspaceConstant(int size, double value, double error, bool isHisto)
void setOrientedLattice(const Mantid::API::MatrixWorkspace_sptr &ws, double a, double b, double c)
Sets the OrientedLattice in the crystal as an crystal with given lattice lengths, angles of 90 deg.
void createInstrumentForWorkspaceWithDistances(const Mantid::API::MatrixWorkspace_sptr &workspace, const Mantid::Kernel::V3D &samplePosition, const Mantid::Kernel::V3D &sourcePosition, const std::vector< Mantid::Kernel::V3D > &detectorPositions)
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWithGeographicalDetectors(const int nlat, const int nlong, const double anginc, int nbins, const double x0=0.5, const double deltax=1.0, const std::string &instrumentName=std::string("testInst"), const std::string &xunit=std::string("Momentum"))
Create an Workspace2D with an instrument that contains detectors arranged at even latitude/longitude ...
Mantid::API::MatrixWorkspace_sptr create2DWorkspaceWithReflectometryInstrumentMultiDetector(const double startX=0.0, const double detSize=0.0, const Mantid::Kernel::V3D &slit1Pos=Mantid::Kernel::V3D(0, 0, 0), const Mantid::Kernel::V3D &slit2Pos=Mantid::Kernel::V3D(0, 0, 1), const double vg1=0.5, const double vg2=1.0, const Mantid::Kernel::V3D &sourcePos=Mantid::Kernel::V3D(0, 0, 0), const Mantid::Kernel::V3D &monitorPos=Mantid::Kernel::V3D(14, 0, 0), const Mantid::Kernel::V3D &samplePos=Mantid::Kernel::V3D(15, 0, 0), const Mantid::Kernel::V3D &detectorCenterPos=Mantid::Kernel::V3D(20,(20 - 15), 0), const int nSpectra=4, const int nBins=20, const double deltaX=5000.0)
Create a 2D workspace with one monitor and three detectors based around a virtual reflectometry instr...
void displayData(const Mantid::API::MatrixWorkspace_const_sptr &ws)
Mantid::API::MatrixWorkspace_sptr createProcessedInelasticWS(const std::vector< double > &L2, const std::vector< double > &polar, const std::vector< double > &azimutal, size_t numBins=4, double Emin=-10, double Emax=10, double Ei=11)
Create a workspace with all components needed for inelastic analysis and 3 detectors in specific plac...
Mantid::API::ITableWorkspace_sptr createEPPTableWorkspace(const std::vector< EPPTableRow > &rows={})
Create a table workspace corresponding to what the FindEPP algorithm gives.
void displayDataY(const Mantid::API::MatrixWorkspace_const_sptr &ws)
Mantid::DataObjects::WorkspaceSingleValue_sptr createWorkspaceSingleValueWithError(double value, double error)
void create2DAngles(std::vector< double > &L2, std::vector< double > &polar, std::vector< double > &azim, size_t nPolar=10, size_t nAzim=10, double polStart=0, double polEnd=90, double azimStart=-30, double azimEnd=30)
Mantid::DataObjects::Workspace2D_sptr create1DWorkspaceConstantWithXerror(int size, double value, double error, double xError, bool isHisto=true)
Mantid::API::MatrixWorkspace_sptr create2DWorkspaceRagged(int version=0)
Create a 2D ragged workspace.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceBinned(size_t nhist, size_t numVals, double x0=0.0, double deltax=1.0)
Create a 2D workspace with this many histograms and bins.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWithRectangularInstrument(int numBanks, int numPixels, int numBins, const std::string &instrumentName="basic_rect")
Create an Workspace2D with an instrument that contains RectangularDetector's.
void populateWsWithInitList(T &destination, size_t startingIndex, const std::initializer_list< double > &values)
Populates a mutable reference from initializer list starting at user specified index.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceNonUniformlyBinned(int nhist, const int numBoundaries, const double xBoundaries[], bool hasDx=false)
Create a 2D workspace with this many histograms and bins.
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspaceWithFullInstrument(int numBanks, int numPixels, bool clearEvents=true)
Create an Eventworkspace with an instrument that contains RectangularDetector's.
Mantid::DataObjects::Workspace2D_sptr create1DWorkspaceFib(int size, bool isHisto)
std::shared_ptr< Mantid::DataObjects::PeaksWorkspace > createPeaksWorkspace(const int numPeaks, const bool createOrientedLattice=false)
Create a simple peaks workspace containing the given number of peaks.
void addNoise(const Mantid::API::MatrixWorkspace_sptr &ws, double noise, const double lower=-0.5, const double upper=0.5)
Add random noise to a 2D workspace.
Mantid::DataObjects::EventWorkspace_sptr createGroupedEventWorkspace(std::vector< std::vector< int > > const &groups, int numBins, double binDelta=1., double xOffset=0.)
Create event workspace, with several detector IDs in one event list.
void removeWS(const std::string &name)
Deletes a workspace.
void displayDataE(const Mantid::API::MatrixWorkspace_const_sptr &ws)
Mantid::HistogramData::Histogram createHisto(bool isHistogram, YType &&yAxis, EType &&eAxis)
Creates and returns point or bin based histograms with the data specified in parameters.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWithValuesAndXerror(int64_t nHist, int64_t nBins, bool isHist, double xVal, double yVal, double eVal, double dxVal, const std::set< int64_t > &maskedWorkspaceIndices=std::set< int64_t >())
Mantid::API::WorkspaceGroup_sptr createWorkspaceGroup(int nEntries, int nHist, int nBins, const std::string &stem)
Create a WorkspaceGroup with N workspaces and the specified parameters.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspace154(int64_t nHist, int64_t nBins, bool isHist=false, const std::set< int64_t > &maskedWorkspaceIndices=std::set< int64_t >(), bool hasDx=false)
std::shared_ptr< Mantid::DataObjects::LeanElasticPeaksWorkspace > createLeanPeaksWorkspace(const int numPeaks, const bool createOrientedLattice=false)
Create a simple lean peaks workspace containing the given number of peaks.
Mantid::DataObjects::EventWorkspace_sptr createRandomEventWorkspace(size_t numbins, size_t numpixels, double bin_delta=1.0)
Create an event workspace with randomized TOF and pulsetimes.
Mantid::API::MatrixWorkspace_sptr create2DWorkspaceWithReflectometryInstrument(const double startX=0.0, const Mantid::Kernel::V3D &slit1Pos=Mantid::Kernel::V3D(0, 0, 0), const Mantid::Kernel::V3D &slit2Pos=Mantid::Kernel::V3D(0, 0, 1), const double vg1=0.5, const double vg2=1.0, const Mantid::Kernel::V3D &sourcePos=Mantid::Kernel::V3D(0, 0, 0), const Mantid::Kernel::V3D &monitorPos=Mantid::Kernel::V3D(14, 0, 0), const Mantid::Kernel::V3D &samplePos=Mantid::Kernel::V3D(15, 0, 0), const Mantid::Kernel::V3D &detectorPos=Mantid::Kernel::V3D(20,(20 - 15), 0), const int nBins=100, const double deltaX=2000.0)
Create a 2D workspace with one detector and one monitor based around a virtual reflectometry instrume...
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspaceWithStartTime(int numPixels, int numBins, int numEvents=100, double x0=0.0, double binDelta=1.0, int eventPattern=1, int start_at_pixelID=0, Mantid::Types::Core::DateAndTime run_start=Mantid::Types::Core::DateAndTime("2010-01-01T00:00:00"))
void addTSPEntry(Mantid::API::Run &runInfo, const std::string &name, double val)
Utility function to add a TimeSeriesProperty with a name and value.
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspace()
Create event workspace with: 500 pixels 1000 histogrammed bins.
Mantid::API::MatrixWorkspace_sptr createFocusedSNAPLiteInstrument(const std::string &wkspName, const std::string &groupingAlg, const std::string &groupingDescr, const double ang1=-65.3, const double ang2=104.95)
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspace3(const Mantid::DataObjects::EventWorkspace_const_sptr &sourceWS, const std::string &wsname, Mantid::API::Algorithm *alg)
Mantid::API::MatrixWorkspace_sptr create2DDetectorScanWorkspaceWithFullInstrument(int nhist, int nbins, size_t nTimeIndexes, size_t startTime=0, size_t firstInterval=1, bool includeMonitors=false, bool startYNegative=false, bool isHistogram=true, const std::string &instrumentName=std::string("testInst"))
Create a workspace as for create2DWorkspaceWithFullInstrument, but including time indexing,...
Mantid::API::MatrixWorkspace_sptr createSNAPLiteInstrument(const std::string &wkspName, const double ang1=-65.3, const double ang2=104.95)
Create a copy of the SNAP "lite" instrument.
Mantid::API::MatrixWorkspace_sptr createProcessedWorkspaceWithCylComplexInstrument(size_t numPixels=100, size_t numBins=20, bool has_oriented_lattice=true)
Mantid::DataObjects::Workspace2D_sptr create2DWorkspace123(int64_t nHist, int64_t nBins, bool isHist=false, const std::set< int64_t > &maskedWorkspaceIndices=std::set< int64_t >(), bool hasDx=false)
Mantid::DataObjects::Workspace2D_sptr maskSpectra(Mantid::DataObjects::Workspace2D_sptr workspace, const std::set< int64_t > &maskedWorkspaceIndices)
Workspace2D_sptr create2DWorkspaceWithValues(int64_t nHist, int64_t nBins, bool isHist, const std::set< int64_t > &maskedWorkspaceIndices, double xVal, double yVal, double eVal, bool hasDx=false)
create2DWorkspaceWithValues
DataObjects::Workspace2D_sptr reflectometryWorkspace(const double startX, const int nSpectra, const int nBins, const double deltaX)
Creates a binned 2DWorkspace with title and TOF x-axis and counts y-axis.
Mantid::DataObjects::RebinnedOutput_sptr createRebinnedOutputWorkspace()
Function to create a fixed RebinnedOutput workspace.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceThetaVsTOF(int nHist, int nBins)
Create a test workspace with a Theta numeric axis instead of a spectrum axis the values run from 1 to...
void displayDataX(const Mantid::API::MatrixWorkspace_const_sptr &ws)
Mantid::DataObjects::Workspace2D_sptr create1DWorkspaceRand(int size, bool isHisto)
Mantid::API::MatrixWorkspace_sptr createGroupedWorkspace2DWithRingsAndBoxes(size_t RootOfNumHist=10, int numBins=10, double binDelta=1.0)
Mantid::DataObjects::Workspace2D_sptr create2DWorkspace123WithMaskedBin(int numHist, int numBins, int maskedWorkspaceIndex, int maskedBinIndex)
void setGoniometer(const Mantid::API::MatrixWorkspace_sptr &ws, double phi, double chi, double omega)
Create a default universal goniometer and set its angles.
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspaceWithNonUniformInstrument(int numBanks, bool clearEvents)
Creates an event workspace with instrument which consists of cylindrical detectors.
const Mantid::Geometry::IComponent * baseInstrumentID(const Mantid::API::ExperimentInfo &expInfo)
The base instrument a workspace was built from, as identified by the root of its base ComponentInfo.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWithFullInstrument(int nhist, int nbins, bool includeMonitors=false, bool startYNegative=false, bool isHistogram=true, const std::string &instrumentName=std::string("testInst"), bool hasDx=false)
Create a test workspace with a fully defined instrument.
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspaceWithFullInstrument2(int numBanks, int numPixels, bool clearEvents=true)
Create an Eventworkspace with instrument 2.0 that contains RectangularDetector's.
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspace2(int numPixels=50, int numBins=100)
Create event workspace with: 50 pixels 100 histogrammed bins from 0.0 in steps of 1....
Mantid::DataObjects::Workspace2D_sptr create2DWorkspace(size_t nhist, size_t numBoundaries)
Mantid::API::MatrixWorkspace_sptr createGroupedWorkspace2D(size_t numHist, int numBins, double binDelta)
Create Workspace2d, with numHist spectra, each with 9 detectors, with IDs 1-9, 10-18,...
void eventWorkspace_Finalize(const Mantid::DataObjects::EventWorkspace_sptr &ew)
Perform some finalization on event workspace stuff.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspacePoints(size_t nhist, size_t numVals, double x0=0.0, double deltax=1.0)
Create a 2D workspace with this many point-histograms and bins.
Generate a tableworkspace to store the calibration results.
STL namespace.
EPPTableRow()=default
Construct a row with the default values.
FitStatus
FindEPP algorithm fitting success status.