\(\renewcommand\AA{\unicode{x212B}}\)

CrossCorrelate v1

Summary

Cross-correlates a range of spectra against one reference spectra in the same workspace.

See Also

GetDetectorOffsets

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MatrixWorkspace

Mandatory

A 2D workspace with X values of d-spacing

OutputWorkspace

Output

MatrixWorkspace

Mandatory

The name of the output workspace

ReferenceSpectra

Input

number

0

The Workspace Index of the spectra to correlate all other spectra against.

WorkspaceIndexMin

Input

number

0

The workspace index of the first member of the range of spectra to cross-correlate against.

WorkspaceIndexMax

Input

number

0

The workspace index of the last member of the range of spectra to cross-correlate against.

WorkspaceIndexList

Input

unsigned int list

A comma-separated list of individual workspace indices of spectra to cross-correlate against.

XMin

Input

number

0

The starting point of the region to be cross correlated.

XMax

Input

number

0

The ending point of the region to be cross correlated.

MaxDSpaceShift

Input

number

Optional

Optional float for maximum shift to calculate (in d-spacing)

Description

Compute the cross correlation function for a range of spectra with respect to a reference spectrum.

This is used in powder diffraction experiments when trying to estimate the offset (in number of bin indices) of one spectrum with respect to another one, where the x-axis units share a common crystallographic unit (such as d-spacing or momentum transfer). The input spectra need to be in d-spacing and then interpolated on the X-axis of the reference before calculating the cross correlation in bin index. In principle, momentum transfer will work, but this is not currently supported. The cross correlation function is computed as:

\[c_{fg}(r) = \frac{1}{\sigma_f \sigma_g} \int_{XMin}^{XMax} (f(x) - \mu_f) (g(x+r)-\mu_g) dx\]

where \(x\) and \(r\) are bin indices. \(r\) being either half of the number of points in the requested range, XMin to XMax, of the reference spectrum, or up to the number of bins corresponding to MaxDSpaceShift, whichever is smaller. \(f(x)\) is the reference spectrum, with \(\mu_f\) and \(\sigma_f\) being the mean and variance respectively. Similarly, \(g(x)\) is the reference spectrum, with \(\mu_g\) and \(\sigma_g\) being the mean and variance respectively. All functions are evaluated as a function of bin number rather than x-value.

More details can be found here.

Comments for creating useful cross-correlation output

  • Supply input data with relatively high signal to noise ratio. When this is not met, the resulting cross-correlation generally have issues having offsets determined from them by GetDetectorOffsets v1.

  • Take note of input binning structure before using GetDetectorOffsets v1 and ConvertDiffCal v1. The different binning modes (linear or logorithmic) correspond to different behavior in the follow-on algorithms.

  • Cross-correlating linear binning generally uses OffsetMode="Relative" or OffsetMode="Absolute" and requires a narrow range of integration around a single Bragg peak with known reference d-spacing.

  • Use a large range for XMin to XMax. This will promote calibrations that take a larger range of the data into account rather than a single diffraction peak. However, it only works for logorithmic binning which will use OffsetMode="Signed" in GetDetectorOffsets v1.

  • With wide range of integration, use the MaxDSpaceShift to limit the value of \(r\). Not only will this speed up the calculation, but the output spectra will only include where the spectra are similar to the reference and not have spurious peaks or background. NOTE: MaxDSpaceShift must be greater than approximately double the maximum Bragg peak full-width of the input data to ensure that the cross correlation contains a complete peak.

Usage

Example - Crosscorrelate 2 spectra

#Create a workspace with 2 spectra with five bins of width 0.5
ws = CreateSampleWorkspace(BankPixelWidth=1, XUnit='dSpacing', XMax=5, BinWidth=0.5)
ws = ScaleX(InputWorkspace='ws', Factor=0.5, Operation='Add', IndexMin=1, IndexMax=1)
# Run algorithm  CrossCorrelate
OutputWorkspace = CrossCorrelate(InputWorkspace='ws', WorkspaceIndexMax=1, XMin=2, XMax=4)

# Show workspaces
print("AutoCorrelation {}".format(OutputWorkspace.readY(0)))
print("CrossCorrelation {}".format(OutputWorkspace.readY(1)))
AutoCorrelation [-0.01890212  1.         -0.01890212]
CrossCorrelation [-0.68136257  0.16838401  0.45685055]

Categories: AlgorithmIndex | Arithmetic

Source

C++ header: CrossCorrelate.h

C++ source: CrossCorrelate.cpp