Mantid
Loading...
Searching...
No Matches
SumSpectra.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 +
9#include "MantidAPI/Run.h"
20
21#include <functional>
22
23namespace Mantid::Algorithms {
24
25// Register the class into the algorithm factory
26DECLARE_ALGORITHM(SumSpectra)
27
28using namespace Kernel;
29using namespace API;
30using namespace DataObjects;
31
32namespace {
40bool validateSingleMatrixWorkspace(std::map<std::string, std::string> &validationOutput, const MatrixWorkspace &ws,
41 const int minIndex, const int maxIndex, const std::vector<int> &indices) {
42 bool success(true);
43 const auto numSpectra = static_cast<int>(ws.getNumberHistograms());
44 // check StartWorkSpaceIndex, >=0 done by validator
45 if (minIndex >= numSpectra) {
46 validationOutput["StartWorkspaceIndex"] = "Selected minimum workspace index is greater than available "
47 "spectra.";
48 success = false;
49 }
50 // check EndWorkspaceIndex in range
51 if (maxIndex != EMPTY_INT()) {
52 // check EndWorkspaceIndex in range
53 if (maxIndex >= numSpectra) {
54 validationOutput["EndWorkspaceIndex"] = "Selected maximum workspace index is greater than available "
55 "spectra.";
56 success = false;
57 // check StartWorkspaceIndex < EndWorkspaceIndex
58 }
59 }
60 // check ListOfWorkspaceIndices in range
61 if (std::any_of(indices.cbegin(), indices.cend(),
62 [numSpectra](const auto index) { return (index >= numSpectra) || (index < 0); })) {
63 validationOutput["ListOfWorkspaceIndices"] = "One or more indices out of range of available spectra.";
64 success = false;
65 }
66 return success;
67}
68
76void validateWorkspaceName(std::map<std::string, std::string> &validationOutput, const std::string &name,
77 const int minIndex, const int maxIndex, const std::vector<int> &indices) {
78 const auto &ads = AnalysisDataService::Instance();
79 if (!ads.doesExist(name))
80 return;
81 auto wsGroup = ads.retrieveWS<WorkspaceGroup>(name);
82 if (!wsGroup)
83 return;
84 size_t index = 0;
85 for (const auto &item : *wsGroup) {
86 auto matrixWs = std::dynamic_pointer_cast<MatrixWorkspace>(item);
87 if (!matrixWs) {
88 validationOutput["InputWorkspace"] = "Input group contains an invalid workspace type at item " +
89 std::to_string(index) + ". All members must be a MatrixWorkspace";
90 break;
91 }
92 if (!validateSingleMatrixWorkspace(validationOutput, *matrixWs, minIndex, maxIndex, indices)) {
93 break;
94 }
95 ++index;
96 }
97}
98} // namespace
99
104 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input,
105 std::make_shared<CommonBinsValidator>()),
106 "The workspace containing the spectra to be summed.");
107 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
108 "The name of the workspace to be created as the output of the algorithm. "
109 " A workspace of this name will be created and stored in the Analysis "
110 "Data Service.");
111
112 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
113 mustBePositive->setLower(0);
114 declareProperty("StartWorkspaceIndex", 0, mustBePositive, "The first Workspace index to be included in the summing");
115 declareProperty("EndWorkspaceIndex", EMPTY_INT(), mustBePositive,
116 "The last Workspace index to be included in the summing");
117
118 declareProperty(std::make_unique<Kernel::ArrayProperty<int>>("ListOfWorkspaceIndices"),
119 "A list of workspace indices as a string with ranges, for "
120 "example: 5-10,15,20-23. \n"
121 "Optional: if not specified, then the "
122 "Start/EndWorkspaceIndex fields are used alone. "
123 "If specified, the range and the list are combined (without "
124 "duplicating indices). For example, a range of 10 to 20 and "
125 "a list '12,15,26,28' gives '10-20,26,28'.");
126
127 declareProperty("IncludeMonitors", true, "Whether to include monitor spectra in the summation.");
128
129 declareProperty("WeightedSum", false,
130 "Instead of the usual spectra sum, calculate the weighted "
131 "sum. This has the form: \n"
132 ":math:`nSpectra "
133 "\\times\\Sigma(Signal_i/Error_i^2)/\\Sigma(1/Error_i^2)`\n "
134 "This property is ignored for event workspace.\n"
135 "The sums are defined for :math:`Error_i != 0` only, so the "
136 "values with zero error are dropped from the summation. To "
137 "estimate the number of dropped values see the "
138 "description. ");
139
140 declareProperty("RemoveSpecialValues", false,
141 "If enabled floating point special values such as NaN or Inf"
142 " are removed before the spectra are summed.");
143
144 declareProperty("MultiplyBySpectra", true,
145 "For unnormalized data one should multiply the weighted sum "
146 "by the number of spectra contributing to the bin.");
147 setPropertySettings("MultiplyBySpectra", std::make_unique<EnabledWhenProperty>("WeightedSum", IS_EQUAL_TO, "1"));
148
149 declareProperty("UseFractionalArea", true,
150 "Normalize the output workspace to the fractional area for "
151 "RebinnedOutput workspaces.");
152}
153
154/*
155 * Validate the input parameters
156 * @returns map with keys corresponding to properties with errors and values
157 * containing the error messages.
158 */
159std::map<std::string, std::string> SumSpectra::validateInputs() {
160 // create the map
161 std::map<std::string, std::string> validationOutput;
162
163 // Non-workspace checks
164 const int minIndex = getProperty("StartWorkspaceIndex");
165 const int maxIndex = getProperty("EndWorkspaceIndex");
166 if (minIndex > maxIndex) {
167 validationOutput["StartWorkspaceIndex"] = "Selected minimum workspace "
168 "index is greater than selected "
169 "maximum workspace index.";
170 validationOutput["EndWorkspaceIndex"] = "Selected maximum workspace index "
171 "is lower than selected minimum "
172 "workspace index.";
173 } else {
174 const std::vector<int> indices = getProperty("ListOfWorkspaceIndices");
175 if (MatrixWorkspace_const_sptr singleWs = getProperty("InputWorkspace")) {
176 validateSingleMatrixWorkspace(validationOutput, *singleWs, minIndex, maxIndex, indices);
177 } else {
178 validateWorkspaceName(validationOutput, getPropertyValue("InputWorkspace"), minIndex, maxIndex, indices);
179 }
180 }
181 return validationOutput;
182}
183
184namespace { // anonymous namespace
185// various checks on the workspace index to see if it should be included in the
186// sum if it is masked, the value of numMasked is incremented
187bool useSpectrum(const SpectrumInfo &spectrumInfo, const size_t wsIndex, const bool keepMonitors, size_t &numMasked) {
188 if (spectrumInfo.hasDetectors(wsIndex)) {
189 // Skip monitors, if the property is set to do so
190 if (!keepMonitors && spectrumInfo.isMonitor(wsIndex))
191 return false;
192 // Skip masked detectors
193 if (spectrumInfo.isMasked(wsIndex)) {
194 numMasked++;
195 return false;
196 }
197 }
198 return true;
199}
200} // anonymous namespace
201
206 // Try and retrieve the optional properties
207 m_keepMonitors = getProperty("IncludeMonitors");
208
209 // setup all of the outputs
210 MatrixWorkspace_sptr outputWorkspace = nullptr;
211 size_t numSpectra(0); // total number of processed spectra
212 size_t numMasked(0); // total number of the masked and skipped spectra
213 size_t numZeros(0); // number of spectra which have 0 value in the first column (used in special cases of evaluating
214 // how good Poissonian statistics is)
215
216 // Get the input workspace -- ths may be a temporary workspace with the special values replaced
218 auto spectrumInfo = localworkspace->spectrumInfo();
219 m_numberOfSpectra = static_cast<int>(localworkspace->getNumberHistograms());
220 numMasked = determineIndices(spectrumInfo, m_numberOfSpectra);
221 numSpectra = m_indices.size();
222 m_yLength = localworkspace->y(*(m_indices.begin())).size();
223
224 // determine the output spectrum number
225 m_outSpecNum = getOutputSpecNo(localworkspace);
226 g_log.information() << "Spectra remapping gives single spectra with spectra number: " << m_outSpecNum << "\n";
227
228 m_calculateWeightedSum = getProperty("WeightedSum");
229 m_multiplyByNumSpec = getProperty("MultiplyBySpectra");
230
231 EventWorkspace_const_sptr eventW = std::dynamic_pointer_cast<const EventWorkspace>(localworkspace);
232 if (eventW) {
233 Progress progress(this, 0.0, 1.0, m_indices.size());
235 g_log.warning("Ignoring request for WeightedSum");
237 }
238 outputWorkspace = create<EventWorkspace>(*eventW, 1, eventW->binEdges(0));
239
240 execEvent(outputWorkspace, progress, numZeros);
241 } else {
242 //-------Workspace 2D mode -----
243
244 // Create the 2D workspace for the output
245 outputWorkspace = API::WorkspaceFactory::Instance().create(
246 localworkspace, 1, localworkspace->x(*(m_indices.begin())).size(), m_yLength);
247
248 // This is the (only) output spectrum
249 auto &outSpec = outputWorkspace->getSpectrum(0);
250
251 // Copy over the bin boundaries
252 outSpec.setSharedX(localworkspace->sharedX(0));
253
254 // Build a new spectra map
255 outSpec.setSpectrumNo(m_outSpecNum);
256 outSpec.clearDetectorIDs();
257
258 for (size_t const i : m_indices) {
259 outSpec.addDetectorIDs(localworkspace->getSpectrum(i).getDetectorIDs());
260 }
261
262 Progress progress(this, 0.0, 1.0, m_yLength);
263 if (localworkspace->id() == "RebinnedOutput") {
264 // this version is for a special workspace that has fractional overlap information
265 // Transform to real workspace types
266 RebinnedOutput_const_sptr inWS = std::dynamic_pointer_cast<const RebinnedOutput>(localworkspace);
267 RebinnedOutput_sptr outWS = std::dynamic_pointer_cast<RebinnedOutput>(outputWorkspace);
269 doFractionalWeightedSum(inWS, outWS, progress, numZeros);
270 } else {
271 doFractionalSum(inWS, outWS, progress, numZeros);
272 }
273 } else {
274 // for things where all the bins are lined up
276 doSimpleWeightedSum(localworkspace, outSpec, progress, numZeros);
277 } else {
278 doSimpleSum(localworkspace, outSpec, progress, numZeros);
279 }
280 }
281 }
282
283 // set up the summing statistics
284 outputWorkspace->mutableRun().addProperty("NumAllSpectra", int(numSpectra), "", true);
285 outputWorkspace->mutableRun().addProperty("NumMaskSpectra", int(numMasked), "", true);
286 outputWorkspace->mutableRun().addProperty("NumZeroSpectra", int(numZeros), "", true);
287
288 // Assign it to the output workspace property
289 setProperty("OutputWorkspace", outputWorkspace);
290}
291
292size_t SumSpectra::determineIndices(SpectrumInfo const &spectrumInfo, const size_t numberOfSpectra) {
293 // assume that m_numberOfSpectra has been set
294 m_indices.clear();
295
296 // try the list form first
297 const std::vector<int> indices_list = getProperty("ListOfWorkspaceIndices");
298 m_indices.insert(indices_list.begin(), indices_list.end());
299
300 // add the range specified by the user
301 // this has been checked to be 0<= m_minWsInd <= maxIndex <=
302 // m_numberOfSpectra where maxIndex can be an EMPTY_INT
303 int minIndex = getProperty("StartWorkspaceIndex");
304 int maxIndex = getProperty("EndWorkspaceIndex");
305 if (isEmpty(maxIndex) && m_indices.empty()) {
306 maxIndex = static_cast<int>(numberOfSpectra - 1);
307 }
308
309 // create the indices in the range
310 size_t numMasked{0};
311 if (!isEmpty(maxIndex)) {
312 for (int i = minIndex; i <= maxIndex; i++) {
313 // only include indices that are not masked and, if requested, are not monitors.
314 // the number of masked spectra is counted in numMasked.
315 if (useSpectrum(spectrumInfo, static_cast<size_t>(i), m_keepMonitors, numMasked)) {
316 m_indices.insert(static_cast<size_t>(i));
317 }
318 }
319 }
320 return numMasked;
321}
322
330 // initial value - any included spectrum will do
331 specnum_t specId = localworkspace->getSpectrum(*m_indices.begin()).getSpectrumNo();
332
333 // the total number of spectra
334 size_t totalSpec = localworkspace->getNumberHistograms();
335
336 specnum_t temp;
337 for (const auto index : m_indices) {
338 if (index < totalSpec) {
339 temp = localworkspace->getSpectrum(index).getSpectrumNo();
340 if (temp < specId)
341 specId = temp;
342 }
343 }
344
345 return specId;
346}
347
354 // Get a copy of the input workspace
355 MatrixWorkspace_sptr wksp = getProperty("InputWorkspace");
356 bool replaceSpecialValues = getProperty("RemoveSpecialValues");
358 auto alg = createChildAlgorithm("ReplaceSpecialValues");
359 alg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", wksp);
360 std::string outName = "_" + wksp->getName() + "_clean";
361 alg->setProperty("OutputWorkspace", outName);
362 alg->setProperty("NaNValue", 0.0);
363 alg->setProperty("NaNError", 0.0);
364 alg->setProperty("InfinityValue", 0.0);
365 alg->setProperty("InfinityError", 0.0);
366 alg->executeAsChildAlg();
367 return alg->getProperty("OutputWorkspace");
368 } else {
369 // Skip any additional processing
370 return wksp;
371 }
372}
373
384 size_t &numZeros) {
385 // Get references to the output workspaces's data vectors
386 auto &YSum = outSpec.mutableY();
387 auto &YErrorSum = outSpec.mutableE();
388
389 // Loop over bins
390 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
391 YSum[jbin] = 0.;
392 YErrorSum[jbin] = 0.;
393 // add the values for this bin together using simple summation
394 for (size_t iwksp : m_indices) {
395 YSum[jbin] += inWS->y(iwksp)[jbin];
396 YErrorSum[jbin] += inWS->e(iwksp)[jbin] * inWS->e(iwksp)[jbin];
397 }
398 YErrorSum[jbin] = sqrt(YErrorSum[jbin]);
399 progress.report();
400 }
401 numZeros = 0;
402}
403
414 size_t &numZeros) {
415 // Get references to the output workspaces's data vectors
416 auto &YSum = outSpec.mutableY();
417 auto &YErrorSum = outSpec.mutableE();
418
419 std::vector<size_t> nZeroes(YSum.size(), 0);
420
421 // Loop over bins
422 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
423 double normalization = 0.;
424 YSum[jbin] = 0.;
425 YErrorSum[jbin] = 0.;
426 // loop over spectra
427 for (size_t iwksp : m_indices) {
428 double weight = 0.;
429 double e = inWS->e(iwksp)[jbin];
430 double y = inWS->y(iwksp)[jbin];
431 if (std::isnormal(e)) {
432 weight = 1. / (e * e);
433 } else {
434 weight = 0.;
435 nZeroes[jbin]++;
436 }
437 normalization += weight;
438 YSum[jbin] += weight * y;
439 }
440 // apply the normalization factor
441 if (normalization != 0.) {
442 normalization = 1. / normalization;
443 YSum[jbin] *= normalization;
444 // NOTE: the total error ends up being the root of the normalization factor
445 YErrorSum[jbin] = sqrt(normalization);
446 }
448 // NOTE: do not include the zero-weighted values in the number of spectra
449 YSum[jbin] *= double(m_indices.size() - nZeroes[jbin]);
450 YErrorSum[jbin] *= double(m_indices.size() - nZeroes[jbin]);
451 }
452 progress.report();
453 }
454 // add up all zeros across the bins to get the total number of spectra that were dropped from the sum
455 numZeros = std::accumulate(nZeroes.begin(), nZeroes.end(), size_t(0));
456}
457
467 Progress &progress, size_t &numZeros) {
468 // Check finalize state prior to the sum process, at the completion
469 // the output is unfinalized
470 auto isFinalized = inWS->isFinalized();
471
472 // Get references to the output workspaces's data vectors
473 auto &outSpec = outWS->getSpectrum(0);
474 auto &YSum = outSpec.mutableY();
475 auto &YErrorSum = outSpec.mutableE();
476 auto &FracSum = outWS->dataF(0);
477
478 // loop over bins
479 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
480 YSum[jbin] = 0.;
481 YErrorSum[jbin] = 0.;
482 FracSum[jbin] = 0.;
483 // loop over spectra
484 for (size_t iwksp : m_indices) {
485 // use the mappin y' --> y * fracVal and e' --> e * fracVal where fracVal is the fractional area for this bin
486 double fracVal = (isFinalized ? inWS->readF(iwksp)[jbin] : 1.0);
487 double y = inWS->y(iwksp)[jbin] * fracVal;
488 double e = inWS->e(iwksp)[jbin] * fracVal;
489 // no do simple sum of the mapped values
490 YSum[jbin] += y;
491 YErrorSum[jbin] += e * e;
492 FracSum[jbin] += inWS->readF(iwksp)[jbin];
493 }
494 YErrorSum[jbin] = sqrt(YErrorSum[jbin]);
495 progress.report();
496 }
497
498 numZeros = 0;
499
500 // Create the correct representation if using fractional area
501 auto useFractionalArea = getProperty("UseFractionalArea");
502 if (useFractionalArea) {
503 outWS->finalize(/*hasSqrdErrs =*/false);
504 }
505}
506
516 Progress &progress, size_t &numZeros) {
517 // Check finalize state prior to the sum process, at the completion
518 // the output is unfinalized
519 auto isFinalized = inWS->isFinalized();
520
521 // Get references to the output workspaces's data vectors
522 auto &outSpec = outWS->getSpectrum(0);
523 auto &YSum = outSpec.mutableY();
524 auto &YErrorSum = outSpec.mutableE();
525 auto &FracSum = outWS->dataF(0);
526
527 std::vector<size_t> nZeroes(YSum.size(), 0);
528
529 // Loop over bins
530 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
531 YSum[jbin] = 0.;
532 YErrorSum[jbin] = 0.;
533 FracSum[jbin] = 0.;
534 double normalization = 0.;
535 // loop over spectra
536 for (size_t iwksp : m_indices) {
537 // use the mappin y' --> y * fracVal and e' --> e * fracVal where fracVal is the fractional area for this bin
538 double fracVal = (isFinalized ? inWS->readF(iwksp)[jbin] : 1.0);
539 double y = inWS->y(iwksp)[jbin] * fracVal;
540 double e = inWS->e(iwksp)[jbin] * fracVal;
541 // now perform weghted sum of the mapped values
542 double weight = 0.;
543 if (std::isnormal(e)) { // is non-zero, nan, or infinity
544 weight = 1. / (e * e);
545 } else {
546 weight = 0.;
547 nZeroes[jbin]++;
548 }
549 normalization += weight;
550 YSum[jbin] += weight * y;
551 FracSum[jbin] += inWS->readF(iwksp)[jbin];
552 }
553 // apply the normalization factor
554 if (normalization != 0.) {
555 normalization = 1. / normalization;
556 YSum[jbin] *= normalization;
557 // NOTE: the total error is the sqrt of the normalization factor
558 YErrorSum[jbin] = sqrt(normalization);
559 }
561 // NOTE: do not include the zero-weighted values in the number of spectra
562 YSum[jbin] *= double(m_indices.size() - nZeroes[jbin]);
563 YErrorSum[jbin] *= double(m_indices.size() - nZeroes[jbin]);
564 }
565 progress.report();
566 }
567 numZeros = std::accumulate(nZeroes.begin(), nZeroes.end(), size_t(0));
568
569 // Create the correct representation if using fractional area
570 auto useFractionalArea = getProperty("UseFractionalArea");
571 if (useFractionalArea) {
572 outWS->finalize(/*hasSqrdErrs =*/false);
573 }
574}
575
582void SumSpectra::execEvent(const MatrixWorkspace_sptr &outputWorkspace, Progress &progress, size_t &numZeros) {
583 MatrixWorkspace_const_sptr localworkspace = getProperty("InputWorkspace");
584 EventWorkspace_const_sptr inputWorkspace = std::dynamic_pointer_cast<const EventWorkspace>(localworkspace);
585
586 // Get the pointer to the output event list
587 EventWorkspace_sptr outputEventWorkspace = std::dynamic_pointer_cast<EventWorkspace>(outputWorkspace);
588 EventList &outputEL = outputEventWorkspace->getSpectrum(0);
589 outputEL.setSpectrumNo(m_outSpecNum);
590 outputEL.clearDetectorIDs();
591
592 // count number of events for the output
593 std::size_t numOutputEvents{0};
594 for (const auto i : m_indices) {
595 numOutputEvents += inputWorkspace->getSpectrum(i).getNumberEvents();
596 }
597 outputEL.switchTo(inputWorkspace->getSpectrum(0).getEventType());
598 outputEL.reserve(numOutputEvents);
599
600 // Loop over spectra
601 for (const auto i : m_indices) {
602 // Add the event lists with the operator
603 const EventList &inputEL = inputWorkspace->getSpectrum(i);
604 if (inputEL.empty()) {
605 ++numZeros;
606 }
607 outputEL += inputEL;
608
609 progress.report();
610 }
611}
612
613} // namespace Mantid::Algorithms
std::string name
Definition Run.cpp:60
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
std::map< DeltaEMode::Type, std::string > index
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
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:422
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
A "spectrum" is an object that holds the data for a particular spectrum, in particular:
Definition ISpectrum.h:38
HistogramData::HistogramY & mutableY() &
Definition ISpectrum.h:177
void clearDetectorIDs()
Clear the detector IDs set.
void setSpectrumNo(specnum_t num)
Sets the spectrum number of this spectrum.
HistogramData::HistogramE & mutableE() &
Definition ISpectrum.h:181
Helper class for reporting progress from algorithms.
Definition Progress.h:25
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
bool isMonitor(const size_t index) const
Returns true if the detector(s) associated with the spectrum are monitors.
bool hasDetectors(const size_t index) const
Returns true if the spectrum is associated with detectors in the instrument.
bool isMasked(const size_t index) const
Returns true if the detector(s) associated with the spectrum are masked.
A property class for workspaces.
void doFractionalSum(RebinnedOutput_const_sptr const &, RebinnedOutput_sptr const &, API::Progress &, size_t &)
Handle logic for RebinnedOutput workspaces.
void doSimpleWeightedSum(API::MatrixWorkspace_const_sptr const &, API::ISpectrum &, API::Progress &, size_t &)
Perform a weighted sum of the spectra in the input workspace, where values in each bin are weighted b...
size_t m_yLength
Blocksize of the input workspace.
Definition SumSpectra.h:100
size_t determineIndices(API::SpectrumInfo const &, const size_t numberOfSpectra)
bool m_keepMonitors
Set true to keep monitors.
Definition SumSpectra.h:96
void exec() override
Executes the algorithm.
std::map< std::string, std::string > validateInputs() override
Cross-input validation.
void doFractionalWeightedSum(RebinnedOutput_const_sptr const &, RebinnedOutput_sptr const &, API::Progress &, size_t &)
This function handles the logic for summing RebinnedOutput workspaces.
specnum_t m_outSpecNum
The output spectrum number.
Definition SumSpectra.h:94
specnum_t getOutputSpecNo(const API::MatrixWorkspace_const_sptr &localworkspace)
Determine the minimum spectrum No for summing.
void execEvent(const API::MatrixWorkspace_sptr &outputWorkspace, API::Progress &progress, size_t &numZeros)
Executes the algorithm.
void init() override
Initialisation method.
API::MatrixWorkspace_sptr replaceSpecialValues()
Calls an algorithm to replace special values within the workspace such as NaN or Inf to 0.
void doSimpleSum(API::MatrixWorkspace_const_sptr const &, API::ISpectrum &, API::Progress &, size_t &)
Handle logic for summing standard workspaces.
size_t m_numberOfSpectra
numberOfSpectra in the input
Definition SumSpectra.h:98
std::set< size_t > m_indices
Set of indices to sum.
Definition SumSpectra.h:102
A class for holding :
Definition EventList.h:57
void reserve(size_t num) override
Reserve a certain number of entries in event list of the specified eventType.
void switchTo(Mantid::API::EventType newType) override
Switch the EventList to use the given EventType (TOF, WEIGHTED, or WEIGHTED_NOTIME)
bool empty() const
Much like stl containers, returns true if there is nothing in the event list.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings const > settings)
Add a PropertySettings instance to the chain of settings for a given property.
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
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
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< const RebinnedOutput > RebinnedOutput_const_sptr
shared pointer to a const RebinnedOutput
Definition SumSpectra.h:24
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::shared_ptr< RebinnedOutput > RebinnedOutput_sptr
shared pointer to the RebinnedOutput class
Definition SumSpectra.h:23
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition EmptyValues.h:24
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54