Table of Contents
The SumSpectra algorithm adds the data values in each time bin across a range of spectra; the output workspace has a single spectrum. If the input is an EventWorkspace, the output is also an EventWorkspace; otherwise it will be a Workspace2D.
Name | Direction | Type | Default | Description |
---|---|---|---|---|
InputWorkspace | Input | MatrixWorkspace | Mandatory | The workspace containing the spectra to be summed. |
OutputWorkspace | Output | MatrixWorkspace | Mandatory | The name of the workspace to be created as the output of the algorithm. A workspace of this name will be created and stored in the Analysis Data Service. |
StartWorkspaceIndex | Input | number | 0 | The first Workspace index to be included in the summing |
EndWorkspaceIndex | Input | number | Optional | The last Workspace index to be included in the summing |
ListOfWorkspaceIndices | Input | int list | A list of workspace indices as a string with ranges, for example: 5-10,15,20-23. Optional: if not specified, then the Start/EndWorkspaceIndex fields are used alone. If specified, the range and the list are combined (without duplicating indices). For example, a range of 10 to 20 and a list ‘12,15,26,28’ gives ‘10-20,26,28’. | |
IncludeMonitors | Input | boolean | True | Whether to include monitor spectra in the summation. |
WeightedSum | Input | boolean | False | Instead of the usual spectra sum, calculate the weighted sum. This has the form: This property is ignored for event workspace. The sums are defined for only, so the values with zero error are dropped from the summation. To estimate the number of dropped values see the description. |
RemoveSpecialValues | Input | boolean | False | If enabled floating point special values such as NaN or Inf are removed before the spectra are summed. |
Takes a workspace as input and sums all of the spectra within it maintaining the existing bin structure and units. Any masked spectra are ignored. The result is stored as a new workspace containing a single spectra.
If we define a the spectrum with bins . The unweighted sum is just
The weighted sum (property ignored for event workspaces), the sum is defined, for
If the weights contributing to the sum are equal, these result in the same value.
The algorithm adds to the OutputWorkspace three additional properties (Log values). The properties (Log) names are: NumAllSpectra, NumMaskSpectra and NumZeroSpectra, where:
Assuming pWS is the output workspace handle, from Python these properties can be accessed by the code:
nSpectra = pWS.getRun().getLogData("NumAllSpectra").value
nMaskedSpectra = pWS.getRun().getLogData("NumMaskSpectra").value
nZeroSpectra = pWS.getRun().getLogData("NumZeroSpectra").value
Example - a simple example of running SumSpectra.
ws = CreateSampleWorkspace("Histogram", Random=True)
print("Workspace has %d spectra" % ws.getNumberHistograms())
ws = SumSpectra(ws)
print("Workspace has %d spectra" % ws.getNumberHistograms())
Output:
Workspace has 200 spectra
Workspace has 1 spectra
Example - running SumSpectra with a list of indicies.
ws = CreateSampleWorkspace("Histogram", Random=True)
print("Workspace has %d spectra" % ws.getNumberHistograms())
ws = SumSpectra(ws, ListOfWorkspaceIndices='0-3, 10-13')
print("Workspace has %d spectra" % ws.getNumberHistograms())
Output:
Workspace has 200 spectra
Workspace has 1 spectra
Example - a running SumSpectra with a start and end index.
ws = CreateSampleWorkspace("Histogram", Random=True)
print("Workspace has %d spectra" % ws.getNumberHistograms())
ws = SumSpectra(ws, StartWorkspaceIndex=0, EndWorkspaceIndex=9)
print("Workspace has %d spectra" % ws.getNumberHistograms())
Output:
Workspace has 200 spectra
Workspace has 1 spectra
Example - a running SumSpectra in weighted sum mode.
ws = CreateSampleWorkspace("Histogram", Random=True)
print("Workspace has %d spectra" % ws.getNumberHistograms())
ws = SumSpectra(ws, WeightedSum=True)
print("Workspace has %d spectra" % ws.getNumberHistograms())
Output:
Workspace has 200 spectra
Workspace has 1 spectra
Categories: Algorithms | Transforms\Grouping
C++ source: SumSpectra.cpp (last modified: 2017-12-11)
C++ header: SumSpectra.h (last modified: 2017-12-11)