51using Mantid::Types::Core::DateAndTime;
59namespace MDEventsTestHelper {
69 double binDelta = 10.0;
71 auto retVal = std::make_shared<EventWorkspace>();
72 retVal->initialize(numPixels + 2, 1, 1);
75 const std::string filename =
FileFinder::Instance().getFullPath(
"unit_testing/MINITOPAZ_Definition.xml");
77 auto instrument = parser.
parseXML(
nullptr);
78 retVal->populateInstrumentParameters();
79 retVal->setInstrument(instrument);
81 DateAndTime run_start(
"2010-01-01T00:00:00");
84 retVal->getSpectrum(0).addDetectorID(-1);
85 retVal->getSpectrum(1).addDetectorID(-2);
87 for (
int pix = 0; pix < numPixels; pix++) {
89 retVal->getSpectrum(pix + 2) += Types::Event::TofEvent((i + 0.5) * binDelta, run_start +
double(i));
91 retVal->getSpectrum(pix + 2).addDetectorID(pix);
95 HistogramData::BinEdges x1(numBins);
96 auto &xRef = x1.mutableData();
97 for (
int i = 0; i < numBins; ++i) {
98 xRef[i] = i * binDelta;
104 retVal->getAxis(0)->setUnit(
"TOF");
111 if (retVal->getInstrument()->getName() !=
"MINITOPAZ")
112 throw std::runtime_error(
"MDEventsTestHelper::"
113 "createDiffractionEventWorkspace(): Wrong "
114 "instrument loaded.");
116 retVal->getInstrument()->getDetectors(dets);
117 if (dets.size() != 100 * 100 + 2)
118 throw std::runtime_error(
"MDEventsTestHelper::"
119 "createDiffractionEventWorkspace(): Wrong "
141 ws1->setCoordinateSystem(coord);
142 ws1->getBoxController()->setSplitThreshold(100);
144 std::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(ws1));
145 FakeMD dataFaker(std::vector<double>(1,
static_cast<double>(
numEvents)), std::vector<double>(), std::vector<double>(),
177 splitter->setSplitThreshold(5);
179 splitter->setSplitInto(10);
180 splitter->setSplitInto(1, 5);
181 splitter->setSplitInto(2, 2);
184 for (
size_t d = 0;
d < 3; ++
d) {
195 std::vector<MDLeanEvent<1>> out;
197 for (std::size_t i = 0; i < num; ++i) {
198 float coords[1] = {
static_cast<float>(i) + 0.5f};
199 out.emplace_back(1.0f, 1.0f, coords);
218 coord_t max,
double errorSquared,
219 const std::string &name,
double numEvents) {
240 const std::string &name) {
241 std::vector<std::string> names{
"x",
"y",
"z",
"t"};
245 std::vector<Mantid::Geometry::MDHistoDimension_sptr> dimensions;
246 for (
size_t d = 0;
d < numDims;
d++)
247 dimensions.emplace_back(
251 ws_sptr->setTo(signal, errorSquared, 1.0 );
273 std::vector<std::string> names,
const std::string &name) {
274 std::vector<Mantid::Geometry::MDHistoDimension_sptr> dimensions;
277 for (
size_t d = 0;
d < numDims;
d++)
278 dimensions.emplace_back(
282 ws_sptr->setTo(signal, errorSquared, 1.0 );
304 size_t numBins,
coord_t max,
double errorSquared,
const std::string &name,
310 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins));
311 }
else if (numDims == 2) {
313 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins),
314 std::make_shared<MDHistoDimension>(
"y",
"y", frame, 0.0f, max, numBins));
315 }
else if (numDims == 3) {
317 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins),
318 std::make_shared<MDHistoDimension>(
"y",
"y", frame, 0.0f, max, numBins),
319 std::make_shared<MDHistoDimension>(
"z",
"z", frame, 0.0f, max, numBins));
320 }
else if (numDims == 4) {
322 std::make_shared<MDHistoWorkspace>(std::make_shared<MDHistoDimension>(
"x",
"x", frame, 0.0f, max, numBins),
323 std::make_shared<MDHistoDimension>(
"y",
"y", frame, 0.0f, max, numBins),
324 std::make_shared<MDHistoDimension>(
"z",
"z", frame, 0.0f, max, numBins),
325 std::make_shared<MDHistoDimension>(
"t",
"t", frame, 0.0f, max, numBins));
329 throw std::runtime_error(
" invalid or unsupported number of dimensions given");
331 ws_sptr->setTo(signal, errorSquared,
numEvents);
332 ws_sptr->addExperimentInfo(std::make_shared<ExperimentInfo>());
343 if (!filename.empty()) {
344 if (Poco::File(filename).
exists()) {
345 Poco::File(filename).remove();
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.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
bool exists(::NeXus::File &file, const std::string &name)
Based on the current group in the file, does the named sub-entry exist?
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.
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.