50using Mantid::Types::Core::DateAndTime;
58namespace MDEventsTestHelper {
68 double binDelta = 10.0;
70 auto retVal = std::make_shared<EventWorkspace>();
71 retVal->initialize(numPixels + 2, 1, 1);
74 const std::string filename = FileFinder::Instance().getFullPath(
"unit_testing/MINITOPAZ_Definition.xml");
76 auto instrument = parser.
parseXML(
nullptr);
77 retVal->populateInstrumentParameters();
78 retVal->setInstrument(instrument);
80 DateAndTime run_start(
"2010-01-01T00:00:00");
83 retVal->getSpectrum(0).addDetectorID(-1);
84 retVal->getSpectrum(1).addDetectorID(-2);
86 for (
int pix = 0; pix < numPixels; pix++) {
88 retVal->getSpectrum(pix + 2) += Types::Event::TofEvent((i + 0.5) * binDelta, run_start +
double(i));
90 retVal->getSpectrum(pix + 2).addDetectorID(pix);
94 HistogramData::BinEdges x1(numBins);
95 auto &xRef = x1.mutableData();
96 for (
int i = 0; i < numBins; ++i) {
97 xRef[i] = i * binDelta;
103 retVal->getAxis(0)->setUnit(
"TOF");
110 if (retVal->getInstrument()->getName() !=
"MINITOPAZ")
111 throw std::runtime_error(
"MDEventsTestHelper::"
112 "createDiffractionEventWorkspace(): Wrong "
113 "instrument loaded.");
115 retVal->getInstrument()->getDetectors(dets);
116 if (dets.size() != 100 * 100 + 2)
117 throw std::runtime_error(
"MDEventsTestHelper::"
118 "createDiffractionEventWorkspace(): Wrong "
140 ws1->setCoordinateSystem(coord);
141 ws1->getBoxController()->setSplitThreshold(100);
142 API::AnalysisDataService::Instance().addOrReplace(wsName,
143 std::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(ws1));
144 FakeMD dataFaker(std::vector<double>(1,
static_cast<double>(
numEvents)), std::vector<double>(), std::vector<double>(),
147 return std::dynamic_pointer_cast<MDEventWorkspace3Lean>(API::AnalysisDataService::Instance().retrieve(wsName));
176 splitter->setSplitThreshold(5);
178 splitter->setSplitInto(10);
179 splitter->setSplitInto(1, 5);
180 splitter->setSplitInto(2, 2);
183 for (
size_t d = 0;
d < 3; ++
d) {
194 std::vector<MDLeanEvent<1>> out;
196 for (std::size_t i = 0; i < num; ++i) {
197 float coords[1] = {
static_cast<float>(i) + 0.5f};
198 out.emplace_back(1.0f, 1.0f, coords);
217 coord_t max,
double errorSquared,
239 const std::string &
name) {
240 std::vector<std::string> names{
"x",
"y",
"z",
"t"};
244 std::vector<Mantid::Geometry::MDHistoDimension_sptr> dimensions;
245 for (
size_t d = 0;
d < numDims;
d++)
246 dimensions.emplace_back(
250 ws_sptr->setTo(signal, errorSquared, 1.0 );
252 AnalysisDataService::Instance().addOrReplace(
name, ws_sptr);
272 std::vector<std::string> names,
const std::string &
name) {
273 std::vector<Mantid::Geometry::MDHistoDimension_sptr> dimensions;
276 for (
size_t d = 0;
d < numDims;
d++)
277 dimensions.emplace_back(
281 ws_sptr->setTo(signal, errorSquared, 1.0 );
283 AnalysisDataService::Instance().addOrReplace(
name, ws_sptr);
303 size_t numBins,
coord_t max,
double errorSquared,
const std::string &
name,
309 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins));
310 }
else if (numDims == 2) {
312 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins),
313 std::make_shared<MDHistoDimension>(
"y",
"y", frame, 0.0f, max, numBins));
314 }
else if (numDims == 3) {
316 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins),
317 std::make_shared<MDHistoDimension>(
"y",
"y", frame, 0.0f, max, numBins),
318 std::make_shared<MDHistoDimension>(
"z",
"z", frame, 0.0f, max, numBins));
319 }
else if (numDims == 4) {
321 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins),
322 std::make_shared<MDHistoDimension>(
"y",
"y", frame, 0.0f, max, numBins),
323 std::make_shared<MDHistoDimension>(
"z",
"z", frame, 0.0f, max, numBins),
324 std::make_shared<MDHistoDimension>(
"t",
"t", frame, 0.0f, max, numBins));
328 throw std::runtime_error(
" invalid or unsupported number of dimensions given");
330 ws_sptr->setTo(signal, errorSquared,
numEvents);
331 ws_sptr->addExperimentInfo(std::make_shared<ExperimentInfo>());
333 AnalysisDataService::Instance().addOrReplace(
name, ws_sptr);
342 if (!filename.empty()) {
343 if (std::filesystem::exists(filename)) {
344 std::filesystem::remove(filename);
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
void setSplitInto(size_t num)
Set the way splitting will be done.
void setSplitThreshold(size_t threshold)
Set the splitting threshold.
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
Provides a helper class to add fake data to an MD workspace.
void fill(const API::IMDEventWorkspace_sptr &workspace)
Add the fake data to the given workspace.
void setExtents(size_t dim, double min, double max)
Set the extents of this box.
Templated class for a multi-dimensional event "box".
std::shared_ptr< MDEventWorkspace< MDE, nd > > sptr
Typedef for a shared pointer of this kind of event workspace.
GeneralFrame : Any MDFrame that isn't related to momemtum transfer.
static const std::string GeneralFrameDistance
Creates an instrument data from a XML instrument description file.
std::shared_ptr< Instrument > parseXML(Kernel::ProgressBase *progressReporter)
Parse XML contents.
MDFrame : The coordinate frame for a dimension, or set of dimensions in a multidimensional workspace.
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.
MDBox< MDLeanEvent< 1 >, 1 > * makeMDBox1(size_t splitInto=10, API::BoxController *splitter=nullptr)
Generate an empty MDBox.
Mantid::DataObjects::EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents, int numPixels=400, int numBins=160)
Create an EventWorkspace containing fake data of single-crystal diffraction.
MDHistoWorkspace_sptr makeFakeMDHistoWorkspace(double signal, size_t numDims, size_t numBins=10, coord_t max=10.0, double errorSquared=1.0, const std::string &name="", double numEvents=1.0)
Make a fake n-dimensional MDHistoWorkspace.
std::vector< MDLeanEvent< 1 > > makeMDEvents1(size_t num)
Return a vector with this many MDEvents, spaced evenly from 0.5, 1.5, etc.
Mantid::DataObjects::MDHistoWorkspace_sptr makeFakeMDHistoWorkspaceGeneral(size_t numDims, double signal, double errorSquared, size_t *numBins, coord_t *min, coord_t *max, const std::string &name="")
More general fake n-dimensionsal MDHistoWorkspace.
MDBox< MDLeanEvent< 3 >, 3 > * makeMDBox3()
Generate an empty MDBox with 3 dimensions, split 10x5x2.
void checkAndDeleteFile(const std::string &filename)
Delete a file from disk.
MDEventWorkspace3Lean::sptr makeFakeMDEventWorkspace(const std::string &wsName, long numEvents=10000, Kernel::SpecialCoordinateSystem coord=Kernel::None)
Make a (optionally) file backed MDEventWorkspace with 10000 fake random data points.
Mantid::DataObjects::MDHistoWorkspace_sptr makeFakeMDHistoWorkspaceWithMDFrame(double signal, size_t numDims, const Mantid::Geometry::MDFrame &frame, size_t numBins=10, coord_t max=10.0, double errorSquared=1.0, const std::string &name="", double numEvents=1.0)
Creates a fake MDHistoWorkspace with MDFrame selection.
std::shared_ptr< MDHistoWorkspace > MDHistoWorkspace_sptr
A shared pointer to a MDHistoWorkspace.
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
Holds support functions for strings.
MANTID_KERNEL_DLL std::string loadFile(const std::string &filename)
Loads the entire contents of a text file into a string.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
std::map< detid_t, Geometry::IDetector_const_sptr > detid2det_map
Typedef of a map from detector ID to detector shared pointer.
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 setGoniometer(const Mantid::API::MatrixWorkspace_sptr &ws, double phi, double chi, double omega)
Create a default universal goniometer and set its angles.