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 <algorithm>
22#include <functional>
23
24namespace Mantid::Algorithms {
25
26// Register the class into the algorithm factory
27DECLARE_ALGORITHM(SumSpectra)
28
29using namespace Kernel;
30using namespace API;
31using namespace DataObjects;
32
33namespace {
41bool validateSingleMatrixWorkspace(std::map<std::string, std::string> &validationOutput, const MatrixWorkspace &ws,
42 const int minIndex, const int maxIndex, const std::vector<int> &indices) {
43 bool success(true);
44 const auto numSpectra = static_cast<int>(ws.getNumberHistograms());
45 // check StartWorkSpaceIndex, >=0 done by validator
46 if (minIndex >= numSpectra) {
47 validationOutput["StartWorkspaceIndex"] = "Selected minimum workspace index is greater than available "
48 "spectra.";
49 success = false;
50 }
51 // check EndWorkspaceIndex in range
52 if (maxIndex != EMPTY_INT()) {
53 // check EndWorkspaceIndex in range
54 if (maxIndex >= numSpectra) {
55 validationOutput["EndWorkspaceIndex"] = "Selected maximum workspace index is greater than available "
56 "spectra.";
57 success = false;
58 // check StartWorkspaceIndex < EndWorkspaceIndex
59 }
60 }
61 // check ListOfWorkspaceIndices in range
62 if (std::any_of(indices.cbegin(), indices.cend(),
63 [numSpectra](const auto index) { return (index >= numSpectra) || (index < 0); })) {
64 validationOutput["ListOfWorkspaceIndices"] = "One or more indices out of range of available spectra.";
65 success = false;
66 }
67 return success;
68}
69
77void validateWorkspaceName(std::map<std::string, std::string> &validationOutput, const std::string &name,
78 const int minIndex, const int maxIndex, const std::vector<int> &indices) {
79 const auto &ads = AnalysisDataService::Instance();
80 if (!ads.doesExist(name))
81 return;
82 auto wsGroup = ads.retrieveWS<WorkspaceGroup>(name);
83 if (!wsGroup)
84 return;
85 size_t index = 0;
86 for (const auto &item : *wsGroup) {
87 auto matrixWs = std::dynamic_pointer_cast<MatrixWorkspace>(item);
88 if (!matrixWs) {
89 validationOutput["InputWorkspace"] = "Input group contains an invalid workspace type at item " +
90 std::to_string(index) + ". All members must be a MatrixWorkspace";
91 break;
92 }
93 if (!validateSingleMatrixWorkspace(validationOutput, *matrixWs, minIndex, maxIndex, indices)) {
94 break;
95 }
96 ++index;
97 }
98}
99} // namespace
100
105 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input,
106 std::make_shared<CommonBinsValidator>()),
107 "The workspace containing the spectra to be summed.");
108 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
109 "The name of the workspace to be created as the output of the algorithm. "
110 " A workspace of this name will be created and stored in the Analysis "
111 "Data Service.");
112
113 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
114 mustBePositive->setLower(0);
115 declareProperty("StartWorkspaceIndex", 0, mustBePositive, "The first Workspace index to be included in the summing");
116 declareProperty("EndWorkspaceIndex", EMPTY_INT(), mustBePositive,
117 "The last Workspace index to be included in the summing");
118
119 declareProperty(std::make_unique<Kernel::ArrayProperty<int>>("ListOfWorkspaceIndices"),
120 "A list of workspace indices as a string with ranges, for "
121 "example: 5-10,15,20-23. \n"
122 "Optional: if not specified, then the "
123 "Start/EndWorkspaceIndex fields are used alone. "
124 "If specified, the range and the list are combined (without "
125 "duplicating indices). For example, a range of 10 to 20 and "
126 "a list '12,15,26,28' gives '10-20,26,28'.");
127
128 declareProperty("IncludeMonitors", true, "Whether to include monitor spectra in the summation.");
129
130 declareProperty("WeightedSum", false,
131 "Instead of the usual spectra sum, calculate the weighted "
132 "sum. This has the form: \n"
133 ":math:`nSpectra "
134 "\\times\\Sigma(Signal_i/Error_i^2)/\\Sigma(1/Error_i^2)`\n "
135 "This property is ignored for event workspace.\n"
136 "The sums are defined for :math:`Error_i != 0` only, so the "
137 "values with zero error are dropped from the summation. To "
138 "estimate the number of dropped values see the "
139 "description. ");
140
141 declareProperty("RemoveSpecialValues", false,
142 "If enabled floating point special values such as NaN or Inf"
143 " are removed before the spectra are summed.");
144
145 declareProperty("MultiplyBySpectra", true,
146 "For unnormalized data one should multiply the weighted sum "
147 "by the number of spectra contributing to the bin.");
148 setPropertySettings("MultiplyBySpectra", std::make_unique<EnabledWhenProperty>("WeightedSum", IS_EQUAL_TO, "1"));
149
150 declareProperty("UseFractionalArea", true,
151 "Normalize the output workspace to the fractional area for "
152 "RebinnedOutput workspaces.");
153}
154
155/*
156 * Validate the input parameters
157 * @returns map with keys corresponding to properties with errors and values
158 * containing the error messages.
159 */
160std::map<std::string, std::string> SumSpectra::validateInputs() {
161 // create the map
162 std::map<std::string, std::string> validationOutput;
163
164 // Non-workspace checks
165 const int minIndex = getProperty("StartWorkspaceIndex");
166 const int maxIndex = getProperty("EndWorkspaceIndex");
167 if (minIndex > maxIndex) {
168 validationOutput["StartWorkspaceIndex"] = "Selected minimum workspace "
169 "index is greater than selected "
170 "maximum workspace index.";
171 validationOutput["EndWorkspaceIndex"] = "Selected maximum workspace index "
172 "is lower than selected minimum "
173 "workspace index.";
174 } else {
175 const std::vector<int> indices = getProperty("ListOfWorkspaceIndices");
176 if (MatrixWorkspace_const_sptr singleWs = getProperty("InputWorkspace")) {
177 validateSingleMatrixWorkspace(validationOutput, *singleWs, minIndex, maxIndex, indices);
178 } else {
179 validateWorkspaceName(validationOutput, getPropertyValue("InputWorkspace"), minIndex, maxIndex, indices);
180 }
181 }
182 return validationOutput;
183}
184
185namespace { // anonymous namespace
186// various checks on the workspace index to see if it should be included in the
187// sum if it is masked, the value of numMasked is incremented
188bool useSpectrum(const SpectrumInfo &spectrumInfo, const size_t wsIndex, const bool keepMonitors, size_t &numMasked) {
189 if (spectrumInfo.hasDetectors(wsIndex)) {
190 // Skip monitors, if the property is set to do so
191 if (!keepMonitors && spectrumInfo.isMonitor(wsIndex))
192 return false;
193 // Skip masked detectors
194 if (spectrumInfo.isMasked(wsIndex)) {
195 numMasked++;
196 return false;
197 }
198 }
199 return true;
200}
201} // anonymous namespace
202
207 // Try and retrieve the optional properties
208 m_keepMonitors = getProperty("IncludeMonitors");
209
210 // setup all of the outputs
211 MatrixWorkspace_sptr outputWorkspace = nullptr;
212 size_t numSpectra(0); // total number of processed spectra
213 size_t numMasked(0); // total number of the masked and skipped spectra
214 size_t numZeros(0); // number of spectra which have 0 value in the first column (used in special cases of evaluating
215 // how good Poissonian statistics is)
216
217 // Get the input workspace -- ths may be a temporary workspace with the special values replaced
219 auto spectrumInfo = localworkspace->spectrumInfo();
220 m_numberOfSpectra = static_cast<int>(localworkspace->getNumberHistograms());
221 numMasked = determineIndices(spectrumInfo, m_numberOfSpectra);
222 if (m_indices.empty()) {
223 throw std::runtime_error("No spectra selected for summing. Check the input parameters.");
224 }
225 numSpectra = m_indices.size();
226 m_yLength = localworkspace->y(m_indices.front()).size();
227
228 // determine the output spectrum number
229 m_outSpecNum = getOutputSpecNo(localworkspace);
230 g_log.information() << "Spectra remapping gives single spectra with spectra number: " << m_outSpecNum << "\n";
231
232 m_calculateWeightedSum = getProperty("WeightedSum");
233 m_multiplyByNumSpec = getProperty("MultiplyBySpectra");
234
235 EventWorkspace_const_sptr eventW = std::dynamic_pointer_cast<const EventWorkspace>(localworkspace);
236 if (eventW) {
237 Progress progress(this, 0.0, 1.0, m_indices.size());
239 g_log.warning("Ignoring request for WeightedSum");
241 }
242 outputWorkspace = create<EventWorkspace>(*eventW, 1, eventW->binEdges(0));
243
244 execEvent(outputWorkspace, progress, numZeros);
245 } else {
246 //-------Workspace 2D mode -----
247
248 // Create the 2D workspace for the output
249 outputWorkspace = API::WorkspaceFactory::Instance().create(localworkspace, 1,
250 localworkspace->x(m_indices.front()).size(), m_yLength);
251
252 // This is the (only) output spectrum
253 auto &outSpec = outputWorkspace->getSpectrum(0);
254
255 // Copy over the bin boundaries
256 outSpec.setSharedX(localworkspace->sharedX(0));
257
258 // Build a new spectra map
259 outSpec.setSpectrumNo(m_outSpecNum);
260 outSpec.clearDetectorIDs();
261
262 for (size_t const i : m_indices) {
263 outSpec.addDetectorIDs(localworkspace->getSpectrum(i).getDetectorIDs());
264 }
265
266 Progress progress(this, 0.0, 1.0, m_indices.size());
267 if (localworkspace->id() == "RebinnedOutput") {
268 // this version is for a special workspace that has fractional overlap information
269 // Transform to real workspace types
270 RebinnedOutput_const_sptr inWS = std::dynamic_pointer_cast<const RebinnedOutput>(localworkspace);
271 RebinnedOutput_sptr outWS = std::dynamic_pointer_cast<RebinnedOutput>(outputWorkspace);
273 doFractionalWeightedSum(inWS, outWS, progress, numZeros);
274 } else {
275 doFractionalSum(inWS, outWS, progress, numZeros);
276 }
277 } else {
278 // for things where all the bins are lined up
280 doSimpleWeightedSum(localworkspace, outSpec, progress, numZeros);
281 } else {
282 doSimpleSum(localworkspace, outSpec, progress, numZeros);
283 }
284 }
285 }
286
287 // set up the summing statistics
288 outputWorkspace->mutableRun().addProperty("NumAllSpectra", int(numSpectra), "", true);
289 outputWorkspace->mutableRun().addProperty("NumMaskSpectra", int(numMasked), "", true);
290 outputWorkspace->mutableRun().addProperty("NumZeroSpectra", int(numZeros), "", true);
291
292 // Assign it to the output workspace property
293 setProperty("OutputWorkspace", outputWorkspace);
294}
295
296size_t SumSpectra::determineIndices(SpectrumInfo const &spectrumInfo, const size_t numberOfSpectra) {
297 // assume that m_numberOfSpectra has been set
298 m_indices.clear();
299
300 // try the list form first
301 const std::vector<int> indices_list = getProperty("ListOfWorkspaceIndices");
302 std::transform(indices_list.cbegin(), indices_list.cend(), std::back_inserter(m_indices),
303 [](const int idx) { return static_cast<size_t>(idx); });
304
305 // add the range specified by the user
306 // this has been checked to be 0<= m_minWsInd <= maxIndex <=
307 // m_numberOfSpectra where maxIndex can be an EMPTY_INT
308 int minIndex = getProperty("StartWorkspaceIndex");
309 int maxIndex = getProperty("EndWorkspaceIndex");
310 if (isEmpty(maxIndex) && m_indices.empty()) {
311 maxIndex = static_cast<int>(numberOfSpectra - 1);
312 }
313
314 // create the indices in the range
315 size_t numMasked{0};
316 if (!isEmpty(maxIndex)) {
317 for (int i = minIndex; i <= maxIndex; i++) {
318 // only include indices that are not masked and, if requested, are not monitors.
319 // the number of masked spectra is counted in numMasked.
320 if (useSpectrum(spectrumInfo, static_cast<size_t>(i), m_keepMonitors, numMasked)) {
321 m_indices.push_back(static_cast<size_t>(i));
322 }
323 }
324 }
325
326 // sort and deduplicate (list and range may overlap)
327 std::sort(m_indices.begin(), m_indices.end());
328 m_indices.erase(std::unique(m_indices.begin(), m_indices.end()), m_indices.end());
329
330 return numMasked;
331}
332
340 // initial value - any included spectrum will do
341 specnum_t specId = localworkspace->getSpectrum(m_indices.front()).getSpectrumNo();
342
343 // the total number of spectra
344 size_t totalSpec = localworkspace->getNumberHistograms();
345
346 specnum_t temp;
347 for (const auto index : m_indices) {
348 if (index < totalSpec) {
349 temp = localworkspace->getSpectrum(index).getSpectrumNo();
350 if (temp < specId)
351 specId = temp;
352 }
353 }
354
355 return specId;
356}
357
364 // Get a copy of the input workspace
365 MatrixWorkspace_sptr wksp = getProperty("InputWorkspace");
366 bool replaceSpecialValues = getProperty("RemoveSpecialValues");
368 auto alg = createChildAlgorithm("ReplaceSpecialValues");
369 alg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", wksp);
370 std::string outName = "_" + wksp->getName() + "_clean";
371 alg->setProperty("OutputWorkspace", outName);
372 alg->setProperty("NaNValue", 0.0);
373 alg->setProperty("NaNError", 0.0);
374 alg->setProperty("InfinityValue", 0.0);
375 alg->setProperty("InfinityError", 0.0);
376 alg->executeAsChildAlg();
377 return alg->getProperty("OutputWorkspace");
378 } else {
379 // Skip any additional processing
380 return wksp;
381 }
382}
383
394 size_t &numZeros) {
395 // Get references to the output workspaces's data vectors
396 auto &YSum = outSpec.mutableY();
397 auto &YErrorSum = outSpec.mutableE();
398
399 std::fill(YSum.begin(), YSum.end(), 0.0);
400 std::fill(YErrorSum.begin(), YErrorSum.end(), 0.0);
401
402 // Loop over spectra (cache-friendly: each spectrum's data is contiguous in memory)
403 for (size_t iwksp : m_indices) {
404 const auto &y = inWS->y(iwksp);
405 const auto &e = inWS->e(iwksp);
406 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
407 YSum[jbin] += y[jbin];
408 const double ev = e[jbin];
409 YErrorSum[jbin] += ev * ev;
410 }
411 progress.report();
412 }
413 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
414 YErrorSum[jbin] = std::sqrt(YErrorSum[jbin]);
415 }
416
417 numZeros = 0;
418}
419
430 size_t &numZeros) {
431 // Get references to the output workspaces's data vectors
432 auto &YSum = outSpec.mutableY();
433 auto &YErrorSum = outSpec.mutableE();
434
435 std::fill(YSum.begin(), YSum.end(), 0.0);
436 std::fill(YErrorSum.begin(), YErrorSum.end(), 0.0);
437
438 std::vector<double> normalization(m_yLength, 0.0);
439 std::vector<size_t> nZeroes(m_yLength, 0);
440
441 // Loop over spectra (cache-friendly: each spectrum's data is contiguous in memory)
442 for (size_t iwksp : m_indices) {
443 const auto &y = inWS->y(iwksp);
444 const auto &e = inWS->e(iwksp);
445 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
446 const double ev = e[jbin];
447 if (std::isnormal(ev)) {
448 const double weight = 1.0 / (ev * ev);
449 normalization[jbin] += weight;
450 YSum[jbin] += weight * y[jbin];
451 } else {
452 nZeroes[jbin]++;
453 }
454 }
455 progress.report();
456 }
457 // apply the normalization factor and optional scaling
458 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
459 if (normalization[jbin] != 0.) {
460 const double norm = 1.0 / normalization[jbin];
461 YSum[jbin] *= norm;
462 // NOTE: the total error ends up being the root of the normalization factor
463 YErrorSum[jbin] = std::sqrt(norm);
464 }
466 // NOTE: do not include the zero-weighted values in the number of spectra
467 const double scale = double(m_indices.size() - nZeroes[jbin]);
468 YSum[jbin] *= scale;
469 YErrorSum[jbin] *= scale;
470 }
471 }
472 // add up all zeros across the bins to get the total number of spectra that were dropped from the sum
473 numZeros = std::accumulate(nZeroes.begin(), nZeroes.end(), size_t(0));
474}
475
485 Progress &progress, size_t &numZeros) {
486 // Check finalize state prior to the sum process, at the completion
487 // the output is unfinalized
488 auto isFinalized = inWS->isFinalized();
489
490 // Get references to the output workspaces's data vectors
491 auto &outSpec = outWS->getSpectrum(0);
492 auto &YSum = outSpec.mutableY();
493 auto &YErrorSum = outSpec.mutableE();
494 auto &FracSum = outWS->dataF(0);
495
496 std::fill(YSum.begin(), YSum.end(), 0.0);
497 std::fill(YErrorSum.begin(), YErrorSum.end(), 0.0);
498 std::fill(FracSum.begin(), FracSum.end(), 0.0);
499
500 // Loop over spectra (cache-friendly: each spectrum's data is contiguous in memory)
501 for (size_t iwksp : m_indices) {
502 const auto &y = inWS->y(iwksp);
503 const auto &e = inWS->e(iwksp);
504 const auto &f = inWS->readF(iwksp);
505 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
506 // use the mapping y' --> y * fracVal and e' --> e * fracVal where fracVal is the fractional area for this bin
507 const double fracVal = (isFinalized ? f[jbin] : 1.0);
508 const double yv = y[jbin] * fracVal;
509 const double ev = e[jbin] * fracVal;
510 // now do simple sum of the mapped values
511 YSum[jbin] += yv;
512 YErrorSum[jbin] += ev * ev;
513 FracSum[jbin] += f[jbin];
514 }
515 progress.report();
516 }
517 for (size_t jbin = 0; jbin < m_yLength; jbin++)
518 YErrorSum[jbin] = std::sqrt(YErrorSum[jbin]);
519
520 numZeros = 0;
521
522 // Create the correct representation if using fractional area
523 auto useFractionalArea = getProperty("UseFractionalArea");
524 if (useFractionalArea) {
525 outWS->finalize(/*hasSqrdErrs =*/false);
526 }
527}
528
538 Progress &progress, size_t &numZeros) {
539 // Check finalize state prior to the sum process, at the completion
540 // the output is unfinalized
541 auto isFinalized = inWS->isFinalized();
542
543 // Get references to the output workspaces's data vectors
544 auto &outSpec = outWS->getSpectrum(0);
545 auto &YSum = outSpec.mutableY();
546 auto &YErrorSum = outSpec.mutableE();
547 auto &FracSum = outWS->dataF(0);
548
549 std::fill(YSum.begin(), YSum.end(), 0.0);
550 std::fill(YErrorSum.begin(), YErrorSum.end(), 0.0);
551 std::fill(FracSum.begin(), FracSum.end(), 0.0);
552
553 std::vector<double> normalization(m_yLength, 0.0);
554 std::vector<size_t> nZeroes(m_yLength, 0);
555
556 // Loop over spectra (cache-friendly: each spectrum's data is contiguous in memory)
557 for (size_t iwksp : m_indices) {
558 const auto &y = inWS->y(iwksp);
559 const auto &e = inWS->e(iwksp);
560 const auto &f = inWS->readF(iwksp);
561 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
562 // use the mapping y' --> y * fracVal and e' --> e * fracVal where fracVal is the fractional area for this bin
563 const double fracVal = (isFinalized ? f[jbin] : 1.0);
564 const double yv = y[jbin] * fracVal;
565 const double ev = e[jbin] * fracVal;
566 // now perform weighted sum of the mapped values
567 if (std::isnormal(ev)) { // is non-zero, nan, or infinity
568 const double weight = 1.0 / (ev * ev);
569 normalization[jbin] += weight;
570 YSum[jbin] += weight * yv;
571 } else {
572 nZeroes[jbin]++;
573 }
574 FracSum[jbin] += f[jbin];
575 }
576 progress.report();
577 }
578 // apply the normalization factor and optional scaling
579 for (size_t jbin = 0; jbin < m_yLength; jbin++) {
580 if (normalization[jbin] != 0.) {
581 const double norm = 1.0 / normalization[jbin];
582 YSum[jbin] *= norm;
583 // NOTE: the total error is the sqrt of the normalization factor
584 YErrorSum[jbin] = std::sqrt(norm);
585 }
587 // NOTE: do not include the zero-weighted values in the number of spectra
588 const double scale = double(m_indices.size() - nZeroes[jbin]);
589 YSum[jbin] *= scale;
590 YErrorSum[jbin] *= scale;
591 }
592 }
593 numZeros = std::accumulate(nZeroes.begin(), nZeroes.end(), size_t(0));
594
595 // Create the correct representation if using fractional area
596 auto useFractionalArea = getProperty("UseFractionalArea");
597 if (useFractionalArea) {
598 outWS->finalize(/*hasSqrdErrs =*/false);
599 }
600}
601
608void SumSpectra::execEvent(const MatrixWorkspace_sptr &outputWorkspace, Progress &progress, size_t &numZeros) {
609 MatrixWorkspace_const_sptr localworkspace = getProperty("InputWorkspace");
610 EventWorkspace_const_sptr inputWorkspace = std::dynamic_pointer_cast<const EventWorkspace>(localworkspace);
611
612 // Get the pointer to the output event list
613 EventWorkspace_sptr outputEventWorkspace = std::dynamic_pointer_cast<EventWorkspace>(outputWorkspace);
614 EventList &outputEL = outputEventWorkspace->getSpectrum(0);
615 outputEL.setSpectrumNo(m_outSpecNum);
616 outputEL.clearDetectorIDs();
617
618 // count number of events for the output
619 std::size_t numOutputEvents{0};
620 for (const auto i : m_indices) {
621 numOutputEvents += inputWorkspace->getSpectrum(i).getNumberEvents();
622 }
623 outputEL.switchTo(inputWorkspace->getSpectrum(0).getEventType());
624 outputEL.reserve(numOutputEvents);
625
626 // Loop over spectra
627 for (const auto i : m_indices) {
628 // Add the event lists with the operator
629 const EventList &inputEL = inputWorkspace->getSpectrum(i);
630 if (inputEL.empty()) {
631 ++numZeros;
632 }
633 outputEL += inputEL;
634
635 progress.report();
636 }
637}
638
639} // namespace Mantid::Algorithms
std::string name
Definition Run.cpp:60
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:542
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:423
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::vector< size_t > m_indices
Sorted list 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