\(\renewcommand\AA{\unicode{x212B}}\)
GetDetectorOffsets v1¶
Summary¶
Creates an OffsetsWorkspace containing offsets for each detector. You can then save these to a .cal file using SaveCalFile.
See Also¶
Properties¶
Name |
Direction |
Type |
Default |
Description |
---|---|---|---|---|
InputWorkspace |
Input |
Mandatory |
A 2D workspace with X values of d-spacing |
|
Step |
Input |
number |
0.001 |
Step size used to bin d-spacing data |
DReference |
Input |
number |
2 |
Center of reference peak in d-space |
XMin |
Input |
number |
0 |
Minimum of CrossCorrelation data to search for peak, usually negative |
XMax |
Input |
number |
0 |
Maximum of CrossCorrelation data to search for peak, usually positive |
GroupingFileName |
Input |
string |
Optional: The name of the output CalFile to save the generated OffsetsWorkspace. Allowed extensions: [‘.cal’] |
|
OutputWorkspace |
Output |
OffsetsWorkspace |
Mandatory |
An output workspace containing the offsets. |
MaskWorkspace |
Output |
MaskWorkspace |
_empty_ |
Mask workspace (optional input / output workspace): when specified, if the workspace already exists, any incoming masked detectors will be combined with any additional outgoing masked detectors detected by the algorithm |
PeakFunction |
Input |
string |
Gaussian |
The function type for fitting the peaks. Allowed values: [‘AsymmetricPearsonVII’, ‘BackToBackExponential’, ‘Bk2BkExpConvPV’, ‘DeltaFunction’, ‘ElasticDiffRotDiscreteCircle’, ‘ElasticDiffSphere’, ‘ElasticIsoRotDiff’, ‘ExamplePeakFunction’, ‘Gaussian’, ‘IkedaCarpenterPV’, ‘Lorentzian’, ‘PearsonIV’, ‘PseudoVoigt’, ‘Voigt’] |
EstimateFWHM |
Input |
boolean |
False |
Whether to esimate FWHM of peak function when estimating fit parameters |
MaxOffset |
Input |
number |
1 |
Maximum absolute value of offsets; default is 1 |
OffsetMode |
Input |
string |
Relative |
Whether to calculate a relative, absolute, or signed offset. Allowed values: [‘Relative’, ‘Absolute’, ‘Signed’] |
DIdeal |
Input |
number |
2 |
The known peak centre value from the NIST standard information, this is only used in Absolute OffsetMode. |
Description¶
This algorithm requires a workspace containing a cross-correlation, generated by the CrossCorrelate v1 algorithm which should contain a single peak and where the x-axis contains spectral offsets, in number of bins.
The algorithm iterates over each spectrum in the input workspace containing the cross-correlation spectra and fits a PeakFunction (default is a Gaussian function) with linear background to the cross-correlation spectra. Remember: the peak shape is used for fitting the cross-correlation spectrum rather than the Bragg peaks in the original data.
Converting peak position to offset¶
The fit is used to calculate the centre of the fitted peak.
In the equations below, the found centre of the cross-correlation peak is refered to as \(CCPeakCentre\).
The other parameters in the equations,
\(Step\) is the Step
property,
\(DReference\) is the DReference
property,
and \(DIdeal\) is the DIdeal
property.
Using the fitted peak center, there are 3 options for calculating offset, depending on the choice for the OffsetMode
input parameter:
OffsetMode="Relative"
(offset relative to reference position):
\(offset = -CCPeakCentre*Step/(DReference+CCPeakCentre*Step)\)
This requires a narrow integration band in CrossCorrelate v1 with linear binning of the input data and a known DReference
.
OffsetMode="Absolute"
(offset relative to ideal position):
\(offset = -CCPeakCentre*Step/(DReference+CCPeakCentre*Step) + (DIdeal - DReference) / DReference\)
This requires a narrow integration band in CrossCorrelate v1 with linear binning of the input data and a known DReference
.
OffsetMode="Signed"
(offset in raw number of bins):
\(offset = -CCPeakCentre\)
This is then written into a .cal file for every detector that contributes to that spectrum. All of the entries in the cal file are initially set to both be included, but also to all group into a single group on DiffractionFocussing v2. The CreateCalFileByNames v1 algorithm can be used to alter the grouping in the cal file.
Estimating the CC-spectrum fit parameters¶
The starting value for the fit is that the linear background is zero.
The peak center is found in two steps. First is the x-value of the highest point in the whole cross-correlation spectrum. Then it is observed again by subtracting the background (which is zero) then finding the highest point again within the neighborhood of the original data.
The height is the background subtracted y-value of the heightest point as described earlier.
The full-width-half-maximum is \(2 \sigma \sqrt{2 ln(2)}\) where \(\sigma=10\) if EstimateFWHM=False
.
When True
, the value is estimated by integrating the background subtracted area under the window and dividing by the height.
Problems can arise for fitting if the cross-correlation peak is broad or the background is high and/or with significant slope. Since a broad peak can be estimated as a very broad peak with a relatively high background, the peak can be easily misfit. Similarly, since the starting value for the background is zero, a heavily sloping background will interfere with determining a starting value for the peak position. Also note that if the input cross-correlation has been calculated over too large a d-spacing range it can contain “harmonics” in addition to the fundamental peak and this will obviously confuse the peak fitting algorithm.
Usage¶
import os
# Create a workspace with a Gaussian peak in the centre.
ws = CreateSampleWorkspace(Function='User Defined',UserDefinedFunction='name=Gaussian,Height=1,PeakCentre=10,Sigma=1',XMin=0,XMax=20,BinWidth=0.1)
ws.getAxis(0).setUnit( 'dSpacing' )
# Generate a file path to save the .cal file at.
calFilePath = os.path.expanduser( '~/MantidUsageExample_CalFile.cal' )
# Run the algorithm
msk = GetDetectorOffsets(ws,0.001,10.0,0, 10, calFilePath)
# Read the saved .cal file back in
f = open( calFilePath, 'r' )
file = f.read().split('\n')
f.close()
# Print out first 10 lines of the file
print("{} ...".format(file[0][:55]))
for line in file[1:10]:
print(line)
Output¶
# Calibration file for instrument basic_rect written on ...
# Format: number UDET offset select group
0 ... ... 1 1
1 ... ... 1 1
2 ... ... 1 1
3 ... ... 1 1
4 ... ... 1 1
5 ... ... 1 1
6 ... ... 1 1
7 ... ... 1 1
Categories: AlgorithmIndex | Diffraction\Calibration
Source¶
C++ header: GetDetectorOffsets.h
C++ source: GetDetectorOffsets.cpp