Mantid
Loading...
Searching...
No Matches
ConvertCWSDExpToMomentum.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 +
10#include "MantidAPI/Run.h"
22
23using namespace Mantid::API;
24using namespace Mantid::Kernel;
25using namespace Mantid::DataObjects;
26using namespace Mantid::Geometry;
27
28namespace Mantid::MDAlgorithms {
29
30DECLARE_ALGORITHM(ConvertCWSDExpToMomentum)
31
32
35 : m_iColScan(0), m_iColPt(1), m_iColFilename(2), m_iColStartDetID(3), m_iMonitorCounts(4), m_iTime(5),
36 m_setQRange(true), m_isBaseName(false), m_removeBackground(false) {}
37
41 declareProperty(std::make_unique<WorkspaceProperty<ITableWorkspace>>("InputWorkspace", "", Direction::Input),
42 "Name of table workspace for data file names in the experiment.");
43
44 declareProperty(std::make_unique<FileProperty>("InstrumentFilename", "", FileProperty::OptionalLoad, ".xml"));
45
46 declareProperty("DetectorSampleDistanceShift", 0.0, "Amount of shift in sample-detector distance from 0.3750 meter.");
47
48 declareProperty("DetectorCenterXShift", 0.0, "Amount of shift of detector center in X-direction from (115, 128).");
49
50 declareProperty("DetectorCenterYShift", 0.0, "Amount of shift of detector center in Y-direction from (115, 128).");
51
52 declareProperty("UserDefinedWavelength", EMPTY_DBL(), "User defined wave length if it is specified.");
53
54 declareProperty("CreateVirtualInstrument", false, "Flag to create virtual instrument.");
55
56 declareProperty(std::make_unique<WorkspaceProperty<ITableWorkspace>>("DetectorTableWorkspace", "", Direction::Input,
58 "Name of table workspace containing all the detectors.");
59
60 declareProperty(std::make_unique<WorkspaceProperty<IMDEventWorkspace>>("OutputWorkspace", "", Direction::Output),
61 "Name of MDEventWorkspace containing all experimental data.");
62
63 declareProperty(std::make_unique<ArrayProperty<double>>("SourcePosition"),
64 "A vector of 3 doubles for position of source.");
65
66 declareProperty(std::make_unique<ArrayProperty<double>>("SamplePosition"),
67 "A vector of 3 doubles for position of sample.");
68
69 declareProperty(std::make_unique<ArrayProperty<double>>("PixelDimension"),
70 "A vector of 8 doubles to determine a cubic pixel's size.");
71
72 declareProperty("IsBaseName", true,
73 "It is specified as true if the data "
74 "file names listed in InputWorkspace are "
75 "base name without directory.");
76
77 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("BackgroundWorkspace", "", Direction::Input,
79 "Name of optional background workspace.");
80
81 declareProperty(std::make_unique<FileProperty>("Directory", "", FileProperty::OptionalDirectory),
82 "Directory where data files are if InputWorkspace gives data file name "
83 "as the base file name as indicated by 'IsBaseName'.");
84}
85
86//----------------------------------------------------------------------------------------------
91 // Parse inputs
92 std::string errmsg;
93 bool createvirtual = getProperty("CreateVirtualInstrument");
94 bool inputvalid = getInputs(createvirtual, errmsg);
95 if (!inputvalid) {
96 g_log.error() << "Importing error: " << errmsg << "\n";
97 throw std::runtime_error(errmsg);
98 }
99 m_detSampleDistanceShift = getProperty("DetectorSampleDistanceShift");
100 m_detXShift = getProperty("DetectorCenterXShift");
101 m_detYShift = getProperty("DetectorCenterYShift");
102
103 // background
104 std::string bkgdwsname = getPropertyValue("BackgroundWorkspace");
105 if (!bkgdwsname.empty()) {
106 m_removeBackground = true;
107 m_backgroundWS = getProperty("BackgroundWorkspace");
108 // check background
109 if (m_backgroundWS->getNumberHistograms() != 256 * 256)
110 throw std::invalid_argument("Input background workspace does not have "
111 "correct number of spectra.");
112 } else {
113 m_removeBackground = false;
114 }
115
116 // Create output MDEventWorkspace
118
119 if (createvirtual)
121
122 // Add MDEventWorkspace
123 addMDEvents(createvirtual);
124
125 setProperty("OutputWorkspace", m_outputWS);
126
127 // Output
128 for (size_t i = 0; i < 3; ++i) {
129 g_log.notice() << "Q-sample at dimension " << i << ": " << m_minQVec[i] << ", " << m_maxQVec[i] << "\n";
130 }
131}
132
133//----------------------------------------------------------------------------------------------
138 // Get detector list from input table workspace
139 std::vector<Kernel::V3D> vec_detpos;
140 std::vector<detid_t> vec_detid;
141 g_log.information("Start to parse detector parameter tables.");
142 parseDetectorTable(vec_detpos, vec_detid);
143
144 // Create a virtual instrument
145 g_log.information("Start to create virtual instrument.");
149 throw std::runtime_error("Failed to create virtual instrument.");
150 g_log.information() << "Virtual Instrument has " << m_virtualInstrument->getDetectorIDs().size() << "Detectors\n";
151}
152
153//----------------------------------------------------------------------------------------------
159
160 // Create workspace in Q_sample with dimenion as 3
161 size_t nDimension = 3;
162 IMDEventWorkspace_sptr mdws = MDEventFactory::CreateMDWorkspace(nDimension, "MDEvent");
163
164 // Extract Dimensions and add to the output workspace.
165 std::vector<std::string> vec_ID(3);
166 vec_ID[0] = "Q_sample_x";
167 vec_ID[1] = "Q_sample_y";
168 vec_ID[2] = "Q_sample_z";
169
170 std::vector<std::string> dimensionNames(3);
171 dimensionNames[0] = "Q_sample_x";
172 dimensionNames[1] = "Q_sample_y";
173 dimensionNames[2] = "Q_sample_z";
174
176
177 // Add dimensions
178 // FIXME - Should I give out a better value???
179 if (m_extentMins.size() != 3 || m_extentMaxs.size() != 3 || m_numBins.size() != 3) {
180 // Default dimenion
181 m_extentMins.resize(3, -10.0);
182 m_extentMaxs.resize(3, 10.0);
183 m_numBins.resize(3, 100);
184 }
185 // Sample-Q range
186 m_minQVec.resize(3);
187 m_maxQVec.resize(3);
188
189 for (size_t d = 0; d < 3; ++d)
190 g_log.debug() << "Direction " << d << ", Range = " << m_extentMins[d] << ", " << m_extentMaxs[d] << "\n";
191
192 // Set Q Sample frame
194
195 for (size_t i = 0; i < nDimension; ++i) {
196 std::string id = vec_ID[i];
197 std::string name = dimensionNames[i];
199 id, name, frame, static_cast<coord_t>(m_extentMins[i]), static_cast<coord_t>(m_extentMaxs[i]), m_numBins[i])));
200 }
201
202 // Set coordinate system
203 mdws->setCoordinateSystem(coordinateSystem);
204
205 return mdws;
206}
207
208//----------------------------------------------------------------------------------------------
215 MatrixWorkspace_sptr spicews;
216
217 // Check whether to add / or \ to m_dataDir
218 std::string sep;
219 if (!m_dataDir.empty()) {
220#if defined _WIN32 || defined _WIN64
221 if (*m_dataDir.rbegin() != '\\') {
222 sep = "\\";
223 }
224#else
225 if (*m_dataDir.rbegin() != '/') {
226 sep = "/";
227 }
228#endif
229 }
230
231 // Init some variables
232 size_t numrows = m_expDataTableWS->rowCount();
233 if (numrows > 1 && !usevirtual) {
234 g_log.warning("There are more than 1 experiment to import. "
235 "Make sure that all of them have the same instrument.");
236 }
237
238 // Loop through all data files in the experiment
239 for (size_t ir = 0; ir < numrows; ++ir) {
240 std::string rawfilename = m_expDataTableWS->cell<std::string>(ir, m_iColFilename);
241 detid_t start_detid = 0;
242 if (usevirtual)
243 start_detid = m_expDataTableWS->cell<detid_t>(ir, m_iColStartDetID);
244
245 // Load data
246 bool loaded;
247 std::string errmsg;
248
249 std::stringstream filess;
250 if (m_isBaseName)
251 filess << m_dataDir << sep;
252 filess << rawfilename;
253 std::string filename(filess.str());
254
255 spicews = loadSpiceData(filename, loaded, errmsg);
256 if (!loaded) {
257 g_log.error(errmsg);
258 continue;
259 }
261 removeBackground(spicews);
262
263 // Convert from MatrixWorkspace to MDEvents and add events to
264 int scanid = m_expDataTableWS->cell<int>(ir, m_iColScan);
265 g_log.notice() << "[DB] Scan = " << scanid << "\n";
266 int runid = m_expDataTableWS->cell<int>(ir, m_iColPt);
267 g_log.notice() << "Pt = " << runid << "\n"
268 << m_iTime << "-th for time/duration"
269 << "\n";
270 double time(0.);
271 try {
272 float time_f = m_expDataTableWS->cell<float>(ir, m_iTime);
273 time = static_cast<double>(time_f);
274 } catch (const std::runtime_error &) {
275 time = m_expDataTableWS->cell<double>(ir, m_iTime);
276 }
277
278 int monitor_counts = m_expDataTableWS->cell<int>(ir, m_iMonitorCounts);
279 if (!usevirtual)
280 start_detid = 0;
281 convertSpiceMatrixToMomentumMDEvents(spicews, usevirtual, start_detid, scanid, runid, time, monitor_counts);
282 }
283
284 // Set box extents
285 std::vector<API::IMDNode *> boxes;
286
287 // Set extents for all MDBoxes
288 progress(0.90, "Set up MDBoxes' dimensions. ");
289 m_outputWS->getBoxes(boxes, 1000, true);
290 auto it1 = boxes.begin();
291 auto it1_end = boxes.end();
292 for (; it1 != it1_end; it1++) {
293 auto box = *it1;
294 for (size_t dim = 0; dim < 3; ++dim) {
295 auto *mdbox = dynamic_cast<DataObjects::MDBox<MDEvent<3>, 3> *>(box);
296 if (!mdbox)
297 throw std::runtime_error("Unable to cast to MDBox");
298 mdbox->setExtents(dim, -10, 10);
299 mdbox->calcVolume();
300 mdbox->refreshCache(nullptr);
301 }
302 }
303}
304
305//----------------------------------------------------------------------------------------------
315 Kernel::DblMatrix &rotationMatrix) {
316 // Check sample logs
317 if (!dataws->run().hasProperty("_omega") || !dataws->run().hasProperty("_chi") || !dataws->run().hasProperty("_phi"))
318 throw std::runtime_error("Data workspace does not have sample log _phi, _chi or _omega. "
319 "Unable to set goniometer and calcualte roation matrix R.");
320
321 // Call algorithm SetGoniometer
322 auto setalg = createChildAlgorithm("SetGoniometer");
323 setalg->initialize();
324 setalg->setProperty("Workspace", dataws);
325 setalg->setProperty("Axis0", "_omega,0,1,0,-1");
326 setalg->setProperty("Axis1", "_chi,0,0,1,-1");
327 setalg->setProperty("Axis2", "_phi,0,1,0,-1");
328 setalg->execute();
329
330 if (setalg->isExecuted()) {
331 rotationMatrix = dataws->run().getGoniometer().getR();
332 g_log.debug() << "Ratation matrix: " << rotationMatrix.str() << "\n";
333 rotationMatrix.Invert();
334 g_log.debug() << "Ratation matrix: " << rotationMatrix.str() << "\n";
335 } else
336 throw std::runtime_error("Unable to set Goniometer.");
337}
338
339//----------------------------------------------------------------------------------------------
355 const detid_t &startdetid, const int scannumber,
356 const int runnumber, double measuretime,
357 int monitor_counts) {
358 // Create transformation matrix from which the transformation is
359 Kernel::DblMatrix rotationMatrix;
360 setupTransferMatrix(dataws, rotationMatrix);
361
362 g_log.information() << "Before insert new event, output workspace has " << m_outputWS->getNEvents() << "Events.\n";
363
364 // Creates a new instance of the MDEventInserte to output workspace
365 MDEventWorkspace<MDEvent<3>, 3>::sptr mdws_mdevt_3 =
366 std::dynamic_pointer_cast<MDEventWorkspace<MDEvent<3>, 3>>(m_outputWS);
367 MDEventInserter<MDEventWorkspace<MDEvent<3>, 3>::sptr> inserter(mdws_mdevt_3);
368
369 // Calcualte k_i: it is assumed that all k_i are same for one Pt.
370 // number, i.e., one 2D XML file
371 Kernel::V3D sourcePos = dataws->getInstrument()->getSource()->getPos();
372 Kernel::V3D samplePos = dataws->getInstrument()->getSample()->getPos();
373 if (dataws->x(0).size() != 2)
374 throw std::runtime_error("Input matrix workspace has wrong dimension in X-axis.");
375 double momentum = 0.5 * (dataws->x(0)[0] + dataws->x(0)[1]);
376 Kernel::V3D ki = (samplePos - sourcePos) * (momentum / sourcePos.norm());
377
378 g_log.debug() << "Source at " << sourcePos.toString() << ", Norm = " << sourcePos.norm()
379 << ", momentum = " << momentum << "\n"
380 << "k_i = " << ki.toString() << "\n";
381
382 // Go though each spectrum to conver to MDEvent
383 size_t numspec = dataws->getNumberHistograms();
384 const auto &specInfo = dataws->spectrumInfo();
385 double maxsignal = 0;
386 size_t nummdevents = 0;
387 for (size_t iws = 0; iws < numspec; ++iws) {
388 // Get detector positions and signal
389 double signal = dataws->y(iws)[0];
390 // Skip event with 0 signal
391 if (fabs(signal) < 0.001)
392 continue;
393 double error = sqrt(fabs(signal));
394 Kernel::V3D detpos = specInfo.position(iws);
395 std::vector<Mantid::coord_t> q_sample(3);
396
397 // Calculate Q-sample and new detector ID in virtual instrument.
398 Kernel::V3D qlab = convertToQSample(samplePos, ki, detpos, momentum, q_sample, rotationMatrix);
399 detid_t native_detid = specInfo.detector(iws).getID();
400 detid_t detid = native_detid + startdetid;
401
402 // Insert
403 inserter.insertMDEvent(static_cast<float>(signal), static_cast<float>(error * error),
404 static_cast<uint16_t>(runnumber), 0, detid, q_sample.data());
405 updateQRange(q_sample);
406
407 g_log.debug() << "Q-lab = " << qlab.toString() << "\n";
408 g_log.debug() << "Insert DetID " << detid << ", signal = " << signal << ", with q_sample = " << q_sample[0] << ", "
409 << q_sample[1] << ", " << q_sample[2] << "\n";
410
411 // Update some statistical inforamtion
412 if (signal > maxsignal)
413 maxsignal = signal;
414 ++nummdevents;
415 }
416
417 g_log.information() << "Imported Matrixworkspace of run number " << runnumber << ": Max. Signal = " << maxsignal
418 << ", Add " << nummdevents << " MDEvents "
419 << "\n";
420
421 // Add experiment info including instrument, goniometer and run number
422 ExperimentInfo_sptr expinfo = std::make_shared<ExperimentInfo>();
423 if (usevirtual)
424 expinfo->setInstrument(m_virtualInstrument);
425 else {
426 Geometry::Instrument_const_sptr tmp_inst = dataws->getInstrument();
427 expinfo->setInstrument(tmp_inst);
428 }
429 expinfo->mutableRun().setGoniometer(dataws->run().getGoniometer(), false);
430 int scan_run_number = scannumber * 1000 + runnumber;
431 expinfo->mutableRun().addProperty("run_number", scan_run_number);
432 expinfo->mutableRun().addProperty("duration", measuretime);
433 expinfo->mutableRun().addProperty("monitor", monitor_counts);
434 // Add all the other propertys from original data workspace
435 const std::vector<Kernel::Property *> vec_property = dataws->run().getProperties();
436 for (auto property : vec_property) {
437 expinfo->mutableRun().addProperty(property->clone());
438 }
439
440 m_outputWS->addExperimentInfo(expinfo);
441}
442
443//----------------------------------------------------------------------------------------------
450bool ConvertCWSDExpToMomentum::getInputs(bool virtualinstrument, std::string &errmsg) {
451 std::stringstream errss;
452
453 // Table workspace for data file names and starting detector IDs (for virtual
454 // instrument)
455 m_expDataTableWS = getProperty("InputWorkspace");
456 const std::vector<std::string> datacolnames = m_expDataTableWS->getColumnNames();
457 if (datacolnames.size() != 6) {
458 errss << "InputWorkspace must have 6 columns. But now it has " << datacolnames.size() << " columns. \n";
459 } else {
460 if (datacolnames[m_iColFilename] != "File Name" && datacolnames[m_iColFilename] != "Filename")
461 errss << "Data file name Table (InputWorkspace)'s Column " << m_iColFilename
462 << " must be 'File Name' or 'Filename' but not " << datacolnames[m_iColFilename] << ". "
463 << "\n";
464 if (datacolnames[m_iColStartDetID] != "Starting DetID" && datacolnames[m_iColStartDetID] != "StartDetID")
465 errss << "Data file name Table (InputWorkspace)'s Column " << m_iColStartDetID
466 << " must be 'Staring DetID' or 'StartDetID' but not " << datacolnames[m_iColStartDetID] << ". "
467 << "\n";
468 }
469 g_log.warning("Finished parsing Data Table");
470
471 // FIXME/TODO: Add the code to read monitor counts from input table workspace
472
473 // Set up parameters for creating virtual instrument
474 g_log.warning() << "About to deal with virtual instrument" << virtualinstrument << "\n";
475 if (virtualinstrument) {
476 // Table workspace for detector positions
477 m_detectorListTableWS = getProperty("DetectorTableWorkspace");
478 const std::vector<std::string> detcolnames = m_detectorListTableWS->getColumnNames();
479 if (detcolnames.size() != 5) {
480 errss << "Detector table (DetectorTableWorkspace) must have 5 columns"
481 << "\n";
482 }
483
484 // Sample and source position
485 std::vector<double> sourcepos = getProperty("SourcePosition");
486 if (sourcepos.size() != 3)
487 errss << "SourcePosition must have 3 items. Input has " << sourcepos.size() << " instead.\n";
488 else {
489 m_sourcePos.setX(sourcepos[0]);
490 m_sourcePos.setY(sourcepos[1]);
491 m_sourcePos.setZ(sourcepos[2]);
492 }
493
494 std::vector<double> samplepos = getProperty("SamplePosition");
495 if (samplepos.size() != 3) {
496 errss << "SamplePosition must have 3 items. Input has " << samplepos.size() << " instead.\n";
497 } else {
498 m_samplePos.setX(samplepos[0]);
499 m_samplePos.setY(samplepos[1]);
500 m_samplePos.setZ(samplepos[2]);
501 }
502 }
503
504 m_isBaseName = getProperty("IsBaseName");
505 if (m_isBaseName)
506 m_dataDir = getPropertyValue("Directory");
507
508 errmsg = errss.str();
509
510 return (errmsg.empty());
511}
512
513//----------------------------------------------------------------------------------------------
525 const Kernel::V3D &detPos, const double &momentum,
526 std::vector<coord_t> &qSample,
527 const Kernel::DblMatrix &rotationMatrix) {
528
529 // Use detector position and wavelength/Q to calcualte Q_lab
530 Kernel::V3D kf;
531 kf = (detPos - samplePos) * (momentum / (detPos - samplePos).norm());
532 Kernel::V3D q_lab = ki - kf;
533
534 // Calculate q_sample from qlab and R matrix
535 Kernel::V3D q_sample = rotationMatrix * q_lab;
536 qSample.resize(3);
537 qSample[0] = static_cast<float>(q_sample.X());
538 qSample[1] = static_cast<float>(q_sample.Y());
539 qSample[2] = static_cast<float>(q_sample.Z());
540
541 return q_lab;
542}
543
544//----------------------------------------------------------------------------------------------
553 std::string &errmsg) {
554 // Init output
556 errmsg = "";
557
558 // Load SPICE file
559 try {
560 auto loader = createChildAlgorithm("LoadSpiceXML2DDet");
561 loader->initialize();
562 loader->setProperty("Filename", filename);
563 // std::vector<size_t> sizelist(2);
564 // sizelist[0] = 256;
565 // sizelist[1] = 256;
566 // loader->setProperty("DetectorGeometry", sizelist);
567 loader->setProperty("LoadInstrument", true);
568 loader->setProperty("ShiftedDetectorDistance", m_detSampleDistanceShift);
569 loader->setProperty("DetectorCenterXShift", m_detXShift);
570 loader->setProperty("DetectorCenterYShift", m_detYShift);
571
572 // TODO/FIXME - This is not a nice solution for detector geometry
573 // std::string idffile = getPropertyValue("InstrumentFilename");
574 // if (idffile.size() > 0) {
575 // loader->setProperty("InstrumentFilename", idffile);
576 // loader->setProperty("DetectorGeometry", "512, 512");
577 // }
578
579 double wavelength = getProperty("UserDefinedWavelength");
580
581 if (wavelength != EMPTY_DBL())
582 loader->setProperty("UserSpecifiedWaveLength", wavelength);
583
584 loader->execute();
585
586 dataws = loader->getProperty("OutputWorkspace");
587 loaded = static_cast<bool>(dataws);
588 } catch (std::runtime_error &runerror) {
589 loaded = false;
590 errmsg = runerror.what();
591 }
592
593 return dataws;
594}
595
596//----------------------------------------------------------------------------------------------
602void ConvertCWSDExpToMomentum::parseDetectorTable(std::vector<Kernel::V3D> &vec_detpos,
603 std::vector<detid_t> &vec_detid) {
604 // Set vectors' sizes
605 size_t numrows = m_detectorListTableWS->rowCount();
606 vec_detpos.resize(numrows);
607 vec_detid.resize(numrows);
608
609 // Parse table
610 for (size_t i = 0; i < numrows; ++i) {
611 detid_t detid = m_detectorListTableWS->cell<int>(i, 0);
612 vec_detid[i] = detid;
613
614 double x = m_detectorListTableWS->cell<double>(i, 1);
615 double y = m_detectorListTableWS->cell<double>(i, 2);
616 double z = m_detectorListTableWS->cell<double>(i, 3);
617 Kernel::V3D detpos(x, y, z);
618 vec_detpos[i] = detpos;
619 }
620}
621
622//----------------------------------------------------------------------------------------------
627void ConvertCWSDExpToMomentum::updateQRange(const std::vector<Mantid::coord_t> &vec_q) {
628 for (size_t i = 0; i < vec_q.size(); ++i) {
629 if (m_setQRange) {
630 m_minQVec[i] = vec_q[i];
631 m_maxQVec[i] = vec_q[i];
632 m_setQRange = false;
633 } else if (vec_q[i] < m_minQVec[i])
634 m_minQVec[i] = vec_q[i];
635 else if (vec_q[i] > m_maxQVec[i])
636 m_maxQVec[i] = vec_q[i];
637 }
638}
639
645 if (dataws->getNumberHistograms() != m_backgroundWS->getNumberHistograms())
646 throw std::runtime_error("Impossible to have this situation");
647
648 size_t numhist = dataws->getNumberHistograms();
649 for (size_t i = 0; i < numhist; ++i) {
650 double bkgd_y = m_backgroundWS->y(i)[0];
651 if (fabs(bkgd_y) > 1.E-2) {
652 dataws->mutableY(i)[0] -= bkgd_y;
653 dataws->mutableE(i)[0] = std::sqrt(dataws->y(i)[0]);
654 }
655 }
656}
657
658} // namespace Mantid::MDAlgorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
double error
Definition: IndexPeaks.cpp:133
#define fabs(x)
Definition: Matrix.cpp:22
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
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
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
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
Definition: FileProperty.h:53
@ OptionalDirectory
to specify a directory that does not have to exist
Definition: FileProperty.h:55
A property class for workspaces.
Templated class for a multi-dimensional event "box".
Definition: MDBox.h:45
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.
MDEventInserter : Helper class that provides a generic interface for adding events to an MDWorkspace ...
Templated class for the multi-dimensional event workspace.
QSample : Q in the sample frame.
Definition: QSample.h:21
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
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
T Invert()
LU inversion routine.
Definition: Matrix.cpp:924
std::string str() const
Convert the matrix into a simple linear string expression.
Definition: Matrix.cpp:1564
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
std::string toString() const
Definition: V3D.cpp:340
void setZ(const double zz) noexcept
Set is z position.
Definition: V3D.h:230
double norm() const noexcept
Definition: V3D.h:263
void setX(const double xx) noexcept
Set is x position.
Definition: V3D.h:218
void setY(const double yy) noexcept
Set is y position.
Definition: V3D.h:224
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
ConvertCWSDExpToMomentum : TODO: DESCRIPTION.
void addMDEvents(bool usevirtual)
Add MDEvents to MDEventWorkspace from data set in the experiment Run number is determined by the row ...
API::IMDEventWorkspace_sptr createExperimentMDWorkspace()
Create output workspace.
void parseDetectorTable(std::vector< Kernel::V3D > &vec_detpos, std::vector< detid_t > &vec_detid)
Parase detetor table workspace to vector of detector positions.
void updateQRange(const std::vector< Mantid::coord_t > &vec_q)
Update (sample) Q range.
const std::string name() const override
Algorithm's name.
void init() override
Init to declare property.
API::MatrixWorkspace_sptr loadSpiceData(const std::string &filename, bool &loaded, std::string &errmsg)
Load SPICE data to Matrix workspace.
bool getInputs(bool virtualinstrument, std::string &errmsg)
Examine input.
double m_detSampleDistanceShift
Shifts in detector position set from user (calibration): all in the unit as meter.
Kernel::V3D convertToQSample(const Kernel::V3D &samplePos, const Kernel::V3D &ki, const Kernel::V3D &detPos, const double &momentum, std::vector< Mantid::coord_t > &qSample, const Kernel::DblMatrix &rotationMatrix)
Convert |Q| with detector position to Q_sample.
void removeBackground(const API::MatrixWorkspace_sptr &dataws)
Remove background from.
void setupTransferMatrix(const API::MatrixWorkspace_sptr &dataws, Kernel::DblMatrix &rotationMatrix)
Set goniometer to matrix workspace and get its rotation matrix R (from Q-sample to Q-lab and output 1...
void convertSpiceMatrixToMomentumMDEvents(const API::MatrixWorkspace_sptr &dataws, bool usevirtual, const detid_t &startdetid, const int scannumber, const int runnumber, double measuretime, int monitor_counts)
Convert a SPICE 2D Det MatrixWorkspace to MDEvents and append to an MDEventWorkspace It is optional t...
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< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
MANTID_GEOMETRY_DLL Geometry::Instrument_sptr createVirtualInstrument(Kernel::V3D sourcePos, Kernel::V3D samplePos, const std::vector< Kernel::V3D > &vecdetpos, const std::vector< detid_t > &vecdetid)
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
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,...
Definition: MDTypes.h:27
int32_t detid_t
Typedef for a detector ID.
Definition: SpectrumInfo.h:21
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54