Mantid
Loading...
Searching...
No Matches
ConvertToDiffractionMDWorkspace.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
9#include "MantidAPI/Axis.h"
11#include "MantidAPI/Progress.h"
12#include "MantidAPI/Run.h"
13#include "MantidAPI/Sample.h"
29#include "MantidKernel/System.h"
30#include "MantidKernel/Timer.h"
31#include "MantidKernel/Unit.h"
33
34using namespace Mantid;
35using namespace Mantid::Kernel;
36using namespace Mantid::API;
37using namespace Mantid::DataObjects;
38using namespace Mantid::Geometry;
39using Mantid::Types::Event::TofEvent;
40
41namespace Mantid::MDAlgorithms {
42
43bool DODEBUG = true;
44
45// Register the algorithm into the AlgorithmFactory
47
48
51 : ClearInputWorkspace(false), // imput workspace should be left untouched
52 OneEventPerBin(false), // it is very expensive otherwise
53 Append(true), // append data to existing target MD workspace if one exist
54 LorentzCorrection(false), // not doing Lorents
55 l1(1.), beamline_norm(1.), failedDetectorLookupCount(0), m_extentsMin(nullptr),
56 m_extentsMax(nullptr) // will be allocated in exec using nDims
57{}
58
62 // Input units must be TOF
63 auto validator = std::make_shared<API::WorkspaceUnitValidator>("TOF");
65 std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input, validator),
66 "An input workspace in time-of-flight. If you specify a "
67 "Workspace2D, it gets converted to "
68 "an EventWorkspace using ConvertToEventWorkspace.");
69
70 declareProperty(std::make_unique<WorkspaceProperty<IMDEventWorkspace>>("OutputWorkspace", "", Direction::Output),
71 "Name of the output MDEventWorkspace. If the workspace "
72 "already exists, then the events will be added to it.");
73 declareProperty(std::make_unique<PropertyWithValue<bool>>("Append", false, Direction::Input),
74 "Append events to the output workspace. The workspace is replaced if "
75 "unchecked.");
76 declareProperty(std::make_unique<PropertyWithValue<bool>>("ClearInputWorkspace", false, Direction::Input),
77 "Clear the events from the input workspace during "
78 "conversion, to save memory.");
79
80 declareProperty(std::make_unique<PropertyWithValue<bool>>("OneEventPerBin", false, Direction::Input),
81 "Use the histogram representation (event for event workspaces).\n"
82 "One MDEvent will be created for each histogram bin (even empty ones).\n"
83 "Warning! This can use significantly more memory!");
84
85 std::vector<std::string> propOptions{"Q (lab frame)", "Q (sample frame)", "HKL"};
86 declareProperty("OutputDimensions", "Q (lab frame)", std::make_shared<StringListValidator>(propOptions),
87 "What will be the dimensions of the output workspace?\n"
88 " Q (lab frame): Wave-vector change of the lattice in the lab frame.\n"
89 " Q (sample frame): Wave-vector change of the lattice in the frame of "
90 "the sample (taking out goniometer rotation).\n"
91 " HKL: Use the sample's UB matrix to convert to crystal's HKL indices.");
92
93 declareProperty(std::make_unique<PropertyWithValue<bool>>("LorentzCorrection", false, Direction::Input),
94 "Correct the weights of events by multiplying by the Lorentz "
95 "formula: sin(theta)^2 / lambda^4");
96
97 // Box controller properties. These are the defaults
98 this->initBoxControllerProps("2" /*SplitInto*/, 1500 /*SplitThreshold*/, 20 /*MaxRecursionDepth*/);
99
100 declareProperty(std::make_unique<PropertyWithValue<int>>("MinRecursionDepth", 0),
101 "Optional. If specified, then all the boxes will be split to this "
102 "minimum recursion depth. 1 = one level of splitting, etc.\n"
103 "Be careful using this since it can quickly create a huge number of "
104 ":math:`boxes = SplitInto^{MinRercursionDepth \\times NumDimensions}`.\n"
105 "But setting this property equal to MaxRecursionDepth property is "
106 "necessary if one wants to generate multiple file based workspaces in "
107 "order to merge them later\n");
108 setPropertyGroup("MinRecursionDepth", getBoxSettingsGroupName());
109
110 std::vector<double> extents{-50, +50};
111 declareProperty(std::make_unique<ArrayProperty<double>>("Extents", std::move(extents)),
112 "A comma separated list of min, max for each dimension,\n"
113 "specifying the extents of each dimension. Optional, default "
114 "+-50 in each dimension.");
116}
117
120
131 if (m_inEventWS && !OneEventPerBin) {
132 // ---------- Convert events directly -------------------------
133 EventList &el = m_inEventWS->getSpectrum(workspaceIndex);
134
135 // Call the right templated function
136 switch (el.getEventType()) {
137 case TOF:
138 this->convertEventList<TofEvent>(workspaceIndex, specInfo, el);
139 break;
140 case WEIGHTED:
141 this->convertEventList<WeightedEvent>(workspaceIndex, specInfo, el);
142 break;
143 case WEIGHTED_NOTIME:
144 this->convertEventList<WeightedEventNoTime>(workspaceIndex, specInfo, el);
145 break;
146 default:
147 throw std::runtime_error("EventList had an unexpected data type!");
148 }
149 } else {
150 // ----- Workspace2D, or use the Histogram representation of EventWorkspace
151 // ------------
152 // Construct a new event list
153 EventList el;
154
155 // Create the events using the bins
156 const auto &inSpec = m_inWS->getSpectrum(workspaceIndex);
157 // If OneEventPerBin, generate exactly 1 event per bin, including zeros.
158 // If !OneEventPerBin, generate up to 10 events per bin, excluding zeros
159 el.createFromHistogram(&inSpec, OneEventPerBin /* Generate zeros */, !OneEventPerBin /* Multiple events */,
160 (OneEventPerBin ? 1 : 10) /* Max of this many events per bin */);
161
162 // Perform the conversion on this temporary event list
163 this->convertEventList<WeightedEventNoTime>(workspaceIndex, specInfo, el);
164 }
165}
166
167//----------------------------------------------------------------------------------------------
176template <class T>
178 EventList &el) {
179 size_t numEvents = el.getNumberEvents();
181
182 // Get the position of the detector there.
183 const auto &detectors = el.getDetectorIDs();
184 if (!detectors.empty()) {
185 // Check if a detector is located at this workspace index, returns
186 // immediately if one is not found.
187 if (!specInfo.hasDetectors(workspaceIndex)) {
189 return;
190 }
191
192 // Neutron's total travelled distance
193 double distance = l1 + specInfo.l2(workspaceIndex);
194
195 // Vector between the sample and the detector
196 const V3D detPos = specInfo.position(workspaceIndex);
197
198 // Detector direction normalized to 1
199 const V3D detDir = detPos / detPos.norm();
200
201 // The direction of momentum transfer in the inelastic convention ki-kf
202 // = input beam direction (normalized to 1) - output beam direction
203 // (normalized to 1)
204 V3D Q_dir_lab_frame = beamDir - detDir;
205 double qSign = -1.0;
206 std::string convention = ConfigService::Instance().getString("Q.convention");
207 if (convention == "Crystallography")
208 qSign = 1.0;
209 Q_dir_lab_frame *= qSign;
210
211 // Multiply by the rotation matrix to convert to Q in the sample frame (take
212 // out goniometer rotation)
213 // (or to HKL, if that's what the matrix is)
214 const V3D Q_dir = mat * Q_dir_lab_frame;
215
216 // For speed we extract the components.
217 auto Q_dir_x = coord_t(Q_dir.X());
218 auto Q_dir_y = coord_t(Q_dir.Y());
219 auto Q_dir_z = coord_t(Q_dir.Z());
220
221 // For lorentz correction, calculate sin(theta))^2
222 double sin_theta_squared = 0;
223 if (LorentzCorrection) {
224 // Scattering angle = 2 theta = angle between neutron beam direction and
225 // the detector (scattering) direction
226 // The formula for Lorentz Correction is sin(theta), i.e. sin(half the
227 // scattering angle)
228 double theta = specInfo.twoTheta(workspaceIndex) / 2.0;
229 sin_theta_squared = sin(theta);
230 sin_theta_squared = sin_theta_squared * sin_theta_squared; // square it
231 }
232
236 const double wavenumber_in_angstrom_times_tof_in_microsec =
237 (PhysicalConstants::NeutronMass * distance * 1e-10) / (1e-6 * PhysicalConstants::h_bar);
238
239 // This little dance makes the getting vector of events more general (since
240 // you can't overload by return type).
241 typename std::vector<T> *events_ptr;
242 getEventsFrom(el, events_ptr);
243 typename std::vector<T> &events = *events_ptr;
244
245 // Iterators to start/end
246 auto it = events.begin();
247 auto it_end = events.end();
248
249 for (; it != it_end; it++) {
250 // Get the wavenumber in ang^-1 using the previously calculated constant.
251 auto wavenumber = coord_t(wavenumber_in_angstrom_times_tof_in_microsec / it->tof());
252
253 // Q vector = K_final - K_initial = wavenumber * (output_direction -
254 // input_direction)
255 coord_t center[3] = {Q_dir_x * wavenumber, Q_dir_y * wavenumber, Q_dir_z * wavenumber};
256
257 // Check that the event is within bounds
258 if (center[0] < m_extentsMin[0] || center[0] >= m_extentsMax[0])
259 continue;
260 if (center[1] < m_extentsMin[1] || center[1] >= m_extentsMax[1])
261 continue;
262 if (center[2] < m_extentsMin[2] || center[2] >= m_extentsMax[2])
263 continue;
264
265 if (LorentzCorrection) {
266 // double lambda = 1.0/wavenumber;
267 // (sin(theta))^2 / wavelength^4
268 auto correct = float(sin_theta_squared * wavenumber * wavenumber * wavenumber * wavenumber);
269 // Push the MDLeanEvent but correct the weight.
270 box->addEvent(MDE(float(it->weight() * correct), float(it->errorSquared() * correct * correct), center));
271 } else {
272 // Push the MDLeanEvent with the same weight
273 box->addEvent(MDE(float(it->weight()), float(it->errorSquared()), center));
274 }
275 }
276
277 // Clear out the EventList to save memory
279 el.clear();
280 }
281 prog->reportIncrement(numEvents, "Adding Events");
282}
283
284//----------------------------------------------------------------------------------------------
288 Timer tim, timtotal;
289 CPUTimer cputim, cputimtotal;
290
291 // ---------------------- Extract properties
292 // --------------------------------------
293 ClearInputWorkspace = getProperty("ClearInputWorkspace");
294 Append = getProperty("Append");
295 std::string OutputDimensions = getPropertyValue("OutputDimensions");
296 LorentzCorrection = getProperty("LorentzCorrection");
297 OneEventPerBin = getProperty("OneEventPerBin");
298
299 // -------- Input workspace -> convert to Event
300 // ------------------------------------
301 m_inWS = getProperty("InputWorkspace");
302 if (LorentzCorrection) {
303 API::Run &run = m_inWS->mutableRun();
304 if (run.hasProperty("LorentzCorrection")) {
305 auto lorentzDone = run.getPropertyValueAsType<bool>("LorentzCorrection");
306 if (lorentzDone) {
307 LorentzCorrection = false;
308 g_log.warning() << "Lorentz Correction was already done for this "
309 "workspace. LorentzCorrection was changed to false.\n";
310 }
311 }
312 }
313
314 m_inEventWS = std::dynamic_pointer_cast<EventWorkspace>(m_inWS);
315
316 // check the input units
317 if (m_inWS->getAxis(0)->unit()->unitID() != "TOF")
318 throw std::invalid_argument("Input event workspace's X axis must be in TOF units.");
319
320 // Try to get the output workspace
321 IMDEventWorkspace_sptr i_out = getProperty("OutputWorkspace");
322 ws = std::dynamic_pointer_cast<DataObjects::MDEventWorkspace<DataObjects::MDLeanEvent<3>, 3>>(i_out);
323
324 // Initalize the matrix to 3x3 identity
325 mat = Kernel::Matrix<double>(3, 3, true);
326
327 // ----------------- Handle the type of output
328 // -------------------------------------
329
330 std::string dimensionNames[3] = {"Q_lab_x", "Q_lab_y", "Q_lab_z"};
332
333 // Setup the MDFrame
334 auto frameFactory = makeMDFrameFactoryChain();
336
337 if (OutputDimensions == "Q (sample frame)") {
338 // Set the matrix based on goniometer angles
339 mat = m_inWS->mutableRun().getGoniometerMatrix();
340 // But we need to invert it, since we want to get the Q in the sample frame.
341 mat.Invert();
342 // Names
343 dimensionNames[0] = "Q_sample_x";
344 dimensionNames[1] = "Q_sample_y";
345 dimensionNames[2] = "Q_sample_z";
346 coordinateSystem = Mantid::Kernel::QSample;
347 // Frame
348 MDFrameArgument frameArgQSample(QSample::QSampleName, "");
349 frame = frameFactory->create(frameArgQSample);
350
351 } else if (OutputDimensions == "HKL") {
352 // Set the matrix based on UB etc.
353 Kernel::Matrix<double> ub = m_inWS->mutableSample().getOrientedLattice().getUB();
354 Kernel::Matrix<double> gon = m_inWS->mutableRun().getGoniometerMatrix();
355 // As per Busing and Levy 1967, q_lab_frame = 2pi * Goniometer * UB * HKL
356 // Therefore, HKL = (2*pi * Goniometer * UB)^-1 * q_lab_frame
357 mat = gon * ub;
358 mat.Invert();
359 // Divide by 2 PI to account for our new convention, |Q| = 2pi / wl
360 // (December 2011, JZ)
361 mat /= (2 * M_PI);
362 dimensionNames[0] = "H";
363 dimensionNames[1] = "K";
364 dimensionNames[2] = "L";
365 coordinateSystem = Mantid::Kernel::HKL;
366 MDFrameArgument frameArgQLab(HKL::HKLName, Units::Symbol::RLU.ascii());
367 frame = frameFactory->create(frameArgQLab);
368 } else {
369 MDFrameArgument frameArgQLab(QLab::QLabName, "");
370 frame = frameFactory->create(frameArgQLab);
371 }
372 // Q in the lab frame is the default, so nothing special to do.
373
374 if (ws && Append) {
375 // Check that existing workspace dimensions make sense with the desired one
376 // (using the name)
377 if (ws->getDimension(0)->getName() != dimensionNames[0])
378 throw std::runtime_error("The existing MDEventWorkspace " + ws->getName() +
379 " has different dimensions than were requested! "
380 "Either give a different name for the output, "
381 "or change the OutputDimensions parameter.");
382 }
383
384 // ------------------- Create the output workspace if needed
385 // ------------------------
386 if (!ws || !Append) {
387 // Create an output workspace with 3 dimensions.
388 size_t nd = 3;
389 i_out = DataObjects::MDEventFactory::CreateMDWorkspace(nd, "MDLeanEvent");
390 ws = std::dynamic_pointer_cast<DataObjects::MDEventWorkspace3Lean>(i_out);
391
392 // ---------------- Get the extents -------------
393 std::vector<double> extents = getProperty("Extents");
394 // Replicate a single min,max into several
395 if (extents.size() == 2) {
396 for (size_t d = 1; d < nd; d++) {
397 extents.emplace_back(extents[0]);
398 extents.emplace_back(extents[1]);
399 }
400 }
401 if (extents.size() != nd * 2)
402 throw std::invalid_argument("You must specify either 2 or 6 extents (min,max).");
403
404 // Give all the dimensions
405 for (size_t d = 0; d < nd; d++) {
406 MDHistoDimension *dim =
407 new MDHistoDimension(dimensionNames[d], dimensionNames[d], *frame, static_cast<coord_t>(extents[d * 2]),
408 static_cast<coord_t>(extents[d * 2 + 1]), 10);
409 ws->addDimension(MDHistoDimension_sptr(dim));
410 }
411 ws->initialize();
412
413 // Build up the box controller, using the properties in
414 // BoxControllerSettingsAlgorithm
415 BoxController_sptr bc = ws->getBoxController();
416 this->setBoxController(bc, m_inWS->getInstrument());
417 // We always want the box to be split (it will reject bad ones)
418 ws->splitBox();
419
420 // Perform minimum recursion depth splitting
421 int minDepth = this->getProperty("MinRecursionDepth");
422 int maxDepth = this->getProperty("MaxRecursionDepth");
423 if (minDepth > maxDepth)
424 throw std::invalid_argument("MinRecursionDepth must be <= MaxRecursionDepth ");
425 ws->setMinRecursionDepth(size_t(minDepth));
426 }
427
428 ws->splitBox();
429
430 if (!ws)
431 throw std::runtime_error("Error creating a 3D MDEventWorkspace!");
432
433 BoxController_sptr bc = ws->getBoxController();
434 if (!bc)
435 throw std::runtime_error("Output MDEventWorkspace does not have a BoxController!");
436
437 // Cache the extents for speed.
438 m_extentsMin = new coord_t[3];
439 m_extentsMax = new coord_t[3];
440 for (size_t d = 0; d < 3; d++) {
441 m_extentsMin[d] = ws->getDimension(d)->getMinimum();
442 m_extentsMax[d] = ws->getDimension(d)->getMaximum();
443 }
444
445 // Copy ExperimentInfo (instrument, run, sample) to the output WS
446 ExperimentInfo_sptr ei(m_inWS->cloneExperimentInfo());
447 uint16_t expInfoIndex = ws->addExperimentInfo(ei);
448 UNUSED_ARG(expInfoIndex);
449
450 // ------------------- Cache values that are common for all
451 // ---------------------------
452 // Extract some parameters global to the instrument
453 m_inWS->getInstrument()->getInstrumentParameters(l1, beamline, beamline_norm, samplePos);
456
457 // Estimate the number of events in the final workspace
458 size_t totalEvents = m_inWS->size();
460 totalEvents = m_inEventWS->getNumberEvents();
461 prog = std::make_shared<Progress>(this, 0.0, 1.0, totalEvents);
462
463 // Create the thread pool that will run all of these.
465 ThreadPool tp(ts, 0);
466
467 // To track when to split up boxes
469 size_t eventsAdded = 0;
470 size_t approxEventsInOutput = 0;
471 size_t lastNumBoxes = ws->getBoxController()->getTotalNumMDBoxes();
472 if (DODEBUG)
473 g_log.information() << cputim << ": initial setup. There are " << lastNumBoxes << " MDBoxes.\n";
474
475 const auto &specInfo = m_inWS->spectrumInfo();
476 for (size_t wi = 0; wi < m_inWS->getNumberHistograms();) {
477 // 1. Determine next chunk of spectra to process
478 auto start = static_cast<int>(wi);
479 for (; wi < m_inWS->getNumberHistograms(); ++wi) {
480 // Get an idea of how many events we'll be adding
481 size_t eventsAdding = m_inWS->blocksize();
483 eventsAdding = m_inEventWS->getSpectrum(wi).getNumberEvents();
484
485 // Keep a running total of how many events we've added
486 eventsAdded += eventsAdding;
487 approxEventsInOutput += eventsAdding;
488
489 if (bc->shouldSplitBoxes(approxEventsInOutput, eventsAdded, lastNumBoxes))
490 break;
491 }
492
493 // 2. Process next chunk of spectra (threaded)
495 for (int i = start; i < static_cast<int>(wi); ++i) {
497 this->convertSpectrum(specInfo, static_cast<int>(i));
499 }
501
502 // 3. Split boxes
503 if (DODEBUG) {
504 g_log.information() << cputim << ": Added tasks worth " << eventsAdded << " events. WorkspaceIndex " << wi
505 << std::endl;
506 g_log.information() << cputim << ": Performing the addition of these events.\n";
507 }
508 // Now do all the splitting tasks
509 ws->splitAllIfNeeded(ts);
510 if (ts->size() > 0)
511 prog->doReport("Splitting Boxes");
512 // Note: For some reason removing this joinAll() increases the runtime
513 // significantly. Does it somehow affect threads in "ts" created by
514 // splitAllIfNeeded()?
515 tp.joinAll();
516
517 // Count the new # of boxes.
518 lastNumBoxes = ws->getBoxController()->getTotalNumMDBoxes();
519 if (DODEBUG)
520 g_log.information() << cputim << ": Performing the splitting. There are now " << lastNumBoxes << " boxes.\n";
521 eventsAdded = 0;
522 }
523
524 if (this->failedDetectorLookupCount > 0) {
525 if (this->failedDetectorLookupCount == 1)
526 g_log.warning() << "Unable to find a detector for " << this->failedDetectorLookupCount
527 << " spectrum. It has been skipped.\n";
528 else
529 g_log.warning() << "Unable to find detectors for " << this->failedDetectorLookupCount
530 << " spectra. They have been skipped.\n";
531 }
532
533 // Recount totals at the end.
534 cputim.reset();
535 ws->refreshCache();
536 if (DODEBUG) {
537 g_log.information() << cputim << ": Performing the refreshCache().\n";
538 g_log.information() << "Workspace has " << ws->getNPoints() << " events. This took " << cputimtotal
539 << " in total.\n";
540 std::vector<std::string> stats = ws->getBoxControllerStats();
541 for (auto &stat : stats)
542 g_log.information() << stat << "\n";
543 g_log.information() << '\n';
544 }
545
546 // Set the special coordinate system.
547 ws->setCoordinateSystem(coordinateSystem);
548
549 // Save the output
550 setProperty("OutputWorkspace", std::dynamic_pointer_cast<IMDEventWorkspace>(ws));
551
552 // Clean up
553 delete[] m_extentsMin;
554 delete[] m_extentsMax;
555}
556
557} // namespace Mantid::MDAlgorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
static std::unique_ptr< QThreadPool > tp
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
Definition: MultiThreaded.h:94
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
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 setBoxController(const Mantid::API::BoxController_sptr &bc, const Mantid::Geometry::Instrument_const_sptr &instrument)
Set the settings in the given box controller.
void initBoxControllerProps(const std::string &SplitInto="5", int SplitThreshold=1000, int MaxRecursionDepth=5)
Initialise the properties.
const std::set< detid_t > & getDetectorIDs() const
Get a const reference to the detector IDs set.
Definition: ISpectrum.cpp:113
bool hasProperty(const std::string &name) const
Does the property exist on the object.
Definition: LogManager.cpp:265
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
Definition: LogManager.cpp:332
This class stores information regarding an experimental run as a series of log entries.
Definition: Run.h:38
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
Definition: SpectrumInfo.h:53
bool hasDetectors(const size_t index) const
Returns true if the spectrum is associated with detectors in the instrument.
double twoTheta(const size_t index) const
Returns the scattering angle 2 theta in radians (angle w.r.t.
Kernel::V3D position(const size_t index) const
Returns the position of the spectrum with given index.
double l2(const size_t index) const
Returns L2 (distance from sample to spectrum).
A property class for workspaces.
A class for holding :
Definition: EventList.h:56
std::size_t getNumberEvents() const override
Return the number of events in the list.
Definition: EventList.cpp:1143
Mantid::API::EventType getEventType() const override
Return the type of Event vector contained within.
Definition: EventList.cpp:643
void createFromHistogram(const ISpectrum *inSpec, bool GenerateZeros, bool GenerateMultipleEvents, int MaxEventsPerBin)
Create an EventList from a histogram.
Definition: EventList.cpp:229
void clear(const bool removeDetIDs=true) override
Clear the list of events and any associated detector ID's.
Definition: EventList.cpp:847
Templated super-class of a multi-dimensional event "box".
Definition: MDBoxBase.h:50
virtual size_t addEvent(const MDE &point)=0
Add a single event.
static API::IMDEventWorkspace_sptr CreateMDWorkspace(size_t nd, const std::string &eventType="MDLeanEvent", const Mantid::API::MDNormalization &preferredNormalization=Mantid::API::MDNormalization::VolumeNormalization, const Mantid::API::MDNormalization &preferredNormalizationHisto=Mantid::API::MDNormalization::VolumeNormalization)
Create a MDEventWorkspace of the given type.
Templated class holding data about a neutron detection event in N-dimensions (for example,...
Definition: MDLeanEvent.h:60
static const std::string HKLName
Definition: HKL.h:27
Input argument type for MDFrameFactory chainable factory.
static const std::string QLabName
Definition: QLab.h:35
static const std::string QSampleName
Definition: QSample.h:23
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
CPUTimer : Timer that uses the CPU time, rather than wall-clock time to measure execution time.
Definition: CPUTimer.h:24
void reset()
Explicitly reset the timer.
Definition: CPUTimer.cpp:23
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 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
Numerical Matrix class.
Definition: Matrix.h:42
T Invert()
LU inversion routine.
Definition: Matrix.cpp:924
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 Thread Pool implementation that keeps a certain number of threads running (normally,...
Definition: ThreadPool.h:36
A First-In-First-Out Thread Scheduler.
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
virtual size_t size()=0
Returns the size of the queue.
A simple class that provides a wall-clock (not processor time) timer.
Definition: Timer.h:27
static const UnitLabel RLU
Reciprocal lattice units.
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
double norm() const noexcept
Definition: V3D.h:263
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
ConvertToDiffractionMDWorkspace : Create a MDEventWorkspace with events in reciprocal space (Qx,...
DataObjects::EventWorkspace_sptr m_inEventWS
The input event workspace.
double beamline_norm
Path length between source and sample.
coord_t * m_extentsMax
Maximum extents of the workspace. Cached for speed.
bool ClearInputWorkspace
Do we clear events on the input during loading?
size_t failedDetectorLookupCount
Path length between source and sample.
API::MatrixWorkspace_sptr m_inWS
The input MatrixWorkspace.
DataObjects::MDEventWorkspace3Lean::sptr ws
The output MDEventWorkspace<3>
void convertSpectrum(const API::SpectrumInfo &specInfo, int workspaceIndex)
Convert one spectrum to DataObjects.
void convertEventList(int workspaceIndex, const API::SpectrumInfo &specInfo, DataObjects::EventList &el)
Convert an event list to 3D q-space and add it to the MDEventWorkspace.
std::shared_ptr< Kernel::ProgressBase > prog
Progress reporter (shared)
coord_t * m_extentsMin
Minimum extents of the workspace. Cached for speed.
void init() override
Initialize the algorithm's properties.
bool OneEventPerBin
Use the histogram representation with one event per bin.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
@ WEIGHTED_NOTIME
Definition: IEventList.h:18
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.
DLLExport void getEventsFrom(EventList &el, std::vector< Types::Event::TofEvent > *&events)
std::unique_ptr< MDFrame > MDFrame_uptr
Definition: MDFrame.h:36
MDFrameFactory_uptr MANTID_GEOMETRY_DLL makeMDFrameFactoryChain()
Make a complete factory chain.
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
Definition: MultiThreaded.h:22
DataObjects::MDLeanEvent< 3 > MDE
Our MDLeanEvent dimension.
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h_bar
Planck constant in J*s, divided by 2 PI.
Helper class which provides the Collimation Length for SANS instruments.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition: MDTypes.h:27
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54