Mantid
Loading...
Searching...
No Matches
ConvertSpiceDataToRealSpace.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
10#include "MantidAPI/Run.h"
26
27#include <Poco/TemporaryFile.h>
28
29namespace Mantid::MDAlgorithms {
30
31using namespace Mantid::API;
32using namespace Mantid::Kernel;
33using namespace Mantid::DataObjects;
34using namespace Mantid::Geometry;
35using namespace Mantid::DataObjects;
36using Mantid::Types::Core::DateAndTime;
37
38DECLARE_ALGORITHM(ConvertSpiceDataToRealSpace)
39
40
43 declareProperty(std::make_unique<WorkspaceProperty<TableWorkspace>>("InputWorkspace", "", Direction::Input),
44 "Input table workspace for data.");
45
46 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("RunInfoWorkspace", "", Direction::Input),
47 "Input matrix workspace containing sample logs. "
48 "It can be the RunInfoWorkspace output from LoadSpiceAscii. "
49 "It serves as parent workspace in the algorithm.");
50
51 declareProperty("RunStart", "",
52 "User specified run start time of the experiment "
53 "in case that the run start time is not specified in the "
54 "input RunInfoWorkspace.");
55
57 std::array<std::string, 1> allowedinstruments = {{"HB2A"}};
58 auto instrumentvalidator = std::make_shared<ListValidator<std::string>>(allowedinstruments);
59 declareProperty("Instrument", "HB2A", instrumentvalidator, "Instrument to be loaded. ");
60
61 declareProperty("DetectorPrefix", "anode", "Prefix of the name for detectors. ");
62
63 declareProperty("RunNumberName", "Pt.", "Log name for run number/measurement point.");
64
65 declareProperty("RotationAngleLogName", "2theta", "Log name for rotation angle as the 2theta value of detector 0.");
66
67 declareProperty("MonitorCountsLogName", "monitor", "Name of the sample log to record monitor counts of each run.");
68
69 declareProperty("DurationLogName", "time", "Name of the sample log to record the duration of each run.");
70
71 declareProperty(std::make_unique<WorkspaceProperty<IMDEventWorkspace>>("OutputWorkspace", "", Direction::Output),
72 "Name to use for the output workspace.");
73
74 declareProperty(
75 std::make_unique<WorkspaceProperty<IMDEventWorkspace>>("OutputMonitorWorkspace", "", Direction::Output),
76 "Name to use for the output workspace.");
77
78 declareProperty(std::make_unique<WorkspaceProperty<TableWorkspace>>("DetectorEfficiencyTableWorkspace", "",
80 "Name of a table workspace containing the detectors' efficiency.");
81}
82
86 // Process inputs
87 DataObjects::TableWorkspace_sptr dataTableWS = getProperty("InputWorkspace");
88 MatrixWorkspace_const_sptr parentWS = getProperty("RunInfoWorkspace");
89 m_instrumentName = getPropertyValue("Instrument");
90
91 DataObjects::TableWorkspace_sptr detEffTableWS = getProperty("DetectorEfficiencyTableWorkspace");
92 std::map<detid_t, double> detEffMap; // map for detector efficiency
93 if (detEffTableWS)
94 detEffMap = parseDetectorEfficiencyTable(detEffTableWS);
95
96 // Check whether parent workspace has run start: order (1) parent ws, (2) user
97 // given (3) nothing
98 DateAndTime runstart(1000000000);
99 bool hasrunstartset = false;
100 if (parentWS->run().hasProperty("run_start")) {
101 // Use parent workspace's first
102 std::string runstartstr = parentWS->run().getProperty("run_start")->value();
103 try {
104 DateAndTime temprunstart(runstartstr);
105 runstart = temprunstart;
106 hasrunstartset = true;
107 } catch (...) {
108 g_log.warning() << "run_start from info matrix workspace is not correct. "
109 << "It cannot be convert from '" << runstartstr << "'."
110 << "\n";
111 }
112 }
113
114 // from properties
115 if (!hasrunstartset) {
116 // Use user given
117 std::string runstartstr = getProperty("RunStart");
118 try {
119 DateAndTime temprunstart(runstartstr);
120 runstart = temprunstart;
121 hasrunstartset = true;
122 } catch (...) {
123 g_log.warning() << "RunStart from input property is not correct. "
124 << "It cannot be convert from '" << runstartstr << "'."
125 << "\n";
126 }
127 }
128
129 if (!hasrunstartset)
130 g_log.warning("Run-start time is not defined either in "
131 "input parent workspace or given by user. 1990-01-01 "
132 "00:00:01 is used");
133
134 // Convert table workspace to a list of 2D workspaces
135 std::map<std::string, std::vector<double>> logvecmap;
136 std::vector<Types::Core::DateAndTime> vectimes;
137
138 // Set up range for x/y/z
139 m_extentMins.resize(3);
140 m_extentMaxs.resize(3);
141 for (size_t i = 0; i < 3; ++i) {
142 m_extentMins[i] = DBL_MAX;
143 m_extentMaxs[i] = -DBL_MAX;
144 }
145
146 std::vector<MatrixWorkspace_sptr> vec_ws2d =
147 convertToMatrixWorkspace(dataTableWS, parentWS, runstart, logvecmap, vectimes);
148
149 // Apply detector efficiency
150 if (!detEffMap.empty())
151 correctByDetectorEfficiency(vec_ws2d, detEffMap);
152
153 // check range for x/y/z
154 m_numBins.resize(3);
155 for (size_t d = 0; d < 3; ++d) {
156 if (fabs(m_extentMins[d] - m_extentMaxs[d]) < 1.0E-6) {
157 // Range is too small so treat it as 1 value
158 double mvalue = m_extentMins[d];
159 m_extentMins[d] = mvalue - 0.1;
160 m_extentMaxs[d] = mvalue + 0.1;
161 m_numBins[d] = 1;
162 } else {
163 m_numBins[d] = 100;
164 }
165 }
166
167 // Convert to MD workspaces
168 g_log.debug("About to converting to workspaces done!");
169 IMDEventWorkspace_sptr m_mdEventWS = createDataMDWorkspace(vec_ws2d);
170 std::string monitorlogname = getProperty("MonitorCountsLogName");
171 IMDEventWorkspace_sptr mdMonitorWS = createMonitorMDWorkspace(vec_ws2d, logvecmap[monitorlogname]);
172
173 // Add experiment info for each run and sample log to the first experiment
174 // info object
175 addExperimentInfos(m_mdEventWS, vec_ws2d);
176 addExperimentInfos(mdMonitorWS, vec_ws2d);
177 appendSampleLogs(m_mdEventWS, logvecmap, vectimes);
178
179 // Set property
180 setProperty("OutputWorkspace", m_mdEventWS);
181 setProperty("OutputMonitorWorkspace", mdMonitorWS);
182}
183
184//------------------------------------------------------------------------------------------------
196 Types::Core::DateAndTime runstart, std::map<std::string, std::vector<double>> &logvecmap,
197 std::vector<Types::Core::DateAndTime> &vectimes) {
198 // Get table workspace's column information
199 size_t ipt, irotangle, itime;
200 std::vector<std::pair<size_t, size_t>> anodelist;
201 std::map<std::string, size_t> sampleindexlist;
202 readTableInfo(tablews, ipt, irotangle, itime, anodelist, sampleindexlist);
203 m_numSpec = anodelist.size();
204
205 // Load data
206 size_t numws = tablews->rowCount();
207 std::vector<MatrixWorkspace_sptr> vecws(numws);
208 double duration = 0;
209 vectimes.resize(numws);
210 for (size_t irow = 0; irow < numws; ++irow) {
211 vecws[irow] = loadRunToMatrixWS(tablews, irow, parentws, runstart, ipt, irotangle, itime, anodelist, duration);
212 vectimes[irow] = runstart;
213 runstart += static_cast<int64_t>(duration * 1.0E9);
214 }
215
216 // Process log data which will not be put to matrix workspace but will got to
217 // MDWorkspace
218 parseSampleLogs(tablews, sampleindexlist, logvecmap);
219
220 g_log.debug() << "Number of matrix workspaces in vector = " << vecws.size() << "\n";
221 return vecws;
222}
223
224//------------------------------------------------------------------------------------------------
232 const std::map<std::string, size_t> &indexlist,
233 std::map<std::string, std::vector<double>> &logvecmap) {
234 size_t numrows = tablews->rowCount();
235
236 std::map<std::string, size_t>::const_iterator indexiter;
237 for (indexiter = indexlist.begin(); indexiter != indexlist.end(); ++indexiter) {
238 std::string logname = indexiter->first;
239 size_t icol = indexiter->second;
240
241 g_log.debug() << " Parsing log " << logname << "\n";
242
243 std::vector<double> logvec(numrows);
244 for (size_t ir = 0; ir < numrows; ++ir) {
245 auto dbltemp = tablews->cell_cast<double>(ir, icol);
246 logvec[ir] = dbltemp;
247 }
248
249 logvecmap.emplace(logname, logvec);
250 }
251}
252
253//------------------------------------------------------------------------------------------------
268 const DataObjects::TableWorkspace_sptr &tablews, size_t irow, const MatrixWorkspace_const_sptr &parentws,
269 Types::Core::DateAndTime runstart, size_t ipt, size_t irotangle, size_t itime,
270 const std::vector<std::pair<size_t, size_t>> &anodelist, double &duration) {
271 // New workspace from parent workspace
272 MatrixWorkspace_sptr tempws = WorkspaceFactory::Instance().create(parentws, m_numSpec, 2, 1);
273
274 // Set up angle, time and run number
275 double twotheta = tablews->cell<double>(irow, irotangle);
276 TimeSeriesProperty<double> *prop2theta = new TimeSeriesProperty<double>("rotangle");
277
278 prop2theta->addValue(runstart, twotheta);
279 tempws->mutableRun().addProperty(prop2theta);
280
282 proprunstart->addValue(runstart, runstart.toISO8601String());
283
284 g_log.debug() << "Run " << irow << ": set run start to " << runstart.toISO8601String() << "\n";
285 if (tempws->run().hasProperty("run_start")) {
286 g_log.information() << "Temporary workspace inherites run_start as "
287 << tempws->run().getProperty("run_start")->value()
288 << ". It will be replaced by the correct value. "
289 << "\n";
290 tempws->mutableRun().removeProperty("run_start");
291 }
292 tempws->mutableRun().addProperty(proprunstart);
293
294 int pt = tablews->cell<int>(irow, ipt);
295 tempws->mutableRun().addProperty(new PropertyWithValue<int>("run_number", pt));
296
297 // Load instrument
298 auto instloader = createChildAlgorithm("LoadInstrument");
299 instloader->initialize();
300 instloader->setProperty("InstrumentName", m_instrumentName);
301 instloader->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(true));
302 instloader->setProperty("Workspace", tempws);
303 instloader->execute();
304
305 tempws = instloader->getProperty("Workspace");
306
307 // Import data
308 const auto &specInfo = tempws->spectrumInfo();
309 for (size_t i = 0; i < m_numSpec; ++i) {
310 const auto &pos = specInfo.position(i);
311 tempws->mutableX(i)[0] = pos[0] + 0.01;
312 double yvalue = tablews->cell<double>(irow, anodelist[i].second);
313 tempws->mutableY(i)[0] = yvalue;
314 tempws->mutableE(i)[0] = std::max(sqrt(yvalue), 1.0);
315 // update X-range, Y-range and Z-range
316 for (size_t d = 0; d < 3; ++d) {
317 if (pos[d] < m_extentMins[d])
318 m_extentMins[d] = pos[d];
319 if (pos[d] > m_extentMaxs[d])
320 m_extentMaxs[d] = pos[d];
321 }
322 }
323
324 // Return duration
325 duration = tablews->cell<double>(irow, itime);
326
327 return tempws;
328}
329
330//------------------------------------------------------------------------------------------------
341 size_t &irotangle, size_t &itime,
342 std::vector<std::pair<size_t, size_t>> &anodelist,
343 std::map<std::string, size_t> &samplenameindexmap) {
344
345 // Get detectors' names and other sample names
346 std::string anodelogprefix = getProperty("DetectorPrefix");
347 const std::vector<std::string> &colnames = tablews->getColumnNames();
348 for (size_t icol = 0; icol < colnames.size(); ++icol) {
349 const std::string &colname = colnames[icol];
350
351 if (colname.starts_with(anodelogprefix)) {
352 // anode
353 std::vector<std::string> terms;
354 boost::split(terms, colname, boost::is_any_of(anodelogprefix));
355 auto anodeid = static_cast<size_t>(std::stoi(terms.back()));
356 anodelist.emplace_back(anodeid, icol);
357 } else {
358 samplenameindexmap.emplace(colname, icol);
359 }
360 } // ENDFOR (icol)
361
362 // Check detectors' names
363 if (anodelist.empty()) {
364 std::stringstream errss;
365 errss << "There is no log name starting with " << anodelogprefix << " for detector. ";
366 throw std::runtime_error(errss.str());
367 }
368
369 // Find out other essential sample log names
370 std::map<std::string, size_t>::iterator mapiter;
371
372 std::string ptname = getProperty("RunNumberName"); // "Pt."
373 std::string monitorlogname = getProperty("MonitorCountsLogName"); //"monitor"
374 std::string durationlogname = getProperty("DurationLogName"); //"time"
375 std::string rotanglelogname = getProperty("RotationAngleLogName"); // "2theta"
376
377 std::vector<std::string> lognames{ptname, monitorlogname, durationlogname, rotanglelogname};
378
379 std::vector<size_t> ilognames(lognames.size());
380
381 for (size_t i = 0; i < lognames.size(); ++i) {
382 const std::string &logname = lognames[i];
383 mapiter = samplenameindexmap.find(logname);
384 if (mapiter != samplenameindexmap.end()) {
385 ilognames[i] = mapiter->second;
386 } else {
387 std::stringstream ess;
388 ess << "Essential log name " << logname << " cannot be found in data table workspace.";
389 throw std::runtime_error(ess.str());
390 }
391 }
392
393 // Retrieve the vector index
394 ipt = ilognames[0];
395 itime = ilognames[2];
396 irotangle = ilognames[3];
397
398 // Sort out anode id index list;
399 std::sort(anodelist.begin(), anodelist.end());
400}
401
402//------------------------------------------------------------------------------------------------
410 const std::map<std::string, std::vector<double>> &logvecmap,
411 const std::vector<Types::Core::DateAndTime> &vectimes) {
412 // Check!
413 size_t numexpinfo = mdws->getNumExperimentInfo();
414 if (numexpinfo == 0)
415 throw std::runtime_error("There is no ExperimentInfo defined for MDWorkspace. "
416 "It is impossible to add any log!");
417 else if (numexpinfo != vectimes.size() + 1)
418 throw std::runtime_error("The number of ExperimentInfo should be 1 more than "
419 "the length of vector of time, i.e., number of matrix workspaces.");
420
421 std::map<std::string, std::vector<double>>::const_iterator miter;
422
423 // get runnumber vector
424 std::string runnumlogname = getProperty("RunNumberName");
425 miter = logvecmap.find(runnumlogname);
426 if (miter == logvecmap.end())
427 throw std::runtime_error("Impossible not to find Pt. in log vec map.");
428 const std::vector<double> &vecrunno = miter->second;
429
430 // Add run_start and start_time to each ExperimentInfo
431 for (size_t i = 0; i < vectimes.size(); ++i) {
432 Types::Core::DateAndTime runstart = vectimes[i];
433 mdws->getExperimentInfo(static_cast<uint16_t>(i))
434 ->mutableRun()
435 .addLogData(new PropertyWithValue<std::string>("run_start", runstart.toFormattedString()));
436 }
437 mdws->getExperimentInfo(static_cast<uint16_t>(vectimes.size()))
438 ->mutableRun()
439 .addLogData(new PropertyWithValue<std::string>("run_start", vectimes[0].toFormattedString()));
440
441 // Add sample logs
442 // get hold of last experiment info
443 ExperimentInfo_sptr eilast = mdws->getExperimentInfo(static_cast<uint16_t>(numexpinfo - 1));
444
445 for (miter = logvecmap.begin(); miter != logvecmap.end(); ++miter) {
446 std::string logname = miter->first;
447 const std::vector<double> &veclogval = miter->second;
448
449 // Check log values and times
450 if (veclogval.size() != vectimes.size()) {
451 g_log.error() << "Log " << logname << " has different number of log values (" << veclogval.size()
452 << ") than number of log entry time (" << vectimes.size() << ")"
453 << "\n";
454 continue;
455 }
456
457 // For N single value experiment info
458 for (uint16_t i = 0; i < static_cast<uint16_t>(veclogval.size()); ++i) {
459 // get ExperimentInfo
460 ExperimentInfo_sptr tmpei = mdws->getExperimentInfo(i);
461 // check run number matches
462 int runnumber = std::stoi(tmpei->run().getProperty("run_number")->value());
463 if (runnumber != static_cast<int>(vecrunno[i]))
464 throw std::runtime_error("Run number does not match to Pt. value.");
465 // add property
466 tmpei->mutableRun().addLogData(new PropertyWithValue<double>(logname, veclogval[i]));
467 }
468
469 // Create a new log
470 auto templog = new TimeSeriesProperty<double>(logname);
471 templog->addValues(vectimes, veclogval);
472
473 // Add log to experiment info
474 eilast->mutableRun().addLogData(templog);
475 }
476}
477
478//------------------------------------------------------------------------------------------------
485 const std::vector<API::MatrixWorkspace_sptr> &vec_ws2d) {
486 // Add N experiment info as there are N measurment points
487 for (const auto &ws2d : vec_ws2d) {
488 // Create an ExperimentInfo object
489 ExperimentInfo_sptr tmp_expinfo = std::make_shared<ExperimentInfo>();
490 Geometry::Instrument_const_sptr tmp_inst = ws2d->getInstrument();
491 tmp_expinfo->setInstrument(tmp_inst);
492
493 int runnumber = std::stoi(ws2d->run().getProperty("run_number")->value());
494 tmp_expinfo->mutableRun().addProperty(new PropertyWithValue<int>("run_number", runnumber));
495
496 // Add ExperimentInfo to workspace
497 mdws->addExperimentInfo(tmp_expinfo);
498 }
499
500 // Add one additional in order to contain the combined sample logs
501 ExperimentInfo_sptr combine_expinfo = std::make_shared<ExperimentInfo>();
502 combine_expinfo->mutableRun().addProperty(new PropertyWithValue<int>("run_number", -1));
503 mdws->addExperimentInfo(combine_expinfo);
504}
505
506//------------------------------------------------------------------------------------------------
513ConvertSpiceDataToRealSpace::createDataMDWorkspace(const std::vector<MatrixWorkspace_sptr> &vec_ws2d) {
514
515 // Create a target output workspace.
517
518 // Extract Dimensions and add to the output workspace.
519
520 std::vector<std::string> vec_ID(3);
521 vec_ID[0] = "x";
522 vec_ID[1] = "y";
523 vec_ID[2] = "z";
524
525 std::vector<std::string> vec_name(3);
526 vec_name[0] = "X";
527 vec_name[1] = "Y";
528 vec_name[2] = "Z";
529
530 // Create MDFrame of General Frame type
532
533 // Add dimensions
534 for (size_t i = 0; i < m_nDimensions; ++i) {
535 std::string id = vec_ID[i];
536 std::string name = vec_name[i];
537
538 for (size_t d = 0; d < 3; ++d)
539 g_log.debug() << "Direction " << d << ", Range = " << m_extentMins[d] << ", " << m_extentMaxs[d] << "\n";
541 id, name, frame, static_cast<coord_t>(m_extentMins[i]), static_cast<coord_t>(m_extentMaxs[i]), m_numBins[i])));
542 }
543
544 // Add events
545 // Creates a new instance of the MDEventInserter.
546 MDEventWorkspace<MDEvent<3>, 3>::sptr MDEW_MDEVENT_3 =
547 std::dynamic_pointer_cast<MDEventWorkspace<MDEvent<3>, 3>>(outWs);
548
549 MDEventInserter<MDEventWorkspace<MDEvent<3>, 3>::sptr> inserter(MDEW_MDEVENT_3);
550
551 for (const auto &thisWorkspace : vec_ws2d) {
552 uint16_t runnumber = static_cast<uint16_t>(std::stoi(thisWorkspace->run().getProperty("run_number")->value()));
553
554 detid_t detindex = 0;
555
556 size_t nHist = thisWorkspace->getNumberHistograms();
557 const auto &specInfo = thisWorkspace->spectrumInfo();
558 for (std::size_t i = 0; i < nHist; ++i) {
559 const auto &vecsignal = thisWorkspace->y(i);
560 const auto &vecerror = thisWorkspace->e(i);
561 auto signal = static_cast<float>(vecsignal[0]);
562 auto error = static_cast<float>(vecerror[0]);
563 const auto &detPos = specInfo.position(i);
564 detid_t detid = specInfo.firstDetectorID(i) + detindex;
565 Mantid::coord_t data[3];
566 data[0] = static_cast<float>(detPos.X());
567 data[1] = static_cast<float>(detPos.Y());
568 data[2] = static_cast<float>(detPos.Z());
569 inserter.insertMDEvent(signal, error * error, runnumber, 0, detid, data);
570 } // ENDFOR(spectrum)
571 } // ENDFOR (workspace)
572
573 return outWs;
574}
575
576//------------------------------------------------------------------------------------------------
584ConvertSpiceDataToRealSpace::createMonitorMDWorkspace(const std::vector<MatrixWorkspace_sptr> &vec_ws2d,
585 const std::vector<double> &vecmonitor) {
586 // Create a target output workspace.
588
589 // Extract Dimensions and add to the output workspace.
590
591 std::vector<std::string> vec_ID(3);
592 vec_ID[0] = "x";
593 vec_ID[1] = "y";
594 vec_ID[2] = "z";
595
596 std::vector<std::string> vec_name(3);
597 vec_name[0] = "X";
598 vec_name[1] = "Y";
599 vec_name[2] = "Z";
600
601 // Create MDFrame of General Frame type
603
604 // Add dimensions
605 for (size_t i = 0; i < m_nDimensions; ++i) {
606 std::string id = vec_ID[i];
607 std::string name = vec_name[i];
608
610 id, name, frame, static_cast<coord_t>(m_extentMins[i]), static_cast<coord_t>(m_extentMaxs[i]), m_numBins[i])));
611 }
612
613 // Add events
614 // Creates a new instance of the MDEventInserter.
615 MDEventWorkspace<MDEvent<3>, 3>::sptr MDEW_MDEVENT_3 =
616 std::dynamic_pointer_cast<MDEventWorkspace<MDEvent<3>, 3>>(outWs);
617
618 MDEventInserter<MDEventWorkspace<MDEvent<3>, 3>::sptr> inserter(MDEW_MDEVENT_3);
619
620 for (size_t iws = 0; iws < vec_ws2d.size(); ++iws) {
621 API::MatrixWorkspace_sptr thisWorkspace = vec_ws2d[iws];
622 short unsigned int runnumber =
623 static_cast<short unsigned int>(std::stoi(thisWorkspace->run().getProperty("run_number")->value()));
624
625 detid_t detindex = 0;
626 auto signal = static_cast<float>(vecmonitor[iws]);
627 float error = 1;
628 if (signal > 1)
629 error = std::sqrt(signal);
630
631 size_t nHist = thisWorkspace->getNumberHistograms();
632 const auto &specInfo = thisWorkspace->spectrumInfo();
633 for (std::size_t i = 0; i < nHist; ++i) {
634 // For each spectrum/detector
635 const auto &detPos = specInfo.position(i);
636 detid_t detid = specInfo.firstDetectorID(i) + detindex;
637 Mantid::coord_t data[3];
638 data[0] = static_cast<float>(detPos.X());
639 data[1] = static_cast<float>(detPos.Y());
640 data[2] = static_cast<float>(detPos.Z());
641 inserter.insertMDEvent(signal, error * error, runnumber, 0, detid, data);
642 } // ENDFOR(spectrum)
643 } // ENDFOR (workspace)
644
645 return outWs;
646}
647
648//------------------------------------------------------------------------------------------------
654std::map<detid_t, double>
656 std::map<detid_t, double> deteffmap;
657
658 // check table workspace
659 size_t numcols = detefftablews->columnCount();
660 if (numcols != 2)
661 throw std::runtime_error("Input tableworkspace must have 2 and only 2 columns.");
662
663 // parse the detector
664 size_t numrows = detefftablews->rowCount();
665 for (size_t i = 0; i < numrows; ++i) {
666 detid_t detid = detefftablews->cell<detid_t>(i, 0);
667 double deteff = detefftablews->cell<double>(i, 1);
668 deteffmap.emplace(detid, deteff);
669 }
670
671 return deteffmap;
672}
673
674//------------------------------------------------------------------------------------------------
680void ConvertSpiceDataToRealSpace::correctByDetectorEfficiency(std::vector<MatrixWorkspace_sptr> vec_ws2d,
681 const std::map<detid_t, double> &detEffMap) {
682 std::vector<MatrixWorkspace_sptr>::iterator it;
683 std::map<detid_t, double>::const_iterator detiter;
684 for (it = vec_ws2d.begin(); it != vec_ws2d.end(); ++it) {
685 MatrixWorkspace_sptr ws = *it;
686 const auto &specInfo = ws->spectrumInfo();
687 size_t numspec = ws->getNumberHistograms();
688 for (size_t iws = 0; iws < numspec; ++iws) {
689 if (!specInfo.hasDetectors(iws))
690 throw Kernel::Exception::NotFoundError("No detector found for workspace index", iws);
691 detid_t detid = specInfo.firstDetectorID(iws);
692 detiter = detEffMap.find(detid);
693 if (detiter != detEffMap.end())
694 ws->mutableY(iws)[0] /= detiter->second;
695 }
696 }
697}
698
699} // namespace Mantid::MDAlgorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:547
double error
#define fabs(x)
Definition Matrix.cpp:22
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
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.
Kernel::Logger & g_log
Definition Algorithm.h:426
A property class for workspaces.
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.
GeneralFrame : Any MDFrame that isn't related to momemtum transfer.
static const std::string GeneralFrameDistance
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 debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
OptionalBool : Tri-state bool.
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 specialised Property class for holding a series of time-value pairs.
void addValue(const Types::Core::DateAndTime &time, const TYPE &value)
Add a value to the map using a DateAndTime object.
ConvertSpiceDataToRealSpace : Convert data from SPICE file to singals in real space contained in MDEv...
void addExperimentInfos(const API::IMDEventWorkspace_sptr &mdws, const std::vector< API::MatrixWorkspace_sptr > &vec_ws2d)
Append Experiment Info.
size_t m_nDimensions
Dimension of the output MDEventWorkspace.
void readTableInfo(const DataObjects::TableWorkspace_const_sptr &tablews, size_t &ipt, size_t &irotangle, size_t &itime, std::vector< std::pair< size_t, size_t > > &anodelist, std::map< std::string, size_t > &samplenameindexmap)
Read parameter information from table workspace.
std::vector< double > m_extentMaxs
x-y-z value maximum
API::MatrixWorkspace_sptr loadRunToMatrixWS(const DataObjects::TableWorkspace_sptr &tablews, size_t irow, const API::MatrixWorkspace_const_sptr &parentws, Types::Core::DateAndTime runstart, size_t ipt, size_t irotangle, size_t itime, const std::vector< std::pair< size_t, size_t > > &anodelist, double &duration)
Load one run (one pt.) to a matrix workspace.
const std::string name() const override
Algorithm's name.
void appendSampleLogs(const API::IMDEventWorkspace_sptr &mdws, const std::map< std::string, std::vector< double > > &logvecmap, const std::vector< Types::Core::DateAndTime > &vectimes)
Append sample logs to MD workspace.
void correctByDetectorEfficiency(std::vector< API::MatrixWorkspace_sptr > vec_ws2d, const std::map< detid_t, double > &detEffMap)
Apply the detector's efficiency correction to.
std::vector< API::MatrixWorkspace_sptr > convertToMatrixWorkspace(const DataObjects::TableWorkspace_sptr &tablews, const API::MatrixWorkspace_const_sptr &parentws, Types::Core::DateAndTime runstart, std::map< std::string, std::vector< double > > &logvecmap, std::vector< Types::Core::DateAndTime > &vectimes)
Parse data table workspace to a vector of matrix workspaces.
void parseSampleLogs(const DataObjects::TableWorkspace_sptr &tablews, const std::map< std::string, size_t > &indexlist, std::map< std::string, std::vector< double > > &logvecmap)
Return sample logs.
API::IMDEventWorkspace_sptr createMonitorMDWorkspace(const std::vector< API::MatrixWorkspace_sptr > &vec_ws2d, const std::vector< double > &vecmonitor)
Create an MDWorkspace for monitor counts.
std::map< detid_t, double > parseDetectorEfficiencyTable(const DataObjects::TableWorkspace_sptr &detefftablews)
Parse detector efficiency table workspace to map.
API::IMDEventWorkspace_sptr createDataMDWorkspace(const std::vector< API::MatrixWorkspace_sptr > &vec_ws2d)
Create an MDEventWorspace by converting vector of matrix workspace data.
std::vector< double > m_extentMins
x-y-z-value minimum
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< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< const TableWorkspace > TableWorkspace_const_sptr
shared pointer to Mantid::DataObjects::TableWorkspace (const version)
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.
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.
@ Input
An input workspace.
Definition Property.h:54
@ Output
An output workspace.
Definition Property.h:55