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