Mantid
Loading...
Searching...
No Matches
CreateSampleWorkspace.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 +
8#include "MantidAPI/Axis.h"
12#include "MantidAPI/Run.h"
13#include "MantidAPI/Sample.h"
21#include "MantidHistogramData/LinearGenerator.h"
22#include "MantidIndexing/IndexInfo.h"
27#include "MantidTypes/SpectrumDefinition.h"
28
29#include <algorithm>
30#include <cmath>
31#include <ctime>
32#include <iterator>
33#include <numeric>
34#include <stdexcept>
35
36namespace Mantid::Algorithms {
37using namespace Kernel;
38using namespace API;
39using namespace Geometry;
40using namespace DataObjects;
41using namespace HistogramData;
42using namespace Indexing;
45using Types::Core::DateAndTime;
46using Types::Event::TofEvent;
47
48// Register the algorithm into the AlgorithmFactory
49DECLARE_ALGORITHM(CreateSampleWorkspace)
50
51
54
56const std::string CreateSampleWorkspace::name() const { return "CreateSampleWorkspace"; }
57
59int CreateSampleWorkspace::version() const { return 1; }
60
62const std::string CreateSampleWorkspace::category() const { return "Utility\\Workspaces"; }
63
67 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
68 "An output workspace.");
69 std::vector<std::string> typeOptions{"Histogram", "Event"};
70 declareProperty("WorkspaceType", "Histogram", std::make_shared<StringListValidator>(typeOptions),
71 "The type of workspace to create (default: Histogram)");
72
73 // pre-defined function strings these use $PCx$ to define peak centres values
74 // that will be replaced before use
75 //$PC0$ is the far left of the data, and $PC10$ is the far right, and
76 // therefore will often not be used
77 //$PC5$ is the centre of the data
78 m_preDefinedFunctionmap.emplace("One Peak", "name=LinearBackground, A0=0.3; name=Gaussian, "
79 "PeakCentre=$PC5$, Height=10, Sigma=0.7;");
80 m_preDefinedFunctionmap.emplace("Multiple Peaks", "name=LinearBackground, A0=0.3;name=Gaussian, "
81 "PeakCentre=$PC3$, Height=10, Sigma=0.7;name=Gaussian, "
82 "PeakCentre=$PC6$, Height=8, Sigma=0.5");
83 m_preDefinedFunctionmap.emplace("Flat background", "name=LinearBackground, A0=1;");
84 m_preDefinedFunctionmap.emplace("Exp Decay", "name=ExpDecay, Height=100, Lifetime=1000;");
85 m_preDefinedFunctionmap.emplace("Powder Diffraction", "name= LinearBackground,A0=0.0850208,A1=-4.89583e-06;"
86 "name=Gaussian,Height=0.584528,PeakCentre=$PC1$,Sigma=14.3772;"
87 "name=Gaussian,Height=1.33361,PeakCentre=$PC2$,Sigma=15.2516;"
88 "name=Gaussian,Height=1.74691,PeakCentre=$PC3$,Sigma=15.8395;"
89 "name=Gaussian,Height=0.950388,PeakCentre=$PC4$,Sigma=19.8408;"
90 "name=Gaussian,Height=1.92185,PeakCentre=$PC5$,Sigma=18.0844;"
91 "name=Gaussian,Height=3.64069,PeakCentre=$PC6$,Sigma=19.2404;"
92 "name=Gaussian,Height=2.8998,PeakCentre=$PC7$,Sigma=21.1127;"
93 "name=Gaussian,Height=2.05237,PeakCentre=$PC8$,Sigma=21.9932;"
94 "name=Gaussian,Height=8.40976,PeakCentre=$PC9$,Sigma=25.2751;");
95 m_preDefinedFunctionmap.emplace("Quasielastic", "name=Lorentzian,FWHM=0.3,PeakCentre=$PC5$,Amplitude=0.8;"
96 "name=Lorentzian,FWHM=0.1,PeakCentre=$PC5$,Amplitude=1;"
97 "name=LinearBackground,A0=0.1");
98 m_preDefinedFunctionmap.emplace("Quasielastic Tunnelling",
99 "name=LinearBackground,A0=0.1;"
100 "name=Lorentzian,FWHM=0.1,PeakCentre=$PC5$,Amplitude=1;"
101 "name=Lorentzian,FWHM=0.05,PeakCentre=$PC7$,Amplitude=0.04;"
102 "name=Lorentzian,FWHM=0.05,PeakCentre=$PC3$,Amplitude=0.04;"
103 "name=Lorentzian,FWHM=0.05,PeakCentre=$PC8$,Amplitude=0.02;"
104 "name=Lorentzian,FWHM=0.05,PeakCentre=$PC2$,Amplitude=0.02");
105 m_preDefinedFunctionmap.emplace("User Defined", "");
106 std::vector<std::string> functionOptions;
107 functionOptions.reserve(m_preDefinedFunctionmap.size());
108 std::transform(m_preDefinedFunctionmap.cbegin(), m_preDefinedFunctionmap.cend(), std::back_inserter(functionOptions),
109 [](const auto &preDefinedFunction) { return preDefinedFunction.first; });
110 declareProperty("Function", "One Peak", std::make_shared<StringListValidator>(functionOptions),
111 "Preset options of the data to fill the workspace with");
112 declareProperty("UserDefinedFunction", "", "Parameters defining the fitting function and its initial values");
113
114 declareProperty("XUnit", "TOF", "The unit to assign to the XAxis (default:\"TOF\")");
115 declareProperty("XMin", 0.0, "The minimum X axis value (default:0)");
116 declareProperty("XMax", 20000.0, "The maximum X axis value (default:20000)");
117 declareProperty("BinWidth", 200.0, std::make_shared<BoundedValidator<double>>(0, 100000, true),
118 "The bin width of the X axis (default:200)");
119 declareProperty("NumEvents", 1000, std::make_shared<BoundedValidator<int>>(0, 100000),
120 "The number of events per detector, this is only used for "
121 "EventWorkspaces (default:1000)");
122 declareProperty("Random", false, "Whether to randomise the placement of events and data (default:false)");
123
124 declareProperty("NumScanPoints", 1, std::make_shared<BoundedValidator<int>>(0, 360, true),
125 "Add a number of time indexed detector scan points to the "
126 "instrument. The detectors are rotated in 1 degree "
127 "increments around the the sample position in the x-z plane. "
128 "Minimum (default) is 1 scan point, which gives a "
129 "non-scanning workspace.");
130
131 declareProperty("InstrumentName", "basic_rect", Direction::Input);
132 declareProperty("NumBanks", 2, std::make_shared<BoundedValidator<int>>(0, 100),
133 "The Number of banks in the instrument (default:2)");
134 declareProperty("NumMonitors", 0, std::make_shared<BoundedValidator<int>>(0, 100),
135 "The number of monitors in the instrument (default:0)");
136 declareProperty("BankPixelWidth", 10, std::make_shared<BoundedValidator<int>>(0, 10000),
137 "The number of pixels in horizontally and vertically in a "
138 "bank (default:10)");
139
140 declareProperty("PixelDiameter", 0.008, std::make_shared<BoundedValidator<double>>(0, 0.1),
141 "Length in meters of one side of a pixel assumed to be square");
142
143 declareProperty("PixelHeight", 0.0002, std::make_shared<BoundedValidator<double>>(0, 0.1),
144 "Height in meters of the pixel");
145
146 declareProperty("PixelSpacing", 0.008, std::make_shared<BoundedValidator<double>>(0, 100000, true),
147 "Distance between the center of adjacent pixels in a uniform grid "
148 "(default: 0.008 meters)");
149
150 declareProperty("BankDistanceFromSample", 5.0, std::make_shared<BoundedValidator<double>>(0, 1000, true),
151 "The distance along the beam direction from the sample to "
152 "bank in meters (default:5.0)");
153 declareProperty("SourceDistanceFromSample", 10.0, std::make_shared<BoundedValidator<double>>(0, 1000, true),
154 "The distance along the beam direction from the source to "
155 "the sample in meters (default:10.0)");
156
157 /* Aggregate properties in groups */
158 std::string instrumentGroupName = "Instrument";
159 setPropertyGroup("InstrumentName", instrumentGroupName);
160 setPropertyGroup("NumMonitors", instrumentGroupName);
161 setPropertyGroup("BankDistanceFromSample", instrumentGroupName);
162 setPropertyGroup("SourceDistanceFromSample", instrumentGroupName);
163 setPropertyGroup("NumBanks", instrumentGroupName);
164 setPropertyGroup("BankPixelWidth", instrumentGroupName);
165 setPropertyGroup("PixelDiameter", instrumentGroupName);
166 setPropertyGroup("PixelHeight", instrumentGroupName);
167 setPropertyGroup("PixelSpacing", instrumentGroupName);
168}
169
170//----------------------------------------------------------------------------------------------
174 const std::string wsType = getProperty("WorkspaceType");
175 const std::string preDefinedFunction = getProperty("Function");
176 const std::string userDefinedFunction = getProperty("UserDefinedFunction");
177 const std::string instrName = getPropertyValue("InstrumentName");
178 const int numBanks = getProperty("NumBanks");
179 const int numMonitors = getProperty("NumMonitors");
180 const int bankPixelWidth = getProperty("BankPixelWidth");
181 const int numEvents = getProperty("NumEvents");
182 const bool isRandom = getProperty("Random");
183 const std::string xUnit = getProperty("XUnit");
184 const double xMin = getProperty("XMin");
185 const double xMax = getProperty("XMax");
186 double binWidth = getProperty("BinWidth");
187 const double pixelDiameter = getProperty("PixelDiameter");
188 const double pixelHeight = getProperty("PixelHeight");
189 const double pixelSpacing = getProperty("PixelSpacing");
190 const double bankDistanceFromSample = getProperty("BankDistanceFromSample");
191 const double sourceSampleDistance = getProperty("SourceDistanceFromSample");
192 const int numScanPoints = getProperty("NumScanPoints");
193
194 if (xMax <= xMin) {
195 throw std::invalid_argument("XMax must be larger than XMin");
196 }
197
198 if (pixelSpacing < pixelDiameter) {
199 g_log.error() << "PixelSpacing (the distance between pixel centers in the uniform grid)"
200 "is smaller than the PixelDiameter (square pixel dimension)"
201 << '\n';
202 throw std::invalid_argument("PixelSpacing must be at least as large as pixelDiameter");
203 }
204
205 if (binWidth > (xMax - xMin)) {
206 // the bin width is so large that there is less than one bin - so adjust it
207 // down
208 binWidth = xMax - xMin;
209 g_log.warning() << "The bin width is so large that there is less than one "
210 "bin - it has been changed to "
211 << binWidth << '\n';
212 }
213
214 std::string functionString;
215 if (m_preDefinedFunctionmap.find(preDefinedFunction) != m_preDefinedFunctionmap.end()) {
216 // extract pre-defined string
217 functionString = m_preDefinedFunctionmap[preDefinedFunction];
218 }
219 if (functionString.empty()) {
220 functionString = userDefinedFunction;
221 }
222
223 if (!m_randGen) {
224 int seedValue = 0;
225 if (isRandom) {
226 seedValue = static_cast<int>(std::time(nullptr));
227 }
228 m_randGen = std::make_unique<Kernel::MersenneTwister>(seedValue);
229 }
230
231 int numPixels = numBanks * bankPixelWidth * bankPixelWidth;
232
233 Progress progress(this, 0.0, 1.0, numBanks);
234
235 // Create an instrument with one or more rectangular banks.
236 Instrument_sptr inst =
237 createTestInstrumentRectangular(progress, numBanks, numMonitors, bankPixelWidth, pixelDiameter, pixelHeight,
238 pixelSpacing, bankDistanceFromSample, sourceSampleDistance, instrName);
239
240 auto numBins = static_cast<int>((xMax - xMin) / binWidth);
241
243 if (wsType == "Event") {
244 ws = createEventWorkspace(numPixels, numBins, numMonitors, numEvents, xMin, binWidth, inst, functionString,
245 isRandom);
246 } else if (numScanPoints > 1) {
247 ws = createScanningWorkspace(numBins, xMin, binWidth, inst, functionString, isRandom, numScanPoints);
248 } else {
249 ws = createHistogramWorkspace(numPixels, numBins, numMonitors, xMin, binWidth, inst, functionString, isRandom);
250 }
251 // add chopper
252 this->addChopperParameters(ws);
253
254 // Set the Unit of the X Axis
255 try {
256 ws->getAxis(0)->unit() = UnitFactory::Instance().create(xUnit);
257 } catch (Exception::NotFoundError &) {
258 ws->getAxis(0)->unit() = UnitFactory::Instance().create("Label");
259 Unit_sptr unit = ws->getAxis(0)->unit();
260 std::shared_ptr<Units::Label> label = std::dynamic_pointer_cast<Units::Label>(unit);
261 label->setLabel(xUnit, xUnit);
262 }
263
264 auto sampleSphere = createSphere(0.001, V3D(0.0, 0.0, 0.0), "sample-shape");
265 ws->mutableSample().setShape(sampleSphere);
266
267 ws->setYUnit("Counts");
268 ws->setTitle("Test Workspace");
269 DateAndTime run_start("2010-01-01T00:00:00");
270 DateAndTime run_end("2010-01-01T01:00:00");
271 Run &theRun = ws->mutableRun();
272 // belt and braces use both approaches for setting start and end times
273 theRun.setStartAndEndTime(run_start, run_end);
274 theRun.addLogData(new PropertyWithValue<std::string>("run_start", run_start.toISO8601String()));
275 theRun.addLogData(new PropertyWithValue<std::string>("run_end", run_end.toISO8601String()));
276
277 // Assign it to the output workspace property
278 setProperty("OutputWorkspace", ws);
279 ;
280}
288
289 auto testInst = ws->getInstrument();
290 auto chopper = testInst->getComponentByName("chopper-position");
291
292 // add chopper parameters
293 auto &paramMap = ws->instrumentParameters();
294 const std::string description("The initial rotation phase of the disk used to calculate the time"
295 " for neutrons arriving at the chopper according to the formula time = "
296 "delay + initial_phase/Speed");
297 paramMap.add<double>("double", chopper.get(), "initial_phase", -3000., &description);
298 paramMap.add<std::string>("string", chopper.get(), "ChopperDelayLog", "fermi_delay");
299 paramMap.add<std::string>("string", chopper.get(), "ChopperSpeedLog", "fermi_speed");
300 paramMap.add<std::string>("string", chopper.get(), "FilterBaseLog", "is_running");
301 paramMap.add<bool>("bool", chopper.get(), "filter_with_derivative", false);
302}
303
307 double x0, double binDelta,
308 const Geometry::Instrument_sptr &inst,
309 const std::string &functionString, bool isRandom) {
310 BinEdges x(numBins + 1, LinearGenerator(x0, binDelta));
311 Points xValues(x);
312
313 Counts y(evalFunction(functionString, xValues.rawData(), isRandom ? 1 : 0));
314
315 std::vector<SpectrumDefinition> specDefs(numPixels + numMonitors);
316 for (int wi = 0; wi < numMonitors + numPixels; wi++)
317 specDefs[wi].add(wi < numMonitors ? numPixels + wi : wi - numMonitors);
318 Indexing::IndexInfo indexInfo(numPixels + numMonitors);
319 indexInfo.setSpectrumDefinitions(std::move(specDefs));
320
321 return create<Workspace2D>(inst, indexInfo, Histogram(x, y));
322}
323
327 const Geometry::Instrument_sptr &inst,
328 const std::string &functionString, bool isRandom,
329 int numScanPoints) {
330 auto builder = ScanningWorkspaceBuilder(inst, numScanPoints, numBins);
331
332 auto angles = std::vector<double>();
333 auto timeRanges = std::vector<double>();
334 for (int i = 0; i < numScanPoints; ++i) {
335 angles.emplace_back(double(i));
336 timeRanges.emplace_back(double(i + 1));
337 }
338
339 builder.setTimeRanges(Types::Core::DateAndTime(0), timeRanges);
340 builder.setRelativeRotationsForScans(angles, inst->getSample()->getPos(), V3D(0, 1, 0));
341
342 BinEdges x(numBins + 1, LinearGenerator(x0, binDelta));
343
344 std::vector<double> xValues(cbegin(x), cend(x) - 1);
345 Counts y(evalFunction(functionString, xValues, isRandom ? 1 : 0));
346
347 builder.setHistogram(Histogram(x, y));
348
349 return builder.buildWorkspace();
350}
351
354EventWorkspace_sptr CreateSampleWorkspace::createEventWorkspace(int numPixels, int numBins, int numMonitors,
355 int numEvents, double x0, double binDelta,
356 const Geometry::Instrument_sptr &inst,
357 const std::string &functionString, bool isRandom) {
358 DateAndTime run_start("2010-01-01T00:00:00");
359
360 std::vector<SpectrumDefinition> specDefs(numPixels + numMonitors);
361 for (int wi = 0; wi < numMonitors + numPixels; wi++)
362 specDefs[wi].add(wi < numMonitors ? numPixels + wi : wi - numMonitors);
363 Indexing::IndexInfo indexInfo(numPixels + numMonitors);
364 indexInfo.setSpectrumDefinitions(std::move(specDefs));
365
366 // add one to the number of bins as this is histogram
367 int numXBins = numBins + 1;
368 BinEdges x(numXBins, LinearGenerator(x0, binDelta));
369
370 auto retVal = create<EventWorkspace>(inst, indexInfo, x);
371
372 std::vector<double> xValues(x.cbegin(), x.cend() - 1);
373 std::vector<double> yValues = evalFunction(functionString, xValues, isRandom ? 1 : 0);
374
375 // we need to normalise the results and then multiply by the number of events
376 // to find the events per bin
377 double sum_of_elems = std::accumulate(yValues.begin(), yValues.end(), 0.0);
378 double event_distrib_factor = numEvents / sum_of_elems;
379 using std::placeholders::_1;
380 std::transform(yValues.begin(), yValues.end(), yValues.begin(),
381 std::bind(std::multiplies<double>(), event_distrib_factor, _1));
382 // the array should now contain the number of events required per bin
383
384 // Make fake events
385 size_t workspaceIndex = 0;
386
387 const double hourInSeconds = 60 * 60;
388 for (int wi = 0; wi < numPixels + numMonitors; wi++) {
389 EventList &el = retVal->getSpectrum(workspaceIndex);
390 for (int i = 0; i < numBins; ++i) {
391 // create randomised events within the bin to match the number required -
392 // calculated in yValues earlier
393 auto eventsInBin = static_cast<int>(yValues[i]);
394 for (int q = 0; q < eventsInBin; q++) {
395 DateAndTime pulseTime = run_start + (m_randGen->nextValue() * hourInSeconds);
396 el += TofEvent((i + m_randGen->nextValue()) * binDelta + x0, pulseTime);
397 }
398 }
399 workspaceIndex++;
400 }
401
402 return retVal;
403}
404//----------------------------------------------------------------------------------------------
415std::vector<double> CreateSampleWorkspace::evalFunction(const std::string &functionString,
416 const std::vector<double> &xVal, double noiseScale = 0) {
417 size_t xSize = xVal.size();
418 // replace $PCx$ values
419 std::string parsedFuncString = functionString;
420 for (int x = 0; x <= 10; ++x) {
421 // get the rough peak centre value
422 auto index = static_cast<int>((xSize / 10) * x);
423 if ((x == 10) && (index > 0))
424 --index;
425 double replace_val = xVal[index];
426 std::ostringstream tokenStream;
427 tokenStream << "$PC" << x << "$";
428 std::string token = tokenStream.str();
429 std::string replaceStr = boost::lexical_cast<std::string>(replace_val);
430 replaceAll(parsedFuncString, token, replaceStr);
431 }
432 g_log.information(parsedFuncString);
433
434 IFunction_sptr func_sptr = FunctionFactory::Instance().createInitialized(parsedFuncString);
435 FunctionDomain1DVector fd(xVal);
436 FunctionValues fv(fd);
437 func_sptr->function(fd, fv);
438
439 auto results = fv.toVector();
440 for (size_t x = 0; x < xSize; ++x) {
441 if (noiseScale != 0) {
442 results[x] += ((m_randGen->nextValue() - 0.5) * noiseScale);
443 }
444 // no negative values please - it messes up the error calculation
445 results[x] = fabs(results[x]);
446 }
447 return results;
448}
449
450void CreateSampleWorkspace::replaceAll(std::string &str, const std::string &from, const std::string &to) {
451 if (from.empty())
452 return;
453 size_t start_pos = 0;
454 while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
455 str.replace(start_pos, from.length(), to);
456 start_pos += to.length(); // In case 'to' contains 'from', like replacing
457 // 'x' with 'yx'
458 }
459}
460
461//----------------------------------------------------------------------------------------------
486 API::Progress &progress, int numBanks, int numMonitors, int pixels, double pixelDiameter, double pixelHeight,
487 double pixelSpacing, const double bankDistanceFromSample, const double sourceSampleDistance,
488 const std::string &instrName) {
489 auto testInst = std::make_shared<Instrument>(instrName);
490 // The instrument is going to be set up with z as the beam axis and y as the
491 // vertical axis.
492 testInst->setReferenceFrame(std::make_shared<ReferenceFrame>(Y, Z, Left, ""));
493
494 /* Captain! This is wrong */
495 const double cylRadius(pixelDiameter / 2);
496 const double cylHeight(pixelHeight);
497 // One object
498 auto pixelShape =
499 createCappedCylinder(cylRadius, cylHeight, V3D(0.0, -cylHeight / 2.0, 0.0), V3D(0., 1.0, 0.), "pixel-shape");
500
501 for (int banknum = 1; banknum <= numBanks; banknum++) {
502 // Make a new bank
503 std::ostringstream bankname;
504 bankname << "bank" << banknum;
505
506 RectangularDetector *bank = new RectangularDetector(bankname.str());
507 bank->initialize(pixelShape, pixels, 0.0, pixelSpacing, pixels, 0.0, pixelSpacing, banknum * pixels * pixels, true,
508 pixels);
509
510 // Mark them all as detectors
511 for (int x = 0; x < pixels; x++) {
512 for (int y = 0; y < pixels; y++) {
513 std::shared_ptr<Detector> detector = bank->getAtXY(x, y);
514 if (detector) {
515 // Mark it as a detector (add to the instrument cache)
516 testInst->markAsDetector(detector.get());
517 }
518 }
519 }
520
521 testInst->add(bank);
522 // Set the bank along the z-axis of the instrument. (beam direction).
523 bank->setPos(V3D(0.0, 0.0, bankDistanceFromSample * banknum));
524
525 progress.report();
526 }
527
528 int monitorsStart = (numBanks + 1) * pixels * pixels;
529
530 auto monitorShape =
531 createCappedCylinder(0.1, 0.1, V3D(0.0, -cylHeight / 2.0, 0.0), V3D(0., 1.0, 0.), "monitor-shape");
532
533 for (int monitorNumber = monitorsStart; monitorNumber < monitorsStart + numMonitors; monitorNumber++) {
534 std::string monitorName = "monitor" + std::to_string(monitorNumber - monitorsStart + 1);
535
536 Detector *detector = new Detector(monitorName, monitorNumber, monitorShape, testInst.get());
537 // Mark it as a monitor (add to the instrument cache)
538 testInst->markAsMonitor(detector);
539
540 testInst->add(detector);
541 // Set the bank along the z-axis of the instrument, between the detectors.
542 detector->setPos(V3D(0.0, 0.0, bankDistanceFromSample * (monitorNumber - monitorsStart + 0.5)));
543 }
544
545 // Define a source component
546 ObjComponent *source = new ObjComponent("moderator", IObject_sptr(new CSGObject), testInst.get());
547 source->setPos(V3D(0.0, 0.0, -sourceSampleDistance));
548 testInst->add(source);
549 testInst->markAsSource(source);
550
551 // Add chopper
552 ObjComponent *chopper = new ObjComponent("chopper-position", IObject_sptr(new CSGObject), testInst.get());
553 chopper->setPos(V3D(0.0, 0.0, -0.25 * sourceSampleDistance));
554 testInst->add(chopper);
555
556 // Define a sample position
557 Component *sample = new Component("sample", testInst.get());
558 testInst->setPos(0.0, 0.0, 0.0);
559 testInst->add(sample);
560 testInst->markAsSamplePos(sample);
561
562 return testInst;
563}
564
565//----------------------------------------------------------------------------------------------
570 const V3D &axis, const std::string &id) {
571 std::ostringstream xml;
572 xml << "<cylinder id=\"" << id << "\">"
573 << "<centre-of-bottom-base x=\"" << baseCentre.X() << "\" y=\"" << baseCentre.Y() << "\" z=\"" << baseCentre.Z()
574 << "\"/>"
575 << "<axis x=\"" << axis.X() << "\" y=\"" << axis.Y() << "\" z=\"" << axis.Z() << "\"/>"
576 << "<radius val=\"" << radius << "\" />"
577 << "<height val=\"" << height << "\" />"
578 << "</cylinder>";
579
580 ShapeFactory shapeMaker;
581 return shapeMaker.createShape(xml.str());
582}
583
584//----------------------------------------------------------------------------------------------
585
589IObject_sptr CreateSampleWorkspace::createSphere(double radius, const V3D &centre, const std::string &id) {
590 ShapeFactory shapeMaker;
591 std::ostringstream xml;
592 xml << "<sphere id=\"" << id << "\">"
593 << "<centre x=\"" << centre.X() << "\" y=\"" << centre.Y() << "\" z=\"" << centre.Z() << "\" />"
594 << "<radius val=\"" << radius << "\" />"
595 << "</sphere>";
596 return shapeMaker.createShape(xml.str());
597}
598
599} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
double height
Definition: GetAllEi.cpp:155
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define fabs(x)
Definition: Matrix.cpp:22
double radius
Definition: Rasterize.cpp:31
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Kernel::Logger & g_log
Definition: Algorithm.h:451
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
Implements FunctionDomain1D with its own storage in form of a std::vector.
A class to store values calculated by a function.
std::vector< double > toVector() const
Return the calculated values as a vector.
void addLogData(Kernel::Property *p)
Add a log entry.
Definition: LogManager.h:115
void setStartAndEndTime(const Types::Core::DateAndTime &start, const Types::Core::DateAndTime &end)
Set the run start and end.
Definition: LogManager.cpp:121
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 property class for workspaces.
CreateSampleWorkspace : This algorithm is intended for the creation of sample workspaces for usage ex...
Geometry::IObject_sptr createSphere(double radius, const Kernel::V3D &centre, const std::string &id)
Create a sphere object.
Geometry::IObject_sptr createCappedCylinder(double radius, double height, const Kernel::V3D &baseCentre, const Kernel::V3D &axis, const std::string &id)
Create a capped cylinder object.
int version() const override
Algorithm's version for identification.
void exec() override
Execute the algorithm.
std::vector< double > evalFunction(const std::string &functionString, const std::vector< double > &xVal, double noiseScale)
Evaluates a function and returns the values as a vector.
std::unique_ptr< Kernel::PseudoRandomNumberGenerator > m_randGen
A pointer to the random number generator.
const std::string name() const override
Algorithm's name for identification.
DataObjects::EventWorkspace_sptr createEventWorkspace(int numPixels, int numBins, int numMonitors, int numEvents, double x0, double binDelta, const Geometry::Instrument_sptr &inst, const std::string &functionString, bool isRandom)
Create event workspace.
void init() override
Initialize the algorithm's properties.
API::MatrixWorkspace_sptr createHistogramWorkspace(int numPixels, int numBins, int numMonitors, double x0, double binDelta, const Geometry::Instrument_sptr &inst, const std::string &functionString, bool isRandom)
Create histogram workspace.
std::map< std::string, std::string > m_preDefinedFunctionmap
Geometry::Instrument_sptr createTestInstrumentRectangular(API::Progress &progress, int numBanks, int numMonitors, int pixels, double pixelDiameter, double pixelHeight, double pixelSpacing, const double bankDistanceFromSample, const double sourceSampleDistance, const std::string &instrName)
Create an test instrument with n panels of rectangular detectors, pixels*pixels in size,...
void addChopperParameters(API::MatrixWorkspace_sptr &ws)
Add chopper to the existing matrix workspace.
const std::string category() const override
Algorithm's category for identification.
API::MatrixWorkspace_sptr createScanningWorkspace(int numBins, double x0, double binDelta, const Geometry::Instrument_sptr &inst, const std::string &functionString, bool isRandom, int numScanPoints)
Create scanning histogram workspace.
void replaceAll(std::string &str, const std::string &from, const std::string &to)
A class for holding :
Definition: EventList.h:56
ScanningWorkspaceBuilder : This is a helper class to make it easy to build a scanning workspace (a wo...
Constructive Solid Geometry object.
Definition: CSGObject.h:51
Component is a wrapper for a Component which can modify some of its parameters, e....
Definition: Component.h:41
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
virtual void setPos(double, double, double)=0
Set the IComponent position, x, y, z respective to parent (if present)
Object Component class, this class brings together the physical attributes of the component to the po...
Definition: ObjComponent.h:33
RectangularDetector is a type of CompAssembly, an assembly of components.
std::shared_ptr< Detector > getAtXY(const int X, const int Y) const
Return a pointer to the component in the assembly at the (X,Y) pixel position.
void initialize(std::shared_ptr< IObject > shape, int xpixels, double xstart, double xstep, int ypixels, double ystart, double ystep, int idstart, bool idfillbyfirst_y, int idstepbyrow, int idstep=1)
Create all the detector pixels of this rectangular detector.
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...
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
Exception for when an item is not found in a collection.
Definition: Exception.h:145
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
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...
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
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
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< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
std::shared_ptr< IObject > IObject_sptr
Typdef for a shared pointer.
Definition: IObject.h:92
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
Definition: Unit.h:229
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54