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
23#include "MantidAPI/Sample.h"
38#include "MantidHistogramData/HistogramDx.h"
39#include "MantidHistogramData/LinearGenerator.h"
40#include "MantidIndexing/IndexInfo.h"
45#include "MantidKernel/V3D.h"
48
49#include <cmath>
50#include <sstream>
51#include <utility>
52
54using namespace Mantid;
55using namespace Mantid::DataObjects;
56using namespace Mantid::Kernel;
57using namespace Mantid::API;
58using namespace Mantid::Geometry;
59using namespace Mantid::HistogramData;
62using Mantid::Types::Core::DateAndTime;
63using Mantid::Types::Event::TofEvent;
64
65StubAlgorithm::StubAlgorithm(size_t nSteps) : m_Progress(std::make_unique<API::Progress>(this, 0.0, 1.0, nSteps)) {}
66
67EPPTableRow::EPPTableRow(const double peakCentre_, const double sigma_, const double height_,
68 const FitStatus fitStatus_)
69 : peakCentre(peakCentre_), sigma(sigma_), height(height_), fitStatus(fitStatus_) {}
70
71EPPTableRow::EPPTableRow(const int index, const double peakCentre_, const double sigma_, const double height_,
72 const FitStatus fitStatus_)
73 : workspaceIndex(index), peakCentre(peakCentre_), sigma(sigma_), height(height_), fitStatus(fitStatus_) {}
74
79void removeWS(const std::string &name) { Mantid::API::AnalysisDataService::Instance().remove(name); }
80
93template <typename YType, typename EType> Histogram createHisto(bool isHistogram, YType &&yAxis, EType &&eAxis) {
94 // We don't need to check if y.size() == e.size() as the histogram
95 // type does this at construction
96 const size_t yValsSize = yAxis.size();
97 if (isHistogram) {
98 BinEdges xAxis(yValsSize + 1, LinearGenerator(1, 1));
99 Histogram histo{std::move(xAxis), std::forward<YType>(yAxis), std::forward<EType>(eAxis)};
100 return histo;
101 } else {
102 Points xAxis(yValsSize, LinearGenerator(1, 1));
103 Histogram pointsHisto{std::move(xAxis), std::forward<YType>(yAxis), std::forward<EType>(eAxis)};
104 return pointsHisto;
105 }
106}
107
109
110 MersenneTwister randomGen(DateAndTime::getCurrentTime().nanoseconds(), 0, std::numeric_limits<int>::max());
111
112 auto randFunc = [&randomGen] { return randomGen.nextValue(); };
113 Counts counts(size, randFunc);
114 CountStandardDeviations errorVals(size, randFunc);
115
116 auto retVal = std::make_shared<Workspace2D>();
117 retVal->initialize(1, createHisto(isHisto, counts, errorVals));
118 return retVal;
119}
120
121Workspace2D_sptr create1DWorkspaceConstant(int size, double value, double error, bool isHisto) {
122 Counts yVals(size, value);
123 CountStandardDeviations errVals(size, error);
124
125 auto retVal = std::make_shared<Workspace2D>();
126 retVal->initialize(1, createHisto(isHisto, yVals, errVals));
127 return retVal;
128}
129
130Workspace2D_sptr create1DWorkspaceConstantWithXerror(int size, double value, double error, double xError,
131 bool isHisto) {
132 auto ws = create1DWorkspaceConstant(size, value, error, isHisto);
133 auto dx1 = Kernel::make_cow<HistogramData::HistogramDx>(size, xError);
134 ws->setSharedDx(0, dx1);
135 return ws;
136}
137
138Workspace2D_sptr create1DWorkspaceFib(int size, bool isHisto) {
139 BinEdges xVals(size + 1, LinearGenerator(1, 1));
140 Counts yVals(size, FibSeries<double>());
141 CountStandardDeviations errVals(size);
142
143 auto retVal = std::make_shared<Workspace2D>();
144 retVal->initialize(1, createHisto(isHisto, yVals, errVals));
145 return retVal;
146}
147
148Workspace2D_sptr create2DWorkspace(size_t nhist, size_t numBoundaries) {
149 return create2DWorkspaceBinned(nhist, numBoundaries);
150}
151
159 Workspace2D_sptr out = create2DWorkspaceBinned(nhist, numBoundaries);
160 for (int workspaceIndex = 0; workspaceIndex < nhist; workspaceIndex++) {
161 std::vector<double> yValues(numBoundaries, static_cast<double>(workspaceIndex));
162 out->mutableY(workspaceIndex) = yValues;
163 }
164
165 return out;
166}
167
169
170 Workspace2D_sptr outputWS = create2DWorkspaceBinned(nHist, nBins);
171 auto newAxis = std::make_unique<NumericAxis>(nHist);
172 auto newAxisRaw = newAxis.get();
173 outputWS->replaceAxis(1, std::move(newAxis));
174 newAxisRaw->unit() = std::make_shared<Units::Degrees>();
175 for (int i = 0; i < nHist; ++i) {
176 newAxisRaw->setValue(i, i + 1);
177 }
178
179 return outputWS;
180}
181
196Workspace2D_sptr create2DWorkspaceWithValues(int64_t nHist, int64_t nBins, bool isHist,
197 const std::set<int64_t> &maskedWorkspaceIndices, double xVal, double yVal,
198 double eVal, bool hasDx = false) {
199 auto x1 = Kernel::make_cow<HistogramData::HistogramX>(isHist ? nBins + 1 : nBins, LinearGenerator(xVal, 1.0));
200 Counts y1(nBins, yVal);
201 CountStandardDeviations e1(nBins, eVal);
202 auto dx = Kernel::make_cow<HistogramData::HistogramDx>(nBins, yVal);
203 auto retVal = std::make_shared<Workspace2D>();
204 retVal->initialize(nHist, createHisto(isHist, y1, e1));
205 for (int i = 0; i < nHist; i++) {
206 retVal->setSharedX(i, x1);
207 if (hasDx)
208 retVal->setSharedDx(i, dx);
209 retVal->getSpectrum(i).setDetectorID(i);
210 retVal->getSpectrum(i).setSpectrumNo(i);
211 }
212 retVal = maskSpectra(retVal, maskedWorkspaceIndices);
213 return retVal;
214}
215
216Workspace2D_sptr create2DWorkspaceWithValuesAndXerror(int64_t nHist, int64_t nBins, bool isHist, double xVal,
217 double yVal, double eVal, double dxVal,
218 const std::set<int64_t> &maskedWorkspaceIndices) {
219 auto ws = create2DWorkspaceWithValues(nHist, nBins, isHist, maskedWorkspaceIndices, xVal, yVal, eVal);
220 PointStandardDeviations dx1(nBins, dxVal);
221 for (int i = 0; i < nHist; i++) {
222 ws->setPointStandardDeviations(i, dx1);
223 }
224 return ws;
225}
226
227Workspace2D_sptr create2DWorkspace123(int64_t nHist, int64_t nBins, bool isHist,
228 const std::set<int64_t> &maskedWorkspaceIndices, bool hasDx) {
229 return create2DWorkspaceWithValues(nHist, nBins, isHist, maskedWorkspaceIndices, 1.0, 2.0, 3.0, hasDx);
230}
231
232Workspace2D_sptr create2DWorkspace154(int64_t nHist, int64_t nBins, bool isHist,
233 const std::set<int64_t> &maskedWorkspaceIndices, bool hasDx) {
234 return create2DWorkspaceWithValues(nHist, nBins, isHist, maskedWorkspaceIndices, 1.0, 5.0, 4.0, hasDx);
235}
236
237Workspace2D_sptr maskSpectra(Workspace2D_sptr workspace, const std::set<int64_t> &maskedWorkspaceIndices) {
238 const auto nhist = static_cast<int>(workspace->getNumberHistograms());
239 if (workspace->getInstrument()->nelements() == 0) {
240 // We need detectors to be able to mask them.
241 auto instrument = std::make_shared<Instrument>();
242 workspace->setInstrument(instrument);
243
244 std::string xmlShape = "<sphere id=\"shape\"> ";
245 xmlShape += R"(<centre x="0.0" y="0.0" z="0.0" /> )";
246 xmlShape += "<radius val=\"0.05\" /> ";
247 xmlShape += "</sphere>";
248 xmlShape += "<algebra val=\"shape\" /> ";
249
250 ShapeFactory sFactory;
251 auto shape = sFactory.createShape(xmlShape);
252 for (int i = 0; i < nhist; ++i) {
253 Detector *det = new Detector("det", detid_t(i + 1), shape, nullptr);
254 det->setPos(i, i + 1, 1);
255 instrument->add(det);
256 instrument->markAsDetector(det);
257 }
258 workspace->setInstrument(instrument);
259 // Set IndexInfo without explicit spectrum definitions to trigger building
260 // default mapping of spectra to detectors in new instrument.
261 workspace->setIndexInfo(Indexing::IndexInfo(nhist));
262 }
263
264 auto &spectrumInfo = workspace->mutableSpectrumInfo();
265 for (const auto index : maskedWorkspaceIndices)
266 spectrumInfo.setMasked(index, true);
267 return workspace;
268}
269
273WorkspaceGroup_sptr createWorkspaceGroup(int nEntries, int nHist, int nBins, const std::string &stem) {
274 auto group = std::make_shared<WorkspaceGroup>();
275 AnalysisDataService::Instance().add(stem, group);
276 for (int i = 0; i < nEntries; ++i) {
277 Workspace2D_sptr ws = create2DWorkspace(nHist, nBins);
278 std::ostringstream os;
279 os << stem << "_" << i;
280 AnalysisDataService::Instance().add(os.str(), ws);
281 group->add(os.str());
282 }
283 return group;
284}
285
289Workspace2D_sptr create2DWorkspaceBinned(size_t nhist, size_t numVals, double x0, double deltax) {
290 BinEdges x(numVals + 1, LinearGenerator(x0, deltax));
291 Counts y(numVals, 2);
292 CountStandardDeviations e(numVals, M_SQRT2);
293 return create<Workspace2D>(nhist, Histogram(x, y, e));
294}
295
299Workspace2D_sptr create2DWorkspacePoints(size_t nhist, size_t numVals, double x0, double deltax) {
300 Points x(numVals, LinearGenerator(x0, deltax));
301 Counts y(numVals, 2);
302 CountStandardDeviations e(numVals, M_SQRT2);
303 return create<Workspace2D>(nhist, Histogram(x, y, e));
304}
305
312Workspace2D_sptr create2DWorkspaceNonUniformlyBinned(int nhist, const int numBoundaries, const double xBoundaries[],
313 bool hasDx) {
314 BinEdges x(xBoundaries, xBoundaries + numBoundaries);
315 const int numBins = numBoundaries - 1;
316 Counts y(numBins, 2);
317 CountStandardDeviations e(numBins, M_SQRT2);
318 auto dx = Kernel::make_cow<HistogramData::HistogramDx>(numBins, LinearGenerator(0.1, .1));
319 auto retVal = std::make_shared<Workspace2D>();
320 retVal->initialize(nhist, createHisto(true, y, e));
321 for (int i = 0; i < nhist; i++) {
322 retVal->setBinEdges(i, x);
323 if (hasDx)
324 retVal->setSharedDx(i, dx);
325 }
326 return retVal;
327}
328
336void addNoise(const Mantid::API::MatrixWorkspace_sptr &ws, double noise, const double lower, const double upper) {
337 const size_t seed(12345);
338 MersenneTwister randGen(seed, lower, upper);
339 for (size_t iSpec = 0; iSpec < ws->getNumberHistograms(); iSpec++) {
340 auto &mutableY = ws->mutableY(iSpec);
341 auto &mutableE = ws->mutableE(iSpec);
342 for (size_t i = 0; i < mutableY.size(); i++) {
343 mutableY[i] += noise * randGen.nextValue();
344 mutableE[i] += noise;
345 }
346 }
347}
348
355Workspace2D_sptr create2DWorkspaceWithFullInstrument(int nhist, int nbins, bool includeMonitors, bool startYNegative,
356 bool isHistogram, const std::string &instrumentName, bool hasDx) {
357 if (includeMonitors && nhist < 2) {
358 throw std::invalid_argument("Attempting to 2 include monitors for a "
359 "workspace with fewer than 2 histograms");
360 }
361
362 Workspace2D_sptr space;
363 // A 1:1 spectra is created by default
364 if (isHistogram)
365 space = create2DWorkspaceBinned(nhist, nbins, hasDx);
366 else
367 space = create2DWorkspace123(nhist, nbins, false, std::set<int64_t>(), hasDx);
368 // actually adds a property called run_title to the logs
369 space->setTitle("Test histogram");
370 space->getAxis(0)->setUnit("TOF");
371 space->setYUnit("Counts");
372
373 InstrumentCreationHelper::addFullInstrumentToWorkspace(*space, includeMonitors, startYNegative, instrumentName);
374
375 return space;
376}
377
378//================================================================================================================
379/*
380 * startTime is in seconds
381 */
383 size_t startTime, size_t firstInterval,
384 bool includeMonitors, bool startYNegative,
385 bool isHistogram,
386 const std::string &instrumentName) {
387
388 auto baseWS =
389 create2DWorkspaceWithFullInstrument(nhist, nbins, includeMonitors, startYNegative, isHistogram, instrumentName);
390
391 auto builder = ScanningWorkspaceBuilder(baseWS->getInstrument(), nTimeIndexes, nbins);
392
393 std::vector<double> timeRanges;
394 for (size_t i = 0; i < nTimeIndexes; ++i) {
395 timeRanges.emplace_back(double(i + firstInterval));
396 }
397
398 builder.setTimeRanges(DateAndTime(int(startTime), 0), timeRanges);
399
400 return builder.buildWorkspace();
401}
402
403//================================================================================================================
409Workspace2D_sptr create2DWorkspaceWithGeographicalDetectors(const int nlat, const int nlong, const double anginc,
410 const int nbins, const double x0, const double deltax,
411 const std::string &instrumentName,
412 const std::string &xunit) {
413 auto inputWorkspace = WorkspaceCreationHelper::create2DWorkspaceBinned(nlat * nlong, nbins, x0, deltax);
414 inputWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create(xunit);
415
417 instrumentName);
418
419 return inputWorkspace;
420}
421
422//================================================================================================================
433 int numBins) {
435 Workspace2D_sptr ws = create2DWorkspaceBinned(numBanks * numPixels * numPixels, numBins);
436 ws->setInstrument(inst);
437 ws->getAxis(0)->setUnit("dSpacing");
438 for (size_t wi = 0; wi < ws->getNumberHistograms(); wi++) {
439 ws->getSpectrum(wi).setDetectorID(detid_t(numPixels * numPixels + wi));
440 ws->getSpectrum(wi).setSpectrumNo(specnum_t(wi));
441 }
442
443 return ws;
444}
445
446//================================================================================================================
458 bool clearEvents) {
460 EventWorkspace_sptr ws = createEventWorkspace2(numBanks * numPixels * numPixels, 100);
461 ws->setInstrument(inst);
462
463 // Set the X axes
464 const auto &xVals = ws->x(0);
465 const size_t xSize = xVals.size();
466 auto ax0 = std::make_unique<NumericAxis>(xSize);
467 ax0->setUnit("dSpacing");
468 for (size_t i = 0; i < xSize; i++) {
469 ax0->setValue(i, xVals[i]);
470 }
471 ws->replaceAxis(0, std::move(ax0));
472
473 // re-assign detector IDs to the rectangular detector
474 const auto detIds = inst->getDetectorIDs();
475 for (int wi = 0; wi < static_cast<int>(ws->getNumberHistograms()); ++wi) {
476 ws->getSpectrum(wi).clearDetectorIDs();
477 if (clearEvents)
478 ws->getSpectrum(wi).clear(true);
479 ws->getSpectrum(wi).setDetectorID(detIds[wi]);
480 }
481 return ws;
482}
483
495 bool clearEvents) {
497 EventWorkspace_sptr ws = createEventWorkspace2(numBanks * numPixels * numPixels, 100);
498 ws->setInstrument(inst);
499
500 // Set the X axes
501 const auto &xVals = ws->x(0);
502 const size_t xSize = xVals.size();
503 auto ax0 = std::make_unique<NumericAxis>(xSize);
504 ax0->setUnit("dSpacing");
505 for (size_t i = 0; i < xSize; i++) {
506 ax0->setValue(i, xVals[i]);
507 }
508 ws->replaceAxis(0, std::move(ax0));
509
510 // re-assign detector IDs to the rectangular detector
511 const auto detIds = inst->getDetectorIDs();
512 for (int wi = 0; wi < static_cast<int>(ws->getNumberHistograms()); ++wi) {
513 ws->getSpectrum(wi).clearDetectorIDs();
514 if (clearEvents)
515 ws->getSpectrum(wi).clear(true);
516 ws->getSpectrum(wi).setDetectorID(detIds[wi]);
517 }
518 return ws;
519}
520
522 // Number of detectors in a bank as created by createTestInstrumentCylindrical
523 const int DETECTORS_PER_BANK(9);
524
525 V3D srcPos(0., 0., -10.), samplePos;
526 Instrument_sptr inst =
527 ComponentCreationHelper::createTestInstrumentCylindrical(numBanks, srcPos, samplePos, 0.0025, 0.005);
528 EventWorkspace_sptr ws = createEventWorkspace2(numBanks * DETECTORS_PER_BANK, 100);
529 ws->setInstrument(inst);
530
531 std::vector<detid_t> detectorIds = inst->getDetectorIDs();
532
533 // Should be equal if DETECTORS_PER_BANK is correct
534 assert(detectorIds.size() == ws->getNumberHistograms());
535
536 // Re-assign detector IDs
537 for (size_t wi = 0; wi < ws->getNumberHistograms(); wi++) {
538 ws->getSpectrum(wi).clearDetectorIDs();
539 if (clearEvents)
540 ws->getSpectrum(wi).clear(true);
541 ws->getSpectrum(wi).setDetectorID(detectorIds[wi]);
542 }
543
544 return ws;
545}
546
555DataObjects::Workspace2D_sptr reflectometryWorkspace(const double startX, const int nSpectra, const int nBins,
556 const double deltaX) {
557
558 auto workspace = create2DWorkspaceBinned(nSpectra, nBins, startX, deltaX);
559
560 workspace->setTitle("Test histogram"); // actually adds a property call run_title to the logs
561 workspace->getAxis(0)->setUnit("TOF");
562 workspace->setYUnit("Counts");
563 return workspace;
564}
565
582 const V3D &slit2Pos, const double vg1,
583 const double vg2, const V3D &sourcePos,
584 const V3D &monitorPos, const V3D &samplePos,
585 const V3D &detectorPos, const int nBins,
586 const double deltaX) {
587 Instrument_sptr instrument = std::make_shared<Instrument>();
588 instrument->setReferenceFrame(
589 std::make_shared<ReferenceFrame>(PointingAlong::Y, PointingAlong::X, Handedness::Left, "0,0,0"));
590
591 InstrumentCreationHelper::addSource(instrument, sourcePos, "source");
592 InstrumentCreationHelper::addMonitor(instrument, monitorPos, 1, "Monitor");
593 InstrumentCreationHelper::addSample(instrument, samplePos, "some-surface-holder");
594 InstrumentCreationHelper::addDetector(instrument, detectorPos, 2, "point-detector");
595 auto slit1 = InstrumentCreationHelper::addComponent(instrument, slit1Pos, "slit1");
596 auto slit2 = InstrumentCreationHelper::addComponent(instrument, slit2Pos, "slit2");
597
598 auto workspace = reflectometryWorkspace(startX, 2, nBins, deltaX);
599 workspace->setInstrument(instrument);
600
601 ParameterMap &pmap = workspace->instrumentParameters();
602 pmap.addDouble(slit1, "vertical gap", vg1);
603 pmap.addDouble(slit2, "vertical gap", vg2);
604
605 workspace->getSpectrum(0).setDetectorID(2);
606 workspace->getSpectrum(1).setDetectorID(1);
607
608 return workspace;
609}
610
630 const double startX, const double detSize, const V3D &slit1Pos, const V3D &slit2Pos, const double vg1,
631 const double vg2, const V3D &sourcePos, const V3D &monitorPos, const V3D &samplePos, const V3D &detectorCenterPos,
632 const int nSpectra, const int nBins, const double deltaX) {
633 Instrument_sptr instrument = std::make_shared<Instrument>();
634 instrument->setReferenceFrame(
635 std::make_shared<ReferenceFrame>(PointingAlong::Y /*up*/, PointingAlong::X /*along*/, Handedness::Left, "0,0,0"));
636
637 InstrumentCreationHelper::addSource(instrument, sourcePos, "source");
638 InstrumentCreationHelper::addSample(instrument, samplePos, "some-surface-holder");
639 InstrumentCreationHelper::addMonitor(instrument, monitorPos, 1, "Monitor");
640
641 const int nDet = nSpectra - 1;
642 const double minY = detectorCenterPos.Y() - detSize * (nDet - 1) / 2.;
643 for (int i = 0; i < nDet; ++i) {
644 const double y = minY + i * detSize;
645 const V3D pos{detectorCenterPos.X(), y, detectorCenterPos.Z()};
646 InstrumentCreationHelper::addDetector(instrument, pos, i + 2, "point-detector");
647 }
648 auto slit1 = InstrumentCreationHelper::addComponent(instrument, slit1Pos, "slit1");
649 auto slit2 = InstrumentCreationHelper::addComponent(instrument, slit2Pos, "slit2");
650
651 auto workspace = reflectometryWorkspace(startX, nSpectra, nBins, deltaX);
652 workspace->setInstrument(instrument);
653 ParameterMap &pmap = workspace->instrumentParameters();
654 pmap.addDouble(slit1, "vertical gap", vg1);
655 pmap.addDouble(slit2, "vertical gap", vg2);
656 for (int i = 0; i < nSpectra; ++i) {
657 workspace->getSpectrum(i).setDetectorID(i + 1);
658 }
659 return workspace;
660}
661
663 const V3D &sourcePosition, const std::vector<V3D> &detectorPositions) {
664 Instrument_sptr instrument = std::make_shared<Instrument>();
665 instrument->setReferenceFrame(std::make_shared<ReferenceFrame>(Y, X, Left, "0,0,0"));
666
667 InstrumentCreationHelper::addSource(instrument, sourcePosition, "source");
668 InstrumentCreationHelper::addSample(instrument, samplePosition, "sample");
669
670 for (int i = 0; i < static_cast<int>(detectorPositions.size()); ++i) {
671 std::stringstream buffer;
672 buffer << "detector_" << i;
673 InstrumentCreationHelper::addDetector(instrument, detectorPositions[i], i, buffer.str());
674
675 // Link it to the workspace
676 workspace->getSpectrum(i).addDetectorID(i);
677 }
678 workspace->setInstrument(instrument);
679}
680
681//================================================================================================================
683 return std::make_shared<WorkspaceSingleValue>(value, sqrt(value));
684}
685
687 return std::make_shared<WorkspaceSingleValue>(value, error);
688}
689
692 // get a proton charge
693 ew->mutableRun().integrateProtonCharge();
694}
695
701
708EventWorkspace_sptr createEventWorkspace2(int numPixels, int numBins) {
709 return createEventWorkspace(numPixels, numBins, 100, 0.0, 1.0, 2);
710}
711
714EventWorkspace_sptr createEventWorkspace(int numPixels, int numBins, int numEvents, double x0, double binDelta,
715 int eventPattern, int start_at_pixelID) {
716 return createEventWorkspaceWithStartTime(numPixels, numBins, numEvents, x0, binDelta, eventPattern, start_at_pixelID,
717 DateAndTime("2010-01-01T00:00:00"));
718}
719
723EventWorkspace_sptr createEventWorkspaceWithStartTime(int numPixels, int numBins, int numEvents, double x0,
724 double binDelta, int eventPattern, int start_at_pixelID,
725 DateAndTime run_start) {
726
727 // add one to the number of bins as this is histogram
728 numBins++;
729
730 auto retVal = std::make_shared<EventWorkspace>();
731 retVal->initialize(numPixels, 1, 1);
732
733 // Make fake events
734 if (eventPattern) // 0 == no events
735 {
736 size_t workspaceIndex = 0;
737 for (int pix = start_at_pixelID + 0; pix < start_at_pixelID + numPixels; pix++) {
738 EventList &el = retVal->getSpectrum(workspaceIndex);
739 el.setSpectrumNo(pix);
740 el.setDetectorID(pix);
741
742 for (int i = 0; i < numEvents; i++) {
743 if (eventPattern == 1) // 0, 1 diagonal pattern
744 el += TofEvent((pix + i + 0.5) * binDelta, run_start + double(i));
745 else if (eventPattern == 2) // solid 2
746 {
747 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
748 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
749 } else if (eventPattern == 3) // solid 1
750 {
751 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
752 } else if (eventPattern == 4) // Number of events per bin = pixelId (aka
753 // workspace index in most cases)
754 {
755 for (int q = 0; q < pix; q++)
756 el += TofEvent((i + 0.5) * binDelta, run_start + double(i));
757 }
758 }
759 workspaceIndex++;
760 }
761 }
762
763 retVal->setAllX(BinEdges(numBins, LinearGenerator(x0, binDelta)));
764
765 return retVal;
766}
767
768// =====================================================================================
771EventWorkspace_sptr createGroupedEventWorkspace(std::vector<std::vector<int>> groups, int numBins, double binDelta,
772 double xOffset) {
773
774 auto retVal = std::make_shared<EventWorkspace>();
775 retVal->initialize(groups.size(), 2, 1);
776
777 for (size_t g = 0; g < groups.size(); g++) {
778 retVal->getSpectrum(g).clearDetectorIDs();
779 std::vector<int> dets = groups[g];
780 for (auto det : dets) {
781 for (int i = 0; i < numBins; i++)
782 retVal->getSpectrum(g) += TofEvent((i + 0.5) * binDelta, 1);
783 retVal->getSpectrum(g).addDetectorID(det);
784 }
785 }
786
787 if (xOffset == 0.) {
788 retVal->setAllX(BinEdges(numBins, LinearGenerator(0.0, binDelta)));
789 } else {
790 for (size_t g = 0; g < groups.size(); g++) {
791 // Create the x-axis for histogramming.
792 const double x0 = xOffset * static_cast<double>(g);
793 retVal->setX(g, make_cow<HistogramX>(numBins, LinearGenerator(x0, binDelta)));
794 }
795 }
796
797 return retVal;
798}
799
800// =====================================================================================
808EventWorkspace_sptr createRandomEventWorkspace(size_t numbins, size_t numpixels, double bin_delta) {
809 auto retVal = std::make_shared<EventWorkspace>();
810 retVal->initialize(numpixels, numbins, numbins - 1);
811
812 // and X-axis for references:
813 auto pAxis0 = std::make_unique<NumericAxis>(numbins);
814 // Create the original X axis to histogram on.
815 // Create the x-axis for histogramming.
816 HistogramData::BinEdges axis(numbins, LinearGenerator(0.0, bin_delta));
817 for (int i = 0; i < static_cast<int>(numbins); ++i) {
818 pAxis0->setValue(i, axis[i]);
819 }
820 pAxis0->setUnit("TOF");
821
822 MersenneTwister randomGen(DateAndTime::getCurrentTime().nanoseconds(), 0, std::numeric_limits<int>::max());
823 // Make up some data for each pixels
824 for (size_t i = 0; i < numpixels; i++) {
825 // Create one event for each bin
826 EventList &events = retVal->getSpectrum(static_cast<detid_t>(i));
827 for (std::size_t ie = 0; ie < numbins; ie++) {
828 // Create a list of events, randomize
829 events += TofEvent(static_cast<double>(randomGen.nextValue()), static_cast<int64_t>(randomGen.nextValue()));
830 }
831 events.addDetectorID(detid_t(i));
832 }
833 retVal->setAllX(axis);
834 retVal->replaceAxis(0, std::move(pAxis0));
835
836 return retVal;
837}
838
839// =====================================================================================
843MatrixWorkspace_sptr createGroupedWorkspace2D(size_t numHist, int numBins, double binDelta) {
844 Workspace2D_sptr retVal = create2DWorkspaceBinned(static_cast<int>(numHist), numBins, 0.0, binDelta);
845 retVal->setInstrument(ComponentCreationHelper::createTestInstrumentCylindrical(static_cast<int>(numHist)));
846
847 for (int g = 0; g < static_cast<int>(numHist); g++) {
848 auto &spec = retVal->getSpectrum(g);
849 for (int i = 1; i <= 9; i++)
850 spec.addDetectorID(g * 9 + i);
851 spec.setSpectrumNo(g + 1); // Match detector ID and spec NO
852 }
853 return std::dynamic_pointer_cast<MatrixWorkspace>(retVal);
854}
855
856// =====================================================================================
857// RootOfNumHist == square root of hystohram number;
858MatrixWorkspace_sptr createGroupedWorkspace2DWithRingsAndBoxes(size_t RootOfNumHist, int numBins, double binDelta) {
859 size_t numHist = RootOfNumHist * RootOfNumHist;
860 Workspace2D_sptr retVal = create2DWorkspaceBinned(static_cast<int>(numHist), numBins, 0.0, binDelta);
861 retVal->setInstrument(ComponentCreationHelper::createTestInstrumentCylindrical(static_cast<int>(numHist)));
862 for (int g = 0; g < static_cast<int>(numHist); g++) {
863 auto &spec = retVal->getSpectrum(g);
864 spec.addDetectorID(g + 1); // Legacy comptibilty: Used to be default IDs in Workspace2D.
865 for (int i = 1; i <= 9; i++)
866 spec.addDetectorID(g * 9 + i);
867 spec.setSpectrumNo(g + 1); // Match detector ID and spec NO
868 }
869 return std::dynamic_pointer_cast<MatrixWorkspace>(retVal);
870}
871
872// not strictly creating a workspace, but really helpful to see what one
873// contains
875 const size_t numHists = ws->getNumberHistograms();
876 for (size_t i = 0; i < numHists; ++i) {
877 std::cout << "Histogram " << i << " = ";
878 const auto &y = ws->y(i);
879 for (size_t j = 0; j < y.size(); ++j) {
880 std::cout << y[j] << " ";
881 }
882 std::cout << '\n';
883 }
884}
886
887// not strictly creating a workspace, but really helpful to see what one
888// contains
890 const size_t numHists = ws->getNumberHistograms();
891 for (size_t i = 0; i < numHists; ++i) {
892 std::cout << "Histogram " << i << " = ";
893 const auto &x = ws->x(i);
894 for (size_t j = 0; j < x.size(); ++j) {
895 std::cout << x[j] << " ";
896 }
897 std::cout << '\n';
898 }
899}
900
901// not strictly creating a workspace, but really helpful to see what one
902// contains
904 const size_t numHists = ws->getNumberHistograms();
905 for (size_t i = 0; i < numHists; ++i) {
906 std::cout << "Histogram " << i << " = ";
907 const auto &e = ws->e(i);
908 for (size_t j = 0; j < e.size(); ++j) {
909 std::cout << e[j] << " ";
910 }
911 std::cout << '\n';
912 }
913}
914
915// =====================================================================================
922void addTSPEntry(Run &runInfo, const std::string &name, double val) {
924 tsp = new TimeSeriesProperty<double>(name);
925 tsp->addValue("2011-05-24T00:00:00", val);
926 runInfo.addProperty(tsp);
927}
928
929// =====================================================================================
938void setOrientedLattice(const Mantid::API::MatrixWorkspace_sptr &ws, double a, double b, double c) {
939 ws->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>(a, b, c, 90., 90., 90.));
940}
941
942// =====================================================================================
950void setGoniometer(const Mantid::API::MatrixWorkspace_sptr &ws, double phi, double chi, double omega) {
951 addTSPEntry(ws->mutableRun(), "phi", phi);
952 addTSPEntry(ws->mutableRun(), "chi", chi);
953 addTSPEntry(ws->mutableRun(), "omega", omega);
956 ws->mutableRun().setGoniometer(gm, true);
957}
958
959//
961 bool has_oriented_lattice) {
962 auto rHist = static_cast<size_t>(std::sqrt(static_cast<double>(numPixels)));
963 while (rHist * rHist < numPixels)
964 rHist++;
965
967 auto pAxis0 = std::make_unique<NumericAxis>(numBins);
968 for (size_t i = 0; i < numBins; i++) {
969 double dE = -1.0 + static_cast<double>(i) * 0.8;
970 pAxis0->setValue(i, dE);
971 }
972 pAxis0->setUnit("DeltaE");
973 ws->replaceAxis(0, std::move(pAxis0));
974 if (has_oriented_lattice) {
975 ws->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.));
976
977 addTSPEntry(ws->mutableRun(), "phi", 0);
978 addTSPEntry(ws->mutableRun(), "chi", 0);
979 addTSPEntry(ws->mutableRun(), "omega", 0);
982 ws->mutableRun().setGoniometer(gm, true);
983 }
984
985 return ws;
986}
987
998 const std::vector<double> &polar,
999 const std::vector<double> &azimutal, size_t numBins,
1000 double Emin, double Emax, double Ei) {
1001 // not used but interface needs it
1002 std::set<int64_t> maskedWorkspaceIndices;
1003 size_t numPixels = L2.size();
1004
1006 create2DWorkspaceWithValues(uint64_t(numPixels), uint64_t(numBins), true, maskedWorkspaceIndices, 0, 1, 0.1);
1007
1008 // detectors at L2, sample at 0 and source at -L2_min
1009 ws->setInstrument(ComponentCreationHelper::createCylInstrumentWithDetInGivenPositions(L2, polar, azimutal));
1010
1011 for (int g = 0; g < static_cast<int>(numPixels); g++) {
1012 auto &spec = ws->getSpectrum(g);
1013 // we just made (in createCylInstrumentWithDetInGivenPosisions) det ID-s to
1014 // start from 1
1015 spec.setDetectorID(g + 1);
1016 // and this is absolutely different nummer, corresponding to det ID just by
1017 // chance ? -- some uncertainties remain
1018 spec.setSpectrumNo(g + 1);
1019 // spec->setSpectrumNo(g+1);
1020 // spec->addDetectorID(g*9);
1021 // spec->setSpectrumNo(g+1); // Match detector ID and spec NO
1022 }
1023
1024 const double dE = (Emax - Emin) / static_cast<double>(numBins);
1025 for (size_t j = 0; j < numPixels; j++) {
1026 std::vector<double> E_transfer;
1027 E_transfer.reserve(numBins);
1028 for (size_t i = 0; i <= numBins; i++) {
1029 E_transfer.emplace_back(Emin + static_cast<double>(i) * dE);
1030 }
1031 ws->mutableX(j) = E_transfer;
1032 }
1033
1034 // set axis, correspondent to the X-values
1035 auto pAxis0 = std::make_unique<NumericAxis>(numBins);
1036 const auto &E_transfer = ws->x(0);
1037 for (size_t i = 0; i < numBins; i++) {
1038 double E = 0.5 * (E_transfer[i] + E_transfer[i + 1]);
1039 pAxis0->setValue(i, E);
1040 }
1041
1042 pAxis0->setUnit("DeltaE");
1043
1044 ws->replaceAxis(0, std::move(pAxis0));
1045
1046 // define oriented lattice which requested for processed ws
1047 ws->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.));
1048
1049 ws->mutableRun().addProperty(new PropertyWithValue<std::string>("deltaE-mode", "Direct"), true);
1050 ws->mutableRun().addProperty(new PropertyWithValue<double>("Ei", Ei), true);
1051 // these properties have to be different -> specific for processed ws, as time
1052 // now should be reconciled
1053 addTSPEntry(ws->mutableRun(), "phi", 0);
1054 addTSPEntry(ws->mutableRun(), "chi", 0);
1055 addTSPEntry(ws->mutableRun(), "omega", 0);
1058 ws->mutableRun().setGoniometer(gm, true);
1059
1060 return ws;
1061}
1062
1063/*
1064 * Create an EventWorkspace from a source EventWorkspace.
1065 * The new workspace should be exactly the same as the source workspace but
1066 * without any events
1067 */
1070 API::Algorithm *alg) {
1071 UNUSED_ARG(wsname);
1072 // 1. Initialize:use dummy numbers for arguments, for event workspace it
1073 // doesn't matter
1076 outputWS->initialize(sourceWS->getInstrument()->getDetectorIDs(true).size(), 1, 1);
1077
1078 // 2. Set the units
1079 outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
1080 outputWS->setYUnit("Counts");
1081 outputWS->setTitle("Empty_Title");
1082
1083 // 3. Add the run_start property:
1084 int runnumber = sourceWS->getRunNumber();
1085 outputWS->mutableRun().addProperty("run_number", runnumber);
1086
1087 std::string runstartstr = sourceWS->run().getProperty("run_start")->value();
1088 outputWS->mutableRun().addProperty("run_start", runstartstr);
1089
1090 // 4. Instrument
1091 Mantid::API::Algorithm_sptr loadInst = alg->createChildAlgorithm("LoadInstrument");
1092 // Now execute the Child Algorithm. Catch and log any error, but don't stop.
1093 loadInst->setPropertyValue("InstrumentName", sourceWS->getInstrument()->getName());
1094 loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", outputWS);
1095 loadInst->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(true));
1096 loadInst->executeAsChildAlg();
1097 // Populate the instrument parameters in this workspace - this works around a
1098 // bug
1099 outputWS->populateInstrumentParameters();
1100
1101 // 6. Build spectrum and event list
1102 // a) We want to pad out empty pixels.
1103 detid2det_map detector_map;
1104 outputWS->getInstrument()->getDetectors(detector_map);
1105
1106 // b) determine maximum pixel id
1107 detid2det_map::iterator it;
1108 detid_t detid_max = 0; // seems like a safe lower bound
1109 for (it = detector_map.begin(); it != detector_map.end(); ++it)
1110 if (it->first > detid_max)
1111 detid_max = it->first;
1112
1113 // c) Pad all the pixels and Set to zero
1114 size_t workspaceIndex = 0;
1115 const auto &detectorInfo = outputWS->detectorInfo();
1116 for (it = detector_map.begin(); it != detector_map.end(); ++it) {
1117 if (!detectorInfo.isMonitor(detectorInfo.indexOf(it->first))) {
1118 auto &spec = outputWS->getSpectrum(workspaceIndex);
1119 spec.addDetectorID(it->first);
1120 // Start the spectrum number at 1
1121 spec.setSpectrumNo(specnum_t(workspaceIndex + 1));
1122 workspaceIndex += 1;
1123 }
1124 }
1125
1126 return outputWS;
1127}
1128
1131 // outputWS->setName("rebinTest");
1132 Mantid::API::AnalysisDataService::Instance().add("rebinTest", outputWS);
1133
1134 // Set Q ('y') axis binning
1135 std::vector<double> qbins{0.0, 1.0, 4.0};
1136 std::vector<double> qaxis;
1137 const auto numY = static_cast<int>(VectorHelper::createAxisFromRebinParams(qbins, qaxis));
1138
1139 // Initialize the workspace
1140 const int numHist = numY - 1;
1141 const int numX = 7;
1142 outputWS->initialize(numHist, numX, numX - 1);
1143
1144 // Set the normal units
1145 outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("DeltaE");
1146 outputWS->setYUnit("Counts");
1147 outputWS->setTitle("Empty_Title");
1148
1149 // Create the i-axis for histogramming.
1150 HistogramData::BinEdges x1{-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0};
1151
1152 // Create a numeric axis to replace the default vertical one
1153 auto verticalAxis = std::make_unique<NumericAxis>(numY);
1154
1155 // Now set the axis values
1156 for (int i = 0; i < numHist; ++i) {
1157 outputWS->setBinEdges(i, x1);
1158 verticalAxis->setValue(i, qaxis[i]);
1159 }
1160 // One more to set on the 'y' axis
1161 verticalAxis->setValue(numHist, qaxis[numHist]);
1162
1163 // Set the 'y' axis units
1164 verticalAxis->unit() = UnitFactory::Instance().create("MomentumTransfer");
1165 verticalAxis->title() = "|Q|";
1166 outputWS->replaceAxis(1, std::move(verticalAxis));
1167
1168 // Set the X axis title (for conversion to MD)
1169 outputWS->getAxis(0)->title() = "Energy transfer";
1170
1171 // Now, setup the data
1172 // Q bin #1
1173
1174 // Populates destination starting at index 1 with the following data
1175 // e.g. y(0)[1] = 2.0, y(0)[2] = 3.0 ..etc. as the starting index is 1
1176 // if you change the values in the line below please update this comment!
1177 populateWsWithInitList(outputWS->mutableY(0), 1, {2.0, 3.0, 3.0, 2.0});
1178 populateWsWithInitList(outputWS->mutableE(0), 1, {2.0, 3.0, 3.0, 2.0});
1179 populateWsWithInitList(outputWS->dataF(0), 1, {2.0, 3.0, 3.0, 1.0});
1180
1181 // Q bin #2
1182 populateWsWithInitList(outputWS->mutableY(1), 1, {1.0, 3.0, 3.0, 2.0, 2.0});
1183 populateWsWithInitList(outputWS->mutableE(1), 1, {1.0, 3.0, 3.0, 2.0, 2.0});
1184 populateWsWithInitList(outputWS->dataF(1), 1, {1.0, 3.0, 3.0, 1.0, 2.0});
1185
1186 // Q bin #3
1187 populateWsWithInitList(outputWS->mutableY(2), 1, {1.0, 2.0, 3.0, 1.0});
1188 populateWsWithInitList(outputWS->mutableE(2), 1, {1.0, 2.0, 3.0, 1.0});
1189 populateWsWithInitList(outputWS->dataF(2), 1, {1.0, 2.0, 2.0, 1.0});
1190
1191 // Q bin #4
1192 populateWsWithInitList(outputWS->mutableY(3), 0, {1.0, 2.0, 3.0, 2.0, 1.0});
1193 populateWsWithInitList(outputWS->mutableE(3), 0, {1.0, 2.0, 3.0, 2.0, 1.0});
1194 populateWsWithInitList(outputWS->dataF(3), 0, {1.0, 2.0, 3.0, 2.0, 1.0, 1.0});
1195
1196 // Set representation
1197 outputWS->finalize();
1198
1199 // Make errors squared rooted and set sqrd err flag
1200 for (int i = 0; i < numHist; ++i) {
1201 auto &mutableE = outputWS->mutableE(i);
1202 for (int j = 0; j < numX - 1; ++j) {
1203 mutableE[j] = std::sqrt(mutableE[j]);
1204 }
1205 }
1206 outputWS->setSqrdErrors(false);
1207
1208 return outputWS;
1209}
1210
1223template <typename T>
1224void populateWsWithInitList(T &destination, size_t startingIndex, const std::initializer_list<double> &values) {
1225 size_t index = 0;
1226 for (const double val : values) {
1227 destination[startingIndex + index] = val;
1228 index++;
1229 }
1230}
1231
1232Mantid::DataObjects::PeaksWorkspace_sptr createPeaksWorkspace(const int numPeaks, const bool createOrientedLattice) {
1233 auto peaksWS = std::make_shared<PeaksWorkspace>();
1235 peaksWS->setInstrument(inst);
1236
1237 for (int i = 0; i < numPeaks; ++i) {
1238 Peak peak(inst, i, i + 0.5);
1239 peaksWS->addPeak(peak);
1240 }
1241
1242 if (createOrientedLattice) {
1243 peaksWS->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>());
1244 }
1245 return peaksWS;
1246}
1247
1249 const Mantid::Kernel::DblMatrix &ubMat) {
1250 if (ubMat.numRows() != 3 || ubMat.numCols() != 3) {
1251 throw std::invalid_argument("UB matrix is not 3x3");
1252 }
1253
1254 auto peaksWS = createPeaksWorkspace(numPeaks, true);
1255 peaksWS->mutableSample().getOrientedLattice().setUB(ubMat);
1256 return peaksWS;
1257}
1258
1259void create2DAngles(std::vector<double> &L2, std::vector<double> &polar, std::vector<double> &azim, size_t nPolar,
1260 size_t nAzim, double polStart, double polEnd, double azimStart, double azimEnd) {
1261 size_t nDet = nPolar * nAzim;
1262 L2.resize(nDet, 10);
1263 polar.resize(nDet);
1264 azim.resize(nDet);
1265
1266 double dPolar = (polEnd - polStart) / static_cast<double>(nDet - 1);
1267 double dAzim = (azimEnd - azimEnd) / static_cast<double>(nDet - 1);
1268 for (size_t i = 0; i < nPolar; i++) {
1269 for (size_t j = 0; j < nAzim; j++) {
1270 polar[i * nPolar + j] = polStart + dPolar * static_cast<double>(i);
1271 azim[i * nPolar + j] = azimStart + dAzim * static_cast<double>(j);
1272 }
1273 }
1274}
1275
1276ITableWorkspace_sptr createEPPTableWorkspace(const std::vector<EPPTableRow> &rows) {
1277 ITableWorkspace_sptr ws = std::make_shared<TableWorkspace>(rows.size());
1278 auto wsIndexColumn = ws->addColumn("int", "WorkspaceIndex");
1279 auto centreColumn = ws->addColumn("double", "PeakCentre");
1280 auto centreErrorColumn = ws->addColumn("double", "PeakCentreError");
1281 auto sigmaColumn = ws->addColumn("double", "Sigma");
1282 auto sigmaErrorColumn = ws->addColumn("double", "SigmaError");
1283 auto heightColumn = ws->addColumn("double", "Height");
1284 auto heightErrorColumn = ws->addColumn("double", "HeightError");
1285 auto chiSqColumn = ws->addColumn("double", "chiSq");
1286 auto statusColumn = ws->addColumn("str", "FitStatus");
1287 for (size_t i = 0; i != rows.size(); ++i) {
1288 const auto &row = rows[i];
1289 if (row.workspaceIndex < 0) {
1290 wsIndexColumn->cell<int>(i) = static_cast<int>(i);
1291 } else {
1292 wsIndexColumn->cell<int>(i) = row.workspaceIndex;
1293 }
1294 centreColumn->cell<double>(i) = row.peakCentre;
1295 centreErrorColumn->cell<double>(i) = row.peakCentreError;
1296 sigmaColumn->cell<double>(i) = row.sigma;
1297 sigmaErrorColumn->cell<double>(i) = row.sigmaError;
1298 heightColumn->cell<double>(i) = row.height;
1299 heightErrorColumn->cell<double>(i) = row.heightError;
1300 chiSqColumn->cell<double>(i) = row.chiSq;
1301 statusColumn->cell<std::string>(i) = row.fitStatus == EPPTableRow::FitStatus::SUCCESS ? "success" : "failed";
1302 }
1303 return ws;
1304}
1306 int maskedWorkspaceIndex, int maskedBinIndex) {
1307 auto ws = create2DWorkspace123(numHist, numBins);
1308 ws->flagMasked(maskedWorkspaceIndex, maskedBinIndex);
1309 return ws;
1310}
1311} // namespace WorkspaceCreationHelper
double value
The value of the point.
Definition: FitMW.cpp:51
double sigma
Definition: GetAllEi.cpp:156
double height
Definition: GetAllEi.cpp:155
double error
Definition: IndexPeaks.cpp:133
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
int nSpectra
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
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:85
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.
Definition: Algorithm.cpp:842
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 the spectrum number of this spectrum.
Definition: ISpectrum.cpp:127
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
Definition: LogManager.h:79
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:38
A class for holding :
Definition: EventList.h:56
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
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...
void setPos(double, double, double) override
Set the IComponent position, x, y, z respective to parent (if present)
Definition: Component.cpp:204
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.
Definition: Goniometer.cpp:271
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Definition: ShapeFactory.h:89
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:144
size_t numCols() const
Return the number of columns in the matrix.
Definition: Matrix.h:147
This implements the the Mersenne Twister 19937 pseudo-random number generator algorithm as a specialz...
double nextValue() override
Generate the next random number in the sequence within the given range default range.
OptionalBool : Tri-state bool.
Definition: OptionalBool.h:25
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
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:34
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
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 createTestInstrumentRectangular(int num_banks, int pixels, double pixelSpacing=0.008, double bankDistanceFromSample=5.0, bool addMonitor=false)
Create a test instrument with n panels of rectangular detectors, pixels*pixels in size,...
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,...
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:61
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, const NexusHDF5Descriptor &descriptor)
Get the number of events in the currently opened group.
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
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
int 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.
Definition: SpectrumInfo.h:21
std::map< detid_t, Geometry::IDetector_const_sptr > detid2det_map
Typedef of a map from detector ID to detector shared pointer.
Definition: Instrument.h:27
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:16
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.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWithRectangularInstrument(int numBanks, int numPixels, int numBins)
Create an Workspace2D with an instrument that contains RectangularDetector's.
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...
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::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.
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 the signalcreate2DWorkspaceWithFullInstrument.
Mantid::API::ITableWorkspace_sptr createEPPTableWorkspace(const std::vector< EPPTableRow > &rows)
Create a table workspace corresponding to what the FindEPP algorithm gives.
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)
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::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 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 createGroupedEventWorkspace(std::vector< std::vector< int > > groups, int numBins, double binDelta=1., double xOffset=0.)
Create event workspace, with several detector IDs in one event list.
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspaceWithNonUniformInstrument(int numBanks, bool clearEvents)
Creates an event workspace with instrument which consists of cylindrical detectors.
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.