SumSpectra v1

../_images/SumSpectra-v1_dlg.png

SumSpectra dialog.

Summary

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.

Properties

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: nSpectra \times\Sigma(Signal_i/Error_i^2)/\Sigma(1/Error_i^2) This property is ignored for event workspace. The sums are defined for Error_i != 0 only, so the values with zero error are dropped from the summation. To estimate the number of dropped values see the description.

Description

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.

The algorithm adds to the OutputWorkspace three additional properties (Log values). The properties (Log) names are: NumAllSpectra, NumMaskSpectra and NumZeroSpectra, where:

  • NumAllSpectra is the number of spectra contributed to the sum
  • NumMaskSpectra is the spectra dropped from the summations because they are masked.
    • If monitors are not included in the summation, they are not counted here.
  • NumZeroSpectra isthe number of zero bins in histogram workspace or empty spectra for event workspace.
    • These spectra are dropped from the summation of histogram workspace when WeightedSum property is set to True.

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

Usage

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

Source

C++ source: SumSpectra.cpp

C++ header: SumSpectra.h